code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 2e6 + 5;
const int Mod = 1e9 + 7;
int n, m, k, fac[N], inv[N];
int Inc (int a, int b) { return (a += b) >= Mod ? a - Mod : a; }
int Dec (int a, int b) { return (a -= b) < 0 ? a + Mod : a; }
int Mul (int a, int b) { return 1ll * a * b % Mod; }
int fpow (int a, int b) { int ans = 1; for (; b; a = Mul(a, a), b >>= 1) if(b & 1) ans = Mul(ans, a); return ans; }
int C (int n, int m) { return n < m ? 0 : Mul(fac[n], Mul(inv[m], inv[n - m])); }
int main () {
cin >> n >> m >> k;
fac[0] = inv[0] = 1;
rep(i, 1, n + m) fac[i] = Mul(fac[i - 1], i), inv[i] = fpow(fac[i], Mod - 2);
if(k >= n) printf("%d", C(n + m, n));
else if(m + k < n) puts("0");
else printf("%d", Dec(C(n + m, n), C(n + m, n - k - 1)));
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define faster ios_base::sync_with_stdio(0);
int main()
{
faster
int a,b,c;
cin>>a>>b>>c;
if(a*a+b*b<c*c)
cout<<"Yes"<<endl;
if(a*a+b*b>=c*c)
cout<<"No"<<endl;
return 0;
}
|
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
ld PI=asin(1)*2;
//using namespace atcoder;
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
int n;
vector<T> d;
BIT(int n=0):n(n),d(n+1) {}
void add(int i, T x=1) {
for (i++; i <= n; i += i&-i) {
d[i] += x;
}
}
T sum(int i) {
T x = 0;
for (i++; i; i -= i&-i) {
x += d[i];
}
return x;
}
T sum(int l, int r) {
return sum(r-1) - sum(l-1);
}
};
int main(){
ll H,W,M;
cin >> H >> W >> M;
vector<ll> X(M),Y(M);
vector<ll> A(W+1,H), B(H+1,W);
rep(i,M){
cin >> X[i] >> Y[i];
X[i]--;Y[i]--;
cmin(A[Y[i]],X[i]);
cmin(B[X[i]],Y[i]);
}
ll ans = 0;
rep(y,B[0]){
ans += A[y];
}
rep(x,A[0]){
ans += B[x];
}
ll sum = 0;
BIT<ll> tr(W);
rep(y,B[0]) tr.add(y,1);
vector<vector<ll> > ends(H+1);
rep(y,B[0]) ends[A[y]].push_back(y);
rep(x,A[0]){
for(auto& y:ends[x]) tr.add(y,-1);
ans -= tr.sum(0,B[x]);
}
cout << ans << endl;
} | #include<bits/stdc++.h>
#define ll long long
using namespace std;
int m=0;
int vis[109],pm[109];
int sm[109];
ll f[2][1050009];
void init()
{
for(int i=2;i<=72;i++)
{
if(!vis[i])
pm[++m]=i;
for(int j=1;j<=m&&i*pm[j]<=72;j++)
vis[i*pm[j]]=1;
}
}
int main()
{
ll a,b;
scanf("%lld%lld",&a,&b);
init();
int cur=0;
f[0][0]=1;
for(ll i=a;i<=b;i++)
{
cur^=1;
memset(f[cur],0,sizeof(f[cur]));
int ns=0;
for(int j=1;j<=m;j++)
if(i%pm[j]==0)
ns|=1<<(j-1);
for(int s=0;s<1<<m;s++)
{
f[cur][s]+=f[cur^1][s];
if((ns&s)==0)
f[cur][ns|s]+=f[cur^1][s];
}
}
ll ans=0;
for(int s=0;s<1<<m;s++)
ans+=f[cur][s];
printf("%lld",ans);
return 0;
} |
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack>
#include <sstream>
#include <set>
typedef long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
if(a%2==0) return 0;
else return 1;
}
int gcd(int a, int b){
if(a%b==0){
return b;
}else{
return (gcd(b,a%b));
}
}
int lcm(int a, int b){
int x = gcd(a,b);
return (a*b/x);
}
using namespace std;
// now
struct UnionFind {
vector<int> d;
UnionFind(int n=0) : d(n,-1){}
int Find (int x){//根の番号を探す
if(d[x] < 0) return x;
return d[x] = Find(d[x]);
}
bool unite (int x, int y){
x = Find(x); y = Find(y);
if(x == y ) return false;
if(d[x] < d[y]){
swap(x,y);
}
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y){
return Find(x) == Find(y);
}
int size(int x) {
return (-d[Find(x)]);
}
};
ll nCr (ll n, ll r){
ll ans = 1;
for(ll i = n ; i > n-r ; i --){
ans *= i;
}
for(ll i = 1 ; i<= r; i ++){
ans /= i;
}
return ans ;
}
int nPr (int n,int r){
int ans = 1;
for(int i = n ; i > n-r ; i --){
ans *= i;
}
return ans ;
}
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
ll ans = n * (mi+ma) /2;
return ans;
}
int r5 (int a){
int x = a * a * a * a * a;
return x;
}
struct Edge {int to,id;};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v,int c = -1, int p = -1){
int k = 1;
REP(i,g[v].size()){
int u = g[v][i].to, ei = g[v][i].id;
if(u == p ) continue;
if(c == k) k++;
ans[ei] = k; k++;
dfs(u,k-1,v);
}
}
int main(){
int n;
cin >> n;
vector<double> x(n),y(n);
REP(i,n){
cin >> x[i] >> y[i];
}
int ans = 0;
for(int i = 0;i<n;i++){
for(int j = i+1;j<n;j++){
double a = x[j] - x[i], b = y[j] - y[i];
if(a == 0) continue;
double c = b/a;
if(-1 <= c && c <=1) ans ++;
}
}
cout << ans <<endl;
}
| #include <bits/stdc++.h>
using namespace std;
template<int M>
struct static_mint {
static_assert(0 < M, "Module must be positive");
int val;
static_mint(): val() {}
static_mint(long long x) : val(x % M) { if (val < 0) val += M; }
static_mint pow(long long n) const { static_mint ans = 1, x(*this); while (n) { if (n & 1) ans *= x; x *= x; n /= 2; } return ans; }
static_mint inv() const { return pow(M - 2); }
friend static_mint pow(const static_mint &m, long long n) { return m.pow(n); }
friend static_mint inv(const static_mint &m) { return m.inv(); }
static_mint operator+() const { static_mint m; m.val = val; return m; }
static_mint operator-() const { static_mint m; m.val = M - val; return m; }
static_mint &operator+=(const static_mint &m) { if ((val += m.val) >= M) val -= M; return *this; }
static_mint &operator-=(const static_mint &m) { if ((val -= m.val) < 0) val += M; return *this; }
static_mint &operator*=(const static_mint &m) { val = (long long) val * m.val % M; return *this; }
static_mint &operator/=(const static_mint &m) { val = (long long) val * m.inv().val % M; return *this; }
friend static_mint operator+ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) += rhs; }
friend static_mint operator- (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) -= rhs; }
friend static_mint operator* (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) *= rhs; }
friend static_mint operator/ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) /= rhs; }
friend bool operator==(const static_mint &lhs, const static_mint &rhs) { return lhs.val == rhs.val; }
friend bool operator!=(const static_mint &lhs, const static_mint &rhs) { return lhs.val != rhs.val; }
static_mint &operator++() { return *this += 1; }
static_mint &operator--() { return *this -= 1; }
static_mint operator++(int) { static_mint result(*this); *this += 1; return result; }
static_mint operator--(int) { static_mint result(*this); *this -= 1; return result; }
template <typename T> explicit operator T() const { return T(val); }
friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
return os << m.val;
}
friend std::istream &operator>>(std::istream &is, static_mint &m) {
long long x; is >> x; m = x;
return is;
}
};
template <typename>
struct is_mint : public std::false_type { };
template <int M>
struct is_mint<static_mint<M>> : public std::true_type { };
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
using mint = static_mint<998244353>;
int n, m;
cin >> n >> m;
vector<mint> fact(n + 1), inv(n + 1);
fact[0] = inv[0] = 1;
for (int i = 1; i <= n; i++) {
fact[i] = i * fact[i - 1];
inv[i] = fact[i].inv();
}
auto choose = [&](int n, int k) -> mint {
if (0 <= n && 0 <= k && k <= n)
return fact[n] * inv[k] * inv[n - k];
return 0;
};
int lg = 32 - __builtin_clz(m) - 1;
vector<vector<mint>> dp(lg + 1, vector<mint>(m + 1));
for (int i = 0; i <= min(n, m); i += 2) {
dp[0][i] = choose(n, i);
}
for (int b = 1; b <= lg; b++) {
for (int sum = 0; sum <= m; sum++) {
for (int c = 0; (1 << b) * c <= sum; c += 2) {
dp[b][sum] += choose(n, c) * dp[b - 1][sum - (1 << b) * c];
}
}
}
cout << dp[lg][m] << '\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LL long long int
const LL MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
#define TIME cerr<<"Time Taken:"<<(float)clock()/CLOCKS_PER_SEC*1000<<"ms"<<endl
// When something is important enough, you do it even if the odds are not in your favor.
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef somujena
freopen("/home/somujena/competitive/input.txt", "r", stdin);
freopen("/home/somujena/competitive/output.txt", "w", stdout);
#endif
// code goes here
LL t=1;//cin>>t;
while(t--){
LL n,i,j;cin>>n;
LL a[n];
fo(i,0,n) cin>>a[i];
std::vector<LL> v;
LL in=1,prev=0,f=1;
fo(i,0,n){
if(a[i]==in){
if(i-1==prev){
if(a[i]>a[i-1]) {f=0;break;}
else{
swap(a[i],a[i-1]);
v.pb(i);
if(a[i]-a[i-1]==1) {prev=i+1,in=a[i]+1;}
else {prev=i;in=a[i-1]+1;}
}
continue;
}
if(i==prev){
prev=i+1;
in=a[i]+1;
continue;
}
bool f1=1;
if(a[prev]-in!=1) f1=0;
fo(j,prev,i-2){
if(a[j+1]-a[j]!=1) f1=0;//,cout<<j<<endl;
}
if(a[i-1]<a[i-2]) f1=0;
if(!f1) f=0;//,cout<<i<<sp<<in<<endl;
else{
rfo(j,i,prev) swap(a[j],a[j-1]),v.pb(j);
if(a[i]-a[i-1]!=1) {in=a[i-1]+1,prev=i;}
else {in=a[i]+1,prev=i+1;}
}
}
}
if(v.size()!=n-1) f=0;
if(!f) cout<<-1;
else{
for(auto x:v) cout<<x<<endl;
}
}
TIME;
return 0;
} | #include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
lli digits(lli n)
{
lli cnt = 0;
while(n)
{
cnt++;
n = n / 10;
}
return cnt;
}
int main()
{
lli i,j,t,n,sum,m,x1,x2,y1,y2,ans,num,a,b,c,d,cnt = 0,l,odd=0,even=0,diff,x,mini,k,maxi,y;
cin >> n;
for(i=1;;i++)
{
if(stoll(to_string(i) + to_string(i)) > n)
{
cout << i - 1;
break;
}
}
return 0;
} |
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ll n;
cin >> n;
vector<pair<int, int> > v;
for (int i = 0; i < n; i++)
{
ll x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
vector<pair<int, int> >::iterator it;
ll result = 0;
for (it = v.begin(); it != v.end(); it++)
{
ll n = it->second - it->first + 1;
ll sum = n * (it->first + it->second) / 2;
result += sum;
}
cout << result << endl;
} | // JG GAP GG
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<unordered_map>
#include<iomanip>
#include<queue>
#include<bitset>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1000000007;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];
#define forr(a,b) for(ll i=a;i<b;i++);
#define vecsort(myVec,x,y) sort(myVec.begin(),myVec.end(),[](const vector<y> &alpha,const vector<y> &beta){return alpha[x] < beta[x];});
#define vsort(v) sort(v.begin(),v.end());
#define vdownsort(v) sort(v.begin(),v.end(),greater<ll>());
ll modpow(ll a, ll n, ll mod)
{
ll res = 1;
while (0 < n)
{
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main()
{
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
ll ans = 0;
ll a, b;
for (ll i = 0; i < n; i++)
{
cin >> a >> b;
ans += (a + b) * (b - a + 1) / 2;
}
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int n , m;
bool palindrome(string s) {
string t = s;
reverse(s.begin() , s.end());
return s == t;
}
void solve(int testCase){
string s;
cin >> s;
for(int i = 0 ; i < 100 ; i ++) {
if(palindrome(s)) {
printf("Yes\n");
return;
}
s = "0" + s;
}
printf("No\n");
}
main(){
int t = 1;
// scanf("%d" , &t);
for(int testCase = 1 ; testCase <= t ; testCase ++){
solve(testCase);
}
return 0;
}
| //#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
ll num[524310];
bool kazu[524310];
const int ma = (1 << 19) - 1;
int k;
void add(ll n) {
int n2 = (n & ma) + 1;
while (num[n2]) {
if (num[n2] == n + 1) {
kazu[n2] = !kazu[n2];
k += (kazu[n2] * 2) - 1;
return;
}
n2 = n2 * 2 % 524309;
}
num[n2] = n + 1;
kazu[n2] = 1;
k++;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int T;
cin >> T;
rep(t, T) {
int N;
cin >> N;
if (N % 2) {
rep(i, N) {
int a;
cin >> a;
}
co("Second");
}
else {
int tmp = k;
rep(i, N) {
int a;
cin >> a;
add(a + 1000000000ll * t);
}
if (tmp == k) co("Second");
else co("First");
}
}
Would you please return 0;
} |
#include <bits/stdc++.h>
#define int long long
#define INF 9223372036854775806
#define cignore cin.ignore(numeric_limits<streamsize>::max(), '\n');
using namespace std;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s[n];
for(int i = 0; i < n; ++i)
cin >> s[i];
unordered_set<string> ust (s, s+n);
for(string ss: s)
{
if(ust.count('!'+ss))
{
cout << ss << '\n';
return 0;
}
}
cout << "satisfiable\n";
return 0;
}
| #include<bits/stdc++.h>
#define y1 y3647
#define earse erase
#define INF 1000000000
#define LL long long
using namespace std;
inline void read(int &x)
{
x=0;int f=1;
char ch=getchar();
while(ch!=45&&(ch>'9'||ch<'0'))ch=getchar();
if(ch==45){f=-1,ch=getchar();}
while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getchar();}
x*=f;
}
/*
*/
const int N=2e5+10;
int i,j,k,n,s,t,m;
char ch[N];
signed main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen(".ans","w",sdtout);
read(n);
scanf("%s",ch+1);
if(ch[1]!=ch[n])
{
printf("1\n");
return 0;
}
for(i=2;i<n;i++)
if(ch[i]!=ch[1]&&ch[i+1]!=ch[n])
{
printf("2\n");
return 0;
}
printf("-1\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
ll N; cin >> N;
unordered_set<ll> s;
for(ll a=2; a*a <= N; a++){
ll x = a*a;
while(x <= N){
s.insert(x);
x *= a;
}
}
ll ans = N - s.size();
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,i,m,ans;
cin>>n;
vector<long long> a;
i=2;
ans=0;
while (i*i<=n)
{
m=pow(i,2);
while (m<=n)
{
a.push_back(m);
m*=i;
}
i++;
}
sort(a.begin(),a.end());
/* for (i = 0; i < a.size(); i++) cout<<a[i]<<" ";
cout<<endl; */
if (a.size()>=1) ans=1;
for (i = 1; i < a.size(); i++)
{
if (a[i]!=a[i-1]) ans++;
}
cout<<n-ans<<endl;
} |
//Author: Xzirium
//Time and Date: 17:04:30 21 March 2021
//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
//Required Libraries
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//Required namespaces
using namespace std;
using namespace __gnu_pbds;
//Required defines
#define endl '\n'
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)
//Required typedefs
template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//Required Constants
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;
// Required random number generators
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
//Required Functions
ll power(ll b, ll e)
{
ll r = 1ll;
for(; e > 0; e /= 2, (b *= b) %= MOD)
if(e % 2) (r *= b) %= MOD;
return r;
}
ll modInverse(ll a)
{
return power(a,MOD-2);
}
//Work
int main()
{
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r"))
{
freopen ("INPUT.txt" , "r" , stdin);
//freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t clk;
clk = clock();
//-----------------------------------------------------------------------------------------------------------//
READV(N);
ll lpf[N+1]={0};
FORI(i,2,N+1)
{
if(lpf[i]==0)
{
lpf[i]=i;
for (ll j = 2; i*j <= N; j++)
{
if(lpf[i*j]==0)
{
lpf[i*j]=i;
}
}
}
}
ll ans[N+1]={0};
ans[1]=1;
FORI(i,2,N+1)
{
ans[i]=ans[i/lpf[i]]+1;
}
FORI(i,1,N+1)
{
cout<<ans[i]<<" ";
}
cout<<endl;
//-----------------------------------------------------------------------------------------------------------//
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
return 0;
} | //Making love with his ego Ziggy sucked up into his mind
#include<bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define ff first
#define ss second
#define ter(x) cerr << #x << " = " << x << endl
typedef long long ll;
typedef pair<ll,ll> ii;
const int N=1e5+100;
int mm[N];
int here[N];
int main(){
int n;cin>>n;
int mx=1;
mm[1]=1;
for(int i=2;i<=n;i++){
here[1]=i;
for(int j=2;j*j<=i;j++)if(i%j==0){
here[mm[j]]=i;
here[mm[i/j]]=i;
}
int j=1;
while(here[j]==i)j++;
mm[i]=j;
mx=max(mx,j);
}
for(int i=1;i<=n;i++)cout<<mm[i]<<" ";
cout<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
int h,w;
cin>>h>>w;
int arr[h*w+10];
int mn=mod;ll sum=0;
for(int i=0;i<h*w;i++)
{
cin>>arr[i];
mn=min(mn,arr[i]);
}
// cout<<mn<<" ";
for(int i=0;i<h*w;i++)
{
sum+=arr[i]-mn;
// cout<<arr[i]<<" ";
}
cout<<sum;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)
#define free(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define ub upper_bound
#define lb lower_bound
#define ld long double
#define bs binary_search
#define le length()
#define np(s) next_permutation(s.begin(),s.end())
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define unq(v) v.erase(unique(v.begin(),v.end()),v.end())
//1 1 1 2 2 2 to 1 2
const ll max_i=1e18+7;
const int dx[]={1,0,-1,0,-1,1,1,-1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const char dir[]={'R','D','L','U'};
const ll mod=1e12+7;
const ll N=1e5+1;
void solve()
{
int n,m;
cin>>n>>m;
char arr[n][m];
forn(i,n)
forn(j,m)
cin>>arr[i][j];
//up
ll ans=0;
forn(i,m){
forn(j,n)
{
if(arr[j][i]=='#')
{
if(arr[j-1][i]=='.' && !(arr[j-1][i+1]=='.' && arr[j][i+1]== '#'))
{
ans++;
}
}
}
}
//cout<<ans<<"\n";
//down
forn(i,m)
for(int j=n-1;j>=0;j--)
{
if(arr[j][i]=='#')
{
if(arr[j+1][i]=='.' && !(arr[j+1][i+1]=='.' && arr[j][i+1]== '#'))
{
ans++;
}
}
}
//cout<<ans<<"\n";
//left
forn(i,n)
forn(j,m)
{
if(arr[i][j]=='#')
{
if(arr[i][j-1]=='.' && !(arr[i-1][j-1]=='.' && arr[i-1][j]== '#'))
{
ans++;
}
}
}
//cout<<ans<<"\n";
//right
forn(i,n){
for(int j=m-1;j>=0;j--)
{
if(arr[i][j]=='#')
{
if(arr[i][j+1]=='.' && !(arr[i-1][j+1]=='.' && arr[i-1][j]== '#'))
{
ans++;
}
}
}
}
cout<<ans<<"\n";
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input1.txt", "r",stdin);
freopen("output1.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}
//unordered_map
//unordered_set
//find
//insert
//cout<<fixed<<setprecision(9)<<x; |
#include<bits/stdc++.h>
using namespace std;
int main(){
string S; cin >> S;
int ans = 0;
for(int i=0; i<=9999; i++){
vector<bool> flag(10);
int X = i;
for(int j=0; j<4; j++){
flag[X%10] = true;
X /= 10;
}
bool flag2 = true;
for(int j=0; j<10; j++){
if(S[j]=='o' && !flag[j]) flag2 = false;
if(S[j]=='x' && flag[j]) flag2 = false;
}
ans += flag2;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
const int MX = 87;
ll n, f[MX];
vi v;
int main () {
ios_base::sync_with_stdio(0); cin.tie(0);
f[0] = f[1] = 1;
for (int i = 2; i < MX; i++)
f[i] = f[i - 1] + f[i - 2];
cin >> n;
int cn = 0;
for (int i = MX - 1; i >= 0; i--) {
if (f[i] <= n) {
v.pb(1);
cn++;
n -= f[i];
} else if (cn) {
v.pb(0);
}
}
int f = v.size() & 1;
v.pop_back();
cout << v.size() + cn << endl;
for (int x : v) {
if (x) {
if (f) cout << 1 << endl;
else cout << 2 << endl;
}
if (f) cout << 4 << endl;
else cout << 3 << endl;
f = 1 - f;
}
return 0;
}
|
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}
int main(){
vector<ll> vec(4);
in(vec);
ll sum=0,sum2=0;
rep(i,4){
sum+=vec[i];
}
bool ans=false;
for(int i=0;i<(1<<4);i++){
sum2=0;
rep(j,4){
if(i&(1<<j))sum2+=vec[j];
}
if(sum2==sum-sum2){
ans=true;
break;
}
}
Yes(ans);
} | #include<bits/stdc++.h>
using namespace std;
void solve();
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
solve();
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}
void solve()
{
int arr[4];
for (int i = 0; i < 4; i++) {
cin >> arr[i];
}
sort(arr, arr + 4);
int sp[6] {};
int k = 0;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
sp[k] = arr[i] + arr[j];
k++;
}
}
sort(sp, sp + 6);
for (int i = 0; i < 5; i++) {
if (sp[i] == sp[i + 1]) {
cout << "Yes";
return;
}
}
int st[4];
st[0] = arr[0] + arr[1] + arr[2];
st[1] = arr[1] + arr[2] + arr[3];
st[2] = arr[2] + arr[3] + arr[0];
st[3] = arr[3] + arr[0] + arr[1];
if (st[0] == arr[3]) {
cout << "Yes";
return;
}
else if (st[1] == arr[0]) {
cout << "Yes";
return;
}
else if (st[2] == arr[1]) {
cout << "Yes";
return;
}
else if (st[3] == arr[2]) {
cout << "Yes";
return;
}
cout << "No";
return;
} |
# include<bits/stdc++.h>
using namespace std;
# define l long long
# define db double
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ' ' << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
#ifdef KRISHNAN_DEBUG
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
const bool MULTIPLE_TEST_CASES = false;
const l MOD=1e9+7;
const l N=1e5+5;
const l INF=1e12;
l H,W,A,B;
void cnt(vector<vector<bool> > &visited, l A_rem, l B_rem, l &ans) {
if(A_rem<0 || B_rem<0) {
return;
}
if(A_rem==0 && B_rem==0) {
ans++;
return;
}
bool found = false;
l i=-1,j=-1;
for(l x=0;x<H;x++) {
for(l y=0;y<W;y++) {
if(visited[x][y]==false) {
i=x;
j=y;
found = true;
break;
}
}
if(found) {
break;
}
}
if(i==-1 || j==-1) {
return;
}
dbg(i,j);
visited[i][j]=true;
cnt(visited, A_rem, B_rem-1,ans);
if(i+1<H && visited[i+1][j]==false) {
visited[i+1][j]=true;
cnt(visited, A_rem-1, B_rem,ans);
visited[i+1][j]=false;
}
if(j+1<W && visited[i][j+1]==false) {
visited[i][j+1]=true;
cnt(visited, A_rem-1, B_rem,ans);
visited[i][j+1]=false;
}
visited[i][j] = false;
}
void solve() {
cin>>H>>W>>A>>B;
vector<vector<bool> > visited(H, vector<bool>(W, false));
l ans = 0;
cnt(visited, A, B, ans);
cout<<ans<<"\n";
return;
}
int main(){
io;
int t=1;
if (MULTIPLE_TEST_CASES) cin>>t;
rep(i,0,t) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
/* #include <atcoder/all> */
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
using namespace std;
/* using namespace atcoder; */
using ll = long long;
using P = pair<int, int>;
const ll INF = 1 << 30;
template<class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
struct Data {
int to;
ll cost;
};
int main() {
int n, m;
cin >> n >> m;
vector<ll> dist(n, INF);
vector<vector<ll>> G2(n, vector<ll>(n, INF));
vector<vector<Data>> G(n, vector<Data>());
rep(i, m) {
int a, b;
ll c;
cin >> a >> b >> c;
a--;
b--;
if (a == b) {
chmin(dist.at(a), c);
} else {
// chmin(G2.at(a).at(b), c);
Data d = {b, c};
G.at(a).push_back(d);
}
}
// vector<vector<Data>> G(n, vector<Data>());
rep(i, n) {
rep(j, n) {
if (i == j) continue;
}
}
vector<vector<ll>> dist2(n, vector<ll>(n, INF));
rep(i, n) {
vector<ll> dist3(n, INF);
dist3.at(i) = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>,
greater<pair<ll, int>>> que;
que.push(make_pair(dist3.at(i), i));
while (!que.empty()) {
int v = que.top().second;
ll d = que.top().first;
que.pop();
if (d > dist3.at(v)) continue;
for (auto e : G.at(v)) {
if (e.to == i) {
continue;
}
if (chmin(dist3.at(e.to), dist3.at(v) + e.cost)) {
que.push(make_pair(dist3.at(e.to), e.to));
}
}
}
rep(j, n) {
// cerr << dist3.at(j) << " ";
dist2.at(i).at(j) = dist3.at(j);
}
// cerr << endl;
}
rep(i, n) {
rep(j, n) {
if (i == j) continue;
dist.at(i) = min(dist.at(i), dist2.at(i).at(j) + dist2.at(j).at(i));
}
}
rep(i, n) {
cout << ((dist.at(i) == INF) ? -1 : dist.at(i)) << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif
namespace templates{
ll modpow(ll x, ll b,ll mod=MOD){
ll res = 1;
while(b){
if(b&1)res = res * x % mod;
x = x * x % mod;
b>>=1;
}
return res;
}
ll modinv(ll x){
return modpow(x, MOD-2);
}
bool was_output = false;
template<class t>
void output(t a){
if(was_output)cout << " ";
cout << a;
was_output = true;
}
void outendl(){
was_output = false;
cout << endl;
}
ll in(){
ll res;
cin >> res;
return res;
}
template<class t>
istream& operator>>(istream&is, vector<t>&x){
for(auto &i:x)is >> i;
return is;
}
template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
is >> x.first >> x.second;
return is;
}
template<class t>
t in(){
t res; cin >> res; return res;
}
template<class t>
void out(t x){
cout << x;
}
template<class t>
vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
sort(line.begin(),line.end(),comp);
return line;
}
template<class t>
vector<t> reversed(vector<t> line){
reverse(line.begin(),line.end());
return line;
}
}
using namespace templates;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n = in();
int m = in();
vector<int> A(m);
vector<int> B(m);
rep(i,m){
A[i] = in()-1;
B[i] = in()-1;
}
int k = in();
vvector<int> C(k,vector<int>(2));
rep(i,k){
rep(j,2){
C[i][j] = in()-1;
}
}
method(func,int,int use){
vector<int> has(n,false);
rep(i,k){
has[C[i][(bit(i)&use) != 0]] = true;
}
int res = 0;
rep(i,m){
if(has[A[i]] and has[B[i]])++res;
}
return res;
};
int ans = 0;
rep(i,bit(k)){
chmax(ans,func(i));
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long N;
cin >> N;
unsigned long long at = -1, bt = -1, ct = -1;
unsigned long long sum = 1ll << 63;
for (unsigned long long b = 0; b < 63; b++) {
unsigned long long a = N / (1ll << b);
unsigned long long c = N % (1ll << b);
if (a + b + c <= sum) {
at = a;
bt = b;
ct = c;
sum = a + b + c;
}
}
cout << sum << endl;
return 0;
} |
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template <uint M>
struct modint {
uint val;
public:
static modint raw(int v) { modint x; x.val = v; return x; }
modint() : val(0) {}
template <class T>
modint(T v) { ll x = (ll)(v%(ll)(M)); if (x < 0) x += M; val = uint(x); }
modint(bool v) { val = ((unsigned int)(v) % M); }
modint& operator++() { val++; if (val == M) val = 0; return *this; }
modint& operator--() { if (val == 0) val = M; val--; return *this; }
modint operator++(int) { modint result = *this; ++*this; return result; }
modint operator--(int) { modint result = *this; --*this; return result; }
modint& operator+=(const modint& b) { val += b.val; if (val >= M) val -= M; return *this; }
modint& operator-=(const modint& b) { val -= b.val; if (val >= M) val += M; return *this; }
modint& operator*=(const modint& b) { ull z = val; z *= b.val; val = (uint)(z % M); return *this; }
modint& operator/=(const modint& b) { return *this = *this * b.inv(); }
modint operator+() const { return *this; }
modint operator-() const { return modint() - *this; }
modint pow(long long n) const { modint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
modint inv() const { return pow(M-2); }
friend modint operator+(const modint& a, const modint& b) { return modint(a) += b; }
friend modint operator-(const modint& a, const modint& b) { return modint(a) -= b; }
friend modint operator*(const modint& a, const modint& b) { return modint(a) *= b; }
friend modint operator/(const modint& a, const modint& b) { return modint(a) /= b; }
friend bool operator==(const modint& a, const modint& b) { return a.val == b.val; }
friend bool operator!=(const modint& a, const modint& b) { return a.val != b.val; }
};
using mint = modint<MOD>;
template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }
template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }
template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }
mint cnt[3000];
int main() {
int n;
cin >> n;
vector<ll> A(n);
for (auto &&i : A) scanf("%lld", &i);
vector<ll> S(n+1);
for (int i = 0; i < n; ++i) {
S[i+1] = S[i] + A[i];
}
auto dp = make_v(n+1, n+1, mint(0));
dp[0][0] = 1;
mint ans = 0;
for (int i = 1; i <= n; ++i) {
fill_n(cnt, 3000, mint(0));
for (int j = 0; j <= n; ++j) {
dp[i][j] += cnt[S[j]%i];
cnt[S[j]%i] += dp[i-1][j];
}
ans += dp[i].back();
}
cout << ans.val << "\n";
return 0;
} | // This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define mem(x,y) memset(x,y,sizeof x)
#define sz(x) (int)(x).size()
#define ln std::puts("")
#define lsp std::putchar(32)
#define pb push_back
#define MP std::make_pair
#ifdef _LOCAL_
#define dbg(x) std::cerr<<__func__<<"\tLine:"<<__LINE__<<' '<<#x<<": "<<x<<"\n"
#define dprintf(x...) std::fprintf(stderr,x)
#else
#define dbg(x) 42
#define dprintf(x...) 42
#endif
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
template <class t> inline void read(t &s){s=0;
reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;}
template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);}
template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x;
int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0;
while(top)putchar(buf[top--]^'0');return;}
inline void setIn(std::string s){freopen(s.c_str(),"r",stdin);return;}
inline void setOut(std::string s){freopen(s.c_str(),"w",stdout);return;}
inline void setIO(std::string s=""){setIn(s+".in");setOut(s+".out");return;}
template <class t>inline bool ckmin(t&x,t y){if(x>y){x=y;return 1;}return 0;}
template <class t>inline bool ckmax(t&x,t y){if(x<y){x=y;return 1;}return 0;}
inline int lowbit(int x){return x&(-x);}
const int MaxN=3050;
const int p=1e9+7;
int a[MaxN],f[MaxN][MaxN],s[MaxN],n;
int w[MaxN][MaxN];
inline void add(int &x,int y){(x+=y)>=p&&(x-=p);}
signed main(void)
{
read(n);
for(int i=1;i<=n;++i)read(a[i]),s[i]=s[i-1]+a[i];
f[0][0]=1,w[1][0]=1;
for(int i=1;i<=n;++i)
{
for(int j=1;j<=i;++j)
add(f[i][j],w[j][s[i]%j]);
if(i<n)
for(int j=0;j<=i;++j)
add(w[j+1][s[i]%(j+1)],f[i][j]);
}
reg int ans=0;
for(int i=1;i<=n;++i)add(ans,f[n][i]);
write(ans),ln;
return 0;
}
/*
* Check List:
* 1. Input / Output File (OI)
* 2. long long
* 3. Special Test such as n=1
* 4. Array Size
* 5. Memory Limit (OI) int is 4 and longlong is 8
* 6. Mod (a*b%p*c%p not a*b*c%p , (a-b+p)%p not a-b )
* 7. Name ( int k; for(int k...))
* 8. more tests , (T=2 .. more)
* 9. blank \n after a case
*/
|
#include <bits/stdc++.h>
#include <limits.h>
#include <math.h>
#define mod 1000000007
#define pi 3.14159265
// sin((deg*pi)/180.0);
using namespace std;
long long int ans = 0;
// map<int,int> m;
vector<int> m(31,0);
vector<vector<int>> dx;
vector<bool> vis(31,true);
void rec(int i,vector<int> cnt,vector<int> x)
{
if(i==31)
{
bool ok = true;
for(int z=0;z<10;z++)
{
if(cnt[z]>1)
{
ok = false;
}
}
if(ok)
{
long long int ll = 1;
bool llzx = false;
for(int z=0;z<x.size();z++)
{
if(m[x[z]]>0)
{
// cout<<x[z]<<" "<<m[x[z]]<<" ";
llzx = true;
}
ll*=m[x[z]];
}
if(llzx)
{
ans+=ll;
}
}
return ;
}
if(vis[i]==true && m[i]>0)
{
for(int k=0;k<10;k++)
{
cnt[k]+=dx[i][k];
}
x.push_back(i);
rec(i+1,cnt,x);
x.pop_back();
for(int k=0;k<10;k++)
{
cnt[k]-=dx[i][k];
}
rec(i+1,cnt,x);
}
else
{
rec(i+1,cnt,x);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double n;
cin>>n;
double price = 1.08*(double(n));
price = floor(price);
if(price>206)
{
cout<<":("<<endl;
}
else if(price==206)
{
cout<<"so-so"<<endl;
}
else
{
cout<<"Yay!"<<endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 200005
int a[maxn];
double n;
signed main()
{
cin>>n;
n*=1.08;
n=floor(n);
if(n<206) puts("Yay!");
if(n==206) puts("so-so");
if(n>206) puts(":(");
return 0;
} |
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>b>>a;
int c=a+b;
if(c>=15&&a>=8)
cout<<1;
else if(c>=10&&a>=3)
cout<<2;
else if (c>=3)
cout<<3;
else
cout<<4;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
int main() {
int n, m;
cin >> n >> m;
if (n == 1) {
cout << ((m == 0) ? "1 2\n" : "-1") << endl;
return 0;
}
if (m < 0 || m > n - 2) {
cout << -1 << endl;
return 0;
}
ll p = 2;
rep(i, m + 1) {
printf("%ld %ld\n", p, p + 1);
p += 2;
}
printf("1 %ld\n", p);
p++;
rep(i, n - m - 2) {
printf("%ld %ld\n", p, p + 1);
p += 2;
}
}
|
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <stdio.h>
#include <stack>
#include <queue>
#include <list>
#include <sstream>
#include <utility>
#include <cctype>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <map>
#include <fstream>
using namespace std;
const long long MOD = 1e9 +7;
const long long MODZ = 998244353;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
uint64_t a,b,c;
cin >> a >> b >> c;
uint64_t sum = 0;
// uint64_t firstterm = (double)(((a % MODZ) * ((a+1)% MODZ )) % MODZ) /2.0;
// uint64_t secterm = (double)(((b % MODZ) *((b+1)% MODZ )) % MODZ) /2.0;
// uint64_t thirdterm = (double)(((c % MODZ) *((c+1)% MODZ )) % MODZ) /2.0;
uint64_t firstterm = ((a*(a+1)) /2) % MODZ;
uint64_t secterm = ((b*(b+1)) /2) % MODZ;
uint64_t thirdterm = ((c*(c+1)) /2) % MODZ;
//sum = ((firstterm % MODZ) * (secterm % MODZ) * (thirdterm % MODZ)) % MODZ;
//sum = firstterm * secterm * thirdterm;
sum = firstterm * secterm % MODZ * thirdterm % MODZ;
// sum = (a * (a+1) * b * (b+1) * c * (c+1))/8 % MODZ;
// for(long long i = 1; i<= a; ++i)
// {
// for(long long j = 1; j <= b; ++j)
// {
// for(long long k = 1; k <= c; ++k)
// {
// sum = (sum % MODZ) + (((i % MODZ) *(j % MODZ) *(k % MODZ)) % MODZ) % MODZ ;
// }
// }
// }
cout << sum;
}
| #include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&...tail) {
cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 998244353LL;
//from http://noshi91.hatenablog.com/entry/2019/03/31/174006
template <std::uint_fast64_t Modulus>
class modint {
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
constexpr u64 &value() noexcept { return a; }
constexpr const u64 &value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint operator^(const u64 rhs) const noexcept {
return modint(*this) ^= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
constexpr modint &operator^=(u64 exp) {
modint rhs = modint(*this);
a = 1;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
friend ostream &operator<<(ostream &os, const modint &x) {
os << x.a;
return os;
}
friend istream &operator>>(istream &is, modint &x) {
is >> x.a;
return is;
}
};
using mint = modint<MOD>;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
mint a, b, c;
cin >> a >> b >> c;
mint res = a * (a + 1) * b * (b + 1) * c * (c + 1) / mint(8);
cout << res << newl;
}
|
#include <bits/stdc++.h>
using namespace std;
int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; }
int __fastio = fastio();
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long ll;
typedef pair<ll, ll> ii;
#define fi first
#define se second
#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
int main(){
string s;
cin >> s;
while(s.size() && s.back() == '0') s.pop_back();
int lo = 0, hi = s.size()-1;
while(lo<hi) {
if(s[lo++] != s[hi--]) {
cout << "No";
return 0;
}
}
cout << "Yes";
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)
#define Rep(i,s,n) for(int i = n; i >= (int)(s); i--)
int n, x[3030][5];
int getmask(int i, int lim) {
int res = 0;
rep(j, 0, 5) if (lim <= x[i][j]) res += 1 << j;
return res;
}
bool check(int lim) {
vector<int>cnt(1 << 5, 0);
rep(i, 0, n) cnt[getmask(i, lim)]++;
rep(m1, 0, 1 << 5) rep(m2, 0, 1 << 5) rep(m3, 0, 1 << 5) {
if ((m1 | m2 | m3) == (1 << 5) - 1 && cnt[m1] && cnt[m2] && cnt[m3]) return 1;
}
return 0;
}
int main() {
cin >> n;
rep(i, 0, n) rep(j, 0, 5) cin >> x[i][j];
int ok = 0, ng = 1e9 + 1;
while (ng - ok != 1) {
int mid = (ok + ng) / 2;
if (check(mid)) ok = mid;
else ng = mid;
}
cout << ok << endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a) (a).begin(),(a).end()
ll ans = 0;
void Main(){
double sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
sy = -sy;
cout << fixed << setprecision(8) << sx - sy * (gx - sx) / (gy - sy) << endl;
}
int main(){
Main();
/*
東方風神録は神が出てくるので当然神ゲー
*/
return 0;
} | #include<bits/stdc++.h>
#define RT register
#define ll long long
#define ull unsigned long long
#define lowbit(x) (x&(-x))
using namespace std;
template<typename T>
inline void read(T &x){
x=0; bool f=0;char ch=getchar();
while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
x=f?-x:x;
}
template<typename T>
inline void print(T x){
if(x<0) x=-x,putchar('-');
if(x>9) print(x/10);
putchar(x%10+'0');
}
int x,y,z;
int main(){
read(x),read(y),read(z);
int m=y*z;
if(m%x==0) print(m/x-1);
else print(m/x);
return 0;
}
|
// |--------------------------------------------|
// | User - Kunal Kumar |
// |--------------------------------------------|
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define pf push_front
#define ppf pop_front
#define pii pair<int,int>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define ulli unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vulli vector<ulli>
#define vb vector<bool>
#define vpii vector<pii>
#define vpll vector<pll>
#define mod 1000000007
#define F first
#define S second
#define NN 200001
#define modu 998244353
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define INF 1e18
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
#define endl "\n"
using namespace std;
int gcd(int a, int b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
//seive
bool prime_num[1000001];
void SOE(vector <int> &v)
{
int n = 1000000;
memset(prime_num, true, sizeof(prime_num));
for (int p = 2; p * p <= n; p++)
{
if (prime_num[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime_num[i] = false;
}
}
for (int p = 2; p <= n; p++)
if (prime_num[p])
v.pb(p);
}
bool binary_search(vector <int> v,int s, int e,int num)
{
while(s<=e)
{
int mid=(s+(e-s)/2);
if(v[mid]==num)
return true;
else
if(v[mid]>num)
e=mid-1;
else
s=mid+1;
}
return false;
}
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
ll modInverse(ll n,ll p)
{
return power(n, p - 2, p);
/*
ll inv[maxn],finv[maxn];
inv[1] =inv[0]= 1;
finv[0]=finv[1]=1;
for (int i=2; i<maxn; ++i)
inv[i] = (m - (m/i) * inv[m%i] % m) % m;
for (int i=2;i<maxn;++i){
finv[i]=(inv[i]%m * finv[i-1]%m)%m;
}
*/
}
ll factorial[200001];
ll nCr(ll n, ll r, ll p)
{
if (n < r)
return 0;
if (r == 0)
return 1;
return (factorial[n] * (modInverse(factorial[r], p) % p) * (modInverse(factorial[n - r], p) % p))% p;
}
void addEdge(vector <int> G[], int s, int e )
{
G[s].pb(e);
G[e].pb(s);
}
void solve()
{
ll n;
cin>>n;
vl A(n),B(n);
rep(i,0,n)
cin>>A[i];
rep(i,0,n)
cin>>B[i];
ll maxA = A[0], minB = B[0];
rep(i,1,n)
{
if(maxA<A[i])
maxA = A[i];
if(minB>B[i])
minB = B[i];
}
if(maxA>minB)
{
cout<<0;
return;
}
cout<<(minB-maxA+1);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
t=1;
//cin>>t;
while(t--)
{
solve();
}
}
// Keep Hustling!!!!!!!!!!! | // #MerinoNoMeRepresenta
#include<bits/stdc++.h>
#define fp(x,a,b) for(ll x=a; x<b; x++)
#define fn(x,a,b) for(int x=a; x>b; x--)
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
// #define tt third
#define print(x) for(auto it:x) cout<<it<<" ";
#define debug(x) cerr << #x << " is " << x << endl;
#define w(x) while(x--)
#define r(x) scanf("%d", &x)
#define rl(x) scanf("%ld", &x)
#define rll(x) scanf("%lld", &x)
typedef long long ll;
using namespace std;
template <typename TYPE> void readint(TYPE &x){
x=0; int f=1; char c;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=x*10+c-'0';
x*=f;
}
#define error(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
template<typename... T>
void read(T& ... args){
((cin >> args), ...);
}
template<typename... T>
void write(T ... args){
((cout << args << ' '), ...);
cout<<'\n';
}
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 3e3 + 5;
const char nl = '\n';
const int INF = 2e9;
int n, k;
//queue front back push pop
//stack top push pop
ll dp[MAX][MAX];
ll sol(int n, int k){
if (n < k) return 0LL;
if(dp[n][k] != -1) return dp[n][k];
if (n == k) return 1LL;
if(k == 0) return 0LL;
dp[n][k] = (sol(n - 1, k - 1) + sol(n, k * 2))%MOD1;
return dp[n][k];
//This belongs to Maestro_Koldo
}
void solve(){
read(n, k);
fp(i, 0, MAX) fp(j, 0, MAX) dp[i][j] = -1LL;
write(sol(n, k));
}
int main(){
cpu();
// int __;
// cin>>__;
// while(__--){
// solve();
// // cout << nl;
// }
solve();
// cout<<nl;
return 0;
} |
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <utility>
#include <climits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define mp make_pair
#define fr first
#define sc second
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define rep(s, i, n) for (int(i) = (s); (i) < (n); (i)++)
#define repe(s, i, n) for (int(i) = (s); (i) <= (n); (i)++)
#define rrep(s, i, n) for (int(i) = (s); (i) > (n); (i)--)
#define rrepe(s, i, n) for (int(i) = (s); (i) >= (n); (i)--)
#define allof(a) (a).begin(), (a).end()
int res=INT_MAX;
int n;
void cal(vi &a,int index,int xo){
if(n==index){
res=min(res,xo);
}
int nowor=0;
rep(index,i,n){
nowor|=a[i];
cal(a,i+1,xo^nowor);
}
}
int main(int argc, char const *argv[])
{
cin>>n;
vi a(n);
rep(0,i,n)cin>>a[i];
cal(a,0,0);
cout<<res<<endl;
return 0;
}
| #include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
ll to;
ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll COM(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
for (size_t i = 0; i < n; i++)
{
for (size_t j = 0; j < n; j++)
{
for (size_t k = 0; k < n; k++)
{
dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}
}
}
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
ll g = gcd(a, b);
return a / g * b;
}
ll mulMod(ll a, ll b)
{
return (((a % MOD) * (b % MOD)) % MOD);
}
ll powMod(ll a, ll p)
{
if (p == 0)
{
return 1;
}
else if (p % 2 == 0)
{
ll half = powMod(a, p / 2);
return mulMod(half, half);
}
else
{
return mulMod(powMod(a, p - 1), a);
}
}
ll ceil(ll a, ll b)
{
return (a + b - 1) / b;
}
void solve(long long N, std::vector<long long> A)
{
ll ans = INF;
for (int bit = 0; bit < (1 << (N - 1)); bit++)
{
vector<ll> stock;
ll now = A[0];
for (int i = 0; i < N - 1; i++)
{
if (bit & (1 << i))
{
now = now | A[i + 1];
}
else
{
stock.push_back(now);
now = A[i + 1];
}
}
stock.push_back(now);
ll score = stock[0];
for (int i = 1; i < stock.size(); i++)
{
score ^= stock[i];
}
ans = min(ans, score);
}
cout << ans << endl;
}
int main()
{
long long N;
scanf("%lld", &N);
std::vector<long long> A(N);
for (int i = 0; i < N; i++)
{
scanf("%lld", &A[i]);
}
solve(N, std::move(A));
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
//using namespace __gnu_pbds;
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define ai(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define ao(arr) for(auto tengo_copyright:arr) cout<<tengo_copyright<<" ";
#define mi(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cin>>arr[i][j];}
#define mo(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<arr[i][j]<<" "; cout<<endl;}
#define ll long long
#define debug cout<<"I AM EXECUTING"<<endl
#define testcases int q_ves; cin>>q_ves; while(q_ves--)
#define vi vector<int>
#define vll vector<long long int>
#define vppo(prs) for(auto x:prs){cout<<x.first<<" "<<x.second<<endl;}
#define For(__,hajmola,adfdf) for(int __ = hajmola; __<adfdf;__++)
#define formax 1e18
#define formin -1e18
#define watch(x) cout << (#x) << " is " << (x) << endl
#define in(x) ll int x; cin>>x
#define stin(x) string x;cin>>x
//#define ordered_multiset tree<pair<ll int,ll int>, null_type, less<pair<ll int,ll int>>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define out1(a) cout<<a<<endl
#define out2(a,b) cout<<a<<"|"<<b<<endl
string sconvert(ll int n)
{
stringstream ss;
ss<<n;
string str = ss.str();
return str;
}
void single() {
in(n);
ll int sum=1e18,a=1,b=1,c=1,pot=0;
ll int res=0;
if (n==0){out1(0);return;}
while (1) {
b = pow(2,pot);
if(b>n)break;
a = n/b;
c = n % (a*b);
res = a+pot+c;
if (sum>res){sum=res;}
pot++;
}
out1(sum);
return;
}
void multiple()
{
testcases
{
single();
}
}
int main()
{
IOS;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
single();
}
//g++ -std=c++11 -O2 -Wall a.cpp -o a | #include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#pragma GCC optimize("Ofast")
using namespace std;
#define int long long
#define double long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ArrayFill(arr,a) memset(arr,a,sizeof arr)
#define endl '\n'
#define countBit(x) __builtin_popcountll(x)
#define all(x) x.begin() , x.end()
#define ln cout<<'\n';
using namespace std;
using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> oset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
int ceil(int a,int b){return (a+b-1)/b;}
#define sim template < class c
#define ris return * this
#define dor > debug_ & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug_&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug_ {~debug_() { cerr << endl; }eni(!=) cerr << boolalpha << i; ris; }eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d){*this << "[";for (auto it = d.b; it != d.e; ++it)*this << ", " + 2 * (it == d.b) << *it;ris << "]";}};
#define db(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define debug(x) debug_() << db(x)
int modulo(int a,int b,int c){
int x=1,y=a%c;
while(b > 0){
if(b%2 == 1)
x=(x*y)%c;
y = (y*y)%c;
b = b>>1;
}
return x%c;
}
const int mod = 1e9 + 7ll;
// const int mod = 998244353ll;
const int N = 5001;
const int inf = 1e10;
void solve(){
int n;
cin >> n;
int ans = n;
for(int i=0;i<=63;i++){
int x = (1ll<<i);
int c = i + n/x + n%x;
ans = min(ans,c);
}
cout << ans;
}
signed main(){
fast;
int tt{1};
// cin >> tt;
for(int ii=1;ii<=tt;ii++){
// cout << "Case #" << ii << ": ";
solve();
ln;
}
return 0;
} |
#include <iostream>
using namespace std;
int main(){
double value, currentValue;
double discount;
cin >> value;
cin >> currentValue;
discount = ((value - currentValue) / value)*100;
cout << discount;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,n) for(LL i=0;i<(n);i++)
int main()
{
double a, b;
cin >> a >> b;
b = a - b;
a = b/a;
a *= 100;
printf("%.10lf",a);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
/* ループ処理 0からnまで*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
int N;
cin >> N;
int sum = 0;
vector<int> av, bv;
rep(i, N)
{
int A;
cin >> A;
av.push_back(A);
}
rep(i, N)
{
int B;
cin >> B;
bv.push_back(B);
}
rep(i, N)
{
sum += av.at(i) * bv.at(i);
}
if (sum == 0)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return 0;
} | // dp[i][0] ---> no. of ways of x[0...i] to get y[i] = 0
// ---> decision on x[i]
// dp[i][1] ---> no. of ways of x[0...i] to get y[i] = 1
// ---> decision on x[i]
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int n; cin >> n;
vector<vector<ll>> dp(n+1, vector<ll>(2, 1));
for(int i = 1; i <= n; i++){
string s; cin >> s;
if(s == "AND"){
dp[i][0] = 2*dp[i-1][0] + dp[i-1][1];
dp[i][1] = dp[i-1][1];
}
else{
dp[i][0] = dp[i-1][0];
dp[i][1] = dp[i-1][0] + 2*dp[i-1][1];
}
}
cout << dp[n][1];
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, x;
cin >> n >> x;
rep(i,n){
int a;
cin >> a;
if(a != x) cout << a << ' ';
}
} | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+10;
int sz[MAXN];
int main() {
int n, x;
cin >> n >> x;
for(int i=0; i<n; i++) {
cin >> sz[i];
}
for(int i=0; i<n; i++) {
if(sz[i]!=x){
cout << sz[i] << " ";
}
}
cout << endl;
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
ll n;cin>>n;
ll a=1e18,b=-1e18,c=0;
rep(i,n){
ll x,t;cin>>x>>t;
if(t==1){
b+=x;
a+=x;
c+=x;
}else if(t==2){
chmax(b,x);
chmax(a,x);
}else{
chmin(a,x);
chmin(b,x);
}
}
ll q;cin>>q;
rep(i,q){
ll x;cin>>x;
ll res=min(max(c+x,b),a);
cout<<res<<endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define MOD 1000000007
#define MAXN 1000001
#define MODA 998244353
#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
const ll INF = numeric_limits<ll>::max() / 4;
ll power(ll a,ll b){
ll result=1;
while(b>0){
int lastbit=(b&1);
if(lastbit){
result=(result*a);
}
a=(a*a);
b=b>>1;
}
return result;
}
ll power2(ll a,ll b,ll p){
ll result=1;
while(b>0){
int lastbit=(b&1);
if(lastbit){
result=(result*a)%p;
}
a=(a*a)%p;
b=b>>1;
}
return result%p;
}
ll gcd(ll a, ll b){
if (b == 0)
return a;
return gcd(b, a % b);
}
vector<ll> Sieve(int n){
bool prime[n+1];
memset(prime, true, sizeof(prime));
for (int p=2; p*p<=n; p++){
if (prime[p] == true){
for (int i=p*p; i<=n; i += p)
prime[i] = false;
}
}
vector<ll>v;
for (int p=2; p<=n; p++)
if (prime[p]) v.pb(p);
return v;
}
vector<ll> SeiveOfEratosthenes(int n){
vector<ll>v(n+1,0);
for(int i=0;i<=n;i++){
v[i]=i;
}
for (int p=2; (p*p)<=n; p++){
if (v[p] == p){
v[p]=p;
for (int i=p*p; i<=n; i += p) {
v[i] = p;
}
}
}
return v;
}
vector<ll> SmallestPrimeFactors(int n){
vector<ll>spf(n+1,0);
spf[1] = 1;
for (int i=2; i<=n; i++){
spf[i] = i;
}
for (int i=4; i<=n; i+=2){
spf[i] = 2;
}
for (int i=3; (i*i)<=n; i++){
if (spf[i] == i){
for (int j=i*i; j<MAXN; j+=i) {
if (spf[j] == j){
spf[j] = i;
}
}
}
}
return spf;
}
void shortest(map<int,vector<pair<int,ll>>>m,int src,int n,ll *dist){
bool visited[n+1];
set<pair<ll,int>>s;
for(int i=0;i<=n;i++){
dist[i]=-1;
visited[i]=false;
}
s.insert(mp(0ll,src));
dist[src]=0;
while(!s.empty()){
auto t=s.begin();
ll dis=(*t).F;
int u=(*t).S;
s.erase(t);
if(visited[u]){
continue;
}
visited[u]=true;
for(auto tt:m[u]){
int v=tt.F;
ll w=tt.S;
if(!visited[v]){
if(dist[v]!=-1 && dist[v]>dis+w){
s.erase(mp(dist[v],v));
dist[v]=dis+w;
s.insert(mp(dist[v],v));
}else if(dist[v]==-1){
dist[v]=dis+w;
s.insert(mp(dist[v],v));
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int ttttt=1;
// cin>>ttttt;
for(int tttt=1;tttt<=ttttt;tttt++){
int n;
cin>>n;
ll a=0,b=-INF,c=INF;
for(int i=0;i<n;i++){
ll A,t;
cin>>A>>t;
if(t==1){
a+=A;
b+=A;
c+=A;
}else if(t==2){
b=max(b,A);
c=max(c,A);
}else{
c=min(A,c);
b=min(A,b);
}
}
ll q;
cin>>q;
while(q--){
ll x;
cin>>x;
cout<<min(c,max(b,x+a))<<endl;
}
cout<<endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int a,b,c;
cin >>a>>b>>c;
int ans=0;
ans = max(a+b,ans);
ans = max(a+c,ans);
ans = max(b+c,ans);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int n, q, flip = 0;
string s;
cin >> n >> s >> q;
while (q --)
{
int t, a, b;
cin >> t;
cin >> a >> b;
a --;
b --;
if (t == 2)
flip = 1 - flip;
else
{
if (flip)
{
if (a >= n)
a -= n;
else
a += n;
if (b >= n)
b -= n;
else
b += n;
}
swap(s[a], s[b]);
}
}
if (flip)
{
for (int i = 0; i < n; ++i)
{
swap(s[i], s[i + n]);
}
}
cout << s << '\n';
return 0;
} |
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int, int> i_i;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = numeric_limits<ll>::max() / 4;
const ll MOD = 1e9+7;
// using mint = atcoder::modint1000000007;
void chmin(ll& a, ll b){ if(a > b) a = b; }
void chmax(ll& a, ll b){ if(a < b) a = b; }
#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)
template <typename T>
struct RMQ {
using Func = function<T(T, T)>;
const T e;
int n;
Func fx;
// node 0<=i<n-1 n-1<=i 葉
vector<T> node, lazy;
RMQ(int n_, T e_, Func func) : n(), e(e_), fx(func), node(n_ * 4, e), lazy(n_ * 4, e) {
int x = 1;
while (n_ > x)
x *= 2;
n = x;
}
void set(int i, T x) { node[i + n - 1] = x; }
void build() {
for (int k = n - 2; k >= 0;k--) {
node[k] = fx(node[2*k+1], node[2*k+2]);
}
}
/* lazy eval */
void eval(int k) {
if (lazy[k] == e) return; // 更新するものが無ければ終了
if (k < n - 1) { // 葉でなければ子に伝搬
lazy[k * 2 + 1] = lazy[k];
lazy[k * 2 + 2] = lazy[k];
}
// 自身を更新
node[k] = lazy[k];
lazy[k] = e;
}
void update(int a, int b, T x, int k, int l, int r) {
eval(k);
if (a <= l && r <= b) { // 完全に内側の時
lazy[k] = x;
eval(k);
} else if (a < r && l < b) { // 一部区間が被る時
update(a, b, x, k * 2 + 1, l, (l + r) / 2); // 左の子
update(a, b, x, k * 2 + 2, (l + r) / 2, r); // 右の子
node[k] = fx(node[k * 2 + 1], node[k * 2 + 2]);
}
}
void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
T query_sub(int a, int b, int k, int l, int r) {
eval(k);
if (r <= a || b <= l) { // 完全に外側の時
return e;
} else if (a <= l && r <= b) { // 完全に内側の時
return node[k];
} else { // 一部区間が被る時
T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
return fx(vl, vr);
}
}
T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
/* debug */
inline T operator[](int a) { return query(a, a + 1); }
void print() {
for (int i = 0; i < 2 * n - 1; ++i) {
cout << (*this)[i];
if (i != n) cout << ",";
}
cout << endl;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, Q;
cin >> N;
ll a[N], t[N];
rep(i,0,N) cin >> a[i] >> t[i];
cin >> Q;
ll x[Q];
rep(i,0,Q) cin >> x[i];
ll low = -INF, high = INF, add = 0;
for (ll i = 0;i < N;i++) {
// if (t[i] == 1) {
// high += a[i];
// low += a[i];
// add += a[i];
// }
// if (t[i] == 2) {
// chmax(low, a[i]);
// chmax(high, a[i]);
// }
// if (t[i] == 3) {
// chmin(high, a[i]);
// chmin(low, a[i]);
// }
if(t[i] == 1){
low += a[i];
high += a[i];
add += a[i];
}
else if(t[i] == 2){
chmax(low, a[i]);
chmax(high, a[i]);
}
else{
chmin(low, a[i]);
chmin(high, a[i]);
}
}
for (ll i = 0;i < Q;i++) {
cout << min(max(low, x[i]+add), high) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
return s;
}
template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
s << "[ "; cout << c.fi << " , " << c.se << " ] ";
return s;
}
const int maxn = 123;
int n;
int a[maxn];
int out[12345][maxn];
string s;
void input()
{
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
++n;
cin >> s;
F1 (i, n) cin >> a[i];
}
void solve()
{
int ans = 12345;
F1 (i, n - 1) ans = min(ans, abs(a[i] - a[i + 1]));
int mn = a[1], cur = 1;
F1 (i, n) if (a[i] < mn) mn = a[i], cur = i;
for (int i = 1; i <= ans; ++i)
out[i][cur] = a[cur] / ans;
for (int i = 1; i <= a[cur] % ans; ++i)
++out[i][cur];
for (int i = cur - 1; i >= 1; --i)
{
if (a[i] < a[i + 1])
{
F1 (j, ans) out[j][i] = out[j][i + 1] - 1;
priority_queue<pii> p;
F1 (j, ans) p.push(mp(out[j][i], j));
F (j, a[i + 1] - a[i] - ans)
{
--out[p.top().se][i];
p.push(mp(out[p.top().se][i], p.top().se));
p.pop();
}
} else
{
F1 (j, ans) out[j][i] = out[j][i + 1] + 1;
priority_queue<pii, vector<pii>, greater<pii>> p;
F1 (j, ans) p.push(mp(out[j][i], j));
F (j, a[i] - a[i + 1] - ans)
{
++out[p.top().se][i];
p.push(mp(out[p.top().se][i], p.top().se));
p.pop();
}
}
}
for (int i = cur + 1; i <= n; ++i)
{
if (a[i] < a[i - 1])
{
F1 (j, ans) out[j][i] = out[j][i - 1] - 1;
priority_queue<pii> p;
F1 (j, ans) p.push(mp(out[j][i], j));
//dbg(p.top());
F (j, a[i - 1] - a[i] - ans)
{
--out[p.top().se][i];
p.push(mp(out[p.top().se][i], p.top().se));
p.pop();
}
} else
{
//MEOW
F1 (j, ans) out[j][i] = out[j][i - 1] + 1;
priority_queue<pii, vector<pii>, greater<pii>> p;
//dbg(ans);
F1 (j, ans) p.push(mp(out[j][i], j));
//dbg(p.top());
F (j, a[i] - a[i - 1] - ans)
{
++out[p.top().se][i];
p.push(mp(out[p.top().se][i], p.top().se));
p.pop();
}
}
}
cout << ans << '\n';
F1 (i, ans)
{
F1 (j, n) cout << out[i][j] << ' ';
cout << '\n';
}
}
main()
{
input();
solve();
}
|
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define PI 2*acos(0.0)
const int mod = 1e9 + 7;
const int sz = 1e7;
#define all(x) x.begin(),x.end()
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) (x/gcd(x,y))*y
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n, m;
int main()
{
optimize();
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t, a, b, c, d, l, x, y, u, v, cn = 0, cs = 1;
string str;
cin >> str;
for (int i = 0; i < str.size(); )
{
if (str[i] == 'Z' && str[i + 1] == 'O' && str[i + 2] == 'N' && str[i + 3] == 'e')
{
cn++;
i += 4;
}
else
i++;
}
cout << cn << endl;
} | #include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif
namespace templates{
ll modpow(ll x, ll b,ll mod=MOD){
ll res = 1;
while(b){
if(b&1)res = res * x % mod;
x = x * x % mod;
b>>=1;
}
return res;
}
ll modinv(ll x){
return modpow(x, MOD-2);
}
bool was_output = false;
template<class t>
void output(t a){
if(was_output)cout << " ";
cout << a;
was_output = true;
}
void outendl(){
was_output = false;
cout << endl;
}
template<class t>
istream& operator>>(istream&is, vector<t>&x){
for(auto &i:x)is >> i;
return is;
}
template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
is >> x.first >> x.second;
return is;
}
template<class t>
ostream& operator<<(ostream&os, vector<t> &v){
os << "{";
for(t &i:v){
os << i << ", ";
}
os << "}";
return os;
}
template<class t = long long>
t in(){
t res; cin >> res; return res;
}
template<class t>
void out(t x){
cout << x;
}
template<class t>
vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
sort(line.begin(),line.end(),comp);
return line;
}
template<class t>
vector<t> reversed(vector<t> line){
reverse(line.begin(),line.end());
return line;
}
string reversed(string str){
reverse(str.begin(),str.end());
return str;
}
long long gcd(long long a,long long b){
while(b){
a %= b;
swap(a,b);
}
return a;
}
long long lcm(long long a,long long b){
return a / gcd(a,b) * b;
}
}
using namespace templates;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string str = in<string>();
int cnt = 0;
rep(i,str.size()){
if(str.substr(i,4)=="ZONe")++cnt;
}
cout << cnt << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
double a, b;
cin >> a >> b;
int c = a - b;
cout << (c / a)*100;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,n) for(LL i=0;i<(n);i++)
int main()
{
double a, b;
cin >> a >> b;
b = a - b;
a = b/a;
a *= 100;
printf("%.10lf",a);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int N = 2020;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n,m; cin >> n >> m;
int s = 0;
forn(_,n) {
int x; cin >> x;
s += x;
}
vi inv(s+n+1);
inv[1] = 1;
forsn(x,2,si(inv)) {
inv[x] = ll(MOD - MOD/x) * inv[MOD%x] % MOD;
assert(ll(inv[x]) * x % MOD == 1);
}
ll ans = 1;
forn(k,s+n) {
ans = ans * (m+n-k) % MOD;
ans = ans * inv[k+1] % MOD;
}
cout << ans << endl;
return 0;
}
| #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define ll long long
#define MAXN 200005
#define uns unsigned
#define MOD 998244353ll
#define INF 0x7f7f7f7f
using namespace std;
inline ll read(){
ll x=0;bool f=1;char s=getchar();
while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
return f?x:-x;
}
ll x,y,p,q;
inline ll exgcd(ll a,ll b,ll&x,ll&y){
if(b==0){x=1,y=0;return a;}
ll res=exgcd(b,a%b,y,x);
y-=a/b*x;return res;
}
signed main()
{
for(int T=read();T--;){
x=read(),y=read(),p=read(),q=read();
ll md=(x+y)<<1,lim=md*(p+q)+1,ans=lim;
ll K,F,G=exgcd(p+q,md,K,F);
for(ll i=x;i<x+y;i++){
ll b=p,a=p+q,c=((i-b)%md+md)%md;
ll k=K,f=F,g=G;
if(c%g!=0)continue;
c/=g,k=(k*c%md+md)%md,f=md/g,k%=f,a=p+q,b=p;
if((k*a+b)%md>=x&&(k*a+b)%md<x+y)ans=min(ans,k*a+b);
}
md=p+q,G=exgcd((x+y)<<1,md,K,F);
for(ll i=p;i<p+q;i++){
ll b=x,a=(x+y)<<1,c=((i-b)%md+md)%md;
ll k=K,f=F,g=G;
if(c%g!=0)continue;
c/=g,k=(k*c%md+md)%md,f=md/g,k%=f,a=(x+y)<<1,b=x;
if((k*a+b)%md>=p&&(k*a+b)%md<p+q)ans=min(ans,k*a+b);
}
if(ans>=lim)printf("infinity\n");
else printf("%lld\n",ans);
}
return 0;
} |
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define For(i,n) for(int i=0;i<n;i++)
#define Forn(i,n) for(int i=1;i<=n;i++)
#define Fors(i,s) for(int i=0;i<s.size();i++)
#define all(v) v.begin(),v.end()
#define gcd(a, b) __gcd(a , b)
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define Max(a) *max_element(a,a+sizeof(a)/sizeof(a[0]))
#define Min(a) *min_element(a,a+sizeof(a)/sizeof(a[0]))
#define End return 0
#define gt greater<int>()
#define ll long long
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define mod 1e9+7 //1000000007
#define sp(n) fixed<<setprecision(n)
#define YES printf("YES\n")
#define NO printf("NO\n")
#define Erase(s) s.erase(unique(s.begin(),s.end()),s.end())
//%%%%%%%%%%%%%p%%%a%%%r%%%v%%%e%%%z%%%%%%%%%%%%%//
int main()
{
MP;
//int T;cin>>T;while(T--)
{
int a, b;
cin >> a >> b;
if (a+b >= 15 and b >= 8) cout << 1 << endl;
else if (a+b >= 10 and b >= 3) cout << 2 << endl;
else if (a+b >= 3) cout << 3 << endl;
else cout << 4 << endl;
}
cerr<<endl<<(float)clock()/(float)CLOCKS_PER_SEC<<" sec"<<endl;
End;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl
#define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
#define sortV(v) sort(v.begin(),v.end())
#define revV(v) reverse(v.begin(),v.end())
ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
string str = "";
//ll mod = 1e9 + 7;
ll mod = 998244353;
const int N = 100009;
void solve(){
cin >> a >> b >> x >> y;
if(a == b){
cout << x << endl;
}else if(a < b){
cout << min( ((b-a)*2 + 1)*x, x + (b-a)*y);
}else{
cout << min( ((a-b-1)*2 + 1)*x, x + (a-b-1)*y);
}
}
int main(){
ios_base::sync_with_stdio(false);
int cases = 1;
// cin >> cases;
while(cases--) solve();
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define ll long long
int main(){
int T;
int n;
cin>>n;
vector<ll> a(n);
ll ta=0,tb=0;
for(int i=0;i<n;i++){
ll x,y;
scanf("%lld%lld",&x,&y);
ta+=x;
a[i]=x+y+x;
}
sort(a.begin(), a.end(),greater<ll>() );
int res=0;
while(tb<=ta){
tb+=a[res];
res++;
}
//cout<<ta<<" "<<tb<<endl;
printf("%d\n",res);
return 0;
} |
// Problem: D - Choose Me
// Contest: AtCoder - AtCoder Beginner Contest 187
// URL: https://atcoder.jp/contests/abc187/tasks/abc187_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vl = vector<ll>;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
void divisors(map<int,int>& d,ll N){
for(int div : {2,3,5}){
int cnt=1;
if(N%2==0){
while((N%2)==0){
N/=2;
cnt++;
}
d[div]=cnt;
}
}
static array<int,8> increments = {4,2,4,2,4,6,2,6};
int i=0;
for(ll div=7;div*div<=N;div+=increments[i++]){
if((N%div)==0){
int cnt=1;
while((N%i)==0){
N/=i;
cnt++;
}
d[i]=cnt;
}
if(i==8)
i=0;
}
if(N>1)
d[N]=2;
}
ll solve(int T){
vl town(T);
ll baseline=0;
for(int i=0;i<T;i++){
ll a,b;
cin>>a>>b;
town[i]=2ll*a+b;
baseline-=a;
}
sort(town.begin(),town.end());
while(baseline<=0 && !town.empty()){
baseline+=town.back();
town.pop_back();
}
return T-(int)town.size();
}
int main(){
int T;
cin>>T;
cout<<solve(T)<<"\n";
return 0;
}
|
#include "iostream"
#include "vector"
#include "queue"
#include "stack"
#include "algorithm"
#include "string"
#include "cstring"
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
if (n % 100 == 0) {
cout << n / 100 << endl;
}
else {
cout << n / 100 + 1 << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
typedef long double lld;
#define all(x) (x).begin(), (x).end()
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
int main(){
int N;
cin>>N;
if(N%100==0)
cout<<N/100;
else
cout<<(N/100)+1;
}
|
#include<iostream>
using namespace std;
int main()
{
int a, b, c;
cin>>a>>b>>c;
int A, B, C;
A=7-a;
B=7-b;
C=7-c;
cout<<A+B+C;
} | #include<bits/stdc++.h>
using namespace std;
int main() {
long long A,B,C,kekka;
cin >> A >> B >> C;
A=A%998244353;
B=B%998244353;
C=C%998244353;
kekka=((A*(A+1)/2%998244353)*(B*(B+1)/2%998244353)%998244353*(C*(C+1)/2%998244353)%998244353);
cout << kekka << endl;
} |
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m, a[N][N], b[N][N];
struct info { int x, y, p; };
queue <info> q;
bool inq[N][N][2];
int dis[N][N][2];
inline void spfa()
{
memset(dis, 0x3f, sizeof(dis));
dis[1][1][0] = 0; q.push( (info) { 1, 1, 0 } ); inq[1][1][0] = 1;
int x, y, p;
while (!q.empty())
{
x = q.front().x, y = q.front().y, p = q.front().p; q.pop(); inq[x][y][p] = 0;
if (y < m)
{
if (dis[x][y][p] + a[x][y] < dis[x][y + 1][0])
{
dis[x][y + 1][0] = dis[x][y][p] + a[x][y];
if (!inq[x][y + 1][0])
{
q.push( (info) { x, y + 1, 0 } );
inq[x][y + 1][0] = 1;
}
}
}
if (y > 1)
{
if (dis[x][y][p] + a[x][y - 1] < dis[x][y - 1][0])
{
dis[x][y - 1][0] = dis[x][y][p] + a[x][y - 1];
if (!inq[x][y - 1][0])
{
q.push( (info) { x, y - 1, 0 } );
inq[x][y - 1][0] = 1;
}
}
}
if (x < n)
{
if (dis[x][y][p] + b[x][y] < dis[x + 1][y][0])
{
dis[x + 1][y][0] = dis[x][y][p] + b[x][y];
if (!inq[x + 1][y][0])
{
q.push( (info) { x + 1, y, 0 } );
inq[x + 1][y][0] = 1;
}
}
}
if (x == 1) continue;
if (p == 0)
{
if (dis[x][y][p] + 2 < dis[x - 1][y][1])
{
dis[x - 1][y][1] = dis[x][y][p] + 2;
if (!inq[x - 1][y][1])
{
q.push( (info) { x - 1, y, 1 } );
inq[x - 1][y][1] = 1;
}
}
}
if (p == 1)
{
if (dis[x][y][p] + 1 < dis[x - 1][y][1])
{
dis[x - 1][y][1] = dis[x][y][p] + 1;
if (!inq[x - 1][y][1])
{
q.push( (info) { x - 1, y, 1 } );
inq[x - 1][y][1] = 1;
}
}
}
}
}
int main()
{
scanf ("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j < m; j++)
scanf ("%d", &a[i][j]);
for (int i = 1; i < n; i++)
for (int j = 1; j <= m; j++)
scanf ("%d", &b[i][j]);
spfa();
printf ("%d\n", dis[n][m][0]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1, 0, 0, -1, -1, 1, 1};
vi dj = { 0, 0, -1, 1, -1, 1, -1, 1};
// 宣言は Dijkstra<コストの型> d(頂点数, コストの型の最大値);
template <class T>
struct Dijkstra {
struct edge {int to; T cost;};
vv<edge> g;
vc<T> dist;
Dijkstra (int n, T INF): g(n), dist(n, INF) {}
// u -> vにコストwの辺を張る
void add_edge (int u, int v, T w) {
g[u].pb({v, w});
}
// startから各点への最小コストを返す
vc<T> get (int start) {
priority_queue<pair<T, T>, V<pair<T, T>>, greater<pair<T, T>>> que;
dist[start] = 0;
que.emplace(0, start);
while (!que.empty()) {
int c = que.top().first, v = que.top().second; que.pop();
if (dist[v] != c) continue;
for (auto e : g[v]) {
if (chmin(dist[e.to], c + e.cost)) que.emplace(dist[e.to], e.to);
}
}
return dist;
}
};
int main () {
int h, w; cin >> h >> w;
Dijkstra<ll> d(h*w*2, 2e9);
rep(i, h) rep(j, w-1) {
int a; cin >> a;
d.add_edge(i*w + j, i*w + j+1, a);
d.add_edge(i*w + j+1, i*w + j, a);
}
rep(i, h-1) rep(j, w) {
int b; cin >> b;
d.add_edge(i*w + j, (i+1)*w + j, b);
}
rep(i, h) rep(j, w) {
d.add_edge(i*w + j, h*w + i*w + j, 1); // 上の階に行く
d.add_edge(h*w + i*w + j, i*w + j, 0); // 下の階に降りる
if (i > 0) d.add_edge(h*w + i*w + j, h*w + (i-1)*w + j, 1); // 上の階で下に移動する
}
auto res = d.get(0);
// int ans = min(res[h*w-1], res[2*h*w-1]);
ll ans = res[h*w-1]; // 下に移動してゴールにつくことはないから, 2*h*w-1は考えなくていい
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long int
#define ld long double
#define pb push_back
#define MOD 1000000007
#define inf 3e18
#define vi vector<int>
#define vld vector<ld>
#define pii pair<int,int>
#define mii map<int,int>
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero) (returns an iterator)
void inp_out()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("debug.txt", "w", stderr);
#endif
}
vector < vi > adj, vec;
vector < vector < pii >> a;
vi ans, sz, cnt, depth, mp;
void cal(int node)
{
for(auto i : a[node])
{
ans[i.se] = cnt[i.fi];
}
}
void dfs(int root, int keep)
{
int bC = - 1, mx = 0;
for(auto i : adj[root])
{
if(sz[i] > mx)
{
mx = sz[i];
bC = i;
}
}
for(auto i : adj[root])
{
if(i != bC)
{
dfs(i, 0);
}
}
if(bC != - 1)
{
dfs(bC, 1);
mp[root] = mp[bC];
}
cnt[depth[root]]++ ;
vec[mp[root]].pb(depth[root]);
for(auto i : adj[root])
{
if(i != bC)
{
for(auto j : vec[mp[i]])
{
cnt[j]++ ;
vec[mp[root]].pb(j);
}
}
}
cal(root);
if(!keep)
{
for(auto i : vec[mp[root]])
{
cnt[i]-- ;
}
}
}
void pre_cal(int root)
{
sz[root]++ ;
for(auto i : adj[root])
{
depth[i] = depth[root] + 1;
pre_cal(i);
sz[root] += sz[i];
}
}
int32_t main()
{
fastIO
inp_out();
int n;
cin >> n;
adj = vec = vector < vi > (n + 1);
a = vector < vector < pii >> (n + 1);
sz = cnt = depth = mp = vi(n + 1);
iota(mp.begin(), mp.end(), 0);
for(int i = 2; i <= n; ++ i)
{
int x;
cin >> x;
adj[x].pb(i);
}
int q;
cin >> q;
ans = vi(q);
for(int i = 0; i < q; ++ i)
{
int u, d;
cin >> u >> d;
a[u].pb({d, i});
}
pre_cal(1);
dfs(1, 1);
for(auto i : ans)
cout << i << '\n';
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define w(x) int x; cin>>x; while(x--)
#define mii map<int,int>
#define endl ("\n")
#define vi vector<int>
#define pii pair<int,int>
#define f(i, a, n) for(int i=a; i<n; i++)
#define r(i, n, a) for(int i=n-1;i>=0;i--)
#define fd(i, a, n, d) for(int i=a; i<n;i+=d)
#define rd(i, n, a, d) for(int i=n-1;i>=0;i-=d)
#define in(a,n) f(i,0,n){cin>>a[i];}
#define pb push_back
#define yy cout<<"YES\n"
#define nn cout<<"NO\n"
#define kk cout<<"-1\n"
#define inf (long long)1e18
#define mod 1000000007LL
#define cc(r) cout<<r<<" "
#define ce(r) cout<<r<<endl
#define out(a,n) f(i,0,n){cc(a[i]);}
#define cn continue
#define br break
#define ins insert
#define pi 3.14159265358979323846
#define aint(a) a.begin(),a.end()
//################################################################################
void ovector_n()
{
ce("Fastest Man Alive!");
}
//################################################################################
void flash() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
//################################################################################
int32_t main()
{
flash();//1 June++;
int T = clock();
int x, y;
cin >> x >> y;
int q = (3LL - (x + y));
if (x == y)
ce(x);
else
ce(q);
cerr << "TIME: " << (long double)(clock() - T) / CLOCKS_PER_SEC << " sec\n";
return 0;
}
|
// Problem: C - Comma
// Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 195)
// URL: https://atcoder.jp/contests/abc195/tasks/abc195_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Date: 2021-03-13 22:42:44
// --------by Herio--------
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define IOS ios::sync_with_stdio(false),cin.tie(0)
void Print(int *a,int n){
for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
int a[20];
ll dp[22][22][2][2];
ll dfs(int x,int c,bool li,bool lead){
if(!x){
//printf("c=%d\n",c);
return (c-1)/3;
}
ll &s=dp[x][c][li][lead];
if(~s) return s;
s=0;
int mx=li?a[x]:9;
for(int i=0;i<=mx;i++)
s+=dfs(x-1,(lead&&!i)?c:c+1,li&(i==mx),lead&&!i);
return s;
}
ll fun(ll n){
int w=0;while(n) a[++w]=n%10,n/=10;
return dfs(w,0,1,1);
}
int main(){
ll n;scanf("%lld",&n);mst(dp,-1);
printf("%lld\n",fun(n));
return 0;
}
| #include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define endl "\n" // interactive problem
#define ll long long
#define int long long
using namespace std;
const int N = (int)(1e5) + 322;
const int inf = (int)(1e9) + 322;
const long long INF = (long long)(1e18) + 322;
const int mod = (int)(1e9) + 7;
void solve() {
string s; cin >> s;
if (sz(s) <= 4) {
sort(all(s));
do {
if (stoi(s) % 8 == 0) {
cout << "Yes";
return;
}
} while (next_permutation(all(s)));
}
unordered_map <char, int> cnt;
for(auto c : s) cnt[c]++;
for(int i = 8; i < 1000; i += 8) {
string cur = to_string(i);
while (sz(cur) < 3) cur += '0';
unordered_map <char, int> no;
for(auto c : cur) no[c]++;
bool good = true;
for(auto it : no) {
if (cnt[it.first] < it.second) good = false;
}
if (good) {
cout << "Yes";
return;
}
}
cout << "No";
}
signed main () {
ios_base :: sync_with_stdio(false);
cin.tie(0);
// freopen("student.in", "r", stdin);
// freopen("student.out", "w", stdout);
int t = 1;//cin >> t;
for(int tt = 1; tt <= t; ++tt) {
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>v[3];
int sz[3];
int baad;
ll calc(int c1,int c2,bool check=false)
{
ll ansmin = 1e18;
ll a1,a2;
int pos, anspos = -1,i;
for(i=0;i<sz[c1];i++)
{
a1 = v[c1][i];
pos = upper_bound(v[c2].begin(), v[c2].end(), a1) - v[c2].begin();
if(pos != sz[c2])
{
a2 = v[c2][pos];
if(abs(a1-a2) < ansmin)
{
if(!(check && baad == pos))
{
ansmin = abs(a1-a2);
anspos = pos;
}
}
}
if(pos > 0)
{
pos--;
a2 = v[c2][pos];
if(abs(a1-a2) < ansmin)
{
if(!(check && baad == pos))
{
ansmin = abs(a1-a2);
anspos = pos;
}
}
}
}
baad = anspos;
return ansmin;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,i,j,k;
ll a;
char c;
cin >> n;
n *= 2;
for(i=1;i<=n;i++)
{
cin >> a >> c;
if(c == 'R') v[0].push_back(a);
else if(c == 'G') v[1].push_back(a);
else v[2].push_back(a);
}
for(i=0;i<3;i++) {
sz[i] = v[i].size();
sort(v[i].begin(), v[i].end());
}
if(sz[0]%2==0 && sz[1]%2==0 && sz[2]%2==0)
{
cout << 0 << endl;
return 0;
}
ll ans1, ans2, ansmin;
if(sz[0]%2 == 0) {
ansmin = calc(1,2);
ans1 = (calc(1,0) + calc(2,0,true));
ans2 = (calc(2,0) + calc(1,0,true));
ansmin = min(ansmin, min(ans1, ans2));
}
else if(sz[1]%2 == 0) {
ansmin = calc(0,2);
ans1 = (calc(0,1) + calc(2,1,true));
ans2 = (calc(2,1) + calc(0,1,true));
ansmin = min(ansmin, min(ans1, ans2));
}
else {
ansmin = calc(0,1);
ans1 = (calc(0,2) + calc(1,2,true));
ans2 = (calc(1,2) + calc(0,2,true));
ansmin = min(ansmin, min(ans1, ans2));
}
cout << ansmin << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()
ll M = 1e9 + 7;
double pi = acos(-1.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}
ll solve(vll a, vll b)
{
ll ans = 1e18;
int id1 = 0, id2 = 0;
int m = a.size(), n = b.size();
while( id1 < m && id2 < n )
{
ans = min( ans , abs(a[id1]-b[id2]) );
if( a[id1] < b[id2] ) id1++;
else id2++;
}
return ans;
}
ll solve1(vll a,vll b,vll c)
{
ll ans1 = 1e18; int id = -1;
int id1 = 0, id2 = 0;
int m = a.size(), n = b.size();
while( id1 < m && id2 < n )
{
if( ans1 > abs(a[id1]-b[id2]) )
{
ans1 = abs(a[id1]-b[id2]);
id = id1;
}
if( a[id1] < b[id2] ) id1++;
else id2++;
}
id1 = 0; id2 = 0;
n = c.size();
ll ans2 = 1e18;
while( id1 < m && id2 < n )
{
if( id1 == id ){ id1++; continue; }
if( ans2 > abs(a[id1]-c[id2]) )
{
ans2 = abs(a[id1]-c[id2]);
}
if( a[id1] < c[id2] ) id1++;
else id2++;
}
return ans1 + ans2;
}
int main() {
//ifstream cin("input.txt");
//ofstream cout("output.txt");
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin>>n;
map <char,vll> m;
forn(i,n*2)
{
ll a; char c;
cin>>a>>c;
m[c].pb(a);
}
sort(all(m['R']));
sort(all(m['G']));
sort(all(m['B']));
if( m['R'].size()%2 == 0 && m['G'].size()%2 == 0 && m['B'].size()%2 == 0 )
{
cout<<0; return 0;
}
string s;
if(m['R'].size()%2 == 0) s = "RBG";
if(m['G'].size()%2 == 0) s = "GRB";
if(m['B'].size()%2 == 0) s = "BRG";
ll h1 = solve(m[s[1]],m[s[2]]);
ll h2 = solve1(m[s[0]],m[s[1]],m[s[2]]);
ll h3 = solve1(m[s[0]],m[s[2]],m[s[1]]);
cout << min( h1 , min( h2 , h3 ) );
return 0;
}
|
#include<iostream>
int n;
int main(){
std::cin >> n;
int ans = 0;
while(true){
ans++;
if((ans-1)*100+1<=n&&n<=ans*100){
std::cout << ans << std::endl;
break;
}
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
int main() {
string s;
cin >> s;
array<int, 10> a{};
for (auto &&i : s) a[i-'0']++;
vector<string> t = {"8", "16", "24", "32", "48", "56", "64", "72", "88", "96"};
if(s.size() <= 2){
for (auto &&i : t) {
for (int j = 0; j < 2; ++j) {
if(i == s) return puts("Yes"), 0;
reverse(i.begin(),i.end());
}
}
return puts("No"), 0;
}
for (int i = 104; i <= 999; i += 8) {
string u = to_string(i);
for (auto &&j : u) a[j-'0']--;
int ok = 1;
for (auto &&j : a) if(j < 0) ok = 0;
if(ok) return puts("Yes"), 0;
for (auto &&j : u) a[j-'0']++;
}
puts("No");
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define il inline
#define rg register
il int read()
{
int re=0,k=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')k=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){re=re*10+ch-48;ch=getchar();}
return re*k;
}
il void write(int x)
{
if(x<0)return putchar('-'),write(-x),void();
if(x<10)return putchar(x+48),void();
return write(x/10),write(x%10),void();
}
int s,p;
signed main()
{
s=read();p=read();
for(rg int i=1;i*i<=p;i++)
{
if(p%i)continue;
if(p/i+i==s)
{
puts("Yes");
return 0;
}
}
puts("No");
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if (abs(a-b)<3) cout<<"Yes";
else cout<<"No";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define SZ(v) ((int)(v).size())
#define abs(x) ((x) > 0 ? (x) : -(x))
typedef long long LL;
const LL mod = 1000000000 + 7;
LL n, p;
void solve() {
cin >> n >> p;
LL b = n - 1, a = (p - 2) % mod;
LL res = 1;
for (; b; b >>= 1) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
}
cout << res * (p - 1) % mod << endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
solve();
return 0;
}
| #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
using ll = long long;
using namespace std;
template<typename A, typename B>
bool chmin(A &a, const B b) {
if (a <= b) return false;
a = b;
return true;
}
template<typename A, typename B>
bool chmax(A &a, const B b) {
if (a >= b) return false;
a = b;
return true;
}
#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;
template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);
template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << "{" << p.first << ", " << p.second << "}";
return out;
}
template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
out << '{';
for (const T &item : v) out << item << ", ";
out << "\b\b}";
return out;
}
void _tostr_rec(ostringstream &oss) {
oss << "\b\b \b";
}
template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
oss << head << ", ";
_tostr_rec(oss, forward<Tail>(tail)...);
}
template<typename... T>
string _tostr(T &&...args) {
ostringstream oss;
int size = sizeof...(args);
if (size > 1) oss << "{";
_tostr_rec(oss, forward<T>(args)...);
if (size > 1) oss << "}";
return oss.str();
}
#endif
constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 200010;
ll power(ll k, ll n, int M) {
ll res = 1;
for (; n; n /= 2) {
if (n & 1) res = res * k % M;
k = k * k % M;
}
return res;
}
int main() {
int N, P;
cin >> N >> P;
ll ans = (ll)(P - 1) * power(P - 2, N - 1, mod);
cout << ans % mod << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll mod = 1e9 + 7;
const ll linf = 1LL << 62;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
ll dp[20][1 << 20];
int N;
ll X[20], Y[20], Z[20];
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < (1 << N); j++) {
dp[i][j] = linf;
}
}
dp[0][1] = 0;
for (int i = 0; i < N; i++) cin >> X[i] >> Y[i] >> Z[i];
for (int i = 0; i < (1 << N); i++) {
for (int j = 0; j < N; j++) {
if (dp[j][i] == linf) continue;
for (int k = 0; k < N; k++) {
ll cost = abs(X[j] - X[k]) + abs(Y[j] - Y[k]) + max(0LL, Z[k] - Z[j]);
chmin(dp[k][i | (1 << k)], dp[j][i] + cost);
}
}
}
ll ans = linf;
for (int i = 1; i < N; i++) {
ll cost = abs(X[0] - X[i]) + abs(Y[0] - Y[i]) + max(0LL, Z[0] - Z[i]);
chmin(ans, dp[i][(1 << N) - 1] + cost);
}
cout << ans << endl;
} | #include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <numeric>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rept(i,k,n) for(long long i = (k); i < (long long)(n); i++)
#define All(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Rsort(v) sort(v.begin(),v.end(),[](auto a, auto b) { return a > b; })
#define Reverse(v) reverse(v.begin(),v.end())
#define MAX 1000000007
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
typedef tuple<int,int,int> Tii;
template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
for(int i=0;i<vec.size();i++){
if(i) s << ',';
else s << '{';
s <<setw(2)<< vec[i];
}
s << '}' << endl;
return s;
}
int main(){
bitset<17> b(0);
int n;
cin>>n;
vector<Tii> vs(n);
rep(i,n){
int x,y,z;
cin>>x>>y>>z;
vs[i]=Tii(x,y,z);
}
vector<vector<int> > dp(1<<n,vector<int>(n,1e9));
dp[0][0]=0;
sort(vs.begin(), vs.end(), [](Tii a, Tii b) { return get<2>(a) < get<2>(b); });
for(int i=1;i<(1<<n);i++){
b = i;
rep(j,n){
if(b.test(j)){
rep(k,n){
int a,b,c,p,q,r;
tie(a,b,c)=vs[k];
tie(p,q,r)=vs[j];
int dist = abs(p-a)+abs(q-b)+max(0,r-c);
dp[i][j]=min(dp[i][j],dp[i-(1<<j)][k]+dist);
}
}
}
}
cout<<dp.back()[0]<<endl;;
return 0;
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int main(void){
long long N;
long long X=1;
long long x=1000000000;
cin>>N;
set<long long> Ax;
for(long long n=0;n<N;n++){
long long a;
cin>>a;
if(X<a)X=a;
if(x>a)x=a;
Ax.insert(a);
}
while(X!=x){
Ax.erase(X);
X-=x;
Ax.insert(X);
auto max=Ax.end();max--;
auto min=Ax.begin();
X=*max;x=*min;
}
cout<<x<<endl;
return 0;
} | #pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using vi = vector<int>;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
F0R(j, sz(v)) i >> v[j];
return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
F0R(i, v.size()) {
o << v[i] << ' ';
}
o << newl;
return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
for (auto& p : m) {
o << p.first << ": " << p.second << newl;
}
o << newl;
return o;
}
#if 1
i64 gcd(i64 a, i64 b) { return b ? gcd(b, a % b) : a; }
// INSERT ABOVE HERE
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
int b = -1;
F0R(i, N) {
int a; cin >> a;
if (i) b = gcd(b, a);
else b = a;
}
cout << b;
}
#endif
|
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, const char * argv[]) {
// cinを高速にするためのおまじない
cin.tie(0);
ios::sync_with_stdio(false);
int n, x;
cin >> n;
cin >> x;
int hai = 0;
int alSum = 0;
int arr[n][2];
for (int i = 0; i < n; i++) {
cin >> arr[i][0];
cin >> arr[i][1];
}
for (int i = 0; i < n; i++) {
hai++;
alSum += arr[i][0] * arr[i][1];
if(alSum > x * 100){
cout << hai << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void solve(){
ll N,c;
cin >> N >> c;
vector<pll> v;
ll a;
vll cs(N+1);
for(int i = 1; i <= N; i++){
cin >> a;
v.pb({a,i});
cin >> a;
v.pb({a+1,-i});
cin >> cs[i];
}
sort(v.begin(),v.end());
//cout << v[0].se<<"lol ";
ll k =cs[v[0].se];
ll l =v[0].fi;
ll ans = 0;
//cout << k <<" kek";
for(int i = 1; i < 2*N; i++){
// cout << "k ans "<<k <<" "<<ans<<"\n";
ans+=(v[i].fi-l)*min(c,k);
l = v[i].fi;
if(v[i].se<0)k-=cs[-v[i].se];
else k+= cs[v[i].se];
}
cout << ans <<"\n";
return;
}
int main(){
int T = 1;
//cin >> T;
while(T--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//vector <long long> v[1000001];
//stack <long long> s, s2;
//queue <long long> s, s2;
long long int z[1000000], x[102][127502], y[1000000], m, szu, wy;
//char s[10000000];
int main()
{
long long int d, e, f, i, j, q, t, k, a, n, b, c, w, p, aa, bb, cc, dd, nn, kk;
t=1;
// scanf("%lld", &t);
for(q=1; q<=t; q++)
{
scanf("%lld%lld%lld", &n, &k, &m);
//n=100;k=100;m=1000000000;
x[0][0]=1;
for(i=1; i<=n; i++)
{
for(j=0; j<=min((long long)50*51/2*100, (i*(i+1))/2*k); j++)
{
x[i][j]=x[i-1][j];
if(j>=i)x[i][j]+=x[i][j-i];
if(j>=i*k+i)x[i][j]-=x[i-1][j-i*k-i];
x[i][j]%=m;
x[i][j]+=m;
x[i][j]%=m;
// if(i<=4)printf("%lld ", x[i][j]);
}
//if(i<=4)printf("\n");
}
for(i=1; i<=n; i++)
{
w=0;
c=i-1;
d=n-i;
for(j=0; j<=min((c*c+c)/2*k, (d*d+d)/2*k); j++)
{
a=x[i-1][j]*x[n-i][j];
a%=m;
b=k+1;
if(j==0)b--;
a*=b;
a%=m;
a+=m;
a%=m;
w=w+a;
w%=m;
w+=m;
w%=m;
}
printf("%lld\n", w);
}
}
return(0);
}
| #include<bits/stdc++.h>
using namespace std;
using LL = long long;
int N, K, M;
constexpr int maxn = 1000000;
int arr[maxn << 1], *dp;
void add(int& X, int Y){
X += Y;
if(X >= M) X -= M;
}
void sub(int& X, int Y){
X -= Y;
if(X < 0) X += M;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> N >> K >> M;
dp = arr + maxn;
vector<int> ans;
for(int i = 1; i <= (N + 1) / 2; i += 1){
int L = -i * (i - 1) / 2 * K, R = (N - i + 1) * (N - i) / 2;
for(int j = L; j <= R; j += 1) dp[j] = 0;
dp[L] = 1;
vector<int> v;
for(int j = 1; j <= N; j += 1) if(i != j) v.push_back(abs(i - j));
sort(v.begin(), v.end());
R = L;
for(int x : v){
int d = x * K;
R += d;
for(int j = L + x; j <= R; j += 1) add(dp[j], dp[j - x]);
for(int j = R; j >= L + d + x; j -= 1) sub(dp[j], dp[j - d - x]);
}
ans.push_back(((LL)dp[0] * (K + 1) + M - 1) % M);
}
for(int i = (N + 1) / 2 + 1; i <= N; i += 1) ans.push_back(ans[N - i]);
for(int x : ans) cout << x << "\n";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define pll pair<ll,ll>
#define vll vector<long long>
#define f first
#define s second
long long mod = 1e9+7;
int diry[] = {-1,0,0,1,1,-1,-1,1};
int dirx[] = {0,-1,1,0,1,-1,1,-1};
bool comp(const pii &a,const pii &b){
return a.second<b.second;
}
ll pow(ll x, ll y, ll p) {
ll res = 1;
x %= p;
if(x == 0) {
return 0;
}
while(y > 0) {
if(y & 1) {
res = (res * x) % p;
}
y >>= 1;
x = (x * x) % p;
}
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ull t=1,k;
// cin>>t;
// cin>>k;
// int ulti=1;
while(t--){
ll n,c; cin>>n>>c;
vector<pll> arr;
for(int i=0;i<n;i++){
ll a,b,d; cin>>a>>b>>d;
arr.push_back({a-1,d});
arr.push_back({b,-d});
}
sort(arr.begin(),arr.end());
ll ans=0,fee=0,t=0;
for(auto j:arr){
ll x=j.first,y=j.second;
if(t!=x){
ans += min(c,fee)*(x-t);
t = x;
}
fee+=y;
}
cout<<ans;
cout<<endl;
}
} | #include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n, C; cin >> n >> C;
ll a[n], b[n], c[n];
rep(i, n){
cin >> a[i] >> b[i] >> c[i];
a[i]--; b[i]--;
}
map<ll, ll> mp;
rep(i, n){
mp[a[i]] += c[i];
mp[b[i] + 1] -= c[i];
}
vector<pair<ll, ll>> vec;
for(const auto& [k, v] : mp){
vec.push_back({k, v});
}
vector<pair<ll, ll>> vec2;
ll len_vec = vec.size();
ll cost = vec[0].second;
rep(i, len_vec - 1){
ll d = vec[i + 1].first - vec[i].first;
vec2.push_back({d, cost});
cost += vec[i + 1].second;
}
ll ans = 0;
for(auto p : vec2){
if(p.second < C){
ans += p.first * p.second;
}
else{
ans += p.first * C;
}
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
int main() {
int N;
cin >> N;
vector<P> xy(N);
rep(i,N) cin >> xy[i].first >> xy[i].second;
int M;
cin >> M;
vector<vector<ll>> state(M+1, vector<ll>(4));//x, y, xの向き, yの向き
state[0][3]=1;//state[0]={0,0, 0,1}
int a, p;
rep(i,M) {
cin >> a;
if(a==2) {
state[i+1][0] = state[i][1]*(-1);
state[i+1][1] = state[i][0];
state[i+1][2] = (state[i][2]+1)%4;
state[i+1][3] = (state[i][3]+1)%4;
}
if(a==1) {
state[i+1][0] = state[i][1];
state[i+1][1] = state[i][0]*(-1);
state[i+1][2] = (state[i][2]+3)%4;
state[i+1][3] = (state[i][3]+3)%4;
}
if(a==3) {
cin >> p;
state[i+1][0] = (ll)2*p-state[i][0];
state[i+1][1] = state[i][1];
if(state[i][2]%2 == 0) {
state[i+1][2] = (state[i][2]+2)%4;
state[i+1][3] = state[i][3];
}
else {
state[i+1][2] = state[i][2];
state[i+1][3] = (state[i][3]+2)%4;
}
}
if(a==4) {
cin >> p;
state[i+1][0] = state[i][0];
state[i+1][1] = (ll)2*p-state[i][1];
if(state[i][2]%2 == 1) {
state[i+1][2] = (state[i][2]+2)%4;
state[i+1][3] = state[i][3];
}
else {
state[i+1][2] = state[i][2];
state[i+1][3] = (state[i][3]+2)%4;
}
}
//for(auto h : state[i+1]) cout << h << " ";
//cout << endl;
//stateはOK
}
int Q;
cin >> Q;
rep(i,Q) {
cin >> a >> p;//state[a] = {o,o,o,o} , xy[p] = {x,y}
p--;
if(state[a][2]==0) {//x=0
if(state[a][3]==1) {//(0,1)
cout << (ll)state[a][0] + xy[p].first << " " << (ll)state[a][1] + xy[p].second << endl;
}
else {//(0,3)
cout << (ll)state[a][0] + xy[p].first << " " << (ll)state[a][1] - xy[p].second << endl;
}
}
if(state[a][2]==1) {//x=1
if(state[a][3]==0) {//(1,0)
cout << (ll)state[a][0] + xy[p].second << " " << (ll)state[a][1] + xy[p].first << endl;
}
else {//(1,2)
cout << (ll)state[a][0] - xy[p].second << " " << (ll)state[a][1] + xy[p].first << endl;
}
}
if(state[a][2]==2) {//x=2
if(state[a][3]==1) {//(2,1)
cout << (ll)state[a][0] - xy[p].first << " " << (ll)state[a][1] + xy[p].second << endl;
}
else {//(2,3)
cout << (ll)state[a][0] - xy[p].first << " " << (ll)state[a][1] - xy[p].second << endl;
}
}
if(state[a][2]==3) {//x=3
if(state[a][3]==0) {//(3,0)
cout << (ll)state[a][0] + xy[p].second << " " << (ll)state[a][1] - xy[p].first << endl;
}
else {//(3,2)
cout << (ll)state[a][0] - xy[p].second << " " << (ll)state[a][1] - xy[p].first << endl;
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x1 gdsfdsf
#define y1 fgdfgdfg
#define endl '\n'
const ll DIM = 2E5+7;
pair<ll,ll> A[DIM],Q[DIM];
vector<pair<ll,ll> > V[DIM];
pair<ll,ll> ans[DIM];
pair<ll,ll> F(pair<ll,ll> a,ll rot){
if (rot==0){
return a;
}
if (rot==1){
return {a.second,a.first};
}
if (rot==2){
return {a.first,a.second};
}
if (rot==3){
return {a.second,a.first};
}
return a;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
for(ll i = 1;i<=n;++i){
cin>>A[i].first>>A[i].second;
}
ll m;
cin>>m;
for(ll i = 1;i<=m;++i){
cin>>Q[i].first;
if (Q[i].first>2)
cin>>Q[i].second;
}
ll q;
cin>>q;
for(ll i = 1;i<=q;++i){
ll x,y;
cin>>x>>y;
V[x].push_back({y,i});
}
for(auto to:V[0]){
ans[to.second] = A[to.first];
}
ll rot = 0;
ll addx = 0,addy = 0,multx = 1,multy = 1;
for(ll i = 1;i<=m;++i){
if (Q[i].first==1){
rot = (rot+1)%4;
swap(addx,addy);
addy = -addy;
swap(multx,multy);
multy = -multy;
}
if (Q[i].first==2){
rot = (3+rot)%4;
swap(addx,addy);
addx = -addx;
swap(multx,multy);
multx = -multx;
}
if (Q[i].first==3){
multx = -multx;
addx = -addx;
addx+=Q[i].second*2;
}
if (Q[i].first==4){
multy = -multy;
addy = -addy;
addy+=Q[i].second*2;
}
for(auto to:V[i]){
pair<ll,ll> a = F(A[to.first],rot);
a.first = a.first*multx+addx;
a.second = a.second*multy+addy;
ans[to.second] = a;
}
}
for(ll i = 1;i<=q;++i)cout<<ans[i].first<<' '<<ans[i].second<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <unordered_set>
#include <algorithm>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i,n) for (ll i = 0; i < (ll)(n); i++)
#define fore(x,a) for(auto&(x) : (a))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(a) (a).begin(), (a).end()
const ll INFL = 1e18;
const int INFI = 1e9;
const int MOD = 1e9 + 7;
const int MAX = 30;
ll dp[MAX+1][MAX+1];
string find_kth(int A,int B,ll K) {
if(A == 0) {
return string(B,'b');
}
if(B == 0) {
return string(A,'a');
}
if(K <= dp[A-1][B]) {
return string("a") + find_kth(A-1,B,K);
}
else {
return string("b") + find_kth(A,B-1,K-dp[A-1][B]);
}
}
int main(){
int A,B;
ll K;
cin >> A >> B >> K;
dp[0][0] = 1;
for (int i = 0; i <= A; i++) {
for (int j = 0; j <= B; j++) {
if(i > 0) {
dp[i][j] += dp[i-1][j];
}
if(j > 0) {
dp[i][j] += dp[i][j-1];
}
}
}
cout << find_kth(A,B,K) << endl;
} | #include<bits/stdc++.h>
using namespace std;
int n,m,x[101010],y[101010];
long long ans=0;
map<pair<int,int>,int>mp;
string s;
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>s;
for(int j=0;j<m;j++)
{
if(s[j]=='0')
{
x[i]++;
}
else
{
y[i]++;
}
}
mp[make_pair(x[i],y[i])]++;
}
for(int i=1;i<=n;i++)
{
int nw=1;
while((y[i]-nw)>=0)
{
ans+=mp[make_pair(x[i]+nw,y[i]-nw)];
nw+=2;
}
nw=1;
while((x[i]-nw)>=0)
{
ans+=mp[make_pair(x[i]-nw,y[i]+nw)];
nw+=2;
}
}
cout<<ans/2<<endl;
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)
ll binpow(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
ll gcd(ll a,ll b)
{
if (b==0) return a;
return gcd(b,a%b);
}
string to_upper(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
return a;
}
string to_lower(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
return a;
}
int SUM(string s)
{
int ans=0;
for (auto i : s)
ans+=(i-'0');
return ans;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
string s,t;
cin>>s;
cin>>t;
cout<<max(SUM(s),SUM(t));
return 0;
} | #include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
// #define NDEBUG
#include<cassert>
#define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i)
#define drep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i)
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define Endl putchar('\n')
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T>inline T fab(T x){ return x<0? -x: x; }
template<class T>inline T readin(T x){
x=0; int f=0; char c;
while((c=getchar())<'0' || '9'<c) if(c=='-') f=1;
for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48));
return f? -x: x;
}
template<class T>inline void writc(T x, char s='\n'){
static int fwri_sta[1005], fwri_ed=0;
if(x<0) putchar('-'), x=-x;
do fwri_sta[++fwri_ed]=x%10, x/=10; while(x);
while(putchar(fwri_sta[fwri_ed--]^48), fwri_ed);
putchar(s);
}
const int maxn=2e5;
ll ans[maxn+5], pre[maxn+5];
int premax[maxn+5], a[maxn+5], n;
signed main(){
n=readin(1);
rep(i, 1, n) a[i]=readin(1);
rep(i, 1, n) premax[i]=max(premax[i-1], a[i]), pre[i]=pre[i-1]+a[i];
ll cur=0;
rep(i, 1, n){
cur+=pre[i];
ans[i]=cur+1ll*premax[i]*i;
}
rep(i, 1, n) writc(ans[i]);
return 0;
} |
#include <bits/stdc++.h>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#define loop(i,a,b) for (int i = (a); i <= (b); i++)
#define loopr(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define inf 1e18
#define mod 1000000007
#define mod1 998244353
using namespace std;
int main()
{
fast_io;
ll s,p;
cin>>s>>p;
int f = 0;
for(ll i = 1;i*i<=p;i++)
{
if(p%i==0)
{
if(i+p/i==s)
{
f = 1;
}
}
}
if(f)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
} | #include <bits/stdc++.h>
#define LOCAL
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()
inline void quickread() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(10);
}
inline void print_vector(vector<int> &A){
for (auto&& x : A){
cout << x << " ";
}
cout << endl;
}
inline void print_vector(vector<ll> &A){
for (auto&& x : A){
cout << x << " ";
}
cout << endl;
}
inline void print_array(const int A[], int n) {
REP(i, n) {
if (i < n - 1) {
cout << A[i] << " ";
} else {
cout << A[i] << endl;
}
}
}
ll gcd(ll x, ll y) {
return (y == 0 ? x : gcd(y, x % y));
}
ll lcm(ll x, ll y) {
return x * y / gcd(x, y);
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
int color[100000 + 10];
int node_color[100000 + 10];
vector<int> res;
set<int> v;
void dfs(int node, unordered_map<int, vector<int>>& nei) {
// cout << node << " " << parent << endl;
v.insert(node);
if (color[node_color[node]] == 0) {res.push_back(node);}
color[node_color[node]]++;
for (auto x : nei[node]) {
if (v.find(x) == v.end()) {
// cout << x << " " << node << endl;
dfs(x, nei);
}
}
color[node_color[node]]--;
}
int solve() {
memset(color, 0, sizeof(color));
memset(node_color, 0, sizeof(color));
int n;
cin >> n;
int c;
REP(i, n) {
cin >> c;
node_color[i+1] = c;
}
unordered_map<int, vector<int>> nei;
int a, b;
REP(i, n - 1) {
cin >> a >> b;
nei[a].push_back(b);
nei[b].push_back(a);
}
dfs(1, nei);
sort(ALL(res));
for (auto x : res) {
cout << x << endl;
}
return 0;
}
int main() {
quickread();
int t = 1;
// cin >> t;
for (int _ = 0; _ < t; _++) {
int res = solve();
// cout << "Case #" << _ + 1 << ": " << res << endl;
}
return 0;
} |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(numeros) (ll) __builtin_popcountll(numeros)
#define cuantos(a,x) count(all(a),x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " es " << (x) <<"\n"
#define test ll deftestcases;cin>>deftestcases;while(deftestcases--)
#define PI acos(-1)
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
//template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
const ll inf = 2e18;
const ll mod = 1e9+7;
const ll MAX = 1e5;
int main(){
fastio;
ll n,k;cin>>n>>k;
while(n%200==0 && k){
k--;
n/=200;
}
bool go =1;
while(k){
if(go){
n*=10;
n+=2;
n*=100;
}else n/=200;
go^=1;
k--;
}
cout<<n<<"\n";
return 0;
} | #include <iostream>
using namespace std;
int H, W, A, B, ans = 0;
void dfs(int i, int bit, int A, int B){
if(i == H * W) return (void)ans++;
if(bit & 1 << i) return dfs(i + 1, bit, A, B);
if(B) dfs(i + 1, bit | 1 << i, A, B - 1);
if(A){
if(i % W != W - 1 && ~bit & 1 << (i + 1)) dfs(i + 1, bit | 1 << i | 1 << (i + 1), A - 1, B);
if(i + W < H * W) dfs(i + 1, bit | 1 << i | 1 << (i + W), A - 1, B);
}
}
int main(){
cin >> H >> W >> A >> B;
dfs(0, 0, A, B);
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");
#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define mii map<int, int>
#define pii pair<int, int>
#define qii priority_que<int, vector<int>, greater<int>>
#define For(i, n) for(int i = 0; i < n; ++i)
#define For1(i, n) for(int i = 1; i <= n; ++i)
#define Forlr(i, l, r) for(int i = l; i <= r; ++i)
#define Forrl(i, r, l) for(int i = r; i >= l; --i)
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) {For(i, a.size()) cout << a[i] <<" ";}
#define ovv(a) {For(i, a.size()) {For(j, a[i].size()) cout << a[i][j] <<" ";cout <<"\n";}}
using ll = long long;
int n, m, k, q;
const int INF = 1e9 + 5;
const int nax = 1e5 + 5;
pair<int, int> a[5 * nax];
int d[1505][1505][2];
int g[1505][1505];
ll rs = 0;
void dfs(int x, int y){
int nx = x, ny = y;
//if(!g[nx][ny] && !d[nx][ny][1] && !d[nx][ny][0]) rs ++, g[nx][ny] = 1;
while(1){
nx ++;
if(nx <= n && !d[nx][ny][0] && !g[nx][ny]){
if(!d[nx][ny][1]) rs ++;
d[nx][ny][0] = 1;
}
else{
break;
}
}
nx = x;
while(1){
nx --;
if(nx >= 1 && !d[nx][ny][0] && !g[nx][ny]){
if(!d[nx][ny][1]) rs ++;
d[nx][ny][0] = 1;
}
else{
break;
}
}
nx = x;
while(1){
ny ++;
if(ny <= m && !d[nx][ny][1] && !g[nx][ny]){
if(!d[nx][ny][0]) rs ++;
d[nx][ny][1] = 1;
}
else{
break;
}
}
ny = y;
while(1){
ny --;
if(ny >= 1 && !d[nx][ny][1] && !g[nx][ny]){
if(!d[nx][ny][0]) rs ++;
d[nx][ny][1] = 1;
}
else{
break;
}
}
}
int main()
{
fast();
cin >> n >> m;
int na, nb;
cin >> na >> nb;
For(i, na){
cin >> a[i].first >> a[i].second;
g[a[i].first][a[i].second] = 1;
rs++;
}
For(i, nb){
int x, y;
cin >> x >> y;
g[x][y] = 1;
}
For(i, na){
dfs(a[i].first, a[i].second);
}
// For(i, n){
// For(j, m){
// cout << g[i + 1][j + 1] <<" ";
// }
// cout <<"\n";
// }
cout << rs;
} | #include <bits/stdc++.h>
#define fo(i, k, n) for (ll i = k; i < n; i++)
#define rfo(i, k, n) for (ll i = k; i >= n ; i--)
#define ll long long
#define ld long double
#define que queue
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define gcd(m,n) __gcd( m, n)
#define sq(x) (x*x)
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define integer(s) stoi(s)
#define intoString(num) to_string(num);
using namespace std;
ll MOD = 1e9 + 7;
//--------------------------------------------functions-------------------------------------------------//
ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
ll res=1ll;
while(b){
if(b%2ll==1ll){
res=mul(a,res,M);
}
a=mul(a,a,M);b/=2ll;
}
return res;
}
//--------------------------------------------SieveOfEratosthenes-------------------------------------------------//
//mem will have true if its prime.
void SieveOfEratosthenes( vector<bool>&mem)
{ ll n = 1e6 +1;
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
fo(i,2,n)
if(prime[i])mem[i]=true;
}
//--------------------------------------------solve-------------------------------------------------//
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin>>s;
int k;
cin>>k;
ll temp;
fo(i,0,k)
{ temp = stoll(s);
if(temp%200)
{
s = s + "200";
}
else
{
temp /= 200;
s=intoString(temp);
}
}
cout<<s<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
struct edge{int to;};
using graph = vector<vector<edge>>;
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
int n, d, h; cin >> n >> d >> h;
ld ans = 0.0;
rep(i, 0, n) {
int di, hi; cin >> di >> hi;
ld slope = ((ld)h-hi)/(d-di);
ans = max(ans, (ld)hi-slope*di);
}
cout << fixed << setprecision(15) << ans << "\n";
}
| #include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define P pair<int,int>
using Graph = vector<vector<int>>;
int main() {
int N; cin >> N;
string S,T; cin >> S >> T;
vector<int> s1,t1;
rep(i,N){
if(S[i]=='1') s1.push_back(i);
if(T[i]=='1') t1.push_back(i);
}
t1.push_back(2*N);
ll cnt = 0; int k = 0; bool skip = false;
rep(i,s1.size()){
if(skip){
skip = false; continue;
}
int x = s1[i]; int y = t1[k];
if(x<y){
if(i==s1.size()-1) cnt = -1;
else{
cnt += (ll)s1[i+1] - (ll)x;
skip = true;
}
}
else{
cnt += (ll)x-(ll)y; k++;
}
}
if(k!=t1.size()-1) cnt = -1;
cout << cnt << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, S, D;
cin >> N >> S >> D;
int X[N], Y[N];
for (int i = 0; i < N; i++) {
cin >> X[i] >> Y[i];
}
bool res = false;
for (int i = 0; i < N; i++) {
if (X[i] < S) {
if (Y[i] > D) {
res = true;
break;
}
}
}
if (res) cout << "Yes" << endl;
else cout << "No" << endl;
} | // g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class MF{//max flow
public:
int n;
vector<vector<edge> >G;//[MAX];
vi level,iter;//[MAX];
MF(int size){
n=size;
G=vector<vector<edge> >(n);
}
void add_edge(int from, int to, int cap){
edge q={to,cap,int(G[to].size())};
G[from].push_back(q);
q={from,0,int(G[from].size()-1)};
G[to].push_back(q);
}
void bfs(int s){
level=vi(n,-1);
queue<int>q;
level[s]=0;
q.push(s);
while(!q.empty()){
int v=q.front();q.pop();
for(int i=0;i<G[v].size();i++){
edge &e=G[v][i];
if(e.cap>0&&level[e.to]<0){
level[e.to]=level[v]+1;
q.push(e.to);
}
}
}
}
int dfs(int v,int t, int f) {
if(v==t)return f;
for(int &i=iter[v];i<G[v].size();i++){
edge &e=G[v][i];
if(level[v]>=level[e.to]||e.cap<=0) continue;
int d =dfs(e.to,t,min(f,e.cap));
if(d>0){
e.cap-=d;
G[e.to][e.rev].cap+=d;
return d;
}
}
return 0;
}
int mf(int s,int t) {//from s to t,ford_fulkerson
int flow=0;
while(1){
bfs(s);
if(level[t]<0)return flow;
iter=vi(n);
int f;
while((f=dfs(s,t,inf))>0)flow+=f;
}
}
};
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,x,y;
cin>>n>>x>>y;
while(n--){
int a,b;
cin>>a>>b;
if(a<x&&b>y){
yes;
return 0;
}
}
no;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll decimaltoOctal(ll deciNum)
{
// initializations
ll octalNum = 0, countval = 1;
ll dNo = deciNum;
while (deciNum != 0) {
// decimals remainder is calculated
ll remainder = deciNum % 8;
// storing the octalvalue
octalNum += remainder * countval;
// storing exponential value
countval = countval * 10;
deciNum /= 8;
}
return octalNum;
}
int main()
{
fast
ll n;
cin>>n;
ll count=0;
for(ll i=1;i<=n;i++)
{
string str1 = to_string(i);
string str2 = to_string(decimaltoOctal(i));
if(str1.find('7') ==string::npos && str2.find('7') ==string::npos)
{
count++;
}
}
cout<<count;
return 0;
} | // 問題の URL を書いておく
//
#include <bits/stdc++.h>
using namespace std;
//#define ENABLE_PRINT
#if defined(ENABLE_PRINT)
#define Print(v) \
do {\
cout << #v << ": " << v << endl; \
}while(0)
#define PrintVec(v) \
do {\
for(int __i = 0; __i < v.size(); ++__i) \
{ \
cout << #v << "[" << __i << "]: " << v[__i] << endl; \
}\
}while(0)
#else
#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)
#endif
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using ll = int64_t;
int main(int, const char**)
{
int N;
cin >> N;
int ans = 0;
rep(i, N)
{
auto n = i + 1;
auto dn = n;
bool valid = true;
while(dn > 0)
{
auto m = dn % 10;
if(m == 7)
{
valid = false;
break;
}
dn /= 10;
}
if(!valid) continue;
auto on = n;
while(on > 0)
{
auto m = on % 8;
if(m == 7)
{
valid = false;
break;
}
on /= 8;
}
if(!valid) continue;
ans++;
}
cout << ans << endl;
return 0;
}
|
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
long long A[10010];
int main()
{
int N;
scanf("%d",&N);
for(int i=0;i<N;i++)
scanf("%lld",&A[i]);
long long ans=A[0];
for(int i=0;i<N;i++)
{
long long minimum=A[i];
for(int j=i;j<N;j++)
{
minimum=min(minimum,A[j]);
ans=max(ans,minimum*(j-i+1));
}
}
printf("%lld",ans);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define irep(i,a,b) for(int i=int(a);i<(int)b;++i)
#define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll,ll>>>
#define vpl vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define pb push_back
#define se second
#define fi first
#define all(v) v.begin(),v.end()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
template<typename T> istream& operator>>(istream&i,v(T)&v){rep(j,v.size())i>>v[j];return i;}
template<typename T> string join(const v(T)&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T> ostream& operator<<(ostream&o,const v(T)&v){if(v.size())o<<join(v);return o;}
using ll = long long;
const ll INF = LLONG_MAX-1e9;
const double PI = acos(-1);
const ll mod = 1e9 + 7; //998244353;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll modpow(ll a,ll b){
if(b == 0){
return 1;
}
if(b%2 == 0){
ll tmp = modpow(a,b/2);
return tmp*tmp%mod;
}else{
return modpow(a,b-1)*a%mod;
}
}
//区間最大値または最小値を求めるセグメント木の構造体
template <typename T>
struct RMQ {
const T INF = numeric_limits<T>::max();
T bound; //最小値のときはinf,それ以外の時0となる
int n;
bool flag; //最大値でtrue
vector<T> dat;
RMQ(int n_,bool flag_ = true) : n(),flag(flag_), dat(n_ * 4,flag_ ? 0 : INF){
int x = 1;
while(n_ > x){
x *= 2;
}
n = x;
if(flag_){
bound = 0;
}else{
bound = INF;
}
}
T func(T a,T b){
if(flag){
return max(a,b);
}else{
return min(a,b);
}
}
void update(int i,T x){
i += n - 1;
dat[i] = x;
while(i > 0){
i = (i-1)/2;
dat[i] = func(dat[i*2+1],dat[i*2+2]);
}
}
T query(int a,int b){
return query_sub(a,b,0,0,n);
}
T query_sub(int a,int b,int k,int l,int r){
if(r <= a || b <= l){
return bound;
}else if(a <= l && r <= b){
return dat[k];
}else{
T v_l = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
T v_r = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
return func(v_l, v_r);
}
}
};
ll dp[10005][10005];
int main(void)
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
ll n;
cin >> n;
vl a(n);
cin >> a;
ll ans = 0;
rep(i,n){
int l = i,r = i;
while(l >= 0){
--l;
if(a[l] < a[i] || l == -1){
l++;
break;
}
}
while(r < n){
r++;
if(a[r] < a[i] || r == n){
--r;
break;
}
}
ans = max(ans,a[i]*(r-l+1));
}
cout << ans << endl;
return 0;
}
|
// Author: old_school
// Created: 18.04.2021 17:30:11
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define lld long long int
#define ld long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define nl '\n'
#define YES cout<<"YES";
#define NO cout<<"NO";
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sz(c) (c).size()
#define tr(x,a) for(auto &a : x)
#define psnt(x,a) (x).find(a)!=(x).end()
#define vpsnt(x,a) find(all(x),a)!=(x).end()
#define MOD 1000000007
#define tod (long long)1e5
#define pi 3.14159265358979323844
#define itr(i,a,b) for(lld i=a;i<=b;i++)
#define itrn(i,a,b) for(lld i=a;i>=b;i--)
#define iot(n) for(lld i=0;i<n;i++)
#define jot(n) for(lld j=0;j<n;j++)
#define pls(n,arr) lld arr[n]; iot(n) cin>>arr[i];
typedef pair<lld,lld> pii;
typedef pair<string,lld> psi;
template <typename T>
bool mycomp(T x,T y){
return (x==y); //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){
return x.second<y.second;
}
void solve(){
lld a,b; cin>>a>>b;
vector<lld> A,B;
lld r=1;
lld za=a,zb=b;
lld sa=0,sb=0;
while(za--) sa+=r,A.pb(r++);
r=-1;
while(zb--) sb+=abs(r),B.pb(r--);
if(sa>sb){
B[b-1]-=(sa-sb);
}
else if(sa<sb){
A[a-1]+=(sb-sa);
}
for(auto &p:A) cout<<p<<" ";
for(auto &p:B) cout<<p<<" ";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
lld t=1; //cin>>t;
while(t--){
solve();
cout<<endl;
}
}
| #include<bits/stdc++.h>
#define ll long long int
#define fab(a,b,i) for(int i=a;i<b;i++)
#define db double
#define endl "\n"
#define f first
#define se second
#define MOD 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, MOD - 2);}
using namespace std;
ll a[10000000],b[10000000];
int main()
{
quick;
#ifndef ONLINE_JUDGE
freopen("C:/coding/input.txt", "r", stdin);
freopen("C:/coding/output.txt", "w", stdout);
#endif
ll m,h;
string s;
cin>>m>>h;
if(h%m==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
typedef long long int ll;
typedef string str;
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
ll nCrModP(ll n, ll r, ll p)
{
if (!r)
return 1;
ll fac[n+1];
fac[0] = 1;
for (ll i=1 ; i<=n; i++)
fac[i] = fac[i-1]*i%p;
return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}
ll gcd(ll a, ll b){
if (a == 0)
return b;
return gcd(b % a, a);
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main ()
{
ll t,n,m,k,i,j,a,b;
// cin >> t;
str st,s;
cin >> n >> k;
while(k>0)
{
if(n%200==0)
{
n/=200;
}
else
{
n*=1000;
n+=200;
}
k--;
}
cout << n << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pp=pair<int,int>;
const ll INF=1e9;
const ll mod=1e9+7;
int main() {
int N;
string s;
cin >> N >> s;
stack<int> ss, res;
int m=0;
int i=0;
while (i<N) {
if (i+2<N && s[i]=='f' && s[i+1]=='o' && s[i+2]=='x') {
m++;
i+=3;
}
else if (i+1<N && s[i]=='f' && s[i+1]=='o') {
ss.push(2);
i+=2;
}
else if (i<N && s[i]=='f') {
ss.push(1);
i++;
}
else if (ss.size()>0 && i<N && s[i]=='x') {
int sss=ss.top();
if (sss==2) {
m++;
i++;
ss.pop();
}
else {
ss=res;
}
}
else if (ss.size()>0 && i+1<N && s[i]=='o' && s[i+1]=='x') {
int sss=ss.top();
if (sss==1) {
m++;
i+=2;
ss.pop();
}
else {
ss=res;
}
}
else if (ss.size()>0 && i<N && s[i]=='o') {
int sss=ss.top();
if (sss==1) {
ss.pop();
ss.push(2);
i++;
}
else {
ss=res;
}
}
else {
ss=res;
i++;
}
}
cout << N-3*m << endl;
}
|
#include <bits/stdc++.h>
/*
// using ASL (use make)
#include <atcoder/all>
using namespace atcoder;
*/
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
// 1次元 vector print
template <class T>
ostream &operator<<(ostream &s, vector<T> vec) {
for (int i = 0; i < (int)vec.size(); ++i) {
if (i > 0) {
s << " ";
}
s << vec[i];
}
return s << endl;
}
// 2次元 vector print
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> vec2) {
for (int i = 0; i < (int)vec2.size(); ++i) {
s << vec2[i];
}
return s;
}
template <class T>
vector<T> make_vec(size_t a) {
return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
int main() {
char C1, C2, C3;
cin >> C1 >> C2 >> C3;
if (C1 == C2 && C2 == C3) {
cout << "Won\n";
} else {
cout << "Lost\n";
}
return 0;
}
| //デバッグ用オプション:-fsanitize=undefined,address
//コンパイラ最適化
#pragma GCC optimize("Ofast")
//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
/*
ビット全探索
for(int bit=0;bit<(1<<n);bit++){
for(int i=0;i<n;i++){
if(bit & (1<<i)){
}
}
*/
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
signed main(){
//小数の桁数の出力指定
//cout<<fixed<<setprecision(10);
//入力の高速化用のコード
//ios::sync_with_stdio(false);
//cin.tie(nullptr);
string s;
cin>>s;
rep(i,s.size()){
if(i%2==1)if(s[i]-'a'>=0){
cout<<"No"<<endl;
return 0;
}
if(i%2==0)if(s[i]-'Z'<=0){
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
return 0;
} |
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
const int MOD = 998244353;
int f[200002];
int find(int x) {
return f[x] == x ? f[x] : f[x] = find(f[x]);
}
int main() {
int n; cin >> n;
REP(i, n) f[i] = i;
REP(i, n) {
int x; cin >> x;
f[find(x)] = find(i);
}
int res = 1;
REP(i, n)
if (f[i] == i)
res = (res<<1) % MOD;
cout << res-1 << '\n';
return 0;
}
| #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <map>
#define amax(a, b) a = std::max(a, b)
#define amin(a, b) a = std::min(a, b)
using ll = long long;
std::pair<int, int> log3(int n) {
int i;
// std::cerr << ": " << n << std::endl;
for (i=0; n % 3 == 0; n /= 3, i++);
// std::cerr << "=> " << i << ' ' << n % 3 << std::endl;
return {i, n % 3};
}
int main() {
int n;
std::string s;
std::cin >> n >> s;
std::map<char, int> zip {
{'B', 0},
{'W', 1},
{'R', 2},
};
std::string unzip = (n % 2 == 1 ? "BWR" : "BRW");
int sum = 0;
ll comb_r = 1;
int cnt3 = 0;
for (int i=0; i<n; i++) {
int comb = (cnt3 == 0 ? comb_r : 0);
sum = (sum + zip[s[i]] * comb) % 3;
if (i == n-1) break;
auto [loga, vala] = log3(n - i - 1);
auto [logb, valb] = log3(i + 1);
int valb_inv = valb;
comb_r = comb_r * vala * valb_inv % 3;
cnt3 += loga - logb;
// std::cerr << sum << ' ' << comb_r << ' ' << cnt3 << std::endl;
}
std::cout << unzip[sum] << '\n';
return 0;
} |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
cout<<"\n";
}
#define vmax(type) std::numeric_limits<type>::max()
#define vmin(type) std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'
ll powm(ll a, ll b, ll mod) {
ll res=1;
while(b) {
if(b&1)
res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
const ll mod = 1e9 + 7;
const ll N = 1000005;
const ll inf = 1e9;
void solve()
{
ll n, a, b;
cin>>n>>a>>b;
cout<<n+b-a<<endl;
}
// #define _DEBUG
// #define testCases
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
int tc = 1;
#ifdef testCases
cin>>tc;
#endif
for(int t = 1; t <= tc; t++)
{
#ifdef _DEBUG
int tt = clock();
#endif
// cout<<"Case #"<<t<<": ";
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
return 0;
}
| //Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する
//インクルードなど
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
typedef long long ll;
//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;
#define coutall(x) {for(int i=0;i<sizeof(x)/sizeof(x[0]);i++){cout<<x[i]<<"|";};};cout<<endl;
//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}
signed main(){
ll x;cin>>x;ll y=0;
FOR(a,1,x){FOR(b,1,x){
if(x<a*b){break;};
y+=myfloor(x,a*b);
};};cout<<y;
} |
#include <bits/stdc++.h>
using namespace std;
#define show(a) for(auto e:a)cout<<e<<" ";cout<<endl
#define size(a) static_cast<int>((a).size())
int main(){
long long n, maxb, powb, ans = LLONG_MAX, a, c;
cin >> n;
maxb = log(n) / log(2);
if(n == 1){
cout << 1 << endl;
return 0;
}
for(int b = 0; b < maxb; ++b){
powb = static_cast<long long>(pow(2.0, b));
a = n / powb;
c = n - a * powb;
ans = min(ans, a + b + c);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;
const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-7;
#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
void Add(ll &a, ll b){
a=(a+b)%mod;
return;
}
void Mul(ll &a, ll b){
a=(a*b)%mod;
return;
}
bool nana(ll x, ll n){
if(!x) return false;
if(x%n==7) return true;
return nana(x/n,n);
}
int main(){
ll N; cin>>N;
ll ans=0;
REP(i,1,N+1) if(!nana(i,10) && !nana(i,8)) ans++;
cout<<ans<<endl;
} |
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test() int t; cin>>t; while(t--)
#define all(v) v.begin(),v.end()
#define st(v) sort(all(v))
#define stA(arr,n) sort(arr,arr+n)
#define dps(n,c) vector<vector<ll>> dp(n,vector<ll>(c,0))
#define vc(v,n,f) vector<ll> v(n,f)
#define vct(v) vector<ll> v
#define findInVec(v,key) (find(all(v),key)!=v.end())
#define findInSet(v,key) (v.find(key) != v.end())
#define findInStr(s,key) (s.find(key) != string::npos)
#define findInMap(m,key) (mp.find(key) != mp.end())
#define prt(i) cout<<i<<"\n"
#define fos(v) for(auto x:v)
#define fo(m,n,i) for(int i=m;i<n;i++)
#define Fo(m,n,i) for(int i=m;i>n;i--)
#define setbit(i) __builtin_popcount(i)
#define del(v,pos) v.erase(v.begin()+pos)
#define cnt(v,key) (count(all(v),key))
#define cnts(s,key) (s.count(key))
#define sumArr(a,s,e,sum)(accumulate(a+s,a+e,sum))
#define pb(c) push_back(c);
#define mod 1000000007
typedef long long ll;
using namespace std;
template <typename Kausi>
void debug(vector<Kausi> v){cout<<"v = [ ";ll n=v.size();fo(0,n,i){cout<<v[i];if(i<n-1)", ";}cout<<" ]\nlength = "<<v.size()<<"\n";}
ll stringToLong(string s){stringstream raaz(s);ll x = 0;raaz >> x;return x;}
string longToString(ll k){stringstream ss;ss<<k;string s; ss>>s; return s;}
bool isPowerOfTwo(int n){if(n==0) return false; return (ceil(log2(n)) == floor(log2(n)));}
void scanArr(int *arr,int n){fo(0,n,i) cin>>arr[i];}
void printArr(int *arr,int n){fo(0,n,i) cout<<arr[i]<<" ";}
template <typename Kausi>
void scanVector(vector<Kausi> &v,int n){fo(0,n,i){Kausi temp;cin>>temp;v.push_back(temp);}}
template <typename Kausi>
void printVector(vector<Kausi> v){fos(v) cout<<x<<" ";}
int main()
{
IOS
ll n;
cin>>n;
vector<ll> v(n);
map<ll,ll> mp;
fo(0,n,i){
cin>>v[i];
mp[v[i]]++;
}
ll ans=0;
fo(0,n,i)
{
mp[v[i]]--;
ll curr = mp[v[i]];
ans+=(n-i-1-curr);
}
prt(ans);
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
template <typename T>
using orderedSet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using orderedMultiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ld pi = 4.0 * atan(1.0);
#define xlr8 \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL); \
cout.precision(10); \
cout << fixed
//76149
template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>>
{
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template <typename... Args>
Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...))
{
}
};
template <typename T>
struct Vec<1, T> : public vector<T>
{
Vec(int n = 0, T val = T()) : vector<T>(n, val)
{
}
};
int main()
{
xlr8;
int testCases = 1;
// cin >> testCases;
while (testCases--)
{
int n;
cin>>n;
vector<int> a(n);
map<int ,int> freq;
for(int i = 0 ; i < n ; i++)
{
cin>>a[i];
freq[a[i]]++;
}
ll ans = 0;
for(auto & k : freq)
{
ans += (1LL*k.second* (n - k.second));
}
cout<<ans/2<<"\n";
}
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
cin>>a;
if(a%2==0)
cout<<"White";
else
cout<<"Black";
} | //g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt
#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime> // へびになりたい
#include <bitset> // へびになった シャー
#include <cassert>
// #include <atcoder/all>
// using namespace atcoder; // コンパイル重い
#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
using P=pair<int,int>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
int main() {
ll n; cin>>n;
vector<string> v[2];
v[0].push_back("AB");
for(int i=0;i<n-1;i++) {
int ii = i % 2;
int jj = (i+1)%2;
string st = "";
for(int j=0;j<1<<(i+1);j++) st+="A";
for(int j=0;j<1<<(i+1);j++) st+="B";
v[jj].push_back(st);
for(string s : v[ii]) {
//cout << i << " " << s << endl;
v[jj].push_back(s+s);
string t;
for(char ch : s) t += (ch == 'B') ? 'A' : 'B';
v[jj].push_back(s+t);
}
v[ii].clear();
v[ii].shrink_to_fit();
}
cout<<v[(n+1)%2].size()<<endl;
for(string s : v[(n+1)%2]) {
cout<<s<<endl;
}
}
// ・配列の大きさok? ・priority_queueはgreater? ・debug消した?
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……
// Thank you for making problems and running the contest
|
#include<bits/stdc++.h>
#include<cstdlib>
#include <algorithm>
#include <string>
using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;
int main(){
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n;
cin>>n;
string t = "atcoder";
for(int i=0;i<n;++i){
string s;
cin>>s;
int m = (int)s.size();
if(s > t){
cout << 0 << endl;
continue;
}
int num = inf;
for(int i=0;i<m;++i){
if(s[i] != 'a'){
swap(s[1],s[i]);
if(s > t) num = min(num,i-1);
swap(s[1],s[i]);
swap(s[0],s[i]);
if(s > t) num = min(num,i);
swap(s[0],s[i]);
break;
}
}
if(num == inf)cout << -1 << endl;
else cout << num << endl;
}
return 0;
} | #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<pll> vpll;
template<typename T> void makeunique(vector<T> &vx) {sort(vx.begin(),vx.end());auto it=unique(vx.begin(),vx.end());vx.resize(std::distance(vx.begin(),it));}
string t="atcoder";
int go() {
string s; cin>>s;
if (t<s) return 0;
int ans=INF;
for (int si=1;si<s.length();si++) if (s[si]>'a') chkmin(ans,si);
if (s[0]=='a') {
for (int si=2;si<s.length();si++) if (s[si]>'t') chkmin(ans,si-1);
}
if (ans>=INF/2)ans=-1;
return ans;
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
int t; cin>>t;
for (int i=0;i<t;i++) {
int ans=go();
cout<<ans<<endl;
}
}
|
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0; i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
ll calc[3000000]{0};
void pre(){
calc[0]=1;
for(int i=1;i<=2e6;i++){
if(i%2==1)
calc[i]=calc[i-1]+((i+2)/2)*2;
else
calc[i]=calc[i-1]+ ((i+2)/2)*2 - 1;
}
}
void solve(){
ll l,r;cin>>l>>r;
if(r<2*l){
cout<<0<<"\n";
}else{
cout<<calc[r-2*l]<<"\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
pre();
long long int num = 1;
cin>>num;
for(long long int i=0;i<num;i++){
solve();
}
}
| #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << '(' << p.first << ',' << p.second << ')';
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
for(int i = 0; i < (int)v.size(); i++) {
if(i) { os << ','; }
os << v[i];
}
os << '}';
return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
cerr << " " << x;
debugg(args...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T> inline void print(T &a){
int sz = a.size();
for(auto itr = a.begin(); itr != a.end(); itr++){
cout << *itr;
sz--;
if(sz) cout << " ";
}
cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;
int main(){
int n; cin >> n;
int sum = 0;
for(int i=1; i<=n; i++){
sum += i;
if(sum >= n){
cout << i << endl;
return 0;
}
}
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
auto read = [&](){
int x; cin >> x;
return x;
};
vector<int> a(4);
for(int & v : a) v = read();
sort(a.begin(), a.end());
if(a[0] + a[3] == a[1] + a[2] || a[3] == a[0] + a[1] + a[2]) cout << "Yes\n";
else cout << "No\n";
return 0;
} |
#include <iostream>
using namespace std;
int main()
{
string x;
cin >> x;
int i=0;
for(int i=0; i<x.length(); i++){
if( ( (i%2!=0)&&(x[i]>='a')&&(x[i]<='z') ) || ( (i%2==0)&&(x[i]>='A')&&(x[i]<='Z') ) ) {
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
ll a,b,x,y;
cin >> a >> b >> x >> y;
ll ans=0;
if(a>b){
if(2*x>y){
ans=x;
for(int i=0;i<a-b-1;i++){
ans+=y;
}
}else{
ans=x;
a--;
for(int i=0;i<2*(a-b);i++){
ans+=x;
}
}
}else if(a==b){
ans=x;
}else{
if(2*x>y){
ans=x;
for(int i=0;i<b-a;i++){
ans+=y;
}
}else{
if(2*x>y){
ans=x;
for(int i=0;i<b-a;i++){
ans+=y;
}
}else{
ans=x;
for(int i=0;i<2*(b-a);i++){
ans+=x;
}
}
}
}
cout << ans;
}
| #include<bits/stdc++.h>
using namespace std;
long long a[200005],b[200005];
int main()
{
int k,n,m;
cin>>k>>n>>m;
for (int i=1;i<=k;i++){
cin>>a[i];
}
priority_queue<pair<long long,int> > q;
long long cn=m;
double c=1.0*m/n;
for (int i=1;i<=k;i++){
b[i]=(int)(c*a[i]);
cn-=b[i];
q.push({-b[i]*n+a[i]*m,i});
//cout<<-b[i]*n+a[i]*m<<" ";
}
while(cn--)
{
pair<long long ,int> now=q.top();
q.pop();
int i=now.second;
b[i]++;
q.push({-b[i]*n+a[i]*m,i});
}
for (int i=1;i<=k;i++) cout<<b[i]<<" ";
cout<<endl;
return 0;
}
|
/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v) v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
return (x > y ? x : y);
}
using namespace std;
const int N = 1000005;
int c = 1;
void solve() {
int n;
cin >> n;
string s[n];
map<string, int> mp;
for(int i = 0; i < n; i++) {
cin >> s[i];
if(s[i][0] == '!') continue;
mp[s[i]]++;
}
for(int i = 0; i < n; i++) {
if(s[i][0] == '!') {
string t = s[i];
t.erase(t.begin());
if(!mp[t]) continue;
cout << t << '\n';
return;
}
}
cout << "satisfiable\n";
}
int main() {
/*int tc;
cin >> tc;
while(tc--)*/
solve();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
map<string, int> m;
int main(){
int n;
cin >> n;
string ans = "satisfiable";
for(int i = 0; i < n; i++){
char a[20];
cin >> a;
if(a[0] == '!'){
if(m[a+1] == 1){
ans = a+1;
}
else{
m[a+1] = 2;
}
}
else{
if(m[a] == 2){
ans = a;
}
else{
m[a] = 1;
}
}
}
cout << ans << '\n';
} |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n;
int a[MAXN << 1];
priority_queue<int,vector<int>,greater<int> > taken;
int main()
{
scanf("%d",&n);
for (int i = 1;i <= n * 2;i++)
scanf("%d",&a[i]);
for (int i = n;i >= 1;i--)
{
int u = a[i],v = a[2 * n - i + 1];
if (u < v)
swap(u,v);
taken.push(u);
if (taken.top() < v)
{
taken.pop();
taken.push(v);
}
}
long long ans = 0;
while (!taken.empty())
{
ans += taken.top();
taken.pop();
}
printf("%lld\n",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define Bit(x, k) (((x) >> (k)) & 1)
#define Xor(x, k) ((x) ^ (1 << (k)))
signed main() {
// freopen("in" , "r", stdin );
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n);
for (auto &i : a) cin >> i;
int ans = 2e9;
for (int mask = 0; mask < (1 << n); mask++) {
int cal = 0, val = 0, mode = -1;
for (int i = 0; i < n; i++) {
int m = Bit(mask, i);
if (m != mode) {
mode = m;
cal ^= val;
val = a[i];
}
else val |= a[i];
}
cal ^= val;
ans = min(ans, cal);
}
cout << ans << endl;
}
|
#include <iostream>
#pragma GCC optimize("O3")
#define int unsigned long long
using namespace std;
bool check(int n,int x){
if(x%n!=1)return 1;
return 0;
}
int gcd(int a,int b){
if(a%b==0){
return b;
}
return gcd(b,a%b);
}
signed main(){
int n;
cin>>n;
int sum=1;
for(int i=2;i<=n;i++){
if(sum%i==0)continue;
int k=gcd(sum,i);
sum=sum/k*i;
}
cout<<sum+1<<'\n';
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define deb(x) cout << #x << " " << x << endl;
#define debtwo(x,y) cout << x << ", " << y << endl;
#define mod 1000000007
#define N 1000001
void solve() {
ll n; cin >> n;
ll res = 1;
vector<bool> primes(31, true);
for (int i = 2; i <= 5; i++) {
if (primes[i]) {
for (int j = i * i; j <= 30; j += i) {
primes[j] = false;
}
}
}
for (int i = 2; i <= n; i++) {
if (primes[i]) {
res = i * res;
if (i == 3 || i == 5)
res = i * res;
if (i == 3)
res = i * res;
}
else if (i == 4) {
res = i * i * res;
}
}
cout << res + 1 << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
//cin >> t;
while (t--) {
solve();
}
} |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
#include <sstream>
#include <map>
#include <unordered_map>
#include <cmath>
// #include <boost/numeric/ublas/vector.hpp>
// #include <boost/numeric/ublas/matrix.hpp>
// #include <boost/numeric/ublas/io.hpp>
// namespace ublas = boost::numeric::ublas;
using namespace std;
using LLI = long long int;
#define Rep(i, N) for (int i = 0; i < N; i++)
// const LLI MAX = 100000001;
using VALUE = int;
using SIZE = int;
int valueOf(vector<SIZE> hako, vector<pair<VALUE, SIZE>> nimotsu) {
std::sort(hako.begin(), hako.end());
// int j = 0;
// for (auto h : hako) {
// while (j < int(nimotsu.size())) {
// auto a = nimotsu[j++];
// if (h >= a.second) {
// val += a.first;
// break;
// }
// }
// }
int val = 0;
vector<int> X(hako.size(), 0);
for (auto p : nimotsu) {
bool f = false;
for (int j = 0; j < hako.size(); j++) {
if (X[j] == 0 && hako[j] >= p.second) {
X[j] = p.first;
val += p.first;
f = true;
break;
}
}
}
return val;
}
int main(int argc, char *argv[])
{
int N, M, Q;
cin >> N >> M >> Q;
vector<pair<VALUE, SIZE>> nimotsu;
Rep(i, N) {
int w, v;
cin >> w >> v;
nimotsu.emplace_back(v, w);
}
vector<SIZE> hako(M);
Rep(i, M) {
cin >> hako[i];
}
vector<pair<int, int>> query;
Rep(i, Q) {
int s, e;
cin >> s >> e;
query.emplace_back(s-1, e-1);
}
sort(nimotsu.begin(), nimotsu.end(), greater<pair<VALUE, SIZE>>());
for (pair<int, int> q : query) {
vector<SIZE> temp;
for (int i = 0; i < q.first; i++) {
temp.push_back(hako[i]);
}
for (int i = q.second + 1; i < hako.size(); i++) {
temp.push_back(hako[i]);
}
int val = valueOf(temp, nimotsu);
cout << val << endl;
}
return 0;
} | #include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(int n){
if(n < 10) return n;
return digit(n/10) + n%10;
}
int main(){
int A,B;
cin>>A>>B;
cout<<A/B;
return 0;}
|
#include<bits/stdc++.h>
using namespace std;
int h,m;
int main()
{
scanf("%d %d",&m,&h);
if(h%m==0) printf("Yes");
else printf("No");
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, w;
cin >> n >> w;
cout << n / w;
return 0;
} |
#include<iostream>
using namespace std;
int main()
{
int n;
int min = 100000;
for (int i = 1; i <= 4;i++){
cin >> n;
if(n<min)
min = n;
}
cout << min;
return 0;
} | #include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
#define ll long long int
#define pb push_back
#define RONALDO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<ll, ll>
#define ff first
#define ss second
#define mod 1000000007
#define vi vector<ll>
#define mi map<ll, ll>
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
//LOVE U MEssi10 && ROnaldo7 !!
//INSPIRATIONAL MICHAEL PHELPS && USAIN BOLT !!
int main()
{
RONALDO;
ll a,b,c,d;
cin >> a>>b>>c>>d;
cout << min({a,b,c,d});
return 0;
} |
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
// typedef pair<int,P> IP;
// typedef pair<P,P> PP;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;
ll N;
void dfs(int v, int p, ll d, vector<ll> &dist, vector<vector<P>> &G){
dist[v]=d;
repr(e,G[v]){
if(e.first!=p) dfs(e.first,v,d^e.second,dist,G);
}
}
int main(){
cin>>N;
vector<vector<P>> G(N,vector<P>());
rep(i,N-1){
ll u,v,w;
cin>>u>>v>>w;
u--, v--;
G[u].push_back({v,w});
G[v].push_back({u,w});
}
vector<ll> dist(N,0);
dfs(0,-1,0,dist,G);
vector<ll> cnt(60,0);
rep(i,N){
rep(j,60) cnt[j]+=dist[i]>>j&1;
}
ll ans=0;
ll two=1;
rep(i,60){
ans+=cnt[i]*(N-cnt[i])%MOD*two%MOD;
ans%=MOD;
two*=2;
two%=MOD;
}
cout<<ans<<endl;
return 0;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
//みんなよく解けるなぁ
const int CM = 1 << 17, CL = 20;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
const ll ma10 = ma1 & (1ll << 32) - 1;
inline int getint() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 72 - dig >> 3;
return tmp;
}
const ll pre[9] = { 1,10,100,1000,10000,100000,1000000,10000000,100000000 };
inline ll getll_karini_sakusei() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
if ((tmp & ma0) ^ ma0) {
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += (72 - dig >> 3);
}
else {
tmp = tmp & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 8;
ll tmp2 = *(ll*)ci;
if ((tmp2 & ma0) ^ ma0) {
int dig = 68 - __builtin_ctzll((tmp2 & ma0) ^ ma0);
if (dig == 64) {
ci++;
return tmp;
}
tmp2 = tmp2 << dig & ma1;
tmp2 = tmp2 * 10 + (tmp2 >> 8) & ma2;
tmp2 = tmp2 * 100 + (tmp2 >> 16) & ma3;
tmp2 = tmp2 * 10000 + (tmp2 >> 32) & ma4;
ci += (72 - dig >> 3);
tmp = tmp * pre[64 - dig >> 3] + tmp2;
}
else {
tmp2 = tmp2 & ma1;
tmp2 = tmp2 * 10 + (tmp2 >> 8) & ma2;
tmp2 = tmp2 * 100 + (tmp2 >> 16) & ma3;
tmp2 = tmp2 * 10000 + (tmp2 >> 32) & ma4;
ci += 8;
tmp = tmp * pre[8] + tmp2;
tmp2 = *(ll*)ci;
int dig = 36 - __builtin_ctzll((tmp2 & ma0) ^ ma0);
tmp2 = tmp2 << dig & ma10;
tmp2 = tmp2 * 10 + (tmp2 >> 8) & ma2;
tmp2 = tmp2 * 100 + (tmp2 >> 16) & ma3;
ci += (40 - dig >> 3);
tmp = tmp * pre[32 - dig >> 3] + tmp2;
}
}
return tmp;
}
const int mod = 1e9 + 7;
int to[400001], ne[400001], he[200001], Q[200001], q;
ll w[200001], W[200001];
ll kazu[20];
const ll mk = 1ll << 40 | 1 << 20 | 1, mk2 = (1ll << 20) - 1;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N = getint();
for(int i = 2; i < 2 * N; i++) {
int u = getint(), v = getint();
w[i >> 1] = getll_karini_sakusei();
to[i] = v;
ne[i] = he[u];
he[u] = i++;
to[i] = u;
ne[i] = he[v];
he[v] = i;
}
Q[q++] = 1;
rep(p, N) {
for (int t = he[Q[p]]; t; t = ne[t]) {
int u = to[t];
if (he[u] >= 0) {
W[u] = W[Q[p]] ^ w[t >> 1];
Q[q++] = u;
}
}
he[Q[p]] = -1;
}
ll kotae = 0;
rep1(i, N) {
rep(j, 20) kazu[j] += W[i] >> j & mk;
}
rep(j, 20) rep(k, 3) {
ll tmp = (kazu[j] >> k * 20 & mk2);
kotae += (1ll << k * 20 + j) % mod * tmp % mod * (N - tmp) % mod;
}
co(kotae % mod);
Would you please return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string s;
cin >> s;
map<ll, ll> mp;
for(int i=0; i<s.size(); i++) {
int x = s[i] - '0';
mp[x]++;
}
if(s == "8") {
cout << "Yes" << endl;
return 0;
}
if(s.size() == 2) {
int x = (s[0] - '0') * 10 + (s[1] - '0');
int y = (s[1] - '0') * 10 + (s[0] - '0');
if(x % 8 == 0 || y % 8 == 0) {
cout << "Yes" << endl;
return 0;
}
}
for(int i=1; i<10; i++) {
if(mp[i] <= 0) continue;
mp[i]--;
for(int j=1; j<10; j++) {
if(mp[j] <= 0) continue;
mp[j]--;
for(int k=1; k<10; k++) {
if(mp[k] <= 0) continue;
int a = i, b = j, c = k;
int m = a * 100 + b * 10 + c;
if(m % 8 == 0) {
cout << "Yes" << endl;
return 0;
}
}
mp[j]++;
}
mp[i]++;
}
cout << "No" << endl;
} | #include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>
#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
using ld = long double;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define mod 998244353
using namespace std;
ll modPow(ll a, ll n, ll p){
if(!n) return 1;
if(n == 1) return a % p;
if(n & 1) return (a * modPow(a, n - 1, p)) % p;
ll t = modPow(a, n / 2, p);
return (t * t) % p;
}
struct UnionFind {
vector<int> d;
int n;
UnionFind(int n): n(n), d(n,-1) {}
int root(int x) {
if (d[x] < 0) return x;
return d[x] = root(d[x]);
}
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (d[x] > d[y]) swap(x,y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y){
return root(x) == root(y);
}
int size(int x){
return -d[root(x)];
}
int gorup_num(){
int res = 0;
rep(i, n) if(d[i] < 0) res++;
return res;
}
};
int main(){
int n;
cin >> n;
UnionFind tree(n);
rep(i, n){
int f; cin >> f;
tree.unite(i, f - 1);
}
cout << modPow(2, tree.gorup_num(), mod) - 1 << "\n";
} |
//ABC_199_
//
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define reps(i,s,n) for(int i=s;i<n;++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
int n,m;
cin >> n >> m;
vector<int> X(m),Y(m),Z(m);
rep(i,m) cin >> X[i] >> Y[i] >> Z[i];
vector<ll> dp((1<<n)+5);
dp[0] = 1;
rep(i,n)
{
rep(bit,1<<n)
{
//経っているbit数が桁と一致しなければ飛ばす
int bit_num = 0;
rep(k,n) if((bit>>k)&1)++bit_num;
if(bit_num != i) continue;
//追加する数
rep(add,n)
{
bool ok=true;
if((bit>>add)&1) continue;
//遷移先のbit
int next_bit = bit | (1<<add);
//next_bitへの遷移が可能かどうかMの条件を見ていく
rep(mi,m)
{
if(i+1 != X[mi]) continue;
//y以下でたってるビット数
int bit_num_y = 0;
rep(k,Y[mi]) if((next_bit>>k)&1)++bit_num_y;
//もしZ以上のbitがたっていたら遷移できない
if(bit_num_y>Z[mi]) ok = false;
}
if(ok) dp[next_bit] += dp[bit];
}
}
}
cout << dp[(1<<n)-1] << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007;
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
ostream &operator<<(ostream &o, const string &obj) {o << "\""; o << obj.c_str(); o << "\""; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}
#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif
template <typename... Ts>
std::istream& IN(Ts&... xs){ return (std::cin >> ... >> xs); }
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll a,b,c;
ll ca,cb;
IN(a,b,c);
ca=cb=1;
ll ans = 0;
ll a1=a%10;
a1=(a1*(a%10))%10;
while(a1!=(a%10)){
ca++;
a1=(a1*(a%10))%10;
}
cb = modpow(b,c,ca);
cb = (cb+(ca-1))%ca;
print(ca,cb)
ll ap=a%10;
rep(i,cb){
ap=(ap*(a%10))%10;
}
ans = ap;
cout << ans << endl;
return 0;
}
|
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int mod = 1e9 + 7;
int dp[2][100][100];
int AB[200], *A = AB, *B = AB + 100;
constexpr ll modpow(ll A, ll B) {
ll kotae = 1;
while (B > 0) {
if (B & 1) kotae = kotae * A % mod;
A = A * A % mod;
B >>= 1;
}
return kotae;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M, K;
cin >> N >> M >> K;
rep(i, N) {
cin >> A[i];
}
auto mae = dp[0], ato = dp[1];
int are = modpow(2 * M, mod - 2);
rep(i, M) {
int x, y;
cin >> x >> y;
x--;
y--;
if (x < y) swap(x, y);
mae[x][x]--;
mae[x][y]++;
mae[y][y]--;
}
rep(x, N) rep(y, x + 1) {
mae[x][y] = (ll(mae[x][y] + mod) * are + (x == y)) % mod;
mae[y][x] = mae[x][y];
}
const ll ma = (1ll << 32) - 1;
rep(i, 30) {
if (K >> i & 1) {
rep(i, N) {
ll t1 = 0, t2 = 0;
rep(j, N) {
auto tmp = (ll)mae[i][j] * A[j];
t1 += tmp >> 32;
t2 += tmp & ma;
}
B[i] = ((t1 % mod << 32) + t2) % mod;
}
swap(A, B);
}
if (!K | i >= 31 - __builtin_clz(K)) break;
rep(x, N) rep(y, x + 1) {
auto tmp1 = mae[x];
auto tmp2 = mae[y];
ll t1 = 0, t2 = 0;
rep(z, N) {
auto tmp = *tmp1++ * (ll)*tmp2++;
t1 += tmp >> 32;
t2 += tmp & ma;
}
ato[y][x] = (ato[x][y] = ((t1 % mod << 32) + t2) % mod);
}
swap(mae, ato);
}
rep(i, N) co(A[i]);
Would you please return 0;
} | /*
* TheMartian0x48
*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// clang-format off
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define rll(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<long long>;
// (* read and write *)
template <class T>
void re(vector<T> &v, int n) {v.resize(n); for (auto &e : v) cin >> e;}
template <class T>
void re(vector<T> &v){for (auto &e : v) cin >> e;}
// clang-format on
void solve() {
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a, b, c; cin >> a >> b >> c;
int res = max(a + b, a + c);
res = max(res, b + c);
cout << res;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define f(i,a,b) for(ll i = a; i < (ll) b ; i++ )
#define af(i,a,b) for(ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < (ll) b ; i+= k )
#define arep(i,a,b,k) for(ll i = a; i >= (ll) b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define sz(a) (ll) a.size()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(0)
// policy-based
using namespace std;
typedef long long ll; // int or ll
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll> vi ;
typedef vector<ii> vii ;
const ll MAX = 1e6 + 20;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
vi adj[MAX];
ll dp[MAX],sz[MAX];
void dfs(ll u){
vi imp;
vii par;
sz[u] = 1;
dp[u] = 1;
for(ll v:adj[u]){
dfs(v);
sz[u] += sz[v];
if(sz[v]%2 == 0) imp.push_back(v);
else par.push_back({2*dp[v]- sz[v],v});
}
ll sum = 0,sum1 = 0;
//cout << u << " ::: " << endl;
for(ll v:imp){
// cout << v <<" ";
if(dp[v] <= sz[v] - dp[v])
dp[u] += dp[v];
else
sum += dp[v],sum1 += sz[v] - dp[v];
}
ll t = 1;
sort(all(par));
for(auto it:par){
ll v = it.ss;
// cout << v <<" - ";
if(t) dp[u] += dp[v];
else dp[u] += sz[v] - dp[v];
t = 1-t;
}
// cout << endl;
if(t) dp[u] += sum;
else dp[u] += sum1;
// cout << u << " :" << dp[u] << endl << endl;
}
int main(){
fastio;
ll n,p;
cin >> n;
f(i,2,n+1){
cin >> p;
adj[p].push_back(i);
}
dfs(1);
cout << dp[1] << endl;
return 0;
} | #define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e9+6969;
int n,dp[nax],last[nax];
bool vis[nax];
vi v[nax];
void dfs(int a, int dad)
{
dp[a] = 1;
int bad = 0;
vi t;
for(auto e: v[a])
{
if(e == dad) continue;
dfs(e,a);
if(last[e])
{
if(dp[e] <= 0) dp[a] += dp[e];
else bad += dp[e];
}
else t.pb(dp[e]);
}
if(t.size()&1)
{
last[a] = 1;
dp[a] -= bad;
}
else
{
last[a] = 0;
dp[a] += bad;
}
sort(all(t));
for(int i=0;i<t.size();i++)
{
if(i&1) dp[a] -= t[i];
else dp[a] += t[i];
}
}
int main()
{
scanf("%d", &n);
for(int i=2;i<=n;i++)
{
int x;
scanf("%d", &x);
v[x].pb(i);
v[i].pb(x);
}
dfs(1,1);
// for(int i=1;i<=n;i++) cout << dp[i] << " " << last[i] << "\n";
cout << (n+dp[1])/2 << "\n";
return 0;
}
|
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 1;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
void solve() {
int n; cin >> n;
vector<int> a(n);
rep(i, n)cin >> a[i];
sort(all(a));
vector<ll> ra(n + 1);
rep(i, n)ra[i + 1] = ra[i] + a[i];
ld ans = INF;
rep(i, n) {
//[0,i]
//x=a[i]/2
ld x = a[i] / 2.0;
ld sum = x * (i + 1);
sum -= x * (n - 1 - i);
sum += ra[n] - ra[i + 1];
ans = min(ans, sum / (ld)n);
}
ans = min(ans, ra[n] / (ld)n);
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
//init_f();
//init(); cout << ps.size() << "\n";
//expr();
//int t; cin >> t; rep(i, t)
solve();
return 0;
}
| // #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lld long double
#define w(x) ll x;cin>>x;while(x--)
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __detail::__lcm(a,b)
#define goog(tno) cout << "Case #" << tno <<": "
#define PRESS_F_TO_PAY_RESPECT ios_base::sync_with_stdio(false), cin.tie(nullptr)
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define bug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define bug(x...)
#endif
ll dx[]= {-1,-1,-1,0,0,1,1,1};
ll dy[]= {-1,0,1,-1,1,-1,0,1};
const lld pi=3.1415926535897932384626433832795;
const ll INF=1e18;
const ll mod=1000000007;
const ll maxn=1e5+5;
template<typename T>
void printv(const vector<T>& v) { for(auto i:v) cout<<i<<' '; cout<<'\n'; }
template<typename T>
void printv(const vector<pair<T, T>>& v) { for(auto p:v) cout<<"("<<p.first<<","<<p.second<<"),"; cout<<'\n'; }
int main(){
PRESS_F_TO_PAY_RESPECT;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
string x; cin>>x;
bool f=0;
for(auto &i:x){
if(i=='.'){
f=1;
break;
}
}
if(!f){
cout<<x<<'\n';
}else{
ll n=x.size();
ll i;
for(i=0;i<n;i++){
if(x[i]=='.'){
break;
}
}
cout<<x.substr(0,i)<<'\n';
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,ans=0;
double x[2010][5];
cin>>n;
for(int i=0;i<n;i++)
for(int j=0;j<3;j++){
cin>>x[i][j];
if(x[i][0]==2)
x[i][2]-=0.1;
if(x[i][0]==3)
x[i][1]+=0.1;
if(x[i][0]==4){
x[i][1]+=0.1;
x[i][2]-=0.1;
}
}
for(int k=0;k<n;k++)
for(int u=k+1;u<n;u++){
if(max(x[u][1],x[k][1])<=min(x[u][2],x[k][2]))
ans++;
}
cout<<ans<<endl;
return 0;
} | // Daniel Grzegorzewski15
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#define MP make_pair
#define PB push_back
#define ST first
#define ND second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const int N = 2003;
int n, res, t[N], l[N], r[N], in[N];
bool cmp(int i, int j) {
return l[i] < l[j];
}
int main() {
init_ios();
cin >> n;
for (int i = 1; i <= n; ++i) {
in[i] = i;
cin >> t[i] >> l[i] >> r[i];
}
sort(in+1, in+n+1, cmp);
for (int i = 1; i <= n; ++i)
for (int j = i+1; j <= n; ++j) {
int p = in[i], q = in[j];
if (l[q] <= r[p]) {
if (l[q] == r[p]) {
if (t[p] == 2 || t[p] == 4 || t[q] == 3 || t[q] == 4)
continue;
}
++res;
}
}
cout<<res<<"\n";
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<(2*a+100)-b<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
template <typename T> bool chmax(T& a, const T& b); //aよりもbが大きいならばaをbで更新する //更新されたならばtrueを返す
template <typename T> bool chmin(T& a, const T& b); //aよりもbが小さいならばaをbで更新する //更新されたならばtrueを返す
int main() {
int a, b;
cin >> a >> b;
cout << 2 * a + 100 - b << endl;
return 0;
}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
if (a < b) {
a = b; // aをbで更新
return true;
}
return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T& a, const T& b) {
if (a > b) {
a = b; // aをbで更新
return true;
}
return false;
} |
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <string>
#include <bitset>
#include <numeric>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define manytests int TT;cin >> TT; while (TT--)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORd(i,a,b) for (int i = (a); i >= (b); --i)
int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, 1, -1, 1, 1, -1, -1};
#define ll long long
#define ld long double
#define fi first
#define se second
#define rev reverse
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vd vector<double>
#define vs vector<string>
#define vld vector<ld>
#define vb vector<bool>
#define vvi vector<vi>
#define pii pair<int, int>
#define pl pair<ll, ll>
#define pld pair<ld, ld>
#define vpi vector<pii>
#define vpl vector<pl>
#define vpld vector<pld>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a, b, c;
cin >> a >> b >> c;
if (!c) {
int cnt = 0;
while (true) {
if (cnt%2==0) {
if (!a) return cout << "Aoki\n", 0;
a--;
} else {
if (!b) return cout << "Takahashi\n", 0;
b--;
}
cnt++;
}
} else {
int cnt = 0;
while (true) {
if (cnt%2==1) {
if (!a) return cout << "Aoki\n", 0;
a--;
} else {
if (!b) return cout << "Takahashi\n", 0;
b--;
}
cnt++;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define print(v,n) for(i=0;i<n;i++) cout<<v[i]<<" ";
#define No cout<<"NO"<<endl;return
#define Yes cout<<"YES"<<endl;return
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
#define PI 3.14159265 ;
ll mod =1e9+7;
bool isPrime(int n)
{
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i*i <= n; i = i + 6)
if (n%i == 0 || n % (i + 2) == 0)
return false;
return true;
}
ll powe(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1) res =( res * x)%mod;
y = y >> 1;
x = (x * x)%mod;
}
return res;
}
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
unsigned long long power(unsigned long long x, int y, int p)
{
unsigned long long res = 1; // Initialize result
x = x % p; // Update x if it is more than or
while (y > 0)
{
if (y & 1) res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
unsigned long long modInverse(unsigned long long n,int p)
{
return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n,int r, int p)
{
if (n < r)
return 0;
// Base case
if (r == 0)
return 1;
unsigned long long fac[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = (fac[i - 1] * i) % p;
return (fac[n] * modInverse(fac[r], p) % p
* modInverse(fac[n - r], p) % p)
% p;
}
bool cmp(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
if(a.ss<b.ss) return true;
return false;
}
bool cmp2(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
if(a.ff<b.ff) return true;
if(a.ff==b.ff) return a.ss<b.ss;
return false;
}
void solve()
{
ll i,x,y,m, j, k, h, n, w, k1, k2,k3,q;
cin>>x>>y>>k;
if(k==0)
{
if(x>=y+1)
{
cout<<"Takahashi"<<ee;
return;
}
cout<<"Aoki"<<ee;
return;
}
if(y>=x+1 ) cout<<"Aoki"<<ee;
else cout<<"Takahashi"<<ee;
}
int main() {
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll i, j, l, k, t, n;
t=1;
for (i = 1; i <= t; i++)
{
//cout<<"Case #"<<i<<": ";
solve();
}
}
// |
#include <bits/stdc++.h>
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl
#define dump(x) cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(2)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>
typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
cin>>head;
CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
x %= MOD;
x += MOD;
x %= MOD;
}
ll GCD(ll a, ll b) {
if(b == 0) return a;
else return GCD(b, a%b);
}
struct COMB{
vl fact, fact_inv, inv;
void init_nCk(long long SIZE) {
fact.resize(SIZE + 5);
fact_inv.resize(SIZE + 5);
inv.resize(SIZE + 5);
fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
for(long long i = 2; i < SIZE + 5; i++) {
fact.at(i) = fact.at(i - 1)*i%MOD;
inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
}
}
long long nCk (long long n, long long k) {
assert(!(n < k));
assert(!(n < 0 || k < 0));
return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
}
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a%b, y, x);
y -= a/b*x;
return d;
}
void dfs(vector<queue<int> > &m, vector<int> &used, int n, vector<int> &C, vector<int> &S, vector<int> &l, ll from) {
// dump(n);
// dump(C.at(n));
if(S.at(C.at(n))) {
used.at(n) = -1;
} else {
used.at(n) = 1;
l.at(n) = 1;
}
S.at(C.at(n))++;
while(m.at(n).size()) {
if(used.at(m.at(n).front()) == 0) {
dfs(m, used, m.at(n).front(), C, S, l, n);
}
m.at(n).pop();
}
if(from != -1) {
S.at(C.at(n))--;
}
}
void Main() {
CIN(N);
vector<int> C(N);
VECCIN(C);
vector<queue<int> > m(N);
for(int i = 0; i < N - 1; i++) {
CIN(a, b);
--a;
--b;
m.at(a).push(b);
m.at(b).push(a);
}
vector<int> used(N, 0);
vector<int> ansl(N, 0);
ll ans = 0;
vector<int> s(1e5 + 10, 0);
// s.insert(C.at(0));
dfs(m, used, 0, C, s, ansl, -1);
for(int i = 0; i < N; i++) {
if(ansl.at(i) == 1) cout << i + 1 << endl;
}
// VECCOUT(used);
// cout << ans << endl;
}
int main() {
cout << fixed << setprecision(15);
Main();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int x, y;
int a, b;
cin >> a >> b;
x = (a + b)/2;
y = (a-b)/2;
cout << x << " " << y << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
const int MD = 1000000007;
long long inv(int n) {
return n == 1 ? 1 : inv(n - MD % n) * (MD / n + 1) % MD;
}
long long choose(int n, int k) {
return n < k ? 0 : k == 0 ? 1 : choose(n - 1, k - 1) * n % MD * inv(k) % MD;
}
int main() {
int n, m, k; cin >> n >> m >> k;
if (n - m >= k + 1) {
cout << "0\n";
return 0;
}
int ans = choose(n + m, n) - choose(n + m, n + (k + 1 - (n - m)));
if (ans < 0)
ans += MD;
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
// LMAX = 18446744073709551615 (1.8*10^19)
// IMAX = 2147483647 (2.1*10^9)
/*
*/
//nCk
const ll MAX = 2000010;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
fac[0] = fac[1]=1;
finv[0] = finv[1]=1;
inv[1] = 1;
for(int i=2; i<MAX; i++){
fac[i] = fac[i-1] * i % MOD;
inv[i] = MOD-inv[MOD%i] * (MOD/i) % MOD;
finv[i] = finv[i-1] * inv[i] % MOD;//逆元の階上
}
}
ll COM(int n, int k){
if(n==0 || k==0) return 1;
if (n<k)
return 0;
if (n<0 || k<0)
return 0;
return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
//modpow
ll modpow(ll a, ll n){//a^n
if (n == 0) return 1;
if (n == 1) return a % MOD;
if (n%2 == 1) return (a * modpow(a, n - 1)) % MOD;
else {
ll t = modpow(a, n / 2) % MOD;
return (t * t) % MOD;
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
COMinit();
ll N, M, K;
cin >> N >> M >> K;
if (M+K<N){
cout << 0 << endl;
return 0;
}
ll total = COM(N+M, N);
// cout << total << endl;
ll cnt = 0;
for(ll i=K; i<N+M; i+=2){ // 左側の総数
++cnt;
if (N < K+cnt) break;
total -= (((COM(i, K+cnt-1) * (K+1))%MOD * modpow(K+cnt, MOD-2))%MOD * COM(N+M - (i+1), M-(cnt-1)))%MOD;
// cout << "total:" << total <<" i:" << i << " K+cnt-1:" << K+cnt-1 << " N+M-(i+1):" << N+M - (i+1) << " M-(cnt-1):" << M-(cnt-1) << endl;
total += MOD;
total %= MOD;
}
cout << total << endl;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5 + 5;
char s[MAXN];
int main(void)
{
int n;
scanf("%d%s",&n,s+1);
if(s[1] != s[n]) return printf("1"), 0;
for(int i=1; i<n; ++i)
if(s[i] != s[1] && s[i+1] != s[1])
return printf("2"), 0;
printf("-1");
return 0;
} | /*CP is fun!*/
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
using namespace std;
const int MAXN=2e5+5;
const int MOD=1e9+7;
const int MAX=205;
ll powerm(ll a,ll b,ll m) { //m-> mod
if(b==0) {
return 1;
}
ll res=powerm(a,b/2,m);
if(b%2) {
return ((res*res)%m*(a%m))%m;
}
return (res*res)%m;
}
//INVERSE -> a^(m-2) ...m -> prime
int power(ll a,ll b) {
if(b==0) {
return 1;
}
ll res=power(a,b/2);
if(b%2==0) {
return res*res;
}
return res*res*a;
}
/*vector<int>fac(1e5);
void facm(ll m) { //factorial mod precompute
fac[0]=1;
for(int i=1;i<fac.size();i++) { //name an array fac
fac[i]=((i)%m*fac[i-1])%m;
}
return;
}
ll choose(ll a,ll b,ll m) { //a choose b mod m
if(a<b) {
return 1;
}
ll ans=((fac[a]*(powerm(fac[a-b],m-2,m)))%m*powerm(fac[b],m-2,m))%m;
return ans;
}*/
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<setprecision(9)<<fixed;
//freopen("diamond.in","r",stdin);
//freopen("diamond.out","w",stdout);
int n;
cin>>n;
string s;
cin>>s;
s.pb('z');
int dp[n+1][26][2];
for(int j=0;j<26;j++) {
dp[n][j][0]=0;
dp[n][j][1]=1e15;
}
for(int i=n-1;i>=0;i--) {
for(int j=0;j<26;j++) {
dp[i][j][0]=dp[i+1][j][1];
if(s[i]!=j+'a') {
dp[i][j][1]=min(1+dp[i+1][s[i+1]-'a'][0],dp[i+1][j][1]);
} else {
dp[i][j][1]=dp[i+1][j][1];
}
}
}
if(dp[0][s[0]-'a'][0]>=1e10) {
cout<<-1;
} else {
cout<<dp[0][s[0]-'a'][0];
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<vector<int> > v;
for(int i = 0 ; i < n ; i++) {
vector<int> temp(5);
for(int i = 0 ; i < 5 ; i++) {
cin >> temp[i];
}
v.push_back(temp);
}
vector<vector<int> > A(n);
A[n-1]=v[n-1];
for(int i=n-2; i>=0; i--) {
if(A[i+1][0]>v[i][0]) {
A[i]=A[i+1];
} else {
A[i]=v[i];
}
}
vector<vector<int> > B(n);
B[n-1]=v[n-1];
for(int i=n-2; i>=0; i--) {
if(B[i+1][1]>v[i][1]) {
B[i]=B[i+1];
} else {
B[i]=v[i];
}
}
vector<vector<int> > C(n);
C[n-1]=v[n-1];
for(int i=n-2; i>=0; i--) {
if(C[i+1][2]>v[i][2]) {
C[i]=C[i+1];
} else {
C[i]=v[i];
}
}
vector<vector<int> > D(n);
D[n-1]=v[n-1];
for(int i=n-2; i>=0; i--) {
if(D[i+1][3]>v[i][3]) {
D[i]=D[i+1];
} else {
D[i]=v[i];
}
}
vector<vector<int> > E(n);
E[n-1]=v[n-1];
for(int i=n-2; i>=0; i--) {
if(E[i+1][4]>v[i][4]) {
E[i]=E[i+1];
} else {
E[i]=v[i];
}
}
int res=0;
for(int i=0; i<n; i++) {
for(int j=i+1; j<n-1; j++) {
for(int k=0; k<5; k++) {
vector<int> *side;
if(k==0) {
side=&A[j+1];
} else if(k==1) {
side=&B[j+1];
} else if(k==2) {
side=&C[j+1];
} else if(k==3) {
side=&D[j+1];
} else if(k==4) {
side=&E[j+1];
}
int foo=INT_MAX;
for(int k=0; k<5; k++) {
foo = min(foo,max(v[i][k],max((*side)[k],v[j][k])));
}
res = max(res,foo);
}
}
}
cout << res << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int charToInt(char c){
char zero_num = '0';
return (int)c - (int)zero_num;
}
int search(vec_int& DP, vector<vec_int>& G, vec_int& A, int town){
if(G.at(town).size()==0){
DP.at(town) = A.at(town-1);
return A.at(town-1);
}
if(DP.at(town)>=0){
return DP.at(town);
}
int result = -1;
for(auto next_town: G.at(town)){
int temp = search(DP, G, A, next_town);
result = max(temp, result);
}
result = max(A.at(town-1), result);
DP.at(town) = result;
return result;
}
signed main(){
int N; cin>>N;
int M; cin>>M;
vec_int A(N); rep(i,N)cin>>A.at(i);
vec_int X(M);
vec_int Y(M);
rep(i,M)cin>>X.at(i)>>Y.at(i);
vector<vec_int> G(N+1);
vector<vec_int> G2(N+1);
rep(i,M){
G.at(X.at(i)).push_back(Y.at(i));
}
vec_int DP(N+1, -1);
int ans = -1*pow(10,12);
for(int i=1;i<=N;i++){
if(G.at(i).size()==0)continue;
int temp = search(DP, G, A, i);
int max_val = -1;
for(auto next_city:G.at(i)){
max_val = max(max_val, DP.at(next_city));
}
ans = max(ans, max_val- A.at(i-1));
}
cout<<ans<<endl;
return 0;
} |
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
//#define mod 998244353
#define inf 1e18
#define PI 3.14159265
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define clr(x,n) x.clear();x.resize(n,0)
#define precise(x) fixed<<setprecision(x)
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> pbds;
/**
* author: nayakashutosh9
* created: [2021-04-11 19:52]
* "Compete against yourself"
**/
const int N = 1e5 + 5;
int n;
vi a, g[N];
bool vis[N];
set<int> ans;
void dfs(int node, int par) {
if (vis[a[node]] == 0) {
ans.insert(node);
}
bool prev = vis[a[node]];
vis[a[node]] = 1;
for (int j : g[node]) {
if (j != par) dfs(j, node);
}
vis[a[node]] = prev;
}
void solve() {
cin >> n;
clr(a, n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i <= n; i++) g[i].clear();
for (int i = 1; i < n; i++) {
int x, y; cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
memset(vis, 0, sizeof(vis));
ans.clear();
dfs(1, 0);
for (int i : ans) cout << i << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T = 1;
//cin >> T; cin.ignore();
for (int i = 1; i <= T; i++) {
//cout << "Case #" << i << ": ";
// clock_t start = clock();
solve();
// clock_t end = clock();
// cout << (end-start) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> A(N), B(N);
vector<vector<int>> G(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--, b--;
A[i] = a;
B[i] = b;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
vector<int> C(N, -1);
C[0] = -2;
{
queue<int> que;
que.push(0);
while (!que.empty()) {
auto u = que.front();
que.pop();
for (int v : G[u]) {
if (C[v] != -1) continue;
C[v] = u;
que.push(v);
}
}
}
int Q;
cin >> Q;
vector<int64_t> res(N, 0);
for (int q = 0; q < Q; q++) {
int t, e;
int64_t x;
cin >> t >> e >> x;
e--;
if (t == 1) {
if (A[e] == C[B[e]]) {
res[0] += x;
res[B[e]] -= x;
} else {
res[A[e]] += x;
}
} else {
if (A[e] == C[B[e]]) {
res[B[e]] += x;
} else {
res[0] += x;
res[A[e]] -= x;
}
}
}
{
queue<int> que;
que.push(0);
vector<bool> used(N, false);
used[0] = true;
while (!que.empty()) {
auto u = que.front();
que.pop();
for (int v : G[u]) {
if (used[v]) continue;
que.push(v);
used[v] = true;
res[v] += res[u];
}
}
}
for (int i = 0; i < N; i++) {
cout << res[i] << '\n';
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
int A=0,B=0,C=0;
cin>>A>>B>>C;
cout<<(B*C-1)/A<<endl;
return 0;
}
| // RAKSHIT KADAM
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update>
// find_by_order returns iterator to element present at that index...
// order_of_key returns no. of elements having value stricktly less than that given in the order_of_key();
#warning !!!check the size of arrayss!!!
// NUMERIC DEFINITIONS :
#define inf 1000000003
#define MOD 1000000007
#define newMOD 998244353
#define MAX 200006
#define pi 3.1415926535897932384626433832795
#define ld long double
#define ll long long
#define int long long
#define INF 1000000000000000008
#define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define satisfy cerr<<"\n\n---------------Running on multiple test cases--------------"<<endl;ll t; cin>> t; while(t--)
#define mp make_pair
#define pb push_back
#define endl "\n"
#define x first
#define y second
#define Endl endl
#define pii pair<ll,ll>
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m; p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn = 500004;
//ll fact[300007] = {0};
//void facto() {fact[0] = 1; fact[1] = 1; for(int i = 2; i < 300005; i++){fact[i] = (fact[i-1]*i)%MOD;}}
//ll ncr(ll n, ll r)
//{
// if(r>n)return 0;
// ll res = 1;
// res = fact[n];
// res*=modInverse(fact[r],MOD);
// res%=MOD;
// res*=modInverse(fact[n-r],MOD);
// res%=MOD;
// return res;
//}
//vector<ll>primes;
void solve()
{
double x,y,z;
cin>>x>>y>>z;
ll i=0;
while(y/x>(double(i))/z)i++;
cout<<--i<<endl;
}
signed main()
{
Need_for_speed(activated);
// satisfy
// { solve();
// }
solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define M 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define ld long double
#define nline "\n"
#define all(x) (x).begin(), (x).end()
// memset(matrix, 0, sizeof(matrix));
// for debug
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
inline int mod(int x) {return (x % M + M) % M;}
inline int add(int a, int b) {return mod(mod(a) + mod(b));}
inline int sub(int a, int b) {return mod(mod(a) - mod(b) + M);}
inline int mul(int a, int b) {return mod(mod(a) * mod(b));}
inline int power(int a, int p) {int r = 1; while (p) { if (p & 1) r = mul(r, a); a = mul(a, a); p >>= 1; } return r;}
inline int modInv(int a) {return power(a, M - 2);}
inline int divi(int a, int b) {return mul(a, modInv(b));}
inline int fact(int a) {int r = 1; while (a) { r = mul(r, a); a--; } return r;}
inline int ncr(int n, int r) {return mul(mul(fact(n), modInv(fact(n - r))), modInv(fact(r)));}
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b);}
inline int ceil(int x, int y) {if (x % y == 0) {return x / y;} return x / y + 1;}
void solve()
{
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
map<int, vector<int> > h;
for (int i = 0; i < n; i++)
{
h[arr[i]].push_back(i);
}
int ans = 0;
for (auto x : h)
{
if (x.second.size() >= 2)
{
ans += (x.second.size() * (x.second.size() - 1)) / 2;
}
}
int v = (n - 1) * n / 2;
cout << v - ans << nline;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("debug.txt", "w", stderr);
#endif
// w(t)
// {
// solve();
// }
solve();
return 0;
} | #include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define m_p make_pair
#define pb push_back
#define ld long double
#define fi first
#define se second
#define ull unsigned long long
#define mod 1000000007
#define md 998244353
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define int ll
using namespace std;
inline void read(int &x){
short negative=1;
x=0;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')negative=-1;
c=getchar();
}
while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
x*=negative;
}
ll qpow(ll n,ll k){
ll ans=1;
while(k){
if(k%2){
ans*=n;
ans%=mod;
}
n*=n;
n%=mod;
k/=2;
}
return ans;
}
const int N=200010;
int n;
int a[N];
int b[N];
int c[N];
int bit[N];
vector<int>v;
queue<int>q[N];
map<int,int>mp;
int lowbit(int x){
return x&(-x);
}
void add(int pos,int val){
while(pos<=n){
bit[pos]+=val;
pos+=lowbit(pos);
}
}
int getsum(int pos){
int res=0;
while(pos>=1){
res+=bit[pos];
pos-=lowbit(pos);
}
return res;
}
signed main(){
ios::sync_with_stdio(0);
cin>>n;
forn(i,1,n)cin>>a[i],a[i]+=i;
forn(i,1,n)cin>>b[i],b[i]+=i;
forn(i,1,n){
v.pb(b[i]);
}
forn(i,1,n){
mp[b[i]]=i;
}
forn(i,1,n){
q[mp[b[i]]].push(i);
}
forn(i,1,n){
if(mp[a[i]]<1||q[mp[a[i]]].empty()){
cout<<-1<<"\n";
return 0;
}
c[i]=q[mp[a[i]]].front();
q[mp[a[i]]].pop();
}
int ans=0;
forn(i,1,n){
add(c[i],1);
ans+=i-getsum(c[i]);
}
cout<<ans<<"\n";
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const int M=2e5+5;
const int N=1e3+5;
#define int long long
int Max(int x,int y){return x>y?x:y;}
int Min(int x,int y){return x>y?y:x;}
int Abs(int x){return x>0?x:-x;}
void write (int x) {
if (x < 0) {
putchar ('-');
x = (~x) + 1;
}
if (x > 9) {
write (x / 10);
}
putchar (x % 10 + '0');
}
int read () {
int f = 1, num = 0;
char s = getchar ();
while (s > '9' || s < '0') {
if (s == '-') f = -1;
s = getchar ();
}
while (s >= '0' && s <= '9') {
num = (num << 3) + (num << 1) + (s - '0');
s = getchar ();
}
return num *= f;
}
int Bit[M];
int H[M],W[M];
int n,m,K;
int ans;
vector<int> G[M];
int lowbit(int x){
return x&(-x);
}
int Sum(int x){
int res=0;
for(int i=x;i>=1;i-=lowbit(i)){
res+=Bit[i];
}
return res;
}
void update(int x,int y){
for(int i=x;i<=n;i+=lowbit(i)){
Bit[i]+=y;
}
}
signed main(){
n=read(),m=read(),K=read();
for(int i=0;i<=n+1;i++) H[i]=m+1;
for(int i=0;i<=m+1;i++) W[i]=n+1;
for(int i=1;i<=K;i++){
int x=read(),y=read();
H[x]=Min(H[x],y);
W[y]=Min(W[y],x);
}
// for(int i=1;i<=n;i++){
// printf("%d\n",H[i]);
// }
// for(int i=1;i<=m;i++){
// printf("%d\n",W[i]);
// }
for(int i=1;i<=n;i++){
if(H[i]==1){
for(int j=i+1;j<=n;j++) H[j]=1;
break;
}
ans+=H[i]-1;
}
for(int i=1;i<=n;i++){
G[H[i]].push_back(i);
}
for(int i=1;i<=m;i++){
if(W[i]==1) break;
ans+=Sum(W[i]-1);
for(int j=0;j<G[i].size();j++){
update(G[i][j],1);
}
}
printf("%lld",ans);
return 0;
} | // atcoder/abc186/F/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/
#include <bits/stdc++.h>
#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))
using namespace std;
template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }
template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;
constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;
template<typename T>
struct SegTree {
int n;
int origin_size;
vector<T> v;
using F = function<T(T, T)>;
F fn;
T e;
SegTree(int n_, T e_, F fn_) {
origin_size = n_;
e = e_;
fn = fn_;
n = 1;
while (n < n_) n *= 2;
v.resize(2 * n - 1, e);
}
void update(size_t k, T a) {
k += n - 1;
v[k] = a;
while (k > 0) {
k = (k - 1) / 2;
v[k] = fn(v[k * 2 + 1], v[k * 2 + 2]);
}
return ;
}
T operator [] (size_t idx) const {
return v.at(idx + n - 1);
}
inline T operator () () const {
return query(0, origin_size, 0, 0, n);
}
inline T operator () (size_t a) const {
return query(a, a+1, 0, 0, n);
}
inline T operator () (size_t a, size_t b) const {
return query(a, b, 0, 0, n);
}
inline T query(size_t a, size_t b) const {
assert(a < b);
assert(b <= origin_size);
return query(a, b, 0, 0, n);
}
T query(size_t a, size_t b, size_t k, size_t l, size_t r) const {
if (r <= a || b <= l) return e;
if (a <= l && r <= b) return v.at(k);
T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return fn(vl, vr);
}
};
int main(int argc, char *argv[])
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.setf(ios_base::fixed);
cout.precision(15);
lli h, w;
int m;
while (cin >> h >> w >> m) {
vec<pair<lli, lli>> v(m);
cin >> v;
each (i, v) --i.first, --i.second;
const int N = 2 * 1e5 + 5;
const lli inf = 1LL << 60;
static lli mn[N];
fill(mn, mn + N, h);
each (i, v) {
setmin(mn[i.second], i.first);
}
lli sum = 0;
for (int j = 0; j < w; ++j) {
if (mn[j] == 0) break;
sum += mn[j];
}
static vec<int> u[N];
fill(u, u + N, vec<int>());
each (i, v) {
u[i.first].push_back(i.second);
}
for (int i = 0; i < N; ++i) {
sort(u[i].begin(), u[i].end());
}
if (u[0].size()) {
for (int j = u[0].front(); j < w; ++j) {
u[0].push_back(j);
}
}
SegTree<int> segtree(N, 0, [] (int a , int b) { return a + b; });
for (int i = 1; i < h; ++i) {
if (u[i].size() && u[i].front() == 0) break;
each (j, u[i - 1]) {
segtree.update(j, 1);
}
sum += segtree.query(0, (u[i].empty() ? w : u[i].front()));
}
cout << sum << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pld> vpld;
typedef unordered_map<int, int> mpii;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed;
cout.precision(17);
ll k; cin >> k;
cin.ignore();
string s; getline(cin, s);
string t; getline(cin, t);
vl vec(10, k);
unordered_map<int, int> S, T;
for (const auto &a : s) S[a - '0']++, vec[a - '0']--;
for (const auto &a : t) T[a - '0']++, vec[a - '0']--;
auto calc = [](auto &cnt) {
ll ret = 0;
for (int i = 1; i <= 9; i++) ret += i * powl(10, cnt[i]);
return ret;
};
ll ans = 0;
for (int i = 1; i <= 10; i++) {
if (!vec[i]) continue;
--vec[i];
for (int j = 1; j <= 10; j++) {
if (!vec[j]) continue;
S[i]++;
T[j]++;
if (calc(S) > calc(T)) { //ok win
if (i == j) ans += vec[i] * (vec[i] + 1);
else ans += (vec[i] + 1) * vec[j];
//cout << i << " " << j << "\n";
}
S[i]--;
T[j]--;
}
++vec[i];
}
ld cnt = 9 * k - 8;
cout << ans / (cnt * (cnt - 1));
}
| /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author aajisaka
*/
#include<bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
class DPoker {
public:
void solve(istream& cin, ostream& cout) {
SPEED;
int k; cin >> k;
string s; cin >> s;
string t; cin >> t;
vector<ll> cnts(10);
vector<ll> cntt(10);
vector<ll> cnt(10, k);
rep(i, 4) {
cnts[s[i]-'0']++;
cntt[t[i]-'0']++;
cnt[s[i]-'0']--;
cnt[t[i]-'0']--;
}
ll all = 9*k-8;
ll allc = all*(all-1);
double ret = 0;
for(int i=1; i<=9; i++) {
cnts[i]++;
ll takahashi = 0;
for(int a=1; a<=9; a++) {
ll now = a;
int tmp = cnts[a];
while(tmp--) {
now *= 10;
}
takahashi += now;
}
cnts[i]--;
for(int j=1; j<=9; j++) {
double p = 0;
if (i==j) {
ll c = cnt[i]*(cnt[i]-1);
p = (double)c/(double)allc;
} else {
ll c = cnt[i] * cnt[j];
p = (double)c/(double)allc;
}
cntt[j]++;
ll aoki = 0;
for(int a=1; a<=9; a++) {
ll now = a;
int tmp = cntt[a];
while(tmp--) {
now *= 10;
}
aoki += now;
}
cntt[j]--;
debug(i, j, takahashi, aoki, p);
if (takahashi > aoki) {
ret += p;
}
}
}
cout << setprecision(10) << fixed;
cout << ret << endl;
}
};
signed main() {
DPoker solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int>pi;
typedef pair<long long, long long>pl;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin() , x.end()
#define mp make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mem(a) memset(a , 0 ,sizeof a)
#define memn(a) memset(a , -1 ,sizeof a)
int main()
{
int t = 1;
//cin >> t;
while (t--)
{
ll n, i, x, y, s = 0, j;
cin >> n;
ll a[n + 3];
unordered_map<ll,ll>m;
for (i = 1; i <= n; i++)
{
cin >> x;
m[x]++;
}
for (auto i = m.begin(); i != m.end(); i++)
{
for (auto j = next(i); j != m.end(); j++)
{
// x =(i->first - j->first);
// x=x*x;
// x = x * (i->second * j->second);
// s += x;
s+=i->second * j->second * ceil(pow(i->first - j->first, 2));
}
}
cout<<s<<endl;
}
}
| #include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif
namespace templates{
ll modpow(ll x, ll b,ll mod=MOD){
ll res = 1;
while(b){
if(b&1)res = res * x % mod;
x = x * x % mod;
b>>=1;
}
return res;
}
ll modinv(ll x){
return modpow(x, MOD-2);
}
bool was_output = false;
template<class t>
void output(t a){
if(was_output)cout << " ";
cout << a;
was_output = true;
}
void outendl(){
was_output = false;
cout << endl;
}
template<class t>
istream& operator>>(istream&is, vector<t>&x){
for(auto &i:x)is >> i;
return is;
}
template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
is >> x.first >> x.second;
return is;
}
template<class t>
ostream& operator<<(ostream&os, vector<t> &v){
os << "{";
for(t &i:v){
os << i << ", ";
}
os << "}";
return os;
}
template<class t = long long>
t in(){
t res; cin >> res; return res;
}
template<class t>
void out(t x){
cout << x;
}
template<class t>
vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
sort(line.begin(),line.end(),comp);
return line;
}
template<class t>
vector<t> reversed(vector<t> line){
reverse(line.begin(),line.end());
return line;
}
string reversed(string str){
reverse(str.begin(),str.end());
return str;
}
long long gcd(long long a,long long b){
while(b){
a %= b;
swap(a,b);
}
return a;
}
long long lcm(long long a,long long b){
return a / gcd(a,b) * b;
}
}
using namespace templates;
string func(){
int n = in();
vector<string> strs(3);
foreach(i,strs)i=in<string>();
string res = "";
rep(_,n)res += "1";
rep(_,n)res += "0";
res += "1";
return res;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n = in();
rep(i,n){
cout << func() << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
int A, B, W;
cin >> A >> B >> W;
int mi = INT_MAX, ma = INT_MIN;
for (int i = 1; i <= 1000000; i++) {
if (A * i <= 1000 * W && 1000 * W <= B * i) {
mi = min(mi, i);
ma = max(ma, i);
}
}
if (ma == INT_MIN)
cout << "UNSATISFIABLE";
else
cout << mi << ' ' << ma;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long double a, b, r;
cin >> a >> b >> r;
r = nextafter(r, INFINITY);
int lx = ceil(a - r), rx = floor(a + r);
long long ans = 0;
for (int x = lx; x <= rx; ++x) {
long double dy = sqrt(r * r - (x - a) * (x - a));
int upper = floor(b + dy), lower = ceil(b - dy);
ans += upper - lower + 1;
}
cout << ans << '\n';
} |
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define m 2147483647
#define mn -2147483647
int main()
{
lli i,j,n,k,add=0,add1;
cin>>n>>k;
for(i=1;i<=n;i++)
{
for(j=1;j<=k;j++)
{
add+=100*i+j;
}
}
cout<<add<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (int) N; i++)
int main() {
int N,K;
cin >> N >> K;
cout << 50*N*(N+1)*K+N*K*(K+1)/2 << endl;
} |
/*Jai Shree Ram*/
// Never Give Up
/*自分を信じない人にとっては、一生懸命働くことは無意味です*/
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define F(i,s,e,j) for(int i=s;i<=e;i+=j)
#define mt19937 rng(chrono::steady_clock::now().tjhe_since_epoch().count());
//shuffle(arr,arr+n,rng)
/*---------------------------------------------------------------------------------------------------------------------------*/
int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
int expo(int a, int b,int m) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b = b >> 1;} return res;}
void extendgcd(int a, int b, int*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); int x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
int mminv(int a, int b) {int arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
int mminvprime(int a, int b) {return expo(a, b - 2, b);}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
int combination(int n, int r, int m, int*fact, int *ifact) {int val1 = fact[n]; int val2 = ifact[n - r]; int val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
vi sieve(int n) {int*arr = new int[n + 1](); vi vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
int mod_add(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
int mod_sub(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
int mod_div(int a, int b, int m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m
int phin(int n) {int number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (int i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
/*--------------------------------------------------------------------------------------------------------------------------*/
void c_p_c()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int MAXN = 2000000;
int fact[MAXN+1];
int inv_fact[MAXN+1];
void pre_compute()
{
fact[0] = 1;
for(int i=1;i<=MAXN;i++)
fact[i] = mod_mul(i,fact[i-1],mod);
inv_fact[0] = 1;
for(int i=1;i<=MAXN;i++)
inv_fact[i] = mod_mul(mminv(i,mod),inv_fact[i-1],mod);
}
int combination(int i,int j)
{
int ans = fact[i];
ans = mod_mul(ans,inv_fact[j],mod);
ans = mod_mul(ans,inv_fact[i-j],mod);
return ans;
}
int32_t main()
{
c_p_c();
pre_compute();
int n,m,k;
cin>>n>>m>>k;
if(n>m+k)
cout<<0<<endl;
else
{
int ans = (combination(m+n,m)-combination(n+m,n-k-1)+mod)%mod;
cout<<ans<<"\n";
}
} | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define int long long
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define endl "\n"
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MAX = 2e6 + 5;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
inline ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline ll power(ll x, ll n) {
if (!n) {
return 1;
}
return (n & 1 ? mul(x, power(mul(x, x), n / 2)) : power(mul(x, x), n / 2));
}
int ways = 0;
void rec(int i, int j, int n, int m, int k, vector<char> a) {
if (i + j == n + m) {
int wi = 0, bi = 0;
bool ok = true;
for (int i = 0; i < n + m; i++) {
wi += a[i] == 'w';
bi += a[i] == 'b';
ok &= (wi <= bi + k);
}
ways += ok;
return;
}
if (i < n) {
a.push_back('w');
rec(i + 1, j, n, m, k, a);
a.pop_back();
}
if (j < m) {
a.push_back('b');
rec(i, j + 1, n, m, k, a);
a.pop_back();
}
}
vector<int> fact(MAX, 1);
void pre() {
for (int i = 1; i < MAX; i++) fact[i] = mul(i, fact[i - 1]);
}
int ncr(int n, int r) {
if (r > n) return 0LL;
return mul(fact[n], mul(power(fact[r], mod - 2), power(fact[n - r], mod - 2)));
}
// 7 4 0
// 0 0
// 0 1
// 0 2
// 165 3
// 275 4
// 319 5
// 329 6
// 330 7
// 330 8
// 330 9
// 330 10
// 330 11
// 4 7 0
// 165 0
// 275 1
// 319 2
// 329 3
// 330 4
// 330 5
// 330 6
// 330 7
// 330 8
// 330 9
// 330 10
// 330 11
void solve() {
pre();
int n, m, k;
cin >> n >> m >> k;
if (n > m) {
if (k >= n) {
cout << ncr(n + m, n) << endl;
} else {
int diff = n - k;
if (diff > m) {
cout << 0 << endl;
} else {
cout << sub(ncr(n + m, n), ncr(n + m, diff - 1)) << endl;
}
}
} else {
if (k >= n) {
cout << ncr(n + m, n) << endl;
} else {
cout << sub(ncr(n + m, n), ncr(n + m, n - k - 1)) << endl;
}
}
// for (int k = 0; k <= n + m; k++) {
// vector<char> a;
// ways = 0;
// rec(0, 0, n, m, k, a);
// cout << ways << " " << k << endl;
// }
}
signed main() {
fastio;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define N 2
#define NN 205
#define For(i,x,y)for(i=x;i<=(y);i++)
int f[NN][NN][N][N][N],val[NN][NN][N][N][N],a[NN],used[NN];
pair<pair<int,int>,pair<bool,pair<bool,bool> > >pre[NN][NN][N][N][N];
int main()
{
int n,i,j,k,p,tot=0,l,u,v;
pair<pair<int,int>,pair<bool,pair<bool,bool> > >pa;
cin>>n;
For(i,1,n)cin>>a[i],a[i]%=200;
f[0][0][0][0][0]=1;
For(i,1,n)
For(l,0,i-1)
For(j,0,199)
For(u,0,1)
For(v,0,1)
For(k,0,1)
if(f[l][j][k][u][v])
{
p=(j+a[i])%200;
f[i][p][1][1][v]=val[i][p][1][1][v]=1;
pre[i][p][1][1][v]=make_pair(make_pair(l,j),make_pair(k,make_pair(u,v)));
p=(j-a[i]+200)%200;
f[i][p][1][u][1]=1;
val[i][p][1][u][1]=2;
pre[i][p][1][u][1]=make_pair(make_pair(l,j),make_pair(k,make_pair(u,v)));
f[i][j][k][1][1]=1;
val[i][j][k][1][1]=3;
pre[i][j][k][1][1]=make_pair(make_pair(l,j),make_pair(k,make_pair(u,v)));
}
if(f[n][0][1][1][1])
{
puts("yEs");
i=n;
j=0;
k=u=v=1;
while(i)
{
/*cout<<i<<' '<<j<<' '<<k<<' '<<u<<' '<<v<<endl;*/
used[i]=val[i][j][k][u][v];
pa=pre[i][j][k][u][v];
i=pa.first.first;
j=pa.first.second;
k=pa.second.first;
u=pa.second.second.first;
v=pa.second.second.second;
}
}
else puts("nO"),exit(0);
For(i,1,n)tot+=used[i]==1||used[i]==3;
cout<<tot;
For(i,1,n)
if(used[i]==1||used[i]==3)cout<<' '<<i;
cout<<endl;
tot=0;
For(i,1,n)tot+=used[i]==2||used[i]==3;
cout<<tot;
For(i,1,n)
if(used[i]==2||used[i]==3)cout<<' '<<i;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)
template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}
const char newl = '\n';
int main() {
int n;
cin >> n;
int a[210];
for (int i = 0;i < n;++i) cin >> a[i];
vector<vector<int>> dp(n+1,vector<int>(200,0));
dp[0][0] = 1;
for (int i = 0;i < n;++i) {
dp[i+1] = dp[i];
for (int j = 0;j < 200;++j) dp[i+1][(j+a[i])%200] += dp[i][j];
for (int j = 0;j < 200;++j) dp[i+1][j] = min(dp[i+1][j],3);
}
dp[n][0]--;
bool ok = false;
int m;
for (int i = 0;i < 200;++i) if (dp[n][i] > 1) {
ok = true;
m = i;
break;
}
if (!ok) {
cout << "No" << newl;
return 0;
}
cout << "Yes" << newl;
int z = m;
for (int i = 0;i < n;++i) {
for (int j = 0;j < n+1;++j) for (int k = 0;k < 200;++k) dp[j][k] = 0;
dp[0][0] = 1;
for (int j = 0;j < n;++j) {
dp[j+1] = dp[j];
if (i == j) continue;
for (int k = 0;k < 200;++k) dp[j+1][(k+a[j])%200] += dp[j][k];
for (int k = 0;k < 200;++k) dp[j+1][k] = min(dp[j+1][k],2);
}
int mm = (m-a[i]%200+200)%200;
if (!(dp[n][m] && dp[n][mm])) continue;
vector<int> b,c;
for (int j = n-1;j >= 0;--j) {
int u = (m-a[j]%200+200)%200;
if (dp[j][u] == 0) continue;
if (j == i) continue;
b.push_back(j);
m = u;
}
for (int j = n-1;j >= 0;--j) {
int u = (mm-a[j]%200+200)%200;
if (dp[j][u] == 0) continue;
if (j == i) continue;
c.push_back(j);
mm = u;
}
c.push_back(i);
reverse(b.begin(),b.end());
sort(c.begin(),c.end());
int x = b.size(),y = c.size();
if (x == 0 || y == 0) continue;
cout << x << " ";
for (int j = 0;j < x;++j) cout << b[j]+1 << " \n"[j == x-1];
cout << y << " ";
for (int j = 0;j < y;++j) cout << c[j]+1 << " \n"[j == y-1];
return 0;
}
} |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int ans=0;
while(n--)
{
int x;
cin>>x;
if(x>10)
ans+=x-10;
}
cout<<ans;
return 0;
} | /*Created By:---- Dibas Behera*/
#include<bits/stdc++.h>
using namespace std;
#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007 //998244353
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define goo(x) cout<<"Case #"<<(x)<<": ";
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll binpow(ll a,ll b){ if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a; a=a*a; b=b>>1;} return ans;}
ll binpowM(ll a,ll b,ll m=MD){ if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a;ans%=m; a=a*a;a%=m; b=b>>1;} return ans;}
template <typename T>
T Min(T a,T b){ return a<b?a:b; }
template <typename T>
T Max(T a,T b){ return a>b?a:b; }
//-------------------------------------------
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
// int n;cin>>n;
// string s;cin>>s;
ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
ll ans=0;
repi(i,n){
if(a[i]>10) ans+=a[i]-10;
}
db(ans);
/*
int test1;cin>>test1;while(test1--){
}
//*/
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.