code1
stringlengths
54
12k
code2
stringlengths
66
12k
similar
int64
0
1
__index_level_0__
int64
24
101M
#include <bits/stdc++.h> #include<chrono> #define ll long long #define db double #define deb(x) cout<<#x<<": "<<x<<"\n" #define all(x) x.begin(),x.end() #define fo(i, n) for(i=0 ; i<n ; i++) #define Fo(i, k, n) for(i=k ; i<n ; i++) using namespace std; using namespace chrono; const ll MOD = 1000000007; const ll N = 300005; const ll inf = 10000000000000000; void print(vector<ll> v) { ll i; fo(i, v.size())cout << v[i] << " "; cout << "\n"; } void print(vector<pair<ll, ll> > v) { ll i; fo(i, v.size()) { cout << v[i].first << " " << v[i].second << "\n"; } } vector<ll> read(ll n) { ll i; vector<ll> arr(n, 0); fo(i, n)cin >> arr[i]; return arr; } vector<ll> read(ll n, ll k) { ll i; vector<ll> arr(n + k, 0); Fo(i, k, n + k)cin >> arr[i]; return arr; } bool isEven(ll n) { return n % 2 == 0; } bool isOdd(ll n) { return n % 2 != 0; } void solve() { ll t = 1; while (t--) { ll i, j, k, n, m, p, q, x, y, a, b, l, r; ll h; cin >> h >> n; vector<ll> arr(n); arr = read(n); y = accumulate(all(arr), 0); if (y >= h) { cout << "Yes\n"; } else { cout << "No\n"; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif auto start = high_resolution_clock::now(); solve(); ll i, j, k, n, m, p, q, x, y, a, b, l, r; auto stop = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop - start); #ifndef ONLINE_JUDGE cerr << "Time: " << duration.count() / 1000.0 << endl; #endif return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <iomanip> #include <map> #include <numeric> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using LP = pair<ll, ll>; const double PI = 3.1415926535897932; int main() { int H, N; cin >> H >> N; ll total = 0; int t; rep(i, N) { cin >> t; total += t; } if (total >= H) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
1
89,562,499
#include <iostream> using namespace std; int main(void) { int N, K, X, Y; int ans = 0; int sab = 0; cin >> N >> K >> X >> Y; sab = N - K; if (sab < 0) { cout << N * X << endl; } else { ans = (K * X) + (sab * Y); cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int main (void) { int N, K, X, Y; int sum = 0; cin >> N >> K >> X >> Y; for (int i = 1; i <= N; i++ ){ if (N > K) { sum = ((K * X) + (N - K) * Y) ; }else { sum = N * X; } } cout << sum << endl; return 0; }
1
41,168,583
#include <bits/stdc++.h> #define rep(i,n) for(long long i=0; i<n; i++) #define Rep(i,n) for(long long i=1; i<n; i++) #define ll long long #include <math.h> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; #define PI acos(-1) using P =pair<int,int>; int main(){ ll a,b; ll ans; cin>>a>>b; b=min(b,a+2019); ans=2018; for(ll i=a;i<b;i++){ for(ll k=i+1;k<=b;k++){ ans=min(ans,i*k%2019); } } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; long long l,r; int main() { scanf("%lld%lld",&l,&r); long long ans=2019; for(long long i=l;i<=r;++i) { for(long long j=i+1;j<=r;++j) { ans=min(ans,(i*j)%2019); if(ans==0) { cout<<ans<<endl; return 0; } } } cout<<ans<<endl; return 0; }
1
73,622,252
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll k=1,n,a,b;cin>>n>>a>>b; if(n<a+b-1 || n>a*b)return cout<<"-1" , 0; vector<ll> arr; for(ll i=0;i<a;i++){ for(ll j=0;j<b && a-i-1+k<=n;j++)arr.push_back(k++); while(!arr.empty())cout<<arr.back()<<" ",arr.pop_back(); } }
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i, s, n) for (int i = (s); i < (n); i++) #define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(a) a.begin(), a.end() const long long MOD = 1e9 + 7, INF = 1e18; template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;} signed main(){ int N,A,B; cin >> N >> A >> B; if(A * B < N || N + 1 < A + B){ cout << -1 << endl; return 0; } vector<int>ans[A]; int yobun = N - A; REP(i,A){ ans[i].push_back(1); int t = min(yobun,B-1); REP(j,t){ ans[i].push_back(1); } yobun -= t; } vector<int>out(N); iota(ALL(out),1); int now = 0; REP(i,N){ reverse(out.begin()+i,out.begin()+i+ans[now].size()); i += (int)ans[now].size() - 1; now++; } REP(i,N){ if(i)cout << " "; cout << out[i]; } cout << endl; }
1
78,079,031
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { string s; cin >> s; int n = s.size(), maxlen = 0;; for(int i = n-1; i > 0; i--){ string ans = s.substr(0,i); int len = ans.size(); if(len % 2 == 1){ continue; } int flag = 0; for(int i = 0; i < len/2; i++){ if(ans[i] != ans[len/2+i]){ flag = 1; break; } } if(flag == 0 && len > maxlen){ maxlen = len; } } cout << maxlen << endl; }
#include <bits/stdc++.h> using namespace std; using ll=long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define debug(x) cerr<<#x<<": "<<x<<endl; #define MOD 1000000007ULL; #define rep(i,n) for(int i=0;i<n;i++) int main() { char S[222]; cin>>S; int n=strlen(S); for(int i=n-2;i;i-=2){ if(strncmp(S,S+i/2,i/2)==0) { cout<<i<<endl; return 0; } } return 0; }
1
90,966
#include<stdio.h> #include<string.h> char inp[16]; int main (void) { int m, n, i, j, ox, oy; scanf(" %d %d", &m, &n); for(i = 0; i < m; i++) { for (j = 0; j < n; j++) { scanf(" %s", &inp); if(!strcmp(inp, "snuke")) { ox = i; oy = j; goto prre; } } } prre: printf("%c%d\n", 'A' + oy, ox + 1); return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <functional> #include <string> #include <sstream> #include <complex> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> using namespace std; typedef long long ll; #define PI 3.141592653589793 #define MOD 1000000007 #define REP(i, n) for(int i = 0; i < n; i++) string s[27][27]; void solve() { int H, W; cin >> H >> W; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> s[i][j]; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (s[i][j] == "snuke") { char a = 'A' + j; int n = 1 + i; cout << a << n << endl; } } int main() { solve(); return 0; }
1
74,098,312
#include<bits/stdc++.h> #include<unordered_set> #include<unordered_map> #include <algorithm> #include <iostream> #include <string> #include <cmath> using namespace std; #define ll long long #define rep(i,n) for (ll i = 0; i < (n); i++) #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define FORR(i,a,b)for(ll i=(a);i<=(b);i++) #define repR(i,n) for(ll i=n;i>=0;i--) #define all(v)(v).begin(),(v).end() #define rall(v)(v).rbegin(),(v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout<<(x)<<"\n" #define PQ priority_queue<ll> #define PQR priority_queue<ll,vector<ll>,greater<ll>> #define YES(n) cout << ((n) ? "YES\n" : "NO\n" ) #define Yes(n) cout << ((n) ? "Yes\n" : "No\n" ) #define mp make_pair #define sz(x) (ll)(x).size() typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef tuple<ll,ll,ll> tll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vvll = vector<vll>; using vstr = vector<string>; using vc = vector<char>; using vvc = vector<vc>; using vb = vector<bool>; using vvb = vector<vb>; 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; } ll dx[4]={0,1,0,-1}; ll dy[4]={1,0,-1,0}; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin>>n; ll ans=0; rep(i,1000001){ if(i==0) continue; if(n%i==0)ans+=n/i-1; else ans+=n/i; } COUT(ans); }
#include<iostream> using namespace std; int main() { int N; cin >> N; long cnt = 0; for (int a = 1; a < N; a++) { cnt += (N-1)/a; } cout<<cnt<<endl; }
1
11,814,695
#include<bits/stdc++.h> using namespace std; int main(){ int intager[100]={0}; int num; while(cin>>num) intager[num-1]++; int flag=0; for(int i=100;i>0;i--){ for(int j=0;j<100;j++){ if(intager[j]==i){ cout<<j+1<<endl; flag=1; } } if(flag==1) break; } return 0; }
#include<iostream> using namespace std; int main(){ int n[101]; int i; for( i = 0;i < 101;i++){ n[i] = 0; } for( i = 1;i != 0;i){ i = 0; cin >> i; n[i]++; } int max = 1; for( i = 2;i < 101;i++){ if(n[max] <= n[i]){ max = i; } } for( i = 1;i < 101;i++){ if(n[i] == n[max]){ cout << i <<endl; } } return 0; }
1
70,047,856
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define fi first #define se second #define pb push_back #define mp make_pair #define all(vr) vr.begin(),vr.end() const int N=1e5+10,inf=2e9; ll a[N],val[N],n,ps[N],ans[N]; ll get(ll x) { int tmp=upper_bound(val+1,val+n+1,x)-val; return ps[tmp]-x*(n-tmp+1); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; for (int i=1;i<=n;i++) cin>>a[i],val[i]=a[i]; sort(val+1,val+n+1); for (int i=n;i;i--) ps[i]=ps[i+1]+val[i]; vector<int> st; a[n+1]=inf; st.pb(n+1); for (int i=n;i;i--) { while (a[i]>=a[st.back()]) st.pop_back(); st.pb(i); } st.pb(0); for (int i=1;i<(int)st.size()-1;i++) { int x=st[i],y=st[i+1]; ans[x]=get(a[y])-get(a[x]); } for (int i=1;i<=n;i++) cout<<ans[i]<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<long long> b(n); vector<pair<int, int>> c(n); for (int i = 0; i < n; i++) c[i] = make_pair(~a[i], i); sort(c.begin(), c.end()); int mn = n; for (int i = 0; i < n; i++) { int j = c[i].second; mn = min(mn, j); b[mn] += (i + 1LL) * (~c[i].first - (i == n - 1 ? 0 : ~c[i + 1].first)); } for (int i = 0; i < n; i++) { cout << b[i] << '\n'; } return 0; }
1
29,135,211
#include <iostream> #include <iomanip> using namespace std; int main() { int a, b; cin >> a >> b; cout << a / b << ' ' << a % b << ' ' << fixed << setprecision(5) << (double)a / b << endl; }
#include<stdio.h> int main(){ int a=0,b=0,d=0,r=0; double f; scanf("%d %d",&a,&b); d=a/b; printf("%d ",d); r=a%b; printf("%d ",r); f=(double)a/(double)b; printf("%f\n",f); return 0; }
1
12,145,139
#include <bits/stdc++.h> using namespace std; int main() { int64_t N,M; cin >> N >> M; vector<int64_t> A(N),B(N); for ( int64_t i = 0; i < N; ++i){ cin >> A.at(i) >> B.at(i); } vector<vector<int64_t>> AB; AB.resize(M+1); for ( int i = 0; i < N; ++i){ if ( A.at(i) > M ) continue; AB.at(A.at(i)).push_back(B.at(i)); } priority_queue<int64_t> que; int64_t ans = 0; for (int d = 1; d <= M; ++d){ for ( int i = 0; i < AB.at(d).size(); ++i){ que.push(AB.at(d).at(i)); } if ( que.size() ){ ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rp(i,n) for(int i=0; i<n; i++) using namespace std; using ll=long long; using P=pair<int,int>; using G=vector<vector<int>>; int main(){ int n,m; cin >> n >> m; priority_queue<P> job; priority_queue<int> ok; rp(i,n){ int a,b; cin >> a >> b; job.push(make_pair(m-a,b)); } ll money=0ll; for(int day=m; day>=0; day--){ bool nxt=false; while(!job.empty()){ P p=job.top(); if(p.first<day) break; job.pop(); ok.push(p.second); } if(ok.empty()) continue; money+=(ll)ok.top(); ok.pop(); } cout << money << endl; return 0; }
1
34,421,135
#include <bits/stdc++.h> typedef long long int ll; using namespace std; #define MAXN 30001 int first[10]; int last[10]; bool syutugen[10]; int main() { int n; string s; cin >> n >> s; memset(syutugen, false, sizeof(syutugen)); for (int i = 0; i < n; i++) { if (!(syutugen[s[i] - '0'])) { first[s[i] - '0'] = i; } syutugen[s[i] - '0'] = true; last[s[i] - '0'] = i; } int count = 0; for (int i = 0; i <= 9; i++) { for (int j = 0; j <= 9; j++) { for (int k = 0; k <= 9; k++) { if ((syutugen[i]) && (syutugen[k]) && (syutugen[j])) { bool ok = false; for (int l = first[i] + 1; l <= last[k] - 1; l++) { if (s[l] - '0' == j) { ok = true; } } if (ok) { count++; } } } } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; #define INF 1000000001 int main() { int n; string s; cin >> n >> s; vector<vector<bool>> l(n, vector<bool>(10, false)),r(n, vector<bool>(10, false)); for(int i = 1; i < n-1; i++) { l[i]=l[i-1]; l[i][(int)s[i-1]-48]=true; } for(int i = n-2; i >=1; i--) { r[i]=r[i+1]; r[i][(int)s[i+1]-48]=true; } vector<set<int>> a(10); for(int i = 1; i < n-1; i++) { int m=(int)s[i]-48; for(int j = 0; j < 10; j++) { for(int k = 0; k < 10; k++) { if(l[i][j] && r[i][k]){ a[m].insert(j*10+k); } } } } int ans=0; for(int i = 0; i < 10; i++) { ans += a[i].size(); } cout << ans << endl; return 0; }
1
100,561,191
#include <string.h> #include <stdlib.h> #include <math.h> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <iomanip> #include <vector> #include <queue> #include <stack> #include <map> #include <unordered_map> #include <utility> #include <limits.h> #include <bitset> #include <set> using namespace std; #define LL long long int const LL INF = (1LL<<60); const int INF_INT = 2147483647-1e6-1; const LL mod = 1000000007ll; const int mod_int = 1000000007; LL N; LL A[80]; LL ans = 0; void solve(){ vector<LL> dp(N+1,0); dp[0] = 1000; for(int i=0;i<N;i++){ for(int j=0;j<=i;j++){ LL stock_minimum = INF; for(int k=j;k<=i;k++) stock_minimum = min(stock_minimum,A[k]); dp[i+1] = max(dp[i+1],dp[j]/stock_minimum*A[i] + dp[j]%stock_minimum); } } ans = dp[N]; } int main(){ cin >> N; for(int i=0;i<N;i++) cin >> A[i]; solve(); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef pair<int, int>pi; typedef pair<long long, long long>pl; #define F first #define S second #define pb push_back #define all(x) x.begin() , x.end() #define mp make_pair #define FOR(i,a,b) for(i=a;i<=b;i++) #define mem(a) memset(a , 0 ,sizeof a) #define memn(a) memset(a , -1 ,sizeof a) int main() { ll f = 0, n, m = 1000, x, y, i, j, st = 0; cin >> n; int a[n + 23]; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 2; i <= n; i++) { if (a[i] > a[i - 1]) { if (f == 0) { st = m / a[i - 1]; m = m % a[i - 1]; } f = 1; } else if (a[i] < a[i - 1]) { if (f == 1) { m += st * a[i-1]; st = 0; } f = 0; } if (i == n) { m += st * a[i]; } } cout << m << endl; }
1
67,853,233
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0;i<(ll)n;++i) int main() { ll n;cin >> n; vector<ll> e(100001,0); vector<ll> o(100001,0); ll emax = -1; ll omax = -1; ll eid = -1; ll oid = -1; rep(i,n){ ll num;cin >> num; if( i%2 == 0 ){ o.at(num)++; if( omax < o.at(num) ){ omax = max(omax,o.at(num)); oid = num; } }else{ e.at(num)++; if( emax < e.at(num) ){ emax = max(emax,e.at(num)); eid = num; } } } sort(o.begin(),o.end()); sort(e.begin(),e.end()); ll e1 = e.back(); ll e2 = e.at(e.size()-2); ll o1 = o.back(); ll o2 = o.at(o.size()-2); if( eid != oid ){ cout << n - e1 - o1 << endl; }else{ cout << min((n - e1 - o2),(n - e2 - o1 ) ) << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n; cin>>n; map<int, int> even; map<int, int> odd; for (int i=0; i<n; i++){ int v; cin>>v; if(i%2==0){ if(even.count(v)){ even[v]=even[v]+1; } else even[v]=1; } if(i%2!=0){ if(odd.count(v)){ odd[v]=odd[v]+1; } else odd[v]=1; } } auto even_begin = even.begin(), even_end = even.end(); auto odd_begin = odd.begin(), odd_end = odd.end(); ll even1 = 0, even2=0, even1_idx=-1, even2_idx=-1; ll odd1 = 0, odd2=0, odd1_idx=-1, odd2_idx=-1; for(auto iter = even_begin; iter != even_end; iter++){ int key = iter->first, value = iter->second; if(value>even1){ even2=even1; even2_idx=even1_idx; even1=value, even1_idx=key; } else if(value>even2){ even2 = value; even2_idx=key; } } for(auto iter = odd_begin; iter != odd_end; iter++){ int key = iter->first, value = iter->second; if(value>odd1){ odd2=odd1; odd2_idx=odd1_idx; odd1=value, odd1_idx=key; } else if(value>odd2){ odd2 = value; odd2_idx=key; } } ll ans = n; if(even1_idx != odd1_idx) ans -= (even1+odd1); else ans -= max(even1+odd2, even2+odd1); cout << ans << endl; }
1
87,645,003
#include<bits/stdc++.h> using namespace std; #define LL long long LL x, y, z, u, d; vector<LL> a, b, c; int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> x >> y >> z >> d; for(int i = 0; i < x; i++) cin >> u, a.push_back(u); for(int i = 0; i < y; i++) cin >> u, b.push_back(u); for(int i = 0; i < z; i++) cin >> u, c.push_back(u); sort(a.rbegin(), a.rend()), sort(b.rbegin(), b.rend()), sort(c.rbegin(), c.rend()); vector<LL> ans, f; for(int i = 0; i < x; i++) for(int j = 0; j < y; j++) f.push_back(a[i] + b[j]); sort(f.rbegin(), f.rend()); for(int i = 0; i < min(x*y, d); i++) for(int j = 0; j < z; j++) ans.push_back(f[i] + c[j]); sort(ans.rbegin(), ans.rend()); for(int i = 0; i < d; i++) cout << ans[i] << '\n'; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <functional> #include <ctime> #include <cmath> #include <limits> #include <numeric> #include <type_traits> #include <iomanip> #include <float.h> #include <math.h> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll ll_gcd(ll a, ll b) { if (a < b) return ll_gcd(b, a); ll r; while ((r = a % b)) { a = b; b = r; } return b; } class UnionFind { public: vector <ll> par; vector <ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } int main() { ll x,y,z,kk; cin >> x >> y >> z >> kk; vector<ll> xx(x); vector<ll> yy(y); vector<ll> zz(z); for (int i = 0; i < x; i++) { cin >> xx[i]; } for (int i = 0; i < y; i++) { cin >> yy[i]; } for (int i = 0; i < z; i++) { cin >> zz[i]; } sort(xx.begin(), xx.end()); reverse(xx.begin(), xx.end()); sort(yy.begin(), yy.end()); reverse(yy.begin(), yy.end()); sort(zz.begin(), zz.end()); reverse(zz.begin(), zz.end()); vector<ll> ans(1000000); ll now = 0; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { for (int k = 0; k < z; k++) { if ((i+1) * (j+1) * (k+1) > kk)break; ans[now] = xx[i] + yy[j] + zz[k]; now++; } } } sort(ans.begin(), ans.end()); reverse(ans.begin(), ans.end()); for (int i = 0; i < kk; i++) { cout << ans[i] << endl; } }
1
94,223,193
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, n) for (int i = 0; i < n; ++i) #define range(i,a,b) ((a)<=(i) && (i)<(b)) #define debug(x) cout << #x << " = " << (x) << endl; #define fs first #define sc second #define pb push_back #define eb emplace_back #define SP << " " << typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef vector<int> vec; typedef vector<P> pvec; typedef vector<vector<int>> vvec; typedef vector<vector<P>> pvvec; typedef priority_queue<int> PQI; typedef priority_queue<P> PQP; typedef priority_queue<int,vector<int>,greater<int>> PQIG; typedef priority_queue<P,vector<P>,greater<P>> PQPG; const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1}; const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1}; constexpr int MOD = (1000000007); const ll INF = (1LL << 60); const double PI = (3.141592653589794); const double EPS = (0.0000000001); template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;} template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);} template<class T> inline T round(T a, T b) {return T(a / b);} template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; } int nmax=200000; vvec G(nmax); struct UnionFind { private: vector<int> child,tree; vector<vector<int>> list; public: UnionFind(int v) { tree.resize(v); list.resize(v); REP(i,v) tree[i] = i, list[i].push_back(i); } int root(int i){ if(i == tree[i]){ REP(j,child.size()) tree[child[j]] = i; child.clear(); return i; } else{ child.push_back(i); return i = root(tree[i]); } } int size(int i){ return list[root(i)].size(); } vector<int> nodes(int no){ return list[root(no)]; } bool unit(int x, int y){ x = root(x); y = root(y); if(x==y) return false; if(list[x].size() < list[y].size()) swap(x,y); for(int no:list[y]) list[x].emplace_back(no); tree[y] = x; return true; } bool isUnit(int x, int y){ return root(x) == root(y); } }; void solve4ts() { int n; cin>>n; int q; cin>>q; UnionFind uf(n+1); rep(i,q){ int t,a,b; cin>>t>>a>>b; if(t==0) uf.unit(a,b); else{ if(uf.isUnit(a,b)){ cout<<1<<endl; } else{ cout<<0<<endl; } } } } signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); int repeat = 1; while(repeat--) solve4ts(); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> p_ll; typedef vector<pair<ll, ll>> vec_p; #define ture ture #define flase false #define falg flag #define REP(i, x) for (ll i = 0; i < (ll)(x); i++) #define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++) #define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--) #define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--) #define all(x) (x).begin(), (x).end() const ll MOD = pow(10, 9) + 7; const ll LLINF = pow(2, 61) - 1; const int INF = pow(2, 30) - 1; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } struct UnionFind { vector<long long> par; UnionFind(int N) : par(N) { for (int i = 0; i < N; i++) par[i] = i; } long long root(long long x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(long long x, long long y) { long long rx = root(x); long long ry = root(y); if (rx == ry) return; par[rx] = ry; } bool same(long long x, long long y) { long long rx = root(x); long long ry = root(y); return rx == ry; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N,Q; string S; cin >> N>>Q; UnionFind tree(N); REP(i,Q){ ll t, a, b; cin >> t >> a >> b; if(t==0){ tree.unite(a, b); } else{ if(tree.same(a,b)==true){ cout << 1 << endl; } else{ cout << 0 << endl; } } } }
1
7,361,926
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; namespace io { #define SIZ (1 << 21 | 1) #define gc() (io::iS == io::iT ? (io::iT= (io::iS= io::ibuff) + fread(io::ibuff, 1, SIZ, stdin), (io::iS == io::iT ? EOF : *io::iS++)) : *io::iS++) #define putc(x) (io::oS == io::oT ? (fwrite(io::obuff, 1, io::oS - io::obuff, stdout), io::oS= io::obuff, (*io::oS++= x)) : *io::oS++= x) #define exit \ fwrite(io::obuff, 1, io::oS - io::obuff, stdout); \ return 0; char *iS, *iT, ibuff[SIZ], obuff[SIZ], *oS= obuff, *oT= oS + SIZ - 1, fu[110], c; int fr; template <class Type> inline void read(Type &x) { x= 0; Type y= 1; for(c= gc(); (c > '9' || c < '0') && c != '-'; c= gc()) ; c == '-' ? y= -1 : x= (c & 15); for(c= gc(); c >= '0' && c <= '9'; c= gc()) x= x * 10 + (c & 15); x*= y; } inline void reads(char *x) { for(c= gc(); c == ' ' || c == '\n'; c= gc()) ; for(; c != ' ' && c != '\n' && c != EOF; *x= c, c= gc(), ++x) ; } template <class Type> inline void print(Type x, char text= '\n') { if(x < 0) putc('-'), x*= -1; if(x == 0) putc('0'); while(x) fu[++fr]= x % 10 + '0', x/= 10; while(fr) putc(fu[fr--]); putc(text); } inline void prints(char *x, char *y= NULL, char text= '\n') { for(; *x && x != y; ++x) putc(*x); putc(text); } } using io::print; using io::prints; using io::read; using io::reads; long long n, x, a, b, ans; signed main() { read(n), read(x); ans= n, a= x, b= n - x; while(1) { if(a < b) swap(a, b); if(a % b == 0) { ans+= a * 2 - b; break; } else { ans+= a / b * 2 * b; a%= b; } } print(ans); exit; }
#include <bits/stdc++.h> #include <math.h> #define rep(i,n) for (int i = 0; i < (n); i++) #define PI 3.141592653589793 using namespace std; typedef long long ll; template<class T> void chmax(T &a,T b) { if (a<b) a=b;} template<class T> void chmin(T &a,T b) { if (a>b) a=b;} int gcd(int a, int b){ if (a < b) gcd(b,a); if (b == 0) return a; else gcd(b, a % b); } const int INF = 1<<30; const int MOD = 1000000007; int dx[4] = {0,0,-1,1}; int dy[4] = {-1,1,0,0}; int main(){ ll N,X; cin >> N >> X; ll res = N; ll a = max(N-X,X), b = min(N-X,X); while(b){ ll q = a/b; ll r = a % b; res += (b * 2) * q; if (r == 0) res -= b; a = b, b = r; } cout << res << endl; return 0; }
1
23,703,791
#include <bits/stdc++.h> #define rep(i, start, end) for (long long i = start; i < end; ++i) #define repreverse(i, start, end) for (long long i = start; i >= end; --i) #define all(x) (x).begin(), (x).end() #define len(x) ((long long)(x).size()) #define lcm(a, b) ((a) / __gcd((a), (b)) * (b)) using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vllvll = vector<vll>; using pll = pair<ll, ll>; template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';} template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);} template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); } template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); } template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template<class T>bool even(T n) { return ! (n & 1); } template<class T>bool odd(T n) { return n & 1; } template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; } template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; } ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} const long double pi = M_PI; const long long big = 1LL << 50; const long long inf = 1LL << 60; const long long mod = 1e9 + 7; int main() { ll N, K; cin >> N >> K; vll l(N); rep(i, 0, N) cin >> l[i]; sort(l.rbegin(), l.rend()); cout << accumulate(l.begin(), l.begin()+K, 0LL) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() #define all2(a, b) (a).begin(), (a).begin() + (b) #define debug(vari) cerr << #vari << " = " << (vari) << endl; int wa(int n) { int s = 0; while (n) { s += n % 10; n /= 10; } return s; } int main() { int n, k; cin >> n >> k; vector<int> l(n); rep(i, n) cin >> l[i]; sort(all(l)); reverse(all(l)); int ans = 0; rep(i, k) { ans += l[i]; } cout << ans << endl; return 0; }
1
13,758,028
#ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { string s; cin>>s; string s1="WB"; string s2="BW"; int count=0; int n; n=s.length(); rep(i,n){ if(s.compare(i,2,"BW")==0)count++; if(s.compare(i,2,"WB")==0)count++; } cout<<count<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; #define all(x) (x).begin(), (x).end() #define call(x) (x).cbegin(), (x).cend() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define sz(x) ((x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++) const double PI = acos(-1); const int mod = 1e9+7; const long long INF = (1LL << 60); const int dx[] = {0,1,0,-1,1,1,-1,-1}; const int dy[] = {1,0,-1,0,1,-1,-1,1}; 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;} ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);} bool isInteger(double x){return floor(x) == x;} ll ceil(ll a, ll b){return ((a)+(b)-1)/b;} template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; } int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; ll cntw = 0, cntb = 0; ll n = sz(s); rep(i, 0, n){ if(s[i] == s[i+1]) continue; else if(s[i] == 'B') cntb++; else if(s[i] == 'W') cntw++; } if(cntw == 0 || cntb == 0) cout << 0 << endl; else cout << cntb + cntw - 1 << endl; return 0; }
1
79,574,743
#include <iostream> #include <algorithm> using namespace std; int H,N; long long sum = 0; int main(){ cin>>H>>N; int A[N]; for(int i =0;i<N;i++){ cin>>A[i]; sum+=A[i]; } if(sum>=H){cout<<"Yes";} if(sum<H){cout<<"No";} }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; int main() { ll h,n; cin >> h >> n; ll total = 0; rep(i,n) { int x; cin >> x; total += x; } if (h <= total) cout << "Yes" << endl; else cout << "No" << endl; }
1
23,573,576
#pragma target("avx") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> P; typedef vector<ll> V; typedef unordered_map<ll, ll> U_MAP; typedef priority_queue<ll> pq; typedef priority_queue<ll, vector<ll>, greater<ll>> rpq; constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10; constexpr ll LINF = 1e18; #define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++) #define rrep(i, a, b) for (ll i = (a); i < (b); i++) #define rrrep(i, a, b) for (ll i = (a); i >= (b); i--) #define all(v) (v).begin(), (v).end() #define Size(n) (n).size() #define Cout(x) cout << (x) << endl #define doublecout(a) cout << fixed << setprecision(15) << a << endl; #define fi first #define se second #define m_p make_pair #define p_b push_back string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto& x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; string alph("abcdefghijklmnopqrstuvwxyz"); char s[100][100]; ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q; int main(void) { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cin >> h >> w; rep(i, h) rep(j, w) cin >> s[i][j]; rep(i, h) { rep(j, w) { if (s[i][j] == '.') continue; int ok = 0; rep(k, 4) { int ny = i + dy[k], nx = j + dx[k]; if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue; if (s[ny][nx] == '#') ok = 1; } if (!ok) { Cout("No"); return 0; } } } Cout("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (long long i = 0; i < N; i++) using ll = long long; const string YES = "Yes"; const string NO = "No"; void solve(long long H, long long W, std::vector<std::string> s) { vector<pair<ll, ll>> dir{pair<ll, ll>(-1, 0), pair<ll, ll>(1, 0), pair<ll, ll>(0, -1), pair<ll, ll>(0, 1)}; rep(i, H) { rep(j, W) { if (s[i][j] == '#') { bool ok = false; rep(k, 4) { ll tmpi = i + dir[k].first; ll tmpj = j + dir[k].second; if (!(tmpi < 0 || tmpi > H - 1 || tmpj < 0 || tmpj > W - 1)) { if (s[tmpi][tmpj] == '#') { ok = true; } } } if (!ok) { cout << "No" << endl; return; } } } } cout << "Yes" << endl; return; } int main() { long long H; scanf("%lld", &H); long long W; scanf("%lld", &W); std::vector<std::string> s(H); for (int i = 0; i < H; i++) { std::cin >> s[i]; } solve(H, W, std::move(s)); return 0; }
1
93,064,332
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9+7; const long long INF = 1e15; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; vector<ll> a(n),b(n); for(ll i = 0; i < n; i++) cin >> a[i]; for(ll i = 0; i < n; i++) cin >> b[i]; ll m = 0; for(ll i = 0; i < n; i++){ if(b[i] > a[i]){ m += (b[i]-a[i]+1)/2; a[i] += 2*((b[i]-a[i]+1)/2); } } for(ll i = 0; i < n; i++){ if(a[i] > b[i]){ m -= a[i]-b[i]; b[i] = a[i]; } if(m < 0){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include<bits/stdc++.h> #define endl "\n" #define int long long #pragma GCC optimize(3) using namespace std; int n,a[10005],b[10005],s1,s2; signed main() { ios::sync_with_stdio(false); cin>>n; for(int i=1;i<=n*2;i++) (i>n)?(cin>>b[i-n]):(cin>>a[i]); for(int i=1;i<=n;i++) (a[i]>b[i])?(s1+=(a[i]-b[i])):(s2+=(b[i]-a[i])/2); cout<<(s1<=s2?"Yes\n":"No\n"); }
1
71,849,658
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <cmath> using ll=long long; #define rep(i,a,b) for(ll i=a;i<ll(b);i++) #define repr(i,a,b) for(ll i=a;i>=ll(b);i--) #define endl "\n" #define ALL(x) x.begin(),x.end() #define ALLR(x) x.rbegin(),x.rend() #define INF 1e9 #define DEBUG(x) cout<<"debug: "<<x<<endl using namespace std; int n, k; int main() { cin >> n >> k; vector<bool> have(n); rep(i,0,k){ int d; cin >> d; rep(i,0,d){ int t; cin >> t; have[t-1] = true; } } int ans = n; rep(i,0,n){ if(have[i]) ans--; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; set<int> s; cin >> n >> k; while (k --> 0) { int d; cin >> d; for (int i = 0; i < d; ++i) { int a; cin >> a; s.emplace(a); } } cout << n - s.size() << '\n'; return (0); }
1
75,613,868
#include <bits/stdc++.h> int main() { int A[3][3]; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) std::cin >> A[i][j]; int N; std::cin >> N; std::vector<int> b(N); for (int i = 0; i < N; ++i) std::cin >> b[i]; for (int p : b) for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) if (A[i][j] == p) A[i][j] = 0; bool ans = false; for (int i = 0; i < 3; ++i) { if (A[0][i] + A[1][i] + A[2][i] == 0) ans = true; } for (int i = 0; i < 3; ++i) { if (A[i][0] + A[i][1] + A[i][2] == 0) ans = true; } if (A[0][0] + A[1][1] + A[2][2] == 0) ans = true; if (A[0][2] + A[1][1] + A[2][0] == 0) ans = true; if (ans) std::cout << "Yes" << std::endl; else std::cout << "No" << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; #define pb push_back #define ld long double #define f first #define s second #define in insert #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const int INF = 1e18 + 5; const int mod = 1e9 + 7; const int N = 2e5 + 314; const long double pi = 3.1415926535897932384626433832795; void solve(){ int a[3][3]; map<int, int>u, d1, d2; for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ cin>>a[i][j]; if(i==j)d1[a[i][j]]++; if(i+j==2)d2[a[i][j]]++; } } int n; cin>>n; vi v(n); int ans1 = 0, ans2 = 0; for(int i = 0; i < n; i++){ cin>>v[i]; u[v[i]]++; if(d1[v[i]])ans1++; if(d2[v[i]])ans2++; } if(ans1==3||ans2==3){ cout<<"Yes\n"; return; } for(int i = 0; i < 3; i++){ int cnt = 0; for(int j = 0; j < 3; j++){ if(u[a[i][j]])cnt++; } if(cnt==3){ cout<<"Yes\n"; return; } cnt=0; for(int j = 0; j < 3; j++){ if(u[a[j][i]])cnt++; } if(cnt==3){ cout<<"Yes\n"; return; } } cout<<"No\n"; } signed main(){ speed; int t=1; while(t--)solve(); }
1
56,041,220
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; int main(void) { priority_queue<int, vector<int>, greater<int>> train; priority_queue<int, vector<int>, greater<int>> bus; vector<int> tmp(4); for (int i = 0; i < 4; i++) cin >> tmp.at(i); for (int i = 0; i < 4; i++) { if (i < 2) train.push(tmp.at(i)); else bus.push(tmp.at(i)); } cout << train.top() + bus.top() << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B,C,D; cin>>A>>B>>C>>D; int E =min(A,B); int F=min(C,D); cout<<E+F<<endl; }
1
97,916,103
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> #include <cmath> #define pi 3.14159265358979323846264338327950 int main() { long long H, W; std::cin >> H >> W; long long m = W * H; if (H == 1 || W == 1) { std::cout << 1 << std::endl; return 0; } if (H % 2 == 1 && W % 2 == 1) std::cout << m / 2 + 1 << std::endl; else std::cout << m / 2 << std::endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> pii; const int INF = 1e9; const int MOD = 1000000007; const double PI = acos(-1); int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; void solve() { ll h, w; cin >> h >> w; if (h == 1 || w == 1) cout << 1 << endl; else cout << h * w / 2 + ((h*w)% 2); } int main() { solve(); return 0; }
1
55,322,744
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0; i < int(n); i++) #define vi vector<int> #define all(x) (x).begin(),(x).end() #define INF (1<<30)-1 using ll = long long; using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; } int main(){ cin.tie(0), ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; const int MOD = 1e9+7; map<char,int> mp; rep(i,n) mp[s[i]]++; ll ans = 1; for(auto x : mp){ ans *= x.second+1; ans %= MOD; } cout << ans-1; cout << "\n"; return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <cstring> #include <complex> #include <stack> #include <queue> #include <unordered_map> #include <set> #include <map> #define INF 100000000 #define rep(i, a) for (int i = 0; i < (a); i++) using namespace std; using P = pair<int, int>; const int MAX = 1000000; const int MOD = 1000000007; int main(){ int n; cin >> n; string s; cin >> s; int data[26] = {0}; int i; for(i = 0; i < n; i++){ data[s[i]-'a']++; } long long int ans = 1; for(i = 0; i < 26; i++){ ans *= (data[i]+1); ans %= MOD; } cout << (ans - 1 + MOD)%MOD << endl; }
1
62,069,590
#include<iostream> using namespace std; int main(void){ int first,last,input,i,times; times = 0; cin >> first >> last >> input; for(i=first; i<last+1; i++){ if(input < i) break; if(input % i == 0) times++; } cout << times << endl; return 0; }
#include<iostream> #include<algorithm> using namespace std; int main(){ int a,b,c; int rmd=0,i=0,ans=0; cin >>a >>b >>c; do{ if(rmd==c%(a+i)){ ans++; } i++; }while(a+i<=b); cout <<ans <<endl; return 0; }
1
37,417,616
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) #define all(v) v.begin(),v.end() #define len(x) (ll)(x).length() using namespace std; typedef long long ll; typedef pair<int,int> P; const int INF=1e9; const int di[] = {-1,0,1,0}; const int dj[] = {0,-1,0,1}; int main(){ ll q,h,s,d,n; cin>>q>>h>>s>>d>>n; ll ans; if(n%2==0){ ans=min(q*8,min(h*4,min(s*2,d)))*(n/2); } if(n%2==1){ ans=min(q*8,min(h*4,min(s*2,d)))*(n/2)+min(q*4,min(h*2,s)); } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { if(v.size() >= 100) { return "Too big container"; } bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define rep(i,n) for (int i = 0; i < n; ++i) #define rep1(i,n) for (int i = 1; i <= n; ++i) #define reps(i,s,n) for (int i = s; i < n; ++i) #define all(c) begin(c),end(c) template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; typedef long double ld; typedef pair<int,int> PINT; typedef pair<ll,ll> PLL; const long long MOD = 1e9+7; #define precout() cout << std::fixed << std::setprecision(20); #define print(a) cout << a << endl; const long long INFLL = (1LL << 62) - 1; const int INFI = (1 << 30) - 1; template<typename T> void printv(vector<T>&v) { int n = v.size() - 1; rep(i, n) cout << v[i] << " "; cout << v.back() << endl; } const int dy[4] = { 0, 1, 0, -1 }; const int dx[4] = { 1, 0, -1, 0 }; double deg2rad(double deg) { return deg * M_PI / 180; } double rad2deg(double rad) { return rad * 180 / M_PI; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll q,h,s,d; cin >> q >> h >> s >> d; ll n; cin >> n; if(h > q * 2) { h = q * 2; } if(s > h * 2) { s = h * 2; } ll ans = 0; if(n&1) { ans += s; n -= 1; } if(d > s * 2) { ans += s * n; } else { ans += d * (n / 2); } print(ans); }
1
89,585,969
#include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(ll i=0;i<n;i++) #define Graph vector<vector<ll>> #define INF (1ll<<60) #define mod 1000000007 int main(){ string N;ll K; cin>>N>>K; ll dp[110][2][5]; rep(i,110)rep(j,2)rep(k,5) dp[i][j][k]=0; dp[0][0][0]=1; for(ll i=0;i<N.size();i++){ for(ll k=0;k<=K;k++){ dp[i+1][true][k+1]+=9*dp[i][true][k]; dp[i+1][true][k]+=dp[i][true][k]; if(N[i]!='0'){ dp[i+1][true][k+1]+=(N[i]-'0'-1)*dp[i][false][k]; dp[i+1][true][k]+=dp[i][false][k]; } if(N[i]!='0'){ dp[i+1][false][k+1]+=dp[i][false][k]; }else{ dp[i+1][false][k]+=dp[i][false][k]; } } } cout<<dp[N.size()][0][K]+dp[N.size()][1][K]<<endl; return 0; }
#include <iostream> #include <string> #include <vector> using namespace std ; using ll = long long ; using vll = vector<ll> ; using vvll = vector<vll> ; int main(){ string s ; cin >> s ; ll n = s.size(); ll k ; cin >> k ; vvll dp1(n,vll(k+1,0)),dp2(n,vll(k+1,0)) ; dp1.at(0).at(0) = (s.at(0)!='0') ; dp1.at(0).at(1) = s.at(0)-'0'-1 ; dp2.at(0).at(1) = 1 ; for(int i=1;i<n;i++){ if(s.at(i)=='0'){ for(int j=0;j<=k;j++) dp2.at(i).at(j) += dp2.at(i-1).at(j) ; for(int j=1;j<=k;j++) dp1.at(i).at(j) += dp1.at(i-1).at(j-1)*9 ; for(int j=0;j<=k;j++) dp1.at(i).at(j) += dp1.at(i-1).at(j) ; }else{ for(int j=1;j<=k;j++) dp2.at(i).at(j) += dp2.at(i-1).at(j-1) ; for(int j=0;j<=k;j++) dp1.at(i).at(j) += dp2.at(i-1).at(j) ; for(int j=1;j<=k;j++) dp1.at(i).at(j) += dp2.at(i-1).at(j-1)*(s.at(i)-'0'-1) ; for(int j=0;j<=k;j++) dp1.at(i).at(j) += dp1.at(i-1).at(j) ; for(int j=1;j<=k;j++) dp1.at(i).at(j) += dp1.at(i-1).at(j-1)*9 ; } } cout << dp1.at(n-1).at(k)+dp2.at(n-1).at(k) << endl ; }
1
10,771,002
#include <bits/stdc++.h> #include <vector> #include <iostream> #include <map> #include <cmath> #include <string> #include <algorithm> #include <math.h> using namespace std; #define rep(i, o) for (ll i = 0; i < (o);i++) #define rep_s(i, o) for (int i = 1; i <= (o);i++) #define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++) #define NUM 1e5 typedef long long ll; typedef unsigned long long ull; ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } ll lcm(ll c, ll d) { return c / gcd(c, d) * d; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { return b; } return a; } template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return a; } return a; } int main() { ll k, a, b; cin >> k >> a >> b; ll ans = 0; if (b-a <= 2) ans = k+1; else { ans += a; ans += (b-a) * ((k-a+1)/2); ans += (k-a+1)%2; } cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <unordered_map> #include <unordered_set> # define ll int64_t # define str string # define rep(i,n) for(ll i=0;i<n;i++) # define rrep(i,n) for(ll i=1;i<=n;i++) # define ALL(x) (x).begin(), (x).end() # define SZ(x) ((int)(x).size()) # define pb push_back # define mod 1000000007 # define PI 3.141592653589793 # define vec vector #define dump(x) cerr<<#x<<"="<<x<<endl using namespace std; #define INF 2000000000 #define MAX_V 10 bool compare_by_b(pair<string,ll> a,pair<string,ll> b){ if(a.second != b.second) return a.second<b.second; else return a.first<b.first; } bool my_compare(pair<ll,ll> a,pair<ll,ll> b){ if(a.first != b.first) return a.first<b.first; if(a.second != b.second) return a.second>b.second; else return true; } ll modpow(ll a,ll n,ll mod1) { ll res=1; while(n>0){ if(n&1) res=res*a%mod1; a = a*a%mod1; n >>= 1; } return res; } ll factorial(ll n){ ll x=1; rrep(i,n) (x*=i)%=mod; return x; } 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; } const ll MAX = 5100000; const ll MOD = 1000000007; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll 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 k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } using graph = vector<vector<ll>>; pair<pair<ll,ll>,ll> p[100010]; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll k,a,b,sum=1; cin>>k>>a>>b; if(b-a<=2 || a>k){ cout<<k+1<<endl; return 0; } k-=(a-1); sum+=(a-1); if(k%2==0) sum+=(b-a)*(k/2); else{ sum+=(b-a)*(k-1)/2; sum++; } cout<<sum<<endl; return 0; }
1
63,897,663
#include <bits/stdc++.h> #include <iomanip> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll gcd(ll a, ll b){ if (a%b == 0){ return(b); } else{ return(gcd(b, a%b)); } } ll lcm(ll a, ll b){ return a / gcd(a, b)* b; } int kan_hyaku(int n){ int kurai = 0; for(int i=0;i<3;i++){ kurai = n%10; n /=10; } return kurai; } int kan_ju(int n){ int kurai = 0; for(int i=0;i<2;i++){ kurai = n%10; n /=10; } return kurai; } int kan_ichi(int n){ int kurai = 0; for(int i=0;i<1;i++){ kurai = n%10; n /=10; } return kurai; } int keta(int n){ int wa = 1; while(n>0){ wa *=10; n--; } return wa; } double kan_half(int n){ double wa = 1; while(n>0){ wa *= 0.5; n--; } return wa; } ll facctorialMethod(ll k){ ll sum = 1; for (ll i = 1; i <= k; ++i) { sum = sum%1000000007 * i%1000000007; } return sum; } bool red[100010] = {}; int main() { int n,k; cin >> n>>k; cout << n-k+1 << endl; }
#include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; int cnt = 0; for (int i = 0; i < n; i++) { if (i + k - 1 < n) { cnt++; } } cout << cnt << endl; return 0; }
1
23,443,926
#include <bits/stdc++.h> using namespace std; string s1,s2,s3; int main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>s1>>s2>>s3; char c =toupper(s1[0]); cout<<c; c =toupper(s2[0]); cout<<c; c =toupper(s3[0]); cout<<c; return 0;}
#include<bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (int i= (a); i < (b); ++i) typedef long long ll; typedef pair<int,int> P; const int INF = 100100100; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int main() { string s1, s2, s3; cin >> s1 >> s2 >> s3; char t = 'a' - 'A'; cout << (char)(s1[0] - t) << (char)(s2[0] - t) << (char)(s3[0] - t) << endl; }
1
93,444,881
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> lpair; const ll MOD = 1e9 + 7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define print2(x,y) cout << (x) << " " << (y) << endl; #define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N,K; cin >> N >> K; print(N-K+1); }
#include <iostream> #include <numeric> #include <stdio.h> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> using namespace std; using ll = long long; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) int Max(int(a), int(b), int(c)) { return max(max(a, b), c); } int Min(int(a), int(b), int(c)) { return min(min(a, b), c); } int main() { ll N,K; cin >> N>>K; cout << N-K+1 << endl; }
1
29,699,424
#include <algorithm> #include <complex> #include <cstdlib> #include <ctime> #include <time.h> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <numeric> #include <limits> #include <type_traits> #include <locale> #include <omp.h> using namespace std; #define SAY_YES cout << "YES" << endl; #define SAY_Yes cout << "Yes" << endl; #define SAY_NO cout << "NO" << endl; #define SAY_No cout << "No" << endl; #define IFYES(TRUE_OR_FALSE) \ if (TRUE_OR_FALSE) \ { \ cout << "YES" << endl; \ } \ else \ { \ cout << "NO" << endl; \ } #define IFYes(TRUE_OR_FALSE) \ if (TRUE_OR_FALSE) \ { \ cout << "Yes" << endl; \ } \ else \ { \ cout << "No" << endl; \ } #define IFyes(TRUE_OR_FALSE) \ if (TRUE_OR_FALSE) \ { \ cout << "yes" << endl; \ } \ else \ { \ cout << "no" << endl; \ } #define DEBUG_OUTPUT_ARRAY(XXX, ONE) \ for (int i = 0; i < (ONE); i++) \ { \ cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \ } #define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO) \ for (int i = 0; i < (ONE); i++) \ { \ cout << "<<< i = " << i << " >>>" << endl; \ for (int j = 0; j < (TWO); j++) \ { \ cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \ } \ } #define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \ for (int i = 0; i < (ONE); i++) \ { \ cout << i << " "; \ for (int j = 0; j < (TWO); j++) \ { \ cout << XXX[i][j] << " "; \ } \ cout << endl; \ } typedef pair<long long int, long long int> pll; typedef pair<long long int, pll> lpll; const long long int mod = 1000000007; const long long int INF = 1e18; const long double PI=3.14159265358979323; long long int N,M,X,H,W,T,A[200200],y[200200],res=0,sum=0,fin=0,cou=0; string S[105]; map<string,bool>mp; vector<pll>vec; vector<long long int>pl,mi; int main(){ cout << fixed << setprecision(18); cin>>M; for(long long int i = 0; i < M; i++){ cin>>A[i]; if(A[i]>=0){ pl.push_back(A[i]); }else{ mi.push_back(A[i]); } } sort(pl.begin(),pl.end()); sort(mi.begin(),mi.end()); if(mi.size()>0&&pl.size()>0){ sum=mi[0]; for(long long int i = 1; i < pl.size(); i++){ vec.push_back({sum,pl[i]}); sum-=pl[i]; } vec.push_back({pl[0],sum}); sum=pl[0]-sum; for(long long int i = 1; i < mi.size(); i++){ vec.push_back({sum,mi[i]}); sum-=mi[i]; } cout<<sum<<endl; for(long long int i = 0; i < M-1; i++){ cout<<vec[i].first<<" "<<vec[i].second<<endl; } }else if(pl.size()>0){ sum=pl[0]; for(long long int i = 1; i < pl.size()-1; i++){ vec.push_back({sum,pl[i]}); sum-=pl[i]; } vec.push_back({pl[pl.size()-1],sum}); sum=pl[pl.size()-1]-sum; cout<<sum<<endl; for(long long int i = 0; i < M-1; i++){ cout<<vec[i].first<<" "<<vec[i].second<<endl; } }else { sum=mi[mi.size()-1]; for(long long int i = 0; i < mi.size()-1; i++){ vec.push_back({sum,mi[i]}); sum-=mi[i]; } cout<<sum<<endl; for(long long int i = 0; i < M-1; i++){ cout<<vec[i].first<<" "<<vec[i].second<<endl; } } }
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define INF 2e9 #define MOD 1000000007 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; using P = pair<int,int>; int main() { int N; cin >> N; vector<int> A(N); REP(i, N) cin >> A[i]; sort(ALL(A)); ll ans = 0; int cnt = 0; REP(i,N){ if((cnt<=N-2&&A.at(i)<0)||i==0){ ans+=-A.at(i); cnt++; }else{ ans+=A.at(i); } } cout << ans << endl; int x = A.at(0); FOR(i,cnt,N-1){ cout << x << " " << A.at(i) << endl; x=x-A.at(i); } cout << A.at(N-1) << " " << x << endl; x = A.at(N-1)-x; FOR(i,1,cnt){ cout << x << " " << A.at(i) << endl; x=x-A.at(i); } }
1
12,083,972
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define fi first #define se second #define em emplace #define eb emplace_back #define mp make_pair #define pi pair<int,int> #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> bool chmax(T &a, U b) { if (a < b) a = b; return true; } template<class T, class U> bool chmin(T &a, U b) { if (a > b) a = b; return true; } using ll = long long; using ld = long double; using namespace std; constexpr ll MOD = 1000000007; int dp[200001]; signed main() { cout << fixed << setprecision(20); ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; rep(i, 200001) dp[i] = MOD; dp[0] = 0; rep(i, n+1) { for (int j = 6; i+j <= n; j *= 6) chmin(dp[i+j], dp[i]+1); for (int j = 9; i+j <= n; j *= 9) chmin(dp[i+j], dp[i]+1); chmin(dp[i+1], dp[i]+1); } cout << dp[n] << endl; return (0); }
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() #define V vector #define P pair typedef long long ll; const int INT_INF = 1e9; const ll INF = 1LL << 30; int main() { int n; cin >> n; V<int> dp(n + 1, n); dp[0] = 0; for(int i = 1; i <= n; i++){ for(int p6 = 1; p6 <= i; p6 *= 6){ dp[i] = min(dp[i], dp[i - p6] + 1); } for(int p9 = 1; p9 <= i; p9 *= 9){ dp[i] = min(dp[i], dp[i - p9] + 1); } } cout << dp[n] << endl; }
1
56,127,673
#include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <string> #include <string.h> using namespace std; int main() { string s,t; cin >> s; bool flag = 0; for(char ch = 'a'; ch <= 'z'; ch++) { for(int i = 0; i < s.size(); i++) { if(ch == s[i]) { flag = 0; break; } else flag = 1; } if(flag) { cout << ch << endl; return 0; } } cout << "None" << 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++) using namespace std; using ll = long long; using pi = pair<int, int>; const ll INF = 1LL << 60; int main() { string s; cin >> s; vector<int>arr(26,0); for (auto ss: s) { arr[ss - 'a']++; } rep(i, 26) { if (arr[i] == 0) { cout << char('a' + i) << endl; return 0; } } cout << "None" << endl; return 0; }
1
66,244,722
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, k; cin >> n >> k; ll ans = pow(n/k, 3); if (k%2==0) ans += pow((n+k/2)/k, 3); cout << ans; return 0; }
#include<iostream> #include <vector> #include <cmath> #include <algorithm> #include <utility> #include <map> using namespace std; int main() { long N,K; cin >> N >> K; long num = N / K; long longCount = num*num*num; if (K % 2 == 1) { cout << longCount << endl; return 0; } else { long num2 = 0; for (int i = 0; i <= N; i++) { if (i % K == K / 2) { num2++; } } longCount= longCount+ num2 * num2 * num2; cout << longCount << endl; return 0; } cout << " "<< endl; return 0; }
1
90,163,372
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i <= (int)(n); i++) using namespace std; typedef long long ll; int main() { int n; cin >> n; int a[n+1]; int b[n+1]; int cnt = 0; rep(i, n) { cin >> a[i]; } rep(i , n) { if(a[a[i]] == i) cnt++; } cout << cnt / 2 << endl; return (0); }
#include <bits/stdc++.h> #include <vector> #include <algorithm> #include <math.h> using namespace std; int CalcSumOfDigit(int n); long long getDigit(long long n); string upper(string str); string lower(string str); #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define sz(a) int((a).size()) #define rep(i,n) for(int(i)=0;(i)<(n);(i)++) #define repe(i,n) for(int(i)=0;(i)<=(n);(i)++) #define vsort(v) sort((v).begin(),(v).end()) #define rvsort(v) sort(rall((v))) #define vi vector<int> #define GCD(a,b) __gcd((a),(b)) #define LCM(a,b) ((a)/GCD((a),(b))*(b)) #define kiriage(a,b) ((a)+(b)-1)/(b) const int INF = 1e9; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> vll; int main() { ll n; cin >> n; vll a(n); rep(i,n) { cin >> a[i]; a[i]--; } ll ans = 0; rep(i,n) { if(i == a[a[i]]) { ans++; } } cout << ans / 2 << endl; return 0; } ll getDigit(ll n) { int i = 1; while(1) { n = n / 10; if(n == 0) break; i++; } return i; } ll CalcSumOfDigit(ll n) { ll s = 0; while(n) { s += n % 10; n = n / 10; } return s; } string upper(string str) { for(auto itr = str.begin();itr != str.end() ; itr++) { if(97 <= *itr && *itr <= 122) { *itr = *itr - 32; } } return str; } string lower(string str) { for(auto itr = str.begin();itr != str.end() ; itr++) { if(65 <= *itr && *itr <= 90) { *itr = *itr + 32; } } return str; }
1
90,641,814
#include <stdio.h> #include <iostream> using namespace std; #define MAX_N 100000 #define NIL -1 struct Node { int parent; int left; int right; }; void print_node(Node nodes[], int i, int depth[]) { printf("node %d: parent = %d, depth = %d, ", i, nodes[i].parent, depth[i]); if(nodes[i].parent == NIL) { printf("root, "); } else if(nodes[i].left == NIL) { printf("leaf, []"); return; } else { printf("internal node, "); } printf("["); for(int n=nodes[i].left; n!=NIL; n=nodes[n].right) { printf("%d", n); if(nodes[n].right != NIL) { printf(", "); } } printf("]"); } void walk_depth(Node nodes[], int depth[], int p, int d) { depth[p] = d; for(int n=nodes[p].left; n!=NIL; n=nodes[n].right) { walk_depth(nodes, depth, n, d+1); } } int main() { Node nodes[MAX_N]; int depth[MAX_N]; int cs[MAX_N]; int n; cin >> n; for(int i=0; i<n; i++) { nodes[i].parent = NIL; } for(int i=0; i<n; i++) { int id, k; cin >> id >> k; cs[0] = NIL; for(int j=0; j<k; j++) { cin >> cs[j]; nodes[cs[j]].parent = id; } cs[k] = NIL; for(int j=0; j<k; j++) { nodes[cs[j]].right = cs[j+1]; } nodes[id].left = cs[0]; } int root = 0; for(int i=0; i<n; i++) { if(nodes[i].parent == NIL) root = i; } walk_depth(nodes, depth, root, 0); for(int i=0; i<n; i++) { print_node(nodes, i, depth); printf("\n"); } }
#include <stdio.h> #define debug #define NMAX 100010 #define NIL -1 int left[NMAX]; int right[NMAX]; int parent[NMAX]; int depth[NMAX]; void setDepth(int i, int d) { debug("setDepth %d %d\n", i, d); if (i == NIL) { return; } depth[i] = d; setDepth(left[i], d + 1); setDepth(right[i], d); } int main() { int n, k, id, prev, x; scanf("%d", &n); for (int i = 0; i < n; i++) { parent[i] = NIL; left[i] = NIL; right[i] = NIL; } for (int i = 0; i < n; i++) { scanf("%d %d", &id, &k); for (int j = 0; j < k; j++) { scanf("%d", &x); parent[x] = id; if (j == 0) { left[id] = x; } else { right[prev] = x; } prev = x; } } int root = 0; for (int i = 0; i < n; i++) { if (parent[i] == NIL) { root = i; break; } } setDepth(root, 0); for (int i = 0; i < n; i++) { printf("node %d: ", i); printf("parent = %d, ", parent[i]); printf("depth = %d, ", depth[i]); if (parent[i] == NIL) { printf("root, "); } else if (left[i] == NIL) { printf("leaf, "); } else { printf("internal node, "); } printf("["); k = left[i]; while (k!=NIL) { printf("%d", k); if (right[k] != NIL) { printf(", "); } k = right[k]; } printf("]\n"); } return 0; }
1
95,693,830
#include <cmath> #include <iostream> #include <iomanip> using namespace std; #define PI 3.141592653589793238 int main(){ int a , b , c; cin >> a >> b >> c; cout << fixed << setprecision(9) << a*b*sin(PI/180*c)/2 << endl; cout << fixed << setprecision(9) << a+b+sqrt(a*a+b*b-2*a*b*cos(PI/180*c)) << endl; cout << fixed << setprecision(9) << b*sin(PI/180*c) << endl; return 0; }
#include <iomanip> #include <iostream> #include <cmath> using namespace std; int main(){ double a, b, deg, rad; cin >> a >> b >> deg; rad = deg / 180 * 3.141592653589793; double bsin = b * sin(rad); cout << fixed << setprecision(5); cout << a * bsin / 2 << endl; cout << a + b + sqrt(a*a + b*b - 2*a*b*cos(rad)) << endl; cout << bsin << endl; }
1
11,307,313
#include <bits/stdc++.h> using namespace std; int main(){ int n,t; cin >> n >> t; int a[n]; for(int i = 0; i < n; i++){ cin >> a[i]; } long long count = t; for(int i = 0; i < n-1; i++){ count += min(a[i+1]-a[i],t); } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=1;i<n;i++) #define ll long long int int main(){ int n; cin>>n; ll T,t[n]; cin>>T; ll count=T; cin>>t[0]; for(int i=1;i<n;i++){ cin>>t[i]; if(t[i]-t[i-1]>T){ count+=T; } else { count+=t[i]-t[i-1]; } } cout<<count<<endl; return 0; }
1
29,738,699
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ string S; cin >> S; ll cnt = 0; if(S[0] != 'A'){ cout << "WA" << endl; return 0; } for(int i = 2; i < S.size() - 1; i++){ if(S[i] == 'C') cnt++; } if(cnt != 1){ cout << "WA" << endl; return 0; } for(int i = 0; i < S.size() ; i++){ if(0 > S[i] - 'a' && S[i] - 'a' >= -32) cnt++; } if(cnt == 3) cout << "AC" << endl; else cout << "WA" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size(); bool b = true; if(S[0] != 'A') { b = false; } bool c = false; for(int i = 2; i < N - 1; i++) { if(S[i] == 'C' && c) { c = false; break; } if(S[i] == 'C' && !c) { c = true; } } if(!c) { b = false; } vector<char> alph = {'a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'}; int count = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < 26; j++) { if(S[i] == alph[j]) { count ++; break; } } } if(count != N - 2) { b = false; } if(b) { cout << "AC" << endl; } else { cout << "WA" << endl; } }
1
64,730,573
#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 (void){ int N,M; ll X; cin >> N >> M >> X; vector<ll> C(N); vector<vector<ll>> A(N,vector<ll>(M)); rep(i,N){ cin >> C[i]; rep(j,M){ cin >> A[i][j]; } } ll ans = 99999999; for(int bit=0; bit < (1 << N); ++bit){ vector<ll> levels(M); ll cost = 0; rep(i,N){ if(bit & (1 << i)){ cost += C[i]; rep(j,M){ levels[j] += A[i][j]; } } } bool can_buy = true; rep(i,M){ if(levels[i] < X){ can_buy = false; } } if(can_buy){ ans = min(ans,cost); } } if(ans == 99999999) cout << "-1" << endl; else cout << ans << endl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long int #define MOD 1000000007 #define oo 1000000000000000000 #define forr(i,n) for(ll i=0;i<n;i++) #define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0); #define all(x) x.begin(),x.end() #define eb emplace_back #define pb push_back #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> using namespace __gnu_pbds; using namespace std; ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); } ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); } ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;} ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL; ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p); } ll inv(ll x){return power(x,MOD-2);} void __sol(){ int n,m,x; cin >> n >> m >> x; int a[n+2][m+3]; for(int i=0;i<n;i++){ for(int j=0;j<=m;j++) cin >> a[i][j]; } int ans = INT_MAX; forr(mask,(1<<n)){ int temp[m+3]; memset(temp,0,sizeof(temp)); int cost=0; forr(i,n){ if( mask&(1<<i)){ cost+= a[i][0]; for(int j=1;j<=m;j++) temp[j]+=a[i][j]; } } bool hit=1; for(int i=1;i<=m && hit;i++){ if(temp[i]<x) hit=0; } if(hit) ans = min(ans , cost); } if(ans==INT_MAX) cout << -1; else cout << ans; } int main(){ fastio ll tc=1; while(tc--) __sol(); return 0; }
1
28,388,171
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <vector> #include <deque> #include <list> #include <queue> #include <math.h> #include <assert.h> #include <set> #include <map> #include <bitset> #include <ctime> #include <time.h> #include <algorithm> #include <cstdio> #include <fstream> #include <stack> #include <ctype.h> #include <numeric> #include <sstream> #include <unistd.h> #include <unordered_map> #include <unordered_set> #include <limits> #include <random> #include <chrono> #include <iomanip> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; #define endl '\n' #define debug(name) DEBUG(#name, (name)) template<typename T> void DEBUG(string label, T value) { cerr << "[" << label << " = " << value << "]\n"; } void solve(){ queue<long long> q; for(int i = 1; i <= 9; ++i){ q.push(i); } int k; cin >> k; ll x; while(k--){ x = q.front(); q.pop(); if(x % 10 != 0){ q.push(10 * x + (x % 10) - 1); } q.push(10 * x + (x % 10)); if(x % 10 != 9){ q.push(10 * x + (x % 10) + 1); } } cout << x << endl; } int main(int argv, char **argc){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; while(t--) solve(); }
#pragma GCC diagnostic ignored "-Wunused-variable" #include <bits/stdc++.h> using namespace std; #define BOOST #ifdef BOOST #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/range/adaptor/reversed.hpp> using namespace boost; using ml = boost::multiprecision::cpp_int; using md = boost::multiprecision::cpp_dec_float_100; #define forir(i, ...) if(ll i=(ll)v.size())for(__VA_ARGS__)if(i--,1) #define eachr(i, e, c) forir(i, auto &&e: adaptors::reverse(c)) #endif using ll = long long; using ld = long double; using pll = pair<long long, long long>; template <class T> using vt = vector<T>; template <class T> using vvt = vector<vector<T>>; template <class T> using vvvt = vector<vector<vector<T>>>; #define all(c) (c).begin(), (c).end() #define coutd cout << fixed << setprecision(10) #define output(x) do{cout<<x;return 0;}while(0) #define rep(i, b, e) for (ll i = b; i < e; i++) #define repr(i, b, e) for (ll i = b; e < i; i--) #define fori(i, ...) if (ll i = -1) for(__VA_ARGS__) if (i++, 1) #define each(i, e, c) fori (i, auto&& e: c) #define llong_max 9223372036854775807 #define ldbl_max 1.79769e+308 #define pi 3.1415926535897932 auto Ceil = [] (auto x) { return (ll)ceil(x); }; auto Count = [] (auto b, auto e, auto x) { return (ll)count(b, e, x); }; auto CtoL = [] (auto c) { return (ll)c - (ll)'0'; }; auto LtoC = [] (auto n) { return (char)('0' + n); }; auto Pow = [] (auto a, auto b) { return (ll)pow(a, b); }; auto Pow2 = [] (auto n) { return (1LL << n); }; auto Pow10 = [] (auto n) { return (ll)pow(10, n); }; auto Size = [] (auto& c) { return (ll)(c).size(); }; auto Sum = [] (auto b, auto e) { return accumulate(b, e, 0LL); }; template <class T> void MakeVVT (ll ys, ll xs, vvt<T>& v, T fill = T()) { v.resize(ys); rep(y, 0, ys) v[y].resize(xs, fill); } template <class T> void MakeVVVT (ll zs, ll ys, ll xs, vvvt<T>& v, T fill = T()) { v.resize(zs); rep(z, 0, zs) MakeVVT(ys, xs, v[z], fill); } template <class T> void InputVVT (ll ys, ll xs, vvt<T>& v, T fix = T()) { MakeVVT(ys, xs, v, fix); rep(y, 0, ys) rep(x, 0, xs) { cin >> v[y][x]; v[y][x] += fix; } } template <class T> void InputVVVT (ll zs, ll ys, ll xs, vvvt<T>& v, T fix = T()) { v.resize(zs); rep(z, 0, zs) InputVVT(ys, xs, v[z], fix); } namespace NyaGadget {} namespace NyaGadget { struct NT_NyaaNumberEnumeration { std::vector<long long> test; void Run(std::pair<long long, long long> range, long long size, std::vector<std::vector<long long>>& res) { if ((long long)test.size() == size) { res.push_back(test); return; } for (long long i = range.first; i <= range.second; ++i) { if (Size(test) != 0 && 1 < abs(test.back() - i)) continue; test.push_back(i); Run(range, size, res); test.pop_back(); } } }; } using namespace NyaGadget; int main(void) { ll K; cin >> K; set<ll> ans; rep(k, 1, 11) { std::vector<std::vector<long long>> res; NT_NyaaNumberEnumeration nne; nne.Run({ 0,9 }, k, res); each(i, e, res) { ll test = 0; rep(j, 0, Size(e)) test += Pow10(j) * e[j]; ans.insert(test); } } each(i, e, ans) if (i == K) cout << e; return 0; }
1
15,033,831
#include <bits/stdc++.h> using namespace std; #define FOR(i,o,n) for(long long i = o;i<n;i++) #define oneforall ios::sync_with_stdio(false);cin.tie(0); #define all(v) (v).begin(),(v).end() #define ini(...) int __VA_ARGS__; in(__VA_ARGS__) #define inl(...) long long __VA_ARGS__; in(__VA_ARGS__) #define ins(...) string __VA_ARGS__; in(__VA_ARGS__) #define int long long const long long INF=1e18; void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);} void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);} typedef vector<int> vi; typedef vector<long long> vl; typedef long long ll; typedef vector<pair<long, long > > vpll; typedef vector<pair<int, int > > vpii; int32_t main() { oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall ini(n); vi morty; if(n <=2){out(0);return 0;} for(int i = 2;i*i<=n;i++){ if(n%i == 0){ morty.push_back(i); if(n/i!=i)morty.push_back(n/i); } } int tmp = 0; FOR(i,0,morty.size()){ int x = morty[i]-1; if(n/x == n%x)tmp+=x; } out(tmp+n-1); }
#include <bits/stdc++.h> #define cout16 cout << setprecision(16) #define rep(i,n) for(int i=0;i<n;i++ ) #define rep2(i,f,n) for(int i=f;i<n;i++ ) #define SORT(A) sort(A.begin(),A.end()) #define REV(A) reverse(A.begin(),A.end()) typedef long long int ll; using vi = std::vector<int>; using vvi = std::vector<std::vector<int>>; using vll = std::vector<ll>; using vvll = std::vector<std::vector<ll>>; using P = std::pair<int,int>; using vp = std::vector<P>; using namespace std; #define INF 1001001001 #define LL_INF 1001001001001001001 #define fi first #define se second vll divisor(ll n){ vll res; for(ll i=1; i*i<=n; i++){ if(n%i) continue; res.push_back(i); if(i*i!=n) res.push_back(n/i); } SORT(res); return res; } int main(void) { ll n; cin >> n; vll divis = divisor(n); ll ans = 0; for(auto di: divis){ if(di==1) continue; ll m = di-1; if((n/m)==(n%m)) ans += m; } cout << ans << endl; }
1
66,868,658
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> t(n+2), a(n+2), h(n+2, 0); t[0] = 0; a[n+1] = 0; for(int i = 1; i <= n; i++){ cin >> t[i]; if(t[i] != t[i-1]) h[i] = t[i]; } for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = n; i >= 1; i--){ if(a[i] != a[i+1]){ if(h[i] == 0) h[i] = a[i]; else{ if(h[i] != a[i]){ cout << 0 << endl; return 0; } } } } long long ans = 1; for(int i = 1; i <= n; i++){ if(h[i] == 0){ ans = (ans * min(t[i], a[i])) % MOD; } else{ if(t[i] < h[i] || a[i] < h[i]){ ans = 0; break; } } } cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <fstream> #include<cstdio> #include<iomanip> #include<stack> #include<queue> #include<string> #include <cstdlib> #include <typeinfo> #include <math.h> #include <list> #define REP(i, n) for(int i=0;i<n;i++) #define REP2(i, s, n) for(int i=s;i<n;i++) #define REP_1(i, n) for(int i=1;i<n+1;i++) #define bitSearch(bit, n) for(int bit = 0; bit < (1 << n); bit++) using namespace std; template<class T> void print(const T &value) { std::cout << value << std::endl; } void yesno(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; } void YesNo(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; } void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; } typedef long long ll; typedef unsigned long ul; typedef long double ld; template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll INF = 10000000; ll mod = 1000000007; int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1}; using Graph = vector<vector<int>>; using GraphW = vector<vector<pair<int, int>>>; using P = pair<int, int>; using lP = pair<ll, ll>; using PP = pair<int, P>; using p_queue = priority_queue<int, vector<int>, greater<int>>; class UnionFindTree { public: UnionFindTree(int size) : memberSize(size) { par.resize(size * sizeof(ll)); rnk.resize(size * sizeof(ll)); diff_weight.resize(size * sizeof(ll)); REP(i, size) { par[i] = i; rnk[i] = 0; diff_weight[i] = 0; } } int memberSize; vector<int> par; vector<int> rnk; vector<ll> diff_weight; void init(ll n) { REP(i, n) { par[i] = i; rnk[i] = 1; } } int find(ll x) { if (par[x] == x) { return x; } else { int r = find(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll 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]++; } } } ll weight(ll x) { find(x); return diff_weight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } void merge(int x, int y, int w) { w += weight(x); w -= weight(y); x = find(x); y = find(y); if (x == y) { return; } if (rnk[x] < rnk[y]) { par[x] = y; diff_weight[x] = -w; } else { par[y] = x; diff_weight[y] = w; if (rnk[x] == rnk[y]) { rnk[x]++; } } } }; int main() { int N; cin >> N; ll T[N], A[N]; REP(i, N) { cin >> T[i]; } REP(i, N) { cin >> A[i]; } if (T[0] > A[0]) { print(0);return 0; } if (T[N - 1] < A[N - 1]) { print(0);return 0; } if (T[N-1] != A[0]) { print(0);return 0; } ll ans = 1; for (int i = 1; i < N - 1; i++) { if (T[i] != T[i - 1]) { if (T[i] > A[i]) { print(0);return 0; } continue; } if (A[i] != A[i + 1]) { if (A[i] > T[i]) { print(0);return 0; } continue; } ans *= min(T[i], A[i]); ans %= mod; } print(ans); }
1
34,355,526
#include <bits/stdc++.h> using namespace std; #define ll long long int #define P 1000000007 #define inf 1e18 int main() { ll i, n; cin >> n; cout << (n * (n - 1)) / 2 << "\n"; return (0); }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; cout << (long long)n * (n-1) /2 << endl; }
1
43,354,680
#include <iostream> #include <fstream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <map> #include <queue> #include <bitset> #include <random> #include <stack> using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<string> vs; typedef vector<vs> vvs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef map<string,int> msi; typedef map<int,int> mii; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; #define REP(i, a, b) \ for (int i = int(a); i <= int(b); i++) #define REPb(j, d, c) \ for (int j = int(d); j >= int(c); j--) #define pb \ push_back #define ff \ first #define ss \ second int main() { int n; cin >> n; int k; REP(i, 1, 10000) { if(i*(i-1) == 2*n) { k = i; break; } if(i*(i-1) > 2*n) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; vi claimed(n+1, -1); vector<priority_queue<int>> elements_in_sets; priority_queue<int> fake; elements_in_sets.pb(fake); priority_queue<int> elements_yet_to_be_used; REP(i, 1, n) { elements_yet_to_be_used.push(-i); } cout << k << endl; REP(subset, 1, k) { cout << k-1 << " "; priority_queue<int> current_subset_elements; REP(previous_subsets, 1, subset-1) { cout << -elements_in_sets[previous_subsets].top() << " "; elements_in_sets[previous_subsets].pop(); } REP(extra_elements, 1, (k-1)-(subset-1)) { cout << -elements_yet_to_be_used.top() << " "; current_subset_elements.push(elements_yet_to_be_used.top()); elements_yet_to_be_used.pop(); } elements_in_sets.pb(current_subset_elements); cout << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int n,maxa,vis[100005]; vector<int> v[505]; int main() { int sum=1;vis[1]=2; for(int i=2;i;i++){if(sum+i>100000) break;sum+=i;vis[sum]=i+1;maxa=max(maxa,vis[sum]);} cin>>n;if(!vis[n]) return !puts("No");int m=1,gg=0; while(gg<n){for(int i=1;i<=m;i++) v[i].push_back(i+gg);for(int i=1;i<=m;i++) v[m+1].push_back(i+gg);gg+=m;m++;} puts("Yes");cout<<vis[n]<<endl; for(int i=1;i<=vis[n];i++) { printf("%d",v[i].size()); for(int j=0;j<v[i].size();j++) printf(" %d",v[i][j]);puts(""); } }
1
35,188,419
#include<algorithm> #include<iostream> #include<functional> #include<cmath> #include<iomanip> using namespace std; int main(){ char s[16]; for(int i=0;i<12;i++){ cin>>s[i]; char a=s[i]; cout<<a; if(i==3) cout<<" "; } cout<<endl; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define REP(i,n) for(int i=0;i<n;i++) #define REPP(i,n) for(int i=1;i<=n;i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e17) #define PI (acos(-1)) #define i_7 (long long)(1e9+7) long mod(long a){ long long c=a%i_7; if(c>=0)return c; return c+i_7; } using namespace std; bool prime_(int n){ if(n==1){ return false; }else if(n==2){ return true; }else{ for(int i=2;i<=sqrt(n);i++){ if(n%i==0){ return false; } } return true; } } long long gcd_(long long a, long long b){ if(a<b){ swap(a,b); } if(a%b==0){ return b; }else{ return gcd_(b,a%b); } } long long lcm_(long long x, long long y){ return (x/gcd_(x,y))*y; } int main(){ string s; cin>>s; string ans = ""; for(int i=0;i<4;i++){ ans += s[i]; } ans += ' '; for(int i=4;i<12;i++){ ans += s[i]; } cout<<ans<<endl; return 0; }
1
51,020,948
#include <cstdio> #include <algorithm> #define fail return puts("-1"), 0 const int N = 1e3 + 5; int n, sz; long long x[N], y[N], bin[33]; void solve(long long x, long long y) { for (int i = sz - 1; i >= 0; i--) { if (std::labs(x) > std::labs(y)) { putchar(x < 0 ? 'L' : 'R'); x < 0 ? x += bin[i] : x -= bin[i]; } else { putchar(y < 0 ? 'D' : 'U'); y < 0 ? y += bin[i] : y -= bin[i]; } } puts(""); } int main() { scanf("%d", &n); bool flg1 = false, flg2 = false; for (int i = 1; i <= n; i++) { scanf("%lld %lld", &x[i], &y[i]); ((x[i] + y[i]) & 1 ? flg1 : flg2) = true; } if (flg1 && flg2) fail; if (flg1) { printf("%d\n", sz = 33); for (int i = sz - 1; i >= 0; i--) { printf("%lld%c", bin[i] = 1LL << i, " \n"[i == 0]); } } else { printf("%d\n", sz = 34); for (int i = sz - 1; i >= 1; i--) { printf("%lld ", bin[i] = 1LL << (i - 1)); } printf("%lld\n", bin[0] = 1); } for (int i = 1; i <= n; i++) solve(x[i], y[i]); return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <string> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); int n, x[1003] = {}, y[1003] = {}, b = 0; cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; for (int i = 1; i < n; i++) if (abs(x[i] + y[i]) % 2 != abs(x[0] + y[0]) % 2) { cout << -1; return 0; } if ((x[0] + y[0]) % 2 == 0) { cout << 32 << '\n'; for (int i = 30; i >= 0; i--) cout << (1 << i) << ' '; cout << 1 << '\n'; for (int i = 0; i < n; i++) x[i]--; b = 1; } else { cout << 31 << '\n'; for (int i = 30; i >= 0; i--) cout << (1 << i) << ' '; cout << '\n'; } for (int i = 0; i < n; i++) { int u = 0, v = 0; for (int j = 30; j >= 0; j--) { if (x[i] - u > y[i] - v && x[i] - u > v - y[i]) u += (1 << j), cout << 'R'; else if (x[i] - u > y[i] - v && x[i] - u < v - y[i]) v -= (1 << j), cout << 'D'; else if (x[i] - u < y[i] - v && x[i] - u > v - y[i]) v += (1 << j), cout << 'U'; else if (x[i] - u < y[i] - v && x[i] - u < v - y[i]) u -= (1 << j), cout << 'L'; else return 1; } if (b) cout << 'R'; cout << '\n'; } }
1
79,077,742
#include <iostream> #include <string> #include <algorithm> #include <cstdio> #include <vector> #include <queue> #include <set> #include <numeric> #include <cmath> using namespace std; typedef long long int lld; const lld mod = 1e9+7; const lld INF = 1e9; const lld MAXN = 1e5; vector<lld> fact,inv; lld f(lld a,lld b, lld p) { if (b == 0) { return 1; }else if (b % 2 == 0) { lld d = f(a,b/2,p); return ((d%mod) * d) % mod; }else { return ((a%mod) * f(a,b-1,p) % mod)%mod; } } void init(lld n) { fact.resize(n+1,1); inv.resize(n+1,1); for(int i = 1; i < n+1; i++) { fact[i] = fact[i-1] % mod * i % mod; } } lld comb(lld n,lld k) { lld x = 0; if (n < k) { return x; } x = ((fact[n]%mod) * (f(fact[k],mod-2,mod) % mod ) %mod) * (f(fact[n-k],mod-2,mod)% mod) % mod; return x; } int main() { lld n; cin >> n; if (n == 1) { cout << 1 << endl; cout << 1 << endl; return 0; } vector<lld> a(n+2); for(int i = 1; i < n+2; i++) { cin >> a[i]; } lld same=0,sum=0; for(int i = 1; i < n+2; i++) { sum += a[i]; } same = sum - (n * (n+1)) / 2; lld left,right; bool ch = false; for(lld i = 1; i < n+2; i++) { if (a[i] == same) { if (!ch) { left = i; ch = true; }else { right = i; break; } } } lld del = left + n - right; init(n+2); for(int i = 1; i < n+2; i++) { cout << (comb(n+1,i) - comb(n-right+left,i-1) + mod)%mod << endl; } return 0; }
#include<cstdio> #include<cstring> #include<vector> #include<queue> #include<algorithm> #include<cmath> #include<climits> #include<string> #include<set> #include<numeric> #include<map> #include<iostream> using namespace std; #define rep(i,n) for(int i = 0;i<((int)(n));i++) #define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++) #define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--) #define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--) typedef long long ll; typedef pair<ll, ll> mp; struct Factorial{ long long N,mod; vector<long long> fact,inv; long long mod_pow(long long x,long long n){ long long res=1; while(n){ if(n&1) (res*=x)%=mod; (x*=x)%=mod; n>>=1; } return res; } long long Inverse(long long n){ return mod_pow(n,mod-2); } Factorial(){} Factorial(long long sn,long long smod){ N=sn; mod=smod; fact.reserve(sn+1); inv.reserve(sn+1); fact[0]=1; for(int i=1;i<=sn;i++){ fact[i]=(fact[i-1]*i) % mod; } inv[sn]=Inverse(fact[sn]); for(int i=sn;i>0;i--){ inv[i-1]=(inv[i]*i) % mod; } } long long Fact(long long n){ if(n<0)return 0; return fact[n]; } long long Inv(long long n){ if(n<0)return 0; return inv[n]; } long long Combination(long long n,long long r){ if(n<r)return 0; if(r<0)return 0; if(r==0)return 1; long long ans=1; ans = (ans*Fact(n)) % mod; ans = (ans*Inv(r)) % mod; ans = (ans*Inv(n-r)) % mod; return ans; } long long plus(long long a,long long b){ a%=mod; b%=mod; return (a+b)%mod; } long long minus(long long a,long long b){ a%=mod; b%=mod; return (a+mod-b)%mod; } long long mul(long long a,long long b){ a%=mod; b%=mod; return (a*b)%mod; } long long div(long long a,long long b){ a%=mod; b%=mod; return (a*Inverse(b))%mod; } }; int main(void){ ll n,a[100010],visit[100010]={},l,r,c,mod=1e9+7; Factorial f(100010,mod); cin>>n; reg(i,1,n+1){ cin>>a[i]; if(visit[a[i]]==0){ visit[a[i]]=i; }else{ l=visit[a[i]]-1; r=n+1-i; } } reg(k,1,n+1){ cout<<(f.Combination(n+1,k)-f.Combination(l+r,k-1)+mod)%mod<<endl; } return 0; }
1
25,516,483
#include <map> #include <unordered_map> #include <unordered_set> #include <set> #include <vector> #include <numeric> #include <algorithm> #include <iostream> #include <string> #include <cstring> #include <sstream> #include <functional> #include <queue> #include <deque> #include <stack> #include <cassert> #include <bitset> using namespace std; using int64 = long long; const int magic = 1000000007; void add (int & a, int b) { a += b; if (a >= magic) a -= magic; } void sub (int & a, int b) { a -= b; if (a < 0) a += magic; } int mul (int a, int b) { return (int64)a * b % magic; } int FastPow(int a, int p) { if (!p) return 1; int res = FastPow(a, p >> 1); res = mul(res, res); if (p & 1) res = mul(res, a); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; vector<int> dp(K + 1); int res = 0; for (int i = K; i >= 1; i--) { dp[i] = FastPow(K / i, N); for (int j = 2 * i; j <= K; j += i) sub(dp[i], dp[j]); add(res, mul(i, dp[i])); } cout << res << "\n"; return 0; }
#include <stdio.h> #include <algorithm> using namespace std; typedef long long ll; ll BigN = 1000000007; ll powmod(ll a, ll n){ ll ret = 1; for(ll i=0;i<60;i++){ if(n&(1LL<<i)) ret*=a; a=(a*a)%BigN; ret%=BigN; } return ret; } int N,K; int visit[100001]={1,1,}; ll dp[100001]={0,1,}; ll sol(int k, int r){ if(r!=1) return sol(k/r,1); else if(visit[k]) return dp[k]; ll ret = powmod(k,N); for(int i=2;i<=k;i++) ret=(ret+BigN-sol(k,i))%BigN; visit[k] = 1; return dp[k] = ret; } int main(int argc, char *argv[]) { scanf("%d %d",&N,&K); ll sum = 0; for(int i=1;i<=K;i++){ sum += 1LL*i*sol(K,i); sum%= BigN; } printf("%lld",sum); }
1
16,006,779
#include<iostream> #include<vector> using namespace std; int main(){ vector<int> sum; int n,m,x,max; while(cin>>n>>m,n||m){ cin>>x; sum.push_back(0); sum.push_back(x); max=-1000000; for(int i=2;i<=n;i++){ cin>>x; sum.push_back(sum[i-1]+x); } for(int i=0;i<n-m+1;i++){ if(sum[m+i]-sum[i]>max) max=sum[m+i]-sum[i]; } cout<<max<<endl; sum.clear(); } return 0; }
#include <iostream> #include <fstream> #include <typeinfo> #include <vector> #include <cmath> #include <set> #include <map> #include <string> #include <algorithm> #include <cstdio> #include <queue> #include <iomanip> #include <cctype> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<P> vp; typedef vector<vp> vvp; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<25; const double pi=acos(-1); const double eps=1e-10; const vi emp; int n,k; vi a; int main(){ while(1){ cin>>n>>k; if(!n&&!k) break; a=vi(n); ll sum=0,ans; for(auto i=a.begin();i!=a.end();i++){ cin>>*i; if(i<a.begin()+k) sum+=*i; } ans=sum; for(auto i=a.begin()+k;i!=a.end();i++){ sum+=*i-*(i-k); ans=max(ans,sum); } cout<<ans<<endl; } }
1
35,895,741
#include <bits/stdc++.h> #include <math.h> using namespace std; int main() { string S;cin >> S; string T = S; int Ans = 0; int A = 0, B = 0; for(int i = 0; i < S.length(); i++){ if(i%2 == 0 && S.at(i) == '1'){ S.at(i) = '0';A++;} if(i%2 == 1 && S.at(i) == '0'){ S.at(i) = '1';A++;} } S = T; for(int i = 0; i < S.length(); i++){ if(i%2 == 0 && S.at(i) == '0'){ S.at(i) = '1';B++;} if(i%2 == 1 && S.at(i) == '1'){ S.at(i) = '0';B++;} } Ans = min(A, B);cout << Ans << endl; }
#include<bits/stdc++.h> using namespace std; int main() { int c=0; string s; cin>>s; for(int i=0;i<s.size();i++) if((i%2&&s[i]=='1')||(i%2==0&&s[i]=='0')) c++; cout<<min(c,(int)s.size()-c); }
1
69,211,140
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(20) << fixed; string S; cin >> S; int countB = 0; int countW = 0; for (int i = 0; i < S.size(); i++) { if ((S[i] == '0' && i % 2 == 0) || (S[i] == '1' && i % 2 != 0)) { countB++; } else { countW++; } } cout << min(countB, countW) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { string S; cin>>S; int a=S.size(); int b=0; int c=0; rep(i,a){ if(i%2==0) { if(S[i]=='0'){ b++; } } else{ if(S[i]=='1'){ b++; } } } rep(i,a){ if(i%2==1) { if(S[i]=='0'){ c++; } } else{ if(S[i]=='1'){ c++; } } } cout<<min(b,c)<<endl; }
1
7,086,789
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<=n;++i) 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(a > b){ a = b; return 1; } return 0; } int main() { int n; cin >> n; vector<int> x(n); rep(i,n) cin >> x[i]; int l; cin >> l; int q; cin >> q; vector<int> a(q), b(q); rep(i,q) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } int M = 20; vector<vector<int>> c(n, vector<int>(M)); rep(i,n) { int lb = -1, ub = n; while(ub - lb > 1) { int mid = (ub + lb)/2; (x[mid] <= x[i] + l ? lb : ub) = mid; } c[i][0] = lb; } rep1(j,M-1) { rep(i,n) { c[i][j] = c[c[i][j-1]][j-1]; } } vector<int> pow2(M+1); pow2[0] = 1; rep(i,M) { pow2[i+1] = pow2[i] * 2; } rep(i,q) { if(a[i] > b[i]) swap(a[i], b[i]); int res = 0; int v = a[i]; while(1) { int idx = 0; while(c[v][idx] < b[i]) idx++; if(idx == 0) { res += pow2[idx]; break; } else { res += pow2[idx-1]; } v = c[v][idx-1]; } cout << res << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define N 100000 + 5 #define rep(i, l, r) for(int i = l; i <= r; ++i) int n, l, q, a, b, tot, siz, x[N], nxt[N], last[N], cntb[N], block[N]; int read(){ char c; int x = 0, f = 1; c = getchar(); while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int main(){ n = read(), siz = sqrt(n), tot = ceil(1.0 * n / siz); rep(i, 1, n) x[i] = read(); l = read(); rep(i, 1, n){ int pos = upper_bound(x + 1, x + n + 1, x[i] + l) - x; if(x[pos] < x[i] + l) last[i] = n + 1; else last[i] = pos - 1; } block[n + 1] = tot + 1; rep(i, 1, n) block[i] = i / siz + 1; rep(i, 1, n){ int pos = i, cnt = 0; while(block[pos] == block[i]) pos = last[pos], ++cnt; cntb[i] = cnt, nxt[i] = pos; } q = read(); while(q--){ a = read(), b = read(); if(a > b) swap(a, b); int pos = a, ans = 0; while(block[pos] < block[b]) ans += cntb[pos], pos = nxt[pos]; while(pos < b) pos = last[pos], ++ans; printf("%d\n", ans); } return 0; }
1
83,420,744
#include <bits/stdc++.h> using namespace std; #define FOR(i, start, end) for(uint64_t i=start; i<end; i++) #define REP(i, n) FOR(i, 0, n) uint64_t gcd(uint64_t m, uint64_t n) { uint64_t temp; while (m % n != 0){ temp = n; n = m % n; m = temp; } return n; } uint64_t lcm(uint64_t m, uint64_t n) { return (m*n)/gcd(m,n); } void comb(vector<vector <uint64_t> > &v){ for(uint64_t i = 0;i <v.size(); i++){ v[i][0]=1; v[i][i]=1; } for(uint64_t k = 1;k <v.size();k++){ for(uint64_t j = 1;j<k;j++){ v[k][j]=(v[k-1][j-1]+v[k-1][j]); } } } bool is_product_overflow(uint64_t a, uint64_t b) { uint64_t prod = a * b; return (prod / b != a); } void primeFactorization(uint64_t a, list<uint64_t> &factors){ long i,sq; if(a%2==0){ factors.push_back(2); primeFactorization(a/2,factors); return; } sq = sqrt(a); for(i=3;i<=sq;i+=2){ if(a%i==0){ factors.push_back(i); primeFactorization(a/i,factors); return; } } if(a!=1){ factors.push_back(a); } } int64_t modinv(int64_t a, int64_t m) { int64_t b = m, u = 1, v = 0; while (b) { int64_t t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } signed main() { int n,m; cin >> n >> m; vector< vector<int> > job(100010); int a,b; for(int i=0;i<n;i++){ cin >> a >> b; job[a].push_back(b); } int totalPayment = 0; priority_queue<int> pays; for(int i=1;i<=m;i++){ for(auto p:job[i]){ pays.push(p); } if(pays.size()>0){ totalPayment += pays.top(); pays.pop(); } } cout << totalPayment << endl; return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; int n,m; pair<int,int> ab[100005]; priority_queue<int> que; bool cmp(const pair<int,int>&a,const pair<int,int>&b) { if(a.first!=b.first) return a.first<b.first; return a.second>b.second; } int main() { scanf("%d%d",&n,&m); for(int i=0;i<n;++i) scanf("%d%d",&ab[i].first,&ab[i].second); sort(ab,ab+n,cmp); int j=0;long long ans = 0; for(int i=1;i<=m;++i){ while(j<n&&ab[j].first<=i){ que.push(ab[j].second);++j; } if(!que.empty()){ ans+=que.top();que.pop(); } } printf("%lld\n",ans); return 0; }
1
82,045,474
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define big 1000000007 map<int,int64_t> p; void fl(int64_t n){ if(n==1){ return ; } int tmp = n; while(tmp%2==0 ){ tmp /= 2; p[2]++; } for(int i=3;i*i<=tmp;i++){ while(tmp % i ==0){ tmp /= i; p[i]++; } } if(tmp!=1){ p[tmp]++; } } int main(){ int n; cin>>n; if(n<=9){ cout<<0<<endl; return 0; } for(int i=1;i<=n;i++){ fl(i); } int s=p.size(); int p75,p3,p25,p5,p15; p75=0; p3=0; p25=0; p5=0; p15=0; for(auto c:p){ int sh = c.second; if(sh>=74){ p75++; } if(sh>=24){ p25++; } if(sh>=14){ p15++; } if(sh>=4){ p5++; } if(sh>=2){ p3++; } } cout<<p75+p25*(p3-1)+(p5-1)*p15+(p3-2)*p5*(p5-1)/2<<endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) #define sz(v) ((int) v.size()) using namespace std; using i64 = long long; using f80 = long double; using vi32 = vector<int>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << endl; exit(0); } inline void no() { cout << "No" << endl; exit(0); } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> inline void amax(T &x, T y) { x = max(x, y); } template <typename T> inline void amin(T &x, T y) { x = min(x, y); } template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } struct Prime { int n; vector<int> pri; Prime() : n(0) {} Prime(int n) : n(n) { vector<bool> f(n, true); f[0] = f[1] = false; for (int i = 2; i < n; i++) { if (!f[i]) continue; pri.push_back(i); for (int j = i * 2; j < n; j += i) { f[j] = false; } } } bool is(int x) { if (n > x) { return binary_search(pri.begin(), pri.end(), x); } if (x < 2) return 0; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } map<int, int> factor(int k) { map<int, int> so; for (auto p : pri) { while (k % p == 0) k /= p, so[p]++; } if (k != 1) so[k] = 1; return so; } }; auto prime = Prime(1000); void solve() { int len = 0; each(p, prime.pri) { if (p >= 100) break; len++; } vi32 cnt(len); int n; cin >> n; reps(i, n) { int x = i; rep(j, len) { int p = prime.pri[j]; while (x % p == 0) cnt[j]++, x /= p; } } int ans = 0; rep(i, len) { if (cnt[i] >= 74) ans++; } rep(i, len) rep(j, len) { if (i == j) continue; if (cnt[i] >= 24 && cnt[j] >= 2) ans++; } rep(i, len) rep(j, len) { if (i == j) continue; if (cnt[i] >= 14 && cnt[j] >= 4) ans++; } set<tuple<int, int, int>> se; rep(i, len) rep(j, len) rep(k, len) { if (i == j || j == k || k == i) continue; if (se.count(make_tuple(min(i, j), max(i, j), k)) >= 1) continue; if (cnt[i] >= 4 && cnt[j] >= 4 && cnt[k] >= 2) ans++; se.insert(make_tuple(min(i, j), max(i, j), k)); } cout << ans << endl; }
1
35,795,510
#include <bits/stdc++.h> typedef long long LL; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define DECIM8 fixed<<setprecision(8) #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(),(c).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) const double EPS = 1e-10; const double PI = acos(-1.0); #define CLR(a) memset((a), 0 ,sizeof(a)) using namespace std; int main(void) { for(;;){ int n,a,b,c,x; cin >> n >> a >> b >> c >> x; if(!n&&!a&&!b&&!c&&!x) return 0; queue<int> y; REP(i,n){ int tmp; cin >> tmp; y.push(tmp); } int answer=0; for(;;){ if(answer>10000){ answer=-1; break; } if(y.front()==x) y.pop(); if(y.empty()) break; answer++; x=(a*x+b)%c; } cout << answer << endl; } }
#include <algorithm> #include <numeric> #include <map> #include <vector> #include <iostream> using namespace std; int main() { while (true) { int n, a, b, c, x; cin >> n >> a >> b >> c >> x; if (!n) break; int d[110]; for (int i = 0; i < n; i++) { cin >> d[i]; } int u = 0; int i = 0; for (i = 0; i < 10001; i++) { if (d[u] == x) { u++; if (u == n) break; } x = (a*x+b)%c; } if (i == 10001) { printf("-1\n"); } else { printf("%d\n", i); } } }
1
56,172,160
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define repp(i, a, b) for (int i = a; i <= (b); ++i) #define repr(i, a, b) for (int i = a; i >= (b); --i) typedef long long ll; const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1000000007; 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; cin >> N; ll Z, W; cin >> Z >> W; vector<ll> a(N); rep(i, N) cin >> a[i]; ll ans; if (N == 1) { ans = abs(a[0] - W); } else { ans = max(abs(W - a[N - 1]), abs(a[N - 2] - a[N - 1])); } cout << ans << endl; }
#include <iostream> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <map> #include <algorithm> #include <iomanip> #include <math.h> #include <string.h> #include <cstdio> #include <tuple> using namespace std; using ll = long long; using pll = pair<ll, ll>; using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>; #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head h, Tail... t) { cerr << " " << h; if (sizeof...(t) > 0) cerr << " :"; debug_out(t...); } template <typename T> ostream& operator<<(ostream& os, vector<T> vec) { for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } ll 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: return 0; } } bool pairCompare(const pll firstElof, pll secondElof) { return firstElof.first > secondElof.first; } ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R; ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1; vl flag, color, D; vll path; int main() { cin >> N >> Z >> W; vl A(N); for (i = 0; i < N; i++) cin >> A[i]; if (N == 1) { cout << abs(A[0] - W); } else { cout << max(abs(A[N - 1] - W), abs(A[N - 2] - A[N - 1])); } }
1
75,098,883
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin>>n>>k; vector<int> a(n); for(auto& e: a) cin>>e; sort(rbegin(a), rend(a)); int res=n; long s=0; for(int i=0; i<n; ++i) { s+=a[i]; if (s>=k) { res=min(res, n-i-1); s-=a[i]; } } cout<<res<<endl; }
#include <iostream> #include <vector> #include <algorithm> #include <set> using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); ++i) #define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i) int main() { int N, K; cin >> N >> K; vector<long long> a(N); REP(i, N) cin >> a[i]; sort(a.begin(), a.end(), greater<long long>()); int ans = 0; set<long long> s; REP(i, N){ if(a[i] >= K) continue; if(!s.empty()){ set<long long> tmp(s); if(a[i]+*(--s.end()) >= K) ans = 0; else ++ans; for(int v: tmp){ if(v+a[i] < K){ s.insert(v+a[i]); s.erase(v); } else break; } }else ++ans; s.insert(a[i]); } cout << ans << endl; return 0; }
1
82,849,401
#include <iostream> #include <string> #include <stdio.h> #include <cmath> #include <cfloat> #include <algorithm> #include <numeric> #include <vector> #include <iterator> #include <set> #include <map> using namespace std; const double PI=acos(-1); int main(){ long a, b, c, n, cnt = 0; cin >> a >> b >> c >> n; for(int aa = 0; a*aa <= n; aa++){ for(int bb = 0; b*bb <= n; bb++){ if(a*aa + b*bb <= n && (n - (aa*a + b*bb))%c == 0) cnt++; } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<string> vs; #define INF 1e9 #define LINF __LONG_LONG_MAX__ int main() { int R, G, B, N; cin >> R >> G >> B >> N; const int N_MAX = 3000; ll cnt = 0; for (int i = 0; i <= N_MAX; i++) { for (int j = 0; j <= N_MAX; j++) { int x = N - i * R - j * G; int k = x / B; if (k < 0 || k > N_MAX) continue; if ((i * R + j * G + k * B) == N) { cnt++; } } } cout << cnt << endl; }
1
25,603,006
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using P = pair<int,int>; int main() { string s; cin >> s; bool ok = true; int cnt = 0; if(s[0] != 'A') ok = false; for(int i = 1; i < (int)s.size(); i++) { if(isupper(s[i])) { if(i == 1 || i == (int)s.size() - 1 || s[i] != 'C') ok = false; cnt++; } } if(cnt != 1) ok = false; if(ok) cout << "AC" << endl; else cout << "WA" << endl; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { string s,ans; int c,p,n; c=0; cin>>s; n=s.size(); ans="AC"; if(s.at(0)!='A') ans="WA"; else { s.at(0)='a'; for(int i=2;i<n-1;i++) { if(s.at(i)=='C') { c++; p=i; } } if(c!=1) ans="WA"; else { s.at(p)='a'; for(int i=0;i<n;i++) { if((s.at(i)<=96)||(s.at(i)>=123)) { ans="WA"; break; } } } } cout<<ans<<endl; }
1
87,425,132
#include<bits/stdc++.h> #define l(i,a,n)for(int i=a;i<n;i++) #define pb push_back #define in insert #define mp make_pair #define lw(v) sort(v.begin(),v.end()); #define hi(v) sort(v.begin(),v.end(),greater<long long>()); #define all(v) v.begin(),v.end() #define filein freopen ("input.txt", "r", stdin) #define fileout freopen ("output.txt", "w", stdout) using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0; vector<long long>v; vector<long long>u; set<long long>s; std::vector<int>::iterator it; string s1,s2,s3,s4; cin>>n>>m>>k; l(i,0,10) { x=n*k-m; cout<<x<<endl; k=x; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) int main(){ ll r, d; cin >> r >> d; vector<ll> x(100); cin >> x[0]; rep(i, 0, 10) x[i+1] = r*x[i] - d; rep(i, 1, 11) cout << x[i] << endl; return 0; }
1
43,403,448
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; using namespace std; vector<ll> a, p; ll dfs(ll n, ll x) { if (n == 0) return x <= 0 ? 0 : 1; else if (x <= a[n - 1] + 1) return dfs(n - 1, x - 1); else return p[n - 1] + 1 + dfs(n - 1, x - 2 - a[n - 1]); } int main() { ll n, x; cin >> n >> x; a.push_back(1), p.push_back(1); rep(i, n) { a.push_back(a[i] * 2 + 3); p.push_back(p[i] * 2 + 1); } cout << dfs(n, x) << endl; return 0; }
#pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long ll calc_size(int level) { return (1LL << (2 + level)) - 3LL; } ll calc_patty(int level) { return (1LL << (1 + level)) - 1LL; } ll solve(int level, ll x) { if (level == 0 && x == 1) return 1LL; --x; if (x == 0) return 0LL; ll sz = calc_size(level - 1); if (x <= sz) return solve(level - 1, x); ll res = calc_patty(level - 1); x -= sz; if (x == 0) return res; res++; --x; if (x == 0) return res; res += solve(level - 1, min(sz, x)); return res; } int main() { int N; ll X; cin >> N >> X; cout << solve(N, X) << endl; return 0; }
1
6,825,438
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, a, b) for(int i = a; i < b; i++) #define all(x) (x).begin(),(x).end() #define rall(v) (v).rbegin(), (v).rend() #define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll; typedef long long int lli; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; } int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; int main(){ int n, s; cin >> n >> s; vector<int> x(n); rep(i,n) cin >> x[i]; vector<int> diff(n); rep(i,n) diff[i] = abs(x[i] - s); int ans = diff[0]; for(int i = 1; i < n; i++){ ans = __gcd(ans, diff[i]); } cout << ans << endl; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, x, first; cin >> n >> x >> first; int ret = abs(x - first); for (int i = 1; i < n; i++) { int a; cin >> a; ret = __gcd(ret, abs(x - a)); } cout << ret << endl; return 0; }
1
89,676,956
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, n) for (int i = 1; i <= (int)(n); i++) int main(){ int N; cin >> N; int total = 0; int candy = 1; for (int i = 1; i <= N; i++){ total += candy; candy += 1; } cout << total << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main(){ int N; cin >> N; int ans =0; rep(i,N) ans += i+1; cout << ans << endl; }
1
47,574,256
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) begin(x), end(x) #define chmax(x,y) x = max(x,y) #define chmin(x,y) x = min(x,y) using namespace std; typedef long long ll; typedef pair <int,int> P; const int MAX = 5000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main(){ COMinit(); int s; cin>>s; int l=1,ans=0; while(s>=l*3){ ll r=s-l*3; ans=(ans+COM(r+l-1,r))%MOD; l++; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define mp make_pair #define pb push_back #define pf push_front #define ss second #define ff first #define sz(x) (int)x.size() #define newl "\n" #define vi vector<int> #define pii pair<int, int> #define vii vector<pii> #define vl vector<ll> #define pll pair<ll, ll> #define vll vector<pll> #define coutp cout << fixed << setprecision(12) #define mem(x, val) memset(x, val, sizeof(x)) #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define all(v) (v).begin(), (v).end() const ld pi = 3.14159265359; ll INF = 1e18 + 10; ll MOD = 998244353; ll mod = 1e9 + 7; inline ll add(ll a, ll b, ll m) { if ((a + b) >= m) return (a + b) % m; return a + b; } inline ll mul(ll a, ll b, ll m) { if ((a * b) < m) return a * b; return (a * b) % m; } ll power(ll x, ll y, ll m) { ll res = 1; x = x % m; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % m; y = y >> 1; x = (x * x) % m; } return res; } void solve() { ll s; cin>>s; vl dp(s+1,0); dp[0]=1; for(int i=3;i<=s;i++) { for(int j=0;j<=i-3;j++) { dp[i]=(dp[i]+dp[j])%mod; } } cout<<dp[s]; } int main() { fastio; int t; t = 1; while (t-- > 0) { solve(); cout << newl; } return 0; }
1
46,872,809
#include<iostream> using namespace std; int main() { int d,s_d; int fx; for(;cin >> d;) { fx=0; for(s_d=d;d<600;d+=s_d) fx+=d*d*s_d; cout << fx << endl; } }
#include<bits/stdc++.h> using namespace std; int main(){ int d, ans; while(scanf("%d", &d)!=EOF){ ans=0; for(int i=d; i<600; i+=d) ans+=pow((double)i, 2.0)*d; printf("%d\n", ans); } return 0; }
1
199,862
#include <bits/stdc++.h> #include "atcoder/dsu" typedef long long int ll; using namespace std; using namespace atcoder; int main() { int n, q; cin >> n >> q; vector<int> ans; dsu d(n); for (int i = 1; i <= q; i++) { int t, u, v; cin >> t >> u >> v; if (t == 0) { d.merge(u, v); } else { if (d.same(u, v)) { ans.push_back(1); } else { ans.push_back(0); } } } for (int i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; #include <atcoder/all> using namespace atcoder; int main(){ int n,q; cin >> n >> q; dsu d(n); rep(i,q){ int t,u,v; cin >> t >> u >> v; if(t==0){ d.merge(u,v); }else{ cout << (d.same(u,v)?1:0) << endl; } } }
1
26,857,668
#include <bits/stdc++.h> using namespace std; int main(void) { int n,L;cin>>n>>L; int a[n]; for(int i = 0; i < n; i++) cin>>a[i]; bool flag = false; int left,right; for(int i = 0; i < n-1; i++){ if(a[i]+a[i+1] >= L){ flag = true; left = i; right = i+1; } } if(flag == false){ cout<<"Impossible"<<endl; return 0; } else{ cout<<"Possible"<<endl; if(left >= 1){ for(int i = 1; i <= left; i++){ cout<<i<<endl; } } if(right < n-1){ for(int i = n-1; i > right; i--){ cout<<i<<endl; } } cout<<right<<endl; } return 0; }
#include <bits/stdc++.h> #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define ll long long using namespace std; const ll P = 1000000007; const long long INF = 1LL << 60; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int main() { cout << fixed << setprecision(10); int N,L; cin >> N >> L; vector<int> a(N),b(N); rep(i,N) { cin >> a[i]; } rep(i,N-1) { b[i] = a[i] + a[i+1]; } sort(RALL(b)); if(b[0]<L) { cout << "Impossible" << endl; return 0; } else { cout << "Possible" << endl; int k = 0; rep(i,N-1) { if(a[i]+a[i+1]==b[0]) { k = i+1; break; } else { cout << i + 1 << endl; } } for(int i = N-1;i>=k;i--) { cout << i << endl; } } return 0; }
1
44,934,600
#include <bits/stdc++.h> #define ll long long #define fast ios_base::sync_with_stdio(false);cin.tie(NULL) #define fr(i,a,b) for(int i=a;i<b;i++) #define frr(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define vi vector<int> #define vl vector<ll> #define pp pop_back #define pi pair<int ,int > #define mk make_pair #define ff first #define ss second #define si set<int> #define sit set<int>::iterator using namespace std; int main() { fast; string s;cin>>s; int cnt=0,ans=0; char cmp='R'; fr(i,0,s.size()) { if(s[i]==cmp) cnt++; else { ans=max(ans,cnt); cnt=0; } } cout<<max(ans,cnt); return 0; }
#include<iostream> #include<string> #include<cmath> #include<algorithm> #include <ctime> using namespace std; int main() { string s; cin>>s; int max=0; for(int i=0; i<=(int)s.size()-1; ++i) { int sum=0; if(s[i]=='R'){ int j=i; while(s[j]=='R') { sum++; j++; } if(sum>max) max=sum; } }cout<<max<<endl; return 0; }
1
26,091,359
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) bool kai(string s, int b, int e) { int n = e - b; bool tf = true; for(int i = b; i < n/2; i++) { if(s[i] != s[n-1-i]) tf = false; } return tf; } int main() { string s; cin >> s; int n = (int)s.size(); bool ans1 = kai(s,0,n); bool ans2 = kai(s,0,n/2); bool ans3 = kai(s,(n+1)/2,n); if(ans1 && ans2 && ans3) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> #include<iostream> #include<algorithm> #include<vector> #include<stdio.h> #include<cstring> #include<math.h> #include<map> #include<bitset> #include<iomanip> #include<queue> #include<functional> #include<stack> #include<tuple> #include<cassert> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using P = pair<int, int>; int main() { string s; cin >> s; int N = s.size(); bool f = true; rep(i, N) { if(s[i] != s[N-1-i]) { f = false; } } rep(i, (N-1)/2) { if(s[i] != s[(N-1)/2 - 1 - i]) { f = false; } } rep(i, N-(N+3)/2+1) { if(s[(N+3)/2-1+i] != s[N-1-i]) { f = false; } } if(f) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
1
54,095,294
#include <bits/stdc++.h> using namespace std; int main() { vector<vector<int>> Bingo(3, vector<int>(3)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) cin >> Bingo.at(i).at(j); } int N, S; cin >> N; vector<int> Bi(N); for(int i = 0; i < N; i++) { cin >> Bi.at(i); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < N; k++) { if (Bingo.at(i).at(j) == Bi.at(k)) Bingo.at(i).at(j) = 0; } } } bool ans = false; for (int i = 0; i < 3; i++) { if (Bingo.at(i).at(0) == 0 && Bingo.at(i).at(1) == 0 && Bingo.at(i).at(2) == 0) ans = true; if (Bingo.at(0).at(i) == 0 && Bingo.at(1).at(i) == 0 && Bingo.at(2).at(i) == 0) ans = true; } if (Bingo.at(0).at(0) == 0 && Bingo.at(1).at(1) == 0 && Bingo.at(2).at(2) == 0) ans = true; else if (Bingo.at(0).at(2) == 0 && Bingo.at(1).at(1) == 0 && Bingo.at(2).at(0) == 0) {ans = true;} cout << (ans ? "Yes" : "No") << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N = 9; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); int Q; cin >> Q; while (Q--) { int b; cin >> b; for (int i = 0; i < N; i++) { if (A.at(i) == b) A.at(i) = -1; } } bool b = 0; if (A.at(0) + A.at(1) + A.at(2) == -3) b = 1; if (A.at(3) + A.at(4) + A.at(5) == -3) b = 1; if (A.at(6) + A.at(7) + A.at(8) == -3) b = 1; if (A.at(0) + A.at(3) + A.at(6) == -3) b = 1; if (A.at(1) + A.at(4) + A.at(7) == -3) b = 1; if (A.at(2) + A.at(5) + A.at(8) == -3) b = 1; if (A.at(0) + A.at(4) + A.at(8) == -3) b = 1; if (A.at(2) + A.at(4) + A.at(6) == -3) b = 1; cout << ((b) ? "Yes" : "No") << "\n"; }
1
87,833,649
#include <stdio.h> #include <string.h> #include <limits.h> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <map> #include <set> #include <stack> #include <queue> typedef unsigned long long ULLONG; typedef long long LLONG; static const LLONG MOD_NUM = 1000000007; template<class _T> static void getint(_T& a) { std::cin >> a; } template<class _T> static void getint(_T& a, _T& b) { std::cin >> a >> b; } template<class _T> static void getint(_T& a, _T& b, _T& c) { std::cin >> a >> b >> c; } template <class _T> static _T tp_abs(_T a) { if (a < (_T)0) { a *= (_T)-1; } return a; } static void exec(); int main() { exec(); fflush(stdout); return 0; } static void exec() { int N, L; getint(N, L); int core = -1; LLONG bfr = 0; std::vector<LLONG> ai(N); for (int i = 0; i < N; i++) { getint(ai[i]); if (bfr + ai[i] >= L) { core = i + 1; } bfr = ai[i]; } if (core < 0) { printf("Impossible\n"); return; } printf("Possible\n"); for (int i = N - 1; i >= core; i--) { printf("%d\n", i); } for (int i = 1; i < core; i++) { printf("%d\n", i); } }
#include<bits/stdc++.h> #define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i) #define rep(i,a,b) for(int i=int(a);i<int(b);++i) #define All(x) (x).begin(),(x).end() #define rAll(x) (x).rbegin(),(x).rend() using namespace std; using ll = long long; int main(){ int N,L; cin>>N>>L; vector<int> a(N); REP(i, N) cin >> a[i]; vector<ll> S(N+1); REP(i,N) S[i+1]=S[i]+a[i]; vector<int> ans1,ans2; REP(i,N-1){ if(a[i]+a[i+1]>=L){ cout<<"Possible"<<endl; REP(j,i) cout<<j+1<<endl; for(int j=N-1;j>i;--j) cout<<j<<endl; return 0; } } cout<<"Impossible"<<endl; }
1
15,193,708
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair< ll, ll > Pi; #define rep(i,n) for(int i=0;i<(n);i++) #define rep2(i,n) for(int i=1;i<=(n);i++) #define rep3(i,i0,n) for(int i=i0;i<(n);i++) #define pb push_back #define mod 1000000007 const ll INF = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define mp make_pair bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; int main() { ll N; cin >>N; vector<ll>a(N); rep(i,N){ cin>>a[i]; } ll ans=INF; rep3(i,-100,101){ ll sum=0; rep(j,N){ sum+=(a[j]-i)*(a[j]-i); } chmin(ans,sum); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; static const long long maxLL = (long long) 1 << 62; int main(void) { int n; cin >> n; vector<int> A(n); for (auto &a: A) cin >> a; long long cost = maxLL; for (int x = -100; x <= 100; ++x) { long long sum = 0; for (int i = 0; i < n; ++i) { sum += (x - A[i]) * (x - A[i]); } cost = min(cost, sum); } cout << cost << endl; }
1
82,890,811
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main(){ int N,X,Y; char x[1024],y[1024]; int dp[1024][1024]; scanf("%d",&N); while(N--){ scanf("%s%s", x, y); X = strlen(x); Y = strlen(y); memset(dp, 0, sizeof dp); for(int i=0;i<X;i++){ for(int j=0;j<Y;j++){ if(x[i]==y[j]) dp[i+1][j+1] = dp[i][j]+1; else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]); } } printf("%d\n", dp[X][Y]); } return 0; }
#include<stdio.h> int hantei(char x[], char y[]) { int xn = 0, yn = 0, flag = 0, i, j, max = 0; int c[1001][1001]; while (flag == 0) { if (x[xn] != '\0') { xn++; } else { flag = 1; } } flag = 0; while (flag == 0) { if (y[yn] != '\0') { yn++; } else { flag = 1; } } for (i = 1; i < xn + 1; i++) c[i][0] = 0; for (j = 1; j < yn + 1; j++) c[0][j] = 0; for (i = 1; i < xn + 1; i++) { for (j = 1; j < yn + 1; j++) { if (x[i - 1] == y[j - 1]) { c[i][j] = c[i - 1][j - 1] + 1; } else if (c[i - 1][j] >= c[i][j - 1]) { c[i][j] = c[i - 1][j]; } else { c[i][j] = c[i][j - 1]; } if (max < c[i][j]) max = c[i][j]; } } return max; } int main(void) { char x[1000], y[1000]; int q, i; scanf("%d", &q); for (i = 0; i < q; i++) { scanf("%s", x); scanf("%s", y); printf("%d\n", hantei(x, y)); } return 0; }
1
49,874,017
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ int n,k,i; string s; cin >> n >> s >> k; for(i=0;i<n;i++){ if(s.at(i)!=s.at(k-1)){ s.at(i)='*'; } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++) #define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--) #define rep(i,n) FOR(i,0,n) #define rrep(i,n) RFOR(i,0,n) #define ALL(v) v.begin(), v.end() #define bra(first,second) '(' << first << ',' << second << ')' ll MOD = 1000000007; ll INF = 100100100100100100; long double EPS = 1e-11; long double PI = 3.141592653589793238; template<typename T> void remove(std::vector<T>& vector, unsigned int index){ vector.erase(vector.begin() + index); } using Graph = vector<vector<ll>>; int main(){ ll N; string S; ll K; cin >> N >> S >> K; rep(i,N){ if(S[i] != S[K-1]) S[i] = '*'; } cout << S << endl; }
1
71,512,419
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define whole(x) (x).begin(),(x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using P = pair<int, int>; #define debug(var) cerr << "[" << #var << "] " << var << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) const ll mod = 1000000007; const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1}; int main(){ int n; cin >> n; vector<int> a(n); map<int, int> mp; rep(i, n) { cin >> a[i]; mp[a[i]]++; } int ans = 0; for (auto m: mp) { if (m.second>=m.first) ans += m.second-m.first; else ans += m.second; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << endl #define COUTF(x) cout << setprecision(15) << (x) << endl #define ENDL cout << endl #define DF(x) x.erase(x.begin()) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define REVERSE(x) reverse(ALL(x)) #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(i, v.size()) cerr << " " << v[i]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using P = pair<ll, ll>; constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } vector<P> factorize(ll n) { vector<P> result; for (ll i = 2; i * i <= n; ++i) { if (n % i == 0) { result.pb({i, 0}); while (n % i == 0) { n /= i; result.back().second++; } } } if (n != 1) { result.pb({n, 1}); } return result; } vll divisor(ll n) { vll 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); return (ret); } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } signed main() { init(); ll N; cin >> N; map<ll, ll> m; rep(i, N) { ll a; cin >> a; m[a]++; } ll ans = 0; for (auto mm : m) { if (mm.first == mm.second) continue; if (mm.first < mm.second) { ans += mm.second - mm.first; } else { ans += mm.second; } } COUT(ans); return 0; }
1
86,718,326
#include<iostream> #include<algorithm> #include<climits> using namespace std; #define INF INT_MAX int a,b,T,flag=1,minn; long long num; int main() { minn=INF; scanf("%d",&T); for(int i=1;i<=T;i++) { scanf("%d%d",&a,&b); num+=a; if(a>b)minn=min(minn,b); if(a!=b)flag=0; } if(flag)printf("0\n"); else printf("%lld",num-minn); }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define F first #define S second #define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++) #define rep(i,n) FOR(i,0,n) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define ve vector #define vi vector<int> #define vp vector<pair<int,int>> #define vvi vector<vector<int>> #define pint pair<int, int> template<typename T> using pq = priority_queue<T,vector<T>,greater<T>>; using ll = long long; ll INF = LLONG_MAX / 4000 - 100; ll mod = 1e9 + 7; int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1}; vector<ll> prime; class fact { public: int fmod = 1e9+7; vector<int> fac, inv; fact (int n, int Mod = 1e9+7) { fmod = Mod; fac = vector<int>(n,0); inv = vector<int>(n,0); fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod; for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2); } ll nCr(ll n, ll r) {if(n < r) return 0; return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;} ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;} inline int operator [] (int i) {return fac[i];} }; template <class T = ll> T in() {T x; cin >> x; return (x);} void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;} void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;} ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;} ll LCM(ll a, ll b) {return (a / GCD(a, b)) * (b / GCD(a, b)) * GCD(a, b);} ll POW(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;} void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}} template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;} template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;} bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;} void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;} void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;} void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;} double dis(int x1, int x2, int y1, int y2) { return sqrt((double)abs(x1-x2)*(double)abs(x1-x2)+(double)abs(y1-y2)*(double)abs(y1-y2)); } class UnionFind { private: vector<int> par; public: UnionFind(int N) { par = vector<int>(N, -1); } int find(int x); ll size(int x); void unite(int x, int y); bool same(int x, int y); }; int UnionFind::find(int x) { if (par[x] < 0) return x; else return par[x] = find(par[x]); } ll UnionFind::size(int x) { return -par[find(x)]; } void UnionFind::unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (size(x) < size(y)) swap(x, y); par[x] += par[y]; par[y] = x; } bool UnionFind::same(int x, int y) { x = find(x); y = find(y); return x == y; } using pi = pair<int, int>; bool solve() { int n; cin >> n; vp ab(n); int sum = 0; int mi = INF; rep (i, n) { cin >> ab[i].F >> ab[i].S; sum += ab[i].F; if (ab[i].F > ab[i].S) chmin(mi, ab[i].S); } sort(all(ab), [&](pi a, pi b){ if (a.S-a.F!=b.S-b.F) return a.S-a.F < b.S-b.F; return a.S < b.S; }); if (ab[0].F == ab[0].S) cout << 0 << endl; else cout << sum-mi << endl; } main() { ios::sync_with_stdio(false); solve(); }
1
26,970,234
#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 fi first #define se second using namespace std; using lint = long long; using uint = unsigned int; using ulint = unsigned long long; using ldouble = long double; using pii = pair<int, int>; using pli = pair<lint, lint>; using pdd = pair<double, double>; using pld = pair<ldouble, ldouble>; using v1i = vector<int>; using v1li = vector<lint>; using v2i = vector<vector<int>>; using v2li = vector<vector<lint>>; using v3i = vector<vector<vector<int>>>; using v3li = vector<vector<vector<lint>>>; using v1b = vector<bool>; using v2b = vector<vector<bool>>; using v3b = vector<vector<vector<bool>>>; using v1c = vector<char>; using v2c = vector<vector<char>>; using v3c = vector<vector<vector<char>>>; constexpr lint mod1 = 1e9+7; constexpr lint mod2 = 998244353; int main() { int n, m, s = 0; scanf("%d %d", &n, &m); s += n * 100 + m * 1800; rep(i, m) s *= 2; printf("%d", s); return 0; }
#include <iostream> using namespace std; int main() { int N, M; cin >> N >> M; cout << (100*N+1800*M)*(1<<M) << endl; }
1
1,567,949
#include <bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=(x);i<(y);++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define show(x) #endif typedef long long int ll; typedef pair<int,int> pii; template<typename T> using vec=std::vector<T>; const int inf=1<<30; const long long int infll=1LL<<62; const double eps=1e-9; const int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } class union_find{ private: vector<int> parent,rank; int size; public: int cnt; union_find()=default; union_find(int n){ init(n); } void init(int n){ size=n; cnt=n; parent.resize(size); rank.resize(size); for(int i=0; i<size; ++i){ parent[i]=i; rank[i]=0; } } int find(int x){ if(parent[x]==x) return x; else return parent[x]=find(parent[x]); } void unite(int x,int y){ x=find(x); y=find(y); if(x==y) return; if(rank[x]<rank[y]){ parent[x]=y; } else { parent[y]=x; if(rank[x]==rank[y]) ++rank[x]; } --cnt; } bool is_same(int x,int y){ return find(x)==find(y); } }; void solve(){ int n; cin >> n; union_find uf(n); int q; cin >> q; rep(i,0,q){ int com,x,y; cin >> com >> x >> y; if(com==0) uf.unite(x,y); if(com==1){ if(uf.is_same(x,y)) cout << 1 << endl; else cout << 0 << endl; } } } int main(){ std::cin.tie(0); std::ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10); solve(); return 0; }
#include <stdio.h> #include <vector> #include <algorithm> #include <math.h> #include <queue> using namespace std; int n,q,com,x,y; int rank[10000],parent[10000]; int find(int x){ if(x == parent[x])return x; else{ return parent[x] = find(parent[x]); } } bool isSame(int x,int y){ return find(x) == find(y); } void unite(int x,int y){ x = find(x); y = find(y); if(x == y)return; if(rank[x] < rank[y]){ parent[x] = y; }else{ parent[y] = x; if(rank[x] == rank[y])rank[x]++; } } int main(){ scanf("%d %d",&n,&q); for(int i = 0; i < n; i++){ rank[i] = 0; parent[i] = i; } for(int i = 0; i < q; i++){ scanf("%d %d %d",&com,&x,&y); if(com == 1){ if(isSame(x,y))printf("1\n"); else{ printf("0\n"); } }else{ if(isSame(x,y))continue; unite(x,y); } } return 0; }
1
1,101,168
#include<bits/stdc++.h> using namespace std; int main(){ char a,b; cin>>a>>b; if(a=='H'&&b=='H'){cout<<'H'<<endl;} else if(a=='D'&&b=='D'){cout<<'H'<<endl;} else if(a=='H'&&b=='D'){cout<<'D'<<endl;} else{cout<<'D'<<endl;} }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); i++) #define All(V) v.begin(), v.end() typedef long long int ll; typedef pair<int, int> P; const ll MOD = 1e9+7, INF = 1e9; int main() { char a, b; cin >> a >> b; if((a == 'H' && b == 'H') || (a == 'D' && b == 'D')){ cout << "H" << endl; } else cout << "D" << endl; system("pause"); }
1
46,128,249
#include <bits/stdc++.h> using namespace std; #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define int long long #define ld long double #define fi first #define se second #define all(uiet) uiet.begin(),uiet.end() #define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i] #define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i] << " " #define mp make_pair #define pb push_back #define eb emplace_back #define vpp vector<pair< int, int > > #define pll pair<int , int > #define ppll pair < pll , pll > #define debug(n1) cout << n1 << endl #define len(a) ((int) (a).size()) #define endl "\n" #define mod 1000000007 const int INF=(1LL<<60)-1; bool isPerfectSquare(long double x) { long double sr = sqrt(x); return ((sr - floor(sr)) == 0); } bool isPrime(int x){ for(int i = 2; i * i <= x; ++i){ if(x % i == 0) return 0; } return 1; } int fun(int n){ if(n & 1) return 3 * n + 1; else return n/2; } int32_t main(){ SPEED; int n, a, b; cin >> n >> a >> b; int rem = n % (a + b); cout << (n/(a + b)) * a + min(rem, a) ; }
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define ll long long #define ld long double #define rep(i, n) for(ll i = 0; i < n; ++i) #define rep2(i, a, b) for(ll i = a; i <= b; ++i) #define rrep(i, a, b) for(ll i = a; i >= b; --i) #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define eb emplace_back #define vi vector<int> #define vll vector<ll> #define vpi vector<pii> #define vpll vector<pll> #define all(a) a.begin(), a.end() #define endl '\n' using namespace std; 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; } const int MOD=1e9+7; const ll INF=1e18; const double PI=acos(-1); int dx[8] = {1,0,-1,0,1,1,-1,-1}; int dy[8] = {0,1,0,-1,-1,1,1,-1}; const int MAX=510000; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,a,b; cin >> n >> a >> b; ll ans = 0; ans += (n/(a+b))*a; n%=(a+b); ans += min(n,a); cout << ans << endl; return 0; }
1
43,930,125
#include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { int N; cin >> N; vector<double> t(N), v(N); for (int i = 0; i < N; i++) cin >> t[i]; for (int i = 0; i < N; i++) cin >> v[i]; t.insert(t.begin(), 0); for (int i = 0; i < N; i++) t[i+1] += t[i]; t.insert(t.begin(), 0); t.insert(t.end(), t.back()); v.insert(v.begin(), 0); v.insert(v.end(), 0); double prevSpeed = 0, ans = 0; for (double time = 0.5; time <= t.back(); time += 0.5) { double speed = 100; for (int i = 0; i <= N+1; i++) { if (time < t[i]) speed = min(speed, v[i] + (t[i] - time)); else if (time > t[i+1]) speed = min(speed, v[i] + (time - t[i+1])); else speed = min(speed, v[i]); } ans += 0.25 * (prevSpeed + speed); prevSpeed = speed; } cout << fixed << setprecision(3) << ans << endl; }
#include <iostream> #include <iomanip> #include <vector> using namespace std; int N; int main() { cin >> N; vector<int> t(N), v(N), s(N + 1); for (int i = 0; i < N; i++) { cin >> t[i]; t[i] <<= 1; s[i + 1] = t[i] + s[i]; } for (int i = 0; i < N; i++) { cin >> v[i]; v[i] <<= 1; } int time = s[N]; vector<int> mx(time); for (int i = 0; i < time / 2; i++) { mx[i] = i; } for (int i = time / 2; i < time; i++) { mx[i] = time - i; } int ans = 0; for (int j = 0; j < time; j++) { for (int i = 0; i < N; i++) { if (j < s[i]) { mx[j] = min(mx[j], -(j - s[i]) + v[i]); } else if (j > s[i + 1]) { mx[j] = min(mx[j], j - s[i + 1] + v[i]); } else { mx[j] = min(mx[j], v[i]); } } ans += mx[j]; } cout << fixed << setprecision(4) << (double) ans * 0.25 << endl; }
1
27,017,667
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <random> #include <cassert> #include <numeric> #define ll long long int #define LL unsigned long long #define pb push_back #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) using namespace std; int mx8[] = {0,0,1,-1,-1,1,-1,1}; int my8[] = {-1,1,0,0,-1,-1,1,1}; int mx4[] = {1,-1,0,0}; int my4[] = {0,0,-1,1}; const int MOD = 1000000007; int main() { int n; cin >> n; vector<ll> a(n),b(n),d(n); vector<pair<ll,ll>> p(n); ll suma = 0, sumb = 0, cnt = 0, m = 0; rep(i,n) { cin >> a[i]; suma += a[i]; } rep(i,n) { cin >> b[i]; sumb += b[i]; } if(suma < sumb){ cout << -1 << endl; }else{ rep(i,n) { d[i] = a[i] - b[i]; if(d[i] < 0) { m += d[i]; cnt++; } p[i].first = d[i]; p[i].second = i; } m *= -1; sort(p.rbegin(),p.rend()); int j = 0; while(m>0){ m -= p[j].first; j++; } cout << j + cnt << endl; } }
#include <bits/stdc++.h> using namespace std; #define lli long long int #define rep(i, n) ;for (int i = 0;i < (int)(n);i++) #define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++) #define ALL(vec) (vec).begin(),(vec).end() #define pi 3.1415926535897932384626433832795 #define MAX_INF 9223372036854775807 #define MIN_INF (922337203685477587+1) #define sosuu 1000000007 string keyence="keyence"; int main() { lli N; cin >> N; lli sumA=0,sumB=0; vector<lli> A(N); vector<lli> B(N); int ans=0; lli lack=0; rep(i, N){ cin >> A[i]; sumA+=A[i]; } rep(i, N){ cin >> B[i]; sumB+=B[i]; } if(sumA<sumB){ cout << -1 << endl; return 0; } vector<lli> defference(N); rep(i, N) { defference[i]=A[i]-B[i]; if(defference[i]<0){ lack-=defference[i]; ans++; } } sort(ALL(defference)); reverse(ALL(defference)); rep(i, N){if(lack<=0){ break; } ans++; lack-=defference[i]; } cout << ans << endl; }
1
26,410,173
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define m0(x) memset(x, 0, sizeof(x)) #define all(x) x.begin(), x.end() #define rep(i, n) for(int i = 0; i < (n); i++) #define asort(x) sort(all(x)); #define dsort(x, t) sort(x.begin(), x.end(), greater<t>()); #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define MINS(m, s) m.insert(make_pair(s, 1)); #define MFIN(m, s) m.find(s) != m.end() #define INF (1 << 29) const int mod = 1000000007; int main() { ll n, tmp; bool flag = true; map<ll, ll> m; cin >> n; for(ll i = 0; i < n; i++) { cin >> tmp; if(MFIN(m, tmp)) { flag = false; } else { MINS(m, tmp); } } if(flag) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int x[n],i=0; int z=0; for (;i<n;i++){ cin>>x[i]; if(z==0&&i>0){ int j=i-1; if(x[j]==x[i]||x[j-1]==x[i]) z++; } } if(z==0){ sort(x,x+n); int j=n-1; int m=n/2+1; int k=n/2-1; for (int i=0;i<n/4+2;i++){ if(x[i+1]==x[i]||x[j]==x[j-1]||x[m]==x[m-1]||x[k]==x[k+1]){ z++; break; } else{ j--; m++; k--; } } } if(z==0) cout<<"YES"; else cout<<"NO"; return 0; }
1
13,594,669
#include <bits/stdc++.h> #define INF INT_MAX #define ll long long #define ull unsigned long long #define rep(i,n) for(ll i=0; i<n; ++i) #define FOR(i, s, e) for(ll i=s; i<e; ++i) #define MOD 1000000007 using namespace std; template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;} template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;} int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; if(S == "RRS" || S == "SRR") cout << 2 << endl; else if(S == "RRR") cout << 3 << endl; else if(S == "SSS") cout << 0 << endl; else cout << 1 << endl; }
#include <math.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define endl '\n' typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; #define pb push_back #define lb lower_bound #define ub upper_bound #define MOD 1000000007 #define pi acos(-1.0) #define MAX 1000010 int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20); string s; cin >> s; int cnt = 0; for(int i = 0; i < 3; i++){ if(s[i] == 'R'){ while(s[i] == 'R'){ cnt++; i++; } break; } } cout << cnt << endl; }
1
96,783,734
#include<bits/stdc++.h> using namespace std; #define ll long long #define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) const int maxn = 1e5 + 5; #define INF 1000000000 const int MOD = 1e9+7; const double PI = 3.14159265358979323846264338; int a[maxn]; int cnt[maxn]; int getSum(int n) { int sum = 0; while (n != 0) { sum = sum + n % 10; n = n/10; } return sum; } int countDigit(long long n) { int count = 0; while (n != 0) { n = n / 10; ++count; } return count; } char S[110]; char T[110]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio int a; cin >> a; cin >> S >> T; for(int i=0; i<a; i++){ cout << S[i] << T[i]; } cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; using pii = pair<int, int>; int main() { int n; string s, t; cin >> n >> s >> t; for (int i = 0; i < n; i++) { cout << s[i] << t[i]; } cout << endl; }
1
58,462,368
#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() { ll a,b,c,d; cin>>a>>b>>c>>d; ll ac=0; ll ad=0; ll bc=0; ll bd=0; a--; ac=a/c; ad=a/d; bc=b/c; bd=b/d; ll acd=0; ll bcd=0; ll q=__gcd(c,d); q=c*d/q; acd=a/(q); bcd=b/(q); cout<<(b+bcd-bc-bd)-(a+acd-ac-ad)<<endl;}
#include<iostream> using namespace std; using ll=long long; int main(){ ll A,B,C,D; cin>>A>>B>>C>>D; ll sum=B-A+1; ll C_cnt=B/C-((A-1)/C); ll D_cnt=B/D-((A-1)/D); ll x=C*D; if(C<D){ ll temp=C; C=D; D=temp; } ll r=C%D; while(r!=0){ C=D; D=r; r=C%D; } x=x/D; ll x_cnt=B/x-((A-1)/x); cout<<sum-(C_cnt+D_cnt)+x_cnt<<endl; return 0; }
1
58,152,213
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FAST_IO std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define setpre(n) fixed << setprecision(n) #define F first #define S second #define pii pair<int, int> #define pll pair<ll, ll> #define pdd pair<ld, ld> #define eb emplace_back #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define sz(a) a.size() #define len(a) a.length() #define pi acos(-1.0) #define g_sin(a) sin(a*pi/180) #define g_cos(a) cos(a*pi/180) #define g_tan(a) tan(a*pi/180) #define ms0(a) memset(a, 0, sizeof(a)); #define ms1(a) memset(a, 1, sizeof(a)); #define msn1(a) memset(a, -1, sizeof(a)); #define msinf(a) memset(a, 0x3f3f3f, sizeof(a)); const int mod1 = 998244353, mod = 1e9+7; const int MAXN = 100005, MAX_M = 200010; int a[MAXN], n; vector<int> g[MAXN]; int dfs(int v, int p){ int val = 0; int mx = 0; for (auto u:g[v]){ if (u == p) continue; int t = dfs(u, v); val += t; mx = max(mx, t); } int x = g[v].size() == 1 ? 1 : 2; if (mx > a[v]){ cout << "NO\n"; exit(0); } if (x*a[v] - val < 0 || x*a[v] - val > a[v]){ cout << "NO\n"; exit(0); } return x*a[v] - val; } void Solve() { cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } for (int i = 1, a, b; i < n; i++){ cin >> a >> b; g[a].pb(b); g[b].pb(a); } cout << (dfs(1, 1) == 0 ? "YES\n":"NO\n"); } signed main(){ FAST_IO; int TC = 1; while(TC--) Solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcount #define ll long long #define mp make_pair #define f first #define s second #define lb lower_bound #define ub upper_bound #define Time (double)clock()/CLOCKS_PER_SEC const int N = 1e5 + 7; vector <int> g[N]; int n, a[N]; int dfs(int u, int p) { int sum = 0, mx = 0; bool lief = 1; for (int v : g[u]) { if (v != p) { lief = 0; int x = dfs(v, u); sum += x; mx = max(mx, x); } } if (lief) return a[u]; if (sum < a[u]) { cout << "NO\n"; exit(0); } int wp = sum - a[u]; int maxp; if (mx * 2 <= sum) maxp = sum >> 1; else maxp = sum - mx; if (wp > maxp) { cout << "NO\n"; exit(0); } return sum - wp * 2; } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 0; i < n - 1; ++i) { int u, v; cin >> u >> v; g[u].app(v); g[v].app(u); } if (n == 2) { if (a[1] == a[2]) cout << "YES\n"; else cout << "NO\n"; exit(0); } int r = -1; for (int i = 1; i <= n; ++i) { if (g[i].size() > 1) { r = i; } } if (!dfs(r, r)) cout << "YES\n"; else cout << "NO\n"; }
1
28,704,380
#include<bits/stdc++.h> #define godspeed ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0); #define ll long long #define ld long double #define fi first #define se second #define mp make_pair #define rep1(i,a,b) for(ll i=a; i<=b; i++) #define repVect(i,n) for(ll i=0; i<sum.size(); i++) #define fixed cout.setf(ios::fixed); #define Precise cout.precision(7); #define yes cout<<"Yes"<<'\n' #define no cout<<"No"<<'\n' using namespace std; int main() { godspeed ll i,j,k,l; char c; cin>>c; if(c=='A') cout<<"T"<<endl; else if(c=='C') cout<<"G"<<endl; else if(c=='T') cout<<"A"<<endl; else if(c=='G') cout<<"C"<<endl; return 0; }
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cmath> #include <fstream> #include <iostream> #include <map> #include <queue> #include <string> #include <stack> #include <vector> #include <set> #include <tuple> #include <utility> #include <functional> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef tuple<int,int,int> T; const int INF = 1000000000; const int MOD = 1000000007; int main(){ char c; cin >> c; if(c == 'A')cout << 'T' << endl; if(c == 'T')cout << 'A' << endl; if(c == 'C')cout << 'G' << endl; if(c == 'G')cout << 'C' << endl; }
1
89,558,360
#include <iostream> #include <cstdlib> #include <list> #include <map> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main(void) { int64_t N, K; cin >> N >> K; int64_t p[1000]; for (int64_t i = 0; i < N; ++i) { cin >> p[i]; } sort(p, p+N); int64_t ans = 0; for (int64_t i = 0; i < K; ++i) { ans += p[i]; } cout << ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) using ll = long long; using Graph = vector<vector<pair<int, int>>>; const ll INF = 1001001001; int main(){ int n, k; cin >> n >> k; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); ll ans = 0; for(int i = 0; i < k; i++){ ans += a[i]; } cout << ans << endl; }
1
93,942,943
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define PB push_back #define MP make_pair int main() { ios_base::sync_with_stdio(0); cin.tie(0); int w, h, x, y; cin >> w >> h >> x >> y; cout << setprecision(10) << double(w) * double(h) / 2 << " " << (2 * x == w && 2 * y == h) << "\n"; }
#include <iostream> #include <stdio.h> #include <algorithm> #include <map> #include <math.h> using namespace std; #include <vector> #define rep(i,n) for (ll i = 0; i < (n) ; i++) #define INF 1e9 #define llINF 1e18 #define base10_4 10000 #define base10_5 100000 #define base10_6 1000000 #define base10_7 10000000 #define base10_8 100000000 #define base10_9 1000000000 #define MOD 1000000007 #define pb push_back #define ll long long #define ull unsigned long long #define vint vector<int> #define vll vector<ll> string ans_Yes = "Yes"; string ans_No = "No"; string ans_yes = "yes"; string ans_no = "no"; double W; double H; ll x; ll y; ll ltmp; string stmp; double dtmp; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> W >> H >> x >> y; cout << W*H/2 << endl; if(W/2==x && H/2==y) cout << 1 << endl; else cout << 0 << endl; }
1
54,481,076
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define LL long long #define INF INT_MAX const double EPS = 1e-14; const double PI = acos(-1.0); int main(){ int a, b; cin >> a >> b; string ans; if (a + b == 15) ans = "+"; else if (a * b == 15) ans = "*"; else ans = "x"; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using msi = map<string, int>; using mii = map<int, int>; using psi = pair<string, int>; using pii = pair<int, int>; using vlai = valarray<int>; using tii = tuple<int, int>; #define rep(i,n) for(int i=0;i<n;i++) #define range(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 fs first #define sc second #define pb push_back #define eb emplace_back #define mp make_pair #define INF INT_MAX #define EPS 1E-9 #define MOD 1000000007 #define PI 3.1415926535897932384 template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v) { rep(i, v.size()) { o << (i > 0 ? " " : "") << v[i]; } return o; } int main() { int a, b; cin >> a >> b; if (a + b == 15)cout << '+' << endl; else if (a*b == 15)cout << '*' << endl; else cout << 'x' << endl; }
1
64,572,202
#include <iostream> #include <string> using namespace std; int main() { string s, p; cin >> s >> p; if ((s + s).find(p) == (size_t) -1) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(void){ string n,s; cin>>n>>s; n+=n; int i,j; int flg=0; for(i=0;i<n.size();i++){ for(j=0;j<s.size();j++){ if(n[i+j]!=s[j]){ break; } } if(j==s.size()) flg=1; } cout<<((flg)?"Yes":"No")<<endl; return 0; }
1
18,282,069
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; ll GetDigit(ll num){ return log10(num)+1; } int main() { int a,b; cin >> a >> b; if(a + b == 15) cout << '+' << endl; else if(a * b == 15) cout << '*' << endl; else cout<< 'x' << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define REP(i,j,k) for(int i = j ; i < k ; ++i) #define RREP(i,j,k) for(int i = j ; i >=k ; --i) #define A first #define B second #define mp make_pair #define pb emplace_back #define PII pair<int , int> #define MEM(i,j) memset(i , j , sizeof i) #define ALL(i) i.begin() , i.end() #define DBGG(i,j) cout << i << " " << j << endl #define DB4(i,j,k,l) cout << i << " " << j << " " << k << " " << l << endl #define IOS cin.tie(0) , cout.sync_with_stdio(0) #define endl "\n" #define MAX #define INF 0x3f3f3f3f int a , b; int32_t main(){ IOS; cin >> a >> b; if(a + b == 15) cout << "+" << endl; else if(a * b == 15) cout << "*" << endl; else cout << "x" << endl; return 0; }
1
52,126,321
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define ArraySizeOf(array) (sizeof(array) / sizeof(array[0])) #define res(i,n) for(int i=n;;i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for(int i=1;i<n;i++) #define rev(i,n) for(int i=n-1;i>=0;i--) #define REV(i,n) for(int i=n-1;i>0;i--) #define req(i,n,m) for(int i=n;i<m;i++) #define REQ(i,n,m,l) for(int i=n;i<m;i+=l) #define _GLIBCXX_DEBUG int INF = 1e9 + 7; long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117; unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1) { unsigned day; if (dow < dow1) dow += 7; day = dow - dow1; day += 7 * n - 6; return day; } signed gcd(long long x, long long y) { if (y == 0)return x; return gcd(y, x % y); } signed lcm(long long x, long long y) { return x / gcd(x, y) * y; } unsigned DayToWeekNumber(unsigned day) { return (day - 1) / 7 + 1; } unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0) { return (dow0 + 35 + day - day0) % 7; } using namespace std; int main() { int A; cin >> A; int a = A / 1000; int b = A % 1000 / 100; int c = A % 100 / 10; int d = A % 10; if (a + b + c + d == 7) { cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl; return 0; } if (a + b + c - d == 7) { cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl; return 0; } if (a + b - c + d == 7) { cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl; return 0; } if (a + b - c - d == 7) { cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl; return 0; } if (a - b + c + d == 7) { cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl; return 0; } if (a - b + c - d == 7) { cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl; return 0; } if (a - b - c + d == 7) { cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl; return 0; } if (a - b - c - d == 7) { cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl; return 0; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { string s; cin >> s; int x = (int)s.size(); for (int i = 0; i < pow(2,x - 1); ++i) { string ans = ""; ans += s[0]; int sum = s[0] - '0'; for (int j = 0, p = 0; j < x - 1; ++j,p++) { if ((i >> j) & 1) { sum = (sum + (s[p + 1] - '0')); ans += "+"; ans += s[p+ 1]; }else { sum = (sum - s[p + 1] + '0'); ans += "-"; ans += s[p + 1]; } } if (sum == 7) { cout << ans << "=7"; return 0; } } }
1
49,853,707
#include <cstdio> int main() { char ch; int n = 0; while ((ch = getchar())!= '0' || n != 0) { if (ch == '\n') { printf("%d\n",n); n = 0; } else { ch &= 0x0F; n += ch; } } return 0; }
#include <iostream> using namespace std; int main() { string line; int s; while(getline(cin, line)) { if(line.length() == 1 && line[0] == '0') break; s = 0; for(int i = 0; i < line.length(); i++) { s += line[i] - '0'; } cout << s << endl; } return 0; }
1
74,025,864