code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
44
101M
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #include <bits/stdc++.h> using namespace std; template<class t> inline t read(t &x){ char c=getchar();bool f=0;x=0; while(!isdigit(c)) f|=c=='-',c=getchar(); while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar(); if(f) x=-x;return x; } 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('-'),write(-x); else{if(x>9) write(x/10);putchar('0'+x%10);} } const int N=55; int n,m; signed main(){ read(n,m); write(n-m+1); }
#include <iostream> #include <string> using namespace std; int main(){ while(1){ string str, left, right; int m, h; cin>>str; if(str == "-") break; cin>>m; for(int i=0;i<m;i++){ cin>>h; left = str.substr(0, h); right = str.substr(h, str.length()-h); str = right + left; } cout<<str<<endl; } return 0; }
0
58,687,822
#include <iostream> using namespace std; bool map[100][100]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a, c; cin >> a >> c; for (int j = 0; j < c; j++) { int b; cin >> b; map[a - 1][b - 1] = true; } } for (int i = 0; i < n; i++) { cout << (map[i][0] ? "1" : "0"); for (int j = 1; j < n; j++) { cout << " " << (map[i][j] ? "1" : "0"); } cout << endl; } return 0; }
#include <bits/stdc++.h> #include <vector> #include <algorithm> #include <math.h> using namespace std; int CalcSumOfDigit(int n); string upper(string str); string lower(string str); #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define pb push_back #define sz(a) int((a).size()) #define rep(i,n) for(int(i)=0;(i)<(n);(i)++) #define repe(i,n) for(int(i)=0;(i)<=(n);(i)++) #define vsort(v) sort((v).begin(),(v).end()) #define rvsort(v) sort(rall((v))) #define vi vector<int> const int INF = 1e9; int main() { int a,b,c; cin >> a >> b >> c; if(a <= c && c <= b) cout << "Yes" << endl; else cout << "No" << endl; return 0; } int CalcSumOfDigit(int n) { int s = 0; while(n) { s += n % 10; n = n / 10; } return s; } string upper(string str) { for(auto itr = str.begin();itr != str.end() ; itr++) { if(97 <= *itr && *itr <= 122) { *itr = *itr - 32; } } return str; } string lower(string str) { for(auto itr = str.begin();itr != str.end() ; itr++) { if(65 <= *itr && *itr <= 90) { *itr = *itr + 32; } } return str; }
0
17,745,092
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int> v,p(n,0),q(n,0); for(int i=0;i<n;i++){ cin>>p[i]; } for(int i=0;i<n;i++){ cin>>q[i]; } int a,b,i=0; bool flag=true; for(int i=1;i<=n;i++){ v.push_back(i); } do{ i++; if(v==p){ a=i; } if(v==q){ b=i; } }while(next_permutation(v.begin(),v.end())); cout<<abs(a-b)<<"\n"; return(0); }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define increment(a, b) (a == '.' && b == '#') int find_root(int h, int w) { unsigned int dp[h][w]; string s[h]; REP(i, h) { cin >> s[i]; REP(j, w) { dp[i][j] = -1; } } dp[0][0] = (s[0][0] == '#'); REP(i, h) { REP(j, w) { if(i != h-1) { dp[i+1][j] = dp[i][j] + increment(s[i][j], s[i+1][j]); } if(j != w-1) { dp[i][j+1] = min(dp[i][j+1], dp[i][j] + increment(s[i][j], s[i][j+1])); } } } return dp[h-1][w-1]; } int main() { int h,w; cin >> h >> w; cout << find_root(h, w) << endl; return 0; }
0
34,085,487
#include<cstdio> int main(){ int n,m,l; scanf("%d %d %d",&n,&m,&l); printf("%s\n",(n<m && m<l)?"Yes":"No"); }
#include <iostream> #include <algorithm> #include <iomanip> #include <cmath> #include <vector> #include <sstream> #include <string> #include <cstdio> #include <stack> #include <queue> #include <list> #include <numeric> #include <fstream> #define NDEBUG #include <cassert> using namespace std; #define TEST #ifdef TEST #define dout cout #else stringstream dummy; #define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy #endif #ifdef OUTPUT2TEXTFILE #define dout outputfile #define OUTPUTFILENAME "output.txt" ofstream outputfile(OUTPUTFILENAME); #define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt" #endif #define disp(A) dout << #A << " = " << (A) << endl #define disP(A) dout << setw(3) << (A) << " " #define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++) #define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl typedef vector<int> vi; const int INF = 999; int M; vi c; int dp[20][50001]; int main(){ int yen; cin >> yen >> M; int cc; rep(i,0,M) { cin >> cc; c.push_back(cc); } rep(i,0,20) { rep(j,0,50001) { dp[i][j] = INF; } } rep(j,0,50001) { dp[0][j] = j; } rep(j,0,yen+1) { dp[0][j] = j; } rep(i,1,M) { rep(j,0,yen+1) { if( j<c[i] ) { dp[i][j] = dp[i-1][j]; } else { dp[i][j] = min( dp[i-1][j], dp[i][j-c[i]]+1 ); } } } dout << dp[M-1][yen] << endl; #ifdef OUTPUT2TEXTFILE outputfile.close(); cout << "\"" << OutputFilePath << "\"" << endl; #endif return 0; }
0
74,541,550
#include <bits/stdc++.h> typedef long long int ll; using namespace std; ll N = pow(10,10); int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,k;cin>>n>>k; int ans=0; if(k==1){ ans =0; } else{ ans = n-k; } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define fi first #define se second #define pb push_back #define soo(v) sort(v.rbegin(),v.rend()) #define so(v) sort(v.begin(),v.end()) #define lb(v,x) lower_bound(v.begin(),v.end(),x) #define ub(v,x) upper_bound(v.begin(),v.end(),x) #define endl '\n' #define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl; #define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;} #define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl; #define mod 1000000007 #define db1(x) cout<<#x<<"="<<x<<endl; #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl; #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl; #define mx 1e18 #define mxe(v) *max_element(v.begin(),v.end()) #define mne(v) *min_element(v.begin(),v.end()) #define double long double int powe(int x,int n) { if(n==0)return 1; if(n%2==0) return powe((x%mod*x%mod)%mod,n/2)%mod; return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod; } int gcd(int A,int B) { if(B==0)return A; return gcd(B,A%B); } #define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define re(s) reverse(s.begin(),s.end()) int32_t main() { io string s,t; cin>>s>>t;int cnt=0; for(int i=0;i<s.length();i++) { if(s[i]!=t[i])cnt++; } cout<<cnt<<endl; }
0
89,523,858
#include <bits/stdc++.h> using namespace std; const int C = 1046527; char baca[C][13]; int hs(int key, int i) { return (key % C + i * (1 + key % (C - 1))) % C; } int cToI(char ch) { if (ch == 'A') return 1; else if (ch == 'C') return 2; else if (ch == 'G') return 3; else if (ch == 'T') return 4; else return 0; } int getKey(string tmp) { int sum = 0, p = 1, l = tmp.length(); for (int i = 0; i < l; i++) { sum += p * cToI(tmp[i]); p *= 5; } return sum; } void ins(string str) { int key = getKey(str); for (int i = 0; i < C; i++) { int h = hs(key, i); if (strlen(baca[h]) == 0) { strcpy(baca[h], str.c_str()); break; } } } int find(string str) { int key = getKey(str); for (int i = 0;; i++) { int h = hs(key, i); if (strlen(baca[h]) == 0) { return 0; } else if (strcmp(baca[h], str.c_str()) == 0) { return 1; } } } int main() { ios::sync_with_stdio(false); int cnt; cin >> cnt; string tmp; string key; for (int i = 0; i < cnt; i++) { cin >> tmp >> key; if (tmp[0] == 'i') { ins(key); } else { find(key) == 1 ? cout << "yes" << endl : cout << "no" << endl; } } return 0; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int table[64][100000]; int b[64]; int Abit[64][100000]; int shift[64]; int dim; void dump(const vector<int>& look, const int N) { for (int i=0; i<look.size(); i++) { for (int j=0; j<N; j++) { cerr << table[i][j] << " "; } cerr << endl; } } int main() { int N; cin >> N; long long A[100000]; for (int i=0; i<N; i++) cin >> A[i]; long long allxor = 0; for (int i=0; i<N; i++) allxor ^= A[i]; vector<int> look; { long long i = allxor; for (int step=0; step<64; step++, i/=2) { if (i%2 == 0) { look.push_back(step); } } } reverse(look.begin(), look.end()); for (int i=0; i<N; i++) { long long x = A[i]; int step = 0; while (x > 0) { if (x % 2 == 1) { Abit[step][i] = 1; } x /= 2; step++; } } { int dim = 0; for (int a: look) { for (int i=0; i<N; i++) table[dim][i] = Abit[a][i]; b[dim] = 1; dim++; } } long long left = 0; int rank = 0; for (int level=0; level<look.size(); level++) { int idx = -1; for (int i=rank; i<N; i++) { if (table[level][i] == 1) { idx = i; break; } } if (idx == -1) { if (b[level] == 0) { left |= 1LL << look[level]; } continue; } for (int i=0; i<look.size(); i++) { int tmp = table[i][rank]; table[i][rank] = table[i][idx]; table[i][idx] = tmp; } for (int i=0; i<look.size(); i++) { if (i == level) continue; if (table[i][rank] == 0) continue; for (int j=0; j<=N; j++) { table[i][j] ^= table[level][j]; } b[i] ^= b[level]; } left |= 1LL << look[level]; rank++; } cout << left + (allxor ^ left) << endl; return 0; }
0
91,736,041
#include<bits/stdc++.h> #define MAX 5000 #define MOD 1000000007 using namespace std; vector<int> p,c; long long go(int start, int k) { long long sum = 0; int ii = start; int steps = 0; vector<int> v; do { ii = p[ii]; v.push_back(c[ii]); sum += 1LL*c[ii]; ++steps; } while(ii^start); long long tmp = 0, res = LLONG_MIN; for(int i=0;i+1<=k&&i<v.size();++i) { tmp += 1LL*v[i]; if(sum>0) res = max(res,tmp+(k-i-1)/steps*1LL*sum); else res = max(res,tmp); } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,k; cin>>n>>k; p = vector<int>(n+1), c = vector<int>(n+1); for(int i=1;i<=n;++i) cin>>p[i]; for(int i=1;i<=n;++i) cin>>c[i]; long long ans = LLONG_MIN; for(int i=1;i<=n;++i) ans = max(ans,go(i,k)); cout<<ans<<endl; return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) constexpr int MOD=1000000007; #define INF (1<<30) #define LINF (lint)(1LL<<56) #define endl "\n" #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define Flag(x) (1<<(x)) #define Flagcount(x) __builtin_popcount(x) #define pint pair<int,int> #define pdouble pair<double,double> #define plint pair<lint,lint> #define fi first #define se second typedef long long lint; int dx[8]={1,1,0,-1,-1,-1,0,1}; int dy[8]={0,1,1,1,0,-1,-1,-1}; const int MAX_N=2e5+5; int main(void){ int N; cin >> N; int A[N+1]; rep(i,N+1) cin >> A[i]; if(N==0){ if(A[0]!=1) cout << -1 << endl; else cout << 1 << endl; return 0; } else if(A[0]!=0){ cout << -1 << endl; return 0; } lint sum=accumulate(A,A+N+1,0LL)-A[0]; lint ans=1; lint vec=1; for(int i=1;i<=N;i++){ vec*=2; if(vec>sum) vec=sum; ans+=vec; vec-=A[i]; if(vec<0){ cout << -1 << endl; return 0; } sum-=A[i]; } cout << ans << endl; }
0
7,793,949
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <set> #include <map> using namespace std; typedef long long ll; #define rep(i, n) for (int i=0;i < (int)(n);i++) const ll INF = 1LL << 60; int main(){ int n; char x; string s; cin >> x; if (x == 'A') cout << 'T' << endl; else if (x == 'T') cout << 'A' << endl; else if (x == 'C') cout << 'G' << endl; else cout << 'C' << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; int main() { vector <char> s, t; string S, T; cin >> S >> T; for (unsigned int i = 0; i < S.length(); i++) { char c = S[i]; s.push_back(c); } for (unsigned int i = 0; i < T.length(); i++) { char c = T[i]; t.push_back(c); } sort(s.begin(), s.end()); sort(t.begin(), t.end(), [](const int& x, const int& y) {return x > y;}); bool ans = false; for (int i = 0; i < t.size(); i++) { if (i >= s.size()) { ans = true; break; } if (s[i] < t[i]) { ans = true; break; } if (s[i] > t[i]) { ans = false; break; } } if (ans) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
0
24,143,160
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin >> n; int a[n],b[n]; rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; int line[n]; rep(i,n) line[i] = i+1; int count = 1; int ansa = 0, ansb = 0; bool flag = true; do{ rep(i,n) { if(line[i] != a[i]) flag = false; } if(flag == true) ansa = count; flag = true; rep(i,n) { if(line[i] != b[i]) flag = false; } if(flag == true) ansb = count; if(ansa > 0 && ansb > 0) break; count++; flag = true; }while(next_permutation(line,line+n)); cout << abs(ansa - ansb) << endl; }
#pragma target("avx") #include<bits/stdc++.h> using ll = int_fast64_t; using P = std::pair<ll,ll>; using V = std::vector<ll>; template<typename T> using pq = std::priority_queue<T>; template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>; #define rep(i,b,e) for(ll i=b; i<e; i++) #define be(vec) vec.begin(),vec.end() #define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]"); #define scan(vec) for(auto &i:vec)scanf("%ld",&i) #define fi first #define se second const int MOD = 1e9+7; const ll INF = 1e18; int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; int main(){ ll n, k, s; scanf("%ld %ld %ld", &n, &k, &s); V ans(n, s); rep(i, k, n){ if(s==1e9) ans[i] = 1; else ans[i] = s+1; } for(ll i: ans) printf("%ld ", i); return 0; }
0
7,244,849
#include<bits/stdc++.h> #define inf 1e9 #define eps 1e-6 #define mp make_pair #define pb push_back #define re register ll #define fr first #define sd second #define pa pair<ll,ll> #define FOR(i,a,b) for(re i=a;i<=b;i++) #define REP(i,a,b) for(re i=a;i>=b;i--) #define lowbit(x) (x&(-x)) #define Z(x) (x>=mod?x-mod:x) #define N 1010 using namespace std; typedef long long ll; typedef unsigned long long ull; inline ll read() { char ch=getchar(); ll s=0,w=1; while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();} return s*w; } ll n; ll x[N],y[N]; ll len[N],tot; ll flag; int main() { n=read(); FOR(i,1,n)x[i]=read(),y[i]=read(); flag=abs(x[1]+y[1])&1; FOR(i,1,n)if((abs(x[i]+y[i])&1)^flag){puts("-1");return 0;} printf("%lld\n1 ",32-flag); len[tot=1]=1; if(!flag){FOR(i,0,30){len[++tot]=(1<<i);printf("%d ",(1<<i));}} else {FOR(i,1,30){len[++tot]=(1<<i);printf("%d ",(1<<i));}} puts(""); FOR(i,1,n) { ll nowx=0,nowy=0; string s; REP(j,tot,1) { ll dx=x[i]-nowx,dy=y[i]-nowy; if(abs(dx)>abs(dy)){dx<0?(s+='L',nowx-=len[j]):(s+='R',nowx+=len[j]);} else {dy<0?(s+='D',nowy-=len[j]):(s+='U',nowy+=len[j]);} } reverse(s.begin(),s.end()); cout<<s<<endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\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; } using namespace std; using P = pair<int,int>; using ll = long long; const ll INF = 1LL<<60; const double PI = 3.1415926535897932; const int MOD = 1e9 + 7; vector<pair<ll, ll>> prime_factorize(ll n) { vector<pair<ll, ll>> res; for (ll i = 2; i * i <= n; i++) { if (n % i != 0) continue; ll ex = 0; while (n % i == 0) { ++ex; n /= i; } res.push_back({i, ex}); } if (n != 1) res.push_back({n, 1}); return res; } int main() { ll n; cin >> n; if (n == 1) { cout << 1 << endl; return 0; } vector<ll> primes; for (auto v : prime_factorize(n)) { for (ll i = 0; i < v.second; i++) { primes.push_back(v.first); } } vector<ll> ans; ll tmp1, tmp2; for (int bit = 0; bit < 1 << primes.size(); bit++) { tmp1 = tmp2 = 1; for (int j = 0; j < primes.size(); j++) { if (bit & 1 << j) { tmp1 *= primes[j]; } else { tmp2 *= primes[j]; } } ans.push_back(max(to_string(tmp1).size(), to_string(tmp2).size())); } cout << *min_element(ans.begin(), ans.end()) << endl; return 0; }
0
33,056,443
#include <bits/stdc++.h> #define MAX 11000 #define ll long int using namespace std; int main() { map<string,int> mp; string s ; ll i,j,n,count=0,sum=0; cin >> n; for(i=0;i<n;i++) { cin >> s; sort(s.rbegin(), s.rend(), greater<char>()); count += mp[s]++; } cout << count; }
#include<iostream> #include<map> #include<cstdio> #include<cstring> #include<string> #include<algorithm> using namespace std; int main(){ string tmp[]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; string str; int i,l,cnt1,cnt2,n; cin >>n; for(int v=0;v<n;v++){ cin >> str; l=str.size(); cnt1=cnt2=0; for(int i=0;i<l;i++){ if(str[i]=='0'){ if(cnt2!=0){ cout << tmp[cnt1][(cnt2%tmp[cnt1].size()==0)?tmp[cnt1].size()-1:cnt2%tmp[cnt1].size()-1]; } cnt1=cnt2=0; } else { if(cnt1==0){ cnt1=str[i]-'0'; cnt2++; }else{ cnt2++; } } } puts(""); } }
0
6,837,524
#include <bits/stdc++.h> #include <cmath> #include <numeric> using namespace std; #define rep(i,a,b) for(int64_t i=(a);i<(b);++i) #define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) #define INF 1000000000000000 #define MOD 1000000007 using PII = pair<int64_t, int64_t>; using VI = vector<int64_t>; using VVI = vector<VI>; using VS = vector<string>; using VP = vector<PII>; using i64 = int64_t; template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} int main() { cin.tie(0); ios::sync_with_stdio(false); string A; cin >> A; int n = A.size(); VI cnt(26, 0); for(char c: A) ++cnt[c - 'a']; i64 ans = 1; rep(i, 0, 26) rep(j, i+1, 26){ ans += cnt[i] * cnt[j]; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, N) for (int i = 0; i < (int)N; ++i) #define all(a) (a).begin(), (a).end() int N; vector<int> A, c, S; int main() { map<int, int> m; cin >> N; A.resize(N); rep(i, N) { cin >> A[i]; m[A[i]]++; } for (auto it = m.begin(); it != m.end(); it++) c.push_back((*it).second); sort(all(c)); S.resize(c.size() + 1, 0); rep(i, c.size()) S[i + 1] = S[i] + c[i]; int l = 0, n = c.size() - 1; for (int k = 1; k <= N; ++k) { int n = c.size() - 1 - l; while (c[n] * (k - l) > S[n + 1]) { --n; ++l; } cout << S[n + 1] / (k - l) << endl; } return 0; }
0
99,513,760
#include <bits/stdc++.h> using namespace std; #define PB push_back #define F first #define S second #define MP make_pair #define all(x) x.begin(), x.end() #define watch(x) cout<<#x<<" : "<<x<<endl #define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) #define testCases int tt;cin>>tt; while(tt--) #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef vector<string> vs; int main() { fastio; int n; cin >> n; set<int> s; for (int i = 0; i < n; i++) { int temp; cin >> temp; s.insert(temp); } if (s.size() == n) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <iostream> #include <string> #include <cmath> using namespace std; int main(void){ int n,t,m; cin >> n; (t = ceil((sqrt(1+8*n)-1) / 2)); m = (t*(t+1))/2; for(int i = 1; i <= t; i++){ if( n == m - i ){ } else{ cout << i << endl; } } }
0
7,845,023
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <string> #include <queue> #include <fstream> #include <string> #include <math.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> T; const ll mod = 1000000007; const ll INF = 100000010000; ll kai[100010]; ll bit[700010]; ll ans[300000]; ll n, a[300000]; ll lar[300000][2][2]; ll sum(ll i) { ll s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(ll i, ll x) { while (i <= 700005) { bit[i] += x; i += i & -i; } } ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll pow_mod(ll x, ll y) { if (y == 0) return 1; if (y % 2 == 1) { return x * pow_mod(x, y - 1) % mod; } else { ll half = pow_mod(x, y / 2); return half * half % mod; } } ll div_mod(ll x) { return pow_mod(x, mod - 2); } ll com(ll x, ll y) { return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod; } void init() { cin >> n; for (int i = 0; i < (1 << n); i++) { cin >> a[i]; } } void output() { } bool cmp(ll x, ll y) { return a[x] > a[y]; } void solve() { for (int i = 1; i < (1 << n); i++) { ll num = 0, r; for (int j = 0; j < n; j++) { if ((i & (1 << j)) > 0) { num++; r = j; } } if (num == 1) { lar[i][0][0] = a[0]; lar[i][1][0] = a[1 << r]; lar[i][0][1] = 0; lar[i][1][1] = (1 << r); } else { ll nu = 0, c[2][2]; vector<ll> xs; for (int j = 0; j < n; j++) { if ((i & (1 << j)) > 0) { xs.push_back(lar[i - (1 << j)][0][1]); xs.push_back(lar[i - (1 << j)][1][1]); nu++; if (nu == 1) { c[0][0] = lar[i - (1 << j)][0][0]; c[0][1] = lar[i - (1 << j)][0][1]; c[1][0] = lar[i - (1 << j)][1][0]; c[1][1] = lar[i - (1 << j)][1][1]; if (c[0][0] > c[1][0]) { swap(c[0][0], c[1][0]); swap(c[0][1], c[1][1]); } } else { if (lar[i - (1 << j)][0][0] > c[0][0] && lar[i - (1 << j)][0][1] != c[0][1] && lar[i - (1 << j)][0][1] != c[1][1]) { c[0][0] = lar[i - (1 << j)][0][0]; c[0][1] = lar[i - (1 << j)][0][1]; } else if (lar[i - (1 << j)][0][0] > c[1][0] && lar[i - (1 << j)][0][1] != c[0][1] && lar[i - (1 << j)][0][1] != c[1][1]) { c[1][0] = lar[i - (1 << j)][0][0]; c[1][1] = lar[i - (1 << j)][0][1]; } if (c[0][0] > c[1][0]) { swap(c[0][0], c[1][0]); swap(c[0][1], c[1][1]); } if (lar[i - (1 << j)][1][0] > c[0][0] && lar[i - (1 << j)][1][1] != c[0][1] && lar[i - (1 << j)][1][1] != c[1][1]) { c[0][0] = lar[i - (1 << j)][1][0]; c[0][1] = lar[i - (1 << j)][1][1]; } else if (lar[i - (1 << j)][1][0] > c[1][0] && lar[i - (1 << j)][1][1] != c[0][1] && lar[i - (1 << j)][1][1] != c[1][1]) { c[1][0] = lar[i - (1 << j)][1][0]; c[1][1] = lar[i - (1 << j)][1][1]; } if (c[0][0] > c[1][0]) { swap(c[0][0], c[1][0]); swap(c[0][1], c[1][1]); } } } } xs.push_back(i); if (a[i] > c[0][0]) { c[0][0] = a[i]; c[0][1] = i; if (c[0][0] > c[1][0]) { swap(c[0][0], c[1][0]); swap(c[0][1], c[1][1]); } } sort(xs.begin(), xs.end(), cmp); xs.erase(unique(xs.begin(), xs.end()), xs.end()); lar[i][0][0] = a[xs[0]]; lar[i][0][1] = xs[0]; lar[i][1][0] = a[xs[1]]; lar[i][1][1] = xs[1]; } } ans[0] = 0; for (int i = 1; i < (1 << n); i++) { ans[i] = lar[i][0][0] + lar[i][1][0]; if (lar[i][1][1] == lar[i][0][1]) { cout << 888888 << ' ' << lar[i][0][1] << endl; } ans[i] = max(ans[i], ans[i - 1]); cout << ans[i] << endl; } } int main() { init(); solve(); output(); ll N; cin >> N; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; #define rep(i, a, b) for (int i = a; i < b; i++) int N; ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll ans = 1; cin >> N; vector<ll> t(N); rep(i, 0, N) { cin >> t[i]; } rep(i, 0, N) { ans = lcm(ans, t[i]); } cout << ans << endl; return 0; }
0
31,864,443
#include<bits/stdc++.h> #include<algorithm> #include<math.h> #include<string> #include<iostream> #include<vector> #include<cstdlib> using namespace std; template <class T> using V = vector<T>; 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; } const long long INF = 1LL << 60; using ll = long long; using db = double; using st = string; using ch = char; using bl = bool; using vll = V<ll>; using vpll =V<pair<ll,ll>>; using vst = V<st>; using vdb = V<db>; using vch = V<ch>; using vbl = V<bl>; #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define rFOR(i,a,b) for(ll i=(a);i>=(b);i--) #define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2) #define bgn begin() #define en end() #define SORT(a) sort((a).bgn,(a).en) #define REV(a) reverse((a).bgn,(a).en) #define M(a,b) max(a,b) #define rM(a,b) min(a,b) #define fi first #define se second #define sz size() #define gcd(a,b) __gcd(a,b) #define co(a) cout<<a<<endl; #define ci(a) cin>>a; vll dp(100100); ll sum(ll n) { ll m=0; FOR(i,0,20){ m+=n%10; n/=10; if(n==0){ break; } } return m; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { 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; } } #define comuse Comuse() ll combi(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; } ll lcm(ll a,ll b){ ll n; n=a/gcd(a,b)*b; return n; } signed main() { ll n; ci(n); vll A(n); FOR(i,0,n){ ci(A[i]) } SORT(A); ll m=A[n-1]; vll B(n-1); FOR(i,0,n-1){ B[i]=min(A[i],m-A[i]); } SORT(B); bl b=true; FOR(i,0,n-1){ if(A[i]==B[n-2]){ cout<<m<<" "<<A[i]<<endl; b=false; break; } } if(b){ cout<<m<<" "<<m-B[n-2]<<endl; } }
#include<iostream> #include<vector> using namespace std; int BFS(int s, int t, const vector<vector<int> >& G){ vector<int> stock1; vector<int> stock2; stock1.push_back(s); vector<int> check(101, 0); int d = 0; while (1) { for (int i = 0; i < stock1.size(); i++) { if (stock1[i] == t) return d; for (int j = 0; j < G[stock1[i]].size(); j++) { if (check[G[stock1[i]][j]] == 0) { check[G[stock1[i]][j]] = 1; stock2.push_back(G[stock1[i]][j]); } } } if (stock2.empty()) return -1; stock1.clear(); stock1.swap(stock2); d++; } } int main(){ int n; cin >> n; vector<vector<int> > G(n + 1); for (int i = 0; i < n; i++) { int u, k; cin >> u >> k; for (int j = 0; j < k; j++) { int v; cin >> v; G[u].push_back(v); } } for (int i = 1; i <= n; i++) { cout << i << " " << BFS(1, i, G) << endl; } return 0; }
0
14,198,311
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int N,A; cin>>N>>A; puts(N%500<=A?"Yes":"No"); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 1000000007 #define INF 1e9 #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } int64_t res = 1LL << 60; for (int bit = 0; bit < (1 << N); bit++) { int k = 1, ma = A[0]; int64_t cost = 0; for (int i = 1; i < N; i++) { int diff = 0; if ((bit >> i) & 1) { diff = max(0, ma - A[i] + 1); cost += diff; } if (chmax(ma, A[i] + diff)) k++; } if (k >= K) res = min(res, cost); } cout << res << '\n'; return 0; }
0
26,847,167
#include<algorithm> #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<map> #include<queue> #include<set> #include<sstream> #include<stack> #include<string> #include<vector> using namespace std; #define MP make_pair int n,m; int a[200005]; bool v[200005]; vector<pair<int,int> > g[200005]; int mx,mn; void dfs(int x){ mn=min(a[x],mn); mx=max(a[x],mx); for(int i=0;i<g[x].size();i++){ int y=g[x][i].first; if(v[y]){ if(a[y]!=a[x]+g[x][i].second){ cout<<"No"; exit(0); } }else{ v[y]=1; a[y]=a[x]+g[x][i].second; dfs(y); } } } int main(){ cin>>n>>m; for(int i=0;i<m;i++){ int x,y,d; cin>>x>>y>>d; g[x].push_back(MP(y,d)); g[y].push_back(MP(x,-d)); } for(int i=1;i<=n;i++){ if(v[i])continue; mx=-1e9,mn=1e9; v[i]=1; a[i]=0; dfs(i); if(mx-mn>1e9){ cout<<"No"; return 0; } } cout<<"Yes"; return 0; }
#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<vector> #include<string> #include<algorithm> #include<map> using namespace std; #define rep(i,x) for(ll i = 0; i < (ll)(x); i++) #define pb push_back #define eb emplace_back #define mp make_pair #define debug(x) cerr << #x << ": " << (x) << "\n"; #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<int,int> P; typedef pair<ll,ll> Pll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<vector<ll>>> vvvl; const ll INF = LLONG_MAX/4; const ll MOD = 1e9+7; const int n_max = 1e5+10; int main(){ ll n,m; cin >> n >> m; vector<ll> s(n); rep(i,n) cin >> s[i]; vector<ll> t(m); rep(i,m) cin >> t[i]; vector<vector<ll>> dp(n,vector<ll>(m,0)), sum(n+1, vector<ll>(m+1,0)); rep(i,n){ rep(j,m){ if(s[i] != t[j])dp[i][j] = 0; else dp[i][j] = (sum[i][j] + 1) % MOD; sum[i+1][j+1] = (sum[i][j+1] + sum[i+1][j] - sum[i][j] + dp[i][j]) % MOD; if(sum[i+1][j+1] < 0)sum[i+1][j+1] += MOD; } } cout << (sum[n][m] + 1) % MOD << endl; }
0
99,403,777
#include<iostream> #include<algorithm> using namespace std; int main() { int nmin, nmax, m; while (cin >> m >> nmin >> nmax, m) { int p[210]; for (int i = 1; i <= m; i++)cin >> p[i]; int ans = nmin, v = p[nmin] - p[nmin + 1]; for (int i = nmin + 1; i <= nmax; i++) { if (v <= p[i] - p[i + 1]) { ans = i; v = p[i] - p[i + 1]; } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int parent[200005]; int ranking[200005]; int n, m; int get_parent(int a) { return (parent[a] = parent[a] == a ? a : get_parent(parent[a])); } void join(int a, int b) { if (get_parent(a) == get_parent(b)) return; if (ranking[get_parent(a)] < ranking[get_parent(b)]) swap(a,b); ranking[get_parent(a)] += ranking[get_parent(b)]; parent[get_parent(b)] = parent[get_parent(a)]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { parent[i] = i; ranking[i] = 1; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; join(a,b); } int ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, ranking[i]); } cout << ans << endl; return 0; }
0
40,564,546
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; int main() { string S, T; cin >> S >> T; int N = S.length(); int M = T.length(); for (int i = N - M; i >= 0; i--) { string s = S.substr(i, M); bool ok = true; for (int j = 0; j < M; j++) { if (s[j] != '?' && s[j] != T[j]) { ok = false; } } if (ok) { string ans = S.substr(0, i) + T + S.substr(i + M); for (auto& c : ans) { if (c == '?') { c = 'a'; } } cout << ans << endl; return 0; } } cout << "UNRESTORABLE" << endl; }
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<set> #include<string> #include<map> #include<string.h> #include<complex> #include<math.h> #include<queue> #include <functional> #include<time.h> #include<iomanip> #include<cassert> #include<bitset> #include<sstream> using namespace std; typedef long long int llint; typedef pair<int, int> pint; typedef pair<llint, llint> pllint; typedef vector<int> vint; typedef vector<llint> vllint; typedef vector<pint> vpint; typedef vector<string> vstring; typedef vector<pair<llint, llint>> vpllint; typedef vector<vector<int>> vvint; typedef vector<vector<llint>> vvllint; typedef vector<vector<pint>> vvpint; typedef vector<bool> vbool; typedef vector<vbool> vvbool; typedef vector<vpllint> vvpllint; #define rep(i,n) for(int i=0;i<n;i++) #define drep(i,n) for(int i=n-1;0<=i;i--) #define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl; #define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl; #define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl; #define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl; #define Pi 3.1415926535897932384626 #define mod llint(1e9+7) #define Inf 2147483647 #define llInf 9223372036854775807 #define all(x) x.begin(),x.end() #define pb push_back #define isin(n,i) 0<=i&&i<n class UnionFind { public: vector<int> Parent; UnionFind(int N) { Parent = vector<int>(N, -1); } int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } int size(int A) { return -Parent[root(A)]; } bool connect(int A, int B) { A = root(A); B = root(B); if (A == B) { return false; } if (size(A) < size(B)) swap(A, B); Parent[A] += Parent[B]; Parent[B] = A; return true; } }; template<typename T> struct SegTree { using F = function<T(T, T)>; vector<T>seg; int siz; const T unit; const F f; SegTree(int n, const T unit, const F f) : unit(unit), f(f) { siz = 1; while (siz < n)siz <<= 1; seg.assign(siz * 2 - 1, unit); siz--; } void set(int k, const T& t) { seg[k + siz] = t; } void build() { for (int i = siz - 1; 0 <= i; i--) { seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2]); } } T operator[](const int i) { return seg[i + siz]; } void update(int k, T x) { k += siz; seg[k] = x; while (0 < k) { k = (k - 1) >> 1; seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]); } } T query(int a, int b) { T l = unit, r = unit; for (a += siz, b += siz; a < b; a >>= 1, b >>= 1) { if (!(a & 1))l = f(seg[a++], l); if (!(b & 1))r = f(seg[--b], r); } return f(l, r); } }; long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } long long extGCD(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } llint nCr(llint n, llint r, llint m) { llint ans = 1; for (llint i = 0; i < r; i++) { ans *= n - i; ans %= m; } for (llint i = 1; i <= r; i++) { ans *= modinv(i, m); ans %= m; } return ans; } llint power(llint a, llint b, llint m) { if (b == 1)return a; if (b == 0)return 1; llint tmp = power(a, (llint)b / 2, m); tmp *= tmp; tmp %= m; if (b % 2 == 1) { tmp *= a; tmp %= m; } return tmp; } bool next_combination(llint& sub, int length) { llint x = sub & -sub, y = sub + x; sub = (((sub & ~y) / x) >> 1) | y; return sub < (llint)(1 << (llint)length); } int main() { int n, k; cin >> n >> k; vint v(n); rep(i, n)cin >> v[i]; int ans = 0; rep(i, n + 1) { drep(j, n) { if (i + (n - j - 1) > k)break; if (i - 1 > j)break; vint tmp; int cnt = 0; rep(l, i) { cnt += v[l]; if (v[l] < 0)tmp.pb(v[l]); } for (int l = n - 1; j < l; l--) { cnt += v[l]; if (v[l] < 0)tmp.pb(v[l]); } sort(all(tmp)); rep(l, min(k - i - (n - j - 1), (int)tmp.size())) { cnt -= tmp[l]; } ans = max(ans, cnt); } } cout << ans << endl; return 0; }
0
32,059,678
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ff first #define ss second #define rsz resize #define ins insert #define mp make_pair #define pf push_front #define pb push_back #define eb emplace_back #define ft front() #define bk back() #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define deb(x) cout<<#x<<" "<<x<<'\n'; #define rep(i,a,b) for (int i = (a); i < (b); ++i) const ll mod = 1e9+7; const ll inf = 1e18; const ld pie = acos((ld)-1); int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int main(){ ll n; scanf("%lld\n",&n); vector<ll> a(n); for(ll i=0;i<n;++i){ scanf("%lld",&a[i]); } ll ans = INT_MAX; for(ll i=-100;i<=100;++i){ ll sum=0; for(ll j=0;j<n;++j){ sum+= (a[j]-i)*(a[j]-i); } ans=min(ans,sum); } ans==INT_MAX?printf("0\n"):printf("%lld\n",ans); return 0; }
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string s; cin >> s; reverse(s.begin(), s.end()); string dream = "dream"; string dreamer = "dreamer"; string erase = "erase"; string eraser = "eraser"; reverse(dream.begin(), dream.end()); reverse(dreamer.begin(), dreamer.end()); reverse(erase.begin(), erase.end()); reverse(eraser.begin(), eraser.end()); int i; for (i = 0; i < s.size(); i++) { if (dream == s.substr(i,5)) { i += 4; continue; } else if (dreamer == s.substr(i,7)) { i += 6; continue; } else if (erase == s.substr(i,5)) { i += 4; continue; } else if (eraser == s.substr(i,6)) { i += 5; continue; } else { break; } } if (i == s.size()) cout << "YES" << endl; else cout << "NO" << endl; }
0
14,380,170
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int remaining = n; int left = 0, right = n - 1; while (right - left > 1) { if (a[left + 1] != a[left]) { left++; } else if (a[right - 1] != a[right]) { right--; } else { left++; right--; remaining -= 2; } } if (a[left] == a[right] && left != right) { remaining -= 2; } cout << remaining << endl; return 0; }
#include <cstdio> #include <iostream> #include <cstring> #include <set> #include <algorithm> #define FOREVER for (;;) #define FOR(i,a,b) \ for (int (i)=(a);(i)<(b);(i)++) #define REP(i,a,b) \ for (int (i)=(a);(i)<=(b);(i)++) #define log(exp) \ printf(#exp" = %d\n", exp) #define INF 100000000 using namespace std; const int maxn = 10+3; int graph[maxn][maxn]; set<int> Set; int main(void) { int N; while (cin>>N && N) { FOR(i,0, maxn) FOR(j, 0, maxn) graph[i][j] = INF; FOR(i,0,10) graph[i][i] = 0; REP(i,1,N) { int u,v,d; cin>>u>>v>>d; graph[u][v] = graph[v][u] = d; Set.insert(u); Set.insert(v); } FOR(k,0,10) FOR(i,0,10) FOR(j,0,10) graph[i][j] = min(graph[i][j], graph[i][k]+graph[k][j]); int ans = INF, ansNode = 0; set<int>::iterator it; for (it = Set.begin(); it!=Set.end(); it++) { int node = *it; int res = 0; set<int>::iterator anotherIt; for (anotherIt = Set.begin(); anotherIt!=Set.end(); anotherIt++) res+=graph[node][*anotherIt]; if (res<ans) ans = res, ansNode = node; } printf("%d %d\n", ansNode, ans); Set.clear(); } return 0; }
0
20,595,632
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9+7; int main() { ll n,m; cin >> n >> m; vector<ll> a(n,0); vector<int> b(n,0); ll lcm = 1; rep(i,n) { cin >> a[i]; int x = a[i]; while (x % 2 == 0) { x /= 2; b[i]++; } lcm = a[i] / __gcd(a[i],lcm) * lcm; } rep(i,n-1) { if (b[i] != b[i+1]) { cout << 0 << endl; return 0; } } ll ans = (2*m/lcm + 1) / 2; cout << ans << endl; return 0; }
#include <iostream> #include <iomanip> #include <algorithm> #include <complex> #include <utility> #include <vector> #include <string> #include <stack> #include <queue> #include <tuple> #include <cmath> #include <bitset> #include <cctype> #include <set> #include <map> #include <unordered_map> #include <numeric> #include <functional> #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; 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; } inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); } template<class itr> void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template<class itr> void array_output(itr start,itr goal){ string ans = "",k = " "; for (auto i = start;i != goal;i++) ans += to_string(*i)+k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e15; const ll MOD = 1000000007; const ll MOD2 = 998244353; typedef pair<ll,ll> P; const ll MAX = 200010; constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1}; constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,c,k; cin >> n >> c >> k; vector<ll> t(n); cins(all(t)); SORT(t); ll cnt = 0,l = t[0],ans = 1; rep(i,n){ if (cnt < c && l <= t[i] && t[i] <= l+k){ cnt++; } else{ cnt = 1; l = t[i]; ans++; } } PRINT(ans); }
0
38,439,263
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define pii pair<int, int> const int mod = 1e9+7; const int MAXN = 1e5+5; const int N = 1e5+5; int fac[N]; int spf[MAXN]; void pre(int p) { fac[0] = 1; for(int i=1; i<N; i++) { fac[i] = (fac[i-1] * i) % p; } } void sieve() { spf[1] = 1; for (int i=2; i<MAXN; i++) spf[i] = i; for (int i=4; i<MAXN; i+=2) spf[i] = 2; for (int i=3; i*i<MAXN; i++) { if (spf[i] == i) { for (int j=i*i; j<MAXN; j+=i) if (spf[j]==j) spf[j] = i; } } } vector<int> getFactorization(int x) { vector<int> ret; while (x != 1) { ret.push_back(spf[x]); x = x / spf[x]; } return ret; } unsigned long long power(unsigned long long x, int y, int p) { unsigned long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; 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 nCr(unsigned long long n, int r, int p) { if (r == 0) return 1; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } void solve(int TC) { int n; cin >> n; map<int, int> cnt; for(int i=0; i<n; i++) { int x; cin >> x; cnt[x]++; } vector<int> a; for(auto it : cnt) { if(it.second >= 2) { int times = it.second / 2; for(int i=0; i<times; i++) { a.push_back(it.first); } } } sort(a.rbegin(), a.rend()); if((int)a.size() < 2) { cout << 0; return; } int ans = a[0]*a[1]; cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(12); int T = 1; for(int i=1; i<=T; i++) { solve(i); } return 0; }
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<iomanip> using namespace std; int main(){ int n; cin>>n; string s; double u; double sum=0; for(int i=0;i<n;i++){ cin>>u>>s; if(s=="JPY")sum+=u; else sum+=u*380000.0; } cout<<sum<<endl; return 0; }
0
8,108,508
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> A(N),B(N); for(int i=0;i<N;i++){ cin >> A.at(i); } for(int i=0;i<N;i++){ cin >> B.at(i); } int64_t sum=0; int64_t ans=0; vector<int> diff; for(int i=0;i<N;i++){ if(A.at(i)>=B.at(i)){ diff.push_back(A.at(i)-B.at(i)); }else{ sum+=B.at(i)-A.at(i); ans++; } } sort(diff.begin(),diff.end(),greater<int>()); for(int i=0;i<diff.size();i++){ if(sum<=0){ break; } sum-=diff.at(i); ans++; } if(sum>0){ cout << -1 << endl; }else{ cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int a, b, c, d; cin >> a >> b >> c >> d; int count = 0; if(a>b) { count+=b; } else { count+=a; } if(c>d) { count+=d; } else { count+=c; } cout << count << endl; }
0
63,920,198
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define enter putchar('\n') #define space putchar(' ') #define MAXN 100005 typedef long long int64; using namespace std; template<class T> void read(T &res) { res = 0;char c = getchar();T f = 1; while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N; int M = 0; int64 op[35],sum,X[1005],Y[1005]; int64 dx[] = {1,0,-1,0},dy[] = {0,-1,0,1}; char s[1005][45]; const char *dir = "RDLU"; void Solve() { read(N); for(int i = 1 ; i <= N ; ++i) { read(X[i]);read(Y[i]); } for(int i = 2 ; i <= N ; ++i) { if((abs(X[i]) + abs(Y[i])) % 2 != (abs(X[1]) + abs(Y[1])) % 2) { puts("-1");return ; } } bool flag = 0; flag = ((abs(X[1]) + abs(Y[1])) % 2 == 0); if(flag) {op[++M] = 1;} for(int i = 30 ; i >= 0 ; --i) {op[++M] = 1 << i;sum += op[M];} pii st = mp(0,0); if(flag) st = mp(1,0); for(int i = 1 ; i <= N ; ++i) { if(flag) s[i][1] = 'R'; pii p = st; int64 tmp = sum; for(int j = flag ? 2 : 1 ; j <= M ; ++j) { for(int k = 0 ; k <= 3 ; ++k) { int64 tx = p.fi + dx[k] * op[j],ty = p.se + dy[k] * op[j]; int64 a = abs(tx - X[i]) + abs(ty - Y[i]); if(a <= tmp - op[j]) { tmp -= op[j]; s[i][j] = dir[k]; p = mp(tx,ty); break; } } } } out(M);enter; for(int i = 1 ; i <= M ; ++i) { out(op[i]);space; } enter; for(int i = 1 ; i <= N ; ++i) { for(int j = 1 ; j <= M ; ++j) { putchar(s[i][j]); } enter; } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
#include<iostream> #include<vector> #include<string> #include<math.h> #include<algorithm> #include<cstring> using namespace std; int canReach[2][16001]; bool DP(vector<int> v,int t,int start){ memset(canReach,0,sizeof(canReach)); canReach[0][8000+start]=1; if(v.size()==0) return canReach[0][8000+t]; int i; for(i=1;i<=v.size();i++){ for(int j=0;j<=16000;j++){ canReach[i%2][j]=((j+v[i-1])>16000?0:canReach[(i-1)%2][j+v[i-1]])||((j-v[i-1])<0?0:canReach[(i-1)%2][j-v[i-1]]); } } return canReach[(i-1)%2][8000+t]; } int main(){ string S; int tx,ty; cin>>S>>tx>>ty; bool whichAxis=0; vector<int> vx; vector<int> vy; int count=0; int len=S.size(); char c; for(int i=0; i<len; i++){ c=S[i]; if(c=='T'){ ((whichAxis==0)?vx:vy).push_back(count); count=0; whichAxis=!whichAxis; } else{ count++; } } ((whichAxis==0)?vx:vy).push_back(count); int start=vx[0]; vx.erase(vx.begin()); if(DP(vx,tx,start)&&DP(vy,ty,0)) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
0
72,592,185
#include <stdio.h> char number[1001]; int main(){ int x,sum; sum=1; while(sum!=0){ sum=0; while((x=getchar())!='\n'){ sum+=x-'0'; } if(sum==0){ break; } printf("%d\n",sum); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename Q_temp> using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>; const ll MOD = (ll)(1e9 + 7); const int INF = (int)1e9; const ll LINF = (ll)4e18; const double PI = acos(-1.0); #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define MP make_pair #define MT make_tuple #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 all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << endl; vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0}; vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0}; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(50) << setiosflags(ios::fixed); int n; cin >> n; struct vec { ld x, y; }; vector<vec> v; rep(i, n) { ld xi, yi; cin >> xi >> yi; if (xi == 0.0 && yi == 0.0) n--, i--; else v.push_back({xi, yi}); } auto comp = [](vec &v1, vec &v2) { return atan2(v1.y, v1.x) < atan2(v2.y, v2.x); }; sort(all(v), comp); rep(i, n) cerr << v[i].x << " " << v[i].y << endl; cerr << endl; rep(i, n) v.push_back(v[i]); ld Max = 0.0; for (int choose = 1; choose <= n; ++choose) { rep(start, n) { ld x_sum = 0.0, y_sum = 0.0; for (int i = start; i < start + choose; ++i) { x_sum += v[i].x; y_sum += v[i].y; } Max = max(Max, sqrt(x_sum * x_sum + y_sum * y_sum)); } } cout << Max << endl; return 0; }
0
62,692,524
#include <iostream> #include <map> using namespace std; int main() { int n; cin >> n; bool ok = true; map<int, bool> vis; for(int i = 1; i <= n; ++i) { int x; cin >> x; if(ok) ok = !vis[x]; vis[x] = true; } cout << (ok ? "YES" : "NO"); }
#include <bits/stdc++.h> using namespace std; int N,K; const int n=200010; int cnt[n]; int main() { cin>>N>>K; for (int i = 0; i < N; i++) { int a; cin>>a; cnt[a-1]++; } sort(cnt,cnt+N); int ans=0; for (int i = 0; i < N-K; i++) { ans+=cnt[i]; } cout << ans << endl; return 0; }
0
61,537,873
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pl; typedef vector<ll> vl; const int MN = 112; const int inf = 1e9; int n, m, dp[MN][MN]; char s[MN][MN]; int ds (int i, int j) { if (dp[i][j] != -1) return dp[i][j]; int res = inf; if (i+1 < n) { if (s[i][j] == '#') { if (s[i+1][j] == '#') { res = min(res, ds(i+1,j)); } else { res = min(res, ds(i+1,j)+1); } } else { res = min(res, ds(i+1,j)); } } if (j+1 < m) { if (s[i][j] == '#') { if (s[i][j+1] == '#') { res = min(res, ds(i,j+1)); } else { res = min(res, ds(i,j+1)+1); } } else { res = min(res, ds(i,j+1)); } } return dp[i][j] = res; } int main (void) { ios::sync_with_stdio(false);cin.tie(0); cout << fixed << setprecision(15); cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; memset(dp,-1,sizeof(dp)); dp[n-1][m-1] = s[n-1][m-1] == '#'; cout << ds(0,0) << '\n'; return 0; }
#include <bits/stdc++.h> #define INF 1000000000000000001 #define ll long long #define pll pair<ll, ll> using namespace std; vector<bool> next(bool fir, bool sec, string& s) { vector<bool> res = {fir, sec}; ll N = s.size(); for (ll i = 0; i < N; ++i) { if (sec) { if (s[i] == 'o') { res.push_back(fir); } else { res.push_back(!fir); } } else { if (s[i] == 'o') { res.push_back(!fir); } else { res.push_back(fir); } } fir = sec; sec = *(res.end() - 1); } return res; } int main() { ll N; cin >> N; string s; cin >> s; vector<bool> temp = next(true, true, s); for (ll i = 0; i < 2; ++i) { for (ll j = 0; j < 2; ++j) { temp = next(i, j, s); if (temp.at(0) == *(temp.end() - 2) && temp.at(1) == *(temp.end() - 1)) { for (ll i = 1; i < N + 1; ++i) { if (temp.at(i)) { cout << "S"; } else { cout << "W"; } } cout << endl; return 0; } } } cout << -1 << endl; }
0
15,599,702
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++) #define rep(i, n) FOR(i,0,n) typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<double> vd; typedef vector<vector<double>> vvd; typedef vector<vector<vector<double>>> vvvd; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<string> vs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, pair<int, int>> plii; const int bigmod = 1000000007; const int INF = 1050000000; const long long INFll = 100000000000000000; int main() { string s; int x, y; cin >> s >> x >> y; int N = s.length(); int st = N; rep(i, N) { if (s[i] == 'F') x--; else { st = i + 1; break; } } vi X, Y; int sign = 1; int cnt = 0; FOR(i, st, N) { if (s[i] == 'F') cnt++; if (i == N - 1 || s[i] == 'T') { if (sign == 1) Y.push_back(cnt); else X.push_back(cnt); sign *= -1; cnt = 0; } } vvb isReachedX(X.size() + 1, vb(16001, false)), isReachedY(Y.size() + 1, vb(16001, false)); isReachedX[0][8000] = true; isReachedY[0][8000] = true; FOR(i, 1, isReachedX.size()) { rep(j, isReachedX[0].size()) { if (isReachedX[i - 1][j] == true) { isReachedX[i][j + X[i - 1]] = true; isReachedX[i][j - X[i - 1]] = true; } } } FOR(i, 1, isReachedY.size()) { rep(j, isReachedY[0].size()) { if (isReachedY[i - 1][j] == true) { isReachedY[i][j + Y[i - 1]] = true; isReachedY[i][j - Y[i - 1]] = true; } } } if (x + 8000>=0 && y+8000>=0 &&isReachedX[isReachedX.size() - 1][x + 8000] && isReachedY[isReachedY.size() - 1][y + 8000]) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; using namespace std; int main() { int ans = 0, N; string n; cin >> n; N = atoi(n.c_str()); for (int i = 0; i <= n.size(); i += 2) { for (int j = pow(10, i); j < pow(10, i + 1); ++j) { if (j <= N) ans++; else { cout << ans << endl; return 0; } } } cout << ans << endl; }
0
35,176,434
#include<bits/stdc++.h> #define rep(i,n) for(int i=0; i<n; i++) #define INF 10000000 using namespace std; bool check(char x){ for(int i=48; i<=57; i++){ if(x == i) return true; } return false; } int main(){ int n; cin >> n; rep(i,n){ string a,b; cin >> a >> b; int flag = 1; int tmp,sum = 0; rep(j,a.size()){ if(check((int)a[j])) flag = a[j]-'0'; else { if(a[j] == 'm') tmp = 1000; else if(a[j] == 'c') tmp = 100; else if(a[j] == 'x') tmp = 10; else if(a[j] == 'i') tmp = 1; sum += tmp*flag; flag = 1; } } rep(j,b.size()){ if(check(b[j])) flag = b[j]-'0'; else { if(b[j] == 'm') tmp = 1000; else if(b[j] == 'c') tmp = 100; else if(b[j] == 'x') tmp = 10; else if(b[j] == 'i') tmp = 1; sum += tmp*flag; flag = 1; } } if(sum/1000 !=0) { if(sum/1000 == 1) cout << 'm'; else cout << sum/1000 << 'm'; sum -= 1000*(sum/1000); } if(sum/100 !=0) { if(sum/100 == 1) cout << 'c'; else cout << sum/100 << 'c'; sum -= 100*(sum/100); } if(sum/10 !=0) { if(sum/10 == 1) cout << 'x'; else cout << sum/10 << 'x'; sum -= 10*(sum/10); } if(sum/1 !=0) { if(sum/1 == 1) cout << 'i'; else cout << sum/1 << 'i'; } cout << endl; } return 0; }
#include<iostream> #include<cmath> #include<cstdio> #include<vector> #include<set> #include<map> #include<stack> #include<queue> #include<utility> #include<algorithm> #include<cstring> #include<sstream> #include <iomanip> using namespace std; typedef long long ll ; typedef double db; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector< pair<int,int> > vii; const double pi = 2*acos(0) ; #define pf printf #define sf scanf #define pb(a) push_back(a) #define mp make_pair #define fi first #define se second #define for0(i,n) for(int i=0;i<n;i++) #define for1(i,n) for(int i=1;i<=n;i++) #define forab(i,a,b) for(int i=a;i<=b;i++) #define lcm(a, b) ((a)*((b)/gcd(a,b))) #define sq(a) (a)*(a) #define nw "\n" #define abs(x) fabs(x) #define pcase(z,x) cout<<"Case "<<z<<": "<<x<<"\n" int main() { int n,T,d; cin>>n; vi t(n+1),x(n+1),y(n+1); t[0]=x[0]=y[0] = 0; for1(i,n){ cin>>t[i]>>x[i]>>y[i]; } for0(i,n){ T = t[i+1] - t[i]; d = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]); if(d>T || d%2 != T%2){ pf("No"); return 0; } } pf("Yes"); return 0; }
0
69,636,796
#include <iostream> #include <string> using namespace std; int main(){ int h, w; string s; int ansi, ansj; cin >> h >> w; for ( int i = 0; i < h; i++ ){ for ( int j = 0; j < w; j++){ cin >> s; if ( s == "snuke" ){ ansi = i; ansj = j; } } } char c = 'A' + ansj; cout << c << ansi + 1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long long unsigned int ull; typedef long double ld; typedef vector<int> vr; typedef pair<int, int> pr; #define pb push_back #define ff first #define ss second #define INF 1999999999 #define MODA 1000000007 #define PI 3.1415926535897932384626433 #define endl "\n" int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int cnt1 = 0, cnt9 = 0, cnt7 = 0, cnt4 = 0; for(int i = 1; i <= 4; i++){ char a; cin >> a; if(a == '1'){ cnt1++; } else if(a == '9'){ cnt9++; } else if(a == '7'){ cnt7++; } else if(a == '4'){ cnt4++; } } if(cnt1 == 1 && cnt9 == 1 && cnt7 == 1 && cnt4 == 1){ cout << "YES" << endl; } else{ cout << "NO" << endl; } return 0; }
0
69,207,983
#include <bits/stdc++.h> #define rep(l, r) for (int i = (l); i < (r); i++) typedef long long ll; using namespace std; int main() { int nums[3]; rep(0, 3) cin >> nums[i]; sort(nums, nums + 3); cout << (nums[0] == nums[1] ? nums[2] : nums[0]) << endl; return 0; }
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; int N; int main() { cin >> N; vector<int> a(N); int mx = 0; for (int i = 0; i < N; i++) { int tmp; cin >> tmp; a[i] = tmp; mx = max(mx, tmp); } int r = -1; for (int i = 0; i < N; i++) { if (abs(mx - a[i] * 2) < abs(mx - r * 2) && a[i] != mx) { r = a[i]; } } cout << mx << " " << r << endl; }
0
40,124,557
#include <stdio.h> #include <string.h> int main(){ int N; scanf("%d",&N); int a; int b; int c; a = N%10; b = N/10%10; c = N/100; if(a==7||b==7||c==7){ printf("Yes"); }else{ printf("No"); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int init(); int solve(); #define rep(i, a) for (int i = 0; i < (int) (a); i++) #define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++) #define rrep(i, a) for (int i = (int) a-1; i >= 0; i--) #define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--) #define MP(a, b) make_pair((a), (b)) #define PB(a) push_back((a)) #define all(v) (v).begin(), (v).end() #define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;} #define TRUE__ "Yes" #define FALSE__ "No" #define PERM(v) next_permutation(all(v)) #define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end()) #define CIN(type, x) type x;cin >> x #ifdef LOCAL #define lcout(a) cout << a #define lcoutln(a) cout << a << endl #define lcerr(a) cerr << a #define lcerrln(a) cerr << a << endl #else #define lcout(a) #define lcoutln(a) #define lcerr(a) #define lcerrln(a) #endif #define MOD 1000000007 #define PI 3.141592653589793238462643383 signed main() { init(); solve(); } int N; int init() { cin >> N; return 0; } int solve() { int sum = 0; int x; for (x = 1; sum < N; x++) sum += x; reps(i, 1, x) { if (i != sum - N) cout << i << endl; } return 0; }
0
5,813,577
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) 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 INF 1000000000 #define PB push_back #define MP make_pair #define F first #define S second int main(){ int N; cin>>N; int a; int c=1; rep(i,N){ cin>>a; if(a==c){ c++; } } int ans; if(c==1) ans=-1; else ans=N - (c-1); cout<<ans<<endl; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; long long dp[101][2][101] = { 0 }; int main() { string n; int ka; cin >> n >> ka; dp[0][0][0] = 1; for (int i = 0; i < n.size(); i++) { for (int k = 0; k < 101; k++) { dp[i + 1][1][k + 1] += dp[i][1][k] * 9; dp[i + 1][1][k] += dp[i][1][k]; } for (int k = 0; k < 101; k++) { if (n[i] == '0') { dp[i + 1][0][k] += dp[i][0][k]; } else { dp[i + 1][0][k + 1] += dp[i][0][k]; dp[i + 1][1][k + 1] += dp[i][0][k] * int(n[i] - '0' - 1); dp[i + 1][1][k] += dp[i][0][k]; } } } cout << dp[n.size()][0][ka] + dp[n.size()][1][ka] << endl; return 0; }
0
53,136,316
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<vector<int>> v(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; v[a].push_back(b); v[b].push_back(a); } bool ok = false; for (auto s : v[0]) { for (auto t : v[s]) if (t == n - 1) { puts("POSSIBLE"); return 0; } } puts("IMPOSSIBLE"); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 100005 using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N; struct node { int to,next; }E[MAXN * 2]; int head[MAXN],sumE,col[MAXN]; bool flag = 0; void add(int u,int v) { E[++sumE].to = v; E[sumE].next = head[u]; head[u] = sumE; } void dfs(int u,int fa) { int s = 0; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(v != fa) { dfs(v,u); s += col[v]; } } if(s == 0) col[u] = 1; if(s >= 2) flag = 1; } void Solve() { read(N); int a,b; for(int i = 1 ; i < N ; ++i) { read(a);read(b); add(a,b);add(b,a); } dfs(1,0); if(col[1] || flag) puts("First"); else puts("Second"); } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
0
30,506,207
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define rep(i,a,b) for(ll i=a; i<b; i++) #define per(i,a,b) for(ll i=a; i>=b; i--) #define ll long long int #define ld long double #define vi vector<ll> #define vii vector <pair<ll,ll> > #define sedes set <ll, greater <ll> > #define seasc set <ll> #define pb push_back #define mkp make_pair #define ff first #define ss second #define MOD 1000000007 #define prec(n) fixed<<setprecision(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int> > #define umap unordered_map<ll, ll> #define map map<ll, ll> #define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++) #define mems(a, i) memset(a, i, sizeof(a)) #define endl '\n' #define all(v) v.begin(),v.end() #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define deba(a) cout << #a << " " <<a << endl; int main() { fast; #ifndef ONLINE_JUDGE freopen("D:\\input.txt", "r", stdin); freopen("D:\\output.txt", "w", stdout); #endif int t = 1; while (t--) { ll n; cin >> n; ll ans = 0; rep(i, 1, n) for (int j = 1; j * i < n; j++) ans++; cout << ans; } return 0; }
#include <iostream> #include <utility> #include <map> #include <vector> #include <algorithm> #include <queue> #include <math.h> #include <stack> #include <set> #include <deque> #include <cmath> using namespace std; typedef long long ll; ll mod = 1e9+7; #define rep(i,n) for(int i = 0; i < (n); ++i) int main(){ ll n; ll m; cin >> n >> m; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<ll> sum(n+1); sum[0] = 0; map<ll, ll> mp; mp[0] = 1; rep(i, n) { sum[i+1] = (sum[i]+a[i]) % m; ++mp[sum[i+1]]; } ll ans = 0; for ( auto p : mp ) { ans += p.second * (p.second - 1 ) / 2; } cout << ans << endl; return 0; }
0
16,402,057
#include <iostream> #include <vector> #include <climits> #include <algorithm> using namespace std; using Int = long long int; using UInt = unsigned long long int; using VI = vector<unsigned long long int>; void PrintVec(VI& v) { for (Int i = 0; i < v.size(); ++i) { cout << v[i] << endl; } return; } int main(void) { VI num; VI v(100001); v[1] = 1; num.push_back(1); Int six = 6; while(six <= 100000) { v[six] = 1; num.push_back(six); six *= 6; } Int nine = 9; while(nine <= 100000) { v[nine] = 1; num.push_back(nine); nine *= 9; } sort(num.begin(), num.end()); for (Int i = 2; i <= 100000; ++i) { v[i] = INT_MAX; bool exist = false; for (Int j = 0; j < num.size(); ++j) { if (i == num[j]) { exist = true; } } if (exist == true) { v[i] = 1; } else { for (Int j = 0; j < num.size(); ++j) { if (num[j] < i) { v[i] = min(v[i], v[i - num[j]] + 1); } } } } Int n; cin >> n; cout << v[n] << endl; return 0; }
#include <iostream> #include <cmath> #include <cstdint> int main() { int64_t a, b, c, d; std::cin >> a >> b >> c >> d; int64_t num[4] = {a * c, a * d, b * c, b * d}; int64_t max = num[0]; for(int i = 1; i < 4; i++) { if(num[i] > max) { max = num[i]; } } std::cout << max << std::endl; return 0; }
0
97,370,192
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define LLINF 1e18 #define pi 3.14159265358979323 #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int gcd(int a, int b) { if(a % b == 0) { return b; } else { return(gcd(b, a % b)); } } int main() { int ha, ma, hb, mb, k; cin >> ha >> ma >> hb >> mb >> k; int time = (hb - ha) * 60; time += mb - ma; cout << time - k << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define all(n) begin(n),end(n) using ll = long long; using P = pair<int,int>; int main() { int n; string s, t; cin >> n >> s >> t; string temp; rep(i,n) { if(s.substr(i, n) == t.substr(0, n-i)){ temp = s.substr(0, i) + t; int ans = temp.size(); cout << ans << endl; return 0; } } int ans = s.size() + t.size(); cout << ans << endl; return 0; }
0
15,646,397
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll) 1e15; struct Vertex { vector<ll> node; }; Vertex V[105]; ll C[105]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; REP(i, N) { C[i] = INF; } REP(i, N) { ll n, k; cin >> n >> k; n--; REP(_, k) { ll v; cin >> v; v--; V[n].node.push_back(v); } } queue<pll> q; q.push(pll(0, 0)); C[0] = 0; while (!q.empty()) { pll t = q.front(); q.pop(); ll cost = t.second + 1; for (auto &n:V[t.first].node) { if (C[n] <= cost) continue; C[n] = cost; q.push(pll(n, cost)); } } REP(i, N) { cout << i + 1 << " "; if (C[i] == INF) cout << -1; else cout << C[i]; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; int main() { int N; string S; cin >> N; cin >> S; if (S[0] == 'W' || S[2 * N - 1] == 'W') { cout << 0 << endl; return 0; } vector<int> C(2 * N); C[0] = 1; long long int cnt = 1; for (int i = 1; i < 2 * N; i++) { if (S[i] == S[i - 1]) { C[i] = 1 - C[i - 1]; } else { C[i] = C[i - 1]; } cnt += (2 * C[i] - 1); } if (C[2 * N - 1] == 1 || (cnt != 0)) { cout << 0 << endl; return 0; } cnt = 1; int cl = 0; for (int i = 0; i < 2 * N; i++) { if (C[i]) { cl++; } else { cnt = cnt * cl % MOD; cl--; } } for (int i = 0; i < N; i++) { cnt = cnt * (i + 1) % MOD; } cout << cnt << endl; }
0
28,781,958
#include <cstdio> int N, M, f[100001], w[100001], b[100001], d[100001]; int F(int x) { if (f[x] == x) return x; F(f[x]); w[x] ^= w[f[x]]; return f[x] = f[f[x]]; } int main() { scanf("%d%d", &N, &M); for (int i = 1; i <= N; i++) f[i] = i; for (int i = 1, u, v; i <= M; i++) { scanf("%d%d", &u, &v); d[u]++; d[v]++; int fu = F(u), fv = F(v); if (fu == fv) { if (w[u] == w[v]) b[fu] = 1; } else { b[fu] |= b[fv]; w[fv] = w[u] ^ w[v] ^ 1; f[fv] = fu; } } int c1 = 0, ce = 0, c = 0; for (int i = 1; i <= N; i++) if (!d[i]) c1++; else if (F(i) == i) { c++; if (!b[i]) ce++; } printf("%lld\n", (long long)c * c + (long long)ce * ce + (long long)N * N - (long long)(N - c1) * (N - c1)); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, m, n) for (int i = (m); i < (int)(n); i++) #define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define reps(i, n) for (int i = 0; i <= (int)(n); i++) #define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define rreps(i, x) for (int i = (int)(x); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define fi first #define se second typedef long long ll; typedef pair<int, int> P; const int inf = INT_MAX; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; const double EPS = 1e-10; const double PI = acos(-1.0); 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; } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); } template <class T1, class T2, class Pred = std::less<T2> > struct sort_pair_second { bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) { Pred p; return p(left.second, right.second); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> a(N); rep(i, N) cin >> a[i]; ll s = 0; rep(i, N) s ^= a[i]; ll ans = s; rep(i, N) { a[i] &= ~s; } int r = 0; vector<int> top(N); for (int i = 60; i >= 0; i--) { int j = r; for (; j < N; j++) { if (a[j] >> i & 1) { swap(a[r], a[j]); break; } } if (j == N) continue; top[r] = i; rep(k, N) { if (r == k) continue; if (a[k] >> i & 1) a[k] ^= a[r]; } r++; } ll x = 0; for (int i = 60; i >= 0; i--) { ll nx = x | (1ll << i); ll b = nx; rep(j, r) { if (b >> top[j] & 1) b ^= a[j]; } if ((b & nx) == 0) { x = nx; } } ans += x * 2; cout << ans << endl; return 0; }
0
66,217,444
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll n,m,k; cin >> n >> m >> k; for(ll i=0;i<=n;i++){ for(ll j=0;j<=m;j++){ ll ans = (n-i)*j+(m-j)*i; if(ans==k){ cout << "Yes" << endl; return 0; } } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> #define WHOLE(v) (v).begin(), (v).end() #define REV_WHOLE(v) (v).rbegin(), (v).rend() using i64 = int64_t; using namespace std; template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};} template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>; template<class T>using vector2d=vector<vector<T>>; struct fixprec{int p;fixprec(int p):p(p){}}; ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);} i64 pmod(i64 x, i64 m) { return (x % m + m) % m; } using P = pair<i64, i64>; int main() { i64 N, L, T; cin >> N >> L >> T; vector<P> data(N); for(P&d : data) { cin >> d.first >> d.second; if(d.second == 2) d.second = -1; } i64 a0, w0, x0; vector<i64> ans(N); for(int i = 0; i < N; i++) { i64 x, w; tie(x, w) = data[i]; ans[i] = pmod(x + w * T, L); } tie(x0, w0) = data[0]; a0 = ans[0]; sort(WHOLE(ans)); int k; for(int i = 0; i < N; i++) { if(ans[i] == a0) { k = i; if(w0 == -1) break; } } i64 shift = 0; for(int i = 1; i < N; i++) { if(w0 != data[i].second) { i64 D; if(w0 == 1) { D = data[i].first - x0; } else { D = x0 + L - data[i].first; } if(D <= 2 * (T % L)) shift++; if(D + L <= 2 * (T % L)) shift++; shift += 2 * (T / L); shift %= N; } } for(int i = 0; i < N; i++) { cout << ans[pmod(k - w0 * shift + i, N)] << endl; } return 0; }
0
59,081,496
#pragma GCC optimize("avx2, O3") #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <queue> #include <set> #include <map> #include <iomanip> #include <deque> #include <map> #include <fstream> #include <utility> #include <stack> #include <unordered_map> #include <unordered_set> #include <numeric> #include <random> #include <math.h> #include <cassert> #include <bitset> #include <chrono> #include <sstream> #include <array> using namespace std; #define DEBUG_VIVOD " SHTO-TO POSHLO NE TAK\n" #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define pf push_front #define _USE_MATH_DEFINES #define filin(x) freopen(x, "r", stdin) #define filout(x) freopen(x, "w", stdout) #define deq deque #define vec vector #define umap unordered_map #define uset unordered_set #define nan nullptr #define rtn(x) {return x;} typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef unsigned long long ui; #define INF 1e9 mt19937 prof_rand(time(0)); #define rand() prof_rand() signed main() { int n; cin >> n; vector<int> ar(n); ll s = 0; for (auto& it : ar) { cin >> it; s += it; } ll k = s / ((ll)n * (n + 1) / 2ll); if (k == 0) { cout << (s == 0 ? "YES" : "NO"); return 0; } if (s % ((ll)n * (n + 1) / 2ll) != 0) { cout << "NO"; return 0; } vector<int> d(n); s = 0; for (int i = 0; i < n; ++i) s += d[i] = ar[(i + 1) % n] - ar[i]; if (s != 0) { cout << "NO"; return 0; } for (int i = 0; i < n; ++i) if ((k - d[i]) % n != 0 || (k - d[i]) < 0) { cout << "NO"; return 0; } cout << "YES"; return 0; }
#include <bits/stdc++.h> #include<cmath> using namespace std; #define int long long int #define pb push_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define F first #define S second #define all(a) a.begin(),a.end() #define endl '\n' #define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define mod 1000000007 #define inf 1e18 #define pf push_front #define pob pop_back #define pof pop_front #define deb(x) cout<<#x<<" "<<x<<endl; #define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl; #define deb3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl; #define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); typedef pair<int,int> pi; typedef pair<int,pair<int,int>> piii; typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<vi> vvi; int32_t main() { int t=1; while(t--) { int n; cin>>n; if(n<3) { cout<<"0"<<endl; continue; } if(n<6) { cout<<"1"<<endl; continue; } int dp[n+1]={0}; dp[0]=dp[1]=dp[2]=0; dp[3]=dp[4]=dp[5]=1; dp[6]=2; for(int i=7;i<=n;i++) { dp[i]=1; for(int j=3;j<=i-3;j++) { dp[i]+=dp[j]; dp[i]%=mod; } } cout<<dp[n]<<endl; } }
0
59,138,113
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <utility> #include <stack> #include <functional> #include <queue> #include <cmath> #include <set> #include <map> #include <numeric> #define rep(i,j,k) for(int i=(int)j;i<(int)k;i++) #define Sort(x) sort((x).begin(),(x).end()) #define all(x) (x).begin(),(x).end() #define fi first #define se second #define vi vector<int> #define INF (int)1e9 #define INFL 1e18 #define MOD 1000000007 #define pb push_back #define MP make_pair typedef long long int ll; typedef std::pair<int,int> P; int D=1; int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0}; using namespace std; int main(){ int n; cin>>n; vector<vector<int>> v(n,vector<int>(n,0)); rep(i,0,n){ int u,k; cin>>u>>k; rep(j,0,k){ int x; cin>>x; v[u-1][x-1]=1; } } rep(i,0,n){ rep(j,0,n){ if(j)cout<<" "; cout<<v[i][j]; } cout<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define LLINF 9223372036854775807 #define MOD ll(1e9+7) int main(){ int n; cin >> n; vector<int> yes; int v = 2; while(v*(v+1)/2<=n){ yes.push_back(v*(v+1)/2); v++; } int exist = -1; for(int i = 0; i < yes.size(); i++){ if(yes[i] == n){ exist = i; } } if(n == 1){ cout << "Yes" << endl; cout << 2 << endl; cout << "1 1" << endl; cout << "1 1" << endl; return 0; } if(exist == -1){ cout << "No" << endl; return 0; } exist += 2; vector<vector<int>> ans(exist+1,vector<int>(exist,0)); int num = 1; for(int cur = 0; cur < exist; cur++){ for(int i = 0; i < exist - cur; i++){ ans[cur][cur+i] = num; ans[cur+1+i][cur] = num; num++; } } cout << "Yes" << endl; cout << exist+1 << endl; for(int i = 0; i < exist+1; i++){ cout << exist << " "; for(int j = 0; j < exist-1; j++){ cout << ans[i][j] << " "; } cout << ans[i][exist-1] << endl; } return 0; }
0
74,912,611
#include <iostream> #include <cmath> #include <algorithm> #include <map> #include <utility> #include <iomanip> #include <queue> #include <set> #include <numeric> #include <unordered_set> #define rep(i,n) for(int i=0;i< (n);++i) typedef long long ll; using namespace std; ll gcd(ll a,ll b){ while(true){ b=b%a; if(b==0){ return a; } a=a%b; if(a==0){ return b; } } } ll lgd(ll a,ll b){ return a*b/gcd(a,b); } int main(){ ll A,B; cin>>A>>B; cout<<lgd(A,B)<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, uint>; const ll INF64 = 1LL << 60; const int INF32 = 1 << 29; const int MOD = 1000000007; const int CASES = 2; void solve(){ int N, K; cin >> N >> K; vector<ll> A(N); for(int i = 0; i < N ; ++i) cin >> A[i]; vector<ll> ands; for(int i = 0; i < N ; ++i){ ll tmp = A[i]; ands.push_back(tmp); for(int j = 1; i + j < N ; ++j){ tmp += A[i + j]; ands.push_back(tmp); } } ll ans = 0; for(ll i = 61; i >= 0; --i){ vector<ll> vec; ll tmp = (1LL << i); for(int j = 0; j < ands.size(); ++j){ if( (ands[j] & tmp) != 0){ vec.push_back(ands[j]); } } if(vec.size() >= K){ ands = vec; ans |= tmp; } } cout << ans << '\n'; } int main() { #ifdef MYLOCAL vector<string> filenames {"input1.txt", "input2.txt", "input3.txt"}; cout << "------------\n"; for(int i = 0; i < CASES; ++i){ ifstream in(filenames[i]); cin.rdbuf(in.rdbuf()); solve(); cout << "------------\n"; } #else solve(); #endif return 0; }
0
34,358,483
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; using P = pair<ll, ll>; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } 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; } struct edge { ll to, cost; }; int main() { ll N; cin >> N; ll ans = 0; REP(i, N) { ans += (i + 1); } cout << ans - N << endl; }
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> #include <iomanip> #include <cstdlib> #include <algorithm> #include <numeric> #include <stdio.h> #include <vector> #include <map> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) int main() { ll N; cin >> N; ll A[N]; rep(i,N) cin >> A[i]; ll B[N]; rep(i,N) cin >> B[i]; ll out = 0; ll plus = 0; ll minus = 0; ll C[N]; rep(i,N){ C[i] = A[i]-B[i]; if(C[i]<0){ out++; minus -= C[i]; }else plus += C[i]; } if(minus>plus) out = -1; else if(out>0){ sort(C,C+N); rep(i,N){ minus -= C[N-1-i]; out++; if(minus<=0) break; } } cout << out << endl; return 0; }
0
83,010,612
#include<bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define ll long long #define rep(i,n) for(int i = 0; i < int(n); i++) #define vi vector<int> using namespace std; const int INF = 1001001001; const int MOD = 1e9+7; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; } int main(){ cin.tie(0), ios::sync_with_stdio(false); int n; cin >> n; vi a(n); int minus = 0, plus = 0; rep(i,n){ cin >> a[i]; if(0 < a[i]) plus++; if(a[i] < 0) minus++; } sort(all(a)); int cnt = 0; vi x,y; while(1 < minus && a.size() != 1){ cnt++; if(a.back() < 0) minus--; x.push_back(a.back()); y.push_back(a[0]); a.back() -= a[0]; minus--; a.erase(a.begin()); } if(a.size() == 1){ cout << a[0] << endl; rep(i,cnt) cout << x[i] << " " << y[i] << endl; return 0; } if(minus == 0 && a.size() == 2){ cout << a[1]-a[0] << endl; cout << a[1] << " " << a[0]; return 0; } int num = a[0]; a.erase(a.begin()); if(minus == 0){ cnt++; x.push_back(num); y.push_back(a[0]); num -= a[0]; a.erase(a.begin()); } while(a.size() != 1){ cnt++; x.push_back(num); y.push_back(a[0]); num -= a[0]; a.erase(a.begin()); } cnt++; x.push_back(a[0]); y.push_back(num); a[0] -= num; cout << a[0] << endl; rep(i,cnt) cout << x[i] << " " << y[i] << endl; return 0; }
#include <iostream> using namespace std; int main() { int first = 0; int second = 0; int third = 0; for (int i = 0; i < 10; ++i) { int number; cin >> number; if (number <= third) continue; third = number; if (third <= second) continue; swap(second, third); if (second <= first) continue; swap(first, second); } cout << first << endl << second << endl << third << endl; return 0; }
0
68,609,546
#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; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef string str; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector <pii> vpii; typedef vector <pll> vpll; typedef map <str,int> mapsi; typedef map <str,int> :: iterator mapsitr; typedef map <int , int> mint; typedef map <ll , ll> mll; typedef set <int> si; typedef set <ll> sll; typedef si :: iterator sitr; typedef si :: reverse_iterator rsitr; typedef sll :: iterator sltr; typedef sll :: reverse_iterator rsltr; #define mset multiset typedef mset <int> msi; typedef mset <ll> msll; typedef msi :: iterator msitr; typedef msi :: reverse_iterator msritr; typedef msll :: iterator msltr; typedef msll :: reverse_iterator mslritr; #define mp make_pair #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define fi first #define se second #define fs first.second #define ss second.second #define ff first.first #define sf second.first #define newl '\n' char to_upper (char x){ if( 97 <= int(x) && int(x) <= 122)return char(x-32); else if( 65 <= int(x) && int(x) <= 90)return x; } char to_lower (char x){ if( 97 <= int(x) && int(x) <= 122)return x; else if( 65 <= int(x) && int(x) <= 90)return char(x+32); } int numerize (char x){ if(48 <= int(x) && int(x) <= 57)return int(x-'0'); else if( 97 <= int(x) && int(x) <= 122)return int(x-96); else if( 65 <= int(x) && int(x) <= 90)return int(x-64); } bool isect (int l1, int r1, int l2, int r2){ pii p1,p2; p1 = mp(l1,r1); p2 = mp(l2,r2); if(p1>p2)swap(p1,p2); if(p2.fi <= p1.se)return true; else return false; } ll quickpow (ll num1, ll num2, ll MOD){ if(num2==0)return 1; else if(num2==1)return num1; else{ ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD; if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res; } } ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);} ll gcd (ll num1, ll num2){ if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ; while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;} return num2; } ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;} int n,ans; map <int,int> f; map <int,int> :: iterator itr; priority_queue <pii> q; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=1;i<=n;i++) { int temp; cin>>temp; f[temp]++; } for(itr=f.begin();itr!=f.end();++itr){ int temp = itr->se; if(temp>=3){ int x = ((temp-3)/2) + 1; ans+=x; f[itr->fi] -= 2*x; } q.push(mp(itr->se,itr->fi)); } while(q.top().fi > 1){ int f1,n1,f2,n2; f1 = q.top().fi; n1 = q.top().se; q.pop(); f2 = q.top().fi; n2 = q.top().se; q.pop(); f1--;f2--; if(f1) q.push(mp(f1,n1)); if(f2) q.push(mp(f2,n2)); } ans = 0; while(!q.empty()){ ans += q.top().fi; q.pop(); } cout<<ans<<newl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define REPR(i,n) for(int i=n; i>-1; --i) #define ALL(a) (a).begin(),(a).end() #define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); } #define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; } #define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} } #define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} } #define Liny "Yes\n" #define Linn "No\n" #define LINY "YES\n" #define LINN "NO\n" #define umap unordered_map int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}} int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} } int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );} ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);} ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;} int main(){ int N; cin>>N; map<string, int> plist; int cumu[N+1]; cumu[0] = 0; REP(i,N){ string s; cin>>s; int t; cin>>t; plist[s] = i+1; cumu[i+1] = cumu[i] +t; } string X; cin>>X; int idx = plist[X]; cout << cumu[N]-cumu[idx] <<"\n"; }
0
3,138,883
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define P pair<ll, ll> #define Graph vector<vector<ll>> #define fi first #define se second constexpr ll mod = 1000000007; constexpr ll INF = (1ll << 60); constexpr double pi = 3.14159265358979323846; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { string S; ll w; cin >> S >> w; for (ll i = 0; i < S.size(); i += w) { cout << S[i]; } cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t A,B; cin >> A >> B; int64_t num; int64_t ans = 0; if ( A % 2 == 0 ){ if ( B % 2 == 0 ){ num = B - A; ans = num/2; ans = ans%2; ans = ans^B; } else { num = B - A + 1; ans = num/2; ans = ans%2; } } else { if ( B % 2 == 0 ){ num = B - A - 1; ans = num/2; ans = ans%2; ans = ans^A; ans = ans^B; } else { num = B - A; ans = num/2; ans = ans%2; ans = ans^A; } } cout << ans << endl; return 0; }
0
80,648,871
#include<cstdio> #include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; int main() { string str; int n; cin >> str>>n; while (n--){ string require; cin >> require; if (require == "replace"){ int a, b; string p; cin >> a >> b >> p; str.replace(a, b - a + 1, p); } else if (require == "reverse"){ int a, b; string rev; cin >> a >> b; rev = str.substr(a, b - a + 1); reverse(rev.begin(), rev.end()); str.replace(a, b - a + 1, rev); } else{ int a, b; cin >> a >> b; cout << str.substr(a, b - a + 1) << endl; } } }
#include <cstdio> #include <cstring> using namespace std; int main() { int W, H; int N; int state[16][16]; int dp[16][16]; while (scanf("%d %d", &W, &H) && W != 0){ scanf("%d", &N); memset(state, 0, sizeof(state)); memset(dp, 0, sizeof(dp)); for (int i = 0; i < N; i++){ int x, y; scanf("%d %d", &x, &y); --x; --y; state[y][x] = 1; } dp[0][0] = 1; for (int i = 0; i < H; i++){ for (int j = 0; j < W; j++){ if (state[i][j] == 1){ continue; } if (i - 1 >= 0){ dp[i][j] += dp[i - 1][j]; } if (j - 1 >= 0){ dp[i][j] += dp[i][j - 1]; } } } printf("%d\n", dp[H - 1][W - 1]); } return (0); }
0
66,066,818
#include <bits/stdc++.h> using namespace std; #define pi acos(-1) #define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); #define ff first #define ss second #define pb push_back #define debug(val) cerr << "The value of " << #val << " is = " << val << '\n'; typedef long long ll; typedef unsigned long long ull; const ll mod = 1e9 + 7; const ll inf = 0x3f3f3f3f; const ll mininf = -922337203685477; const ll nax = 0; ll n; int main(){ IOS cin >> n; n--; ll temp=(1+n); if(n%2==0){ cout << n/2 * temp << '\n'; } else{ temp/=2; cout << n*temp << '\n'; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int,int>; int main(){ int l, r; cin >> l >> r; if(r - l >= 2019) cout << 0 << endl; else{ vector<int> n; for(int i = l; i <= r; i++){ n.push_back(i % 2019); } vector<int> m; rep(i,n.size()){ for(int j = i+1; j < n.size(); j++) m.push_back((n[i]*n[j])%2019); } sort(m.begin(), m.end()); cout << m[0] << endl; } }
0
29,697,788
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; cout << t << s << endl; return 0; }
#include <iostream> #include <queue> #include <string> #include <stdio.h> using namespace std; int main(){ string command; int k; priority_queue<int> S; while(cin >> command && command != "end"){ if(command == "insert"){ cin >> k; S.push(k); }else if(command == "extract"){ cout << S.top() << endl; S.pop(); } } }
0
85,811,482
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL<<62 #define inf 1000000007 int main() { ll n; cin>>n; ll cnt1=n/100; ll cnt2=n%100; if(cnt1*5>=cnt2){ cout << 1; } else{ cout << 0; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef pair<int,int>P; int main(){ int N,M; while(1){ cin >>N>>M; if(N==0 && M==0)break; P a[N]; for(int i=0 ; i < N ; i++){ cin >>a[i].second>>a[i].first; } sort(a,a+N,greater<P>()); for(int i=0 ; i < N ; i++){ int d=min(M,a[i].second); M-=d; a[i].second-=d; } int ans=0; for(int i=0 ; i < N ; i++){ ans+=a[i].first*a[i].second; } cout <<ans<<endl; } return 0; }
0
48,233,908
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for (int i = 0; i < (n); ++i) int H, W, K; int main() { cin >> H >> W >> K; vector<string> s(H); rep(i, H) cin >> s[i]; int ans = 0; rep(is, 1 << H) rep(js, 1 << W) { int cnt = 0; rep(i, H) rep(j, W) { if ((is >> i) & 1) continue; if ((js >> j) & 1) continue; if (s[i][j] == '#') cnt++; } if (cnt == K) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e6+10; const int mod=1e9+7; const int inf=0x3f3f3f3f; ll n,cnt=0; ll a[N],f[N]; bool prime[N]; string s1,s2; int main() { ios::sync_with_stdio(false); ll t, i, j = 0; ll m, x, y,k; memset(prime,true,sizeof(prime)); for(i=2;i<=N;i++){ if(prime[i]){ for(j=i*2;j<=N;j+=i) prime[j]=false; } } cin>>n; for(i=0;i<n;i++) { cin>>x; if(prime[x]) f[x]++; else{ for(j=2;j<=sqrt(x);j++){ if(x%j==0) f[j]++; while(x%j==0) x/=j; } f[x]++; } } bool f1=true,f2=true; for(i=2;i<=N;i++){ if(f[i]>1) f1=false; if(f[i]>=n) f2=false; } if(f1) cout<<"pairwise coprime"; else if(f2) cout<<"setwise coprime"; else cout<<"not coprime"; cout<<endl; return 0; }
0
23,777,289
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define all(v) begin(v),end(v) using ll = long long; int main() { int n,a,b;cin>>n>>a>>b; int cnt=0; for(int i=1;i<=n;i++){ int c=i,ans=0; while(c){ ans+=c%10; c/=10; } if(a<=ans&&ans<=b)cnt+=i; } cout<<cnt<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ map<long long,int> dict; int n; cin >> n; for(int i=0;i<n;i++){ int a; cin >> a; if(dict.count(a)){ cout << "NO" << endl; return 0; }else{ dict[a] = 1; } } cout << "YES" << endl; }
0
3,264,460
#include <bits/stdc++.h> #include <boost/range/adaptors.hpp> #include <boost/range/irange.hpp> using namespace std; using namespace boost; using namespace boost::adaptors; int main() { int64_t n, m; cin >> n >> m; vector<bool> e(n); for (auto _ : irange(0L, m)) { int64_t a, b; cin >> a >> b; --a; --b; e[a] = !e[a]; e[b] = !e[b]; } if (count(e.begin(), e.end(), true) == 0) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" using namespace std; using ll = long long; const ll MOD = 1000000007LL; const double PI = 3.14159265358979; class UnionFind{ public: vector<int> p; vector<int> rank; UnionFind(int n){ p.resize(n, -1); rank.resize(n, 1); } int root(int x){ if(p[x] == -1)return x; else return p[x] = root(p[x]); } void unite(int x, int y){ x = root(x); y = root(y); if(x == y)return; if(rank[x] > rank[y]) swap(x, y); rank[y] += rank[x]; p[x] = y; } int size(int x){ return rank[root(x)]; } bool same(int x, int y){ return (root(x) == root(y)); } }; void solve() { int n, m; cin >> n >> m; vector<int> p(n); for(int i = 0; i < n; ++i) { cin >> p[i]; } UnionFind uf(n + 1); ll inx, iny; for(int i = 0; i < m; ++i) { cin >> inx >> iny; uf.unite(inx, iny); } int ans = 0; for(int i = 0; i < n; ++i) { ans += uf.root(i + 1) == uf.root(p[i]); } cout << ans; } int main() { fastio; solve(); return 0; }
0
46,394,532
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,x,n) for(int i=x;i<n;i++) #define mod 1000000007 #define INF 1000000000000 #define F first #define S second #define P pair<int,int> #define all(vec) vec.begin(),vec.end() int n,m; int h[200000]; int ans=0; vector<int>vec[200000]; signed main(){ cin>>n>>m; rep(i,n)cin>>h[i+1]; rep(i,m){ int a,b; cin>>a>>b; vec[a].push_back(b); vec[b].push_back(a); } rep(i,n){ int l=vec[i+1].size(); bool gt=true; rep(j,l){ if(h[i+1]<=h[vec[i+1][j]])gt=false; } if(gt){ ans++; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; int main(){ int n, m, x; cin >> n >> m >> x; vi c(n); vector<vector<int>> a(n, vector<int>(m)); rep(i,n){ cin >> c[i]; rep(j,m) cin >> a[i][j]; } ll ans = 1000000000000000000; rep(is,1<<n){ ll money=0; vi total(m,0); rep(i,n){ if(is>>i&1){ rep(j,m) total[j] += a[i][j]; money += c[i]; } } sort(total.begin(),total.end()); if(total[0] >= x) ans = min(ans, money); } if(ans == 1000000000000000000) cout << -1 << endl; else cout << ans << endl; }
0
51,729,168
#include <math.h> #include <iostream> #include <stdio.h> using namespace std; typedef long long ll; int main() { ll X,Y; cin >> X >> Y; ll out = X+Y/2; cout << out << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define PI acos(-1) #define INF 100000000 #define sc(n) scanf("%d",&n); #define ssc(n) scanf("%s",n); #define lsc(n) scanf("%lld",&n); #define dsc(n) scanf("%lf",&n); #define csc(n) scanf("%c",&n); #define LL long long int #define UI unsigned int #define ULL unsigned long long int #define DB double #define pii pair<int,int> #define VI vector<int> #define MII map<int,int> #define PB push_back #define MP make_pair #define M(mx,a) mx=max(mx,a) #define IT ::iterator #define all(a) a.begin(),a.end() #define mems(a,b) memset(a,b,sizeof(a)) #define F(i,a,b) for(i=a;i<b;i++) #define IN(n,aa) for(i=0;i<n;i++)scanf("%d",&aa[i]); #define PNT(n,aa) for(i=0;i<n;i++)printf("%lld ",aa[i]); #define mod 1000000007 #define NUM 10000009 #define NUM2 1000000000 int main() { int T=1,QQ=0; while(T--) { char c; cin >> c; if(c=='A')cout << "T" ; else if(c=='C')cout << "G" ; else if(c=='T')cout << "A" ; else cout << "C" ; } }
0
81,061,770
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) int main(){ ll X; cin >> X; ll n = X/100; ll m = X - 100*n; if(m <= 5*n)cout << 1 << endl; else cout << 0 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int ma=0; for(int i=0;i<2;i++){ int sum=0; for(int j=0;j<4;j++){ int a; cin>>a; sum+=a; } ma=max(ma,sum); } cout<<ma<<endl; return 0; }
0
6,500,389
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; const int inf = 1e9; const ll INF = 1e18; const double pi = 3.14159265358979323846; #define rep(i,n) for(int i=0;i<n;i++) int main(){ int n;cin>>n; ll a[n],b[n],c[n]; rep(i,n) { cin>>a[i]>>b[i]; c[i]=-(a[i]%b[i]); if(a[i]%b[i]!=0) c[i]+=b[i]; } for(int i=n-1;i>0;i--){ if(c[i-1]<c[i]){ ll cnt=(c[i]-c[i-1])/b[i-1]; if((c[i]-c[i-1])%b[i-1]!=0) cnt++; c[i-1]+=b[i-1]*cnt; } } cout<<c[0]<<"\n"; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <unordered_map> #include <unordered_set> using namespace std; 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; } int main(){ long long N; vector <long long> arr; cin >> N; for(int i=0; i < N; ++i){ long long tmp; cin >> tmp; arr.push_back(tmp); } long long sum = 0; long long max = arr[0]; for(int i=1; i < N; ++i){ if(max>arr[i]){ sum += (max-arr[i]); } else{ max = arr[i]; } } cout << sum << endl; return 0; }
0
24,329,986
#include <bits/stdc++.h> #pragma GCC optimize("O2") #define vi vector<int> #define vpii vector<pii> #define pii pair<int, int > #define mp make_pair #define fi first #define se second #define pb push_back #define LL long long #define rep(i,a,n) for (int i=a;i<=n;i++) #define per(i,a,n) for (int i=n;i>=a;i--) #define all(x) (x).begin(), (x).end() #define aal(x,n) (x+1), (x+1+n) #define sz(x) ((int)(x).size()) #define mod(x) ((x)%MOD) #define eb emplace_back #define o(X) (1<<(X)) #define oL(X) (1LL<<(X)) #define ppt(x) __builtin_popcount(x) using namespace std; const int INF=0x3f3f3f3f,N=2e6+5,MOD=1004535809; const LL INF_LL=0x3f3f3f3f3f3f3f3fLL; template<typename T> inline int getplc(T x,int y) { return (x>>y)&1; } template<typename T> T square(T x) {return x*x;} LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){ LL res=1; for(;b;b>>=1,a=a*a%_MOD){ if(b&1)res=res*a%_MOD; } return res; } template <typename T> T Smax(T x) { return x; } template<typename T, typename... Args> T Smax(T a, Args... args) { return max(a, Smax(args...)); } template <typename T> T Smin(T x) { return x; } template<typename T, typename... Args> T Smin(T a, Args... args) { return min(a, Smin(args...)); } template <typename T> #define errorl(args...) { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ errl(_it, args); \ } void errl(istream_iterator<string> it) {} template<typename T, typename... Args> void errl(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; errl(++it, args...); } #define error(args...) { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ cerr<<endl; \ } 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...); } void Solve(){ int x; cin>>x; int k=360/__gcd(360,x); cout<<k<<endl; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif ios::sync_with_stdio(false);cin.tie(0),cout.tie(0); Solve(); return 0; }
#include <bits/stdc++.h> using namespace std; signed main () { int n, l; cin >> n >> l; vector < int > a(n + 1, 0); int j = 0; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i < n; ++i) { if (a[i] + a[i + 1] >= l) { j = i; break; } } if (j == 0) cout << "Impossible\n"; else { cout << "Possible\n"; for (int i = 1; i < j; ++i) cout << i << '\n'; for (int i = n - 1; i > j; --i) cout << i << '\n'; cout << j << '\n'; } }
0
81,032,550
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define P pair<int,int> int main(){ ll n,x; cin>>n>>x; --x; vector<vector<ll>> index(n+1,vector<ll>(3)); vector<ll> p(n+1); index[0][0]=0; index[0][1]=0; index[0][2]=0; p[0]=1; for(int i =1; i <= n; i++){ index[i][0]=0; index[i][2]=(index[i-1][2]+1)*2+3-1; index[i][1]=index[i][2]/2; p[i]=p[i-1]*2+1; } ll ans=0; for(int i = n; i >= 0; i--){ if(x==index[i][1]){ ans+=p[i]/2+1; break; } if(x==index[i][0]) break; if(x==index[i][2]){ ans+=p[i]; break; } if(index[i][0]<x && x<index[i][1]){ x--; } if(index[i][1]<x && x<index[i][2]){ x=x-index[i][1]-1; ans+=p[i]/2+1; } } cout<<ans<<endl; }
#include <bits/stdc++.h> #define lli long long int #define vec2 vector<vector<lli>> #define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define FRE freopen("explicit.in","r",stdin);freopen("explicit.out","w",stdout) #define pll pair <lli,lli> #define vll vector <lli> #define vpll vector <pll> #define f first #define s second #define pb push_back #define priq priority_queue #define unm unordered_map #define pf push_front #define minii LLONG_MAX #define all(x) x.begin(), x.end() #define mem(a,b) memset(a,b,sizeof(a)) #define ld double #define eb emplace_back const long double pi = 3.1415926535898; const lli mod=1e9+7; using namespace std; lli lcm (lli a, lli b) {return ((a*b)/__gcd(a,b));} lli modpower (lli a,lli b) { if(b==0) return 1; lli c=modpower(a,b/2)%mod; if (b%2) return (((a*c)%mod)*c)%mod; else return (c*c)%mod; } lli power (lli a,lli b) { if(b==0) return 1; lli c=power(a,b/2); if (b%2) return (a*c*c); else return c*c; } bool prime (lli k) { if (k==1||k==0) return 0; bool flag=1; lli a=sqrt(k); for (int i=2;i<=a;i++) { if (k%i==0) {flag=0;break;} } return flag; } lli b[10000007]; lli sieve (int n) { for (int i=2;i<n;i++) { if (b[i]==0) { for (int j=i;j<=n;j+=i) { if (b[j]==0) { b[j]=i; } } } } return 0; } lli find(lli n) { lli sum=0,ans=1; vll v; lli z; while (1) { if (n==1) { break; } sum=0; z=b[n]; while (n%z==0) { n/=z; sum++; } v.pb(sum); } for (int i=0;i<v.size();i++) { ans*=(v[i]+1); } return ans; } int main() { fio; sieve(10000000); lli n; cin>>n; lli ans=1; for (int i=2;i<=n;i++) { ans+=i*(find(i)); } cout<<ans; return 0; }
0
17,629,358
#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;} 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;} ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);} ll npr(ll n,ll r){return fact(n)/fact(n-r);} 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 main(){ string S; cin>>S; int N=S.size(); if(N<4||(S[0]!='Y'||S[1]!='A'||S[2]!='K'||S[3]!='I')) cout<<"No"; else cout<<"Yes"; return 0;}
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> pii; const int MN = 200010; int N; int A[MN]; set<pii> st; bool check(int x) { st.clear(); for(int i = 1; i < N; i++) { if(A[i - 1] < A[i]) { continue; } else { int pos = A[i]; while(pos) { auto it = st.lower_bound(pii(pos, -1)); if(it == st.end()) { st.insert(pii(pos, 1)); break; } pii t = *it; st.erase(t); if(pos < t.first) { st.insert(pii(pos, 1)); break; } if(t.second == x - 1) { pos--; continue; } t.second++; st.insert(t); break; } if(!pos) return false; while(st.size() && st.rbegin()->first > pos) { st.erase(*st.rbegin()); } } } return true; } int main() { scanf("%d", &N); for(int i = 0; i < N; i++) { scanf("%d", &A[i]); } bool ok = true; for(int i = 1; i < N; i++) { if(A[i - 1] >= A[i]) { ok = false; break; } } if(ok) { printf("1"); return 0; } int s = 2, e = N, p = -1; while(s <= e) { int m = (s + e)>>1; if(check(m)) { p = m; e = m - 1; } else s = m + 1; } printf("%d", p); }
0
70,808,679
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize ("-ffloat-store") #pragma GCC optimize ("-fno-defer-pop") #define all(a) a.begin(),a.end() #define ll long long int #define ld long double ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;} ll modInverse(ll a, ll m) { return power(a, m-2, m); } #define ps push_back #define fs first #define sc second #define takeline cin.ignore(); #define iactive cout.flush(); #define N 100005 #define endl "\n" #define mod 1000000007 ll n,ar[N][4],dp[N][4],k; ll maxval(ll i,ll flg){ if(i>n) return 0; if(dp[i][flg]!=-1){ return dp[i][flg]; } ll j,an=0; for(j=1;j<=3;j++){ if(j==flg) continue; an=max(an,maxval(i+1,j)+ar[i][j]); } return dp[i][flg]=an; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll i,j,l; cin>>n; for(i=1;i<=n;i++){ cin>>ar[i][1]>>ar[i][2]>>ar[i][3]; } memset(dp,-1,sizeof(dp)); ll an=maxval(1,0); cout<<an; return 0; }
#include <bits/stdc++.h> using namespace std; void print(vector<int> x){ int n; for (n = 1; n < x.size()-1; n++){ cout << x.at(n) << " "; } cout << x.at(n) << endl; } void clean(vector<int> &x){ for (int n = 0; n < x.size(); n++){ x.at(n) = 0; } } int main(){ int N, K; cin >> N >> K; vector<int> A(N+1); vector<int> B(N+1); for (int n = 1; n <= N; n++){ cin >> A.at(n); } for (int k = 0; k < K; k++){ bool is_satu = true; clean(B); for (int n = 1; n <= N; n++){ int v = A.at(n); int spos = max(1, n-v); int epos = min(N, n+v); B.at(spos)++; if (epos+1 <= N){ B.at(epos+1)--; } } for (int n = 1; n <= N; n++){ B.at(n) += B.at(n-1); if (B.at(n) != N){ is_satu = false; } } A = B; if (is_satu){ break; } } print(A); }
0
64,474,016
#include "bits/stdc++.h" #define pb push_back #define mp make_pair #define mt make_tuple #define endl '\n' #define F first #define S second #define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define cf ll testcases;cin>>testcases;while(testcases--) #define prn(x) if(x) cout<<"YES"<<endl; else cout<<"NO"<<endl; #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define minel(x) (*min_element(all(x))) #define maxel(x) (*max_element(all(x))) #define cou dbg=1;cout using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<ld> vd; typedef vector<pi> vp; ll dbg=0; template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p); template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p); template<typename A> istream& operator>>(istream& cin, vector<A> &v); int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; void solve(){ ll n,k; cin>>n>>k; vi arr(n+1); for(ll i=1;i<=n;i++) cin>>arr[i]; vi dp(n+1,0); for(ll i=2;i<=n;i++){ dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]); for(ll j=2;j<=k;j++){ if(i-j<=0) break; dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j])); } } cout<<dp[n]<<endl; } int main(){ IO; solve(); return 0; } template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { if(dbg){ return cout << "(" << p.F << ", " << p.S << ")"; }else{ return cout<<p.F<<' '<<p.S; } dbg=0;} template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { if(dbg){ cout << "["; for(ll i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]"; }else{ for(ll i=0;i<v.size()-1;i++) cout<<v[i]<<' '; return cout<<v[v.size()-1]; dbg=0;} } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } template<typename A> istream& operator>>(istream& cin, vector<A> &v) { for(ll i=0;i<v.size()-1;i++) cin>>v[i]; return cin >> v[v.size()-1]; }
#include<iostream> #include<cmath> using namespace std; int min_one_way(int h, int w){ return min(h,w); } int min_two_way(int h, int w){ int divh = h/3; int divw = w/2; int s1 = divh*w; int s2 = (h-divh)*divw; int s3 = (h-divh)*(w-divw); int min_horizon1 = min(min(s1,s2),s3); int max_horizon1 = max(max(s1,s2),s3); divh++; s1 = divh*w; s2 = (h-divh)*divw; s3 = (h-divh)*(w-divw); int min_horizon2 = min(min(s1,s2),s3); int max_horizon2 = max(max(s1,s2),s3); divw = w/3; divh = h/2; s1 = divw*h; s2 = (w-divw)*divh; s3 = (w-divw)*(h-divh); int min_vertical1 = min(min(s1,s2),s3); int max_vertical1 = max(max(s1,s2),s3); divw++; s1 = divw*h; s2 = (w-divw)*divh; s3 = (w-divw)*(h-divh); int min_vertical2 = min(min(s1,s2),s3); int max_vertical2 = max(max(s1,s2),s3); return min(min(max_horizon1-min_horizon1,max_horizon2-min_horizon2),min(max_vertical1-min_vertical1,max_vertical2-min_vertical2)); } int main(void){ int h,w; cin>>h>>w; if(h%3==0 || w%3==0){ cout<<0<<endl; } else{ cout<<min(min_one_way(h,w),min_two_way(h,w))<<endl; } return 0; }
0
79,879,003
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <string> #include <iomanip> #include <map> #include <set> #include <cmath> #include <cstdio> #include <cstdint> using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; bool check(int i, int male0, string sex) { if(sex == "Male" && male0 == true && i % 2 == 0) return true; if(sex == "Female" && male0 == true && i % 2 == 1) return true; if(sex == "Male" && male0 == false && i % 2 == 1) return true; if(sex == "Female" && male0 == false && i % 2 == 0) return true; return false; } int main() { int N; cin >> N; int l = 0, r = N; cout << 0 << "\n" << flush; string S; cin >> S; int male0 = 0; if(S == "Vacant") return 0; else if(S == "Male") male0 = 1; while(1) { int mid = (l + r) / 2; cout << mid << "\n" << flush; string s; cin >> s; if(s == "Vacant") { return 0; } if(check(mid, male0, s)) { l = mid; } else r = mid; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const int mod=1e9 + 7; int n,k; cin>>n>>k; vector<int> v(n,0); for(int i=0;i<n;i++) cin>>v[i]; vector<ll> dp(k+1,0); for(int i=0;i<=min(k,v[0]);i++) dp[i]=1; for(int i=1;i<n;i++){ vector<ll> pre=dp; for(int j=1;j<=k;j++){ pre[j]+=pre[j-1]; pre[j]%=mod; } for(int j=1;j<=k;j++){ int lo=max(0,j-v[i]),hi=j; ll tmp=0; if(lo>0) tmp=pre[lo-1]; dp[j]=(pre[hi]-tmp+mod)%mod; } } cout<<dp[k]<<endl; return 0; }
0
507,858
#include <bits/stdc++.h> using namespace std; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } #ifdef __LOCAL #define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n' #define debugArray(x, n) \ cerr << __LINE__ << ": " << #x << " = {"; \ for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \ cerr << ((hoge) ? "," : "") << x[hoge]; \ cerr << "}" << '\n' #define debugMatrix(x, h, w) \ cerr << __LINE__ << ": " << #x << " =\n"; \ for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) { \ cerr << ((hoge ? " {" : "{{")); \ for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga)) \ cerr << ((fuga ? ", " : "")) << x[hoge][fuga]; \ cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \ } #else #define debug(x) (void(0)) #define debugArray(x, n) (void(0)) #define debugMatrix(x, h, w) (void(0)) #endif signed main() { cin.tie(0); ios::sync_with_stdio(0); function<pair<int, long long>(int, long long)> rec = [&](int d, long long n) { if (n == 1) return make_pair(d, 0ll); long long ret = n / 2; int D = 2 * d; if (D >= 10) { ret += n / 2; D = D % 10 + 1; } int DD; long long add; tie(DD, add) = rec(D, n / 2); ret += add; if (n & 1) { ret++; DD += d; if (DD >= 10) { ret++; DD = DD % 10 + 1; } } return make_pair(DD, ret); }; int M; cin >> M; long long ans = -1; int cur = 0; for (int i = 0; i < M; i++) { int d; long long c; cin >> d >> c; int D; long long cnt; tie(D, cnt) = rec(d, c); ans += cnt + 1; cur += D; if (cur >= 10) { ans++; cur = cur % 10 + 1; } } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) using ll = long long; const ll M = 1000000000000000000; int main(){ ll n; cin >> n; vector<ll> a(n); bool flag = false; rep(i,n){ cin >> a[i]; if(a[i]==0) flag = true; } ll ans=1; rep(i,n){ if(flag) { ans = 0; break; } if(a[i]>M/ans){ ans = -1; break; } ans *= a[i]; } cout << ans << endl; }
0
16,846,369
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, a, b) for (ll i = (a); i < (b); i++) typedef uint64_t ull; typedef int64_t ll; typedef std::pair<ll, ll> PLL; using namespace std; ll N, M, d; signed main() { cin >> N >> M >> d; ll p = 0; if (d == 0) { p += N; } else { p += (N-d); p += (N-d); } double ans = (1.0 * p / (N*N)) * (M-1); printf("%.10f\n", ans); }
#include <iostream> #include <stack> #include <string> using namespace std; int main() { int n; stack<int> st; int cef; int ans; cin >> n; for(int i = 0; i < n; i++) { string mcxi1, mcxi2; cin >> mcxi1 >> mcxi2; int temp1 = 0; int temp2 = 0; cef = 1; for(int i = 0; i < mcxi1.size(); i++) { if(mcxi1[i] >= '2' && mcxi1[i] <= '9') { st.push(mcxi1[i]-'0'); } else { while(!st.empty()) { cef = st.top(); st.pop(); } if(mcxi1[i] == 'm') temp1 += cef * 1000; else if(mcxi1[i] == 'c') temp1 += cef * 100; else if(mcxi1[i] == 'x') temp1 += cef * 10; else if(mcxi1[i] == 'i') temp1 += cef * 1; cef = 1; } } cef = 1; for(int i = 0; i < mcxi2.size(); i++) { if(mcxi2[i] >= '2' && mcxi2[i] <= '9') { st.push(mcxi2[i]-'0'); } else { while(!st.empty()) { cef = st.top(); st.pop(); } if(mcxi2[i] == 'm') temp2 += cef * 1000; else if(mcxi2[i] == 'c') temp2 += cef *100; else if(mcxi2[i] == 'x') temp2 += cef * 10; else if(mcxi2[i] == 'i') temp2 += cef * 1; cef = 1; } } ans = temp1 + temp2; if((cef = ans / 1000) != 0) { ans = ans % 1000; if(cef != 1) cout << cef; cout << 'm'; } if((cef = ans / 100) != 0) { ans = ans % 100; if(cef != 1) cout << cef; cout <<'c'; } if((cef = ans / 10) != 0) { ans = ans % 10; if(cef != 1) cout << cef; cout <<'x'; } if(ans / 1 != 0) { cef = ans; if(cef != 1) cout << cef; cout <<'i'; } cout << endl; } return 0; }
0
33,731,336
#include<bits/stdc++.h> using namespace std; int main() { int n,m=1e32,s,p,j,i,a[500]; cin>>n; for(i=0;i<n;i++)cin>>a[i]; sort(a,a+n); for(i=a[0];i<=a[n-1];i++) { s=0; for(j=0;j<n;j++) { p=(a[j]-i); s+=(p*p); } if(s<m)m=s; } cout<<m<<endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long #define hcf __gcd bool is_prime(ll n){ if(n==2) return true; if(n%2==0) return false; for(ll i=3;i*i<=n;i+=2){ if(n%i==0) return false; } return true; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen ("C:\\Users\\Animesh\\Desktop\\i.txt", "r", stdin); #endif int n; cin>>n; int l; cin>>l; vector<string> s(n); for(auto& it:s) cin>>it; sort(s.begin(),s.end()); for(auto it:s) cout<<it; return 0; }
0
90,557,254
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; int main(){ int a, b; cin >> a >> b; if ((a*b)%2 == 0) cout << "Even" << endl; else cout << "Odd" << endl; }
#include <iostream> #include <vector> #include <set> using namespace std; int H, W, M; int main() { cin >> H >> W >> M; vector<int> h(H), w(W); set<pair<int, int> > st; int maxH = 0, maxW = 0; for (int i = 0; i < M; i++) { int ih, iw; cin >> ih >> iw; --ih; --iw; st.insert({ih, iw}); h[ih]++; w[iw]++; maxH = max(maxH, h[ih]); maxW = max(maxW, w[iw]); } vector<int> mhl, mwl; for (int i = 0; i < H; i++) { if (maxH == h[i]) mhl.push_back(i); } for (int i = 0; i < W; i++) { if (maxW == w[i]) mwl.push_back(i); } int ans = maxH + maxW - 1; for (int i = 0; i < mhl.size(); i++) { for (int j = 0; j < mwl.size(); j++) { if (st.find({mhl[i], mwl[j]}) == st.end()) { ans++; cout << ans; return 0; } } } cout << ans; }
0
67,024,231
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i]; #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(),(v).end() #define mod 1000000007 #define FS fixed<<setprecision(15) using namespace std; typedef long long ll; template<class T> using V=vector<T>; using Graph = vector<vector<int>>; using P=pair<ll,ll>; typedef unsigned long long ull; typedef long double ldouble; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const ll INF=1e18; void chmax(P &a,P b) { if (a.ft<b.ft) a.sc=max(a.ft,b.sc), a.ft=b.ft; else a.sc=max(a.sc,b.ft); } int main(){ cin.tie(0);ios::sync_with_stdio(false); int n; cin>>n; V<ll> a((1<<n)); V<P> dp(1<<n); rep(i,(1<<n)){ cin>>a[i]; dp[i]=make_pair(a[i],-INF); } rep(j,n){ rep(i,(1<<n)){ if(i>>j&1){ chmax(dp[i],dp[i^(1<<j)]); } } } ll ans=-INF; rep(i,(1<<n)){ ll tmp=dp[i].ft+dp[i].sc; ans=max(ans,tmp); if(i) cout<<ans<<'\n'; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll H,W,K,i,j,count; ll ans = 0; char C[6][6],B[6][6]; cin >> H >> W >> K; for(i=0;i<=H-1;i++) cin >> C[i]; for(ll bith = 0;bith < (1<<H);bith++) for(ll bitw = 0;bitw < (1<<W);bitw++){ count = 0; for(i=0;i<=H-1;i++) for(j=0;j<=W-1;j++) B[i][j] = C[i][j]; for(i=0;i<=H-1;i++) for(j=0;j<=W-1;j++) if((bith & (1<<i)) || (bitw & (1<<j))) B[i][j] = '.'; for(i=0;i<=H-1;i++) for(j=0;j<=W-1;j++) if(B[i][j] == '#') count++; if(count == K) ans++; } cout << ans << endl; }
0
92,657,746
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++) #define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--) #define yes cout << "yes" << endl; #define Yes cout << "Yes" << endl; #define YES cout << "YES" << endl; #define no cout << "no" << endl; #define No cout << "No" << endl; #define NO cout << "NO" << endl; #define AC cout << "AC" << endl; #define WA cout << "WA" << endl; #define out(s) cout << s << endl; #define ll long long #define ull unsigned long long #define vi vector<int> const double PI = 3.14159265358979323846; int main() { int N, i; cin >> N >> i; cout << N - i + 1 << endl; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; #define INF 1000000 void make_multiplier(int x, int N, vector<int>& coins) { int num = x; while(num <= N) { coins.push_back(num); num *= x; } } int main() { int N; cin >> N; int dp[100010]; for(int i = 0;i < 100010;i++) dp[i] = INF; dp[0] = 0; vector<int> coins = {1}; make_multiplier(6, N, coins); make_multiplier(9, N, coins); sort(coins.begin(), coins.end()); unique(coins.begin(), coins.end()); int m = coins.size(); for(int i = 0;i < m;i++) { int j = 0; while(j + coins.at(i) <= N) { if(dp[j + coins.at(i)] > dp[j] + 1) dp[j + coins.at(i)] = dp[j] + 1; j++; } } cout << dp[N] << endl; }
0
98,575,216
#include<bits/stdc++.h> #define ll long long int #define pb push_back #define forn(n1,n2) for(ll i=n1;i<n2;i++) #define w(t) ll t;cin>>t;while(t--) #define en "\n" #define mod 1e6+3 #define f first # define s second using namespace std; ll i,n,m,x,y,z,j,k,l,mn=LLONG_MAX,mx=0,c,a[100005],r,cnt=0,sum=0; string str;char ch;set<ll>s;map<ll,ll>mp; vector<vector<ll>>g; vector<ll>v; void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; *yp = temp; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>str;ll len=str.size(); forn(0,len) {sum+=str[i]-48;} sum%9==0?cout<<"Yes":cout<<"No"; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--){ long long a,b; cin>>a>>b; long long sum = a*b; long long ss = (long long)sqrt(sum); if(a==b||abs(a-b)==1){ a = min(a,b); cout<<2*a-2<<endl; }else{ if(ss*ss==a*b) ss--; if(ss*(ss+1)>=a*b){ cout<<2*ss-2<<endl; }else{ cout<<2*ss-1<<endl; } } } }
0
1,940,186
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); i++) const long double EPS = 1e-10; const long long INF = 1e18; const long double PI = acos(-1.0L); ll gcd(ll a, ll b){ if(b==0){ return a; } return gcd(b , a%b); } ll sum_digit(ll n){ ll value = 0; while(n!=0){ value += n%10; n = n/10; } return value; } int main() { int n; cin>>n; ll a[n]; ll maxx = INT_MIN; ll sum = 0; for(int i=0;i<n;i++){ ll x; cin>>x; a[i] = x - (i+1); maxx = max(maxx,a[i]); } sort(a,a+n); for(int i=0;i<n;i++){ sum += abs(a[i] - a[n/2]); } cout<<sum<<"\n"; return 0; }
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)n; i++) #define repa(i, s, n) for(int i = s; i < (int)n; i++) #define MOD 1000000007 using namespace std; using ll = long long; typedef vector<int> vi; typedef pair<int, int> P; #define rrep(i,a,b) for(int i=a;i>=b;i--) 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; } signed main(){ ll l, r; cin >> l >> r; ll ans = 2019; if(r - l >= 2019){ cout << 0 << endl; return 0; } for(ll i = l+1; i <= r; i++){ for(ll j = l; j < i; j++){ chmin(ans, ((i*j)%2019)); if(ans == 0) break; } } cout << ans << endl; }
0
23,447,059
#include <iostream> #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 <numeric> #include <cmath> #include <iomanip> #include "atcoder/all" #define ll long long int #define pb push_back #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) using namespace std; using namespace atcoder; int main(){ int n, q; cin >> n >> q; dsu tree(n); while(q--){ int t, u, v; cin >> t >> u >> v; if(t){ if(tree.same(u,v)) cout << 1 << endl; else cout << 0 << endl; }else{ int a = tree.merge(u,v); } } }
#include <bits/stdc++.h> using namespace std; const int maxn=3e5+10; struct point { int x,y; }p[maxn]; map<int,int> xcnt,ycnt; signed main(void){ int n,m,k; cin>>n>>m>>k; int x,y,maxr=0,maxc=0; for(int i=0;i<k;i++){ cin>>x>>y; p[i]={x,y}; xcnt[x]++,ycnt[y]++; maxr=max(maxr,xcnt[x]),maxc=max(maxc,ycnt[y]); } int num1=0,num2=0; for(auto tmp:xcnt) if(tmp.second==maxr) num1++; for(auto tmp:ycnt) if(tmp.second==maxc) num2++; int cnt=0; for(int i=0;i<k;i++){ x=p[i].x,y=p[i].y; if(xcnt[x]==maxr&&ycnt[y]==maxc)cnt++; } if(cnt==num1*num2) cout<<(maxc+maxr-1)<<endl; else cout<<(maxc+maxr)<<endl; return 0; }
0
50,949,067
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n; int cnt[maxn], Max; void no() { puts("Impossible"); exit(0);} int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) { int v; scanf("%d", &v); ++cnt[v]; Max = max(Max, v); } if(Max % 2 == 0) { int h = Max / 2; for(int i = 1; i < h; ++i) if(cnt[i]) no(); if(cnt[h] != 1) no(); for(int i = h + 1; i <= Max; ++i) if(cnt[i] < 2) no(); } else { int h = (Max + 1) / 2; for(int i = 1; i < h; ++i) if(cnt[i]) no(); if(cnt[h] != 2) no(); for(int i = h + 1; i <= Max; ++i) if(cnt[i] < 2) no(); } puts("Possible"); return 0; }
#define _USE_MATH_DEFINES #include <cmath> #include <iostream> # include <bits/stdc++.h> using namespace std; long long powerexp(long long base, long long exp, int mod) { long long res = 1; while (exp > 0) { if (exp % 2 == 1) res= (res * base) % mod; exp = exp >> 1; base = (base * base) % mod; } return res; } int gcd(int a, int b) { int c = a % b; while(c != 0) { a = b; b = c; c = a % b; } return b; } void PrintVector(vector<long long int> v,long long int n) { for(int i=v.size()-1;i>=0;i--) { cout<<v[i]<<" "; } cout<<endl; } void Takevector(vector<long long int> &v,long long int n) { for(long long int i=0;i <n;i++) { long long int number; cin>>number; v.push_back(number); } } typedef long long int ll; typedef vector<long long int> vi; #define sci(x) int x; scanf("%d", &x); #define scii(x, y) int x, y; scanf("%d %d", &x, &y); #define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z); #define scl(x) ll x; scanf("%lld", &x); #define scll(x, y) ll x, y; scanf("%lld %lld", &x, &y); #define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z); #define TC(x) sci(x); while(x --) #define rep(i, x, y) for (__typeof(x) i = x; i <= y; i ++) #define repi(i, x, y) for (__typeof(x) i = x; i >= y; i --) #define fore(itr, x) for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++) #define forei(itr, x) for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --) #define nl cout<<"\n"; int min(int x, int y) { return (x < y)? x: y; } int main() { int flag=1; ll sum=0; int flag1=0; ll tot=0; int ans=0; map<int,int>mp; vi v; set<int>st; string str; scii(s,w); if(w>=s) cout<<"unsafe"; else cout<<"safe"; return 0; }
0
70,897,883
#include<iostream> #include<stdio.h> #include<string> #include<vector> #include<map> #include<tuple> #include<algorithm> #include<cmath> #include<limits> #include<set> #include<queue> using namespace std; #define int long long int #define rep(i, n) for (int i = 0; i < (int)(n); i++) int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } signed main() { int X, Y; cin >> X >> Y; cout << X + Y / 2; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main() { int n; cin >> n; ll ans = 0; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; ) { ll tmp = 0; int j = i; while (j < n && a[j] > 0) { tmp += a[j]; j++; } ans += tmp / 2; i = j+1; } cout << ans << endl; return 0; }
0
48,696,091
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; using lint = long long int; int H, W, N; vector<P> p; int count(int x, int y) { if (x <= 0 || y <= 0 || x >= H-1 || y >= W-1) return 0; int ans = 0; for (int i=-1; i<=1; i++) { for (int j=-1; j<=1; j++) { ans += binary_search(p.begin(), p.end(), P(x+i, y+j)); } } return ans; } int main() { cin >> H >> W >> N; for (int i=0; i<N; i++) { int a, b; cin >> a >> b; a--; b--; p.push_back(P(a, b)); } sort(p.begin(), p.end()); vector<set<P>> ans(9); for (int i=0; i<N; i++) { for (int x=-1; x<=1; x++) { for (int y=-1; y<=1; y++) { int n = count(p[i].first+x, p[i].second+y); if (n) ans[n-1].insert(P(p[i].first+x, p[i].second+y)); } } } lint ans0 = (lint)(H-2) * (W-2); for (auto v : ans) ans0 -= v.size(); cout << ans0 << endl; for (auto v : ans) cout << v.size() << endl; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> #include <stack> #include <functional> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif #define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i) #define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i) #define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i) #define all(x) (x).begin(), (x).end() 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; } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <ll,ll> P; typedef long double ld; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); rep (i, n) cin >> a[i]; ll sum[1000][1000] = {}; rep (i, n) { rep (j, n) { sum[i][j] = (i > j ? sum[i - 1][j] : 0) + (i >= j ? a[i] : 0); eprintf("%3lld ", sum[i][j]); } eprintf("\n"); } int m = 40; ll ans = 0; reprev(x, m) { int count = 0; ll tmp = ans + (1LL << x); rep (i, n) { rep (j, n) { if (i >= j && (sum[i][j] & tmp) == tmp) { count++; } } } if (count >= k) ans = tmp; } cout << ans << "\n"; return 0; }
0
23,906,555
#include<bits/stdc++.h> #define ll long long using namespace std; const ll N=1e5+5; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>s; for(ll i=2; i<s.size(); i++) { if(s[i]==s[i-1]&&s[i-1]==s[i-2]) { cout<<"Yes"; return 0; } } cout<<"No"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() typedef long long ll; typedef pair<int, int> P; typedef pair<long long, long long> Pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef vector<vector<long long>> vvll; typedef vector<string> vs; const long long INF = 1LL << 60; const int INT_INF = 1 << 30; const double PI = acos(-1.0); bool divisor(int x) { int cnt = 0; int tmp = 1; while (tmp * tmp <= x) { if (x % tmp == 0) { if (tmp * tmp != x) cnt += 2; else cnt++; } tmp++; } if (cnt == 8) return true; else return false; } int main() { int N; cin >> N; int ans = 0; rep2(i, 1, N + 1) { if ((i % 2) && divisor(i)) ans++; } cout << ans << endl; }
0
75,048,089
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; int gcd(int a, int b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int gcds(vector<int> as) { int ans = as[0]; for (int i = 1; i < as.size(); i++) { ans = gcd(ans, as[i]); } return ans; } int main() { int n; cin >> n; vector<int> as(n); rep(i, n) { cin >> as[i]; } cout << gcds(as) << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> #include <string> #include <vector> #include <map> #include <set> #include <algorithm> #include <bitset> #include <math.h> typedef long long ll; typedef unsigned long long ull; #define vi std::vector<int> #define vl std::vector<ll> #define floop(n) for(int i = 0; i < n; ++i) #define print(x) std::cout << x << std::endl; const ll INF = 1e18; int main() { std::string s, res=""; std::cin >> s; int len = s.length(); floop(len) { if(s[i] == 'B') { if(res != "") res.pop_back(); } else res += s[i]; } print(res); return 0; }
0
41,960,839
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define mp make_pair #define PI pair<ll,ll> #define poly vector<ll> #define mem(a) memset((a),0,sizeof(a)) #define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++) #define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--) #define pb push_back #define fi first #define se second #define SZ(x) ((int)(x.size())) inline char gc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } #define gc getchar inline ll read(){ ll x = 0; char ch = gc(); bool positive = 1; for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(ll a){ if(a<0){ a=-a; putchar('-'); } if(a>=10)write(a/10); putchar('0'+a%10); } inline void writeln(ll a){write(a); puts("");} inline void wri(ll a){write(a); putchar(' ');} ll rnd(){ ull ans=0; For(i,0,4)ans=ans<<15^rand(); return ans%((ull)1<<63); } const int N=10005; int a[N],b[N]; void GG(){ puts("No"); exit(0); } char ask(int t){ cout<<t<<endl; string s; cin>>s; if(s[0]=='V')exit(0); return s[0]; } void solve(int l,int r,char L){ int mid=(l+r)>>1; char t=ask(mid); if((t==L)^(l%2)^(mid%2))solve(mid,r,t); else solve(l,mid,L); } int main(){ #ifdef Brollan #endif int n=read(); ask(n-1); solve(0,n-1,ask(0)); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1'000'000'007; const ld PI = acos(-1); const ld EPS = 0.0000000001; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define rep(i, n) for(ll i=0; i<(ll)(n); i++) #define repd(i, n) for(ll i=n-1; 0<=i; i--) #define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++) #define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--) #define ALL(x) x.begin(), x.end() #define rALL(x) x.rbegin(), x.rend() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main(){ ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; ll res=0; rep(i, n){ while(0<a[i]){ FOR(j, i, n){ if(!a[j]) break; a[j] -= 1; } res += 1; } } cout << res << endl; }
0
6,966,226
#include <bits/stdc++.h> using ll = long long; using namespace std; ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; } int main(){ int h,w,d; cin>>h>>w>>d; vector<vector<int>> a(h,vector<int>(w)); map<int,pair<int,int>> m; map<pair<int,int>,int> m2; for(int i=0; i<h; i++){ for(int j=0; j<w; j++){ cin>>a[i][j]; a[i][j]--; m[a[i][j]]=make_pair(i,j); } } int q; cin>>q; vector<int> l(q),r(q); for(int i=0; i<q; i++){ cin>>l[i]>>r[i]; l[i]--; r[i]--; } vector<vector<ll>> sums(d,vector<ll>((h*w/d)+1)); vector<bool> visit(h*w,false); for(int i=0; i<d; i++){ if(visit[i]) continue; for(int j=0; i+(j+1)*d<h*w; j++){ pair<int,int> now=m[i+j*d]; pair<int,int> next=m[i+(j+1)*d]; sums[i%d][j+1]=(sums[i%d][j]+(abs(now.first-next.first)+abs(now.second-next.second))); } } for(int i=0; i<q; i++){ ll tmp=sums[r[i]%d][(r[i]/d)]-sums[r[i]%d][(l[i]/d)]; cout<<tmp<<endl; } }
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; using VVI = vector<VI>; using PII = pair<int, int>; using LL = long long; using VL = vector<LL>; using VVL = vector<VL>; using PLL = pair<LL, LL>; using VS = vector<string>; #define ALL(a) begin((a)),end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_back #define MP make_pair #define MT make_tuple #define SZ(a) int((a).size()) #define SORT(c) sort(ALL((c))) #define RSORT(c) sort(RALL((c))) #define UNIQ(c) (c).erase(unique(ALL((c))), end((c))) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define FF first #define SS second #define DUMP(x) cout<<#x<<":"<<(x)<<endl template<class S, class T> istream& operator>>(istream& is, pair<S,T>& p){ return is >> p.FF >> p.SS; } template<class T> istream& operator>>(istream& is, vector<T>& xs){ for(auto& x: xs) is >> x; return is; } template<class S, class T> ostream& operator<<(ostream& os, const pair<S,T>& p){ return os << p.FF << " " << p.SS; } template<class T> ostream& operator<<(ostream& os, const vector<T>& xs){ for(unsigned int i=0;i<xs.size();++i) os << (i?" ":"") << xs[i]; return os; } template<class T> void maxi(T& x, T y){ if(x < y) x = y; } template<class T> void mini(T& x, T y){ if(x > y) x = y; } const double EPS = 1e-10; const double PI = acos(-1.0); const LL MOD = 1e9+7; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; vector<PLL> xs(N); cin >> xs; LL pr = (abs(xs[0].FF) + abs(xs[0].SS)) % 2; for(auto& x: xs){ if(pr != (abs(x.FF) + abs(x.SS)) % 2){ cout << -1 << endl; return 0; } } bool ev = (pr == 0); if(ev){ for(auto& x: xs) ++x.FF; } LL mx = 0; for(auto& p: xs) maxi(mx, abs(p.FF) + abs(p.SS)); VL ans; LL i=1, p=0; for(;p<mx;){ p += i; ans.PB(i); i *= 2; } if(SZ(ans) > 40){ cout << -1 << endl; return 0; } int M = SZ(ans); cout << (M + (ev?1:0)) << endl << ans << (ev ? " 1":"") << endl; for(auto p: xs){ string str(M, '?'); for(int i=M-1;i>=0;--i){ vector<tuple<LL,PLL,char>> ps; for(LL dx=-1;dx<=1;dx+=2){ LL tx = p.FF + dx * ans[i]; ps.EB(abs(tx)+abs(p.SS), MP(tx,p.SS), "RL"[(dx+1)/2]); } for(LL dy=-1;dy<=1;dy+=2){ LL ty = p.SS + dy * ans[i]; ps.EB(abs(p.FF)+abs(ty), MP(p.FF,ty), "UD"[(dy+1)/2]); } SORT(ps); str[i] = get<2>(ps[0]); p = get<1>(ps[0]); } cout << str << (ev? "L" : "") << endl; } return 0; }
0
70,112,224
#include<bits/stdc++.h> using namespace std; int main() { int i,j,k,ar[32]= {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51}; cin>>k; for(i=0; i<=32; i++) { if(i==(k-1)) cout<<ar[i]; } return 0; }
#include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <functional> #include <iterator> #include <numeric> #include <cstdint> #include <cmath> #include <bitset> #include <string> #include <list> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #define N_TIMES(i, n) for ( uint64_t i = 0; i < n; ++i ) #define N_TIMES_REV(i, n) for ( int64_t i = n - 1; i >= 0; --i ) template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>; template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; using namespace std; int main() { uint64_t N; cin >> N; vector<uint64_t> A(N), B(N); N_TIMES(n, N) { cin >> A[n]; } N_TIMES(n, N) { cin >> B[n]; } uint64_t S = accumulate(A.begin(), A.end(), static_cast<uint64_t>(0)); uint64_t T = accumulate(B.begin(), B.end(), static_cast<uint64_t>(0)); if (S < T) { cout << -1 << endl; return 0; } maximum_heap<uint64_t> xs; minimum_heap<uint64_t> ys; N_TIMES(n, N) { if (A[n] >= B[n]) { xs.push(A[n] - B[n]); } else { ys.push(B[n] - A[n]); } } uint64_t r = 0; while (!xs.empty()) { uint64_t x = xs.top(); xs.pop(); r += x; uint64_t c = 0; while (!ys.empty()) { uint64_t y = ys.top(); ys.pop(); if (r < y) { ys.push(y); break; } r -= y; ++c; } if (ys.empty()) { if (c == 0) { xs.push(x); } break; } } cout << (N - xs.size()) << endl; return 0; }
0
38,893,005
#include <iostream> #include <string> using namespace std; int main(){ string s,p; int index = 0; getline(cin, s); getline(cin, p); for (int i = 0; i < s.size(); i++){ index = i; if (s[i] == p[0]){ for (int j = 0; j < p.size(); j++){ index = (i + j) % s.size(); if (s[index] != p[j]) break; if (j == p.size() - 1) { cout << "Yes" << endl; return 0; } } } } cout << "No" << endl; return 0; }
#include <cstdio> int main() { int m,f,r; while(1){ scanf("%d %d %d", &m, &f, &r); if(m == -1 && f == -1 && r == -1) break; if(m == -1 || f == -1) printf("F\n"); else if(m + f < 30) printf("F\n"); else if(m + f >= 30 && m + f < 50){ if(r < 50) printf("D\n"); else printf("C\n"); } else if(m + f >= 50 && m + f < 65) printf("C\n"); else if(m + f >= 65 && m + f < 80) printf("B\n"); else printf("A\n"); } return 0; }
0
32,380,821
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl '\n' #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second using ll = long long; using P = pair<ll, ll>; int main() { FASTIO; ll x, y; cin >> x >> y; vector<ll> ans; ans.pb(x); while(true){ if(x*2 <= y){ x *= 2; ans.pb(x); } else{ break; } } cout << (int)ans.size() << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(void){ int N; cin>>N; vector<char> S(N); for(int i=0;i<N;i++){ cin>>S[i]; } int K; cin>>K; char temp=S[K-1]; for(int i=0;i<N;i++){ if(S[i]!=temp){ S[i]='*'; } } for(int i=0;i<N;i++){ cout<<S[i]; } cout<<endl; return 0; }
0
92,582,972
#include <iostream> using namespace std; int main(void) { int k, a, b; cin >> k >> a >> b; bool flag = 0; int tmp = k; while (tmp <= b) { if (tmp >= a && tmp <= b) { flag = true; break; } tmp += k; } if (flag) cout << "OK" << endl; else cout << "NG" << endl; }
#include<bits/stdc++.h> using namespace std; template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;} template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); } template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);} template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;} template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); } template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);} #define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;} vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x; while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {} template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) { cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);} int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1; #define F first #define S second #define pb push_back #define mp make_pair #define Pi atan(1)*4 #define ll long long int #define happy cin.tie(0); #define point(x) setprecision(x) #define coding ios::sync_with_stdio(false); #define Test printf("Case %d: ",tc++); #define Unique(c) (c).resize(unique(all(c))-(c).begin()) #define vout(v) for (auto z: v) cout << z << " "; cout << endl; void print(int n){printf("%d\n", n);} void Print(int n){printf("%d ", n);} void print(int n,int m){printf("%d ",n);printf("%d ",m);} void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);} void print(ll n){printf("%I64d\n", n);} void Print(ll n){printf("%I64d ", n);} void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);} void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);} int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;} int length(string s){return s.size();} #define pr pair<int, int> #define vpr vector<pr> #define vi std::vector<int> #define vll std::vector<ll> #define all(n) n.begin(),n.end() const int M = 1e9 + 7; const int Inf = (int)2e9 + 5; const ll Lnf = (ll)2e18 + 5; const int N = 4e5 + 5; const int NN = 1e6 + 5; long long Lcm(long long a,long long b){ return (((a)*(b)))/__gcd(a,b); } int solve() { ll a,b,c,d; cin>>a>>b>>c>>d; ll x = ((b/c) - ((a-1LL)/c)); ll y = ((b/d) - ((a-1LL)/d)); ll z = Lcm(c,d); ll x1 = (b/z) - ((a-1LL)/z); cout<<(b-a+1LL) - (x+y - x1)<<endl; return 0; } int main(){ int test = 1; while (test--)solve();return 0; }
0
74,115,275
#include <fstream> #include <iostream> #include <cmath> #include <vector> #include <queue> #include <utility> #include <algorithm> using namespace std; int cnt_sum_s(int n, int k, int s, int tmp_sum) { if (n == 0) { return (tmp_sum == s) ? 1 : 0; } int res = 0; for (int i = k+1; i < 10; i++) { res += cnt_sum_s(n-1, i , s, tmp_sum + i); } return res; } int main() { while (true) { int n,s; cin >> n >> s; if (!(n|s)) break; int res = cnt_sum_s(n, -1, s, 0); cout << res << endl; } }
#include <cstdio> #include <iostream> #include <string> #include <vector> #include <sstream> #include <map> #include <set> #include <queue> #include <algorithm> #include <cmath> #include <cstring> #include <typeinfo> #include <numeric> #include <functional> #include <unordered_map> #include <bitset> #include <stack> #include <assert.h> #include <unordered_set> #include <random> using namespace std; using ll = long long; using ull = unsigned long long; const ll INF = 1e18; const ll MOD = 1e9 + 7; #define REP(i, n) for(ll i = 0; i < n; i++) int main(){ ll n; cin >> n; vector<ll> a(n), c(n + 1); REP(i, n){ cin >> a[i]; c[a[i]]++; } vector<ll> d(n + 1); REP(i, n + 1){ d[c[i]]++; } vector<ll> r1(n + 1), r2(n + 1); for(ll i = 1; i <= n; i++){ r1[i] += r1[i - 1]; r1[i] += i * d[i]; r2[i] += r2[i - 1]; r2[i] += d[i]; } auto f = [&](ll x){ return (r1[x] + x * (r2[n] - r2[x])) / x; }; ll ans = n; REP(i, n){ while(ans > 0 && i + 1 > f(ans)) ans--; cout << ans << endl; } }
0
39,151,330
#include <stdio.h> #include <iostream> #include <algorithm> using namespace std; const int M=3e5+5; int a[M],cnt[M]; int main() { int n; scanf("%d",&n); int nu; for(int i=0;i<n;i++) { scanf("%d",&nu); a[nu]++; } for(int i=1;i<=n;i++) cnt[a[i]]++; int ans=n; int j=n; for(int i=1;i<=n;i++) { while(j>ans/i) { int ncnt=0; int tmp=ans/i; while(j>tmp) { ans-=(j-tmp)*cnt[j]; ncnt+=cnt[j]; j--; } cnt[j]+=ncnt; } printf("%d\n",ans/i); } return 0; }
#include<iostream> #include<vector> using namespace std; int main(){ int pair[100]; int input; vector<int> inputs; for(int i = 0; i < 10; i++) for(int j = 0; j < 10; j++) pair[i * 10 + j] = i + j; while(cin >> input) inputs.push_back(input); for(int k = 0; k < (int)inputs.size(); k++){ int input = inputs[k]; int count = 0; if(input <= 36){ for(int i = 0; i < 100; i++){ int cd = input - pair[i]; if(cd <= 18 && cd >= 0){ for(int j = 0; j < 100; j++) if(pair[j] == cd) count++; } } } cout << count << endl; } return 0; }
0
68,835,902
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <fstream> #include <iostream> #include <iomanip> #include <map> #include <math.h> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using ld = long double; using Pii = pair<int, int>; using Pil = pair<int, ll>; using Pid = pair<int, ld>; using Pis = pair<int, string>; const int INF = 1 << 28; const ll INF_L = 1LL << 60; const int MOD = 1e9+7; 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; } vector<vector<int>> adjMat; vector<set<Pii>> adjList; void Dijkstra(){} void BellmanFord(){} void WarshallFloyd(){} ll gcd(ll A, ll B) {if (A%B == 0) {return(B);} else {return(gcd(B, A%B));}} ll lcm(ll A, ll B) {return A * B / gcd(A, B);} ll powMod(ll B, ll P) { if(P == 0) return 1; if(P%2 == 0){ll t = powMod(B, P/2); return t*t % MOD;} return B * powMod(B, P-1) % MOD; } vector<bool> sieve; void sieveInit(int size){ int sb = size + 9; sieve.resize(sb); sieve[0] = sieve[1] = false; for(int i=2; i<sb; i++) sieve[i] = true; for(int i=2; i<sb; i++){ if(sieve[i]){ int m = 2*i; while(m < sb){sieve[m] = false; m += i;} } else { continue; } } } const int FAC_INIT_SIZE = 5e6+9; vector<ll> fac, finv, inv; void factModInit() { fac.resize(FAC_INIT_SIZE); finv.resize(FAC_INIT_SIZE); inv.resize(FAC_INIT_SIZE); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i=2; i < FAC_INIT_SIZE; 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 factMod(ll N){return fac[N] % MOD;} ll factInvMod(ll N){return finv[N] % MOD;} ll permMod(ll N, ll K){ if (N < 0 || K < 0 || N < K) return 0; else return factMod(N) * factInvMod(N-K) % MOD; } ll combMod(ll N, ll K){ if (N < 0 || K < 0 || N < K) return 0; else if (N < FAC_INIT_SIZE){ return factMod(N) * (factInvMod(K) * factInvMod(N-K) % MOD) % MOD;} else { ll ans = 1; ll Ks = K < N-K ? K : N-K; for (ll i=N; i > N-Ks; i--) {ans *= i; ans %= MOD;} return ans * factInvMod(Ks) % MOD; } } int main() { std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int xd = x2 - x1; int yd = y2 - y1; int x3, y3, x4, y4; x3 = x2 - yd; y3 = y2 + xd; x4 = x1 - yd; y4 = y1 + xd; cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pb push_back #define f(i,n) for(int i=0; i<n; ++i) #define fi(i,st,n) for(int i=st; i<=n; ++i) #define veci vector<int> #define vecp vector<pair<int,int> > #define vecl vector<ll> int prime[100000+10]; ll lcm(ll a, ll b) { return a*b/__gcd(a,b); } ll power(ll a, ll n, ll mod) { ll res = 1; while(n > 0) { if(n&1) { res = (res*a)%mod; } a = (a*a)%mod; n = n/2; } return res; } ll sum(int arr[], int n) { ll res = 0; f(i,n) { res += arr[i]; } return res; } void seive() { prime[1] = 0; for(int i=2; i<=100000; i++) { prime[i] = 1; } for(ll i=2; i<=100000; i++) { if(prime[i]) { for(ll j=i*i; j<=100000; j+=i) { prime[j] = 0; } } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while(t--){ int n; cin>>n; string s; cin>>s; int ans = 1; for(int i=1; i<s.length(); i++) { if(s[i] != s[i-1]) ans++; } cout<<ans<<"\n"; } return 0; }
0
52,345,011
#include <stdio.h> int main(void) { char line[80]; int d; while (fgets(line, sizeof line, stdin)) { if (sscanf(line, "%d", &d) == 1) { int s = 0; for (int i = 1; d*i <= 600 - d; i++) { s += (d*i)*(d*i) * d; } printf("%d\n", s); } } return 0; }
#include<bits/stdc++.h> #define int long long #define maxn 100005 #define pii pair<int,int> using namespace std; int N; pii arr[maxn]; int sz[maxn]; vector<int> G[maxn]; int dfs(int u,int pa) { int ret = 0; for(int v:G[u]) if(v!=pa) ret += sz[v]+dfs(v,u); return ret; } main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N; for(int i=1;i<=N;i++) cin >> arr[arr[i].second=i].first; sort(arr+1,arr+1+N); for(int i=1;i<=N;i++) sz[i] = 1; for(int i=N;i>1;i--) { int val = arr[i].first; int idx = arr[i].second; int pa_val = val-(N-sz[idx])+(sz[idx]); int tem = lower_bound(arr+1,arr+1+N,pii{pa_val,-1})-arr; if(tem>=i || arr[tem].first!=pa_val) { cout << -1 << endl; return 0; } int pa = arr[tem].second; sz[pa] += sz[idx]; G[pa].emplace_back(idx); } if(dfs(arr[1].second,arr[1].second)==arr[1].first) { for(int u=1;u<=N;u++) for(int v : G[u]) cout << u << " " << v << endl; } else cout << -1 << endl; return 0; }
0
10,008,459
#include<bits/stdc++.h> using namespace std; #define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);} #define pa pair<int,int> #define mod 998244353 #define ll long long #define mk make_pair #define pb push_back #define fi first #define se second #define cl(x) memset(x,0,sizeof x) #ifdef Devil_Gary #define bug(x) cout<<(#x)<<" "<<(x)<<endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define bug(x) #define debug(...) #endif const int INF = 0x7fffffff; const int N=1e5+5; int vis[N],n,k,r,s,p,ans; char S[N]; int main(){ #ifdef Devil_Gary freopen("in.txt","r",stdin); #endif cin>>n>>k>>r>>s>>p>>S+1; for(int i=1;i<=n;i++){ if(i>k&&vis[i-k]&&S[i]==S[i-k]) continue; ans+=(S[i]=='r')?p:((S[i]=='s')?r:s); vis[i]=1; } cout<<ans<<endl; return 0; }
#include <iostream> using namespace std; bool board[7][7]; bool row[7], col[7]; int h, w, k, tol = 0; void dfs(int i, int j) { if (i < h) { col[i] = true; dfs(i + 1, j); col[i] = false; dfs(i + 1, j); } else if (j < w) { row[j] = true; dfs(i, j + 1); row[j] = false; dfs(i, j + 1); } if (i == h && j == w) { int sum = 0; for (int i1 = 0; i1 < h; i1++) for (int j1 = 0; j1 < w; j1++) sum += !col[i1] && !row[j1] && board[i1][j1]; tol += sum == k; } } int main() { cin >> h >> w >> k; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { char c; cin >> c; board[i][j] = c == '#'; } dfs(0, 0); cout << tol; return 0; }
0
54,598,834
#include<bits/stdc++.h> using namespace std; #define LL long long #define DD double #define Pb push_back #define Bp pop_back #define Pf push_front #define Fp pop_front #define Ub upper_bound #define Lb lower_bound #define In insert #define All(x) x.begin(), x.end() #define mem(a, b) memset(a, b, sizeof(a)) #define fast ios_base::sync_with_stdio(0);cin.tie(0) #define X first #define Y second #define mx1 10 #define mx2 110 #define mx3 1010 #define mx4 10010 #define mx5 100010 #define mx6 1000010 typedef vector<LL> Vl; typedef vector<DD> Vd; typedef vector<bool> Vb; typedef vector<Vl> VVl; typedef pair<LL, LL> Pll; typedef pair<DD, DD> Pdd; typedef vector<Pll> Vpl; typedef vector<Pdd> Vpd; typedef queue<LL> Ql; typedef stack<LL> Sl; typedef deque<LL> Dl; LL _set(LL N, LL pos) {return N = N | (1 << pos);} LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);} bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));} bool _upper(char a) {return a >= 'A' && a <= 'Z';} bool _lower(char a) {return a >= 'a' && a <= 'z';} bool _digit(char a) {return a >= '0' && a <= '9';} LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1}; LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1}; int N[2 * mx5]; int main() { int n, k; cin >> n >> k; int a; for(int i = 0; i < n; i++) cin >> a, N[a]++; vector<int> v; for(int i = 1; i <= n; i++) if(N[i]) v.Pb(N[i]); sort(All(v)); int ans = 0, L = v.size(), M = L; for(int i = 0; i < L; i++) { if(M > k) M--, ans += v[i]; else break; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #include <math.h> #define rep(i, n) for(int i = 0; i < (n); i++) #define rrep(i, n) for(int i = 0; i <= (n); i++) using namespace std; typedef long long ll; const ll INF = 1LL<<62; 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; } using Graph = vector<vector<int>>; typedef pair<int, int> P; typedef priority_queue<int, vector<int>, greater<int>> PQ; const int MOD = 1000000007; const int max_a = 20005; int main(){ int H, N; cin >> H >> N; vector<int> A(N), B(N); rep(i,N) cin >> A[i] >> B[i]; vector<ll> dp(H+1, INF); dp[0] = 0; rep(i,N){ rep(j, H+1){ int nh = min(j + A[i], H); dp[nh] = min(dp[nh], dp[j]+B[i]); } } cout << dp[H] << endl; }
0
70,095,036
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; #define INF ((1<<30)-1) #define LINF (1LL<<60) #define EPS (1e-10) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MOD2 = 998244353; int main(){ string s, t; cin >> s >> t; sort(s.begin(), s.end()); sort(t.begin(), t.end()); reverse(t.begin(), t.end()); if (s < t) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(), (x).end() #define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;}) #define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end())) #define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;}) #define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end()) #define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl #define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i) #define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end())) #define OUT(x) cout<<x<<endl #define REP(i,n) FOR(i,0,n) typedef long long ll; typedef pair<ll, ll> P; struct edge { int to,cost; }; int main() { int N;cin>>N; map<int,int> mp; REP(i,N) { int a;cin>>a; mp[a]++; } int tmp = 0; for (auto m:mp) { if (m.second > 1) { tmp += m.second-1; } } int action_cnt = (tmp+1)/2; OUT(N-action_cnt*2); return 0; }
0
14,943,948
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<n; i++) #define PI 3.14159265359 #define INF 1000100100 #define MOD 1000000007 #define all(x) (x).begin(),(x).end() typedef long long ll; #define P pair<int, int> #define PP pair<P,P> #define T tuple<ll,ll,ll> #define pr(x) cout << x << endl; using namespace std; int main(){ int n,m; cin >> n >> m; vector<T> cakes; rep(i,n){ ll x,y,z; cin >> x >> y >> z; cakes.emplace_back(x,y,z); } ll ans=0; rep(i,2)rep(j,2)rep(k,2){ vector<ll> sum(n); rep(p,n){ ll nx,ny,nz; tie(nx,ny,nz) = cakes[p]; if(i==1) nx*=-1; if(j==1) ny*=-1; if(k==1) nz*=-1; sum[p]=nx+ny+nz; } sort(all(sum)); ll tmp=0; rep(i,m) tmp+=sum[n-i-1]; ans=max(ans,tmp); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL) #define int long long using namespace std; const int mod = 1e9+7; int expo(int a, int b){ if(b == 0){ return 1; } int ans = expo((a*a)%mod,b/2); if(b%2){ return (a*ans)%mod; } return ans%mod; } void solve(){ int n,k; cin>>n>>k; int ans = 0; vector<int> dp(k+1); for(int i=k; i>=1; --i){ int t = k/i; int curans = expo(t,n); curans %= mod; int minus = 0; for(int j=2*i; j<=k; j+=i){ minus += dp[j]; minus %= mod; } dp[i] = (curans-minus+mod)%mod; ans += (dp[i]*i)%mod; ans %= mod; } cout<<ans<<endl; } int32_t main(){ IOS; { solve(); } return 0; }
0
21,989,610
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <cmath> #include <cstdio> #include <queue> #include <deque> #include <map> #include <stack> #include <set> #include <utility> #include <functional> #include <cstring> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> P; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; const int MAXN = 100000; const int MAXE = 100000; const int MAXV = 10000; const int inf = 1e9; const ll INF = 2e18; const ll MOD = 1e9 + 7; struct UnionFind { vector<int> par, rank; UnionFind(int n) : par(n), rank(n) { for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return; if (rank[ry] > rank[rx]) par[rx] = ry; else par[ry] = rx; if (rank[rx] == rank[ry]) rank[rx]++; } bool same(int x, int y) { return root(x) == root(y); } }; vector<ll> fac, inv, finv; void initcom() { fac = inv = finv = vector<ll>(1e6); fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1; for (ll i = 2; i < 1e6; ++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 0; if (n < k) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll mopow(ll a, ll x, ll mod) { ll res = 1; while (x > 0) { if (x & 1) res = res * a % mod; a = a * a % mod; x >>= 1; } return res; } int main(){ ll n,k;cin>>n>>k; vector<ll> p(n),c(n); for(int i=0;i<n;++i) cin>>p[i],--p[i]; for(int i=0;i<n;++i) cin>>c[i]; vector<vector<ll> > next(60,vector<ll>(n)); vector<vector<ll> > val(60,vector<ll>(n)); vector<vector<ll> > all(60,vector<ll>(n)); for(int i=0;i<n;++i){ next[0][i]=p[i]; val[0][i]=all[0][i]=c[i]; } for(int d=0;d+1<60;++d){ for(int i=0;i<n;++i){ next[d+1][i]=next[d][next[d][i]]; val[d+1][i]=val[d][i]+val[d][next[d][i]]; all[d+1][i]=max(all[d][i],val[d][i]+all[d][next[d][i]]); } } ll ans=-INF; for(int v=0;v<n;++v){ ll sum=0; ll offset=v; for(int d=0;d<60;++d){ if(k&(1LL<<d)){ ans=max(ans,sum+all[d][offset]); sum+=val[d][offset]; offset=next[d][offset]; } } } cout<<ans<<endl; return 0; }
#include <iostream> #include <algorithm> #include <tuple> #include <vector> #include <string> #include <queue> #include <cmath> #include <set> #include <map> #include <cassert> using namespace std; using ll = long long; 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; } int main() { int n, m; cin >> n >> m; priority_queue<int> a; for(int i = 0; i < n; i++){ int s; cin >> s; a.push(s); } for(int i = 0; i< m; i++){ int tmp = a.top(); a.pop(); tmp /= 2; a.push(tmp); } ll ans = 0; for(int i = 0; i< n; i++){ ans += a.top(); a.pop(); } cout << ans << endl; return 0; }
0
88,727,667
#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #include<algorithm> #define rep(i,n) for (int i = 0;i < (n);i++) #define all(v) v.begin(),v.end() #define dec(n) cout << fixed << setprecision(n); #define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define small "abcdefghijklmnopqrstuvwxyz" using namespace std; using ll = long long; using P = pair<ll,ll>; using vl = vector<ll>; using vvl = vector<vl>; ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b , a % b); } const ll MOD = 1000000007; const ll MAX = 2000001; ll mod(ll a){ return a % MOD; } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } int main(){ ll a,b,c; cin >> a >> b >> c; if(a == b) cout << c << endl; else if(a == c) cout << b << endl; else cout << a << endl; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, m = 1e5; int f[m + 2], frq[m + 1] = {}; int modularPow(int a, int p) { if (!p) return 1; if (p & 1) return (1ll * a * modularPow((1ll * a * a) % mod, p / 2)) % mod; return modularPow((1ll * a * a) % mod, p / 2); } int modF(int a, int b) { return (1ll * a * modularPow(b, mod - 2)) % mod; } int choose(int n, int k) { return modF(f[n], (1ll * f[n - k] * f[k]) % mod); } int sub(int a, int b) { a -= b; if (a < 0) a += mod; return a; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); f[0] = 1; for (int i = 1; i <= m + 1; i++) f[i] = (1ll * i * f[i - 1]) % mod; int n, ind1, ind2; cin >> n; int arr[n + 1]; for (int i = 0; i <= n; i++) { cin >> arr[i]; frq[arr[i]]++; if (frq[arr[i]] == 2) { for (int j = 0; j < i; j++) if (arr[j] == arr[i]) { ind1 = j + 1; break; } ind2 = i + 1; } } for (int i = 1; i <= n + 1; i++) { int all = choose(n + 1, i); if (i - 1 <= (n + 1 - ind2) + (ind1 - 1)) all = sub(all, choose((n + 1 - ind2) + (ind1 - 1), i - 1)); cout << all << "\n"; } return 0; }
0
48,205,337
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; #define ll long long const int inf = 1000000000; int main(){ int a,b,m; cin >> a >> b >> m; vector<int> A(a); vector<int> B(b); vector<int> x(m); vector<int> y(m); vector<int> c(m); rep(i,a){ cin >> A[i]; } rep(i,b){ cin >> B[i]; } rep(i,m){ cin >> x[i] >> y[i] >> c[i]; } int ans=1000000; rep(i,m){ ans=min(ans,A[x[i]-1]+B[y[i]-1]-c[i]); } sort(A.begin(),A.end()); sort(B.begin(),B.end()); ans=min(ans,A[0]+B[0]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define nl '\n' #define INF 1e9 + 5 #define f(i, n) for (int i = 0; i < n; ++i) using namespace std; pair<int, int> get(vector<int>& a, bool even, int skip) { int n = a.size(); unordered_map<int, int> book; pair<int, int> res = {0, 0}; if (even) { for (int i = 0; i < n; ++i) { if (i & 1 || a[i] == skip) continue; if (book.count(a[i])) book[a[i]]++; else book[a[i]] = 1; if (res.second < book[a[i]]) { res.first = a[i]; res.second = book[a[i]]; } } } else { for (int i = 0; i < n; ++i) { if (!(i & 1) || a[i] == skip) continue; if (book.count(a[i])) book[a[i]]++; else book[a[i]] = 1; if (res.second < book[a[i]]) { res.first = a[i]; res.second = book[a[i]]; } } } return res; } void solve() { int n; cin >> n; vector<int> a(n); f(i, n) cin >> a[i]; int m = n / 2; pair<int, int> one = get(a, true, INF); pair<int, int> two = get(a, false, one.first); pair<int, int> three = get(a, false, INF); pair<int, int> four = get(a, true, one.first); int ans = min({(m - one.second) + (m - two.second), (m - three.second) + (m - four.second)}); cout << ans << nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); }
0
34,982,198
#include <bits/stdc++.h> const int M = 1e4+10; using namespace std; int cnt; vector<int> arr,vec[M]; set<int> st; int in[M]; void go(){ while(!st.empty()){ int u=*st.begin(); st.erase(st.begin()); arr.push_back(u); cnt++; for(int i=0;i!=vec[u].size();i++){ in[vec[u][i]]--; if(!in[vec[u][i]]) st.insert(vec[u][i]); } } } main(){ int n,m; cin>>n>>m; for(int i=1;i<=m;i++){ int x,y; cin>>x>>y; vec[x].push_back(y); in[y]++; } for(int i=0;i<n;i++) if(!in[i]) st.insert(i); go(); for(int i=0;i<n;i++) cout<<arr[i]<<endl; }
#include<iostream> using namespace std; int main() { long long a,b,k,d=0,m=0; cin>>a>>b>>k; if(a>=k) { d=a-k; cout<<d<<" "<<b<<endl; } else if(k>a) { d=k-a; m=b-d; if(d>b) { cout<<0<<" "<<0<<endl; } else if(b>=d) { cout<<0<<" "<<m<<endl; } } return 0; }
0
25,454,127
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0;i<(ll)n;++i) int main(){ ll n,k; cin >> n >> k; vector<pair<ll,ll>> ab(n); rep(i,n){ ll anum,bnum; scanf("%lld %lld",&anum,&bnum); ab.at(i).first = anum; ab.at(i).second = bnum; } sort(ab.begin(),ab.end()); ll cnt = 0; rep(i,n){ cnt += ab.at(i).second; if( cnt >= k ){ cout << ab.at(i).first << endl; return 0; } } 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; } signed main(){ int N, Q; cin>>N>>Q; vec_int a(N-1), b(N-1); rep(i,N-1)cin>>a.at(i)>>b.at(i); vec_int p(Q), x(Q); rep(i,Q)cin>>p.at(i)>>x.at(i); vec_int scores(N+1,0); rep(i,Q){ scores.at(p.at(i)) += x.at(i); } vector<vector<int>> tree_str(N+1); for(int i=0;i<N-1;i++){ tree_str.at(a.at(i)).push_back(b.at(i)); tree_str.at(b.at(i)).push_back(a.at(i)); } queue<P> next_nodes; vec_int visited(N+1,0); for(auto pos: tree_str.at(1)){ next_nodes.push(make_pair(pos, scores.at(1))); } visited.at(1) = 1; while(next_nodes.size()>0){ int pos, score; tie(pos,score) = next_nodes.front(); next_nodes.pop(); visited.at(pos) = 1; scores.at(pos) = scores.at(pos) + score; for(auto next_pos: tree_str.at(pos)){ if(visited.at(next_pos)==1)continue; next_nodes.push(make_pair(next_pos, scores.at(pos))); } } for(int i=1;i<N;i++){ cout<<scores.at(i)<<" "; } cout<<scores.at(N)<<endl; return 0; }
0
86,882,021
#include <iostream> #include <numeric> #include <cmath> #include <limits> #include <stdio.h> #include <iomanip> #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> using namespace std; using ll = long long; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); } ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); } int main() { ll K, A, B; cin >> K >> A >> B; if (A + 2 >= B)cout << K + 1 << endl; else { cout << (B - A) * max(ll(0), (K - A + 1) / 2)+1+K- 2*max(ll(0), (K - A + 1) / 2) << endl; } }
#include <bits/stdc++.h> using namespace std; using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vll = vector<long long>; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite) #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back #define vint vector<int> constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 1e9 + 7LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size() - 1; ++i) { os << v[i] << " "; } if (v.size() > 0) { os << v[v.size() - 1] << endl; } return os; } int main() { int n; cin >> n; vll t(n), a(n); cin >> t >> a; if (n == 1){ if (a[0] != t[0]){ cout << 0 << endl; }else{ cout << 1 << endl; } return 0; } if ((a[0] > a[1] && t[0] != a[0]) || (t[0] > a[0])){ cout << 0 << endl; return 0; } ll ans = 1; FOR(i, 1, n-1){ if (a[i] > a[i+1] && t[i-1] < t[i]){ if (a[i] != t[i]){ cout << 0 << endl; return 0; } }else if (a[i] > a[i+1]){ if (a[i] > t[i]) { cout << 0 << endl; return 0; } } else if (t[i - 1] < t[i]) { if (a[i] < t[i]) { cout << 0 << endl; return 0; } } else { ans = (ans * min(a[i], t[i])) % MOD; } } if ( (t[n-2] < t[n-1] && t[n-1] != a[n-2]) || (t[n-1] < a[n-1]) ){ cout << 0 << endl; return 0; } cout << ans << endl; }
0
34,780,685
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int a[100]; int b,sum=0,point; while(1){ cin >> b; if(b==0) break; for(int i=0;i<b;i++){ cin >> a[i]; } sort(a,a+b); for(int j=1;j<b-1;j++){ sum+=a[j]; } point=sum/(b-2); cout << point << endl; sum=0; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> int t,n,m; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); string x,y; int ans=1001; cin >> x >> y; for (int i=0, last=x.length()-y.length(); i<=last; i++){ int tans=0; for (int j=0; j<y.length(); j++){ if (x[i+j] != y[j]) ++tans; } ans = min(ans,tans); } cout << ans << endl; return 0; }
0
58,768,091