code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
2
101M
#include <bits/stdc++.h> #include <iostream> #include <cmath> #include <stdio.h> int main(void){ int h1,m1,h2,m2,t,k; std::cin >>h1>>m1>>h2>>m2>>k; t=(h2-h1)*60+(m2-m1); if(t==k){ std::cout << "0"; }else{ std::cout << t-k; } return 0; }
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> P; typedef long long ll; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) const double EPS = 1e-10; const double PI = acos(-1.0); const int INT_INF = 2147483647; const long long LL_INF = 1LL<<60; const long long MOD = 1000000007; #define CLR(a) memset((a), 0 ,sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 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; } long long modp(long long a, long long p) { long long res = a % p; if (res < 0) res += p; return res; } bool comp(pair<ll,ll> a, pair<ll,ll> b){ return a.second < b.second; } int main(void){ ll N,L,T; cin >> N >> L >> T; vector<ll> X(N), W(N); REP(i,N) cin >> X[i] >> W[i]; ll n_swap = 0; REP(i,N-1){ if(W[0] == W[i+1]) continue; if(W[0] == 1) n_swap += (2*T + (L-X[i+1]+X[0])) / L; else n_swap += (2*T + (X[i+1]-X[0])) / L; } ll init; if(W[0] == 1) init=-1; else init=LL_INF; vector<pair<ll,ll>> after(N, pair<ll,ll>(0,init)); if(W[0] == 1) after[0].second = modp(n_swap, N); else after[0].second = modp(-n_swap, N); ll key = after[0].second; REP(i,N){ if(W[i] == 1) after[i].first = modp(X[i]+T, L); else after[i].first = modp(X[i]-T, L); } SORT(after); int pos = 0; while(after[pos].second != key) pos++; REP(i,N){ after[pos].second = key; pos = (pos+1)%N; key = (key+1)%N; } sort(after.begin(), after.end(), comp); REP(i,N) cout << after[i].first << endl; return 0; }
0
38,665,118
#include <iostream> #include <vector> #include <cassert> #include <cmath> #include <map> using ll = long long; #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) < (b)) ? (b) : (a)) int const nmax = 20000; int main() { int x, y; std::cin >> x >> y; if(0 <= x && x <= y) std::cout << y - x; else if(x <= y && y <= 0) std::cout << y - x; else { int coef = fabs(fabs(x) - fabs(y)); if(0 < x && 0 < y) std::cout << coef + 2; else if(x < 0 && y < 0) std::cout << coef + 2; else std::cout << 1 + coef; } return 0; }
#include<iostream> #include<vector> using namespace std; using ll=long long; int main(){ int n; cin>>n; ll now=1; ll MAX=1e18; vector<ll> a(n); for(int i=0;i<n;i++){ cin>>a[i]; if(a[i]==0){ cout<<0<<endl; return 0; } } for(int i=0;i<n;i++){ if(MAX/now<a[i]){ cout<<-1<<endl; return 0; } else if(MAX<now*a[i]){ cout<<-1<<endl; return 0; } now*=a[i]; } cout<<now<<endl; }
0
36,250,976
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define pb push_back #define mp make_pair #define ll long long int #define ld long double #define vi vector<int> #define vl vector<ll> #define v2i vector<vector<int>> #define v2l vector<vector<ll>> #define ppi pair<int,int> #define ppl pair<ll,ll> #define vpi vector<ppi> #define vpl vector<ppl> #define all(x) x.begin(),x.end() #define ii int,int #define ff first #define ss second #define forn(i,a,b) for(int i=a;i<b;i++) #define forr(i,a,b) for(int i=a;i>=b;i--) #define forv(i,m) for(auto i : m) #define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;} #define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl; #define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl; #define imx INT_MAX #define imn INT_MIN #define inf 9000000000000000000 #define minf -inf #define endl "\n" #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define sze size() #define rvs reverse #define itr iterator #define pre cout<<fixed<<setprecision(10); #define umap unordered_map #define uset unordered_set #define pi 3.141592653589793 #define MAXN 100005 #define test1(x) cout << #x " = " << x << endl; #define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl; #define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; #define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; const ll infinity = 9e18; #define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define MODM(a,b,md) ((a%md)*(b%md))%md #define MODA(a,b,md) ((a%md)+(b%md))%md #define ull unsigned long long int bool compare(int a,int b) {return a > b;} bool compare1(ppi a,ppi b) {return a.ff > b.ff;} bool compare2(ppi a,ppi b) {return a.ss < b.ss;} ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;} ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;} bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;} ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);} ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; } int main() { fast /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n,p; cin>>n>>p; string s; cin>>s; ll total = 0; if(p == 2 || p == 5) { forn(i,0,n) { if((s[i]-'0')%p==0) { total += (i+1); } } cout<<total; return 0; } map<ll,ll> m; m[0] = 1; ll rem = 0; forr(i,n-1,0) { rem = (rem + power(10,n-1-i,p)*(s[i]-'0'))%p; total += m[rem]; m[rem]++; } cout<<total; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mp make_pair #define pb push_back #define lp(i,s,f) for(ll i = s; i < ll(f); i++) #define inF freopen("input.in", "r", stdin); #define outF freopen("output.in", "w", stdout); #define endl '\n' #define MOD 1000000007 #define mm(arr) memset(arr, 0, sizeof(arr)) #define F first #define S second #define int ll int32_t main(){ FAST int n, m; cin >> n >> m; vector<int> arr[m + 1]; for(int i = 0; i < n; i++){ int a, b; cin >> a >> b; if(a > m)continue; arr[a].pb(b); } priority_queue<int> pq; int ans = 0; for(int i = 1; i <= m; i++){ for(int j = 0; j < arr[i].size(); j++){ pq.push(arr[i][j]); } if(pq.empty())continue; ans += pq.top(); pq.pop(); } cout << ans; return 0; }
0
40,398,263
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; const int MOD = 1e9 + 7; int f(int n) { int ret = 0; while (n >= 1) { ret += n % 10; n /= 10; } return ret; } int main() { int n; cin >> n; if (n % f(n) == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main(){ int h, w; cin >> h >> w; vector<string> field(h); rep(i, h) cin >> field[i]; vector<vector<int>> yoko(h, vector<int>(w, 0)); vector<vector<int>> tate(h, vector<int>(w, 0)); rep(i, h){ vector<bool> done(w, 0); rep(j, w){ if(field[i][j] == '#') continue; if(done[j]) continue; int l = 0; while(j + l < w){ if(field[i][j + l] == '.') l++; else break; } rep(k, l){ yoko[i][j + k] = l; done[j + k] = true; } } } rep(i, w){ vector<bool> done(h, 0); rep(j, h){ if(field[j][i] == '#') continue; if(done[j]) continue; int l = 0; while(j + l < h){ if(field[j + l][i] == '.') l++; else break; } rep(k, l){ tate[j + k][i] = l; done[j + k] = true; } } } int ans = 0; rep(i, h){ rep(j, w){ ans = max(ans, tate[i][j] + yoko[i][j] - 1); } } cout << ans << endl; return 0; }
0
74,131,171
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) typedef long long ll; typedef pair<int, int> P; const int MAX = 1e5 + 5; const int INF = 1001001001; const int MOD = 1e9 + 7; int main(){ int N, K; cin >> N >> K; vector<int> A(N); rep(i, N) cin >> A[i]; vector<ll> sum(N + 1); rep(i, N) sum[i + 1] = sum[i] + A[i]; vector<ll> B; rep(i, N + 1) { rep(j, i) B.push_back(sum[i] - sum[j]); } ll ans = 0; int M = B.size(); vector<bool> available(M, true); for (int i = 60; i >= 0; --i) { int cnt = 0; rep(j, M) if (available[j] && B[j] >> i & 1) cnt++; if (K <= cnt) { ans += 1L << i; rep(j, M) { if (!(B[j] >> i & 1)) available[j] = false; } } } cout << ans << endl; }
#include<bits/stdc++.h> #include<math.h> using namespace std; #define ll long long int #define mp make_pair #define pb push_back #define MOD 1000000007 bool isvowel(char c) { if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') return true; return false; } ll isprime(ll n) { ll ans=1; for(ll i=2;i<=sqrt(n);i++) { if(n%i==0) ans = i; } return ans; } ll power(ll a,ll b,ll m) { if(b==0) return 1; if(b==1) return a%m; ll temp=power(a,b/2,m); if(b%2==0) return ((temp%m)*(temp%m))%m; else return ((((temp%m)*(temp%m))%m)*a%m)%m; } ll c(ll n, ll k) { ll C[n + 1][k + 1]; ll i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= min(i, k); j++) { if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = (C[i - 1][j - 1]%MOD + C[i - 1][j])%MOD; } } return C[n][k]%MOD; } ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } ll func(ll n) { ll ans=0; for(ll i=2;i*i<=n;i++) { if(n%i==0) { if(i/10==0) ans+=1+func(i)*func(n/i); else ans+=func(i)*func(n/i); } } return ans; } ll dp[205][205][205]; ll check(ll red[],ll gre[],ll blu[],ll r,ll g,ll b,ll i,ll j,ll k) { if(dp[i][j][k]!=-1) return dp[i][j][k]; if(i<r&&j<g&&k<b) { return dp[i][j][k]=max(red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k),max(gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1),blu[k]*red[i]+check(red,gre,blu,r,g,b,i+1,j,k+1))); } else if(i<r&&j<g) { return dp[i][j][k]=red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k); } else if(j<g&&k<b) { return dp[i][j][k]=gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1); } else if(i<r&&k<b) { return dp[i][j][k]=red[i]*blu[k]+check(red,gre,blu,r,g,b,i+1,j,k+1); } else { return 0; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; t=1; while(t--) { ll n,k; cin>>n>>k; ll a[n+1]; a[0]=0; for(ll i=1;i<=n;i++) { a[i]=a[i-1]+i; } ll ans=0; ll m=1000000007; for(ll i=k;i<=n+1;i++) { ll mn=a[i-1]; ll mx; if(i==n+1) mx=a[n]; else mx=a[n]-a[n-i]; ll p=mx-mn+1; ans+=p; } cout<<ans%m; } }
0
80,666,563
#include <bits/stdc++.h> using namespace std; #define MAXN 300*1000 + 5 using ll = long long; ll freq[MAXN], freq_freq[MAXN]; ll f(int x) { ll res = x * (freq_freq[MAXN-1] - freq_freq[x]) + freq[x]; return res / x; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) { int x; cin >> x; freq[x]++; } for(int i = 0; i < MAXN; i++) { if(freq[i] == 0) continue; freq_freq[freq[i]]++; } for(int i = 1; i <= n; i++) { freq[i] = freq[i-1] + 1LL * i * freq_freq[i]; } partial_sum(freq_freq, freq_freq + MAXN, freq_freq); for(int k = 1; k <= n; k++) { int lo = 0, hi = n+1; while(lo < hi) { int x = lo + (hi-lo+1)/2; if(k <= f(x)) { lo = x; } else { hi = x-1; } } cout << lo << '\n'; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> n >> d; vector<vector<double>> p(n, vector<double>(d)); for (int i = 0; i < n; i++) { for (int j = 0; j < d; j++) { cin >> p[i][j]; } } int ans = 0; for (int i = 0; i < n-1; i++) { for (int j = i+1; j < n; j++) { double temp = 0; for (int k = 0; k < d; k++) { temp += (p[i][k]-p[j][k])*(p[i][k]-p[j][k]); } double dist = sqrt(temp); if (modf(dist, &temp) == 0) { ans++; } } } cout << ans << endl; }
0
29,951,126
bool DBG = false; #include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define IFOR(i,a,b) for(int i=((b)-1);i>=(a);--i) #define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i) #define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i) #define ALL(x) x.begin(),x.end() #define RALL(x) x.rbegin(),x.rend() #define fs first #define sd second #define couts(x) cout << (x) << (" ") #define coutn(x) cout << (x) << ("\n") #define dcouts(x) if(DBG) couts(x) #define dcoutn(x) if(DBG) coutn(x) #define endl "\n" #define psb push_back #define ppb pop_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define LBIT(x,a) (((x)>>(a))&1LL) #define IBIT(x,a) (((x)>>(a))&1) #define BCOUNT(x) (__builtin_popcount(x)) template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec){ for (auto &v : vec) is >> v; return is; } template<typename T1, typename T2> std::istream &operator>>(std::istream &is, std::pair<T1,T2> &p){is >> p.first >> p.second; return is; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::deque<T> &vec){ os << "deque["; for (auto v : vec) os << v << ","; os << "]"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T1, typename T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; } template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template<class T> using V = vector<T>; template<class T> using V2 = V<V<T>>; template<class T> using V3 = V<V2<T>>; template<class T> using V4 = V<V3<T>>; constexpr ll LINF = 1LL << 60; constexpr int IINF = 1 << 28; constexpr ll mod = 1'000'000'007; void solve(){ int n; cin >> n; using P = pair<int,int>; V<P> reds(n), blues(n); cin >> reds >> blues; sort( ALL(reds) ), sort(ALL(blues)); int ans = 0; FOR(i,0,n){ P now(-IINF, -IINF); FOR(j,0,n){ if(reds[j].fs>=blues[i].fs || reds[j].sd>=blues[i].sd) continue; if(reds[j].sd>now.sd ){ now.fs = reds[j].fs; now.sd = reds[j].sd; } } for(auto &x:reds){ if(x.fs==now.fs && x.sd==now.sd){ x.fs = -IINF; x.sd = -IINF; break; } } if(now.fs>-IINF && now.sd>-IINF) ++ans; } cout << ans; } void solve2(){ } int main(void){ cin.tie(0); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long n,i,k,l; cin>>n; vector<long long>a(n); for(i=0;i<n;i++) cin>>a[i]; sort(a.begin(),a.end()); reverse(a.begin(),a.end()); queue<long long >q; for(i=0;i<n-1;i++) { if(a[i]==a[i+1]) { q.push(a[i]); i++; } } if(q.size()>=2) { k=q.front(); q.pop(); l=q.front(); } cout<<k*l<<endl; return 0; }
0
63,305,304
#include <iostream> #include <string> using namespace std; int main(int argc, char const *argv[]) { string S; cin >> S; string k = "keyence"; string str1, str2; int find1, find2, find3; for (int i = 1; i <= 6; i++) { str1 = k.substr(0, i); str2 = k.substr(i, 7 - i); find1 = S.find(str1); find2 = S.rfind(str2); find3 = S.find(k); if ((find1 != string::npos && find2 != string::npos) && (find1 < find2) && (0 == find1) && (S.size() - (7 - i) == find2)) { cout << "YES" << endl; return 0; } if (find3 != string::npos) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define _CRT_SECURE_NO_WARNINGS #define rep(i, n) for (int i = 0; i < n; i++) #define _GLIBCXX_DEBUG const int MOD = 1e9 + 7; const int INF = 1e18 + 9; constexpr long double pi = 3.141592653589793238462643383279; int fact(int i) { if (i == 0) return 1; return (fact(i - 1)) * i; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return a * b / gcd(a, b); } int keta(int n) { if (n == 0) return 1; int count = 0; while (n != 0) { n /= 10; count++; } return count; } int ketasum(int n) { int sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } 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 a, b, c; cin >> a >> b >> c; cout << a + b + c - max({ a,b,c }) << endl; return 0; }
0
38,783,626
#include<bits/stdc++.h> using namespace std; int main() { int n,m; cin>>m>>n; if(n*m==15)cout<<"*"; else if(n+m==15)cout<<"+"; else cout<<'x'; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for(int i = (a); i <= (n); ++i) using ll = long long; using P = pair<int, int>; int main(){ int a, b; cin >> a >> b; int count = 0; rep(i,a,b){ auto isP = [](int n){ ostringstream sout; sout << n; string s = sout.str(); string b = s.substr(0, (s.size()+1)/2); string a = s.substr((s.size()-1)/2, string::npos); reverse(a.begin(), a.end()); return b == a; }; if (isP(i)){ ++count; } } cout << count << endl; return 0; }
0
46,118,799
#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <ctype.h> #include <math.h> #include <stack> #include <string> #include <string.h> using namespace std; double PI = 3.1415926535897932; long mod = 1000000007; const long INF = (1<<30); int main() { int n,k,h[110000]; cin >> n >> k; for(int i = 0; i < n; i++) cin >> h[i]; vector<long> dp(n, INF); dp[0] = 0; dp[1] = abs(h[1] - h[0]); for(int i = 2; i < n; i++) { for(int j = 1; j < k+1; j++) { if(i >= j) dp[i] = min(dp[i-j] + abs(h[i]-h[i-j]), dp[i]); } } cout << dp[n-1] << endl; }
#include <bits/stdc++.h> using namespace std; long long N, A[100100], kotak, kotak2; int main() { cin >> N; for(int i=1; i<=N; i++) { cin >> A[i]; } sort(A+1, A+N+1); for (int i=N; i>=2; i--){ if(A[i]==A[i-1]){ kotak=i; break; } } for (int i=kotak-2; i>=2; i--){ if(A[i]==A[i-1]){ kotak2=i; break; } } cout << A[kotak]*A[kotak2] << endl; }
0
94,085,416
#include<iostream> #include<complex> #include<cmath> using namespace std; typedef complex<double> xy_t; xy_t P[4]; double cross(xy_t p,xy_t q){ return (conj(p)*q).imag(); } int main(){ int n; double eps=pow(10,-11); cin>>n; for(int i=0;i<n;++i){ for(int j=0;j<4;++j){ double x,y; cin>>x>>y; P[j]=xy_t(x,y); } xy_t a[2]={ P[0]-P[1], P[2]-P[3] }; bool flag=(abs(cross(a[0],a[1]))<eps); cout<<(flag?"YES":"NO")<<"\n"; } }
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cctype> #include<math.h> #include<string> #include<string.h> #include<stack> #include<queue> #include<vector> #include<utility> #include<set> #include<map> #include<stdlib.h> #include<iomanip> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define MOD 1000000007 #define rep(i,n) for(int i=0;i<(n);i++) #define loop(i,a,n) for(i=a;i<(n);i++) #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) #define int ll typedef vector<int> vi; typedef vector<string> vs; typedef pair<int,int> pii; int gcd(int a, int b){ if(b==0) return a; return gcd(b,a%b); } int lcm(int a, int b){ return a*b/gcd(a,b); } #define MAX 200005 signed main(void) { int i,j; int n; cin >> n; vi a(n); rep(i,n) cin >> a[i]; bool b = true; rep(i,n-1)if(a[i] >= a[i+1])b = false; if(b){ cout << 1 << endl; return 0; } int ok = MAX, ng = 1; while(ok-ng > 1){ int mid = (ok+ng)/2; bool c = true; vector<pii> ans; ans.push_back(pii(a[0],0)); rep(i,n-1){ if(ans.empty()){ c = false; break; } if(a[i] < a[i+1]){ if(ans.back().second){ ans.push_back(pii(a[i+1]-a[i],0)); }else{ ans.back().first += a[i+1]-a[i]; } }else{ int num = a[i] - a[i+1]; while(num > 0 && ans.back().first <= num){ num -= ans.back().first; ans.pop_back(); } if(num)ans.back().first -= num; int t = ans.back().second; int add = 0; if(t+1 == mid){ if(ans.size() == 1){ c = false; break; } add += ans.back().first; ans.pop_back(); } if(ans.back().first == 1){ ans.back().second++; t = ans.size()-1; if(ans.size() >= 2 && ans[t].second == ans[t-1].second){ ans[t-1].first += ans[t].first; ans.pop_back(); } }else{ t = ans.back().second; ans.back().first--; ans.push_back(pii(1,t+1)); } if(add)ans.push_back(pii(add, 0)); } } if(c)ok = mid; else ng = mid; } cout << ok << endl; }
0
51,238,433
#include<bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ld long double #define mem(a, b) memset(a, (b), sizeof(a)) #define rep(i, j, k) for (int i = j ; i < k ; ++i) #define rrep(i, j, k) for (int i = j; i > k; --i) #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define foreach(i, a) for(auto i: a) #define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++) #define in(A, B, C) assert( B <= A && A <= C) #define debug(a) cout << #a << ": " << a << endl #define Flag(n) cout << "here " << n << endl #define w(x) int x;cin>>x;while(t--) #define mp make_pair #define pb push_back #define endl '\n'; #define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define TRACE #ifdef TRACE #define see(...) __f(#__VA_ARGS__,__VA_ARGS__); template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr<<name<<" : "<<arg1<<endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...); } #else #endif const int POSITIVE_INFINITY = 9223372036854775807; const int NEGATIVE_INFINITY = -9223372036854775807; const int MOD = 1000000007; const ld PI = acos(-1.0); const int INF = 1e18; const int MX = 1000001; int32_t main() { io; string s,t; cin>>s>>t; int res= t.size(); for(int i = 0;i<=s.size()-t.size();i++){ int diff= 0; for(int j = 0;j<t.size();j++){ if(t[j]!=s[i+j])diff++; } res= min(res,diff); } cout<<res<<endl; return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define int long long #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(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define pcnt(bit) __builtin_popcountll(bit) 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;} const long double pi = acos(-1.0); const int MAX = 1000010; const int INF = 1LL << 60; const int MOD = 1000000007; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; if (n == 1) {cout << k << endl; return 0;} else { int ans = k; rep(i,n-1) ans *= k-1; cout << ans << endl; return 0; } }
0
8,477,770
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<set> #include<string> #include<sstream> #include<complex> #include<random> #include<cmath> #include<math.h> #include<stack> #include<queue> #include<map> #include<iomanip> #include<locale> #define rt "\n" #define rep(i,n) for(int i=0;i<n;i++) #define rop(i,n) for(int i=1;i<=n;i++) #define drep(i,n) for(int i=n-1;0<=i;i--) #define drop(i,n) for(int i=n;0<i;i--) #define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt; #define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt; #define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt; #define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt; #define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt; #define vcin(a,n) rep(i,n)cin>>a[i]; #define sort(s) sort(s.begin(),s.end()) #define reve(s) reverse(s.begin(),s.end()) #define please return #define AC 0 #define Inf 2147483647 #define llInf 9223372036854775807 #define rapid cin.tie(0);ios::sync_with_stdio(false) #define pi 3.1415926535897932384626 #define nine 1000000000 #define print(a) printf("%.15f\n",a) using namespace std; typedef vector<int> vint; typedef long double ldouble; typedef vector<string> vstr; typedef vector<char> vchar; typedef vector<double> vdou; typedef vector<double> vdouble; typedef long long int llint; typedef pair<int, int> pint; typedef pair<llint, llint> pllint; typedef vector<llint> vllint; typedef vector<pint> vpint; typedef vector<pair<llint, llint>> vpllint; typedef vector<vector<int>> vvint; typedef vector<vector<char>> vvchar; typedef vector<vector<double>> vvdouble; typedef vector<vector<llint>> vvllint; typedef vector<vector<string>> vvstr; typedef vector<vector<bool>> vvbool; typedef vector<vector<pint>> vvpint; typedef vector<bool> vbool; long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } long long LCM(long long a, long long b) { return a * b / GCD(a, b); } unsigned GetDigit(unsigned num) { return std::to_string(num).length(); } int tow(int n) { if (n == 0)return 1; int x = tow(n / 2); x *= x; if (n % 2 == 1)x *= 2; return x; } int KETA(int n) { int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } unsigned ND(unsigned num) { return std::to_string(num).length(); } bool KIBN(string s) { rep(i, s.size() / 2) { if (s[i] != s[s.size() - 1 - i])return false; } return true; } bool inte(double n) { if (ceil(n) == floor(n)) { return true; } else return false; } bool KISU(int n) { if (n % 2 == 0)return false; else return true; } bool GUSU(int n) { if (n % 2 == 0)return true; else return false; } int a = 0, n = 0, x = 0, y = 0, ans = 0, cnt = 0, sum = 0; string s = ""; int main(void) { rapid; int a, b, k; cin >> a >> b >> k; rep(i, k / 2) { if (a % 2 == 1)a--; b += a / 2; a /= 2; if (b % 2 == 1)b--; a += b / 2; b /= 2; } if (k % 2 == 1) { if (a % 2 == 1)a--; b += a / 2; a /= 2; } cout << a << " " << b << rt; please AC; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define repo(i,n) for(int i = 1; i < (int)(n); i++) #define pb push_back #define mp make_pair #define np next_permutation #define lb lower_bound #define ub upper_bound #define fi first #define se second #define all(x) (x).begin(),(x).end() #define mod 1000000007 #define pi acos(-1.0) const ll INF = 1LL<<61; 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; } 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 jou(ll N, ll P){if(P==0) return 1; if(P%2==0){ll t = jou(N, P/2);return t*t % mod; }return (N * jou(N, P-1)) % mod;} int main() { ll n; cin>>n; ll dai=0; ll sho=10000; vector<ll> p(n); rep(i,n){ cin>>p[i]; chmax(dai,p[i]); chmin(sho,p[i]); } ll ans=sho; for(ll i=dai;i>sho;i--){ rep(j,n){ if(p[j]==i&&j+1<n&&p[j+1]!=i) ans++; if(j==n-1&&p[j]==i) ans++; } rep(j,n){ if(p[j]==i) p[j]--; } } cout << ans << endl; }
0
38,123,595
#pragma GCC optimization ("O3") #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <climits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <ratio> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL); #define endl "\n" #define mod 1000000007 typedef long long int bigint ; typedef std::vector< int > vi; typedef std::vector< long long int > vll; typedef std::vector< vi > vvi; using namespace std; int main(){ FAST() ; int A , B , C ; cin >> A >> B >> C ; int arr[] = { A , B , C } ; sort( arr , arr + 3 ) ; int cnt1 = 0 , cnt2 = 0 ; cnt1 += (arr[2] - arr[0]) / 2 ; cnt2 += ( arr[2] - arr[1] ) / 2 ; arr[0] = arr[0] + 2 * cnt1 ; arr[1] = arr[1] + 2 * cnt2 ; sort( arr , arr + 3 ) ; if( arr[0] == arr[1] && arr[1] == arr[2] ){ cout << cnt1 + cnt2 << endl ; return 0 ; } if( arr[0] == arr[1] ){ cout << cnt1 + cnt2 + arr[2] - arr[1] << endl ; return 0 ; } if( arr[0] != arr[1] ){ cout << cnt1 + cnt2 + 2 << endl ; } return 0 ; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using ll = long long; using P = pair<int,int>; const int mx = 100005; vector<int> p; vector<int> e[mx]; int visited[mx] ={0}; void rec(vector<int> *pos,vector<int> *val,int cur) { visited[cur] = 1; pos->push_back(cur); val->push_back(p[cur]); for(int u : e[cur]) { if(visited[u]) continue; rec(pos,val,u); } } int main() { int ans = 0; int n, m; cin >> n >> m; p.resize(n+1); rep(i, n) cin >> p[i+1]; rep(i, m) { int x, y; cin >> x >> y; e[x].push_back(y); e[y].push_back(x); } for(int i=1;i<=n;i++) { if(visited[i]) continue; vector<int> pos; vector<int> val; rec(&pos,&val,i); int y = pos.size(); sort(pos.begin(), pos.end()); sort(val.begin(), val.end()); while(!pos.empty()||!val.empty()) { int pp = pos.back(); int vv = val.back(); if(pp < vv) val.pop_back(); else if(pp == vv) { pos.pop_back(); val.pop_back(); ans++; }else{ pos.pop_back(); } } } cout << ans; }
0
29,637,820
#include "bits/stdc++.h" using namespace std; using ll = long long; #define rep(i, begin, n) for (int i = begin; i < n; i++) #define repe(i, begin, n) for (int i = begin; i <= n; i++) #define repr(i, begin, n) for (int i = begin; i > begin - n; i--) #define repre(i, begin, end) for (int i = begin; i >= end; i--) 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; } const int inf = 1000000007; const int MOD = 1000000007; const long long INF = 1000000000000000007; ll N, K; int main() { cin >> N >> K; if (K % 2 == 1) { ll v = N / K; cout << v * v * v << endl; } else { ll v = N / K; ll v2 = N / (K / 2); ll v3 = v2 - v; cout << v * v * v + v3 * v3 * v3 << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { int A, B; cin >> A >> B; A--; B--; char a[100][100]; for (int i = 0; i < 50; i++) { for (int j = 0; j < 100; j++) { a[i][j] = '#'; } } for (int i = 50; i < 100; i++) { for (int j = 0; j < 100; j++) { a[i][j] = '.'; } } for (int i = 1; i < 50; i+=2) { bool flag = false; for (int j = 1; j < 100; j+=2) { if (A == 0) { flag = true; break; } a[i][j] = '.'; A--; } if (flag) { break; } } for (int i = 51; i < 100; i+=2) { bool flag = false; for (int j = 1; j < 100; j+=2) { if (B == 0) { flag = true; break; } a[i][j] = '#'; B--; } if (flag) { break; } } cout << 100 << " " << 100 << endl; for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { cout << a[i][j]; } cout << endl; } return 0; }
0
100,788,866
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <string> #include <vector> #include <map> #include <unordered_map> #include <queue> #include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <limits> using namespace std; int main(int argc, char* argv[]){ cin.tie(0); ios::sync_with_stdio(false); long long N, M; cin >> N >> M; long long ans = 0; if(N > M/2){ ans = M / 2; } else{ ans = (M + 2 * N) / 4; } printf("%lld\n", ans); return 0; }
#include <iostream> #include <vector> #include <algorithm> #define MAXVALUE 10000 #define rep(i,a) for(i=0;i<a;i++) using namespace std; void CountingSort(vector<int> &A, vector<int> &B, int k){ int i,j; vector<int> C(k+1,0); for(j=0; j<A.size(); j++) { C[A[j]]++; } for(i=1; i<=k; i++) { C[i] = C[i] + C[i-1]; } for(j=A.size()-1; j>=0; j--){ B[C[A[j]]-1] = A[j]; C[A[j]]--; } } int main(void) { vector<int> A; vector<int> B; int i,n,num; cin >> n; for(i = 0; i < n; i++) { cin >> num; A.push_back(num); } B.resize(n); CountingSort(A,B,*max_element(A.begin(),A.end())); rep(i,n){ cout << B[i]; if(i != n-1) { cout << " "; } else { continue; } } cout << endl; return 0; }
0
36,272,703
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rep2(i,s,n) for(int i = (s); i < (n); ++i) #define ll long long #define ld long double #define P pair<ll,ll> #define all(v) v.begin(),v.end() const ll mod = 1e9+7; const ll INF = 1e18; const double pi = acos(-1.0); ll f(ll n){ ll sum=0; for(int i=1;i<=n;i++){ if(n%i==0) sum++; } return sum; } int main(void) { ll a,b,k; cin>>a>>b>>k; ll cnt=0; for(int i=min(a,b);i>=1;i--){ if(a%i!=0 || b%i!=0) continue; else cnt++; if(cnt==k){ cout<<i<<endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define Alhamdulillah return 0; #define debug(n) cerr << "[" << #n << " = " << n << "]" << endl void Suhaib_Sawalha (){ int a , b , c; cin >> a >> b >> c; cout << (c >= a && c <= b ? "Yes" : "No"); } int main(){ In_The_Name_Of_Allah_The_Merciful #ifndef ONLINE_JUDGE freopen("SuhaibSawalha1.txt","r",stdin); #endif Suhaib_Sawalha(); Alhamdulillah }
0
31,703,249
#include<bits/stdc++.h> using namespace std; int main(){ int m,f,r,s; char G; while(1){ cin>>m>>f>>r; if(m==-1&&f==-1&&r==-1)break; s=m+f; if((m==-1)||(f==-1)){ G='F'; }else if(s>=80){ G='A'; }else if((s>=65)&&(s<80)){ G='B'; }else if((s>=50)&&(s<65)){ G='C'; }else if((s>=30)&&(s<50)){ if(r>=50){ G='C'; }else{ G='D'; } }else if(s<30){ G='F'; } cout<<G<<endl; } return(0); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; cin >> N; vector<int> A(N); for(int i = 0; i < N; i++) { cin >> A[i]; } int ok[1000001] = {0}; int cnt[1000001] = {0}; for(int i = 0; i < N; i++) { cnt[A[i]]++; } for(int i = 1; i <= 1000000; i++) { if(cnt[i] > 0) { if(cnt[i] > 1) { ok[i] = 1; } for(int j = i + i; j <= 1000000; j += i) { ok[j] = 1; } } } int ans = 0; for(int i = 0; i < N; i++) { if(ok[A[i]] == 0) ans++; } cout << ans; return 0; }
0
43,962,981
#include<iostream> using namespace std; #define ll long long int main() { ll n,i,j,c=1,d,mini; cin>>n; ll a[n]; for(i=0;i<n;i++) { cin>>a[i]; if(i>0) { if(a[i]<=mini) { c++; mini=a[i]; } } else { mini=a[i]; } } cout<<c<<endl; }
#include "bits/stdc++.h" using namespace std; const int mx = 2e5 + 9; int ans[mx]; bitset <mx> mark; vector <int> adj[mx]; void bfs(int s) { mark[s] = 1; queue <int> q; q.push(s); while (!q.empty()) { auto u = q.front(); q.pop(); for (auto v : adj[u]) { if (mark[v]) continue; mark[v] = 1; ans[v] = u; q.push(v); } } } int main() { int n, m; cin >> n >> m; memset(ans, -1, sizeof ans); while (m--) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } bfs(1); for (int i = 2; i <= n; i++) { if (ans[i] == -1) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; for (int i = 2; i <= n; i++) { cout << ans[i] << endl; } }
0
5,756,041
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vs = vector<string>; using pll = pair<ll, ll>; using vp = vector<pll>; template<class T> using V = vector<T>; template<class T> using VV = vector<vector<T> >; #define rep(i, n) for(ll i = 0; i < (n); i++) #define repb(i, n) for(ll i = (n)-1; i >= 0; i--) #define repr(i, a, b) for(ll i = (a); i < (b); i++) #define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) const ll MOD = 1000000007; const ll INF = 100000000000000000LL; const ld EPS = 1e-12L; const ld PI = 3.1415926535897932385L; inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; } inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; } inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; } inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; } template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; } template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; } #ifdef OJ_LOCAL #include "dump.hpp" #else #define dump(...) ((void)0) #endif void PR(bool f){ cout << (f ? "YES" : "NO") << endl; exit(0); } int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n; cin >> n; vll a(n); rep(i, n){ cin >> a[i]; } ll sum = accumulate(ALL(a), 0ll); if(sum % (n*(n+1)/2) != 0){ PR(false); } ll m = sum / (n*(n+1)/2); vll diff(n); rep(i, n){ diff[i] = m - (a[(i+1)%n]-a[i]); if(diff[i] % n != 0){ PR(false); } diff[i] /= n; } rep(i, n){ if(diff[i] < 0 || diff[i] > m){ PR(false); } } PR(accumulate(ALL(diff), 0ll) == m); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int MOD = 1e9 + 7; void add(int &a, int b) { a = (a + b) % MOD; } int main() { int n, k; cin >> n >> k; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; vector<vector<int>> dp(n+1, vector<int>(k+1, 0)); dp[0][0] = 1; for(int i = 1; i <= n; i++) { int num = 0; for(int j = 0; j <= k; j++) { add(num, dp[i-1][j]); dp[i][j] = num; if(j-a[i-1] >= 0) add(num, -dp[i-1][j-a[i-1]]); } } cout << (dp[n][k]+MOD)%MOD << endl; }
0
19,865,402
#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 = 998244353; const ll MAX = 2000001; ll mod(ll a){ if(a % MOD < 0) return MOD + (a % MOD); return a % MOD; } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } int main(){ ll n,h; cin >> n >> h; ll cnt = 0; vvl table(n,vl(2)); rep(i,n) cin >> table[i][0] >> table[i][1]; vl bn(n); rep(i,n) bn[i] = table[i][1]; sort(all(bn)); reverse(all(bn)); ll maxcut = 0; rep(i,n){ maxcut = max(maxcut,table[i][0]); } rep(i,n){ if(bn[i] > maxcut){ cnt++; h -= bn[i]; if(h <= 0){ cout << cnt << endl; return 0; } } } cnt += (h+maxcut-1)/maxcut; cout << cnt << endl; }
#include <iostream> #include <string> #include <vector> #include <set> #include <algorithm> #include <cctype> #include <cmath> #include <queue> #include <map> #include <numeric> #include <unordered_map> #include <iomanip> #include <functional> #include <bitset> #include <complex> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define repi(i,a,b) for(int i=int(a);i<int(b);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; } typedef long long ll; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; vector<int>city(n); rep(i,n)cin>>city[i]; int l,q; cin>>l>>q; int nl=n,c=0; while(nl>0){c++;nl/=2;} vector<vector<int>>db(n,vector<int>(c,n)); int r=0; rep(i,n) { while(r+1<n&&city[r+1]<=city[i]+l)r++; db[i][0]=r; } rep(i,c-1) { rep(j,n) { db[j][i+1]=db[db[j][i]][i]; } } rep(i,q) { int a,b; cin>>a>>b; a--;b--; if(a>b)swap(a,b); int cnt=0; int ma=lower_bound(all(db[a]),b)-db[a].begin(); for(int j=ma-1;j>=0;j--) { if(db[a][j]<b) { a=db[a][j]; cnt+=1<<j; } } cout<<cnt+1<<"\n"; } cout<<flush; return 0; }
0
3,868,589
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <cmath> #include <queue> #include <map> #include <unordered_map> #include <set> #include <functional> #include <bitset> #include <numeric> #include <complex> #include <iomanip> #include <cassert> #include <random> int main() { int n; std::cin >> n; std::vector<long long> a(n); for (int i = 0; i < n; i++) std::cin >> a[i]; long long ans = 0; for (int i = 0; i < n; i++) { ans += a[i] / 2; if (i < n - 1 && a[i] & 1 && a[i + 1] > 0) { ans++; a[i + 1]--; } } std::cout << ans << std::endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int,int>; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define MOD 1000000007 int main(){ int n; cin >> n; int _A = 0,B_ = 0,BA = 0; ll res = 0; rep(i,n){ string s;cin >> s; if(s[0] == 'B' && s.back() == 'A'){ BA++; }else if(s[0] == 'B'){ B_++; }else if(s.back() == 'A'){ _A++; } for(int j = 1;j < s.size();j++){ if(s[j] == 'B' && s[j-1] == 'A')res++; } } if(BA > 0){ res += BA-1; if(B_ > 0)res++,B_--; if(_A > 0)res++,_A--; } res += min(B_,_A); cout << res << endl; return 0; }
0
21,264,923
#include <iostream> #include <math.h> using namespace std; int main() { int a,b; cin>>a>>b; if(a >= b){ cout<<"10"; } else{ cout<<"0"; } return 0; }
#include <stdio.h> int main() { long long int n; long long int t; scanf("%lld", &t); long long int num[t]; long long int sum = 1; for(long long int i = 0; i<t; i++){ scanf("%lld", &n); num[i] = n; } for(long long int i = 0; i<t; i++){ if(num[i]==0){ printf("0\n"); return 0; } } for(long long int i = 0; i<t; i++){ if(num[i]<=1000000000000000000/sum){ sum *= num[i]; } else{ printf("-1\n"); return 0; } } printf("%lld\n", sum); return 0; }
0
89,359,857
#include <stdio.h> #include <string> #include <stdlib.h> #include<vector> #include<iostream> #include<set> #include<map> #include<algorithm> using namespace std; long long int divide(long long int h,long long w){ if(h %2 == 0){ return (h/2)*w; } if(w %2 == 0){ return (w/2)*h; } long long int mi = min(h,w); long long int ma = max(h,w); return (ma/2)*mi; } long long int calcRes(long long int rect1,long long int rect2,long long int rect3){ long long int ma = max(rect1,max(rect2,rect3)); long long int mi = min(rect1,min(rect2,rect3)); return ma - mi; } int main() { int h,w; cin >> h >> w; cout << (h-1)*(w-1) <<endl; return 0; }
#pragma GCC target ("avx2") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("O3") #include "bits/stdc++.h" #include <unordered_set> #include <unordered_map> #include <random> using namespace std; typedef long long ll; const ll MOD = 1'000'000'007LL; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) const int dx[4]={ 1,0,-1,0 }; const int dy[4]={ 0,1,0,-1 }; signed main(){ char c; cout << "? " << 10'000'000'000LL << endl; cin >> c; if(c == 'Y'){ for(ll i=1'000'000'000; i>=1; i/=10){ cout << "? " << i+1 << endl; cin >> c; if(c == 'N'){ cout << "! " << i*10 << endl; return 0; } } cout << "! 1" << endl; return 0; } for(ll i=1'000'000'000; i>=1; i/=10){ cout << "? " << i << endl; cin >> c; if(c == 'Y'){ ll r = i*10; ll l = i; while(r-l > 1){ ll m = (r+l)/2; cout << "? " << m << 0 << endl; cin >> c; if(c == 'Y') r = m; else l = m; } cout << "! " << r << endl; break; } } }
0
99,084,301
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cstdlib> #include<queue> #include<set> #include<cstdio> using namespace std; #define ll long long #define rep(i, n) for(int i = 0; i < n; i++) #define P pair<int, int> typedef vector<int> vec; typedef vector<vec> mat; const ll mod = 1000000007; int main(){ int n; cin >> n; vector<int> a(n); rep(i, n){ int x; cin >> x; a[x-1]++; } sort(a.begin(), a.end()); vector<int> s(n+1); rep(i, n) s[i+1] = s[i] + a[i]; for (int k = 1; k <= n; k++){ int l = 0, r = n / k + 1; while(l + 1 < r){ int c = (l + r) / 2; bool ok = [&](int c){ int i = lower_bound(a.begin(), a.end(), c) - a.begin(); int sum = c * (n - i) + s[i]; return (sum >= c * k); }(c); if(ok) l = c; else r = c; } printf("%d\n", l); } }
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <cassert> #include <cfloat> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i) #define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i) #define Sort(v) sort(v.begin(), v.end()) #define rSort(v) sort(v.rbegin(), v.rend()) #define Reverse(v) reverse(v.begin(), v.end()) #define Lower_bound(v, x) \ distance(v.begin(), lower_bound(v.begin(), v.end(), x)) #define Upper_bound(v, x) \ distance(v.begin(), upper_bound(v.begin(), v.end(), x)) using ll = long long; using ull = unsigned long long; using P = pair<ll, ll>; using T = tuple<ll, ll, ll>; using vll = vector<ll>; using vP = vector<P>; using vT = vector<T>; using vvll = vector<vector<ll>>; using vvP = vector<vector<P>>; using dqll = deque<ll>; ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0}; ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; const ll INF = 1LL << 50; int main() { cout << fixed << setprecision(15); ll h, w; cin >> h >> w; vector<string> mp(h); rep(i, h) { cin >> mp[i]; } queue<T> que; rep(i, h) rep(j, w) { if (mp[i][j] == '#') que.emplace(i, j, 0); } ll ans = 0; while (!que.empty()) { ll y, x, n; tie(y, x, n) = que.front(); que.pop(); for (ll i = 0; i < 4; i++) { ll ny = y + dy[i], nx = x + dx[i], nn = n + 1; bool ok = 0 <= ny && ny < h && 0 <= nx && nx < w && mp[ny][nx] == '.'; if(ok){ mp[ny][nx] = '#'; chmax(ans, nn); que.emplace(ny, nx, nn); } } } cout << ans << endl; return 0; }
0
20,157,178
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <string> #include <numeric> #include <math.h> using namespace std; double condition = 0.0; bool kaibun(string S, int start, int length) { string tmp1, tmp2; tmp1 = S.substr(start, length); tmp2 = tmp1; reverse(tmp2.begin(), tmp2.end()); return tmp1 == tmp2; } void func() { string S; cin >> S; int l = S.length(); if (kaibun(S,0,l) && kaibun(S, 0, (l-1)/2) && kaibun(S, (l + 3) / 2 - 1, l- (l + 3) / 2 + 1)) { cout << "Yes\n"; } else { cout << "No\n"; } } int main() { func(); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (lli i = 0; i < (n); i++) #define rrep(i, n) for (lli i = (n)-1; i >= 0; i--) using namespace std; using lli = long long int; lli calc(lli a, lli b) { if (a % b == 0) { return a / b - 1; } else { return a / b; } } int main() { int n; cin >> n; vector<lli> a(n); rep(i, n) cin >> a[i]; int state = 1; lli ans = 0; rep(i, n) { if (i != 0) { if (state < a[i]) { ans += calc(a[i], state); } else if (state == a[i]) { state++; } } else { ans += calc(a[i], state); state++; } } cout << ans << endl; }
0
86,339,011
#include<algorithm> #include<bitset> #include<cassert> #include<cfloat> #include<climits> #include<cmath> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<map> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> using namespace std; using lint = long long; using P = pair<int, int>; using LLP = pair<long long, long long>; #define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i) #define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i) #define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i) #define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i) #define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i) #define SORT(x) sort((x).begin(), (x).end()) #define SORT_INV(x) sort((x).rbegin(), (x).rend()) #define REVERSE(x) reverse((x).begin(), (x).end()) #define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n' #define endl '\n' constexpr int IINF = (1 << 30) - 1; constexpr long long LLINF = 1LL << 61; constexpr double EPS = 1e-10; constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1}; constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template<typename T> bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; } template<typename T> bool chmin(T& a, T b){ if(b < a){ a = b; return true; } return false; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int n; cin >> n; vector<lint> a(n); rep(i, n){ cin >> a[i]; } lint ans = 0; bool flag = true; while(flag){ flag = false; rep(i, n){ if(a[i] >= n){ flag = true; lint k = a[i] / n; ans += k; rep(j, n){ if(i == j){ a[j] -= k * n; }else{ a[j] += k; } } } } } cout << ans << endl; cout << flush; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define fi first #define se second long long mo = 1000000007; typedef long long ll; typedef long double ld; typedef pair<int,int> Pii; typedef pair<ll,ll> Pll; template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; } template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; } template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";} ld PI=3.14159265358979323846; int main(){ ll N; cin >> N; vector<ll> A(N); map<ll,ll> mp; rep(i,N){ cin >> A[i]; } rep(i,N){ mp[A[i]] = i; } sort(A.begin(), A.end()); ll OtoE = 0; ll EtoO = 0; rep(i,N){ if((mp[A[i]] - i) % 2 != 0){ if(mp[A[i]]%2 == 0){ EtoO++; }else{ OtoE++; } } } cout << OtoE << endl; }
0
20,455,524
#include<bits/stdc++.h> using namespace std; #define all(a) (a).begin(),(a).end() typedef long long ll; const ll mod=1000000007; #define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i) int main() { int a,b,c,k;cin>>a>>b>>c>>k; int out; if(k<=a){ out =k; } else if(k<=a+b){ out = a; } else { out = 2*a + b - k; } cout << out << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const ll MOD = 1000000007; long long longpow(long long n, long long a, long long mod) { if (a == 0) return 1; if (a == 1) return n % mod; if (a % 2 == 1) return (n * longpow(n, a - 1, mod)) % mod; ll t = longpow(n, a / 2, mod) % mod; return (t * t) % mod; } int main() { int N; cin >> N; vector<ll> A(N + 2); REP(i, N + 1) cin >> A[i]; ll ans = 0; vector<ll> L(N + 2), R(N + 2); L[N] = A[N], R[N] = A[N]; for (int i = N - 1; i >= 0; i--) { L[i] = A[i] + (L[i + 1] + 1) / 2; R[i] = A[i] + R[i + 1]; } if (L[0] != 1) { cout << -1 << endl; return 0; } ll current = 1; REP(i, N + 1) { ans += current; current -= A[i]; current = min(current * 2, R[i + 1]); } cout << ans << endl; }
0
23,710,220
#include<bits/stdc++.h> using namespace std; #define int long long #define double long double #define pb push_back #define pob pop_back #define mp make_pair #define fi first #define se second #define endl '\n' #define Ptest(x) return cout << x << endl, 0; typedef vector <int> vi; typedef pair <int, int> ii; typedef vector <vi > vvi; typedef vector <ii > vii; const int N = 1e5 + 5, mod = 1e9 + 7, inf = 1e18 + 7; int n, m, sum, p, d, k; int a[N]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; m = (n * (n + 1)) / 2; for (int i = 0; i < n; i++){ cin >> a[i]; sum += a[i]; } if (sum % m){ Ptest("NO"); } k = sum / m; for (int i = 0; i < n; i++){ d = a[(i + 1) % n] - a[i]; if (k < d || (k - d) % n){ Ptest("NO"); } p += (k - d) / n; } if (k != p){ Ptest("NO"); } cout << "YES"; }
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) #define ll long long using namespace std; int main(){ string s;cin>>s; int result=0; int l=0, r = s.size()-1; while(r>l){ if(s[l]==s[r]){ l++; r--; continue; } if(s[l]!=s[r]){ if(s[l]=='x'){ l++; result++; }else if(s[r]=='x'){ r--; result++; }else{ cout<<-1<<endl;return 0; } } } cout<<result<<endl; return 0; }
0
75,267,392
#include <bits/stdc++.h> #ifdef LOCAL_DEBUG #define DEBUG 1 #define CERR if(DEBUG) cerr #define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME #define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl #define pr1(a) (#a)<<"="<<(a)<<" " #define pr2(a,b) pr1(a)<<pr1(b) #define pr3(a,b,c) pr1(a)<<pr2(b,c) #define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d) #define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e) #define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f) #define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g) #define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h) #define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i) #define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j) #define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;} #else #define DEBUG 0 #define pr(...) #define prArr(a) #endif using namespace std; using Int = long long; using _int = int; using ll = long long; using Double = long double; const Int INF = (1LL<<60)+1e9; const Int mod = (1e9)+7; const Double EPS = 1e-8; const Double PI = 6.0 * asin((Double)0.5); using P = pair<Int,Int>; template<class T> T Max(T &a,T b){return a=max(a,b);} template<class T> T Min(T &a,T b){return a=min(a,b);} template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";} template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";} template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;} template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;} template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;} Int solve(Int A, Int B){ if(A > B) swap(A, B); auto check=[&](Int x){ Int v = (x + 1 - A) / 2; Int mx = 0; for(Int i = v - 10; i < v + 10; i++){ Int a = A + i; Int b = (x - i + 1); if(!(A + 1 <= a && a <= A + x)) continue; if(!(1 <= b && b <= x)) continue; Max(mx, a * b); } return mx < A * B; }; Int L = 0, R = B; while(L + 1 < R){ Int M = (L + R) / 2; check(M)? (L=M):(R=M); } Int res = (A - 1) + L; return res; } signed main(){ srand((unsigned)time(NULL)); cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); Int Q; cin>>Q; while(Q--){ Int A, B; cin>>A>>B; Int ans = solve(A, B); cout<<ans<<endl; } return 0; }
#include "bits/stdc++.h" #include <unordered_set> #include <numeric> #define rep(i,n) for(int i = 0; i < n; i++) typedef long long ll; typedef unsigned long long ull; using namespace std; #define vll vector<vector<long long>> #define vl vector<long long> #define vi vector<int> #define vii vector<vector<int>> #define pb push_back #define pf push_front #define ld long double #define Sort(a) sort(a.begin(),a.end()) #define cSort(a,cmp) sort(a.begin(),a.end(),cmp) #define reSort(a) sort(a.rbegin(), a.rend()) static const ll llMAX = numeric_limits<long long>::max(); static const int intMAX = numeric_limits<int>::max(); static const ll llMIN = numeric_limits<long long>::min(); static const int intMIN = numeric_limits<int>::min(); static const ll d_5 = 100000; static const ll d9_7 = 1000000007; static const ll d_9 = 1000000000; static const double PI=3.14159265358979323846; template<class T> void Printvector(std::vector<T> a){ int size = a.size(); rep(i,size){ cout<<a[i]<<" "; } cout<<endl; } template<class T> void Printvector(std::vector<std::vector<T>> a){ int size = a.size(); rep(i,size){ int size2=a[i].size(); rep(j,size2){ cout<<a[i][j]<<" "; } cout<<endl; } cout<<endl; } set< ll > divisor(ll n) { set< ll > ret; for(ll i = 1; i * i <= n; i++) { if(n % i == 0) { ret.insert(i); if(i * i != n) ret.insert(n / i); } } return (ret); } template<class T> T digitpower(T a,T b){ int mode=1; if(b==1){ return a; }else if(b==0){ return 1; } if(b%2==1){ T tmp = digitpower(a,(b-1)/2); if(mode==0){ tmp%=d9_7; } tmp*=tmp; if(mode==0){ tmp%=d9_7; } tmp*=a; if(mode==0){ return (tmp)%d9_7; }else{ return tmp; } }else{ T tmp = digitpower(a,(b)/2); if(mode==0){ tmp%=d9_7; } tmp*=tmp; if(mode==0){ tmp%=d9_7; } if(mode==0){ return (tmp)%d9_7; }else{ return tmp; } } } vl facs(2000008,-1); ll Factrial(ll num){ if(facs[num]!=-1){ return facs[num]; } if(num==1||num<=0){ return 1; }else if(num<0){ return 1; }else{ facs[num]=(num*Factrial(num-1))%d9_7; return facs[num]; } } 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; } ll linercomb(ll n,ll k, ll mod){ if(n<k)return 0; if(n<0)return 0; ll ans=Factrial(n); ans*=modinv(Factrial(k),mod); ans%=mod; ll k1=Factrial(n-k); k1%=mod; ans*=modinv(k1,mod); ans%=mod; return ans; } ll Permatation(ll n,ll k){ if(n<k){ return 0; } return (Factrial(n)*modinv(Factrial(n-k),d9_7))%d9_7; } unordered_map<ll,ll> prime_factor(ll n) { unordered_map<ll,ll> ret; for(ll i = 2; i * i <= n; i++) { while(n % i == 0) { ret[i]++; n /= i; } } if(n != 1) ret[n] = 1; return ret; } template<class T> vector<T> getaccum(vector<T> a,int mode){ int size=a.size(); vector<T> ans(size); ans[0]=a[0]; for(int i=0;i<size-1;i++){ ans[i+1]=ans[i]+a[i+1]; if(mode==0){ ans[i+1]%=d9_7; } } return ans; } template<class T> T get_digisum(T n){ T ret=0; while(n>=1){ ret+=n%10; n/=10; } return ret; } template<class T> T getdigit(T num, T n){ T ans=0; while(num!=0){ ans++; num/=n; } return ans; } struct datas{ ull c; ull d; }; int main(void){ ull m; cin>>m; vector<datas> nums(m); rep(i,m){ cin>>nums[i].d>>nums[i].c; } ull ans=0; ull tmpsum=0; ull sumd=0; rep(i,m){ tmpsum+=nums[i].d*nums[i].c; sumd+=nums[i].c; } cout<<sumd-1+(tmpsum-1)/9<<endl; return 0; }
0
99,719,327
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i,N) for(int i = 0; i < (N); i++) #define erep(i,N) for(int i = N - 1; i >= 0; i--) const ll INF = 1000000000; const ll mod = 1000000007; #define PI 3.1415926535 using Graph = vector<vector<int>>; 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;} typedef pair<int, int> pair; bool seen[505][505]; int main(){ int N; cin >> N; int ans = 0; for (int i = 1; i <= N; i++) { if (i > 0 && i < 10) ans++; else if (i > 99 && i < 1000) ans++; else if (i > 9999 && i < 100000) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 1e9 + 7; ll fast_pow(ll a, ll b) { ll ans = 1; while(b) { if(b&1) ans = ans * a % M; b >>= 1; a = a * a % M; } return ans; } ll f(int n, int k, int x) { return fast_pow(k/x, n); } const int N = 2e5 + 7; ll F[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; ll ans = 0; for(int i = k; i >= 1; --i) { ll aux = 0; aux = f(n, k, i); for(int j = i + i; j <= k; j += i) { aux = (aux - F[j] + M)%M; } ans += aux * i % M; ans %= M; F[i] = aux; } cout << ans << '\n'; }
0
93,687,984
#include <iostream> using namespace std; int main(){ int n,k; cin >> n >> k; int c = 1; int i; for(i=0;i<n;i++){ if(c<=k) c*=2; else c+=k; } cout << c << "\n"; return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <boost/sort/spreadsort/spreadsort.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/dijkstra_shortest_paths.hpp> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/tag_and_trait.hpp> #include <ext/pb_ds/trie_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property, boost::property<boost::edge_weight_t, int> > Graph; #define rep(i,n) for(int i=0;i<(n);++i) #define reps(i,n) for(int i=1;i<=(n);++i) #define all(x) (x).begin(),(x).end() #define Fixed fixed << setprecision(12) #define bsort boost::sort::spreadsort::spreadsort #define int int_fast64_t using pii = pair<int,int>; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int mod1 = 1e9+7; constexpr int mod2 = 998244353; template <class Func> class FixPoint : Func { public: explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {} template <class... Args> constexpr decltype(auto) operator()(Args&&... args) const { return Func::operator()(*this, std::forward<Args>(args)...); } }; template <class Func> static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept { return FixPoint<Func>{forward<Func>(f)}; } template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >; template <class T> using max_heap = priority_queue<T>; template <class A, class B> using umap = unordered_map<A,B>; template <typename T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename K, typename V> using Umap = gp_hash_table<K, V>; using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>; inline int square(int a){ return a * a;} inline int updiv(int a,int b){ return (a + b - 1) / b; } constexpr int dx[] = {1,0,-1,0,1,1,-1,-1}; constexpr int dy[] = {0,-1,0,1,1,-1,-1,1}; struct negrightshift { inline int operator() (const int &x, const unsigned offset) { return -(x >> offset); } }; signed main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; umap<string,int> mp; mp.reserve(n); int sum = 0; rep(i,n){ string s; cin >> s; bsort(all(s)); ++mp[s]; sum += mp[s]-1; } cout << sum << '\n'; return 0; }
0
46,255,283
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; using namespace std; const long long int INF = 1e18; const long long int mod = 1e9+7; typedef pair<ll, ll> pairs; typedef vector<pairs> p; struct Edge{ ll to, weight; Edge(ll t, ll w) : to(t), weight(w){} }; using graph = vector<vector<ll>>; using Graph = vector<vector<Edge>>; ll gcd(ll a,ll b){ if(b == 0){ return a; }else{ return gcd(b, a%b); } } ll lcm(ll a, ll b){ return a / gcd(a, b) * b; } ll keta(ll N){ int tmp{}; while( N > 0 ){ tmp += ( N % 10 ); N /= 10; } N = tmp; return N; } bool kai(string S){ bool flag = true; for(ll i=0;i<S.size()/2;++i){ if(S[i] != S[S.size()-i-1]){ flag = false; break; } } return flag; } int main(){ ll a, b, c, k; cin>>a>>b>>c>>k; ll ans = a - b; if(k % 2 == 1){ ans *= -1; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std ; #define pb(n) push_back(n) #define fi first #define se second #define all(r) begin(r),end(r) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout<<#x<<": "<<x<<endl #define fcout(n) cout<<fixed<<setprecision((n)) #define scout(n) cout<<setw(n) #define vary(type,name,size,init) vector< type> name(size,init) #define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init)) #define mp(a,b) make_pair(a,b) #define rep(i,n) for(int i = 0; i < (int)(n);++i) #define REP(i,a,b) for(int i = (a);i < (int)(b);++i) #define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it) #define repa(n,array) for(auto &n :(array)) using ll = long long; using pii = pair<int,int> ; using pll = pair<ll,ll> ; template<typename T> void O(T t){ cout << t << endl; } const ll mod = 1e9+7; constexpr ll inf = ((1<<30)-1)*2+1 ; constexpr double PI = acos(-1.0) ; double eps = 1e-10 ; const int dy[] = {-1,0,1,0,1,-1,1,-1}; const int dx[] = {0,-1,0,1,1,-1,-1,1}; inline bool value(int x,int y,int w,int h){ return (x >= 0 && x < w && y >= 0 && y < h); } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; while(cin >> n,n){ vector<pair<string,string>> s(n); rep(i,n){ cin >> s[i].fi >> s[i].se; } int c = 1; sort(all(s)); vector<string> t; t.push_back(s[0].se); rep(i,n-1){ bool f = false; rep(j,t.size()){ if(s[i+1].fi >= t[j]){ f = true; t[j] = s[i+1].se; break; } } if(!f){ ++c; t.push_back(s[i+1].se); } } std::cout << c << std::endl; } return 0; }
0
68,631,769
#include<bits/stdc++.h> using namespace std; #define MOD 1000000007 #define INF 1000000010 #define EPS 1e-9 #define fst first #define scd second #define debug(x) cout<<x<<endl; #define repi(i,x,n) for(int i=x;i<n;i++) #define rep(i,n) repi(i,0,n) #define lp(i,n) repi(i,0,n) #define repn(i,n) for(int i=n;i>=0;i--) #define int long long #define endl "\n" signed main(){ cin.tie(0); ios::sync_with_stdio(false); string s; cin>>s; if(s.substr(0,4)=="YAKI") cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define st first #define nd second typedef pair < int , int > pp; const int mod = 1e9 + 7; const int N = 2e5 + 5; vector < pp > V[N]; int T[N],H[N],n,m,i,x,y,z; void f(int x){ H[x] = 1; for(int y, i=0; i<V[x].size(); i++){ if(!H[ y = V[x][i].st ]){ T[y] = T[x] + V[x][i].nd; f(y); } else if(T[y] != T[x] + V[x][i].nd){ puts("No"); exit(0); } } } signed main(){ scanf("%d%d",&n,&m); for(; m-- ;){ scanf("%d%d%d",&x,&y,&z); V[x].pb(mp(y,z)); V[y].pb(mp(x,-z)); } for(i=1;i<=n;i++){ if(H[i]) continue; f(i); } puts("Yes"); return 0; }
0
30,642,126
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i ++) using namespace std; using ll = long long; using PL = pair<ll,ll>; using P = pair<int,int>; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; int main() { int a,b; cin >> a >> b; int ans = (a + b + 1)/2; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef vector<ll> V; typedef complex<double> Point; #define PI acos(-1.0) #define EPS 1e-10 const ll INF = 1e16; const ll MOD = 1e9 + 7; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define rep(i,N) for(int i=0;i<(N);i++) #define ALL(s) (s).begin(),(s).end() #define EQ(a,b) (abs((a)-(b))<EPS) #define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) ) #define fi first #define se second #define N_SIZE (1LL << 20) #define NIL -1 ll sq(ll num) { return num*num; } ll mod_pow(ll x, ll n) { if (n == 0)return 1; if (n == 1)return x%MOD; ll res = sq(mod_pow(x, n / 2)); res %= MOD; if (n % 2 == 1) { res *= x; res %= MOD; } return res; } ll mod_add(ll a, ll b) { return (a + b) % MOD; } ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; } ll mod_mul(ll a, ll b) { return a*b % MOD; } ll n; int main(){ while(cin >> n && n){ vector<ll> v(n); rep(i,n)cin >> v[i]; sort(ALL(v)); ll ans = 0; FOR(i,1,n-1)ans += v[i]; cout << ans / (n-2) << endl; } }
0
98,708,211
#include <iostream> #include <string> #include <algorithm> #include <cmath> #include <deque> #include <queue> #include <stack> #include <vector> #include <utility> #include <iomanip> #include <bitset> #include <set> #include <map> #include <stdio.h> #include <numeric> #include <cstring> #define rep(i,n) for (int i = 0; i < (n); i++) #define rep1(i,n) for (int i = 1; i < (n); i++) #define FOR(i,a,b) for (int i=(a); i < (b); i++) #define MOD 1000000007 using namespace std; using ll = long long; using PII = pair<int, int>; using PLL = pair<ll, ll>; const int INF = numeric_limits<int>::max(); const ll INFL = numeric_limits<ll>::max(); long long mod(long long val, long long m) { long long res = val % m; if (res < 0) res += m; return res; } long long gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } long long lcm(ll a, ll b) { return a / gcd(a, b) * b ; } ll factorial(ll n) { ll res = 1; for (ll i = 1; i <= n; i++) { res *= i; } return res; } int main() { int n; cin >> n; string s, t; cin >> s >> t; rep(i,n) cout << s[i] << t[i]; cout << endl; return 0; }
#include<iostream> #include<vector> using namespace std; const long long MOD = 1000000007LL; int main() { long long n, k; cin >> n >> k; vector<long long> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } long long ans = 0; for (int i = n-1; i >= 0; --i) { long long num = 0; for (int j = n-1; j > i; --j) { if (a[i] > a[j]) { ++num; } } ans = (ans + num * k) % MOD; } const long long p = (k-1) * k / 2 % MOD; for (int i = 0; i < n; ++i) { long long num = 0; for (int j = 0; j < n; ++j) { if (a[i] > a[j]) { ++num; } } ans = (ans + num * p) % MOD; } cout << ans << endl; return 0; }
0
21,435,904
#define _GIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; using P = pair<int, int>; const double EPS = 1e-10; int main(void) { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A[i]; ll num = 0; map<int, int> m; rep(i, N) { m[A[i]]++; } for (auto itr = m.begin(); itr != m.end(); ++itr) { num += (ll) itr->second * (itr->second - 1) / 2; } ll before, after; rep(i, N) { ll val = m[A[i]]; before = val * (val - 1) / 2; after = (val - 1) * (val - 2) / 2; cout << num + after - before << endl; } return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define deb(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define deb(x...) #endif typedef long long int ll; typedef pair<int,int> pi; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; #define ff first #define ss second #define pb push_back #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define all(x) (x).begin(), (x).end() #define ps(x,y) fixed<<setprecision(y)<<x #define rep(i,a,b) for(ll i=a ; i<b ; ++i) const ll MOD = 1e9 + 7; const ll INF = 1e18; const ll maxn = 1e6 + 4; void solve(){ ll ans=INF; ll n,m; cin >> n >> m; ans = min({ans,((n+2)/3 - n/3)*m,((m+2)/3 - m/3)*n}); for(ll i=1;i<=n-1;i++){ ans = min(ans,max({i*m,(n-i)*(m/2),(n-i)*((m+1)/2)})-min({i*m,(n-i)*(m/2),(n-i)*((m+1)/2)})); } swap(n,m); for(ll i=1;i<=n-1;i++){ ans = min(ans,max({i*m,(n-i)*(m/2),(n-i)*((m+1)/2)})-min({i*m,(n-i)*(m/2),(n-i)*((m+1)/2)})); } cout << ans; } int main(){ IOS solve(); }
0
100,129,762
#include <bits/stdc++.h> using namespace std; #define int 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; } const int MAX =1002; const int MOD =1000000007; signed main(){ int n,y; cin>>n>>y;y/=1000; for(int i=0;i<=n;i++)for(int j=0;j+i<=n;j++)if(i+5*j+10*(n-i-j)==y){ cout<<n-i-j<<' '<<j<<' '<<i<<endl; return 0; } cout<<-1<<' '<<-1<<' '<<-1<<endl; }
#include <bits/stdc++.h> using namespace std; #define all(a)a.begin(),a.end() using ll=long long; const int INF = 1<<30; const ll INFll =1LL<<62; const int mod = int(1e9)+7; using V = vector<ll>; using P = pair<ll,ll>; int main(){ ll n,m;cin >>n>>m; vector<ll>co(n,0); for (int i = 0; i < m; ++i) { ll a,b;cin >>a>>b; a--;b--; co[a]++;co[b]++; } bool flg=true; for (int i = 0; i < n; ++i) { if(co[i]%2==1)flg=false; } if(flg)puts("YES"); else puts("NO"); return 0; }
0
14,917,059
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(var) cerr << (#var) << " = " << (var) << endl; #else #define debug(var) #endif void init() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void solve() { int n; cin >> n; int ans = 0; int a = 0, b = 0, ba = 0; for (int i = 0; i < n; ++i) { string s; cin >> s; for (int j = 0; j < (int)s.size(); ++j) { if (s[j] == 'A' && s[j+1] == 'B') ++ans; } if (s[0] == 'B' && s.back() == 'A') ++ba; else if (s[0] == 'B') ++b; else if (s.back() == 'A') ++a; } ans += max(ba-1, 0); if (ba && a) { --a; ++ans; } if (ba && b) { --b; ++ans; } ans += max(min(a, b), 0); printf("%d", ans); } int main() { init(); int t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T& value, Ts&... args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T& value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T& value, const Ts&... args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; int main() { in(int, n); vector<int> target(3); rep(i, 3) cin >> target[i]; vector<int> l(n); rep(i, n) cin >> l[i]; vector<int> current(3); int ans = numeric_limits<int>::max(); function<void(int, int)> dfs = [&](int depth, int used_mp) { if (depth == n) { rep(i, 3) { if (current[i] == 0) return; used_mp += abs(target[i] - current[i]); } ans = min(ans, used_mp); return; } rep(i, 4) { int mp = 0; if (i < 3) { if (current[i] != 0) { mp += 10; } current[i] += l[depth]; } dfs(depth + 1, used_mp + mp); if (i < 3) { current[i] -= l[depth]; } } }; dfs(0, 0); out(ans); }
0
32,656,727
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int main(){ double a,b,c,cr,S,L,h; cin >> a >> b >> c; cr = c*3.1415926535/180; h = b*sin(cr); S = a/2.0*b*sin(cr); L = a+b+sqrt(a*a+b*b-2.0*a*b*cos(cr)); printf("%f\n",S); printf("%f\n",L); printf("%f\n",h); return 0; }
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<deque> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf=1e9+7; const ll INF=1LL<<60 ; const ll mod=1e9+7 ; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(),c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; 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; } void solve() { int n, m, X, Y; cin >> n >> m >> X >> Y; vector<int> x(n), y(m); rep(i, n) { cin >> x[i]; } rep(i, m) { cin >> y[i]; } for(int Z = X + 1; Z <= Y; ++ Z) { bool flag = 1; rep(i, n) { if(x[i] >= Z) flag = 0; } rep(i, m) { if(y[i] < Z) flag = 0; } if(flag) { cout << "No War" << endl; return; } } cout << "War" << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
0
16,926,512
#include<iostream> #include<algorithm> #include<vector> #include<numeric> #include<string> #include<cmath> #include<set> #include<queue> #include<deque> #include<bitset> #include<iomanip> #include<cctype> #include<map> #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++) #define all(x) (x).begin(),(x).end() using namespace std; const int inf = 1001001000; const long long int Inf = 1001001001001001000; void print(vector<vector<int>> a){ for (int i = 0; i < a.size(); i++) { for (int j=0;j<a[i].size();j++){ cout << a[i][j] << " "; } cout << endl; } } void print(vector<vector<long long int>> a){ for (int i=0;i<a.size();i++){ for (int j=0;j<a[i].size();j++){ cout << a[i][j] << " "; } cout << endl; } } void print(vector<int> a){ int n = a.size(); for (int j=0;j<n;j++) { if (j != n-1) cout << a[j] << " "; else cout << a[j] << endl; } } void print(set<int> a){ for (auto x:a) cout << x << " "; cout << endl; } int main() { long long int n, d, a; cin >> n >> d >> a; vector<pair<long long int, long long int>> enemy(n); rep(i,n){ long long int x, y; cin >> x >> y; enemy[i] = pair<long long int, long long int>(x, y); } sort(all(enemy)); d = d * 2; queue<pair<long long int,long long int>> ruiseki_damage; long long int ruiseki = 0; long long int ans = 0; rep(i, n) { long long int x = enemy[i].first; long long int h = enemy[i].second; while(!ruiseki_damage.empty() && ruiseki_damage.front().first < x){ ruiseki -= ruiseki_damage.front().second; ruiseki_damage.pop(); } h -= ruiseki; if (h > 0){ long long int t = (h + a - 1) / a; ans += t; long long int damage = t * a; ruiseki += damage; ruiseki_damage.push(pair<long long int, long long int>(x + d, damage)); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; using graph = vector<vector<ll>>; const ll nmax = 100001; ll n, m; ll notop[nmax]; ll h[nmax]; bool dfs(ll v, const graph &G){ for(auto nv : G[v]){ if(h[v]<=h[nv]){ notop[v]++; return false; } } return true; } int main(){ cin >> n >> m; for(ll i=0; i<n; ++i){cin >> h[i];} graph g(n); for(ll i=0; i<m; ++i){ ll a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } memset(notop, 0, sizeof(notop)); ll res = 0; for(ll i=0; i<n; ++i){ if(notop[i]!=0){continue;} if(dfs(i, g)){ res++; } } cout << res << endl; return 0; }
0
40,045,046
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { if(v.size() >= 200) { return "Too big container"; } bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define rep(i,n) for (int i = 0; i < n; ++i) #define per(i,n) for (int i = n - 1; i >= 0; --i) #define rep1(i,n) for (int i = 1; i <= n; ++i) #define reps(i,s,n) for (int i = s; i < n; ++i) #define all(c) begin(c),end(c) template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; typedef long double ld; typedef pair<int,int> PINT; typedef pair<ll,ll> PLL; const long long MOD = 1e9+7; #define precout() cout << std::fixed << std::setprecision(20); #define print(a) cout << a << endl; const int INFI = (1 << 30) - 1; const long long INFLL = (1LL << 62) - 1; template<typename T> void printv(vector<T>&v) { int n = v.size() - 1; rep(i, n) cout << v[i] << " "; cout << v.back() << endl; } const int dy[4] = { 0, 1, 0, -1 }; const int dx[4] = { 1, 0, -1, 0 }; double deg2rad(double deg) { return deg * M_PI / 180; } double rad2deg(double rad) { return rad * 180 / M_PI; } ll repeat_squaring(ll N, ll P) { if(P == 0) return 1; if(P % 2 == 0) { ll t = repeat_squaring(N, P / 2); return t * t; } return N * repeat_squaring(N, P - 1); } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> dp(N + 1, 0); rep(i, N + 1) dp[i] = i; for(int i = 1; i <= N; ++i) { ll six = repeat_squaring(6, i); if(six > N) break; for(int i = 0; i + six <= N; ++i) { chmin(dp[i + six], dp[i] + 1); } ll nine = repeat_squaring(9, i); for(int i = 0; i + nine <= N; ++i) { chmin(dp[i + nine], dp[i] + 1); } } print(dp[N]); }
#include <bits/stdc++.h> #define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) using namespace std; #define ll long long #define ull unsigned long long #define fori(i,n) for (int i=0; i<int(n);i++) #define srt(v) sort(v.begin(), v.end()) #define MOD 1000000007 const int INF = 1e9; const double PI = 3.14159265358979323846; ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ll spow(ll base, ll exp){ ll ans = 1; for(ll i=0;i<exp;i++) ans = ans * base % MOD; return ans; } ll divide(ll a, ll b){ return a * spow(b, MOD-2) % MOD; } template<typename T> void print(const T &x){cout<<x<<endl;} template<typename T=int> vector<T> read(size_t n){ vector<T> arr(n); for(size_t i=0;i<n;i++) cin>>arr[i]; return arr; } void solve(){ } int main(){ int n; cin >> n; auto v = read(n); int result = v[0]; int maxNum = v[0]; for(int x : v){ result = __gcd(result, x); maxNum = max(maxNum, x); } if (result != 1){ print("not coprime\n"); return 0; } vector<int> prime(maxNum + 1, 0); for(int i=2; i<=maxNum; i++){ if(prime[i]) continue; for(int j=i; j<=maxNum; j+=i){ prime[j] = i; } } unordered_map<int, int> m; for(int x : v){ int temp = x; while(temp != 1){ int p = prime[temp]; while(temp%p == 0){ temp /= p; } m[p]++; } } for(auto x : m){ if (x.second > 1){ print("setwise coprime\n"); return 0; } } print("pairwise coprime\n"); }
0
5,042,061
#include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> #include<functional> #include<vector> #include<queue> using namespace std; #define f(i,n) for(int i=0;i<(int)n;i++) #define MOD 1000000009 int main(void){ char a[201]; f(i, 201)a[i] = 0; int k, s; int n, m; int x, y, z; int ans = 0; for (;;){ scanf("%s", a); if (a[0] == '-')return 0; m = strlen(a); scanf("%d", &n); s = 0; f(i, n){ scanf("%d", &x); s += x; } s = s%m; for (int i = s; i < m; i++)printf("%c", a[i]); for (int i = 0; i < s; i++)printf("%c", a[i]); printf("\n"); } return 0; }
#include <vector> #include <iostream> #include <algorithm> #include <functional> #include <string> #include <limits.h> #include <cmath> #include <queue> #include <map> #include <iomanip> #include <random> #include <fstream> #include <cassert> #define rep(i, n) for (int i = 0; i < n; i++) #define PI 3.14159265358979323846 #define MOD 1000000007 #define vi vector<int> using namespace std; using ll = long long; const int MAX = 1000000; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll gcd(ll a, ll b) { ll r; while ((r = a % b)) { a = b; b = r; } return b; } template <class T> struct cord{ T x,y; }; template <class T> double dist(cord<T> a, cord<T> b){ T dx=a.x-b.x; T dy=a.y-b.y; return sqrt(dx*dx+dy*dy); } struct s{ int p,i,r; }; bool cmpP(const s &a, const s &b){ return a.p > b.p; } bool cmpI(const s &a, const s &b){ return a.i < b.i; } int n,m,d[10010],p[10010]; int solve() { int answer=0; vector< pair<int,int> > pd(n); rep(i,n){ cin >> pd[i].second >> pd[i].first; } sort(begin(pd),end(pd)); reverse(begin(pd),end(pd)); int sum=0; int index=n; rep(i,n){ sum += pd[i].second; if (sum > m){ index=i; break; } } rep(i,index){ pd[i].second = 0; } if (index != n){pd[index].second = sum - m;} rep(i,n){ answer += pd[i].first * pd[i].second; } return answer; } int main() { while (cin >> n >> m && n > 0){ cout << solve() << endl; } return 0; }
0
46,011,658
#include <bits/stdc++.h> #define ll long long #define PI 3.14159265358979323846 using namespace std; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int a,b,k; cin>>k>>a>>b; for(int i=a;i<=b;i++){ if((i%k)==0) return cout << "OK" << endl,0; } cout << "NG" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 51; int mp[MAX_N][MAX_N]; ll X[MAX_N], Y[MAX_N]; pair<ll, ll> dot[MAX_N]; int N, K; int minmp(int i, int j) { if(i >= 0 && j >= 0) return mp[i][j]; else return 0; } int main() { cin >> N >> K; for(int i = 0; i < N; ++i) { cin >> dot[i].first >> dot[i].second; X[i] = dot[i].first, Y[i] = dot[i].second; } sort(X, X + N); sort(Y, Y + N); for(int i = 0; i < N; ++i) { int nx = lower_bound(X, X + N, dot[i].first) - X; int ny = lower_bound(Y, Y + N, dot[i].second) - Y; ++mp[nx][ny]; } for(int i = 0; i < N; ++i) { for(int j = 1; j < N; ++j) mp[i][j] += mp[i][j-1]; } for(int i = 1; i < N; ++i) { for(int j = 0; j < N; ++j) mp[i][j] += mp[i-1][j]; } ll res = LLONG_MAX; for(int i = 0; i < N; ++i) { for(int j = 0; j < N; ++j) { for(int k = i + 1; k < N; ++k) { for(int l = j + 1; l < N; ++l) { int num = minmp(k, l) - minmp(i-1, l)- minmp(k, j-1) + minmp(i-1, j-1); if(num >= K) { ll S = 1LL * (X[k] - X[i]) * (Y[l] - Y[j]); res = min(res, S); } } } } } cout << res << endl; return 0; }
0
18,254,519
#include <bits/stdc++.h> using ll = long long; #define FOR(i, k, n) for(ll i = (k); i < (n); i++) #define FORe(i, k, n) for(ll i = (k); i <= (n); i++) #define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--) #define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--) #define REP(i, n) FOR(i, 0, n) #define REPr(i, n) FORre(i, n, 0) #define ALL(x) (x).begin(), (x).end() #define ALLr(x) (x).rbegin(), (x).rend() #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; const int INF = 1001001001; int main(void){ int a, b; cin >> a >> b; if((a+b)%3 == 0 || a%3 == 0 || b%3 == 0) cout << "Possible" << endl; else cout << "Impossible" << endl; return 0; }
#include <bits/stdc++.h> #define rep(l, r) for (int i = (l); i < (r); i++) typedef long long ll; using namespace std; int main() { char b; cin >> b; switch (b) { case 'A': cout << 'T'; break; case 'C': cout << 'G'; break; case 'G': cout << 'C'; break; case 'T': cout << 'A'; break; } cout << endl; return 0; }
0
5,682,557
#include <bits/stdc++.h> using namespace std; int main() { int K, X; cin >> K >> X; if (K * 500 < X){ cout << "No"; } else{ cout << "Yes"; } return 0; }
#include <bits/stdc++.h> using namespace std; # define REP(i,n) for (int i=0;i<(n);++i) # define rep(i,a,b) for(int i=a;i<(b);++i) # define p(s) std::cout << s ; # define pl(s) std::cout << s << endl; # define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl; # define YES(j) cout << (j ? "YES" : "NO") << endl; # define Yes(j) std::cout << (j ? "Yes" : "No") << endl; # define yes(j) std::cout << (j ? "yes" : "no") << endl; # define all(v) v.begin(),v.end() # define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("") 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;} typedef long long int ll; typedef pair<ll,ll> P_ii; typedef pair<double,double> P_dd; template<class T> vector<T> make_vec(size_t a){ return vector<T>(a); } template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){ return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;} template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); } const int MOD = 1000000007; const int inf=1e9+7; const ll longinf=1LL<<60 ; void addM(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; } void mulM(long long &a, long long b) { a = ((a%MOD)*(b%MOD))%MOD ; } const int MAX = 510000; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(ll n, ll k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { int N; cin >> N; vector<pair<int,int>> a(N); int max_a = -1; REP(i,N){ cin >> a[i].second; chmax(max_a,a[i].second); } REP(i,N){ a[i].first = min(max_a-a[i].second,a[i].second); a[i].second *= -1; } sort(all(a),greater<>()); cout << max_a << " " << a[0].second*-1 << endl; return 0; }
0
96,286,795
#include <bits/stdc++.h> using namespace std; # define C continue; # define R return # define D double # define I insert # define ll long long # define ld long double # define ull unsigned long long # define ui unsigned int # define pb push_back # define pf push_front # define vi vector < int > # define vc vector < char > # define vs vector < string > # define vb vector < bool > # define vd vector < D > # define vll vector < ll > # define vull vector < ull > # define vld vector < ld > # define PQ priority_queue # define vvi vector < vector < int > > # define vvb vector < vector < bool > > # define vvc vector < vector < char > > # define vvs vector < vs > # define vvll vector < vector < ll > > # define vvd vector < vector < D > > # define vvld vector < vector < ld > > # define all(v) (v).begin() , (v).end() # define allrev(v) (v).rbegin() , (v).rend() # define allcomp(v) v.begin() , v.end() , comp # define allrevcomp(v) v.rbegin() , v.rend() , comp # define pii pair < int , int > # define pll pair < ll , ll > # define pld pair < ld , ld > # define pDD pair < D , D > # define vpld vector < pld > # define vpii vector < pii > # define vpll vector < pll > # define vpDD vector < pDD > # define vvpii vector < vector < pii > > # define F first # define S second # define mp make_pair # define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b)) # define pp(n) printf("%.10Lf",n); # define line cout<<"\n"; # define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0); # define fr(a,b) for(int i = a; i < b; i++) # define rep(i,a,b) for(int i = a; i < b; i++) string vow = "aeiou"; int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; const int dx[] = { -1 , 0 , 1 , 0 } ; const int dy[] = { 0 , 1 , 0 , -1 } ; const ld pie = 3.1415926535897932384626 ; const ll mod = 1e9 + 7 ; void solve(){ int n,k; cin>>n>>k; ll ans = 1; ans = k*(pow(k-1,n-1)); cout << ans;line return; } int main(){ fast int t=1; while(t--){ solve(); } R 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; using pii = pair<int, int>; using pll = pair<ll, ll>; #define rep(i, N) for (ll i = 0; i < (N); i++) #define For(i, a, b) for (ll i = (a); i < (b); i++) #define all(A) (A).begin(), (A).end() const ll MOD = 1000000007; ll modpow(ll n, ll r) { ll p = n; ll ret = 1; while (r > 0) { if (r & 1) ret = (ret * p) % MOD; p = (p * p) % MOD; r >>= 1; } return ret; } int main(){ ll ans = 0; ll N, K; cin >> N >> K; ll lst[K + 1]; rep(i, K + 1) lst[i] = 0; for (ll k = K; k > 0; --k) { ll a = K / k; ll tmp = modpow(a, N); for (ll j = k; j <= K; j += k) { tmp = (MOD + tmp - lst[j]) % MOD; } ans = (ans + k * tmp) % MOD; lst[k] = tmp; } cout << ans << endl; return 0; }
0
100,231,814
#include <iostream> #include <iomanip> #include <cassert> #include <cstring> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <limits> #include <queue> #include <unordered_map> #include <list> #include <set> using namespace std; using ll = long long; #define rep_init(i, init, n) for(int i = (init); i < (n); ++i) #define rep(i, n) rep_init(i, 0, n) int main() { string S; ll K; cin >> S >> K; char ans = '1'; for (int i = 0; i < S.size() && i < K; ++i) { if (S[i] != '1') { ans = S[i]; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i=0; i<(int)(n); i++) #define all(x) x.begin(), x.end() #define mod 1000000007 typedef long long ll; int main(){ int h, w; cin >> h >> w; vector<string> mp; rep(i, h){ string str; cin >> str; mp.push_back(str); } vector<vector<int>> row(h, vector<int>(w, 0)); vector<vector<int>> col(h, vector<int>(w, 0)); bool light = false; int cnt = 0; rep(i, h){ light = false; cnt = 0; rep(j, w){ if(mp[i][j] == '.'){ if(light){ cnt++; }else{ light = true; cnt = 1; } }else{ if(light){ light = false; for(int k=1; k<=cnt; k++) row[i][j-k] = cnt; } } } if(light){ light = false; for(int k=1; k<=cnt; k++) row[i][w-k] = cnt; } } light = false; cnt = 0; rep(j, w){ light = false; cnt = 0; rep(i, h){ if(mp[i][j] == '.'){ if(light){ cnt++; }else{ light = true; cnt = 1; } }else{ if(light){ light = false; for(int k=1; k<=cnt; k++) col[i-k][j] = cnt; } } } if(light){ light = false; for(int k=1; k<=cnt; k++) col[h-k][j] = cnt; } } int biggest = 0; rep(i, h) rep(j, w) biggest = max(biggest, row[i][j]+col[i][j]-1); cout << biggest << endl; return 0; }
0
77,710,674
#include <bits/stdc++.h> using namespace std; #define ll long long const int MOD=1e9+7; const long double Pi=acos(-1); int main(){ ll dp[100020]; ll x; cin>>x; dp[0]=1; for(ll i=100;i<=x;i++){ if(dp[i]==0 && dp[max((ll)0,i-100)]==1)dp[i]=dp[max((ll)0,i-100)]; if(dp[i]==0 && dp[max((ll)0,i-101)]==1)dp[i]=dp[max((ll)0,i-101)]; if(dp[i]==0 && dp[max((ll)0,i-102)]==1)dp[i]=dp[max((ll)0,i-102)]; if(dp[i]==0 && dp[max((ll)0,i-103)]==1)dp[i]=dp[max((ll)0,i-103)]; if(dp[i]==0 && dp[max((ll)0,i-104)]==1)dp[i]=dp[max((ll)0,i-104)]; if(dp[i]==0 && dp[max((ll)0,i-105)]==1)dp[i]=dp[max((ll)0,i-105)]; } cout<<dp[x]<<endl; }
#include<bits/stdc++.h> using namespace std; int main() { int H, W; cin >> H >> W; vector<vector<int>> grid(H, vector<int> (W, -1)); queue<pair<int, int>> black; for(int i = 0; i < H; i++) { for(int j = 0; j < W; j++) { char c; cin >> c; if(c == '#') { grid.at(i).at(j) = 0; black.push(make_pair(i, j)); } } } vector<int> dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0}; while(!black.empty()) { auto st = black.front(); black.pop(); for(int i = 0; i < 4; i++) { int px = st.first + dx.at(i); int py = st.second + dy.at(i); if(px >= 0 && px < H && py >= 0 && py < W) { if(grid.at(px).at(py) == -1) { grid.at(px).at(py) = grid.at(st.first).at(st.second) + 1; black.push(make_pair(px, py)); } } } } int count = 0; for(int i = 0; i < H; i++) { for(int j = 0; j < W; j++) { count = max(count, grid.at(i).at(j)); } } cout << count << endl; }
0
87,784,125
#include <iostream> using namespace std; int F[50]; int main() { int n; cin >> n; F[0] = 1; F[1] = 1; for (int i = 2; i < 45; i++) { F[i] = F[i-1] + F[i-2]; } cout << F[n] << '\n'; }
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin >> n >> m; vector<string>data_a(n); vector<string>data_b(m); for(int i=0;i<n;i++){ cin >> data_a.at(i); } for(int i=0;i<m;i++){ cin >> data_b.at(i); } bool exist=false; for(int li=0;li<n;li++){ for(int lj=0;lj<n;lj++){ if(li+m-1>=n||lj+m-1>=n){ continue; } bool judge=true; for(int i=0;i<m;i++){ for(int j=0;j<m;j++){ if(data_a.at(li+i).at(lj+j)!=data_b.at(i).at(j)){ judge=false; } } } if(judge){ exist=true; } } } if(exist){ cout << "Yes" << endl; } else{ cout << "No" << endl; } }
0
3,450,024
#include<stdio.h> int main(){ int C=0; for(int i=1;i<1000;i++) {if(i%3==0)C+=200;else C+=195;} int n,y,m,d; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d%d",&y,&m,&d); if(y==0&&m==0&&d==0)break; int c=0; for(int i=1;i<y;i++) {if(i%3==0)c+=200;else c+=195;} for(int i=1;i<m;i++){ if(y%3==0)c+=20; else if(i%2==0)c+=19; else c+=20; } c+=d; int s=C-c+1; printf("%d\n",s); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; if (k == 1||k == 2||k == 3||k == 5||k == 7||k == 11||k == 13||k == 15||k == 17||k == 19||k == 23||k == 29||k == 31){ cout << 1 << endl; } else if (k == 28||k == 30){ cout << 4 << endl; } else if (k == 8||k == 12||k == 18||k == 20||k == 27){ cout << 5 << endl; } else if (k == 16){ cout << 14 << endl; } else if (k == 24){ cout << 15 << endl; } else if (k == 32){ cout << 51 << endl; } else { cout << 2 << endl; } }
0
65,483,124
#include <iostream> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main(void) { ios::sync_with_stdio(false); string S; cin >> S; int N = S.size(); string T; for (int i = 0; i < N; i += 2) { T += S[i]; } cout << T << endl; return 0; }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define fi first #define se second #define debug(x) cout << #x << ": " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> void Print(vector<T> v) { F0R(i, v.size()) { cout << v[i] << ' '; } cout << newl; } #if 1 signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; int result = 0, n = 0, ph = 0; F0R(i, N) { int h; cin >> h; if (h <= ph) { n++; } else { chmax(result, n); n = 0; } ph = h; } chmax(result, n); cout << result; } #endif
0
32,042,573
#include <bits/stdc++.h> #include<cstring> using namespace std; int main() { int i,k=0; string s,t; cin>>s>>t; for(i=0;i<s.size();i++) { if(s[i]!=t[i]) k++; } if(k>0) cout<<"No"<<endl; else cout<<"Yes"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n; vector<int> G[maxn]; int main() { scanf("%d", &n); for (int i = 1, u, v; i < n; i++) { scanf("%d %d", &u, &v); G[u].push_back(v), G[v].push_back(u); } function<int(int, int)> solve = [&](int v, int fa) { int s = 0; for (int u : G[v]) if (u ^ fa) { s += solve(u, v); } return s >= 2 ? s : s ^ 1; }; printf("%s\n", solve(1, 0) ? "First" : "Second"); return 0; }
0
62,833,331
#include<iostream> #include<algorithm> using namespace std; pair<int,int> A[100005]; long long Fr[100005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i=1; i<=n; i++) { cin>>A[i].first; A[i].second=i; } sort(A+1,A+n+1); int ind=n+1; for(int i=n; i>=1; i--) { ind=min(ind,A[i].second); Fr[ind]=Fr[ind]+1LL*(n-i+1)*(A[i].first-A[i-1].first); } for(int i=1; i<=n; i++) cout<<Fr[i]<<"\n"; return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define pb push_back #define str to_string #define endl "\n" #define PI 3.141592653589 using namespace std; using lint = long long; template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;} int main(){ int n,tmp,rem=-1,ans=0;cin>>n; for(int i=0;i<n;i++){ cin>>tmp; if(tmp==rem){ ans++; rem=-1; } else rem=tmp; } cout<<ans<<endl; }
0
89,480,548
#include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <stack> #include <queue> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <random> #include <chrono> #include <utility> #include <numeric> #include <cstdlib> #include <cstring> #include <climits> #include <sstream> #include <assert.h> #include <iostream> #include <iomanip> #include <algorithm> #include <unordered_map> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(bool x) {cerr << (x ? "true" : "false");} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef HOME #warning CHECK int:ll::INT_MAX:LLONG_MAX #define maxn 20 #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define maxn 2000006 #define gcd __gcd #define debug(x...) #endif #define ff first #define endl '\n' #define ss second #define inf 0x3f3f3f3f #define MOD 1000000007 #define PI 3.14159265358979323846264338327950L #define f(i,x,n) for(int i=x;i<=n;i++) #define fr(i,x,n) for(int i=x;i>=n;i--) struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _; int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1}; int dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; int main() { int k, x; cin >> k >> x; cout << ((500 * k >= x) ? "Yes" : "No"); return 0; }
#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 <functional> #include <ctime> #include <cmath> #include <limits> #include <numeric> #include <type_traits> #include <iomanip> #include <float.h> #include <math.h> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll ll_gcd(ll a, ll b) { if (a < b) return ll_gcd(b, a); ll r; while ((r = a % b)) { a = b; b = r; } return b; } struct UnionFind { vector <ll> par; vector <ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } vector<int> tpsort(vector<vector<int>>& G) { int V = G.size(); vector<int> sorted_vertices; queue<int> que; vector<int> indegree(V); for (int i = 0; i < V; i++) { for (int j = 0; j < G[i].size(); j++) { indegree[G[i][j]]++; } } for (int i = 0; i < V; i++) { if (indegree[i] == 0) { que.push(i); } } while (que.empty() == false) { int v = que.front(); que.pop(); for (int i = 0; i < G[v].size(); i++) { int u = G[v][i]; indegree[u] -= 1; if (indegree[u] == 0) que.push(u); } sorted_vertices.push_back(v); } return sorted_vertices; } struct Point { double x; double y; }; struct LineSegment { Point start; Point end; }; double tenkyori(const LineSegment& line, const Point& point) { double x0 = point.x, y0 = point.y; double x1 = line.start.x, y1 = line.start.y; double x2 = line.end.x, y2 = line.end.y; double a = x2 - x1; double b = y2 - y1; double a2 = a * a; double b2 = b * b; double r2 = a2 + b2; double tt = -(a * (x1 - x0) + b * (y1 - y0)); if (tt < 0) return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); else if (tt > r2) return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0)); double f1 = a * (y1 - y0) - b * (x1 - x0); return sqrt((f1 * f1) / r2); } int main() { ll n; cin >> n; vector<ll> z(101); for (ll i = 0; i < n; i++) { ll k = i + 1; for (int j = 2; j <= n; j++) { while (k % j == 0) { z[j]++; k /= j; } } } ll ans = 0; for (int i = 0; i < 101; i++) { if (z[i] >= 74)ans++; } ll a = 0; ll b = 0; for (int i = 0; i < 101; i++) { if (z[i] >= 24)a++; if (z[i] >= 2)b++; } ans += a * (b - 1); a = 0; b = 0; for (int i = 0; i < 101; i++) { if (z[i] >= 14)a++; if (z[i] >= 4)b++; } ans += a * (b - 1); a = 0; b = 0; for (int i = 0; i < 101; i++) { if (z[i] >= 4)a++; if (z[i] >= 2)b++; } ans += a * (a - 1) * (b - 2) / 2; cout << ans << endl; }
0
231,831
#include<stdio.h> #include<math.h> #include<algorithm> #include<queue> #include<deque> #include<stack> #include<string> #include<string.h> #include<vector> #include<set> #include<map> #include<bitset> #include<stdlib.h> #include<cassert> #include<time.h> #include<bitset> using namespace std; const long long mod=1000000007; const long long inf=mod*mod; const long long d2=(mod+1)/2; const double EPS=1e-10; const double INF=1e+10; const double PI=acos(-1.0); const int C_SIZE = 3121000; long long fact[C_SIZE]; long long finv[C_SIZE]; long long inv[C_SIZE]; long long Comb(int a,int b){ if(a<b||b<0)return 0; return fact[a]*finv[b]%mod*finv[a-b]%mod; } void init_C(int n){ fact[0]=finv[0]=inv[1]=1; for(int i=2;i<n;i++){ inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod; } for(int i=1;i<n;i++){ fact[i]=fact[i-1]*i%mod; finv[i]=finv[i-1]*inv[i]%mod; } } long long pw(long long a,long long b){ long long ret=1; while(b){ if(b%2)ret=ret*a%mod; a=a*a%mod; b/=2; } return ret; } int ABS(int a){return max(a,-a);} long long ABS(long long a){return max(a,-a);} double ABS(double a){return max(a,-a);} int main(){ int a;scanf("%d",&a); while(a--){ long long A,B; scanf("%lld%lld",&A,&B); if(A>B)swap(A,B); long long ret=A-1; long long tmp=A*B-1; long long val=(long long)((sqrt(4*tmp+1+0.5)-1)/2); ret+=max(0LL,val-A); val=max(val,A); ret+=(A*B-1)/(val+1); printf("%lld\n",ret); } }
#include <bits/stdc++.h> using namespace std; int main() { int h,w; cin >> h >> w; char s[h][w]; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ cin >> s[i][j]; } } int flag = 0; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(s[i][j] == '#'){ if(s[i-1][j] == '#' && i != 0){ continue; }else if(s[i][j-1] == '#' && j != 0){ continue; }else if(s[i][j+1] == '#' && j != w-1){ continue; }else if(s[i+1][j] == '#' && i != h-1){ continue; }else{ flag = 1; break; } } } if(flag == 1){ break; } } if(flag == 0){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
0
46,314,709
#include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; int sum = 0, rui = 0; for(int i = 0; i < 3; i++) { if(s[i] == 'R') rui++; else rui = 0; if(sum <= rui) sum = rui; } cout << sum << "\n"; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i,n) for(int i = 0; i < (n); ++i) #define REP(i,x,n) for(int i = (x); i < (n); ++i) #define ll long long #define P pair<ll,ll> #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() const ll mod = 1e9+7; const ll INF = 1e18; const double pi = acos(-1); int main(void) { string s; cin >> s; ll ans=0,n=s.size(); vector<ll> a(n+1,0); rep(i,n){ if(s[i] == '<') a[i+1] = max(a[i+1], a[i]+1); } for(int i=n-1; i>=0; i--){ if(s[i] == '>') a[i] = max(a[i], a[i+1]+1); } rep(i,n+1) ans += a[i]; cout << ans << endl; return 0; }
0
93,759,034
#include <iostream> using namespace std; int fiboArray[44] = {0}; int fibonacci(int anySection) { if (anySection == 0 || anySection == 1) return (fiboArray[anySection] = 1); if (fiboArray[anySection] == 0) { fiboArray[anySection] = fibonacci(anySection - 1) + fibonacci(anySection - 2); return fiboArray[anySection]; } else return fiboArray[anySection]; } int main() { int anySection; cin >> anySection; int answer = fibonacci(anySection); cout << answer << endl; return 0; }
#include <iostream> #include <stdio.h> #include <algorithm> #include <map> #include <math.h> using namespace std; #include <vector> #define rep(i,n) for (ll i = 0; i < (n) ; i++) #define INF 1e9 #define llINF 1e18 #define base10_4 10000 #define base10_5 100000 #define base10_6 1000000 #define base10_7 10000000 #define base10_8 100000000 #define base10_9 1000000000 #define MOD 1000000007 #define pb push_back #define ll long long #define ull unsigned long long #define vint vector<int> #define vll vector<ll> string ans_Yes = "Yes"; string ans_No = "No"; string ans_yes = "yes"; string ans_no = "no"; ll A; long double B; ll B_int; long double B_d; ll ltmp; string stmp; double dtmp; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> A; cin >> B; B_int = B; B_d = B - B_int; B_int = B_int * A; B_d = B_d * A; ll ans = B_int + B_d; cout << ans << endl; }
0
94,591,692
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=2e5+5; ll a[maxn], num[maxn]; int main() { ll n,p; scanf("%lld%lld",&n,&p); for(int i=1;i<=n;i++) { scanf("%1d",&a[i]); } ll ans=0; if(p==2 || p==5) { for(int i=1;i<=n;i++) { if(a[i]%p == 0) ans+=i; } } else { num[0]=1; ll sum=0, x=1; for(int i=n;i>=1;i--) { (sum+=a[i]*x)%=p; x=x*10%p; ans+=num[sum]; num[sum]++; } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; vector<long long>A(N+1); vector<long long>B(N); for(int X=0;X<N+1;X++){ cin>>A[X]; } for(int X=0;X<N;X++){ cin>>B[X]; } long long K=0; for(int X=0;X<N;X++){ if(B[X]<=A[X]){ K+=B[X]; A[X]-=B[X]; } else if(B[X]>=A[X]+A[X+1]){ K+=A[X]+A[X+1]; A[X]=0; A[X+1]=0; } else{ K+=B[X]; A[X+1]+=A[X]-B[X]; A[X]=0; } } cout<<K<<endl; }
0
7,709,957
#include <iostream> #include <iomanip> #include <sstream> #include <stdio.h> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <math.h> #include <utility> #include <string> #include <ctype.h> #include <cstring> #include <cstdio> #include <sstream> #include <functional> using namespace std; #define FOR(i,k,n) for(int i = (k); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define INF 114514810 #define ll long long char city[1005][1005]; int way[1005][1005]; int di[4] = { -1, 0, 0, 1 }; int dj[4] = { 0, -1, 1, 0 }; int main() { int h, w, n; cin >> h >> w >> n; REP(i, h)REP(j, w) cin >> city[i][j]; typedef queue<pair<int, int>> que; que start; REP(i, h)REP(j, w) { if (city[i][j] == 'S') start.push(make_pair(i, j)); } FOR(k, 1, n+1) { REP(i, h)REP(j, w) { if (city[i][j] - '0' == k) { start.push(make_pair(i, j)); } } } int cnt = 0; REP(i,n) { REP(i, 1005)REP(j, 1005) way[i][j] = INF; que q; way[start.front().first][start.front().second] = 0; q.push(start.front()); start.pop(); while (1) { int tmpi = q.front().first; int tmpj = q.front().second; q.pop(); if (tmpi == start.front().first&&tmpj == start.front().second) { cnt += way[tmpi][tmpj]; break; } else { REP(i, 4) { if (tmpi + di[i] >= 0 && tmpi + di[i] < h &&tmpj + dj[i] >= 0 && tmpj + dj[i] < w && city[tmpi + di[i]][tmpj + dj[i]] != 'X' && way[tmpi + di[i]][tmpj + dj[i]] == INF) { way[tmpi + di[i]][tmpj + dj[i]] = way[tmpi][tmpj] + 1; q.push(make_pair(tmpi + di[i], tmpj + dj[i])); } } } } } cout << cnt << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <string> #include <sstream> #include <vector> #include <set> #include <stack> #include <map> #include <cmath> #include <queue> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; #define MAX_N 100 const ll INF = 1000000000000000; ll d[MAX_N][MAX_N]; void init(){ rep(i,MAX_N){ rep(j,MAX_N) d[i][j] = INF; d[i][i] = 0; } } void warshall_floyd(int n){ for(int k = 0; k < n; k++){ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if( d[i][k] == INF || d[k][j] == INF){ }else{ d[i][j] = min(d[i][j],d[i][k] + d[k][j]); } } } } } bool existNegativeCycle(int n){ for(int start = 0; start < n; start++){ if(d[start][start] < 0){ return true; } } return false; } int main() { init(); int v,e; cin>>v>>e; rep(i,e){ ll s,t,c; cin>>s>>t>>c; d[s][t] = c; } warshall_floyd(v); if( existNegativeCycle(v) == true){ cout<<"NEGATIVE CYCLE"<<endl; }else{ rep(i,v){ rep(j,v-1){ if(d[i][j] == INF){ cout<<"INF "; }else{ cout<<d[i][j]<<" "; } } if(d[i][v-1] == INF){ cout<<"INF"<<endl; }else{ cout<<d[i][v-1]<<endl; } } } return 0; }
0
14,539,477
#include <iostream> #include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.1415926535897932384626433832795l #define F first #define S second #define mp make_pair #define f(i,n) for(int i=0;i<n;i++) #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define all(v) (v).begin(),(v).end() #define sort(v) sort((v).begin(),(v).end()) #define rall(v) (v).rbegin(),(v).rend() #define rsort(v) sort((v).rbegin(),(v).rend()) #define gcd(a,b) __gcd((a),(b)) #define minn(v) *min_element(v.begin(), v.end()); #define maxx(v) *max_element(v.begin(), v.end()); #define print(x) cout<<(x)<<endl; typedef pair<int,int> pii; typedef vector<int> vi; struct type{ int k, i, j; }; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int findSubarray(int arr[], int n, int k) { int window_sum = 0; int min_window = INT_MAX; int last = 0; for (int i = 0; i < n; i++) { window_sum += arr[i]; if (i + 1 >= k) { if (min_window > window_sum) { min_window = window_sum; last = i; } window_sum -= arr[i + 1 - k]; } } int sum=0; for(int i=last-k+1;i<=last;i++) { sum+=arr[i]; } return sum; } signed main() { fastio; int k,x; cin>>k>>x; if(500*k>=x)print("Yes") else print("No") }
#include<bits/stdc++.h> #define ASORT(arr, n) sort(arr,arr+n) #define SORT(v) sort(v.begin(), v.end()) #define REV(v) reverse(v.begin(), v.end()) #define FOR(i, n) for (int i=0; i<n; i++) #define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define PI acos(-1.0) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; const double eps = 1e-9; int main() { fastIO(); ll k , a, b ; cin>>k>>a>>b; for(int i=a; i<=b; i++) { if(i%k==0) { cout<<"OK"<<'\n'; return 0; } } cout<<"NG"<<'\n'; return 0; }
0
3,191,314
#include<iostream> #include<iomanip> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<utility> #include<numeric> #include<algorithm> #include<cmath> #include<climits> using namespace std; using ll = long long; class Stream{ public: Stream(){ } void read(){ } template<typename First, typename... Rest> void read(First& first, Rest&... rest){ cin >> first; read(rest...); } template<typename T> void write_vec(vector<T>& v, char divider){ for(size_t i = 0; i < v.size(); i++){ cout << v[i] << divider; } } }; int main(){ Stream io; int X, Y; io.read(X, Y); cout << X + Y / 2; return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; #define rep(i,n) for(ll i=0;i<ll(n);i++) #define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; const double pi = 3.14159265358979; int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; ll n = s.size(); if (n != 26){ vector<bool> m(26,false); for (ll i = 0;i < n;i++){ m[s[i] - 'a'] = true; } for (ll i = 0; i < 26; i++){ if (!m[i]){ char x = 'a' + i; cout << s << x << endl; break; } } } else if (s == "zyxwvutsrqponmlkjihgfedcba"){ cout << -1 << endl; } else{ vector<bool> m(26,false); ll c = 0; ll j = 0; for (ll i = 25; i >= 1; i--){ if (s[i] < s[i-1]){ m[s[i] - 'a'] = true; } else{ m[s[i] - 'a'] = true; m[s[i-1] - 'a'] = true; c = s[i-1] - 'a'; j = i-1; break; } } for (ll i = c+1; i < 26; i++){ if (m[i]){ s[j] = 'a' + i; break; } } for (ll i = 0; i <= j; i++){ cout << s[i]; } cout << endl; } }
0
78,492,508
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define COUT(x) cout<<(x)<<endl #define dump(x) cout << #x << " = " << (x) << endl; using ll = long long; using P = pair<int,int>; using Graph = vector<vector<int>>; using M = map<int,int>; using PQ = priority_queue<int>; using PQG = priority_queue<int, vector<int>, greater<int>>; const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; int main() { int r,g; cin >> r >> g; cout << 2.0*g-r << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; #define chmax(x,y) x = max(x,y); const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int INF = 1001001001; int main() { int n, k; cin >> n >> k; vector<int> p(n), c(n); rep(i,n) cin >> p[i]; rep(i,n) cin >> c[i]; rep(i,n) p[i]--; ll ans = -1e18; rep(si,n) { int x = si; vector<int> s; ll tot = 0; while (1) { x = p[x]; s.push_back(c[x]); tot += c[x]; if (x == si) break; } int l = s.size(); ll t = 0; rep(i,l) { t += s[i]; if (i+1 > k) break; ll now = t; if (tot > 0) { ll e = (k-(i+1))/l; now += tot*e; } ans = max(ans, now); } } cout << ans << endl; return 0; }
0
72,992,343
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<ll,ll> P; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define EFOR(i,a,b) for(int i=(a);i<=(b);++i) #define REP(i, n) FOR(i,0,n) #define IINF 1e9 int DFS(Graph& q, vector<bool>& vis, int x, int n){ bool can = true; int tot = 0; REP(i,n){ if(!vis[i]) can = false; } if(can) return 1; REP(i,n){ if(q[x][i] == -1) continue; if(vis[i]) continue; vis[i] = true; tot += DFS(q,vis,i,n); vis[i] = false; } return tot; } int main(void){ int n,m; cin >> n >> m; Graph q(n,vector<int>(n,-1)); vector<bool> vis(n,false); REP(i,m){ int a,b; cin >> a >> b; a--; b--; q[a][b] = 1; q[b][a] = 1; } vis[0] = true; cout << DFS(q,vis,0,n) << endl; return 0; }
#include <iostream> using namespace std; int main (int argc, const char * argv[]) { int x,y; while(1){ cin >>x>>y; if(x==0&&y==0)break; else if (x<y){ cout << x <<" "<<y<<endl; }else{ cout << y <<" "<<x<<endl; } } return 0; }
0
91,470,455
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i=0; i<n; ++i) #define MAX_N 200000 vector<int> V; int a[MAX_N]; int main() { int n, k; cin >> n >> k; rep(i, n) cin >> a[i]; sort(a, a+n); int num = a[0]; int cnt = 1; for(int i=1; i<n; ++i) { if(num==a[i]) { ++cnt; }else { V.push_back(cnt); cnt = 1; num = a[i]; } } V.push_back(cnt); if(V.size()<=k) { cout << 0 << endl; }else { ll res = 0; sort(V.begin(), V.end()); for(int i=0; i<V.size()-k; ++i) { res += V[i]; } cout << res << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) int main(){ cin.tie(0); ios::sync_with_stdio(false); int n;cin>>n; vector<int> a(n); rep(i,n)cin>>a[i]; int maxi=0,mini=1e9+7,tmp=1e9+7; rep(i,n)maxi=max(maxi,a[i]); rep(i,n)if(a[i]==maxi)a[i]=0; if(maxi%2==0){ rep(i,n)if(abs(a[i]-maxi/2)<tmp)mini=a[i],tmp=abs(a[i]-maxi/2); } else { rep(i,n){ if(a[i]<=maxi/2 && abs(a[i]-maxi/2)<tmp)mini=a[i],tmp=abs(a[i]-maxi/2); else if(a[i]>maxi/2 && abs(a[i]-maxi/2-1)<tmp)mini=a[i],tmp=abs(a[i]-maxi/2-1); } } cout<<maxi<<' '<<mini<<endl; return 0; }
0
14,369,925
#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<int,int> #define poly vector<ll> #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 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(' ');} inline ull rnd(){ return ((ull)rand()<<30^rand())<<4|rand()%4; } const int N=1005; int x[N],y[N]; bool vis[2]; char ans[35]; int main(){ int n=read(); For(i,1,n){ x[i]=read(); y[i]=read(); vis[(x[i]+y[i])&1]=1; } if(vis[0]&&vis[1]){ puts("-1"); return 0; } int m=31; cout<<m+vis[0]<<endl; For(i,0,m-1)wri(1<<i); if(vis[0]){ m++; For(i,1,n)x[i]--; puts("1"); ans[31]='R'; } For(i,1,n){ Rep(j,30,0){ int t=1<<j; if(x[i]>=t){x[i]-=t; ans[j]='R';} else if(x[i]<=-t){x[i]+=t; ans[j]='L';} else if(y[i]>=t){y[i]-=t; ans[j]='U';} else if(y[i]<=-t){y[i]+=t; ans[j]='D';} else if(abs(x[i])>=abs(y[i])){ if(x[i]>0){x[i]-=t; ans[j]='R';} else {x[i]+=t; ans[j]='L';} }else{ if(y[i]>0){y[i]-=t; ans[j]='U';} else {y[i]+=t; ans[j]='D';} } } cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; int main(){ ll n; string s; cin>>n>>s; ll x=s.size()-1; string ans[4]={"SS","SW","WS","WW"}; for(int i=0;i<4;i++){ for(int j=1;j<x;j++){ if(s[j]=='o'){ if(ans[i][j]=='S')ans[i]+=ans[i][j-1]; else ans[i]+=(ans[i][j-1]=='S'?"W":"S"); }else{ if(ans[i][j]=='S')ans[i]+=(ans[i][j-1]=='S'?"W":"S"); else ans[i]+=ans[i][j-1]; } } char c,d; if(s[x]=='o'){ if(ans[i][x]=='S')c=ans[i][x-1]; else c=(ans[i][x-1]=='S'?'W':'S'); }else{ if(ans[i][x]=='S')c=(ans[i][x-1]=='S'?'W':'S'); else c=ans[i][x-1]; } if(s[0]=='o'){ if(ans[i][0]=='S')d=ans[i][1]; else d=(ans[i][1]=='S'?'W':'S'); }else{ if(ans[i][0]=='S')d=(ans[i][1]=='S'?'W':'S'); else d=ans[i][1]; } if(c==ans[i][0]&&d==ans[i][x]){ cout<<ans[i]<<endl; return 0; } } cout<<-1<<endl; return 0; }
0
88,205,973
#include <bits/stdc++.h> using namespace std; using ll=long long; using vb=vector<bool>; using vvb=vector<vb>; using vd=vector<double>; using vvd=vector<vd>; using vi=vector<int>; using vvi=vector<vi>; using vl=vector<ll>; using vvl=vector<vl>; using pii=pair<int,int>; using pll=pair<ll,ll>; using tll=tuple<ll,ll>; using tlll=tuple<ll,ll,ll>; using vs=vector<string>; #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define rep(i,n) range(i,0,n) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define range(i,a,n) for(int i=(a);i<(n);i++) #define LINF ((ll)1ll<<60) #define INF ((int)1<<30) #define EPS (1e-9) #define MOD (1000000007ll) #define fcout(a) cout<<setprecision(a)<<fixed #define fs first #define sc second #define PI 3.1415926535897932384 int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1}; template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;} template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;} template<class S>S acm(vector<S>&a){return accumulate(all(a),S());} template<class S>S max(vector<S>&a){return *max_element(all(a));} template<class S>S min(vector<S>&a){return *min_element(all(a));} void YN(bool b){cout<<(b?"YES":"NO")<<"\n";} void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";} void yn(bool b){cout<<(b?"yes":"no")<<"\n";} ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);} template<class T>void puta(T&&t){cout<<t<<"\n";} template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);} template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;}; template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;} #define _cTime (chrono::system_clock::now()) #define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count()) #define reset _sTime=_cTime auto reset; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; ll mn=0,ans=0; cin>>n; vl v(n); rep(i,n){ cin>>v[i]; ll tmp=(v[i]-1)/(mn+1); if(tmp)ans+=tmp; else chmax(mn,v[i]); if(mn==0)mn++; } cout<<ans<<endl; }
#include<iostream> using namespace std; int main(){ int number; int i=1; while(1<3){ cin >> number; if(number == 0){ break; } cout << "Case " << i << ": " << number << endl; i++; } return 0; }
0
61,626,650
#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 n, k; cin >> n >> k; int m = (n-1) * (n-2) / 2 - k; if (m < 0) { cout << -1 << endl; return 0; } cout << n-1+m << endl; for (int i = 1; i < n; ++i) { cout << 1 << " " << i+1 << endl; } int s = 0; for (int i = 1; i < n; ++i) { if (s >= m) break; for (int j = i+1; j < n; ++j) { if (s >= m) break; cout << i+1 << " " << j+1 << endl; s++; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long n,m,a[200005],b[200005],c[200005]={}; cin>>n>>m; for(int i=0;i<m;i++){ cin>>a[i]>>b[i]; if(b[i]==n){ c[a[i]]=1; } } for(int i=0;i<m;i++){ if(a[i]==1){ if(c[b[i]]==1){ cout<<"POSSIBLE"<<endl; return(0); } } } cout<<"IMPOSSIBLE"<<endl; return(0); }
0
30,474,527
#include <cstdio> #include <cmath> int main() { double a, b, C, c; double pi = 4*atan(1), theta; double S, L, h; scanf("%lf %lf %lf", &a, &b, &C); theta = C * pi / 180.; h = b * fabs(sin(theta)); S = 0.5 * a * h; c = sqrt(a*a + b*b - 2*a*b*cos(theta)); L = a + b + c; printf("%lf %lf %lf\n", S, L, h); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; using WGraph = vector<vector<pair<int, ll>>>; template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; } template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0}; constexpr int INF = 1e9; constexpr int MOD = 1e9 + 7; constexpr long long LINF = 1e18; constexpr double EPS = 1e-10; constexpr double PI = M_PI; void solve() { ll w, h; cin >> w >> h; vector<ll> p(w), q(h); for (int i=0; i<w; ++i) cin >> p.at(i); for (int i=0; i<h; ++i) cin >> q.at(i); sort(p.begin(), p.end()); sort(q.begin(), q.end()); ll res = 0; ll cnt = (h+1) * (w+1) - 1; ll curP = 0, curQ = 0; while (cnt > 0) { bool addP = true; if (curP == w || (curQ < h && p.at(curP) > q.at(curQ))) addP = false; ll add = addP ? h+1-curQ : w+1-curP; chmin(add, cnt); cnt -= add; res += add * (addP ? p.at(curP++) : q.at(curQ++)); } cout << res << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); solve(); return 0; }
0
61,921,876
#include<bits/stdc++.h> using namespace std; #define int long long int const int mod=1e9+7; int32_t main() { int n,k; cin>>n>>k; int x=n,y=0; int make=0,last_make=0; for(int i=0;i<k;i++) { make+=y; y++; last_make+=x; x--; } int ans=(last_make-make+1)%mod; for(int i=k+1;k<=n && make<=last_make;k++) { make+=y; y++; last_make+=x; x--; ans=(ans+(last_make-make+1)%mod)%mod; } cout<<ans<<endl; }
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <unordered_map> #include <iomanip> #include <cmath> #include <tuple> using namespace std; using ll = long long; #define rep(i, j, n) for(int i = j; i < (int)n; ++i) #define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i) constexpr ll MOD = 0x3b9aca07; constexpr int INF = 0x3f3f3f3f; constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> d(n); rep(i, 0, n) cin >> d[i]; sort(d.begin(), d.end()); cout << d[n / 2] - d[n / 2 - 1] << endl; return 0; }
0
55,604,019
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<int, int> Pi; typedef vector<ll> Vec; typedef vector<int> Vi; typedef vector<string> Vs; typedef vector<vector<ll>> VV; #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 rep(i, n) REP(i, 0, n) #define per(i, n) PER(i, n, 0) const ll INF=1e16+18; const ll MAX=100005; const ll MOD=1000000007; #define Yes(n) cout << ((n) ? "Yes" : "No") << endl; #define YES(n) cout << ((n) ? "YES" : "NO") << endl; #define ALL(v) v.begin(), v.end() #define pb(x) push_back(x) #define mp(a, b) make_pair(a,b) #define Each(a,b) for(auto &a :b) #define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i) #define dbg(x_) cerr << #x_ << ":" << x_ << endl; #define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;} #define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;} #define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl; #define sum(v) accumulate(ALL(v),0) #define fi first #define se second template<typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; } template<typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len=v.size(); for(int i=0; i<len; ++i) { s<<v[i]; if(i<len-1) s<<" "; } return s; } template<typename T> ostream &operator<<(ostream &s, const vector<vector<T> > &vv) { int len=vv.size(); for(int i=0; i<len; ++i) { s<<vv[i]<<endl; } return s; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout<<std::setprecision(10); ll n,k; cin>>n>>k; ll ans=n+1-k; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #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 EPS (1e-7) #define INF 1e9 typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; int vx[]={0,1,0,-1}; int vy[]={1,0,-1,0}; int dx[]={0,1,0,-1,1,1,-1,-1}; int dy[]={1,0,-1,0,1,-1,1,-1}; const ll mod=1000000000+7; const int MAX_N=1000; int dp[1<<26]; int main(){ string s; cin>>s; int n=s.size(); int a[n+1]; a[0]=0; a[1]=0|(1<<(s[0]-'a')); for(int i=2;i<=n;i++){ a[i]=a[i-1]^(1<<(s[i-1]-'a')); } int opt[n+1]; fill(opt,opt+n+1,INT_MAX); opt[0]=0; fill(dp,dp+(1<<26),INT_MAX); dp[a[0]]=0; int X[27]; X[0]=0; for(int i=1;i<27;i++){ X[i]=1<<(i-1); } for(int i=1;i<=n;i++){ int minx=INT_MAX; for(int j=0;j<27;j++){ minx=min(minx,dp[a[i]^X[j]]); } opt[i]=minx+1; dp[a[i]]=min(dp[a[i]],opt[i]); } cout<<opt[n]<<endl; return 0; }
0
8,193,518
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <vector> using namespace std; typedef long long ll; ll const INF = 1LL << 60; int main() { ll H, W; cin >> H >> W; vector<string> A(H); vector<vector<ll>> D(H, vector<ll>(W, INF)); for (int i = 0; i < H; i++) { cin >> A[i]; } queue<pair<ll, ll>> q; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] == '#') { q.push({i, j}); D[i][j] = 0; } } } int step_x[4] = {0, 0, 1, -1}; int step_y[4] = {1, -1, 0, 0}; while (!q.empty()) { ll cur_x = q.front().first; ll cur_y = q.front().second; q.pop(); for (int i = 0; i < 4; i++) { ll next_x = cur_x + step_x[i]; ll next_y = cur_y + step_y[i]; if (next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue; if (D[next_x][next_y] != INF) continue; D[next_x][next_y] = D[cur_x][cur_y] + 1; q.push({next_x, next_y}); } } ll ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans = max(ans, D[i][j]); } } cout << ans << endl; return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<string> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < n; i++) #define INF 1000000000 #define all(x) (x).begin(), (x).end() vector<int> dp; vector<int> h; int k; int dfs(int i){ if(i <= 0){ return 0; } int ans; if(dp.at(i) != -1){ ans = dp.at(i); }else{ ans = INF; for(int j = 1; j <= min(k, i); j++){ ans = min(ans, dfs(i - j) + abs(h.at(i) - h.at(i - j))); } dp.at(i) = ans; } return ans; } int main(){ int n; cin >> n >> k; h = vector<int>(n); rep(i, n){ cin >> h.at(i); } dp = vector<int>(n, -1); cout << dfs(n - 1) << endl; }
0
19,497,877
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int> >; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define brep(n) for(int bit=0;bit<(1<<n);bit++) #define erep(i,container) for (auto i : container) #define irep(i, n) for(int i = n-1; i >= (int)0; i--) #define rrep(i,m,n) for(int i = m; i < (int)(n); i++) #define reprep(i,j,h,w) rep(i,h)rep(j,w) #define all(x) (x).begin(),(x).end() #define aall(x,n) (x).begin(),(x).begin()+(n) #define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i]; #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define mp make_pair #define sum accumulate #define keta fixed<<setprecision #define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a)) #define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a))); #define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) )); typedef long long ll; const int INF = 2000000000; const ll INF64 = 1000000000000000ll; const ll MOD = 1000000007LL; int main(){ int n; std::cin >> n; std::vector<pair<int,int>> a(n); rep(i,n){ int dum; std::cin >> dum; a[i]=mp(dum,i+1); } sort(all(a)); std::vector<int> aa(n); rep(i,n)aa[a[i].se-1]=i+1; int ans=0; for (int i = 1; i < n; i+=2) { if(aa[i]%2==1)ans++; } std::cout << ans << std::endl; }
#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++) ll gcd(ll a, ll b){ if(a < b) return gcd(b, a); ll r = a % b; while(r != 0){ a = b; b = r; r = a % b; } return b; } ll lcm(ll a, ll b){ ll ret = a / gcd(a,b) * b; return ret; } int main(){ ll a, b, c, d; cin >> a >> b >> c >> d; ll numc = (b / c) - ((a + c - 1) / c) + 1; ll numd = (b / d) - ((a + d - 1) / d) + 1; ll l = lcm(c, d); ll numl = (b / l) - ((a + l - 1) / l) + 1; cout << b - a + 1 - numc - numd + numl << endl; return 0; }
0
92,478,182
#include<iostream> using namespace std; int main() { int n; cin>>n; if(n >= 400 && n <= 599) cout<<8<<endl; else if(n >= 600 && n <= 799) cout<<7<<endl; else if(n >= 800 && n <= 999) cout<<6<<endl; else if(n >= 1000 && n <= 1199) cout<<5<<endl; else if(n >= 1200 && n <= 1399) cout<<4<<endl; else if(n >= 1400 && n <= 1599) cout<<3<<endl; else if(n >= 1600 && n <= 1799) cout<<2<<endl; else if(n >= 1800 && n <= 1999) cout<<1<<endl; else cout<<-1<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; using P = pair<int, int>; const int dx[] = {0, 1}; const int dy[] = {1, 0}; int main() { int h, w; cin >> h >> w; vector<string> s(h); rep(i, h) cin >> s[i]; vector<vector<int>> d(h, vector<int>(w, -1)); queue<P> q1, q2; int sx = 0, sy = 0; int gx = h - 1, gy = w - 1; q1.push(P(sx, sy)); d[0][0] = 0; char here = s[0][0]; while (!q1.empty() || !q2.empty()) { while (!q1.empty()) { P p = q1.front(); int cx = p.first, cy = p.second; q1.pop(); rep(i, 2) { int nx = cx + dx[i], ny = cy + dy[i]; if (nx < 0 || h <= nx || ny < 0 || w <= ny) continue; if (d[nx][ny] != -1) continue; if (s[nx][ny] == here) { d[nx][ny] = d[cx][cy]; q1.push(P(nx, ny)); } else { d[nx][ny] = d[cx][cy] + 1; q2.push(P(nx, ny)); } } } swap(q1, q2); here = (here == '.' ? '#' : '.'); } int ans; if (s[sx][sy] == '.') ans = (d[gx][gy] + 1) / 2; else ans = d[gx][gy] / 2 + 1; cout << ans << endl; return 0; }
0
53,312,191
#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>; #define chmax(x,y) x = max(x,y) #define chmin(x,y) x = min(x,y) const int INF = 1e9 + 10; int main() { string s; cin >> s; int n = s.size(); int ans = 0; rep(i,n) { ans += s[i] - '0'; } string res = (ans%9==0) ? "Yes" : "No"; cout << res << endl; return 0; }
#include <vector> #include <cstdio> #include <bitset> #include <utility> #include <cstdlib> #include <sstream> #include <fstream> #include <set> #include <map> #include <deque> #include <cmath> #include <ctime> #include <queue> #include <stack> #include <string> #include <iostream> #include <algorithm> #include <functional> int main() { std::ios::sync_with_stdio(0); std::string s; std::cin >> s; int n = s.size(); int st = 0; std::map<int, int> mp; mp[0] = 0; for (int i = 0; i < n; ++i) { st ^= (1 << (s[i] - 'a')); int hs = n + 1; if (mp.count(st)) { hs = mp[st]; } int &ans = mp[st]; ans = hs; for (int j = 0; j < 26; ++j) { int prev = st ^ (1 << j); if (mp.count(prev)) { ans = std::min(ans, mp[prev] + 1); } } } int ans = mp[st]; if (ans == 0) ans = 1; std::cout << ans << std::endl; return 0; }
0
47,742,722
#include<bits/stdc++.h> using namespace std; int main(){ long long N; unsigned long long ans = 1; cin >> N; bool zero = false; bool ng = false; for(long long i = 0; i < N; i++) { unsigned long long tmp; cin >> tmp; if(tmp == 0) { zero = true; } if(!zero && 1000000000000000000/ans < tmp) { ng = true; } if(!zero && !ng) { ans *= tmp; } } if(zero) { cout << 0 << endl; } else if(ng) { cout << -1 << endl; } else { cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<long long, long long> pll; #define pb push_back #define ff first #define ss second #define INF int(3e9) #define BIG_INF ll(9e18) #define SIZE 100001 #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define len(v) int((v).size()) #define sqr(x) (x) * (x) #define cube(x) (x) * (x) * (x) #define filein freopen("input.txt", "r", stdin) #define fileout freopen("output.txt", "w", stdout); ll binpow(ll a, ll b, ll MOD = BIG_INF) { ll res = 1; while(b) { if(b & 1) res *= a; a *= a; b >>= 1; a %= MOD; res %= MOD; } return res % MOD; } const ll mod = 1e9 + 7; int T = 1; int n, m, k; vector<int> g[SIZE], b[SIZE]; int p[SIZE]; int cnt[SIZE]; bool used[SIZE]; void dfs(int u, int P, int &kol) { used[u] = 1; p[u] = P; for(int v: g[u]) { if(!used[v]) { kol++; dfs(v, P, kol); } } } void solve() { cin >> n >> k; vector<ll> pref(n + 1, 0); for(ll i = 1; i <= n; i++) { pref[i] = pref[i - 1] + i; } ll ans = 0; for(int i = k; i <= n; i++) { ll x = pref[i - 1]; ll y = pref[n] - pref[n - i]; ans += y - x + 1; ans %= mod; } cout << ans + 1; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); while(T--) { solve(); } return 0; }
0
94,996,347
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int> > vii; #define rrep(i, m, n) for(int (i)=(m); (i)<(n); (i)++) #define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++) #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) #define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--) #define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--) #define rev(i, n) for(int (i)=(n)-1; (i)>=0; (i)--) #define vrep(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define pb push_back template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); } template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; } template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; } static const int INF = 1000000000; static const ll MOD = 1000000007LL; static const double EPS = 1E-12; int n; int d; int main() { while(cin >> n, n){ int sum = 0; int mn = INF; int mx = -INF; rep(i, n){ cin >> d; sum += d; minup(mn, d); maxup(mx, d); } cout << (sum - mx - mn) / (n - 2) << endl; } return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <string> #include <sstream> #include <complex> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <iterator> #include <numeric> #include <bitset> #include <cassert> #include <functional> using namespace std; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<ll, ll> P; inline ll min(ll x, ll y) { return x < y ? x : y; } inline ll max(ll x, ll y) { return x > y ? x : y; } #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << (x) << endl #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) int main() { string S; cin >> S; if (S.length() >= 4) { if (S.substr(0, 4) == "YAKI") { cout << "Yes"; return 0; } } cout << "No"; return 0; }
0
77,386,879
#include <iostream> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main(void) { ios::sync_with_stdio(false); int64_t N, M; cin >> N >> M; unordered_map<int64_t, int64_t> count; int64_t sum = 0; count[sum]++; rep(i, N) { int a; cin >> a; sum = (sum + a) % M; count[sum]++; } int64_t answer = 0; for (auto& n : count) { answer += (n.second) * (n.second - 1) / 2; } cout << answer << endl; return 0; }
#include <iostream> #include <string> using std::cin; using std::cout; using std::endl; using std::string; int main(void) { int n; while (cin >> n) { if (n == 0) { break; } int times = 0; bool status = 0; bool left = 0; bool right = 0; for (int i = 0; i < n; i++) { string act; cin >> act; if (act == "lu") { left = 1; } else if (act == "ru") { right = 1; } else if (act == "ld") { left = 0; } else if (act == "rd") { right = 0; } if (left == 1 && right == 1 && status == 0) { times++; status = 1; } else if (left == 0 && right == 0 && status == 1) { times++; status = 0; } } cout << times << endl; } return 0; }
0
22,135,689
#include<stdio.h> int main(){ char str[20]; scanf("%[^\n]",&str); str[5]= ' '; str[13]= ' '; printf("%s", str); return 0; }
#include <bits/stdc++.h> #include <boost/multiprecision/cpp_int.hpp> #define rep(i,a,b) for(ll i=a;i<b;i++) #define rrep(i,b,a) for(int i=b;i>=a;i--) #define fori(a) for(auto i : a ) #define all(a) begin(a), end(a) #define set(a,b) memset(a,b,sizeof(a)) #define sz(a) a.size() double pi=acos(-1); #define ll long long #define ull unsigned long long #define pb push_back #define PF push_front #define pq priority_queue const ll mod=1000000007; #define f first #define s second #define pii pair< ll, ll > #define vi vector<int> #define vpii vector<pii> #define debug(v) for(auto i:v) cout<<i<<" "; #define tc int t; cin >> t; while(t--) using namespace boost::multiprecision; using namespace std; void optimizeIO(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int N=1000005; ll fact[N],invfact[N]; ll power(ll x,ll y){ if(y<=0) return 1LL; ll z=power(x,y/2); if(y%2) return (((z*z)%mod)*x)%mod; return (z*z)%mod; } void pre(){ fact[0]=invfact[0]=invfact[1]=fact[1]=1; rep(i,2,N) fact[i]=(i*fact[i-1])%mod; rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod; } ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; } const int N1=1e6+1; vector<int> isprime(N1,1),prime; void seive(){ rep(i,2,sqrt(N1)+1){ if(isprime[i]){ for(int j=i*i;j<N1;j+=i) isprime[j]=0; prime.pb(i); } } rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i); } struct dsu { vector<int> par, rank; dsu(int n): par(n+1), rank(n+1) { for (int i = 0; i <= n; i++) { par[i] = i; rank[i]= 1; } } int root(int a) { if (a == par[a]) return a; return par[a] = root(par[a]); } void merge(int a, int b) { a = root(a); b = root(b); if (a == b) return; if (rank[a] > rank[b]) swap(a, b); par[b] = a; } set<int> parent(int n){ set<int> s; for(int i=1;i<=n;i++){ s.insert(root(i)); } return s; } }; void solve(){ string s,t; cin>>s>>t; sort(all(s)); sort(all(t),greater<char>()); if(s<t) cout<<"Yes\n"; else cout<<"No\n"; } int main(){ optimizeIO(); int r=1; {solve();} }
0
85,383,968
#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() { ll a, b; cin >> a >> b; if (a <= 8 && b <= 8) cout << "Yay!\n"; else cout << ":(\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define sz(x) int(x.size()) #define pb push_back #define eb emplace_back using ll=long long; using P = pair<int,int>; using LP=pair<ll,int>; #define chmax(x,y) x = max(x,y) #define chmin(x,y) x = min(x,y) const ll MOD=1000000007,MOD2=998244353; int main() { int N,M; cin>>N>>M; vector<LP> AB(N); rep(i,N){ cin>>AB.at(i).first>>AB.at(i).second; } sort(AB.begin(),AB.end()); ll ans=0; int now=0; int po=0; while(po<N && now+AB.at(po).second<=M){ ans+=AB.at(po).first*AB.at(po).second; now+=AB.at(po).second; po++; } if(now<M)ans+=AB.at(po).first*(M-now); cout<<ans<<endl; }
0
9,710,195
#include <string> #include <vector> #include <sstream> #include <iostream> #include <algorithm> #include <map> #include <list> #include <set> #include <numeric> #include <queue> #include <stack> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <cstring> #include <climits> #include <cfloat> #include <ctime> #include <complex> #include <cassert> #include <array> #include <bitset> #include <unordered_map> #include <random> using namespace std; typedef long long LL; typedef pair<int,int> P; const int L=1e5; int m[L]; int p[L]; LL a[L]; LL r[L]; int main() { int N; cin >> N; LL sum=0; for(int i=0;i<N;i++){ cin >> a[i]; sum+=a[i]; } int c=-1; LL v=0; for(int i=0;i<N;i++){ if(a[i]>v){ p[i]=c; v=a[i]; c=i; } } map<int,LL> vs; for(int i=N-1;i>0;i--){ vs[a[i]]++; if(c==i){ c=p[i]; while(vs.size()){ auto it=vs.end(); it--; auto w=it->second; if(it->first>a[c]){ auto d=it->first-a[c]; vs.erase(it); vs[a[c]]+=w; r[i]+=w*d; sum-=w*d; } else{ break; } } } } r[0]=sum; for(int i=0;i<N;i++){ cout << r[i] << endl; } return 0; }
#include<iostream> #include<stdio.h> #include<bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define pb push_back #define ll long long #define pii pair<int,int> #define pcc pair<char,char> #define F first #define S second #define int long long #define pi 3.141592653589793238462643383279502 #define M 1000000007 #define rep(i,a,n) for(int i=a;i<n;i++) #define INF 10000000000000 #define N 200005 #define vi vector<int> #define all(v) v.begin(),v.end() int dp[105][105][2];int k; int calc(int pos,int cnt,int flag,vi num) { if(pos == num.size()) { if(cnt == k) return 1; else return 0; } if(dp[pos][cnt][flag]!=-1)return dp[pos][cnt][flag]; int limit=(flag? 9 : num[pos]); int ans=0; for(int i=0;i<=limit;i++) { int currcnt=cnt; if(i!=0)currcnt++; int currflag=flag; if(i < num[pos]) currflag=1; ans+=calc(pos + 1,currcnt,currflag,num); } return dp[pos][cnt][flag]=ans; } signed main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); string s; cin>>s; cin>>k; memset(dp,-1,sizeof(dp)); vi num; for(int i=0;i<s.length();i++) { int x = s[i] - '0'; num.pb(x); } cout<<calc(0,0,0,num)<<endl; }
0
81,020,631
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ll n, a, b; cin >> n >> a >> b; ll res = n / (a+b)*a; ll r = n % (a+b); res += min(r, a); cout << res << endl; return 0; }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for (int i=0;i<(int)(n);i++) #define codefor int test;scanf("%d",&test);while(test--) #define yn(ans) if(ans)printf("Yes\n");else printf("No\n") #define YN(ans) if(ans)printf("YES\n");else printf("NO\n") #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} vector<long long int> fibo(100001,-1); long long int fibonatti(long long int n){ if(fibo[n]!=-1){ return fibo[n]; }else if(n==0){ fibo[0]=1; return 1; }else if(n==1){ fibo[1]=1; return 1; }else if(n>=2){ fibo[n]=(fibonatti(n-1)+fibonatti(n-2))%MOD; return fibo[n]; } } int main(){ ll n,m; in(n,m); vector<int> vec(m); in(vec); fibonatti(100000); vec.push_back(n+1); ll target=0,ans=1,d=0; rep(i,m+1){ if(i==0)target=vec[i]-1; else target=vec[i]-vec[i-1]-2; if(target==-1){ ans=0; break; } d=0; if(target==0)d=1; else if(target==1)d=1; else if(target==2)d=2; else if(target>=3){ d=fibo[target]; } ans*=d; if(ans>MOD)ans%=(ll)MOD; } out(ans); }
0
49,838,178
#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(){ ll N; cin >> N; if (N%2==1){ cout << 0 << endl; return 0; } ll ans = 0; N /= 2; while (N > 0){ ans += N / 5; N /= 5; } cout << ans << endl; }
#include <iostream> #include <fstream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <map> #include <iomanip> #include <stdlib.h> #include <stdio.h> #include <queue> #include <deque> #include <set> #include <stack> #include <time.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<int, ll> Pil; typedef pair<ll, ll> Pll; typedef pair<ll, int> Pli; #define fi first #define se second const ll MOD = 1e9 + 7; const ll MOD2 = 998244353; const ll MOD3 = 1812447359; const ll INF = 1ll << 62; const double PI = 2 * asin(1); void yes() {printf("yes\n");} void no() {printf("no\n");} void Yes() {printf("Yes\n");} void No() {printf("No\n");} void YES() {printf("YES\n");} void NO() {printf("NO\n");} int N, K; ll V[55], ans = 0; int main(){ scanf("%d%d", &N, &K); for (int i = 0; i < N; i++) scanf("%lld", V + i); for (int L = 0; L <= min(N, K); L++){ for (int R = 0; L + R <= min(N, K); R++){ priority_queue <ll, vector<ll>, greater<ll> > que; ll now = 0; for (int i = 0; i < L; i++){ now += V[i]; if (V[i] < 0) que.push(V[i]); } for (int i = 0; i < R; i++){ now += V[N - 1 - i]; if (V[N - 1 - i] < 0) que.push(V[N - 1 - i]); } int cnt = 0; while (!que.empty() && cnt < K - (L + R)){ ll Q = que.top(); que.pop(); cnt++; now -= Q; } ans = max(ans, now); } } cout << ans << endl; return 0; }
0
31,844,112
#include <bits/stdc++.h> using namespace std; int main() { string s; int w; cin >> s >> w; string ans; for (int i = 0; i < s.length(); i++) { if (i % w == 0) ans += s[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; const long long MOD=1e09+7; #define rep(i,n) for(int i=0;i<n;i++) #define rep2(i,m,n) for(int i=m;i<n;i++) #define ALL(v) v.begin(), v.end() #define pb push_back ll factorial(int n){ if (n==0){ return 1; } if (n==1){ return 2; } if (n%2==0){ return (factorial(n/2)*factorial(n/2))%MOD; } if (n%2==1){ return (((factorial(n/2)*factorial(n/2))%MOD)*2)%MOD; } } int main(){ ll n; cin>>n; vector<ll> data(n); rep(i,n){ ll tmp; cin>>tmp; data.at(i)=tmp; } vector<ll> count0(61,0); vector<ll> count1(61,0); rep(i,n){ bitset<61> x(data.at(i)); rep(j,61){ if (x.test(j)==1){ count1.at(j)++; } else { count0.at(j)++; } } } ll answer=0; rep(i,61){ ll tmp; tmp=((count0.at(i)*count1.at(i)%MOD)*factorial(i))%MOD; answer+=tmp; answer%=MOD; } cout<<answer<<endl; }
0
11,626,793
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<pair<int,int>> a(n), b(m); for(int i = 0; i < n; i++)cin >> a[i].first >> a[i].second; for(int i = 0; i < m; i++)cin >> b[i].first >> b[i].second; for(int i = 0; i < n; i++) { int ind = -1; int dist = 1e9; int x = a[i].first, y = a[i].second; for(int j = 0; j < m; j++) { if(dist > abs(x - b[j].first) + abs(y - b[j].second)) { ind = j; dist = abs(x - b[j].first) + abs(y - b[j].second); } } cout << ind + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; char s[30005]; bool dp[1005][4]; int main(){ int n; scanf("%d%s", &n, s+1); dp[0][0] = 1; for(int i=1;i<=n;i++){ s[i] -= '0'; for(int j=999;j>=0;j--){ for(int k=2;k>=0;k--){ if(dp[j][k]){ dp[j*10+s[i]][k+1] = 1; } } } } int ans = 0; for(int i=0;i<1000;i++) ans += dp[i][3]; printf("%d\n", ans); }
0
90,659,015
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { long double a,b; cin >> a >> b; cout << (ll) (a * b + 1e-4) << endl; }
#include<bits/stdc++.h> using namespace std; inline int rd(char c[]){ int i, sz=0; for(;;){ i = getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ putchar_unlocked(c[i]); } } int K; char S[17]; int main(){ int i, res=0; K = rd(S); for(i=0;i<K;i++){ if(S[i]=='x'){ res++; } } if(res<=7){ wt_L("YES"); wt_L('\n'); } else{ wt_L("NO"); wt_L('\n'); } return 0; }
0
18,428,604
#define _USE_MATH_DEFINES #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; #define MAX(x,y) (x>y?x:y) #define MIN(x,y) (x<y?x:y) #define ABS(x) (x>0?x:-(x)) #define INF 2147483647 #define LLINF 9223372036854775807 #define MOD 1000000007 typedef long long int lli; void swap(int* a, int* b) { int tmp; tmp = *a; *a = *b; *b = tmp; } void ll_swap(lli* a, lli* b) { lli tmp; tmp = *a; *a = *b; *b = tmp; } int gcd(int a, int b) { if (a < b) swap(&a, &b); if (a % b == 0) return b; else return gcd(b, a % b); } int lcm(int a, int b) { return a * b / gcd(a, b); } long power(long x, int n) { long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans = ans * x; } x = x * x; n >>= 1; } return ans; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; printf("res:%lld a:%lld\n", res,a); } return res; } lli comb(lli n, lli r) { if (n == 0) return 0; if (r == 0 || r == n) return (1); else if (r == 1) return (n); return (comb(n - 1, r - 1) + comb(n - 1, r)); } int main() { int N, K; int A[100000]; scanf("%d%d", &N, &K); for (int i = 0; i < N; i++) scanf("%d", &A[i]); int a; if ((N - K) % (K - 1) == 0) a = 0; else a = 1; printf("%d", a+(N-K)/(K - 1) + 1); }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define chmin(x,y) x = min(x,y) #define chmax(x,y) x = max(x,y) using namespace std; typedef long long ll; typedef pair<int,ll> P; const ll INF = 10010010010; void warshall_floyd(int n, vector<vector<ll> > &D) { rep(k,n) rep(i,n) rep(j,n) D[i][j] = min(D[i][j], D[i][k]+D[k][j]); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n, m, r; cin >> n >> m >> r; vector<int> R(r); rep(i,r) { cin >> R[i]; R[i]--; } sort(R.begin(), R.end()); vector<vector<ll> > dist(n, vector<ll>(n, INF)); rep(i,m) { int a, b; ll c; cin >> a >> b >> c; a--; b--; dist[a][b] = c; dist[b][a] = c; } warshall_floyd(n, dist); ll ans = INF; do { ll temp = 0; rep(i,r-1) { temp += dist[R[i]][R[i+1]]; } ans = min(ans, temp); } while (next_permutation(R.begin(), R.end())); cout << ans << endl; return 0; }
0
41,452,798
#include <algorithm> #include <cmath> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <cassert> #include <functional> using namespace std; #define LOG(...) printf(__VA_ARGS__) #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define REP(i,n) for(int i=0;i<(int)(n);++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) #define RSORT(c) sort((c).rbegin(),(c).rend()) #define CLR(a) memset((a), 0 ,sizeof(a)) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 }; struct UnionFind { vector<int> v; UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; } int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); } void unite(int x, int y) { v[find(x)] = find(y); } }; int main() { int n; cin >> n; while (n--) { int ans = 196470; int y, m, d; cin >> y >> m >> d; y--; m--; d--; ans -= (y / 3)*(20 * 20 + 19 * 10); ans -= (y % 3)*(20 * 5 + 19 * 5); if(y%3!=2) ans -= (m /2)*(20 + 19); else ans -= (m / 2)*(20 + 20); ans -= (m % 2)*(20); ans -= d; cout << ans << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { string s; string b; int cnt = 0; cin >> s; cin >> b; rep(i, s.size()) { if(s[i] != b[i]) { cnt++; } } cout << cnt << endl; return 0; }
0
91,375,123
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using ld = long double; #define ALL(x) x.begin(),x.end() #define P pair<ll,ll> #define mod 1000000007 int main() { int h, n, a, b; cin >> h >> n; vector<P> magic; vector<ll> cost(h + 1, pow(10, 17)); rep(i, n) { cin >> a >> b; magic.push_back(P(a, b)); } for (int i = 1; i <= h; i++) { for (int j = 0; j < n; j++) { if (magic[j].first >= i) { cost[i] = min(cost[i], magic[j].second); } else { cost[i] = min(cost[i], magic[j].second + cost[i - magic[j].first]); } } } cout << cost[h] << endl; return 0; }
#include <iostream> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; void solve(std::string O, std::string E){ if (O.size() == E.size()) { REP(i, O.size()) cout << O[i] << E[i]; cout << '\n'; } else { char c = O[O.size() - 1]; REP(i, O.size() - 1) cout << O[i] << E[i]; cout << c << '\n'; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); std::string O; std::cin >> O; std::string E; std::cin >> E; solve(O, E); return 0; }
0
67,811,513
#include <bits/stdc++.h> #define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++) #define rep(i,n) rep2(i,0,n) #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) using namespace std; using ll = long long; template <typename T> T sq(T x){ return x * x; } signed main (){ char a,b; cin >> a >> b; bool A_flag , B_flag; if((a == 'H'&& b == 'H')||(a == 'D' && b == 'D')){ cout << 'H' << endl; }else{ cout << 'D' << endl; } return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<cstdint> #include<cstdlib> template<typename T> void fin(T const& t){ std::cout << t << std::endl; exit(0); } template<int64_t Prime> struct mod_int { int64_t v_; mod_int(int64_t x=0) : v_(x) { normalize(); } void normalize() { ((v_ %= Prime) += Prime) %= Prime; } mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; } mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; } mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; } mod_int operator+(mod_int const& r) { mod_int res(*this); return res += r; } mod_int operator-(mod_int const& r) { mod_int res(*this); return res -= r; } mod_int operator*(mod_int const& r) { mod_int res(*this); return res *= r; } mod_int pow(int x) const { int64_t res = 1, v = v_; while(x > 0) { if(x&1) (res *= v) %= Prime; x/=2; (v *= v) %= Prime; } return mod_int(res); } mod_int inv() const { return pow(Prime-2); } }; int64_t const MOD = 1e9+7; typedef mod_int<MOD> mint; int main() { int N, M; std::cin >> N >> M; std::vector<int> S(N), T(M); for(int i = 0; i < N; ++i) std::cin >> S[i]; for(int i = 0; i < M; ++i) std::cin >> T[i]; std::vector<std::vector<mint>> sum(N+1, std::vector<mint>(M+1)); for(int i = 0; i < N; ++i) { for(int j = 0; j < M; ++j) { mint tmp = sum[i][j+1] + sum[i+1][j]; if(S[i] == T[j]) sum[i+1][j+1] = tmp+1; else sum[i+1][j+1] = tmp - sum[i][j]; } } fin((sum[N][M]+1).v_); return 0; }
0
33,443,769
#include<iostream> #include<vector> #include<algorithm> #include<set> #include<queue> #include<map> #include<math.h> #include<string> #include <cctype> #include <cstdlib> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, s, n) for (int i = s; i < (int)(n); i++) #define out(x) cout << x << endl #define INF 1ll<<60; using namespace std; using ll = long long; typedef pair<int, int> P; int main(){ int n, m, x, y; cin >> n >> m >> x >> y; int x_n[n], y_n[m]; rep(i, n) cin >> x_n[i]; rep(i, m) cin >> y_n[i]; bool last_flag=false; for(int i=x+1; i<=y; i++){ bool flag=true; rep(j, n) if(x_n[j]>=i) flag=false; rep(z, m) if(y_n[z]<i) flag=false; if(flag==true) {last_flag=true;} } if(x>y) last_flag=false; if(last_flag==true) out("No War"); else out("War"); }
#include <iostream> int main(){ int a,b; std::cin >> a >> b; std::cout << "a "; if(a==b){ std::cout << "=="; } else if(a<b){ std::cout << "<"; } else{ std::cout << ">"; } std::cout << " b" << std::endl; return 0; }
0
94,858,120
#include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < n; i++) #define repr(i, a, n) for (int i = n - 1; i >= a; i--) using namespace std; using ll = long long; using P = pair<int, int>; template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chmax(T &a, T b) { a = max(a, b); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; ll a = 0; rep(i, 0, m) { int x; cin >> x; a += x; } if (a <= n) cout << n - a << endl; else cout << -1 << endl; }
#ifdef ARYANC403 #include "/home/aryan/codes/PastCodes/template/header.h" #else #pragma GCC optimize ("Ofast") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize ("-ffloat-store") #include<iostream> #include<bits/stdc++.h> #define dbg(args...) #endif using namespace std; #define fo(i,n) for(i=0;i<(n);++i) #define repA(i,j,n) for(i=(j);i<=(n);++i) #define repD(i,j,n) for(i=(j);i>=(n);--i) #define all(x) begin(x), end(x) #define sz(x) ((lli)(x).size()) #define pb push_back #define mp make_pair #define X first #define Y second typedef long long int lli; typedef long double mytype; typedef pair<lli,lli> ii; typedef vector<ii> vii; typedef vector<lli> vi; const auto start_time = std::chrono::high_resolution_clock::now(); void aryanc403() { #ifdef ARYANC403 auto end_time = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> diff = end_time-start_time; cerr<<"Time Taken : "<<diff.count()<<"\n"; #endif } const lli INF = 0xFFFFFFFFFFFFFFFL; lli seed; mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count()); inline lli rnd(lli l=0,lli r=INF) {return uniform_int_distribution<lli>(l,r)(rng);} class CMP {public: bool operator()(ii a , ii b) { return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y )); }}; void add( map<lli,lli> &m, lli x,lli cnt=1) { auto jt=m.find(x); if(jt==m.end()) m.insert({x,cnt}); else jt->Y+=cnt; } void del( map<lli,lli> &m, lli x,lli cnt=1) { auto jt=m.find(x); if(jt->Y<=cnt) m.erase(jt); else jt->Y-=cnt; } bool cmp(const ii &a,const ii &b) { return a.X<b.X||(a.X==b.X&&a.Y<b.Y); } const lli mod = 1000000007L; lli T,n,i,j,k,in,cnt,l,r,u,v,x,y; lli m; string s; vi a; lli ans; bool query(lli x,bool fl=true) { if(fl) x*=1e9; if(x==0) return true; #ifdef ARYANC403 cout<<"? "<<x<<endl; return (x<=ans&&to_string(x)<=to_string(ans))||(x>ans&&to_string(x)>to_string(ans)); #else cout<<"? "<<x<<endl; cin>>s; return s=="Y"; #endif } void solve1() { exit(0); } int main(void) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); { #ifdef ARYANC403 dbg("inp",ans) dbg(ans); #endif { lli cur=0; for(lli i=1;i<=9;++i) { lli l=-1,r=10; while(r-l>1) { lli m=(l+r)/2; if(query(cur*10+m)) r=m; else l=m; } if(l==9) { cur=cur*10+l; continue; } if(r==0) { cur=cur*10; continue; } if(i==1&&r==1) { cur=cur*10+1; continue; } if(query(cur*10+l,false)&&query(cur*10+r,false)) { cur=cur*10+r; break; } cur=cur*10+l; } if(cur==0) cur++; while(cur<1e11&&query(cur*10-1,false)) cur*=10; if(cur!=1) { if(cur>1e10) cur=1; } else { while(!query(cur*10-1,false)) cur*=10; } if(ans%1000000==0) { dbg("upto",ans); } dbg(cur,ans); cout<<"! "<<cur<<endl; } } aryanc403(); return 0; }
0
97,029,594
#include <bits/stdc++.h> using namespace std; int main() { int s, w; cin >> s >> w; if (w >= s) { printf("unsafe"); } else { printf("safe"); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> p_ll; typedef vector<pair<ll, ll>> vec_p; #define REP(i, x) for (ll i = 0; i < (ll)(x); i++) #define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++) #define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--) #define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--) #define all(x) (x).begin(), (x).end() const ll MOD = pow(10, 9) + 7; const ll LLINF = pow(2, 61) - 1; const int INF = pow(2, 30) - 1; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll N=0; string S,T; cin >> S>>T; REP(i,3){ if(S.at(i)==T.at(i)){ N++; } } cout << N << endl; }
0
62,719,494
#include <bits/stdc++.h> using namespace std; #ifdef ENABLE_DEBUG_OUTPUT #define DEBUG_LOG(s) cout << s << endl; #else #define DEBUG_LOG(s) void(); #endif int main(){ int n; cin >> n; vector<map<int, int>> v(2); for (auto i = 0; i < n; i++) { int a; cin >> a; if (i % 2 == 0) v[0][a]++; else v[1][a]++; } vector<int> max_count(4, 0), max_index(4, 0); int ans, index = 0; for (auto & vec : v) { for (auto i = 0; i < 2; i++) { for (auto & elm : vec) { if (max_count[index] < elm.second) { max_count[index] = elm.second; max_index[index] = elm.first; } } vec.erase(max_index[index]); index++; } } if(max_index[0] == max_index[2]) { if(max_count[0] + max_count[3] < max_count[1] + max_count[2]) { ans = n - (max_count[2] + max_count[1]); } else { ans = n - (max_count[3] + max_count[0]); } } else { ans = n - (max_count[0] + max_count[2]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define INF 2e18 #define eps 1e-9 #define FastRead ios_base::sync_with_stdio(0);cin.tie(0) #define fRead freopen("input.txt","r",stdin) #define fWrite freopen("output.txt","w",stdout) #define LL long long #define ull unsigned long long #define PI acos(-1.0) #define pb push_back #define mk make_pair #define pii pair<int,int> #define pLL pair<LL,LL> #define ff first #define ss second #define all(a) a.begin(),a.end() #define SQR(a) ((a)*(a)) #define min3(a,b,c) min(a,min(b,c)) #define max3(a,b,c) max(a,max(b,c)) #define min4(a,b,c,d) min(min(a,b),min(c,d)) #define max4(a,b,c,d) max(max(a,b),max(c,d)) #define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e)) #define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e)) #define vi vector <int> #define vL vector <LL> #define LB(a,x) (lower_bound(all(a),x)-a.begin()) #define UB(a,x) (upper_bound(all(a),x)-a.begin()) #define prec(n) fixed << setprecision(n) #define MEM(a,x) memset(a,x,sizeof(a)) #define SORT(v) sort(v.begin(),v.end()) #define REV(v) reverse(v.begin(),v.end()) #define Unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define ROF(i,a,b) for(int i=a;i>=b;i--) #define REP(i,b) for(int i=0;i<b;i++) #define IT(it,x) for(it=x.begin();it!=x.end();it++) LL mp[100]; const LL mod=(1e9)+7; int main() { LL n; cin>>n; for(LL i=0; i<n; i++) { LL x; cin>>x; for(LL i=0;i<62;i++) { if(x&(1LL<<i)) mp[i]++; } } LL ans=0; for(LL i=0;i<60;i++) { LL x=mp[i]; LL y=n-x; LL z=1LL<<i; ans+=(((x*y)%mod)*(z%mod))%mod; ans=ans%mod; } cout<<ans; }
0
93,293,313
#include <bits/stdc++.h> using namespace std; int main() { vector<int> n(3); cin >> n[0] >> n[1] >> n[2]; sort(n.begin(), n.end(), greater<int>()); cout << n[0] * 10 + n[1] + n[2]; }
#include <bits/stdc++.h> #define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a) #define rep2(i, s, n) rep3(i, s, n, 1) #define rep(i, n) rep2(i, 0, n) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; int main(){ int n, m; cin >> n >> m; vector<int> q, P, Y; vector<vector<int>> vq(n+1, q); rep(i, m){ int p, y; cin >> p >> y; P.push_back(p); Y.push_back(y); vq[p].push_back(y); } rep2(i, 1, n+1){ sort(vq[i].begin(), vq[i].end()); } rep(i, m){ int nowp = P[i], digp=0; while(nowp){ nowp /= 10; digp++; } auto it = lower_bound(vq[P[i]].begin(), vq[P[i]].end(), Y[i]); int x = it - vq[P[i]].begin() + 1, digx=0; while (x) { x /= 10; digx++; } rep(j, 6-digp){ cout << 0; } cout << P[i]; rep(j, 6-digx){ cout << 0; } cout << it - vq[P[i]].begin() + 1<< endl; } return 0; }
0
28,943,285
#include<iostream> #include<vector> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int main() { vector<int> q(3); rep(i,3) cin>>q[i]; int choose=2; int min=1<<23; for (int bit = 0; bit < (1<<3); bit++) { int cnt=0; int buf=0; for (int i = 0; i < 3; i++) { if(bit & (1<<i)) { buf+=q[i]; cnt++; } } if(cnt!=choose)continue; if(min>buf) min=buf; } cout<<min<<endl; return 0; }
#pragma target("avx") #pragma optimize("O3") #include<bits/stdc++.h> using ll = int_fast64_t; using P = std::pair<ll,ll>; using PP = std::pair<ll,P>; 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 ALL(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 n, a, b, c, l[8]; int rec(int A, int B, int C, int x, int mp){ x--; if(x<0){ if(A*B*C==0) return 1e9; return mp + abs(a-A) + abs(b-B) + abs(c-C) - 30; } return std::min({ rec(A+l[x], B, C, x, mp+10), rec(A, B+l[x], C, x, mp+10), rec(A, B, C+l[x], x, mp+10), rec(A, B, C, x, mp) }); } int main(){ scanf("%d %d %d %d", &n, &a, &b, &c); REP(i, 0, n) scanf("%d", &l[i]); printf("%d\n", rec(0, 0, 0, n, 0)); return 0; }
0
3,199,935
#include <iostream> #include<algorithm> using namespace std; int main() { int n; cin>>n; int arr[n]; for (int i=0; i<n; i++){ cin>>arr[i]; } sort(arr, arr+n); int z = 0; for (int i=0; i<n; i++){ int cnt = 0; for (int j=0; j<n; j++){ if (arr[j]==arr[i]) cnt++; else if (arr[j] ==arr[i]-1) cnt++; else if (arr[j]==arr[i]+1) cnt++; } z = max(cnt, z); } cout << z; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n{0}; cin>>n; ll arr[n]; for(ll i=0;i<n;i++) cin>>arr[i]; ll money=1000; ll start{0}; for(ll i=0;i<n-1;i++){ if(arr[i+1]>arr[i]){ continue; } else{ ll stocks=money/arr[start]; money=(money%arr[start])+(stocks*arr[i]); start=i+1; } } if(start!=n-1){ ll stocks=money/arr[start]; money=(money%arr[start])+(stocks*arr[n-1]); } cout<<money<<endl; return 0; }
0
36,325,570
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() typedef long long ll; #define _GLIBCXX_DEBUG typedef vector<int> vec; typedef vector<ll> lvec; typedef vector<char> cvec; typedef vector<double> dvec; typedef pair<ll, ll> LP; typedef tuple<ll, ll, ll> LT; typedef pair<int, int> P; typedef tuple<int, int, int> T; #define fs first #define sc second int main() { string s; cin>>s; vector<int>num(4); rep(i,4) num[i]=s[i]-'0'; for(int tmp=0;tmp<(1<<3);tmp++){ int sum=num[0]; string s; s=(char)('0'+num[0]); bitset<3>t(tmp); rep(i,3){ if(t.test(i)){ sum+=num[i+1]; s+='+'; s+=(char)('0'+num[i+1]); } else{ sum-=num[i+1]; s+='-'; s+=(char)('0'+num[i+1]); } } if(sum==7){ s+="=7"; cout<<s<<endl; return 0; } } }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cassert> #include <functional> #include <algorithm> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> using namespace std; using llong = long long; llong k; llong a[100005]; llong res(llong x) { for (int i = 0; i < k; i++) { x -= x % a[i]; } return x; } int main() { cin >> k; for (int i = 0; i < k; i++) { cin >> a[i]; } llong minv; llong maxv; { llong valid, invalid; valid = 1ll << 60ll; invalid = 0; while (valid - invalid > 1) { llong mid = (valid + invalid) / 2; if (res(mid) >= 2) { valid = mid; } else { invalid = mid; } } minv = valid; } { llong valid, invalid; valid = 0; invalid = 1ll << 60ll; while (invalid - valid > 1) { llong mid = (valid + invalid) / 2; if (res(mid) > 2) { invalid = mid; } else { valid = mid; } } maxv = valid; } if (res(minv) != 2) cout << -1 << endl; else cout << minv << ' ' << maxv << endl; return 0; }
0
13,591,528
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(),v.end() #define _GLIBCXX_DEBUG using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vd = vector<double>; using vvi = vector<vi>; using vvll = vector<vll>; using vvd = vector<vd>; using vvvi = vector<vvi>; using vvvll = vector<vvll>; using vvvd = vector<vvd>; const double pi=3.141592653589793; const ll MOD=1e9+7; int n; ll p[51]; ll b[51]; ll solve(int x,ll y){ if (y==0){ return 0; } if (y==1 && x==0){ return 1; } if (y==1){ return 0; } else if (y<=b[x-1]+1){ return solve(x-1,y-1); } else if (y==b[x-1]+2){ return p[x-1]+1; } else if (y<=2*b[x-1]+2){ return solve(x-1,y-2-b[x-1])+p[x-1]+1; } else{ return p[x-1]*2+1; } } int main() { cin>>n; ll x; cin>>x; p[0]=1; b[0]=1; rep(i,n){ p[i+1]=2*p[i]+1; b[i+1]=2*b[i]+3; } ll ans=solve(n,x); cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll a,b; int main() { int q;scanf("%d",&q); while(q--) { scanf("%lld%lld",&a,&b); ll s=a*b,ans; ll t=sqrt(s); if(t*(t+1)<s) ans=2*(t-1)+1; else ans=2*(t-1); if(t*t==s&&a!=b) ans--; if(a*b==4) ans=1; printf("%lld\n",ans); } }
0
6,483,059
#include<stdio.h> #include<string.h> char in[13]; int hash[10000000]; int n; void insert(void); void find(void); int gethash(void); int Getchar(char); int main(){ char ins[7]; scanf("%d",&n); while(n--){ scanf("%s%s",ins,in); if(ins[0]=='i'){ insert(); }else{ find(); } } return 0; } void insert(){ hash[gethash()] = 1; } void find(){ if(hash[gethash()]==1) printf("yes\n"); else printf("no\n"); } int gethash(void){ int hash=0,i,p=1; for(i=0;i<strlen(in);i++){ hash += p*(Getchar(in[i])); p *= 4; } return hash; } int Getchar(char in){ if(in=='A')return 1; else if(in=='C')return 2; else if(in=='G')return 3; else return 4; }
#include <stdio.h> #define maxn 100010 struct node{ int to,next; }e[maxn<<1]; int h[maxn],head[maxn],tot,cnt; void add_edge(int u,int v){ tot++,e[tot].to=v,e[tot].next=head[u],head[u]=tot; } int main(){ int n,m,u,v,i,b,flag1,flag2; scanf("%d%d",&n,&m); for(i=1;i<=n;i++)scanf("%d",&h[i]); for(i=1;i<=m;i++){ scanf("%d%d",&u,&v); add_edge(u,v),add_edge(v,u); } for(i=1;i<=n;i++){ flag1=0,flag2=0; for(b=head[i];b;b=e[b].next){ flag1=1,v=e[b].to; if(h[i]<=h[v]){flag2=1;break;} } if(!flag1)cnt++; else if(!flag2)cnt++; } printf("%d\n",cnt); return 0; }
0
8,757,604