code1
stringlengths
54
12k
code2
stringlengths
71
12k
similar
int64
0
1
__index_level_0__
int64
0
101M
#include <iostream> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> c(m), results(n+1); for (int i = 0; i < m; ++i) cin >> c[i]; results[0] = 0; for (int i = 1; i <= n; ++i) { results[i] = n + 1; for (int j = 0; j < m; ++j) { if (i >= c[j]) { int tmpCoins = results[i - c[j]] + 1; if (tmpCoins < results[i]) results[i] = tmpCoins; } } } cout << results[n] << endl; }
#include<bits/stdc++.h> #define INF 999999999 using namespace std; const int MAX_N = 50000; const int MAX_M = 20; int dp[MAX_M+1][MAX_N+1]; int c[MAX_N]; int main() { int n,m; cin >> n >> m; for(int i=0;i<m;i++){ cin >> c[i]; } for(int i=0;i<=m;i++){ dp[i][0] = 0; } for(int j=0;j<=n;j++){ dp[0][j] = INF; } for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ if(j>=c[i-1]){ dp[i][j] = min(dp[i-1][j],dp[i][j-c[i-1]] + 1); }else{ dp[i][j] = dp[i-1][j]; } } } cout << dp[m][n] << "\n"; }
1
53,121,970
#include <bits/stdc++.h> using namespace std; int main(void){ string s, t; cin >> s >> t; sort(s.begin(), s.end()); sort(t.begin(), t.end()); reverse(t.begin(), t.end()); bool flag = true; for (int i=0; i<min(s.size(), t.size()); i++) { if (s.at(i) != t.at(i)) flag = false; } if (s < t || (flag && s.size() < t.size())) cout << "Yes" << endl; else cout << "No" << 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++) int main(){ string s, t; cin >> s >> t; sort(s.begin(),s.end()); sort(t.begin(),t.end()); reverse(t.begin(),t.end()); bool ans=false; if(s.size()<t.size()){ ll flg=0; rep(i,0,s.size()){ if(s[i]==t[i])flg++; else if(s[i]<t[i]){ans=true;break;} } if(flg==s.size()) ans=true; } if(min(s.size(),t.size())>=1) { rep(i,0,min(s.size(),t.size())){ if(s[i]==t[i])continue; else if(s[i]<t[i])ans=true; } } cout << (ans ? "Yes":"No") << endl; return 0; }
1
83,111,712
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define bit(n) (1<<(n)) #define ii(x) int x; cin >> (x) #define ii2(x, y) int x, y; cin >> (x) >> (y) #define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z) #define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<bool> vb; typedef pair<int, int> pii; typedef pair<ll, ll> pll; 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;} ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} int const INF = 1001001001; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; stack<char> st; rep(i,n) { if(!st.empty() && st.top() == '(') { if(s[i] == ')') { st.pop(); } else { st.push(s[i]); } } else st.push(s[i]); } int cntl = 0, cntr = 0; while(!st.empty()) { char c = st.top(); if(c == '(') cntl++; if(c == ')') cntr++; st.pop(); } rep(i,cntr) { s = '(' + s; } rep(i,cntl) { s = s + ')'; } cout << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++) typedef pair<int, int> P; int main() { int n; cin >> n; string s; cin >> s; list<char> C; for (auto &&c: s) C.push_back(c); int depth = 0; int min_ = 1000000; for (auto &&c: s) { if (c == '(') depth++; else depth--; min_ = min(min_, depth); } while (min_++ < 0) C.push_front('('); depth = 0; for (auto &&c: C) { if (c == '(') depth++; else depth--; } while (depth-- > 0) C.push_back(')'); for (auto&&c: C) cout << c; cout << endl; return 0; }
1
13,021,212
#define LOCAL #include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<(n); ++i) #define rrep(i, n) for(int i=(n-1); i>=0; --i) #define rep2(i, s, n) for(int i=s; i<(n); ++i) #define ALL(v) (v).begin(), (v).end() #define memr(dp, val) memset(dp, val, sizeof(dp)) using namespace std; typedef long long ll; static const int INTINF = (INT_MAX >> 1); static const ll LLINF = (LLONG_MAX >> 1); static const int MAX = 100001; static const ll MOD = 1000000007; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; } template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >; string to_string(string s) { return '"' + s + '"'; } string to_string(bool b) { return b ? "true" : "false"; } template <size_t N> string to_string(bitset<N> bs) { string res; for (size_t i = 0; i < N; ++i) res += '0' + bs[i]; return res; } string to_string(vector<bool> v) { string res = "{"; for (bool e : v) res += to_string(e) + ", "; return res += "}"; } template <class T, class U> string to_string(pair<T, U> p); template <class C> string to_string(C c) { string res = "{"; for (auto e : c) res += to_string(e) + ", "; return res += "}"; } template <class T, class U> string to_string(pair<T, U> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void debug() { cerr << '\n'; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << '\t' << to_string(head), debug(tail...); } #ifdef LOCAL #define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) #else #define print(...) #endif int main(int argc, const char * argv[]) { std::cout << std::fixed << std::setprecision(15); string str; cin >> str; int ans = 0; int k = 0; while(1){ if(k > str.size() / 2) break; int rev_k = str.size() - 1 - k; if(str[k] != str[rev_k]){ if(str[k] != 'x' && str[rev_k] != 'x'){ cout << -1 << endl; return 0; } else if(str[k] == 'x'){ str.insert(str.begin() + rev_k + 1, 'x'); ans++; } else{ str.insert(str.begin() + k, 'x'); ans++; } } k++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<long long,long long> pll; #define ep emplace_back #define pb push_back #define mp make_pair #define rep(i,n) for(int i=0;i<(n);++i) constexpr int mod=1000000007; constexpr int mod1=998244353; vector<int> dx={0,1,0,-1},dy={-1,0,1,0}; bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; } 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(){ cin.tie(0); ios::sync_with_stdio(false); string s;cin >> s; int n = s.size(); bool ok = true; rep(i,n / 2){ if(s.at(i) != s.at(n - 1 - i)){ ok = false; break; } } if(ok){ cout << 0 << endl; return 0; } string t = ""; rep(i,n){ if(s.at(i) != 'x') t += s.at(i); } int m = t.size(); ok = true; rep(i,m / 2){ if(t.at(i) != t.at(m - 1 - i)){ ok = false; break; } } if(!ok){ cout << -1 << endl; return 0; } int ans = 0; int i = 0, j = n - 1; while(i < j){ int cnt1 = 0, cnt2 = 0; while(s.at(i) == 'x'){ i++; cnt1++; } while(s.at(j) == 'x'){ j--; cnt2++; } if(i > j) break; ans += abs(cnt1 - cnt2); i++; j--; } cout << ans << endl; }
1
64,965,508
#include <iostream> #include <vector> using namespace std; void print(vector<vector<int>> &A, int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (j > 0) cout << " "; cout << A[i][j]; } cout << endl; } } int main() { int n; cin >> n; int id; int num; vector<vector<int>> A(n, vector<int>(n)); for (int i = 0; i < n; i++) { cin >> id >> num; if (num == 0) continue; else { int tmp; for (int j = 0; j < num; j++) { cin >> tmp; A[id - 1][tmp - 1] = 1; } } } print(A, n); return 0; }
#include <iostream> #include <vector> #include <cmath> #include <string> #include <algorithm> #include <iomanip> #include <map> #include <bitset> #include <cstdio> #include <set> #include <stack> #include <queue> #include <cassert> #include <numeric> using namespace std; typedef long long ll; #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++) #define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__) #define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__) template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; } template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;} template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;} #define vi vector<int> #define vii vector<vector<int>> #define mii map<int,int> #define Sort(v) sort(v.begin(),v.end()) #define Reverse(v) reverse(v.begin(),v.end()) #define ALL(a) (a).begin(),(a).end() #define pb push_back #define mp make_pair const int md = 1000000007; const int INF = 1<<30; int main(){ int n; cin >> n; vector<vector<int>> e(n,vector<int>(n,0)); rep(i,n){ int a; cin >> a; int tmp; cin >> tmp; rep(j,tmp) { int to; cin >> to; e[i][to-1] = 1; } } cout << e << endl; }
1
65,158,230
#include <iostream> #include <iomanip> #include <vector> #include <string> #include <cmath> #include <map> #include <climits> #include <cassert> #include <algorithm> #include <utility> using namespace std; using Int = long long int; using UInt = unsigned long long int; using VI = vector<long long int>; using VVI = vector<vector<long long int> >; int main(void) { Int a, b, c; cin >> a >> b >> c; if (a == b && b == c) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(),(x).end() #define sq(x) ((x)*(x)) #define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++) #define EQ(a,b) (abs((a)-(b))<eps) template<class T> void chmin(T& a,const T& b){if(a>b)a=b;} template<class T> void chmax(T& a,const T& b){if(a<b)a=b;} int A,B,C; bool check(int a,int b,int c){ return a==b; } int main(){ cin >> A >> B >> C; if(check(A,B,C)&&check(B,C,A)&&check(C,A,B))cout << "Yes" << endl; else cout << "No" << endl; return 0; }
1
59,254,494
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; typedef long long ll; ll mypow(ll x, ll n){ if(n == 0) return 1; if(n % 2 == 0) return mypow(x * x, n / 2); else return x * mypow(x, n - 1); } const ll num = mypow(10,9); const ll num2 = mypow(10, 17); int main() { ll s; cin >> s; if(s == mypow(10,18)){ cout << 0 << " " << 0 << " " << num << " " << 0 << " " << 0 << " " << num << endl; return 0; } if (s <= num){ cout << 0 << " "<< 0 << " " << s << " " << 0 << " " << 0 << " "<< 1 << endl; }else { ll sqrt_num = sqrt(s); sqrt_num++; ll tmp = s - sqrt_num * sqrt_num; cout << 0 << " " << 0 << " " << sqrt_num << " " << 1 << " " << abs(tmp) << " " << sqrt_num << endl; } }
#include <bits/stdc++.h> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int INF = 1<<30; const ll mod = 1000000007LL; int main() { ll S; cin>>S; ll t = (S-1LL)/1000000000LL+1LL; cout<<0<<" "<<0<<" "<<t<<" "<<1<<" "<<t*1000000000-S<<" "<<1000000000<<endl; }
1
63,814,483
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <string> #include <numeric> using namespace std; void func() { string S, T; cin >> S; cin >> T; if (1 > S.length() || S.length() > 10) { cout << "No\n"; return; } if(S.length() + 1 != T.length()) { cout << "No\n"; return; } for (int i = 0; i < S.length(); ++i) { if(!islower(S[i]) || S[i] != T[i]) { cout << "No\n"; return; } } if (!islower(*T.rbegin())) { cout << "No\n"; return; } cout << "Yes\n"; return; } int main() { func(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S, T; cin >> S; cin >> T; bool result = true; for (int i = 0; i < S.size(); i++) { if (S.at(i) != T.at(i)) { result = false; break; } } if(result) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
1
81,780,559
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; } int main(){ ll N; cin >> N; vector<ll> A(N, 0); vector<ll> B(N, 0); for(int i = 0; i < N; i++){ cin >> A[i] >> B[i]; } ll ans = 0; for(int i = N - 1; i >= 0; i--){ A[i] += ans; if(A[i] % B[i] != 0){ if(A[i] > B[i]){ B[i] = B[i] * ((A[i] / B[i])+ 1); } ans += B[i] - A[i]; } } cout << ans << endl; }
#include"bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using pi = pair<int, int>; const ll INF = 1LL << 60; int main() { int n; cin >> n; vector<int>A(n), B(n); rep(i, n)cin >> A[i] >> B[i]; ll btn = 0; if (A[n - 1] % B[n - 1] != 0)btn = ll((B[n - 1] * ceil(double(A[n - 1]) / double(B[n - 1]))) - A[n - 1]); for (int i = n - 2; i >= 0; i--) { if ((A[i] + btn) % B[i] != 0)btn += ll((B[i] * ceil(double(A[i] + btn) / double(B[i]))) - (A[i]+ btn)); } cout << btn << endl; return 0; }
1
5,893,632
#include <bits/stdc++.h> #include <vector> #include <algorithm> #include <iostream> using namespace std; int main() { int N, K, ans; cin >> N >> K; ans=0; vector<int> h(N); for (int i=0; i<N; i++) { cin >> h.at(i); } for (int j=0; j<N; j++) { if (h.at(j)>=K) { ans=ans+1; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) const ll mod = 1000000007; int main() { int N, K, ans; cin >> N >> K; ans = 0; rep(i, N){ int h; cin >> h; if(h >= K){ ans++; } } cout << ans << endl; return 0; }
1
26,370,540
#include <iostream> #include <climits> #include <set> #include <string> #include <algorithm> #include <vector> #define MAX 1000000007 using namespace std; #define ll long long #define dbg if(0) int main(){ ll n; do{ cin >>n; if (n==0)break; int mtown=0; ll g[10][10]; for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ g[i][j]=INT_MAX; } g[i][i]=0; } for(int i=0;i<n;i++){ int a,b,c; cin>>a>>b>>c; mtown=max(a,max(mtown,b)); g[a][b]=c; g[b][a]=c; } for(int k=0;k<10;k++){ for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ g[i][j]=min(g[i][j],g[i][k]+g[k][j]); } } } dbg{ for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ cout <<g[i][j]<<" "; } cout <<endl; } } ll ans=INT_MAX; ll ansid=11; for(int i=0;i<=mtown;i++){ ll cand=0; for(int j=0;j<=mtown;j++){ if (g[i][j]==INT_MAX)break; cand+=g[i][j]; } if(ans>=cand){ if (cand==ans){ ansid=min((ll)i,ansid); }else{ ans=cand; ansid=i; } } } cout <<ansid<<" "<<ans<<endl; }while(1); return 0; }
#include <bits/stdc++.h> using namespace std; int a[110][110]; int vis[110]; int n, x, y, z; int main() { while(1) { scanf("%d", &n); if (n == 0) break; memset(a, 0, sizeof(a)); for(int i=0; i<=9; i++) for(int j=0; j<=9; j++) a[i][j] = 100000; for(int i=0; i<=9; i++) a[i][i] = 0; memset(vis, 0, sizeof(vis)); for(int i=1; i<=n; i++) { scanf("%d%d%d", &x, &y, &z); a[x][y] = min(a[x][y], z); a[y][x] = min(a[y][x], z); vis[x] = 1; vis[y] = 1; } for(int i=0; i<=9; i++) for(int j=0; j<=9; j++) for(int k=0; k<=9; k++) { if (a[j][i] + a[i][k] < a[j][k]) a[j][k] = a[j][i] + a[i][k]; } int ans1 = -1; int ans2 = 0; for(int i=0; i<=9; i++) { if (vis[i] == 0) continue; int sum = 0; for(int j=0; j<=9; j++) sum += a[i][j] * vis[j]; if (sum < ans2 || ans1 == -1) {ans1 = i; ans2 = sum;} } cout<<ans1<<' '<<ans2<<endl; } }
1
47,220,645
#include <iostream> using namespace std; int main(){ int n, x; int cnt; while(true){ cnt = 0; cin >> n >> x; if(n==0 && x==0) break; for(int i=1;i<n-1;i++){ for(int j=i+1; j<n;j++){ for(int k=j+1; k<n+1; k++){ if(i+j+k==x){ cnt++; } } } } cout << cnt << endl; } }
#include <iostream> using namespace std; int main(int argc, const char * argv[]) { int n,x,ans=0; while (1) { cin >> n >> x; if (n==0 && x==0) { break; } for (int i=1; i<n+1; i++) { for (int j=i+1; j<n+1; j++) { for (int k=j+1; k<n+1; k++) { if (i+j+k == x) { ans++; } } } } cout << ans <<endl; ans = 0; } return 0; }
1
72,325,144
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; int K; cin>>K; vector<long long> H(N); for(int i=0;i<N;i++){ cin>>H[i]; } sort(H.begin(), H.end()); reverse(H.begin(), H.end()); long long a=0; for(int i=K;i<N;i++){ a+=H[i]; } cout<<a<<endl; return 0; }
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ long long N, K; long long H_tmp; long long sum = 0; long long sum_tgt = 0; std::cin >> N >> K; vector<long long> mons_list(N); if(K >= N){ goto finish; } for(long long i = 0; i < N; i++){ std::cin >> H_tmp; sum = sum + H_tmp; mons_list[i] = H_tmp; } std::sort(mons_list.begin(), mons_list.end(), std::greater<long long>()); for(long long i = 0; i < K; i++){ sum_tgt = sum_tgt + mons_list[i]; } sum = sum - sum_tgt; finish: std::cout << sum; }
1
65,403,283
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdlib> #include <utility> using namespace std; int main() { pair<int, int> x; pair<int, int> y; cin >> x.first >> x.second >> y.first >> y.second; int a = max(x.first, y.first); int b = min(x.second, y.second); if (b - a < 0) { cout << 0 << endl; } else { cout << b - a << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int,int> pi; #define F first #define S second #define PB push_back #define MP make_pair #define FOR(i,a,b) for (int i = a; i < b; i++) #define SQ(a) (a)*(a) template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; } template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; } template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; } const double PI = 3.141592653589793238463; int main() { ios::sync_with_stdio(0); cin.tie(0); int a, b, c, d; cin >> a >> b >> c >> d; int bot = max(a,c); int top = min(b,d); cout << max(top - bot,0); cout << endl; }
1
29,167,260
#include <bits/stdc++.h> using namespace std; #define modulo 998244353 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 100000000 int main(){ int N; cin>>N; vector<int> C(N+1,0); for(int i=0;i<N;i++){ int a; cin>>a; C[a]++; } sort(C.begin(),C.end()); C.insert(C.begin(),0); auto S = C; for(int i=1;i<C.size();i++)S[i]+=S[i-1]; vector<int> ans(N+1,0); for(int i=1;i<=N;i++){ int ind = distance(C.begin(),lower_bound(C.begin(),C.end(),i)); int cnt = 0; if(ind!=0)cnt += S[ind-1]; cnt += i*(C.size()-ind); cnt/=i; cnt = min(cnt,N); if(cnt>=0)ans[cnt] = i; } for(int i=N-1;i>=0;i--)ans[i] = max(ans[i],ans[i+1]); for(int i=1;i<=N;i++)cout<<ans[i]<<endl; return 0; }
#include<bits/stdc++.h> #define REP(i,s,n) for(int i=s;i<n;++i) #define rep(i,n) REP(i,0,n) #define ALL(x) x.begin(),x.end() #define EPS (1e-8) #define equals(a,b) (fabs((a)-(b))<EPS) using namespace std; typedef long long ll; bool LTE(double a,double b) { return equals(a,b) || a < b; } bool LT(double a,double b) { return !equals(a,b) && a < b; } #define MAX 310000 int N, A[MAX]; vector<int> convert() { map<int,int> mp; rep(i,N) ++mp[A[i]]; vector<int> C; for(auto v : mp) C.push_back(v.second); sort(ALL(C)); return C; } vector<int> C; ll sum[MAX]; bool check(ll ans, ll K) { int ptr = lower_bound(ALL(C), ans) - C.begin(); --ptr; int rem = (int)C.size() - 1 - ptr; ll sigma = sum[ptr] + (ll)rem * ans; return sigma >= ans * K; } void compute() { C = convert(); sum[0] = C[0]; REP(i,1,(int)C.size()) sum[i] = sum[i-1] + C[i]; REP(K,1,N+1) { ll L = 1, R = N+1; while( R - L ){ ll ans = ( L + R ) / 2LL; if( check(ans,K) ) L = ans + 1LL; else R = ans; } cout << L - 1LL << endl; } } int main() { cin >> N; rep(i,N) cin >> A[i]; compute(); return 0; }
1
45,312,347
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n; string t[10]; t[1] = ".,!? "; t[2] = "abc"; t[3] = "def"; t[4] = "ghi"; t[5] = "jkl"; t[6] = "mno"; t[7] = "pqrs"; t[8] = "tuv"; t[9] = "wxyz"; int cc=0; while(cin>>n){ cc++; string s[n]; string ans=""; int cnt=0; for(int i=0;i<n;i++)cin>>s[i]; for(int i=0;i<n;i++){ ans=""; for(int j=0;j<s[i].length()-1;j++){ cnt=0; bool fl = false; while(1){ if(s[i][j]=='0'){ j++; if(j>(s[i].length()-1)){ fl=true; break; } continue; } if(s[i][j]==s[i][j+1]){ cnt++;j++; } if(s[i][j+1]=='0'){ break; } } if(fl)break; int tmp = s[i][j]-'0'; ans += t[tmp][(cnt)%t[tmp].length()]; j++; } cout<<ans<<endl; } if(cc==n)break; } }
#include <iostream> using namespace std; int main(){ string keys[] = { "", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz", }; int n; string s; int kind; int cur; cin >> n; for( int lp=0;lp<n;lp++ ){ cin >> s; cur=-1; for( unsigned int i=0;i<s.length();i++ ){ if( s[i]=='0' ){ if( cur>=0 ){ cout << keys[ kind][cur%keys[kind].length() ] ; cur=-1; } }else{ if( cur<0 ){ kind = s[i] - '0'; cur=0; }else cur++; } } cout << endl; } return 0; }
1
30,415,775
#include<bits/stdc++.h> using namespace std; #define PI 3.1415926536 #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define REP(i,n) for(i=0;i<n;i++) #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void c_p_c() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { FIO; int n; cin >> n; cout << (n * (n - 1)) / 2; }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ ll N,sum; cin>>N; sum=N*(N+1)/2-N; cout<<sum<<endl; return 0; }
1
90,061,725
#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, cost; }; 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; } vector<bool> IsPrime; void sieve(size_t max){ if(max+1 > IsPrime.size()){ IsPrime.resize(max+1,true); } IsPrime[0] = false; IsPrime[1] = false; for(size_t i=2; i*i<=max; ++i){ if(IsPrime[i]){ for(size_t j=2; i*j<=max; ++j){ IsPrime[i*j] = false; } } } } ll modpow(ll a, ll n){ ll res = 1; while(n){ if(n & 1){ res = res * a % MOD; } a = a * a % MOD; n = n >> 1; } return res; } ll MAXN = 2e5+10; vector<ll> inv(MAXN); ll nCk(ll n, ll k) { ll res = 1; for(ll i = 1; i <= k; i++) { res = res*(n-i+1) % MOD; } for(ll i = 1; i <= k; i++) { res = res*inv[i] % MOD; } return res; } 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 h, n; cin>>h>>n; vector<pair<ll, ll>> a(n); for(ll i=0;i<n;++i){ ll A, B; cin>>A>>B; a[i] = make_pair(A, B); } vector<vector<ll>> dp(n+1, vector<ll> (h+1, INF)); for(ll i=0;i<=n;++i){ dp[i][0] = 0; } for(ll i=0;i<n;++i){ for(ll j=0;j<=h;++j){ if(j - a[i].first < 0){ dp[i+1][j] = min(dp[i][j], dp[i+1][0] + a[i].second); }else{ dp[i+1][j] = min(dp[i][j], dp[i+1][j - a[i].first] + a[i].second); } } } ll ans = dp[n][h]; cout<<ans<<endl; return 0; }
#include"bits/stdc++.h" using namespace std; typedef long long ll; #define int ll const int inf=1e18; int32_t main() { #ifndef ONLINE_JUDGE freopen("in","r", stdin); freopen("out","w",stdout); #endif int h,n; cin>>h>>n; vector<int> dp(h+1, inf); dp[h]=0;int a,b; for(int i=0;i<n;i++) { cin>>a>>b; for(int j=h;j>=0;j--) { int x=min(a,j); dp[j-x]=min(dp[j]+b,dp[j-x]); } } cout<<dp[0]; }
1
23,410,075
#include <bits/stdc++.h> #define PI 3.1415926535897 using namespace std; typedef long long ll; const int INF = 1000000000; const ll LINF = 1000000000000000000; const double EPS = 1e-10; int main(void) { int N; cin >> N; N++; vector<int> time(N); vector<int> x(N); vector<int> y(N); time[0] = 0; x[0] = 0; y[0] = 0; for (int i = 1; i < N; i++) { cin >> time[i] >> x[i] >> y[i]; } int turn; int diff_x; int diff_y; int dis; for (int i = 0; i < N - 1; i++) { turn = time[i + 1] - time[i]; diff_x = abs(x[i + 1] - x[i]); diff_y = abs(y[i + 1] - y[i]); dis = diff_x + diff_y; if (turn < dis) { cout << "No" << endl; return (0); } else { int diff = turn - dis; if (diff % 2 == 0) { continue; } else { cout << "No" << endl; return (0); } } } cout << "Yes" << endl; return (0); }
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int N; int t[110000]; int x[110000]; int y[110000]; t[0]=0; x[0]=0; y[0]=0; cin >> N; for (int i = 1; i < N+1; i++) { cin >> t[i] >> x[i] >> y[i]; } bool flag=true; for (int i = 1; i < N+1; i++) { int dist=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]); int tdist = t[i] - t[i-1]; if(tdist>=dist){ if(tdist%2 == 0){ if(dist%2 != 0){ flag=false; break; } }else{ if(dist%2 != 1){ flag=false; break; } } }else{ flag=false; break; } } if(flag) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
1
11,399,499
#include <bits/stdc++.h> using namespace std; using str = string; using ss = stringstream; int main() { cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; map<str, int> m; bool ans=true; str bw=""; for(int i=0;i<n;i++) { str w; cin>>w; if(bw!="") { if(bw[bw.size()-1]!=w[0]) { ans=false; break; } } bw=w; if(m[w]>0) { ans=false; break; } m[w]++; } puts(ans?"Yes":"No"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef pair<ll, P> PP; static const double EPS = 1e-8; static const double PI = 4.0 * atan(1.0); static const ll INF = 1023456789; #define REP(i,n) for(int i=0;i<n;++i) #define REPR(i,n) for(int i=n-1;i>=0;--i) #define FOR(i,s,n) for(int i=s;i<n;++i) #define FORR(i,s,n) for(int i=n-1;i>=s;--i) #define ALL(c) (c).begin(),(c).end() #define CLEAR(v) memset(v,0,sizeof(v)) #define MP(a,b) make_pair((a),(b)) #define ABS(a) ((a)>0?(a):-(a)) #define F first #define S second int main(int argc, char **argv) { ll n; string s, t; cin >> n >> s; set<string> used; used.insert(s); REP(i, n-1) { cin >> t; if (s[s.length()-1] != t[0] || used.count(t) != 0) { cout << "No" << endl; return 0; } s = t; used.insert(t); } cout << "Yes" << endl; return 0; }
1
23,057,549
#ifdef DEBUG #include "../utils.cpp" #endif #include <bits/stdc++.h> using namespace std; using ll = int64_t; #define int int64_t #define INF 10e9 void solve(); void getInput(); int N; vector<int> L, R; vector<vector<int>> dp; void getInput() { cin>>N; L = vector<int>(N, 0); R = vector<int>(N, 0); dp = vector<vector<int>>(N, vector<int>(N, 1e9)); for(int i=0; i<N; ++i) { cin>>L[i]>>R[i]; } } void solve() { for(int i=0; i<N; ++i) { dp[i][i] = 0; } for(int i=0; i+1<N; ++i) { dp[i][i+1] = L[i]*R[i]*R[i+1]; } for(int i=2; i<N; ++i) { for(int j=0; i+j < N; ++j) { for(int k = 0; k<i; ++k) { int p = L[j]; int q = R[j+k]; int r = R[j+i]; dp[j][j+i] = min(dp[j][j+i], p*q*r + dp[j][j+k] + dp[j+k+1][j+i]); } } } cout<<dp[0][N-1]<<endl; } signed main(){ getInput(); solve(); return 0; }
#include <iostream> #include <limits> #include <utility> #include <vector> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> v; for (int i = 0; i < n; ++i) { int r, c; cin >> r >> c; v.emplace_back(r, c); } vector<vector<int>> dp(n, vector<int>(n, numeric_limits<int>::max())); for (int i = 0; i < n; ++i) { dp[i][i] = 0; } auto cost = [&v](int i, int k, int j) { return v[i].first * v[k].second * v[j].second; }; for (int l = 2; l <= n; ++l) { for (int i = 0; i < n - l + 1; ++i) { int j = i + l - 1; for (int k = i; k < j; ++k) { dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + cost(i, k, j)); } } } cout << dp[0][n - 1] << endl; }
1
61,664,850
#include<iostream> using namespace std; int main(){ int x,y; for (int i = 0; i+= 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; }
#include <iostream> int main(int argc, char *argv[]) { int x, y, t; while (std::cin >> x >> y) { if (x == 0 && y == 0) break; if (x > y) { t = x; x = y; y = t; } std::cout << x << " " << y << std::endl; } return 0; }
1
7,360,982
#include <iostream> #include <algorithm> #include <string> using namespace std; int main(){ string str,aoki; int q,a,b; cin>>str>>q; for(int i=0;i<q;++i){ cin>>aoki>>a>>b; if(aoki=="print"){ for(int i=a;i<=b;++i){ cout<<str[i]; } cout<<endl; } else if(aoki=="reverse"){ string rina=str; for(int i=a;i<=b;++i){ str[i]=rina[b-(i-a)]; } } else if(aoki=="replace"){ string yazawa; cin>>yazawa; for(int i=a;i<=b;++i){ str[i]=yazawa[i-a]; } } } return 0; }
#include <iostream> #include <string> using namespace std; int main(){ string str,order,space ; char temp; int q,a,b; cin>> str ; cin>> q; for(int i=0;i<q;i++){ cin >> order; if (order =="print"){ cin >> a >> b; for(int j=a;j<=b;j++){ cout << str[j]; } cout << "\n"; } else if(order == "replace"){ cin >> a >> b ; cin >> space; for(int j=a;j<=b;j++){ str[j]=space[j-a]; } } else { cin >> a >>b ; for(int j=0;j<(b-a+1)/2;j++){ temp=str[a+j]; str[a+j]=str[b-j]; str[b-j]=temp; } } } return 0; }
1
19,083,517
#include<stdio.h> int main(void) { int a,b; scanf("%d%d",&a,&b); if(a<b) printf("a < b\n"); else if(a==b) printf("a == b\n"); else printf("a > b\n"); }
#include <cstdlib> #include <iostream> #include <sstream> std::string eq_string(int a, int b) { std::string res; if (a < b) { res = std::string {"a < b"}; } else if (a > b) { res = std::string {"a > b"}; } else { res = std::string {"a == b"}; } return res; } int main() { int a; int b; std::cin >> a; std::cin >> b; std::cout << eq_string(a, b) << std::endl; return EXIT_SUCCESS; }
1
33,152,499
#include<bits/stdc++.h> using namespace std; int a,b; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>a>>b; if(a * b % 2 == 0){ cout<<"Even"<<endl; }else{ cout<<"Odd"<<endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; int C = A * B; if ( C % 2 == 0 ) { cout << "Even"; } else { cout << "Odd"; } }
1
98,780,353
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> ii; #define DEBUG freopen("in.txt", "r", stdin); struct fastio { fastio() { ios::sync_with_stdio(false); cout << setprecision(10) << fixed; cin.tie(0); } }; fastio _fast_io; const int N = 205; int h, w; char ans[N][N]; int main() { cin >> h >> w; for (int i = 1; i <= h; ++i) { for (int j = 0; j < w; ++j) { cin >> ans[i][j]; } } for (int i = h * 2; i > 0; --i) { for (int j = 0; j < w; ++j) { ans[i][j] = ans[(i + 1) / 2][j]; } } for (int i = 1; i <= h * 2; ++i) { for (int j = 0; j < w; ++j) { cout << ans[i][j]; } cout << endl; } return 0; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define X first #define Y second #define pb push_back #define max_el(x) max_element(x.begin(),x.end())-x.begin() #define min_el(x) min_element(x.begin(),x.end())-x.begin() #define mp make_pair #define endl '\n' #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; void solve(){ int h,w; cin>>h>>w; vector<string> c(h+1); for(int i=1;i<=h;i++){ cin>>c[i]; c[i] = " "+c[i]; } for(int i=1;i<=2*h;i++){ for(int j=1;j<=w;j++){ cout<<c[(i+1)/2][j]; } cout<<endl; } } int main(){ fastread; int t = 1; for(int i=1;i<=t;i++){ solve(); } return 0; }
1
15,316,058
#include <bits/stdc++.h> using namespace std; using ll = long long; using vec = vector<ll>; using mat = vector<vec>; using pll = pair<ll,ll>; #define INF (1LL << 60) #define MOD 1000000007 #define PI 3.14159265358979323846 #define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i)) #define FORR(i,v) for(auto (i):v) #define ALL(x) (x).begin(), (x).end() #define PR(x) cout << (x) << endl #define PS(x) cout << (x) << " " #define SZ(x) ((ll)(x).size()) #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) #define REV(x) reverse(ALL((x))) #define ASC(x) sort(ALL((x))) #define DESC(x) ASC((x)); REV((x)) #define pb push_back #define eb emplace_back int main() { ll H, W; cin >> H >> W; vector<string> S(H+2); REP(i,0,W+2) { S[0] += "."; S[H+1] += "."; } REP(i,1,H+1) { cin >> S[i]; S[i] = "." + S[i] + "."; } bool f = true; REP(i,1,H+1) { REP(j,1,W+1) { if(S[i][j] == '#') { if(S[i-1][j] == '.' && S[i+1][j] == '.' && S[i][j-1] == '.' && S[i][j+1] == '.') { f = false; break; } } } if(!f) break; } if(f) PR("Yes"); else PR("No"); return 0; }
#include <iostream> #include <bits/stdc++.h> #include <vector> #include <algorithm> #include <cctype> #include <string> #include <map> #include <set> #include <math.h> #include <cmath> #define ll long long using namespace std; using P = pair<int,int>; int main(){ int h, w; cin >> h >> w; vector<vector<string>> vec(h+2, vector<string>(w+2)); for (int i = 0; i < h+2; i++) { for (int j = 0; j < w+2; j++) { vec.at(i).at(j) = "*"; } } string s; for (int i = 1; i < h+1; i++) { cin >> s; for (int j = 1; j < w+1; j++) { vec.at(i).at(j) = s[j-1]; } } for (int i = 1; i < h+1; i++) { for (int j = 1; j < w+1; j++) { if(vec.at(i).at(j) == "#"){ if(vec.at(i-1).at(j) != "#" && vec.at(i).at(j-1) != "#" && vec.at(i).at(j+1) != "#" && vec.at(i+1).at(j) != "#"){ cout << "No" << endl; return 0; } } } } cout << "Yes" << endl; return 0; }
1
10,777,364
#include <bits/stdc++.h> using namespace std; int main(){ int A,P; int x = 0; cin >> A >> P; x = (A*3 + P)/2; cout << x <<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 pii = pair<int,int>; ll MOD=1000000007; const double PI = acos(-1); int main(){ int a,p; cin>>a>>p; int piece = a*3 + p; cout << piece/2 << endl; }
1
53,278,775
#include <iostream> #include <string> #include <stack> #include <queue> #include <cctype> #include <algorithm> #include <vector> #include <map> #include <cmath> #include <stdlib.h> #include <tuple> #include <iomanip> #include <iterator> #include <stdio.h> #include <fstream> #include <time.h> using namespace std; const double PI = 3.14159265358979323846; const long long int MOD = 1000000000 + 7; struct UnionFind { vector<int> parent; UnionFind(int N) : parent(N) { for (int i = 0; i < N; i++) { parent[i] = -1; } } int root(int i) { if (parent[i] < 0) { return i; } return (parent[i] = root(parent[i])); } bool unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx != ry) { parent[ry] += parent[rx]; parent[rx] = ry; return true; } else { return false; } } bool same(int x, int y) { return root(x) == root(y); } int treeSize(int x) { return -parent[root(x)]; } }; long long int modpow(long long int base, long long int pow, long long int mod) { if (pow == 1) { return base; } else if (pow == 0) { return 1; } if (pow % 2 == 0) { auto temp = modpow(base, pow / 2, mod); return (temp * temp) % mod; } else { return base * modpow(base, pow - 1, mod) % mod; } } long long int moddiv(long long int X, long long int Y, long long int mod) { auto fermatDiv = modpow(Y, mod - 2, mod); return (X * fermatDiv) % mod; } long long modCombination(long long left, long long right, long long int mod) { long long answer = 1; for (long long i = 0; i < right; i++) { answer = (answer * (left - i)) % mod; answer = moddiv(answer, (i + 1), mod); } return answer; } bool IsPrime(long long N) { if (N == 1) { return false; } for (long long i = 2; i * i <= N; i++) { if (N % i == 0) { return false; } } return true; } vector<pair<long long, long long> > prime_factorize(long long N) { vector<pair<long long, long long> > res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({ a, ex }); } if (N != 1) res.push_back({ N, 1 }); return res; } long long euclid(long long a, long long b) { if (a > b) { long long temp = b; b = a; a = temp; } if (b % a == 0) { return a; } else { return euclid(a, b - a); } } int main() { long long N, M; cin >> N >> M; priority_queue<long long> items; for (long long i = 0; i < N; i++) { long long temp; cin >> temp; items.push(temp); } for (long long i = 0; i < M; i++) { long long item = items.top(); items.pop(); item = item >> 1; items.push(item); } long long answer = 0; while (!items.empty()) { answer += items.top(); items.pop(); } cout << answer << endl; return 0; }
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <stdlib.h> #include <math.h> #include <vector> #include <queue> #include <stack> #include <cmath> #include <map> #include <iomanip> #include <set> #include <ctime> #include <tuple> #include <bitset> #include <assert.h> #include <deque> using namespace std; typedef long long ll; #define fi first #define se second #define rep(i, n) for (ll i = 0; i < n; i++) #define debugA() cerr << "AAAAA" << endl #define debug_() cerr << "-------------" << endl #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ for (int i = 0; i < v.size(); i++) \ { \ cout << v[i] << " "; \ } \ cout << endl; #define debug_vec2(v) \ for (int i = 0; i < v.size(); i++) \ { \ for (int j = 0; j < v[i].size(); j++) \ { \ cout << v[i][j] << " "; \ } \ cout << endl; \ } using Graph = vector<vector<int>>; using P = pair<int, int>; int main() { int n, m; cin >> n >> m; priority_queue<int, vector<int>, less<int>> que; for (int i = 0; i < n; i++) { int a; cin >> a; que.push(a); } for (int i = 0; i < m; i++) { int x = que.top(); que.pop(); que.push(x / 2); } ll ans = 0; while (!que.empty()) { ans += que.top(); que.pop(); } cout << ans << endl; return 0; }
1
58,019,912
#include<bits/stdc++.h> using namespace std; #define endl '\n' #define int long long #define eb emplace_back #define pb push_back #define pob pop_back #define mp make_pair #define upb upper_bound #define lwb lower_bound #define fi first #define se second #define For(i, l, r) for (int i = l; i < r; i++) #define ForE(i, l, r) for (int i = l; i <= r; i++) #define Ford(i, r, l) for (int i = r; i > l; i--) #define FordE(i, r, l) for (int i = r; i >= l; i--) #define Fora(i, a) for (auto i : a) #define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl; #define PrintVl(a) Fora(iiii, a) cout << iiii << endl; #define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl; #define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl; #define Ptest(x) return cout << x, 0; #define gl(s) getline(cin, s); #define setpre(x) fixed << setprecision(x) #define bend(a) a.begin(), a.end() #define rbend(a) a.rbegin(), a.rend() #define mset(a) memset(a, 0, sizeof(a)) #define mset1(a) memset(a, 1, sizeof(a)) #define msetn1(a) memset(a, -1, sizeof(a)) #define msetinf(a) memset(a, 0x3f, sizeof(a)) #define gcd __gcd #define __builtin_popcount __builtin_popcountll #define pque priority_queue #define mts multiset #define y0 _y0_ #define y1 _y1_ #define div divi typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <ld> vld; typedef vector <string> vs; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef vector <vi > vvi; typedef vector <vll > vvll; typedef vector <pii > vpii; typedef vector <pll > vpll; const int N = 2e5 + 5; int mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7; ll infll = 1e18 + 7; int f(int x){ int ans = 0; Ford(i, 50, 0){ int t = x / (1ll << i); if (t % 2 == 0) continue; int kek = x % (1ll << i); if (kek % 2 == 0) ans ^= (1ll << i); } if (x % 4 == 1 || x % 4 == 2) ans++; return ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int x, y; cin >> x >> y; cout << (f(x - 1) ^ f(y)); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1999999999 #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define MODA 1000000007 int main() { ll ans = 0; ll tmp; ll a[2]; cin >> a[0] >> a[1]; a[1]++; ll x[2]; REP(i,40){ REP(j, 2){ ll sh = a[j] / ((ll)1 << (i+1)); ll mo = a[j] % ((ll)1 << (i+1)); x[j] = sh * ((ll)1 << (i)); x[j] %= 2; tmp = max((ll)0, mo - ((ll)1 << (i))); x[j] += tmp; x[j] %= 2; } ans += (x[0] ^ x[1]) * ((ll)1 << (i)); } cout << ans << endl; }
1
42,145,154
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin >>a>>b; int s=a+b; if(s%2==1) cout <<s/2+1<<endl; else if(s%2==0) cout <<s/2<<endl; return 0; }
#include <iostream> using namespace std; int main(void){ int a,b,z; cin>>a>>b; z=a+b; if(z%2==0){ cout<<z/2<<endl; } else if(z%2>0){ cout<<z/2+1<<endl; } else{ cout<<z/2<<endl; } }
1
53,562,025
#include<bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) using namespace std; int main(){ int n; cin >> n; vector<string> w(n); rep(i,n) cin >> w[i]; bool flg = true; for(int i=0; i<n-1; i++){ if(w[i].back() != w[i+1].front()){ flg = false; break; } } for(int i=0; i<n; i++){ for(int j=i+1; j<n; j++){ if(w[i] == w[j]){ flg = false; break; } } } if(flg) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define Rep(i,s,n) for(int i=s;i<n;i++) #define fi first #define se second #define all(c) c.begin(),c.end() typedef long long int ll; typedef pair<int, int> P; typedef long double ld; void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;} const ll INF=1001001001; const ll mod=1000000007; int main(){ int n;cin>>n; string s; string o; cin>>s; o=s; set<string> st; st.insert(o); int c=0; rep(i,n-1){ cin>>s; if(st.end()!=st.find(s)) c++; else{ st.insert(s); } if(o[o.size()-1]!=s[0]){ c++; } o=s; } Ans(c==0); }
1
92,410,435
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e18; #define rep(i, a, b) for (int i = a; i < b; i++) #define per(i, a, b) for (int i = b - 1; i >= a; i--) #define int ll using pint = pair<int, int>; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; signed main() { int n; string s; cin >> n >> s; int ans = 0; rep(i, 0, 1000) { string t; int x = i; rep(j, 0, 3) { t += '0' + x % 10; x /= 10; } int ti = 0; rep(j, 0, n) { if (s[j] == t[ti]) { ti++; if (ti == 3) break; } } if (ti == 3) ans++; } cout << ans << "\n"; }
#include <bits/stdc++.h> #include <math.h> #include <vector> #include <queue> #include <iomanip> #include <string> #include <algorithm> using namespace std; using Graph = vector<vector<int>>; #define rep(i,n) for(int i=0;i<n;i++) #define rep_1 (i,j,n) for(int i=j;i<n;i++) typedef long long ll; typedef long l; const ll l_INF = 1010101010101010; const int INF = 1010101010; const int dx[4] = {-1,0,1,0}; const int dy[4] = {0,-1,0,1}; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; using pii = pair<int,int>; using pll = pair<ll,ll>; int main(){ int n; cin>>n; string s; cin>>s; set<int> ans; int cnt=0; rep(i,10){ rep(j,10){ rep(k,10){ bool judge1=false,judge2=false,judge3=false; rep(x,n){ if(!judge1&&i==s[x]-'0') judge1=true; else if(!judge2&&!judge3&&judge1&&s[x]-'0'==j) judge2=true; else if(!judge3&&judge2&&s[x]-'0'==k) judge3=true; } if(judge3){ cnt++; } } } } cout<<cnt; }
1
51,717,892
#include <bits/stdc++.h> #define INF 1000000000 using namespace std; int main() { int n, m; cin >> n >> m; vector<int> dp(n+1, INF); dp[0] = 0; for (int i = 0, c; i < m; i++) { cin >> c; for (int j = c; j <= n; j++) { if (dp[j - c] != INF && dp[j] > dp[j - c] + 1) { dp[j] = dp[j - c] + 1; } } } cout << dp[n] << endl; return 0; }
#include <iostream> #include <set> #include <vector> #include <utility> using namespace std; #define FOR(i,n) for(int i=0; i<n; i++) #define FOR2(i, z, n) for(int i=z; i<n; i++) int main() { int change, nbr_coins; cin >> change >> nbr_coins; set<int> coins_set; FOR(i, nbr_coins) { int coin; cin >> coin; coins_set.insert(coin); } vector<int> changes_list(change); changes_list[0] = 1; FOR2(i, 1, change) { if (coins_set.find(i + 1) != coins_set.end()) { changes_list[i] = 1; } else { int min_coins_nbr = 100000; for (int j = 0, y = i - 1; j <= y; j++, y--) { if (changes_list[j] + changes_list[y] < min_coins_nbr) { min_coins_nbr = changes_list[j] + changes_list[y]; } } changes_list[i] = min_coins_nbr; } } cout << changes_list[change - 1] << endl; }
1
69,200,212
#include<stdio.h> #include<algorithm> #include<iostream> using namespace std; struct Card{ char suit,value; }; void BubbleSort(struct Card C[],int n){ Card tmp; for (int i = 0; i < n; i++){ for (int j = n - 1; j >= i; j--){ if (C[j].value < C[j - 1].value){ tmp = C[j]; C[j] = C[j - 1]; C[j - 1] = tmp; } } } } void SelectionSort(struct Card C[],int n){ Card tmp; for (int i = 0; i < n; i++){ int min = i; for (int j = i; j < n; j++){ if (C[j].value < C[min].value){ min = j; } } tmp = C[i]; C[i] = C[min]; C[min] = tmp; } } void print(struct Card C[],int n){ for (int i = 0; i < n; i++){ if (i != 0) cout << " "; cout << C[i].suit << C[i].value; } cout << endl; } bool isStable(struct Card C1[],struct Card C2[],int n){ for (int i = 0; i < n; i++){ if (C1[i].suit != C2[i].suit){ return false; } } return true; } int main(){ Card C1[100], C2[100]; int n; char ch; cin >> n; for (int i = 0; i < n; i++){ cin >> C1[i].suit >> C1[i].value; } for (int i = 0; i < n; i++) C2[i] = C1[i]; BubbleSort(C1, n); SelectionSort(C2, n); print(C1, n); cout << "Stable" << endl; print(C2, n); if (isStable(C1, C2, n)){ cout << "Stable" << endl; } else{ cout << "Not stable" << endl; } return 0; }
#include <cstdio> #include <algorithm> using namespace std; typedef pair<char,int> pci; int N; pci A[100], B[100], C[100]; void print(pci X[]) { for (int i=0; i<N; i++) { if (i > 0) putchar(' '); printf("%c%d", X[i].first, X[i].second); } putchar('\n'); } bool same(pci X[], pci Y[]) { for (int i=0; i<N; i++) { if (X[i].first != Y[i].first) return false; } return true; } void bubbleSort(pci X[]) { for (int i=0; i<N; i++) { bool loop = false; for (int j=N-1; j>i; j--) { if (X[j-1].second > X[j].second) { swap(X[j-1], X[j]); loop = true; } } if (!loop) break; } } void selectionSort(pci X[]) { for (int i=0; i<N; i++) { int minI = i; for (int j=i+1; j<N; j++) { if (X[j].second < X[minI].second) minI = j; } if (minI != i) swap(X[minI], X[i]); } } int main() { scanf("%d", &N); for (int i=0; i<N; i++) { getchar(); A[i].first = getchar(); A[i].second = getchar() - '0'; B[i] = C[i] = A[i]; } bubbleSort(B); print(B); puts("Stable"); selectionSort(C); print(C); if (same(B, C)) puts("Stable"); else puts("Not stable"); return 0; }
1
70,854,771
#include<bits/stdc++.h> using namespace std; int main(){ int n,cnt=0; string s; cin >> n >> s; for(int i=0;i<s.size();i++)if(s[i]!=s[i+1])cnt++; cout << cnt << endl; }
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define REP(i,x) for(int i=0;i<(int)(x);i++) #define REPS(i,x) for(int i=1;i<=(int)(x);i++) #define mp(a,b) make_pair(a, b) #define pb push_back #define eb emplace_back #define ll long long int main() { int n; cin>>n; string s; cin>>s; int c=1; REPS(i,n-1) { if(s[i]==s[i-1]) continue; else c++; } cout<<c; }
1
13,844,507
#include<bits/stdc++.h> using namespace std; #define ll long long #define F(i,s,e) for(ll i=s;i<e;++i) #define MOD 1000000007 using Graph=vector<vector<ll>>; int main(){ ll n,m; cin >> n >> m; Graph G(n); ll a,b; F(i,0,m){ cin >> a >> b; G[a-1].push_back(b-1); G[b-1].push_back(a-1); } queue<ll> q; F(i,0,G[0].size()) q.push(G[0][i]); while(!q.empty()){ ll p=q.front(); q.pop(); F(i,0,G[p].size()){ if(G[p][i]==n-1){ cout << "POSSIBLE" << endl; return 0; } } } cout << "IMPOSSIBLE" << endl; return 0; }
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <sstream> #include <iomanip> #include <cmath> #include <cstring> #include <cstdlib> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <list> #include <set> #include <map> #include <bitset> #include <utility> #include <numeric> #include <iterator> using namespace std; using ll = long long; using ull = unsigned long long; const ll inf = 1ll << 60; const ll mod = (ll)1e9 + 7; #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define print(s) cout << s; #define println(s) cout << s << endl; #define printd(s, f) cout << fixed << setprecision(f) << s << endl; int main() { ll n, m; cin >> n >> m; set<ll> x; vector<pair<ll, ll>> p(m); for (ll i = 0; i < m; i++) { ll a, b; cin >> a >> b; p[i].first = a; p[i].second = b; if (a == 1) { x.insert(b); } } string res = "IMPOSSIBLE"; for (ll i = 0; i < m; i++) { if (p[i].second == n) { if (x.count(p[i].first)) { res = "POSSIBLE"; } } } println(res); }
1
15,348,989
#include <bits/stdc++.h> using namespace std; using ll =long long; typedef pair<int,int> P; #define SORT(a) sort((a).begin(),(a).end()) #define rSORT(a) reverse((a).begin(),(a).end()) #define For(i, a, b) for(int i = (a) ; i < (b) ; ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int n, a, b; cin >> n >> a >> b; vector<int> p(n); rep(i, n)cin>>p[i]; int x, y, z; x = y = z = 0; rep(i,n){ if(p[i] <= a) x++; else if(p[i] <= b) y++; else z++; } cout << min({x,y,z}) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const ll M = 1e9 + 7; int si[8] = {-1,0,1,-1,1,-1,0,1}; int sj[8] = {-1,-1,-1,0,0,1,1,1}; int main() { int n; cin >> n; int a, b; cin >> a >> b; int x = 0, y = 0, z = 0; rep(i,n){ int p; cin >> p; if (p <= a) x++; if (a+1 <= p && p <= b) y++; if (b+1 <= p) z++; } cout << min(x, min(y,z)) << endl; return 0; }
1
63,004,161
#include<iostream> #include<math.h> #include<algorithm> #include<stdint.h> #include<vector> #include<deque> #include<stack> #include<string> #include<cstring> #include<time.h> #include<array> #include<iomanip> #include<list> #include<set> #include<unordered_map> #include<unordered_set> #include<random> #include<bitset> #include <queue> #include <map> using namespace std; using ll = long long; using ull = unsigned long long; using uint = unsigned int; using ldouble = long double; #define PRI(s) cout << s << endl #define PRIY PRI("Yes") #define PRIN PRI("No") int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: cout << "ERR_ctoi" << endl; return -1; } } int main() { char b; cin >> b; if (b == 'A')PRI('T'); if (b == 'T')PRI('A'); if (b == 'G')PRI('C'); if (b == 'C')PRI('G'); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; const ll mod=1000000007; const int MAX_N = 1000; double nCk(int n, int k) { double res=1.0; for(int i=0; i<n; i++){ res*=0.5;} for(int i=0; i<k; i++){ res*=(double)(n-i); res/=(double)(k-i); } return res;} int main() { cout << fixed << setprecision(10); string s; cin>>s; if(s.at(0)=='A'){ cout<<'T'<<endl;} else if(s.at(0)=='T'){ cout<<'A'<<endl;} else if(s.at(0)=='C'){ cout<<'G'<<endl;} else if(s.at(0)=='G'){ cout<<'C'<<endl;}}
1
12,738,831
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; for (int i = 1; i <= 1000; i++) { int aa = (double)i * 0.08; int bb = (double)i * 0.10; if (aa==a && bb==b) { cout << i << endl; return 0; } } cout << -1 << endl; }
#include <bits/stdc++.h> #define ll long long int #define yorn(f) cout<<((f)?"Yes":"No")<<endl; #define YORN(f) cout<<((f)?"YES":"NO")<<endl; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define put(x) cout << x << endl; #define println(x) cout << x << endl; using namespace std; signed main() { int a, b; cin >> a >> b; repi(i, 2001) { if (i * 8 / 100 == a && i * 10 / 100 == b) { put(i); return 0; } } put(-1) return 0; }
1
28,071,594
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; ll mm=1000000000;ll MM=mm+7; #define rep(i, n) for(int i=0;i<n;i++) #define PI 3.141592653589793 int main(){ int n; cin >> n; VI d(n); rep(i,n){ cin >> d.at(i); } sort(d.begin(),d.end()); int ans=d.at(n/2) - d.at((n/2)-1); cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; int main() { int n,ans; ans=0; cin>>n; vector<int> d(n); for(int i=0;i<n;i++) { cin>>d.at(i); } sort(d.begin(),d.end()); if(d.at(n/2-1)!=d.at(n/2)) { for(int i=d.at(n/2);i>d.at(n/2-1);i--) { ans++; } } cout<<ans<<endl; }
1
38,468,440
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 int main(){ ll n,k; cin>>n>>k; vector<ll> t(n+1); ll v; for(int i=0;i<n;i++){ cin>>v; t.at(v)++; } ll co=0; for(int i=0;i<n+1;i++){ if(t.at(i)==0){ t.at(i)=200001; }else{ co++; } } sort(t.begin(),t.end()); ll ans=0; for(int i=0;i<(co-k);i++){ ans += t.at(i); } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ ll N,K;cin>>N>>K; vector<ll> A(N);rep(i,N)cin>>A[i]; vector<ll> cnt(N,0); rep(i,N) cnt[A[i]-1]++ ; sort(cnt.begin(),cnt.end(),greater<ll>()); ll ans=0; for(int i=K;i<N;++i){ ans+=cnt[i]; } cout<<ans<<endl; }
1
8,718,344
#include <bits/stdc++.h> using namespace std; int main() { char c; cin >> c; if (c == 'a') { cout << "vowel" << endl; } else if (c == 'e') { cout << "vowel" << endl; } else if (c == 'i') { cout << "vowel" << endl; } else if (c == 'o') { cout << "vowel" << endl; } else if (c == 'u') { cout << "vowel" << endl; } else if (c != 'a', 'e', 'i', 'o', 'u') { cout << "consonant" << endl; } }
#include <iostream> #include <vector> using namespace std; int main(){ string c; cin >> c; string B = "aiueo"; if(B.find(c) != string::npos) { cout << "vowel" << endl; } else { cout << "consonant" << endl; } return 0; }
1
4,024,786
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100000 #define PB emplace_back #define MP make_pair #define F first #define S second #define Umap unordered_map #define Uset unordered_set int main(){ ll w, h, x, y; cin >> w >> h >> x >> y; cout << double(w * h) / double(2) << " "; if(w == x*2 && h == y*2) cout << 1; else cout << 0; return 0; }
#include<bits/stdc++.h> using namespace std; #define read FILE *fp;\ fp=freopen("testcase.txt","r",stdin); #define ll long long #define ull unsigned long long #define sf(n) scanf("%lld",&n) #define pf(n) printf("%lld ",n) #define loop for(long long i=0;i<n;i++) #define lp(b,n) for(long long i=b;i<=n;i++) #define pb(n) push_back(n) #define srt(v) sort(v.begin(),v.end()) #define rvs(v) sort(v.begin(), v.end(), greater<long long>()); #define F first #define S second #define mp(a,b) make_pair(a,b); #define fio ios::sync_with_stdio(false); cin.tie(),cout.tie(); bool sortbysec(const pair<pair<ll,ll>,ll> &a, const pair<pair<ll,ll>,ll> &b) { return (a.second < b.second); } string add(string st1,string st2) { ll r=0; string ans; ans.resize(3000); for(ll i=2999; i>=0; i--) { ll x=st1[i]-'0'; ll y=st2[i]-'0'; ll z=x+y+r; if(z>=10) { r=1; } else r=0; ans[i]=(z%10)+'0'; } return ans; } ll p(ll x) { return ((x%1000000007)*2)%1000000007; } ll f(ll h,set<ll> s,ll ans) { if(h<=1) { return ans; } cout<<ans<<endl; ll ans1,ans2,ans3,ans4; if(s.find(h-1)==s.end()) { ans1=f(h-1,s,ans); } else { ans1=f(h-1,s,ans+1); } if(s.find(h-1)==s.end()) { ans2=f(h-2,s,ans+1); } else { ans2=f(h-2,s,ans); } cout<<ans1<<" "<<ans2<<"t\n"; return min(ans1,ans2); } #define int long long int gcdExtended(int a, int b, int *x, int *y); int modInverse(int a, int m) { int x, y; int g = gcdExtended(a, m, &x, &y); int res = (x%m + m) % m; return res; } int gcdExtended(int a, int b, int *x, int *y) { if (a == 0) { *x = 0, *y = 1; return b; } int x1, y1; int gcd = gcdExtended(b%a, a, &x1, &y1); *x = y1 - (b/a) * x1; *y = x1; return gcd; } #undef int ll nCr(ll n,ll r) { ll u=1; ll m= 998244353; for(ll i=0; i<r; i++) { u=(u*(n-i))%m; } ll d=1; for(ll i=1; i<=r; i++) { d = (d*i)%m; } return (u*modInverse(d,m))%m; } ll Pow(ll a,ll b) { if(b==0) return 1; if(a==0) return 1; ll an=1; while(b--) { an*=a; } return an; } ll sumofdig(ll x) { ll s=0; while(x) { s+=x%10; x/=10; } return s; } #define pr pair< pair<ll,ll>, pair<ll,ll> > int main() { ll w,h,x,y; cin>>w>>h>>x>>y; if(x*2==w && y*2==h) { double ans = double(h)*double(w)/2.0; printf("%.10lf 1\n",ans); } else { double ans = double(h)*double(w)/2.0; printf("%.10lf 0\n",ans); } }
1
58,542,732
#include <iostream> using namespace std; int main() { string s, str; cin >> s >> str; int a, b; cin >> a >> b; string u; cin >> u; if(u == s) --a; else --b; cout << a << ' ' << b; }
#include <stdio.h> #include <string.h> int main(){ char S[15], T[15], U[15]; int a, b; scanf("%s %s", S, T); scanf("%d %d", &a, &b); scanf("%s", U); (strcmp(U, S) == 0) ? a-- : b--; printf("%d %d", a, b); return 0; }
1
64,540,493
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int m; cin >> m; ll D = 0; ll S = 0; for(int i = 0; i < m; i++){ ll d,c; cin >> d >> c; D += c; S += d*c; } cout << (D-1)+(S-1)/9 << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++) #define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--) #define ll long long #define ALL(a) (a).begin(),(a).end() #define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key))) #define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key))) #define pb push_back #define mp std::make_pair #define endl "\n" using std::cin; using std::cout; using std::vector; using std::string; using std::upper_bound; using std::lower_bound; using vi=vector<ll>; using vii=vector<vi>; using pii=std::pair<ll,ll>; const ll MOD=1e9+7; const ll MAX=1e7; const ll INF=(1ll<<60); template<class T> class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {}; struct Binary_indexed_tree{ int N; vi bit; Binary_indexed_tree(int n):N(n){ bit.resize(N+1,0); } void add(int x,int a){ for(x;x<=N;x+=(x&-x)) bit[x]+=a; } ll sum(int x){ ll ret=0; for(x;x>0;x-=(x&-x)) ret+=bit[x]; return ret; } ll lower_bound(ll X){ if(sum(N)<X) return -1; ll ret=0,memo=1,sum=0; while(memo*2<=N) memo*=2; while(memo>0){ if(memo+ret<=N&&sum+bit[memo+ret]<X){ sum+=bit[memo+ret]; ret+=memo; } memo/=2; } return ret+1; } }; struct Union_Find{ ll N; vi par; vi siz; Union_Find(int n):N(n){ par.resize(N); siz.resize(N,1); rep(i,0,N) par[i]=i; } ll root(ll X){ if(par[X]==X) return X; return par[X]=root(par[X]); } bool same(ll X,ll Y){ return root(X)==root(Y); } void unite(ll X,ll Y){ X=root(X); Y=root(Y); if(X==Y) return; par[X]=Y; siz[Y]+=siz[X]; siz[X]=0; } ll size(ll X){ return siz[root(X)]; } }; ll modpow(ll X,ll Y){ ll sum=X,cnt=1; vi A; while(cnt<=Y){ A.pb(sum); sum*=sum; sum%=MOD; cnt*=2; } int M=A.size(); ll ret=1; REP(i,1,M){ if(Y>=(1ll<<M-i)){ Y-=(1ll<<M-i); ret*=A[M-i]; ret%=MOD; } } return ret; } 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; } } ll COM(ll n,ll r){ if(n<r||n<0||r<0) return 0; return fac[n]*finv[r]%MOD*finv[n-r]%MOD; } signed main(){ ll M; cin>>M; ll sum=0,ans=-1; rep(i,0,M){ ll X,Y; cin>>X>>Y; if(X==0){ ans+=Y; continue; } vector<pii> me; me.pb(mp(X,0)); while(1){ ll P=me[me.size()-1].first+X; ll Q=me[me.size()-1].second+1; if(P>9){ P=P%10+P/10; Q++; } me.pb(mp(P,Q)); if(P==me[0].first) break; } while(Y>0){ ans+=Y/me.size()*me[me.size()-1].second; ll Z=Y%me.size(); if(Z>0){ ans+=me[Z-1].second+1; sum+=me[Z-1].first; if(sum>=10){ sum=sum%10+sum/10; ans++; } } Y/=me.size(); } } cout<<ans<<endl; }
1
27,053,463
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> iint; typedef pair<ll,ll> llll; #define ALL(x) (x).begin(),(x).end() const ll zero = 0; const ll one = 1; const ll INF = 9223372036854775807; const int inINF = 2147483647; const ll MOD = 1000000007; const ll MOD2 = 998244353; void Yes() {printf("Yes\n");} void No() {printf("No\n");} void YES() {printf("YES\n");} void NO() {printf("NO\n");} int main(){ ll N, Z, W; cin >> N >> Z >> W; vector<ll> A(N); for(int i = 0; i < N; i++) { cin >> A[i]; } if(N == 1){ printf("%d\n", abs(W - A[0])); return 0; } W -= A[N-1]; W = abs(W); A[N-2] -= A[N-1]; A[N-2] = abs(A[N-2]); if(W > A[N-2]){ printf("%lld\n", W); } else{ printf("%d\n", A[N-2]); } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<int> vi; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; const long long mod = 1000000007; const long long inf = 1e18; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,z,w; cin>>n>>z>>w; vi v; for(int i=0;i<n;i++){ int k; cin>>k; v.pb(k); } if(n==1){ cout<<abs(v[0]-w)<<endl; } else{ cout<<max(abs(v[n-1]-v[n-2]),abs(v[n-1]-w)); } return 0; }
1
71,045,269
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ int n; cin >> n; int w[n]; rep(i,n){cin>>w[i];} int ABS = 0; rep(t,n){ int s1=0,s2=0; for(int i = 0; i < t; i++){ s1 += w[i]; } for(int j = t; j < n; j++){ s2 += w[j]; } if(t==0){ ABS = abs(s1-s2); }else{ if(ABS > abs(s1-s2)) ABS = abs(s1-s2); } } cout << ABS << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int sum=0; vector<int> w(n); for(int i=0;i<n;i++){ cin>>w[i]; sum+=w[i]; } int mini=1e8; for(int i=0;i<n;i++){ int r=0,l=sum; for(int j=0;j<i;j++){ r+=w[j]; l-=w[j]; } mini=min(mini,abs(r-l)); } cout<<mini<<endl; }
1
4,061,823
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define fi first #define se second #define m_p make_pair #define p_b push_back #define e_b emplace_back #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++) #define rep(i,n) REP(i,0,n) #ifdef LOCAL #define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl #define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\ rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl #define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\ rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl #else #define debug(x) void(0) #define debug_vec(x) void(0) #define debug_mat(x) void(0) #endif 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;} class Union_Find_size{ public: vector<int> Parent; Union_Find_size(int N){ Parent=vector<int>(N,-1); } int root(int x){ if(Parent.at(x)<0) return x; return Parent.at(x)=root(Parent.at(x)); } int size(int x){ return -Parent.at(root(x)); } bool same(int x,int y){ return root(x)==root(y); } void unite(int x,int y){ x=root(x); y=root(y); if(x==y) return; if(size(x)<size(y)) swap(x,y); Parent.at(x)+=Parent.at(y); Parent.at(y)=x; } }; int main(){ ios_base::sync_with_stdio(false);cin.tie(0); int N,M; cin >> N >> M; vector<int> p(N); rep(i,N){ cin >> p.at(i); p.at(i)--; } Union_Find_size uni(N); rep(i,M){ int x,y; cin >> x >> y; x--; y--; uni.unite(x,y); } int ans=0; rep(i,N){ if(uni.same(i,p.at(i))) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, from, to) for (int i = from; i < (to); ++i) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define pb push_back using ll = long long; using vin=vector<int>; using vll=vector<ll>; using vst=vector<string>; using P = pair<int, int>; const int inf=1e9+7; const ll INF=1e18; 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); } template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } const int dx[4] = { 1, 0, -1, 0 }; const int dy[4] = { 0, 1, 0, -1 }; int par[100010]; int rnk[100010]; void init(int n){ for(int i=0;i<n;i++){ par[i]=i; rnk[i]=0; } } int find(int x){ if(par[x]==x) return x; return par[x]=find(par[x]); } void unite(int x,int y){ x=find(x); y=find(y); if(x==y)return; if(rnk[x]<rnk[y]){ par[x]=y; } else{ par[y]=x; if(rnk[x]==rnk[y])rnk[x]++; } } bool same(int x,int y){ return find(x)==find(y); } int main(){cout<<fixed<<setprecision(10); int n,m; cin>>n>>m; map<int,int> mp; init(n+1); vin p(n);rep(i,0,n){cin>>p[i];mp[p[i]]=i+1;} rep(i,0,m){ int x,y; cin>>x>>y; unite(x,y); } int ans=0; rep(i,0,n){ if(same(mp[p[i]],p[i]))ans++; } cout<<ans<<endl; }
1
19,030,782
#include <bits/stdc++.h> using namespace std; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } #ifdef __LOCAL #define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl #define debugArray(x, n) \ cerr << __LINE__ << ": " << #x << " = {"; \ for (long long hoge = 0; (hoge) < (n); ++(hoge)) \ cerr << ((hoge) ? "," : "") << x[hoge]; \ cerr << "}" << endl #else #define debug(x) (void(0)) #define debugArray(x, n) (void(0)) #endif signed main() { cin.tie(0); ios::sync_with_stdio(false); vector<int> v(5); for (int i = 0; i < 5; i++) cin >> v[i]; int ans = INT_MAX; sort(v.begin(), v.end()); for (int cnt = 5 * 4 * 3 * 2 * 1; cnt--;) { int tmp = 0; for (int i = 0; i < 5; i++) { tmp = (tmp + 9) / 10 * 10; tmp += v[i]; } ans = min(ans, tmp); next_permutation(v.begin(), v.end()); } cout << ans << '\n'; return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <map> #define ll long long const ll MOD = 1e9 + 7; const ll INF = 1 << 29; int main() { std::vector<int> durations(5); for (auto i=0; i<5; ++i) std::cin >> durations[i]; std::sort(durations.begin(), durations.end(), [](int lhs, int rhs) { if (lhs % 10 == 0) return true; if (rhs % 10 == 0) return false; return (10 - lhs % 10) < (10 - rhs % 10); }); int sum = 0; for (auto i=0; i<4; ++i) { auto a = durations[i]; auto intervals = a % 10 == 0 ? a : a - (a % 10) + 10; sum += intervals; } sum += durations[4]; std::cout << sum << std::endl; }
1
13,076,369
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = int64_t; using pint = pair<int, int>; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); rep(i, a) cin >> p[i]; rep(i, b) cin >> q[i]; rep(i, c) cin >> r[i]; sort(p.begin(), p.end(), greater<int>()); sort(q.begin(), q.end(), greater<int>()); sort(r.begin(), r.end(), greater<int>()); int z = 0; while (true) { if (x == 0 && y == 0) break; if (x == 0) { if (q[y - 1] < r[z]) { --y; ++z; if (z == c) break; continue; } } else if (y == 0) { if (p[x - 1] < r[z]) { --x; ++z; if (z == c) break; continue; } } else { if (p[x - 1] < q[y - 1]) { if (p[x - 1] < r[z]) { --x; ++z; if (z == c) break; continue; } } else { if (q[y - 1] < r[z]) { --y; ++z; if (z == c) break; continue; } } } break; } ll ans = 0; rep(i, x) ans += p[i]; rep(i, y) ans += q[i]; rep(i, z) ans += r[i]; cout << ans << endl; }
#include <iostream> #include <algorithm> using namespace std; int X, Y, A, B, C; int P[1 << 18]; int Q[1 << 18]; int R[1 << 18]; int main() { cin >> X >> Y >> A >> B >> C; for (int i = 0; i < A; i++) cin >> P[i]; for (int i = 0; i < B; i++) cin >> Q[i]; for (int i = 0; i < C; i++) cin >> R[i]; sort(P, P + A); reverse(P, P + A); sort(Q, Q + B); reverse(Q, Q + B); for (int i = 0; i < X; i++) R[C + i] = P[i]; for (int i = 0; i < Y; i++) R[C + X + i] = Q[i]; sort(R, R + C + X + Y); reverse(R, R + C + X + Y); long long score = 0; for (int i = 0; i < X + Y; i++) score += R[i]; cout << score << endl; return 0; }
1
25,631,313
#include <iostream> using namespace std; int f(int x){ return x*x; } int main(void){ int dx; while(cin>>dx){ int sum=0; for(int i=1;i*dx<600;i++){ sum+=dx*f(i*dx); } cout<<sum<<endl; } }
#include <iostream> using namespace std; int main( void ) { while ( 1 ) { int d; cin >> d; if ( cin.eof() ) break; int sum = 0; for ( int i = d; i < 600; i += d ) { sum += (i*i*d); } cout << sum << endl; } return 0; }
1
3,382,048
#include <bits/stdc++.h> #define irep(i,n) for(int i = 0; i < (int)(n); i++) #define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++) #define irrep(i,n) for(int i = (int)(n-1); i > -1; i--) #define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--) #define fi first #define se second using ll = long long; using v_int = std::vector<int>; using v2_int = std::vector<v_int>; using v_ll = std::vector<ll>; using v2_ll = std::vector<v_ll>; using v_string = std::vector<std::string>; using v_bool = std::vector<bool>; using v2_bool = std::vector<v_bool>; using pii = std::pair<int, int>; using pll = std::pair<ll, ll>; using mii = std::map<int, int>; using mll = std::map<ll, ll>; const double PI = 3.1415926535897932; const int INF = 2*(int)1e9; const ll LINF = (ll)1e18; const ll MOD = 1000000007; const int dc[4] = {1, -1, 0, 0}; const int dr[4] = {0, 0, 1, -1}; using namespace std; template<typename T, typename U> inline ostream& operator<<(ostream &o, pair<T,U> &p) { return o << "{" << p.first << "," << p.second << "}"; } template<typename T> inline istream& operator>>(istream &is, vector<T> &v) { int len = (int)v.size(); for(int i = 0; i < len; i++) { is >> v[i]; } return is; } template<typename T> inline ostream& operator<<(ostream &os, vector<T> &v) { int len = (int)v.size(); for(int i = 0; i < len; i++) { os << v[i]; if(i != len-1) { os << ","; } } return os; } template<typename T> inline void chmin(T &a, T b) { a = min(a, b); } template<typename T> inline void chmax(T &a, T b) { a = max(a, b); } int main(void) { string s; cin >> s; int n = s.size(); irep(i, 1<<(n-1)) { ll sum = 0; string ans; irep(j, n) { int op = 1; string op_str = "+"; if(j>0 && i & (1 << (j-1))) { op *= -1; op_str = "-"; } sum += op * (s[j]-'0'); if(j > 0) { ans += op_str; } ans += s[j]; } if(sum == 7) { cout << ans << "=7" << endl; return 0; } } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define fi first #define se second #define vi vector<int> #define vpi vector<pair<int,int>> #define vll vector<ll> #define vpll vector<pair<ll,ll>> #define endl '\n' #define si(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i) #define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i) template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; } template<class T, class U> void chmin(T &a, U b) { if (a > b) a = b; } using ll = long long; using ld = long double; using namespace std; constexpr ll MOD = 1000000007; signed main() { cout << fixed << setprecision(20); ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int d[4]; rep(i, 4) d[i] = s[i] - '0'; rep(bit, 1<<3) { int result = d[0]; string ans; ans += s[0]; rep(i, 3) { if (bit & (1<<i)) result += d[i+1], ans += '+'; else result -= d[i+1], ans += '-'; ans += s[i+1]; } if (result == 7) { cout << ans << "=7" << endl; return (0); } } return (0); }
1
76,808,636
#include <algorithm> #include <iostream> #include <stack> #include <queue> #include <cmath> #include <string> #include <iterator> #include <map> #include <set> #include <iomanip> #include <vector> #include <cstdint> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using Graph = vector<vector<int>>; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; #define rep(i, N) for(int i = 0; i < N; i++) #define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++) #define INF 1000000000000000 #define MAX 200001 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") const ll MOD = 1000000007; template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();}; vector<int> solve(int N){ vector<int> res(100,0); for(int i = 1; i < N+1; i++){ int now = i; for(int j = 2; j < N+1; j++){ if(now % j != 0) continue; int cnt = 0; while(now % j == 0){ cnt++; now /= j; } res[j] += cnt; } if(now != 1) res[now] += 1; } return res; } int main(){ int N; cin >> N; vector<int> res(100); res = solve(N); int ans = 0; int cnt_25 = 0; int cnt_15 = 0; int cnt_5 = 0; int cnt_3 = 0; rep(i,100){ if(res[i] >= 74) ans++; if(res[i] >= 24){ cnt_25++; cnt_15++; cnt_5++; cnt_3++; } else if(res[i] >= 14){ cnt_15++; cnt_5++; cnt_3++; } else if(res[i] >= 4){ cnt_5++; cnt_3++; } else if(res[i] >= 2) cnt_3++; } ans += cnt_25*(cnt_3-1); ans += cnt_15*(cnt_5-1); ans += cnt_5*(cnt_5-1)/2*(cnt_3-2); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n;cin>>n; int pf[100]{}; int c[1000]{}; for (int i=2;i<=n;i++) { int t=i; for (int j=2;j*j<=t&&t>1;j++) while (t%j==0) { t/=j; pf[j]++; c[pf[j]]++; } if (t>1) { pf[t]++; c[pf[t]]++; } } cout<<c[74]+c[24]*(c[2]-1)+c[14]*(c[4]-1)+c[4]*(c[4]-1)/2*(c[2]-2)<<endl; return 0; }
1
39,794,792
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <vector> #include <map> #include <set> #include <list> #include <stack> #include <queue> using namespace std; int n; int s; vector<int> v; int f; int b; int sum = 0; int ans = 0; int main() { while (cin >> n) { if (n == 0) break; for (int i = 0; i < n; i++) { cin >> s; v.push_back(s); } sort(v.begin(), v.end()); f = v[0]; b = v[v.size() - 1]; for (int i = 0; i != v.size(); ++i) { sum += v[i]; } sum = sum - f - b; ans = sum / (v.size() - 2); cout << ans << endl; v.clear(); sum = 0; ans = 0; } }
#include<stdio.h> int main(){ int a,ten[100],i,max=0,min=1000,sum=0,ave=0; while(1){ max=0; min=1000; sum=0; ave=0; scanf("%d",&a); if(a==0)break; else{ for(i=0;i<a;i++){ scanf("%d",&ten[i]); } for(i=0;i<a;i++){ if(max<ten[i]){ max=ten[i]; } } for(i=0;i<a;i++){ if(min>ten[i]){ min=ten[i]; } } for(i=0;i<a;i++){ sum+=ten[i]; } ave=(sum-max-min)/(a-2); printf("%d\n",ave); } } return 0; }
1
83,214,624
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; void print(string word,vector<string>& output) { int a,b; cin >> a >> b; output.push_back(word.substr(a,b-a+1)); } void reverse(string& word) { int a,b; cin >> a >> b; string temp = word.substr(a,b-a+1); reverse(temp.begin(),temp.end()); word.replace(a,b-a+1,temp); } void replace(string& word) { int a,b; string change; cin >> a >> b >> change; word.replace(a,b-a+1,change); } int main(int argc, char* argv[]) { string word,command; vector<string> output; int count; cin >> word >> count; for(int i=0;i<count;i++) { cin >> command; if(command=="print") print(word,output); else if(command=="reverse") reverse(word); else if(command=="replace") replace(word); } for(string n:output) { cout << n << endl; } }
#include <algorithm> #include <iostream> #include <string> using namespace std; int main () { string str; cin >> str; int n; cin >> n; for (int i = 0; i < n; i++){ string a = ""; int b = 0; int c = 0; string d = ""; cin >> a; cin>>b>> c; if (a == "replace") { cin >> d; str.replace (b, c - b + 1, d); } else if (a == "reverse") { string s=str.substr (b, c - b + 1); reverse (s.begin (),s.end ()); str=str.substr(0,b)+s+str.substr(c+1,str.length()); } else if (a=="print") { cout << str.substr (b, c - b + 1) << endl; } } return 0; }
1
53,596,779
#include <stdio.h> #include <math.h> #include <algorithm> using namespace std; int main() { int n, m, x, i; scanf("%d%d", &n, &m); for (i = 0; i < m; i++) { scanf("%d", &x); n -= x; } if (n < 0) n = -1; printf("%d\n", n); return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; int main(){ ll m; cin>>m; ll N; ll c=0; cin>>N; vector<ll>tr(N); for(ll i=0;i<N;i++){ cin>>tr.at(i); c+=tr.at(i); } ll b=m-c; if(b<0){ b=-1; } cout<<b<<endl; }
1
19,950,240
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <list> #include <set> #include <map> #include <numeric> #include <regex> #include <tuple> using namespace std; typedef long long ll; typedef pair<int, int> P; #define MOD 1000000007 #define INF 1000000000 #define LLINF 1LL<<60 bool claim[100001]; bool kind[100001]; bool next_animal(bool before, bool animal, bool say) { if (animal) { if (say) return before; else return !before; } else { if (say) return !before; else return before; } } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int i = 0; i < N; i++) { char c; cin >> c; if (c == 'o') claim[i] = true; } for (int i = 1; i >=0; i--) { for (int j = 1; j >=0; j--) { bool flag = true; kind[0] = i; kind[1] = j; for (int k = 1; k <= N - 1; k++) kind[k + 1] = next_animal(kind[k - 1], kind[k], claim[k]); if (kind[0] != kind[N]) flag = false; if (kind[1] != next_animal(kind[N - 1], kind[0], claim[0])) flag = false; if (flag) { string S; for (int i = 0; i < N; i++) { if (kind[i]) S.push_back('S'); else S.push_back('W'); } cout << S << endl; return 0; } } } cout << -1 << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,m) for(long long i=0; i<m; i++) #define per(i,m) for(long long i=m-1; i>=0; i--) #define FOR(i,n,m) for(long long i=n; i<m; i++) #define ROF(i,n,m) for(long long i=m-1; i>=n; i--) #define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0) #define all(x) (x).begin(),(x).end() #define EPS (1e-7) #define INF (1e18) #define PI (acos(-1)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; using namespace std; typedef long long ll; const ll MOD = 1000000007; typedef pair<ll, ll> LP; ll POW(ll x,ll n){ if(n==0)return 1; if(n%2==0)return POW(x*x,n/2)%MOD; return x%MOD*POW(x,n-1)%MOD; } ll POW2(ll x,ll n){ if(n==0)return 1; if(n%2==0)return POW2(x*x,n/2); return x*POW2(x,n-1); } ll POW3(ll x,ll n,ll m){ x%=m; if(n==0)return 1; if(n%2==0)return POW3(x*x,n/2,m)%m; return x*POW3(x,n-1,m)%m; } ll gcd(ll u, ll v) { ll r; while (0 != v) { r = u % v; u = v; v = r; } return u; } ll lcm(ll u, ll v) { return u*v/gcd(u,v); } ll KAI(ll m) { if(m<0) return 0; if(m==0) return 1; return m*KAI(m-1)%MOD; } ll KAI2(ll m) { if(m<0) return 0; if(m==0) return 1; return m*KAI2(m-1); } ll extGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a%b, y, x); y -= a / b * x; return d; } inline ll mod(ll a, ll m) { return (a % m + m) % m; } ll modinv(ll a) { ll x, y; extGCD(a, MOD, x, y); return mod(x, MOD); } ll COM(ll m,ll n) { if(m<n) return 0; if(n<0) return 0; if(n==0) return 1; if(m==n) return 1; return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD; } ll COM2(ll m,ll n) { if(m<n) return 0; if(n<0) return 0; if(n==0) return 1; if(m==n) return 1; return KAI2(m)/KAI2(n)/KAI2(m-n); } ll DEC(ll x,ll m,ll n) { return x%POW2(m,n+1)/POW2(m,n); } ll keta(ll x,ll n) { if(x==0)return 0; return keta(x/n,n)+1; } ll DIV(ll x,ll n) { if(x==0)return 0; return x/n+DIV(x/n,n); } ll ORD(ll x,ll n) { if(x==0)return INF; if(x%n!=0)return 0; return 1+ORD(x/n,n); } ll SGS(ll x,ll y, ll m) { if(y==0)return 0; if(y%2==0){ return (1+POW3(x,y/2,m))*SGS(x,y/2,m)%m; } return (1+x*SGS(x,y-1,m))%m; } ll SSGS(ll x,ll y,ll m) { if(y==0)return 0; if(y==1)return 1; if(y%2==0){ return (SSGS(x,y/2,m)*(POW3(x,y/2,m)+1)%m+SGS(x,y/2,m)*y/2%m)%m; } return (SSGS(x,y-1,m)*x%m+y)%m; } int main() { ll n,a=0,b=0,c=0,d=0;; char s[110000],t[110000],u[110000]; cin >> n; rep(i,n)cin >> s[i]; rep(i,n)t[i]='S'; rep(i,n)u[i]='o'; rep(i,n){ if(s[i]!=u[i]){ if(t[(i+1)%n]=='S')t[(i+1)%n]='W'; else t[(i+1)%n]='S'; if(u[i]=='o')u[i]='x'; else u[i]='o'; if(u[(i+1)%n]=='o')u[(i+1)%n]='x'; else u[(i+1)%n]='o'; if(u[(i+2)%n]=='o')u[(i+2)%n]='x'; else u[(i+2)%n]='o'; } } rep(i,n){ if(s[i]!=u[i]){ if(t[(i+1)%n]=='S')t[(i+1)%n]='W'; else t[(i+1)%n]='S'; if(u[i]=='o')u[i]='x'; else u[i]='o'; if(u[(i+1)%n]=='o')u[(i+1)%n]='x'; else u[(i+1)%n]='o'; if(u[(i+2)%n]=='o')u[(i+2)%n]='x'; else u[(i+2)%n]='o'; } } rep(i,n){ if(s[i]!=u[i]){ if(t[(i+1)%n]=='S')t[(i+1)%n]='W'; else t[(i+1)%n]='S'; if(u[i]=='o')u[i]='x'; else u[i]='o'; if(u[(i+1)%n]=='o')u[(i+1)%n]='x'; else u[(i+1)%n]='o'; if(u[(i+2)%n]=='o')u[(i+2)%n]='x'; else u[(i+2)%n]='o'; } } rep(i,n){ if(s[i]!=u[i]){ goto A; } } rep(i,n)printf("%c",t[i]); return 0; A:; rep(i,n)if(s[i]=='x')d++; if(n%3==1){ rep(i,n)t[i]='W'; rep(i,n){ if(s[i]=='x'){ if(i%3==0)a++; if(i%3==1)b++; if(i%3==2)c++; } if(i%3==0&&b%2==1)t[i]='S'; if(i%3==1&&c%2==1)t[i]='S'; if(i%3==2&&a%2==1)t[i]='S'; } a=0; b=0; c=0; per(i,n){ if(s[i]=='x'){ if(i%3==0)a++; if(i%3==1)b++; if(i%3==2)c++; } if(i%3==0&&c%2==1&&t[i]=='W')t[i]='S'; else if(i%3==0&&c%2==1)t[i]='W'; if(i%3==1&&a%2==1&&t[i]=='W')t[i]='S'; else if(i%3==1&&a%2==1)t[i]='W'; if(i%3==2&&b%2==1&&t[i]=='W')t[i]='S'; else if(i%3==2&&b%2==1)t[i]='W'; } if(d%2==1)rep(i,n)printf("%c",t[i]); else { rep(i,n){ if(t[i]=='W')printf("S"); if(t[i]=='S')printf("W"); } } return 0; } if(n%3==2){ rep(i,n)t[i]='W'; rep(i,n){ if(s[i]=='x'){ if(i%3==0)a++; if(i%3==1)b++; if(i%3==2)c++; } if(i%3==0&&c%2==1)t[i]='S'; if(i%3==1&&a%2==1)t[i]='S'; if(i%3==2&&b%2==1)t[i]='S'; } a=0; b=0; c=0; per(i,n){ if(s[i]=='x'){ if(i%3==0)a++; if(i%3==1)b++; if(i%3==2)c++; } if(i%3==0&&b%2==1&&t[i]=='W')t[i]='S'; else if(i%3==0&&b%2==1)t[i]='W'; if(i%3==1&&c%2==1&&t[i]=='W')t[i]='S'; else if(i%3==1&&c%2==1)t[i]='W'; if(i%3==2&&a%2==1&&t[i]=='W')t[i]='S'; else if(i%3==2&&a%2==1)t[i]='W'; } if(d%2==1)rep(i,n)printf("%c",t[i]); else { rep(i,n){ if(t[i]=='W')printf("S"); if(t[i]=='S')printf("W"); } } return 0; } printf("-1"); }
1
86,017,875
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i = 0; i < n; i++) int main() { int W,N; cin >> W >> N; vector<ll> dp(W+1,100000000000); dp[0] = 0; int w,v; rep(i,N) { cin >> w >> v; rep(j,W+1) dp[j] = min(dp[j], dp[max(0,j-w)]+v); } cout << dp[W] << 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); #define chmin(x,y) x = min(x,y); const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int INF = 1001001001; int dp[1005][10005]; int main() { int h, n; cin >> h >> n; rep(i,n+1)rep(j,h+1) dp[i][j] = INF; dp[0][0] = 0; rep(i,n) { int a, b; cin >> a >> b; rep(j,h+1) { chmin(dp[i+1][j], dp[i][j]); chmin(dp[i+1][min(j+a,h)], dp[i+1][j] + b); } } cout << dp[n][h] << endl; return 0; }
1
97,091,722
#include<bits/stdc++.h> using namespace std; #define int long long #define tc(t) int t; cin>>t; while(t--) #define f(n) for(int i=0;i<n;i++) #define endl "\n" int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; vector<int> v(n); int sum=0; f(n)cin>>v[i]; for(int i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { sum+=(v[i]*v[j]); } } cout<<sum<<endl; }
#include <bits/stdc++.h> typedef long long int lli; typedef unsigned long long int ulli; typedef long double ld; #define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define eb emplace_back #define vi vector <int> #define vlli vector <lli> #define vulli vector <ulli> #define vchar vector <char> #define vstr vector <string> #define vb vector <bool> #define fst first #define sec second #define all(a) (a).begin(),(a).end() #define srt(a) sort(a.begin(),a.end()) #define rev(a) reverse(a.begin(),a.end()) #define vpii vector <pair <int,int> > #define pii pair <int,int> #define vplli vector <pair <lli,lli> > #define vvi vector <vector <int> > #define vvlli vector <vector <lli> > #define vvpii vector <vector <pair <int,int>> > #define fr(i,n) for (int i = 0; i < (n); ++i) #define frbig(i,n) for (lli i = 0; i < (n); ++i) #define fra(i,a,n) for (lli i = a; i < (n); ++i) #define run(c,s) for(auto c:s) #define read(n) int n; cin >> n; #define readchar(n) char n; cin >> n; #define readstr(n) string n; cin >> n; #define readarr(a,n) fr(i,n) cin >> a[i]; #define read2(x,y) int x,y; cin >> x >> y; #define read2ll(x,y) long long int x,y; cin >> x >> y; #define readll(n) lli n; cin >> n; #define watch(x) cout << (#x) << " is " << (x) << endl #define print_array(x) fr(i,x.size()) cout << x[i]; using namespace std; const lli MOD=1e9+7; const lli MAXN=5e4+1; const ld PI=acos(-1); int main(){ rapgame int t=1; while(t--){ read(n); lli sum=0; vlli a(n); fr(i,n){ cin >> a[i]; fr(j,i) { sum+=a[i]*a[j]; } } cout << sum; } return 0; }
1
55,204,076
#include<bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; int main(){ ll X,Y,Z,K,i,j,k;scanf("%lld%lld%lld%lld",&X,&Y,&Z,&K); ll A[X],B[Y],C[Z]; for(i=0;i<X;i++) scanf("%lld",&A[i]); for(j=0;j<Y;j++) scanf("%lld",&B[j]); for(k=0;k<Z;k++) scanf("%lld",&C[k]); sort(A,A+X,greater<ll>()); sort(B,B+Y,greater<ll>()); sort(C,C+Z,greater<ll>()); vector<ll> ans; for(i=0;i<X && i+1 <= K;i++){ for(j=0;j<Y && (i+1)*(j+1) <= K;j++){ for(k=0;k<Z && (i+1)*(j+1)*(k+1) <= K;k++){ ans.emplace_back(A[i]+B[j]+C[k]); } } } sort(ans.begin(),ans.end(),greater<ll>()); for(i=0;i<K;i++) printf("%lld\n",ans[i]); }
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; using PL = pair<ll,ll>; int main() { int x, y, z, k; cin >> x >> y >> z >> k; vector<ll> a(x), b(y), c(z), ab, abc; for(int i = 0; i < x; i++)cin >> a[i]; for(int i = 0; i < y; i++)cin >> b[i]; for(int i = 0; i < z; i++)cin >> c[i]; for(int i = 0; i < x; i++) { for(int j = 0; j < y; j++) { ab.push_back(a[i] + b[j]); } } sort(ab.begin(), ab.end(), greater<ll>()); ab.resize(k); for(int i = 0; i < k; i++) { for(int j = 0; j < z; j++) { abc.push_back(ab[i] + c[j]); } } sort(abc.begin(), abc.end(), greater<ll>()); for(int i = 0; i < k; i++)cout << abc[i] << endl; }
1
100,405,393
#include <bits/stdc++.h> #define f(i, a, b) for (int i = a; i < (b); ++i) #define f1(i, a, b) for (int i = a; i <= (b); ++i) #define rep(i, n) f(i, 0, n) using namespace std; using ll = long long; int main(void) { int n; cin >> n; vector<int> p(n), q(n); rep(i, n) cin >> p[i]; rep(i, n) cin >> q[i]; vector<int> a(n); rep(i, n) a[i] = i + 1; map<vector<int>, int> np; do { np[a] = np.size(); } while (next_permutation(a.begin(), a.end())); int ans = abs(np[p] - np[q]); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int facctorialMethod(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; } void solve(){ int n,m,x,count=0,r[2]; scanf("%d",&n); int a[2][n]; for (int i = 0; i < n; i++) { scanf("%d",&a[0][i]); } for (int i = 0; i < n; i++) { scanf("%d",&a[1][i]); } vector<int> v; for(int i=0;i<2;i++){ r[i]=1; for (int i = 1; i <= n; i++) { v.push_back(i); } for(int j=0;j<n;j++){ auto x=find(v.begin(),v.end(),a[i][j]); int a=distance(v.begin(),x); r[i]+=facctorialMethod(v.size()-1)*a; v.erase(x); } } printf("%d",abs(r[0]-r[1])); } int main(){ solve(); return 0; }
1
71,002,450
#include <iostream> #include <iomanip> #include <map> #include <set> #include <utility> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <climits> #include <list> #include <queue> #include <deque> #include <stack> #include <numeric> #include <complex> #include <memory> #include <sstream> #ifdef USE_CPP11 #include <unordered_map> #include <unordered_set> #include <functional> #endif #define PRINT(obj) cout << obj << endl #define REP(i, n) for(int (i) = 0; (i) < (n); i++) #define SPACE " " typedef long long ll; const int INF = 1e9 + 10; using namespace std; namespace Scanner { #ifdef USE_PRINTF int nextInt() { int d; scanf("%d" , &d); return d; } float nextFloat() { float f; scanf("%f" , &f); return f; } double nextDouble() { double f; scanf("%lf", &f); return f; } string nextString() { string s; scanf("%s" , &s); return s; } ll nextll() { ll l; scanf("%ll", &l); return l; } #else int nextInt() { int d; cin >> d; return d; } float nextFloat() { float f; cin >> f; return f; } double nextDouble() { double f; cin >> f; return f; } string nextString() { string s; cin >> s; return s; } ll nextll() { ll l; cin >> l; return l; } #endif string getLine() { string input; getline(cin, input); return input; } }; namespace myLibrary { vector<string> split(const string& str, char delim) { vector<string> ret; size_t current = 0, found; while ((found = str.find_first_of(delim, current)) != string::npos) { ret.push_back(string(str, current, found - current)); current = found + 1; } ret.push_back(string(str, current, str.size() - current)); return ret; } #ifdef USE_CPP11 template<typename T_IN, typename T_OUT, class Functor> vector<T_OUT> _Map(vector<T_IN> src, Functor func) { vector<T_OUT> ret; for (int i = 0; i < src.size(); i++) { ret.push_back(func(src[i])); } return ret; } #endif }; int main() { while (true) { int m = Scanner::nextInt(); int nmin = Scanner::nextInt(); int nmax = Scanner::nextInt(); if (m + nmin + nmax == 0) { break; } vector<int> Ps(m); REP(i, m) { int p = Scanner::nextInt(); Ps[i] = p; } int ans, ans_diff = -1; for (int i = nmin - 1; i <= nmax - 1; i++) { int diff = Ps[i] - Ps[i + 1]; if (diff >= ans_diff) { ans_diff = diff; ans = i; } } PRINT(ans + 1); } return 0; }
#include<iostream> #include<algorithm> #include<string> #include<cstdlib> #include<map> #include<iomanip> #include<sstream> #include<vector> #include<stack> #include<math.h> #include<queue> #include<complex> #include<random> #include<ctime> #include<set> using namespace std; const long long int mod=1000000007; const long long int INF=99999999999999999; long long int m,nmin,nmax; string s; int main() { cout << fixed << setprecision(18); cin>>m>>nmin>>nmax; while(0!=m){ long long int p[210],res,gap=0; for(int i=1;i<=m;i++){ cin>>p[i]; } sort(p+1,p+m+1); for(int i=m-nmax+1;i<=m-nmin+1;i++){ if(gap<p[i]-p[i-1]){ gap=p[i]-p[i-1]; res=m-i+1; } } cout<<res<<endl; cin>>m>>nmin>>nmax; } }
1
74,881,553
#include <iostream> #include <vector> #include <algorithm> #define INF 1010101010 using namespace std; int main() { long long n; cin >> n; long long ans = 0; for (long long i = 1; i * i < n; i++) { long long t = (n - i) / i; if ((n - i) % i == 0 && n / t == n % t) { ans += (n - i) / i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using Int = long long; using namespace std; int main() { Int n; cin >> n; Int ans = 0LL; for (Int i = 1; i * i < n; i++) { if (n % i == 0) { auto j = n / i; if (j - i >= 2) { ans += j - 1; } } } cout << ans << endl; }
1
24,699,429
#include<iostream> #include<math.h> using namespace std; #define ll long long int main(){ int n,k,x,y; cin>>n>>k>>x>>y; int total=0; if(n<=k) { total=x*(n); }else{ total=k*x; total+=y*(n-k); } cout<<total; }
#include <bits/stdc++.h> using namespace std; int main(void) { int N,K,X,Y,ans; cin>>N>>K>>X>>Y; ans=min(N,K)*X+max(N-K,0)*Y; cout<<ans<<endl; return 0; }
1
97,753,752
#include <bits/stdc++.h> using namespace std; int main() { long H; int N; int ans = 0; int t = 0; cin >> N >> H; for(int i=0;i<N-1;++i){ long h; cin >> h; if(h <= H){ t++; }else{ if(t > ans){ ans = t; } t = 0; } H = h; } if(t > ans){ ans = t; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define ll long long int using namespace std; const ll mod=1000000007; const ll inf=1e18; int main(){ ll n; cin >> n; ll h[n]; for(int i=0;i<n;i++)cin >> h[i]; ll m=0; for(int i=0;i<n;i++){ if(h[i]<h[i+1])continue; ll k=0; while(i+k+1<=n-1 && h[i+k]>=h[i+k+1]){ k++; } i+=k; m=max(m,k); } cout << m << endl; }
1
90,898,060
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0; i < n; i++) #define REP(i, n) for(ll i = 1; i < n + 1; i++) #define PI 3.14159265359 #define EPS 0.0000000001 #define MOD 1000000007 int main(){ ll A, B, K; cin >> A >> B >> K; ll v = min(A, B) + 1; ll counter = 0; while(counter < K){ v--; if(A % v == 0 && B % v == 0){ counter++; } } cout << v << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B, K; cin >> A >> B >> K; vector<int> c; for (int i = 1; i <= min(A, B); ++i) { if (A % i == 0 && B % i == 0) c.push_back(i); } reverse(c.begin(), c.end()); cout << c[K-1] << endl; }
1
42,783,914
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { cin.tie(0)->sync_with_stdio(false); string s; cin >> s; int n = s.size(); int cnt = 0; REP(i, n) if (s[i] == 'o') cnt++; if (15 - n + cnt >= 8) cout << "YES" << '\n'; else cout << "NO" << '\n'; return 0; }
#include<iostream> #include<algorithm> #include<cmath> using namespace std; int main() { string s; cin>>s; int x=0,n=s.size(); for(int i=0;i<n;i++)s[i]-'o'?x++:0; cout<<(15-x>7?"YES":"NO")<<endl; }
1
32,462,922
#include <stdio.h> int main(void) { int n; scanf("%d", &n); float x1, y1, x2, y2, x3, y3, x4, y4; while (n--) { scanf("%f %f %f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4); if ((y2 - y1)/(x2 - x1) == (y4 - y3)/(x4 - x3)) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
#include <iostream> #include <cmath> #define rep(i,a,n) for(int i=a; i<n; i++) using namespace std; int main() { int n; cin >> n; for(int i=0; i<n; i++) { double x1, y1, x2, y2, x3, y3, x4, y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; double a1 = x2 - x1; double b1 = y2 - y1; double a2 = x4 - x3; double b2 = y4 - y3; if(abs(a1 * b2 - a2 * b1) < 1e-10) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
1
6,216,374
#include <iostream> #include <stdio.h> using namespace std; int HelloWorld(){ cout << "Hello World" << endl; return 0; } int XCubic(){ int x; cin >> x; if (1 <= x && x <= 100){ x = x*x*x; cout << x << endl; return 0; } return 1; } int Rectangle(){ int a, b, area, perimeter; cin >> a >>b; if (1 <= a && b <= 100){ area = a*b; perimeter = (a + b) * 2; cout << area << " " << perimeter << endl; return 0; } return 1; } int Watch(){ int S; cin >> S; int D = 60; int s = S%D; int m = (S / D) % D; int h = (S / D) / D; if (0 <= S && S <= 86400){ printf("%u:%u:%u\n", h, m, s); return 0; } return 1; } int SmallLargeOrEqual(){ int a, b; cin >> a >> b; if (!(a <= a && b <= 1000)) return 1; if (a < b) cout << "a < b" << endl; else if (a > b) cout << "a > b" << endl; else cout << "a == b" << endl; return 0; } int main(){ SmallLargeOrEqual(); return 0; }
#include<stdio.h> int main(void) { int a, b; scanf("%d",&a); scanf("%d",&b); if(a<b){ printf("a < b\n",a, b); } if(a>b){ printf("a > b\n",a, b); } if(a==b){ printf("a == b\n",a, b); } return 0; }
1
43,989,339
#include <bits/stdc++.h> using namespace std; int main(){ int k, s, r=0; cin >> k>>s; for (int y=0; y<=k; y++){ for (int z=0;z<=k;z++){ int op=s-y-z; if (op >= 0 && op <= k) r++; } } cout << r; return 0; }
#include <bits/stdc++.h> #define arep(a,i,n) for(ll i=(a);i<(n);i++) #define rep(i,n) for(ll i=0;i<(n);i++) #define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i]; #define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; ll cnt[3]; int main(){ ll k,s; cin >> k >> s; rep(x,k+1){ arep(x+1,y,k+1){ arep(y+1,z,k+1){ if(x+y+z==s) cnt[0]++; } } } rep(x,k+1){ arep(x+1,z,k+1){ if(x+x+z==s) cnt[1]++; } } rep(x,k+1){ arep(x+1,y,k+1){ if(x+y+y==s) cnt[2]++; } } rep(x,k+1){ if(x+x+x==s) cnt[3]++; } cout << cnt[0]*6+cnt[1]*3+cnt[2]*3+cnt[3] << endl; }
1
40,350,722
#include <bits/stdc++.h> using namespace std; int main() { string s;cin>>s; long long n;cin>>n; for(int i=0;i<n;++i){ if(s[i]=='1' && n<=i+1){ cout<<1<<endl; return 0; } else if(s[i]!='1'){ cout<<s[i]<<endl; return 0; } } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { string S; long long K; cin >> S >> K; for (long long i=0; i<K; i++) { if (S.at(i)!='1') { cout << S.at(i); return 0; } } cout << "1\n"; }
1
14,760,170
#include<bits/stdc++.h> #define ll long long #define int ll #define fi first #define si second #define mp make_pair #define pb push_back #define pi pair<ll,ll> #define clr(x) memset(x,0,sizeof(x)); #define f(i,l,r) for(int i=l;i<=r;i++) #define rf(i,r,l) for(int i=r;i>=l;i--) #define done(i) cout<<"done = "<<i<<endl; #define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll inf=1e18; const int mod=1e9+7; const int M=100009; int fnd(int n) { int ret=(n*(n-1))/2; return ret; } main() { fast int n,k; cin>>n>>k; int hi=fnd(n-1); if(k>hi) { cout<<"-1"<<endl; return 0; } vector<pi>vec; f(i,2,n) { vec.pb(mp(1,i)); } for(int x=2;x<=n-1;x++) { for(int y=x+1;y<=n;y++) { if(hi==k)break; vec.pb(mp(x,y)); hi--; } if(hi==k)break; } cout<<vec.size()<<endl; for(auto x:vec) { cout<<x.fi<<" "<<x.si<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(i = 0;i < n;++i) #define all(v) v.begin(), v.end() using ll = long long; int main() { ll i,j; ll n,k; cin >> n >> k; ll sup = (n-1)*(n-2)/2; if(k > sup){ cout << -1 << endl; return 0; } vector<pair<ll,ll>> ans; for(i = 2;i <= n;++i){ ans.emplace_back(1,i); } bool flag = false; for(i = 2;i <= n-1;++i){ for(j = i+1;j <= n;++j){ if(sup == k){ flag = true; break; } ans.emplace_back(i,j); --sup; } if(flag) break; } cout << ans.size() << endl; for(i = 0;i < ans.size();++i){ cout << ans.at(i).first << " " << ans.at(i).second << endl; } return 0; }
1
24,316,679
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i = 0; i < (n); i++) #define all(v) v.begin(), v.end() #define MOD 1000000007 const int INF = 1LL<<30; int main(){ int n; cin>>n; vector<ll> a(n); rep(i,n) cin>>a[i]; vector<ll> s(n+1,0); rep(i,n) s[i+1]=s[i]+a[i]; map<ll,ll> m; rep(i,n+1){ m[s[i]]++; } ll ans=0; for(auto e : m){ ans+=e.second*(e.second-1)/2; } cout<<ans<<endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int (i) = 0; (i) < (n); i++) #define ll long long using namespace std; int main() { ll n; cin>>n; ll a[n]; ll ans=0; rep(i,n){ cin>>a[i]; } ll sum[n+1]; sum[0]=0; map<ll,ll> b; b[0]=1; rep(i,n){ sum[i+1]=sum[i]+a[i]; } rep(i,n){ if(b.find(sum[i+1])==b.end()){ b[sum[i+1]]=1; } else { b[sum[i+1]]++; } } for(auto i:b){ if(i.second>=2){ ans+=(i.second*(i.second-1))/2; } } cout<<ans<<endl; }
1
89,139,231
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,x,y) for(int i=x;i<y;i++) #define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a/__gcd(a, b)*b) #define range(a) (a).begin(),(a).end() #define pb push_back #define mp make_pair #define nnn "\n" #define spa " " template<class T>inline bool chmin(T& a,T b,bool f){ if(f==1){if(a>b){a=b;return true;}return false;} else if(f==0){if(a<b){a=b;return true;}return false;}return false;} typedef pair<int,string> p; const int inf = 2147483647; const ll INF = 9223372036854775807; int main (){ vector<int>t(3);cin>>t[0]>>t[1]>>t[2]; sort(range(t)); if((t[1]-t[0])%2==0){ cout<<(t[2]-t[1]+t[2]-t[0])/2<<nnn; }else{ cout<<(t[2]-t[1]+t[2]-t[0])/2+2<<nnn; } }
#include<bits/stdc++.h> #define PI 3.141592653589 using namespace std; using ll = long long; template<typename T_char> T_char ToUpper(T_char cX){return toupper(cX);} int main(){ vector<int> a(3); for(int i=0; i<3; ++i) cin >> a[i]; sort(a.rbegin(), a.rend()); int mx = a[0], mid = a[1]; int dif = mx - mid; int cnt = 0; for(int i=0; i<dif; ++i){ a[1]++; a[2]++; cnt++; } int dif2 = a[0] - a[2]; if(dif2%2==1){ a[0]++; a[1]++; cnt++; } int dif3 = a[0]-a[2]; for(int i=0; i<dif3/2; ++i){ a[2] += 2; cnt++; } cout <<cnt << endl; }
1
34,985,666
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<pair<int, int>> a(100001), b(100001); for (int i = 0; i < 100001; i++) { a[i] = make_pair(0, i + 1); b[i] = make_pair(0, i + 1); } for (int i = 0; i < n; i++) { int v; cin >> v; if (i % 2 == 0) a[v].first++; else { b[v].first++; } } sort(a.rbegin(),a.rend()); sort(b.rbegin(),b.rend()); ll mxa = a[0].first,mxb = b[0].first; if(a[0].second == b[0].second){ if(a[1].first > b[1].first) mxa = a[1].first; else if(a[1].first < b[1].first) mxb = b[1].first; else if(a[1].first == 0 && b[1].first == 0){ cout << n / 2 << endl; return 0; } } cout << n - mxa - mxb << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; const int N = 100010; signed main() { int n; cin >> n; vector<int> a(n); vector<int> odd(N), even(N); int odd_max = 0, oddv = 0; int even_max = 0, evenv = 0; rep(i,n) { cin >> a[i]; if(i % 2 == 0) { even[a[i]]++; if(even[a[i]] > even_max) { even_max = even[a[i]]; evenv = a[i]; } } else { odd[a[i]]++; if(odd[a[i]] > odd_max) { odd_max = odd[a[i]]; oddv = a[i]; } } } int answer = n + 1; for (int i = 0; i < N; i++) { if(i == evenv) continue; int tmp = n - even_max - odd[i]; answer = min(answer, tmp); } for (int i = 0; i < N; i++) { if(i == oddv) continue; int tmp = n - odd_max - even[i]; answer = min(answer, tmp); } cout << answer << endl; return 0; }
1
90,777,562
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, s, n) for (int i = (s); i < (n); ++i) #define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define len(x) (int)(x).size() #define dup(x, y) (((x) + (y)-1) / (y)) #define pb push_back #define Field(T) vector<vector<T>> using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; cout << n * n << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long void solve(){ int r; cin>>r; cout<<r * r<<endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while(t--){ solve(); } return 0; }
1
78,600,425
#include <bits/stdc++.h> using namespace std; struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(10);}} fast; #define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++) #define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--) #define ALL(X) (X).begin(),(X).end() #define pb push_back #define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)) #define debug(x) cerr<<#x<<':'<<x<<endl; #define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl; #define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} #define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define ctoi(C) (C-'0') using ll = long long; using ld = long double; using vi = vector<int>; using vii = vector<vector<int>>; using vl = vector<long long>; using vll = vector<vector<long long>>; using pi = pair<int,int>; using pl = pair<long long,long long>; template<typename T> using PQ = priority_queue<T>; template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; const long long dx[] = {1,0,-1,0}; const long long dy[] = {0,1,0,-1}; const long long dx8[] = {1,1,0,-1,-1,-1,0,1}; const long long dy8[] = {0,1,1,1,0,-1,-1,-1}; const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0}; const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0}; const int INF = 1000000007; const long long LINF = 1000000000000000007; template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;} template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;} long long max(long long x,int y){return max(x,(long long)y);} long long max(int x,long long y){return max((long long)x,y);} long long min(long long x,int y){return min(x,(long long)y);} long long min(int x,long long y){return min((long long)x,y);} signed main(){ ll K; cin >> K; cout << 50 << endl; FOR(i,0,50){ if(i < K%50)cout << K/50+50-i << " \n"[i == 50-1]; else cout << K/50+49-i << " \n"[i == 50-1]; } }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define LL long long #define pb push_back #define pob pop_back #define mp make_pair #define FILL(a,v) memset((void*)a,v,sizeof(a)) #define FILL0(a) FILL(a,0) #define FILL1(a) FILL(a,-1) #define ALL(a) (a).begin(),(a).end() #define Inf 1e9 #define Mod 1000000007 #define foreach(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();it++) #define FOR(i,x) for(int i=0;i<x;i++) #define RFOR(i,x) for(int i=x-1;i>=0;i--) #define FFOR(i,a,b) for(int i=a;i<b;i++) #define FRFOR(i,a,b) for(int i=a-1;i>=b;i--) #define SZ(a) ((int)(a).size()) #define FI first #define SE second #define OVER(a) return puts(a),0 #define fastio ios::sync_with_stdio(0) #define filei(f) freopen(f,"r",stdin) #define fileo(f) freopen(f,"w",stdout) using namespace std; typedef pair<int,int> pii; typedef unsigned long long UINT; typedef unsigned int Uint; typedef long long INT; typedef pair<INT,INT> PII; INT k; INT beit[55],xunhuan[55][55]; void init() { memset(xunhuan[0],0,sizeof(xunhuan[0])); for(int i=0;i<50;i++) for(int j=0;j<50;j++) { if(j==i) xunhuan[i+1][j]=xunhuan[i][j]+50; else xunhuan[i+1][j]=xunhuan[i][j]-1; } } int main() { init(); cin>>k; INT d=49+(k/50); fill(beit,beit+50,d); INT a=k%50; for(int i=0;i<50;i++) beit[i]+=xunhuan[a][i]; cout<<50<<endl; for(int i=0;i<50;i++) cout<<beit[i]<<(i==49?'\n':' '); return 0; }
1
12,480,746
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); vector <int> cnt(26, 0); for (int i = 0; i < n; i++) { cnt[s[i] - 'a']++; } long long ans = 1 + (long long) n * (n - 1) / 2; for (int x : cnt) { ans -= (long long) x * (x - 1) / 2; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> typedef long long ll; ll gi(){ ll x=0,f=1; char ch=getchar(); while(!isdigit(ch))f^=ch=='-',ch=getchar(); while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return f?x:-x; } char S[200010]; int main(){ #ifdef XZZSB freopen("in.in","r",stdin); freopen("out.out","w",stdout); #endif scanf("%s",S+1);int c[26]={0},n=strlen(S+1); for(int i=1;i<=n;++i)++c[S[i]-'a']; ll ans=1ll*n*(n-1)/2+1; for(int i=0;i<26;++i)ans-=1ll*c[i]*(c[i]-1)/2; printf("%lld\n",ans); return 0; }
1
7,265,172
#include <bits/stdc++.h> #include <algorithm> #include <functional> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define DEBUG #define PI 3.141592653589793238462643383279 #define _GLIBCXX_DEBUG #ifdef DEBUG #define s(...) show(__VA_ARGS__); #define sl(...) show(__VA_ARGS__);cout<<endl; #else #define s(...) #define sl(...) #endif void show() {} template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);} #define REP(i, n) for(ll i = 0; i < n; i++) #define REPR(i, n) for(ll i = n; i >= 0; i--) #define FOR(i, m, n) for(ll i = m; i < n; i++) #define REP1(i, n) for(ll i = 1; i <= n; i++) #define REPR1(i, n) for(ll i = n; i >= 1; i--) #define FOR1(i, m, n) for(ll i = m; i <= n; i++) const ll INF = LLONG_MAX; const ll MOD = 1000000007; #define VEC(type,A,N) vector<type> A(N) #define VECi(type,A,N,i) vector<type> A(N,i) #define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M)) #define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i)) #define ALL(v) v.begin(), v.end() ll frac(ll k){ int s = 1; for (ll i=1; i<=k; ++i)s *= i; return s; } ll gcd(ll a, ll b){ if (a%b==0)return(b); else return(gcd(b, a%b)); } ll lcm(ll a,ll b){ return a*b/gcd(a,b); } ll antidiv(ll N,ll C,ll D){ return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D)); } vector<ll> yakusuu(ll N){ vector<ll> ret; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { ret.push_back(i); if (i * i != N) ret.push_back(N / i); } } sort(ret.begin(), ret.end()); return ret; } int main(){ ll N; cin>>N; map<ll,ll> m; REP(i,N){ ll t;cin>>t; if(m.count(t)==0)m[t]=1;else m[t]++; t++; if(m.count(t)==0)m[t]=1;else m[t]++; t--;t--; if(m.count(t)==0)m[t]=1;else m[t]++; } ll ans=0,ii=0; for(const auto t:m){ if(ans<t.second){ ans=t.second; ii=t.first; } } cout<<ans; cout<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const long long INF = 1LL << 60; const ll MOD = 1000000007; using pint = pair<ll, ll>; int main(){ ll N; cin >> N; vector<ll> sum(110000, 0); for (int i = 0; i < N; i++){ ll tmp = 0; cin >> tmp; sum[tmp]++; sum[tmp + 1]++; sum[tmp + 2]++; } ll out = 0; for (int i = 0; i < 110000; i++){ out = max(out, sum[i]); } cout << out << endl; return 0; }
1
8,887,605
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; while(true){ cin>>n>>m; if(n==0&&m==0)break; vector<pair<int,int>> e; for (int i = 0; i < n; ++i) { int a,b; cin>>a>>b; e.emplace_back(b,a); } sort(e.rbegin(),e.rend()); long long ans=0; for (int i = 0; i < n; ++i) { if(m<=0)ans+=e[i].first*e[i].second; else { if(e[i].second<=m){ m-=e[i].second; e[i].second=0; } else{ e[i].second-=m; m=0; ans+=e[i].first*e[i].second; } } } cout<<ans<<endl; } }
#include <iostream> #include <utility> #include <algorithm> using namespace std; int main() { pair<int, int> road[20000]; int i, n, money, a, b, j = 0, kitai = 0; cin >> n; cin >> money; while (n != 0 || money != 0) { for (i = 0; i < n; i++) { cin >> a >> b; road[i] = make_pair(b, a); kitai += a*b; }; sort(road, road + n); reverse(road, road + n); while (money > 0 && kitai > 0 ) { if (money >= road[j].second) { money -= road[j].second; kitai -= road[j].first * road[j].second; j++; } else { kitai -= road[j].first * money; money = 0; }; }; cout << kitai << endl; cin >> n >> money; kitai = 0; j = 0; }; return 0; }
1
9,768,269
#include <bits/stdc++.h> using namespace std; using ll =long long; #define all(v) v.begin(),v.end() int main() { ll N; cin>>N; set<ll> S; for(ll i=0;i<N;i++) { ll A; cin>>A; if(S.count(A)) { cout<<"NO"<<endl; return 0; } S.insert(A); } cout<<"YES"<<endl; }
#include <bits/stdc++.h> using namespace std; #define END '\n' #define int long long #define pb push_back #define pii pair<int, int> #define ff first #define ss second #define trace(x) cerr<<x<<END; #define loop(i, a, b) for(int i = (a); i < (b); i++) #define loopb(i, b, a) for(int i = (b); i > (a); --i) const int mod = 1e9+7; const int mod1 = 998244353; const int inf = 1e18; set<int> s; int n,x; void solve() { cin>>n; loop(i,0,n) { cin>>x; s.insert(x); } cout<<((int)s.size() == n ? "YES" : "NO"); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
1
51,423,032
#include <bits/stdc++.h> using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(false); string S,T="keyence"; cin >> S; int N=S.size(); for (int i=0;i+6<N;++i){ if (S.substr(i,7)==T){ cout << "YES" << '\n'; return 0; } } for (int i=1;i<7;++i){ int ok=1; for (int j=0;j<7;++j){ if (j<i&&S[j]!=T[j]) ok=0; if (i<=j&&S[N-7+j]!=T[j]) ok=0; } if (ok){cout << "YES" << '\n'; return 0;} } cout << "NO" << '\n'; }
#include <bits/stdc++.h> #define ll long long #define MODV 1000000007 #define INFLL LLONG_MAX #define EPS 1e-9 #define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++) #define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++) #define all(v) v.begin(), v.end() #define endl "\n" #define vi vector<ll> #define vvi vector<vector<ll>> #define Yes() cout << "Yes" << endl #define YES() cout << "YES" << endl #define No() cout << "No" << endl #define NO() cout << "NO" << endl #define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15); template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; } using namespace std; int main(){ Init(); string s; cin >> s; string t = "keyence"; ll d = abs((ll)t.size() - (ll)s.size()); bool chk = false; for(ll i=0; i<s.size()-d; i++){ string sd = s.substr(0, i) + s.substr(i+d); if(sd == t){ chk = true; break; } } chk ? YES() : NO(); }
1
21,072,228
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> #include <stack> #include <functional> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif #define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i) #define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i) #define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #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; } using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <int,int> P; typedef long double ld; int main (void) { cin.tie(0); ios::sync_with_stdio(false); ll h, w, n; cin >> h >> w >> n; map<P, ll> m; rep (i, n) { ll a, b; cin >> a >> b; a--; b--; rep (y, max(0LL, a - 2), min(h - 2, a + 1)) { rep (x, max(0LL, b - 2), min(w - 2, b + 1)) { m[P{y, x}]++; } } } vector<ll> ans(10); for (auto p : m) ans[p.second]++; ans[0] = (h - 2) * (w - 2); rep (i, 1, 10) ans[0] -= ans[i]; rep (i, 10) cout << ans[i] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false), cin.tie(0) #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define ALL(x) (x).begin(), (x).end() #define dump(x) cout << (x) << endl #define LMAX 9223372036854775807LL #define LMIN -9223372036854775807LL using ll = long long; template<typename T> using vec = vector<T>; using P = pair<ll, ll>; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T *)array, (T *)(array + N), val); } const ll INF = 1e18; const ll mod = 1e9 + 7; ll powm(ll a, ll b, ll c) { if (b == 0)return 1; else if (b % 2 == 0) { ll d = powm(a, b / 2, c); return (d * d) % c; } else return (a * powm(a, b - 1, c)) % c; } signed main(){ IOS; ll h,w,n; cin >> h >> w >> n; map<P,ll> mp; REP(i,n){ ll x, y; cin >> y >> x; for(int dx = -1;dx <= 1;dx++){ for(int dy = -1;dy <= 1;dy++){ int nx = x + dx, ny = y + dy; if(nx >= 2 && nx <= w - 1 && ny >= 2 && ny <= h - 1) mp[P(nx,ny)]++; } } } vec<ll> cnt(10,0); ll sum = 0; for(auto it = mp.begin();it != mp.end();it++){ cnt[it->second]++; sum++; } cnt[0] = (h - 2) * (w - 2) - sum; REP(i,10){ dump(cnt[i]); } }
1
86,721,146
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pi 3.14159265359; #define inf (1 << 21); #define mod 1000000007; int main() { int N, K; cin >> N >> K; int R, S, P; cin >> R >> S >> P; string T; cin >> T; vector<vector<char>> t(K); for (int i = 0; i < N; i++) { int m = i % K; t.at(m).push_back(T.at(i)); } int ans = 0; for (int i = 0; i < K; i++) { char prev = 'n'; for (int j = 0; j < t.at(i).size(); j++) { if (t.at(i).at(j) != prev) { if (t.at(i).at(j) == 'r') { ans += P; prev = 'r'; } else if (t.at(i).at(j) == 's') { ans += R; prev = 's'; } else { ans += S; prev = 'p'; } } else { if (j < t.at(i).size() - 1) { if (t.at(i).at(j + 1) == 'r') { prev = 's'; } else if (t.at(i).at(j + 1) == 's') { prev = 'p'; } else { prev = 'r'; } } } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define watch(x) cout <<(#x)<<" is "<<(x)<<endl #define debug cout <<"hi"<<endl using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; const int MOD=1e9+7; const int INF32=1<<30; const ll INF64=1LL<<60; void solve(){ int n,k,r,s,p; cin >>n >>k >>r >>s >>p; int R=0,S=0,P=0,cnt=1; vector<vector<char>>v(k); for(int i=0; i<n; i++){ char c; cin >>c; v[i%k].push_back(c); } for(int i=0; i<k; i++){ if(v[i].size()==1){ if(v[i][0]=='s') R++; else if(v[i][0]=='p') S++; else P++; cnt=1; } else for(int j=0; j<v[i].size()-1; j++){ if(v[i][j]==v[i][j+1]) cnt++; else{ if(v[i][j]=='s') R+=(cnt+1)/2; else if(v[i][j]=='p') S+=(cnt+1)/2; else P+=(cnt+1)/2; cnt=1; } if(j==v[i].size()-2&&v[i][j]==v[i][j+1]){ if(v[i][j+1]=='s') R+=(cnt+1)/2; else if(v[i][j+1]=='p') S+=(cnt+1)/2; else P+=(cnt+1)/2; cnt=1; } else if(j==v[i].size()-2){ if(v[i][j+1]=='s') R++; else if(v[i][j+1]=='p') S++; else P++; cnt=1; } } } cout <<R*r+S*s+P*p; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0;}
1
1,207,153
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <math.h> #include <algorithm> #include <string> #include <string.h> #include <vector> #include <functional> #include <queue> #include <unordered_set> #include <climits> #include <set> #include <list> #include <cmath> using namespace std; typedef long long ll; int main() { ll N; vector<int> A; cin >> N; for(int i = 0; i < N; i++){ ll a; cin >> a; A.push_back(a); } sort(A.begin(), A.end()); vector<ll> first; vector<ll> second; bool flag = false; while(A.size() > 2){ int a = A.back(); int a_ = A[A.size()-2]; if(a > 0 && a_ > 0 && !flag){ A.pop_back(); first.push_back(A.front()); second.push_back(a); A.front() -= a; }else{ flag = true; int b = A.front(); A.erase(A.begin(), A.begin()+1); first.push_back(A.back()); second.push_back(b); A.back() -= b; } } cout << A[1] - A[0] << endl; for(int i = 0; i < first.size(); i++){ cout << first[i] << " " << second[i] << endl; } cout << A[1] << " " << A[0] << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int INF=1e+9; const int MOD=1e+9+7; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++) #define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--) 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...)); } #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int main(){ ll N; cin>>N; vector<ll> A(N),A_minus,A_plus; REP(i,N){ cin>>A[i]; if(A[i]>=0) A_plus.push_back(A[i]); else A_minus.push_back(A[i]); } sort(ALL(A)); sort(ALL(A_minus)); sort(ALL(A_plus)); ll sum=0; vector<pair<ll,ll>> ans(N-1); if(A_minus.size()==0){ ll x,y; x=A[0]; y=A[1]; ans[0]=make_pair(x,y); REP2(i,1,N-1){ x-=y; y=A[i+1]; if(i==N-2){ sum=y-x; ans[i]=make_pair(y,x); break; } ans[i]=make_pair(x,y); } }else if(A_plus.size()==0){ ll x,y; sort(ALL(A),greater<ll>()); x=A[0]; y=A[1]; ans[0]=make_pair(x,y); REP2(i,1,N-1){ x-=y; y=A[i+1]; ans[i]=make_pair(x,y); } sum=x-y; }else{ ll x,y; x=A_minus[0]; REP(i,A_plus.size()-1){ y=A_plus[i]; ans[i]=make_pair(x,y); x-=y; } ll y_last=x; x=A_plus[A_plus.size()-1]; REP2(i,1,A_minus.size()){ y=A_minus[i]; ans[A_plus.size()-2+i]=make_pair(x,y); x=x-y; } ans[N-2]=make_pair(x,y_last); sum=x-y_last; } cout<<sum<<endl; REP(i,N-1){ cout<<ans[i].first<<" "<<ans[i].second<<endl; } }
1
12,822,815
#include <iostream> #include <vector> #include <algorithm> #include <numeric> int main() { int n ; std::vector< long long > a ; std::cin >> n ; for( int i = 0 ; i < n ; i++ ) { long long ii ; std::cin >> ii ; a.push_back( ii ) ; } std::cout << *std::min_element( a.begin() , a.end() ) << " " << *std::max_element( a.begin() , a.end() ) << " " << std::accumulate( a.begin() , a.end() , 0LL ) << std::endl ; }
#include <iostream> #define REP(i, a, n) for(int i = a; i < n; i++) using namespace std; int n; long M, m, s; int main(void) { cin >> n; M = -1000000; m = 1000000; s = 0; REP(i, 0, n) { long a; cin >> a; M = max(M, a); m = min(m, a); s += a; } cout << m << " " << M << " " << s << endl; return 0; }
1
1,254,916
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; #define getbit(n, i) (((n) & (1LL << (i))) != 0) #define setbit0(n, i) ((n) & (~(1LL << (i)))) #define setbit1(n, i) ((n) | (1LL << (i))) #define togglebit(n, i) ((n) ^ (1LL << (i))) #define lastone(n) ((n) & (-(n))) char gap = 32; template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; for (const auto &x : v) os << gap << x; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << gap << p.second << ')'; } template <class T> void read(T &x) { char c; for (c = getchar(); c < '0' || c > '9'; c = getchar()) ; for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15); } #define ll long long #define lll __int128_t #define pb push_back #define mp make_pair typedef pair < int,int> ii; typedef vector<ii> vii; typedef vector<ll>vl; typedef vector<int> vi; typedef vector<vi> vvi; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll hashPrime = 1610612741; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ll i,j,k,l,n,m; cin >> n >> m >> k; if(m*k>=n){ cout << "Yes\n"; } else cout << "No\n"; return 0; }
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<stack> #include<queue> #include<set> #include<map> #include<time.h> #include<vector> using namespace std; int main() { int d,t,s; scanf("%d%d%d",&d,&t,&s); if(t*s>=d){ printf("Yes\n"); } else printf("No\n"); return 0; }
1
78,328,239
#include<iostream> #include<cmath> using namespace std; int main() { int N, Y; cin >> N >> Y; string ans = "-1 -1 -1"; for (int i = 0; i <= N; ++i) { for (int j = 0; j <= N; ++j) { int k = N - j - i; if (k < 0) continue; if (i * 10000 + j * 5000 + k * 1000 == Y) { ans = to_string(i) + ' ' + to_string(j) + ' ' + to_string(k); break; } } if (ans != "-1 -1 -1") break; } cout << ans << endl; }
#pragma GCC optimize("O3") #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i < ll(b); i++) #define FORD(i, a, b) for (ll i = a; i > ll(b); i--) #define ALL(x) x.begin(), x.end() #define SIZE(x) ll(x.size()) #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100000 #define PB push_back #define MP make_pair #define F first #define S second #define Umap unordered_map #define Uset unordered_set const unsigned int BIT_FLAG_0 = (1 << 0); const unsigned int BIT_FLAG_1 = (1 << 1); const unsigned int BIT_FLAG_2 = (1 << 2); const unsigned int BIT_FLAG_3 = (1 << 3); const unsigned int BIT_FLAG_4 = (1 << 4); const unsigned int BIT_FLAG_5 = (1 << 5); const unsigned int BIT_FLAG_6 = (1 << 6); const unsigned int BIT_FLAG_7 = (1 << 7); int main() { ll n, y; cin >> n >> y; bool fl = false; set<int> ans; REP(i, n + 1) { REP(j, n + 1) { if (i + j <= n) { if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) { cout << i << ' ' << j << ' ' << n - i - j << endl; fl = true; } } if (fl) { break; } } if (fl) { break; } } if (!fl) { cout << -1 << ' ' << -1 << ' ' << -1 << endl; } }
1
64,040,341
#include <bits/stdc++.h> using namespace std; #define int long long #define ii pair<int,int> #define fi first #define sc second #define all(x) (x).begin(),(x).end() signed main() { #ifdef _DEBUG #endif ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; set<char> d; for (char c = 'a'; c <= 'z'; c++) d.insert(c); for (auto &i : s) d.erase(i); if (d.empty()) cout << "None" << '\n'; else cout << *d.begin() << '\n'; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; ll mm=1000000000;ll MM=mm+7; #define rep(i, n) for(int i=0;i<n;i++) #define PI 3.141592653589793 int main(){ string s; cin >>s; set<char> chk; int n=s.size(); rep(i,n){ chk.insert(s.at(i)); } if(chk.size()==26)cout << "None" << endl; else{ rep(i,26) if(chk.count(char(i+'a'))){ } else{ cout << char(i+'a') << endl; break; } } }
1
45,241,379
#include<bits/stdc++.h> #define fast ios::sync_with_stdio(false), cin.tie(0); #define ll long long #define pb push_back #define mp make_pair #define ff first #define ss second #define endl '\n' using namespace std; main() { fast; string s1,s2; cin>>s1; cin>>s2; if (s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0]) cout<<"YES\n"; else cout<<"NO\n"; }
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; i <(n); ++i) #define REP2(i,x,n) for (int i = x; i <(n); ++i) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using P = pair<int,int>; static const double PI = acos(-1); int main(){ string s, t; cin >> s >> t; bool ok = true; if(s[0] != t[2]) ok = false; if(s[1] != t[1]) ok = false; if(s[2] != t[0]) ok = false; if(ok) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
1
90,267,092
#include<bits/stdc++.h> using namespace std; using ll=long long; constexpr ll mod=1e9+7; int main() { ll h,w; cin>>h>>w; if(h!=1&&w!=1) { cout<<(h*w+1)/2<<endl; return 0; } cout<<1; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) #define rrep(i,n) for(int i=1;i<(n);++i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define maxs(a, b) a = max(a, b) #define mins(a, b) a = min(a, b) using namespace std; typedef long long ll; typedef pair<int, int> P; const ll linf = (1ll << 61); const int inf = 1001001001; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); ll h, w; cin >> h >> w; ll ans = h * w; ans = ans / 2 + (ans % 2 == 0 ? 0 : 1); if (h == 1 || w == 1) ans = 1; cout << ans << endl; return 0; }
1
4,841,579
#include <bits/stdc++.h> #define ll long long #define endl '\n' #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; void solve(){ int k,n; cin >> k >> n; if(k*500 >= n) cout <<"Yes"; else cout <<"No"; } int main(){ fastio; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; t = 1; while(t--){ solve(); } return 0; }
#include <iostream> int main() { int K, X; std::cin >> K >> X; if (500*K >= X) std::cout << "Yes" << std::endl; else std::cout << "No" << std::endl; return 0; }
1
94,683,768
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) #define rng(a) a.begin(),a.end() using namespace std; using ll = long long; int main() { int h, w; cin >> h >> w; vector<string> s(h); rep(i,h) cin >> s[i]; int l[h][w]; rep(i,h) { rep(j,w) { if(s[i][j]=='#') l[i][j] = 0; else if(j==0) l[i][0] = 1; else l[i][j] = l[i][j-1]+1; } } int r[h][w]; rep(i,h) { for(int j = w-1; j >= 0; j--) { if(s[i][j]=='#') r[i][j] = 0; else if(j==w-1) r[i][j] = 1; else r[i][j] = r[i][j+1]+1; } } int u[h][w]; rep(j,w) { rep(i,h) { if(s[i][j]=='#') u[i][j] = 0; else if(i==0) u[0][j] = 1; else u[i][j] = u[i-1][j]+1; } } int d[h][w]; rep(j,w) { for(int i = h-1; i >= 0; i--) { if(s[i][j]=='#') d[i][j] = 0; else if(i==h-1) d[i][j] = 1; else d[i][j] = d[i+1][j] + 1; } } int ans = 0; rep(i,h) { rep(j,w) { if(s[i][j]=='#') continue; ans = max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int h,w;cin>>h>>w; int a[2003][2003]; rep(i,h){ string s;cin>>s; rep(j,w){ if(s[j]=='#')a[i][j]=0; else a[i][j]=1; } } int ans = 0; int cc=1; int tt=0; rep(i,h)rep(j,w){ int tmp = 0; if(a[i][j]==1){ ++tmp; cc=1; while(a[i-cc][j]==1 && i-cc>=0){ ++tmp; ++cc; } cc=1; while(a[i+cc][j]==1 && i+cc<=h-1){ ++tmp; ++cc; } cc=1; while(a[i][j-cc]==1 && j-cc>=0){ ++tmp; ++cc; } cc=1; while(a[i][j+cc]==1 && j+cc<=w-1){ ++tmp; ++cc; } } ans=max(ans,tmp); ++tt; if(ans>=1960 && tt>=100000)break; } cout<<ans<<endl; return 0; }
1
14,029,734
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> using namespace std; typedef long long ll; ll mod = 1e9+7; #define rep(i,n) for(int i = 0; i < (n); ++i) int main() { int n; cin >> n; cout << ( n - 1 ) / 2 << endl; return 0; }
#include<iostream> using namespace std; int main() { int N,ans; cin >> N; if (N%2==0) { ans = N/2-1; } else { ans = (N-1)/2; } cout << ans; }
1
56,754,539
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long #define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);} typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vii; #define rep(n) for(int i=0;i<(n);i++) #define rrep(n) for(int i=(n)-1;i>=0;i--) #define mem(a,b) memset((a),(b),sizeof (a)) #define pb push_back #define mp make_pair #define ff first #define ss second #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define INF (long long) 1e18 #define MOD 1000000007 int dp[1005][1005]; int32_t main(){ int n,m; cin>>n>>m; bool arr[1005][1005]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ char ch; cin>>ch; if(ch == '#') arr[i][j] = 0; else arr[i][j] = 1; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(i==1 && j==1) dp[i][j] = 1; else if(arr[i][j] == 1){ dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD; }else { dp[i][j] = 0; } } } cout<<dp[n][m]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; char grid[5001][5001]; long long mod=1e9+7; int soln(int n,int m){ int dp[n][m];memset(dp,0,sizeof(dp)); dp[n-1][m-1]=1; for(int i=n-1;i>=0;i--){ for(int j=m-1;j>=0;j--){ if(i==n-1&&j==m-1)continue; else if(grid[i][j]=='#')dp[i][j]=0; else dp[i][j]=(((n-1-i>0)?dp[i+1][j]:0)+((m-1-j>0)?dp[i][j+1]:0))%mod; } } return dp[0][0]; } int main() { int n,m;cin>>n>>m; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>grid[i][j]; } } cout<<soln(n,m); }
1
54,497,609
#include <bits/stdc++.h> #define rep(i, n) for(int i= 0; i < (n); i++) using ll= long long int; using namespace std; ll mod= 1e9 + 7; int main() { int a,b,c; cin >> a>> b>> c; if(a-b<=c){cout << c-(a-b) << endl;}else{cout << 0 << endl;} }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using namespace std; int main(){ int a,b,c;cin>>a>>b>>c; cout<<max(0,c-(-b+a))<<endl; }
1
12,523,837
#include<bits/stdc++.h> using namespace std; using p=pair<int,int>; #define int long long #define rep(i,N) for(int i=0;i<N;i++) signed main(){ string S; cin>>S; int A[26]; rep(i,26)A[i]=0; rep(i,S.size())A[S[i]-'a']+=1; for(int j:A){ if(j>=2){ cout<<"no"<<endl; return 0; } } cout<<"yes"<<endl; return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = 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++) int main() { string S; cin >> S; int N = S.size(); int co = 0; int ans = 0; rep(i, N) { rep(j, N) { if(S.at(i) == S.at(j)) { co++; } } if(co > 1) { ans++; break; } co = 0; } if(ans == 0) { cout << "yes" << endl; } else { cout << "no" << endl; } }
1
53,574,992
#include <iostream> #include <vector> #include <string> #include <map> #include <algorithm> #include <math.h> using namespace std; int main(){ while (1){ int n; vector<int> student; cin >> n; if (n == 0) break; for (int i = 0; i < n; i++){ int s; cin >> s; student.push_back(s); } int ans = 999999999; for (int i = 0; i < n; i++){ for (int j = i + 1; j < n; j++){ ans = min(ans, abs(student[i] - student[j])); } } cout << ans << endl; } return 0; }
#define _USE_MATH_DEFINES #include "bits/stdc++.h" #define EPS 1e-10 using namespace std; typedef long long llong; int main() { int n; while (cin >> n, n) { vector<int>v(n); for (int i = 0; i < n; i++)cin >> v[i]; sort(v.begin(), v.end()); int a = 100000000; for (int i = 1; i < n; i++) { a = min(a, abs(v[i] - v[i - 1])); } cout << a << endl; } return 0; }
1
64,900,506
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,s,n) for(int i=(s);i<=(n);i++) #define repr(i,n) for(int i=n-1;i>=0;i--) #define REPR(i,s,n) for(int i=(s);i>=(n);i--) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define Eunique(v) v.erase(unique(all(v)),v.end()) #define Eback(s) s.erase(s.end()-1,s.end()) #define rev(v) reverse(all(v)) #define minvec(v) *min_element(all(v)) #define maxvec(v) *max_element(all(v)) #define sumvec(v) accumulate(all(v),0LL) #define mapmin(v) v.rbegin()->first #define mapmax(v) v.begin()->first #define pb push_back #define pf push_front #define m_p make_pair #define DOUBLE fixed << setprecision(15) #define OK cerr<<"OK\n" #define OK1 cerr<<"OK1\n" #define OK2 cerr<<"OK2\n" #define SIZE(s) (int)s.size() #define INF ((1LL<<62)-(1LL<<31)) #define zero(x,n) setw(x) << setfill('0') << n typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<long long> vll; typedef vector<vll> vvll; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; typedef pair<ll,ll> pll; typedef pair<int,int> pii; typedef vector<pair<int,int>> vpii; typedef vector<pair<ll,ll>> vpll; const double pi = acos(-1.0); const int mod=1000000007; const int mod2=998244353; template<class A, class B> ostream& operator<<(ostream& ost, const pair<A, B>&p) { ost << "{" << p.first << ", " << p.second << "} "; return ost; } template<class T> ostream& operator<<(ostream& ost, const vector<T>&v) { ost << "{"; for (int i = 0; i<(int)v.size(); i++) { if (i)ost << " "; ost << v[i]; } ost << "} \n"; return ost; } template<class A, class B> ostream& operator<<(ostream& ost, const map<A, B>&v) { ost << "{"; for (auto p:v) { ost << "{" << p.first << ", " << p.second << "} "; } ost << "} "; return ost; } 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;} void YES(bool b) {cout << ((b)?"YES\n":"NO\n");} void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");} void yes(bool b) {cout << ((b)?"yes\n":"no\n");} void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");} ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;} ll gcd(ll x, ll y) {return __gcd(x,y);} ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;} int main() { ll n,ans=0; cin >> n; vll a(n); rep(i,n) cin >> a[i]; rep(i,n){ ans+=a[i]/2; a[i]%=2; if(a[i] && a[i+1]>0 && i!=n-1){ ans++; a[i+1]--; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) using namespace std; signed main(void) { int n; cin >> n; long long ans; int a[n]; ans = 0; rep(i, n) { cin >> a[i]; if (a[i] == 0) continue; if (i != 0) a[i] += a[i - 1]; ans += a[i] / 2; a[i] %= 2; } cout << ans << endl; return 0; }
1
53,788,422