code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
44
101M
#include<bits/stdc++.h> using namespace std; #define debug(x) cout<<#x<<" :"<<x<<endl; #define ff first #define ss second #define ar array #define int long long #define ld long double #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define f(i,n) for(int i=0;i<n;i++) #define MOD 1000000007 #define pi 3.14159265 #define umii unordered_map<int,int> #define umci unordered_map<char,int> #define umsi unordered_map<string,int> void k_007() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("ip1.txt", "r", stdin); freopen("op1.txt", "w", stdout); #endif } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int prime(int n) { int flag = 1; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) {flag = 0; break;} } return flag; } int power(int x, int y) { if (y == 0) return 1; else if (y % 2 == 0) return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD; else return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD; } int lcm(int a, int b) { return (a * b) / gcd(a, b); } int32_t main() { k_007(); string s, t; int n; cin >> n; cin >> s >> t; for (int i = 0; i < n; i++) { cout << s[i] << t[i]; } }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("unroll-loops") #ifdef _MSC_VER #include <intrin.h> #define __builtin_popcount __popcnt #define __builtin_popcountll __popcnt64 #endif #include <limits.h> #include <math.h> #include <time.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m - 1; i >= n; --i) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define REVERSE(v, n) reverse(v, v + n); #define VREVERSE(v) reverse(v.begin(), v.end()) #define ll long long #define print(x) cout << (x) << '\n' #define pe(x) cout << (x) << " " #define DEBUG(x) cout << #x << ": " << x << endl #define lb(v, n) lower_bound(v.begin(), v.end(), (n)) #define ub(v, n) upper_bound(v.begin(), v.end(), (n)) #define int long long #define double long double #define all(x) (x).begin(), (x).end() #define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ") template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } typedef pair<int, int> pii; typedef pair<long long, long long> pll; std::random_device rd; std::mt19937 mt(rd()); constexpr ll MOD = 1e9 + 7; constexpr int MAX = 500050; const double pi = acos(-1); constexpr double EPS = 1e-8; constexpr ll LINF = 1e18 + 1; constexpr int INF = 1e9 + 1; bool A[101][101]; void solve() { int W, H; cin >> W >> H; int N; cin >> N; REP(_, N) { int x, y; cin >> x >> y; int a; cin >> a; if (a == 1) { REP(i, W)REP(j, H)if (i < x)A[i][j] = true; } else if (a == 2) { REP(i, W)REP(j, H)if (i >= x)A[i][j] = true; } else if (a == 3) { REP(i, W)REP(j, H)if (j < y)A[i][j] = true; } else if (a == 4) { REP(i, W)REP(j, H)if (j >= y)A[i][j] = true; } } int ans = 0; REP(i, W)REP(j, H)if (!A[i][j])ans++; print(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
0
57,741,713
#include <stdio.h> #include <string.h> int main(){ char A[11], B[11], C[11]; scanf("%s %s %s", A, B, C); int lenA=0, lenB=0, lenC=0; lenA = strlen(A); lenB = strlen(B); lenC = strlen(C); if(A[lenA-1] == B[0] && B[lenB-1] == C[0] ){ printf("YES"); } else { printf("NO"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; ll MOD = 1000000007; int main() { ll N,Y; cin >> N >> Y; Y /= 1000; bool flag = false; for(ll yukiti = 0;yukiti<=N;yukiti++){ for(ll itiyou = 0;itiyou <= N-yukiti;itiyou++){ ll hideyo = N-yukiti-itiyou; if(yukiti*10+itiyou*5+hideyo == Y){ flag = true; cout << yukiti << " " << itiyou << " " << hideyo << endl; break; } } if(flag){ break; } } if(!flag){ cout << "-1 -1 -1" << endl; } }
0
58,325,213
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long int #define ull unsigned int #define ld long double #define pb push_back #define pa pair<int,int> #define ppa pair<pair<int,int>,int> #define pap pair<int,pair<int,int>> #define v1d vector<int> #define v2d vector<vector<int> > #define vpa vector<pair<int,int>> #define M 1000000007 #define MN LLONG_MIN #define MX LLONG_MAX #define ff first #define ss second #define endl "\n" #define v1s vector<string> #define all(v) v.begin(),v.end() #define S(v) sort(v.begin(),v.end()) #define RS(v) sort(v.rbegin(),v.rend()) #define R(v) reverse(v.begin(),v.end()) #define mxpq(T) priority_queue <T> #define mnpq(T) priority_queue<T,vector<T>,greater<T>> #define T int tc;cin>>tc;while(tc--) #define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;} #define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl; #define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl; #define forIloop(i,n) for(auto i=0;i<n;i++); #define forDloop(i,n) for(auto i=n-1;i>=0;i--); #define qqq 400005 #define isEven(n) (!n & 1); const int MOD = 1e9 + 7; void codeforce2(){ int n; cin>>n; string a,b; cin>>a>>b; string ans; for(int i=0; i<n; i++){ ans = ans + a[i]; ans = ans + b[i]; } cout << ans << endl; } int32_t main(){ cout<<fixed<<setprecision(16); cin.sync_with_stdio(false); cin.tie(0);cout.tie(0); codeforce2(); return 0; }
#include <bits/stdc++.h> using namespace std; #define fast_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define show(x) cout << #x << " = " << x << '\n' #define ll long long #define ull unsigned long long #define PI 3.1415926535897932384626433832795 #pragma GCC optimize ("Ofast") #pragma GCC optimize ("-ffloat-store") #define modulo 998244353 clock_t time_p = clock(); void time() { time_p = clock() - time_p; cerr << "Time Taken : " << (double)(time_p) / CLOCKS_PER_SEC << '\n'; } int main() { fast_IO ll n, mx = 0; cin >> n; vector<ll> a(n+1); a[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] && a[i-1]) { mx++; a[i]--; } mx += a[i] / 2; a[i] = a[i] % 2; } cout << mx << '\n'; return 0; }
0
41,528,728
#include <bits/stdc++.h> using namespace std; #define rep(i,N) for(int i=0;i<int(N);++i) using ll = long long; const int INF = 2147483647; int main(){ string s; cin >> s; vector<ll> a(s.size()+1); ll cnt=0; for(int i=1;i<=s.size();i++){ if(s.at(i-1)=='<') cnt++; if(s.at(i-1)=='>') cnt=0; a[i]=cnt; } cnt=0; for(int i=s.size()-1;i>=0;i--){ if(s.at(i)=='>') cnt++; if(s.at(i)=='<') cnt=0; a[i]=max(a[i],cnt); } ll sum=0; for(int i=0;i<=s.size();i++){ sum+=a[i]; } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,n-1,0) #define all(v) v.begin(), v.end() const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; class Doubling { public: int N; int logK; vector<vector<int>> next; Doubling(int N, vector<int>& ini, ll K) { logK = log2(K); next = vector<vector<int>>(logK+1, vector<int>(N)); rep(i, N) next[0][i] = ini[i]; rep(k, logK) { rep(i, N) { next[k+1][i] = (next[k][i] == -1 ? -1 : next[k][next[k][i]]); } } } int query(int p, ll q) { for(int k=logK; k>=0; k--) { if(p == -1) break; if((q>>k)&1) p = next[k][p]; } return p; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> X(n); rep(i, n) cin >> X[i]; ll l; cin >> l; vector<int> next(n); rep(i, n) next[i] = --upper_bound(all(X), X[i]+l) - begin(X); vector<int> rnext(n); rrep(i, n) rnext[i] = lower_bound(all(X), X[i]-l) - begin(X); Doubling dbl(n, next, n); Doubling rdbl(n, rnext, n); auto bsearch = [&](int s, int t) { int ok = n, ng = 0; while(ok-ng>1) { int mid = (ok+ng)/2; if(s < t) (dbl.query(s, mid)>=t ? ok : ng) = mid; else (rdbl.query(s, mid)<=t ? ok : ng) = mid; } return ok; }; int q; cin >> q; rep(_, q) { int a, b; cin >> a >> b; a--; b--; cout << bsearch(a, b) << "\n"; } return 0; }
0
95,840,030
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;} #define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl; #define yn(ans) cout<<(ans?"Yes":"No")<<endl #define YN(ans) cout<<(ans?"YES":"NO")<<endl using namespace std; using ll = long long; template <typename T>T digitsum(T n); template <typename T>bool isPrime(T n); template <typename T>vector<pair<T, T>> prime_factor(T n); long long int intpow(long long int,long long int); template <typename T>T intlog(T); long long int combination(long long int,long long int); long long int series_sum(long long int); int main(){ long long int ans,a,b,c,d; cin>>a>>b>>c>>d; ans=b-a+1; long long int e=0; e+=(b/c)-(a/c); if(a%c==0)e++; e+=(b/d)-(a/d); if(a%d==0)e++; long long int f=c*d/__gcd(c,d); e-=(b/f)-(a/f); if(a%(f)==0)e--; cout<<ans-e<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<bool> snuke(n,false); int d, a; for (int i = 0; i < k; i++) { cin >> d; for (int j = 0; j < d; j++) { cin >> a; snuke[a-1] = true; } } int s = 0; for (int i = 0; i < n; i++) { if (snuke[i] == false) { s++; } } cout << s; }
0
96,855,851
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++) #define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--) using namespace std; using ll = long long; using vl = vector<ll>; using vc = vector<char>; using vvl = vector<vl>; using vvc = vector<vc>; using pll = pair<ll, ll>; using vpll = vector<pll>; int main(){ ll a, b, c, d; cin >> a >> b >> c >> d; if((abs(a - c) <= d) || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define mp(a,b) make_pair(a,b) #define ff first #define setp(a) setprecision(a)<<fixed #define ss second #define fori(v) for(ll i=0; i<v; i++) #define forj(v) for(ll j=0; j<v; j++) #define fork(v) for(ll k=0; k<v; k++) #define forl(v) for(ll l=0; l<v; l++) #define fort(v) for(ll t=0; t<v; t++) #define forz(v) for(ll z=0; z<v; z++) #define ll long long #define ld long double #define MAX (int)(7*pow(10,2) + 10) #define pb(a) push_back(a) ll inf = pow(10,9); ll INF = inf; ll modulo = inf; double eps = 1e-10; ifstream in; ofstream out; void deal(){ ll a, b, c; cin>>a>>b>>c; string ans[2] = {"No", "Yes"}; cout<<ans[((a==b)&&(b==c))]; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); deal(); }
0
34,288,248
#include <bits/stdc++.h> using namespace std; #define d(x) cerr << #x ":" << x << endl; #define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl #define rep(i, n) for (int i = (int)(0); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define dump(v) \ cerr << #v ":[ "; \ for (auto macro_vi : v) { \ cerr << macro_vi << " "; \ } \ cerr << "]" << endl; #define ddump(v) \ cerr << #v ":" << endl; \ for (auto macro_row : v) { \ cerr << "["; \ for (auto macro__vi : macro_row) { \ cerr << macro__vi << " "; \ } \ cerr << "]" << endl; \ } using lint = long long; const int INF = 1e9; const lint LINF = 1e18; const double EPS = 1e-10; int main() { int H, W; cin >> H >> W; vector<string> G(H); rep(i, H) cin >> G[i]; vector<vector<lint>> L(H, vector<lint>(W, 0)); vector<vector<lint>> R(H, vector<lint>(W, 0)); vector<vector<lint>> U(H, vector<lint>(W, 0)); vector<vector<lint>> D(H, vector<lint>(W, 0)); for (int i = 0; i < H; i++) { for (int j = 0; j < W - 1; j++) { L[i][j + 1] = L[i][j] + 1; if (G[i][j] == '#') L[i][j + 1] = 0; } } for (int i = 0; i < H; i++) { for (int j = W - 1; 0 < j; j--) { R[i][j - 1] = R[i][j] + 1; if (G[i][j] == '#') R[i][j - 1] = 0; } } for (int j = 0; j < W; j++) { for (int i = 0; i < H - 1; i++) { U[i + 1][j] = U[i][j] + 1; if (G[i][j] == '#') U[i + 1][j] = 0; } } for (int j = 0; j < W; j++) { for (int i = H - 1; 0 < i; i--) { D[i - 1][j] = D[i][j] + 1; if (G[i][j] == '#') D[i - 1][j] = 0; } } lint ans = -1; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (G[i][j] == '#') continue; lint cnt = L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1; ans = max(ans, cnt); } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 1000000000000000000 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define SIZE 100005 char L[SIZE]; ll dp[2][SIZE]; int main(){ scanf("%s",L); int len; for(len = 0; L[len] != '\0'; len++); for(int i = 0; i < 2; i++){ for(int k = 0; k <= len; k++){ dp[i][k] = 0; } } dp[true][0] = 2; dp[false][0] = 1; for(int i = 1; i < len; i++){ if(L[i] == '1'){ dp[true][i] = dp[true][i-1]*2; dp[true][i] %= MOD; dp[false][i] += dp[true][i-1]; dp[false][i] %= MOD; }else{ dp[true][i] = dp[true][i-1]; } dp[false][i] += dp[false][i-1]*3; dp[false][i] %= MOD; } printf("%lld\n",(dp[true][len-1]+dp[false][len-1])%MOD); return 0; }
0
9,570,978
#include <bits/stdc++.h> using namespace std; using ll =long long; typedef vector<int> VI; typedef vector<VI> VVI; typedef pair<int,int> PII; #define SORT(a) sort((a).begin(),(a).end()) #define rSORT(a) reverse((a).begin(),(a).end()) #define For(i, a, b) for(int i = (a) ; i < (b) ; ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } using P = pair<int,int>; int main() { string s; cin >> s; int k; cin >> k; int now = 0; rep(i,s.size()){ if(s[i] != '1'){ cout << s[i] << endl; return 0; } else { now += s[i] - '0'; if(now == k){ cout << 1 << endl; return 0; } } } }
#include <bits/stdc++.h> #include <boost/multiprecision/cpp_int.hpp> #define rep(i,a,b) for(ll i=a;i<b;i++) #define rrep(i,b,a) for(int i=b;i>=a;i--) #define fori(a) for(auto i : a ) #define all(a) begin(a), end(a) #define set(a,b) memset(a,b,sizeof(a)) #define sz(a) a.size() double pi=acos(-1); #define ll long long #define ull unsigned long long #define pb push_back #define PF push_front #define pq priority_queue const ll mod=1000000007; #define pii pair< ll, ll > #define vi vector<int> #define vpii vector<pii> #define debug(v) for(auto i:v) cout<<i<<" "; #define tc int t; cin >> t; while(t--) using namespace boost::multiprecision; using namespace std; void optimizeIO(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int N=1000005; ll fact[N],invfact[N]; ll power(ll x,ll y){ if(y<=0) return 1LL; ll z=power(x,y/2); if(y%2) return (((z*z)%mod)*x)%mod; return (z*z)%mod; } void pre(){ fact[0]=invfact[0]=invfact[1]=fact[1]=1; rep(i,2,N) fact[i]=(i*fact[i-1])%mod; rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod; } ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; } const int N1=1e6+1; vector<int> isprime(N1,1),prime; void seive(){ rep(i,2,sqrt(N1)+1){ if(isprime[i]){ for(int j=i*i;j<N1;j+=i) isprime[j]=0; prime.pb(i); } } rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i); } struct dsu { vector<int> par, rank; dsu(int n): par(n+1), rank(n+1) { for (int i = 0; i <= n; i++) { par[i] = i; rank[i]= 1; } } int root(int a) { if (a == par[a]) return a; return par[a] = root(par[a]); } void merge(int a, int b) { a = root(a); b = root(b); if (a == b) return; if (rank[a] > rank[b]) swap(a, b); par[b] = a; } set<int> parent(int n){ set<int> s; for(int i=1;i<=n;i++){ s.insert(root(i)); } return s; } }; void solve(){ int n,k; cin>>n>>k; int a[n]; map<int,int> m1; rep(i,0,n) {cin>>a[i];m1[a[i]]++;} vector<int> v1; for(auto i:m1) v1.pb(i.second); sort(all(v1)); if(v1.size()<=k){ cout<<0<<endl; return; } int cnt=0; rep(i,0,v1.size()){ if(v1.size()-1-i>=k) cnt+=v1[i]; } cout<<cnt<<endl; } int main(){ optimizeIO(); int r=1; {solve();} }
0
20,114,681
#include<bits/stdc++.h> #define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++) #define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++) #define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--) #define rrep1(i,n) for(int i=(int)(n);1<=i;i--) #define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define all(obj) (obj).begin(),(obj).end() #define pcount __builtin_popcount #define SZ(x) ((int)(x).size()) #define LEN(x) ((int)(x).length()) #define dump(x) cerr << #x << " = " << (x) << endl; #define endl "\n" template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;} typedef long long lint; using namespace std; int main(){ int x; cin>>x; cout<<(x<1200?"ABC":"ARC")<<endl; }
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<cmath> #include<vector> #include<stack> #include<climits> #include<cstring> #include<queue> #include<complex> using namespace std; void grading(int m, int f, int r){ if(m == -1 || f == -1) {cout << "F" <<endl;return;} if(m+f >= 80) {cout << "A" <<endl;return;} if(m+f >= 65) {cout << "B" <<endl;return;} if(m+f >= 50) {cout << "C" <<endl;return;} if(m+f >= 30){ if(r >= 50) {cout << "C" <<endl;return;} cout << "D" <<endl;return; } if(m+f < 30) {cout << "F" << endl;return;} } int main(){ int m, f, r; cin >> m >> f >> r; while( m!=-1 || f !=-1 || r!=-1){ grading(m ,f, r); cin >> m >> f >> r; } return 0; }
0
59,268,248
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = ll(1e12); const ll mod = ll(1e9+7); const double pi = acos(-1); #define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i)) #define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i)) #define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i)) #define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i)) #define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i)) #define pf(x) cout << (x) << endl #define all(x) (x).begin(),(x).end() #define yes pf("Yes") #define no pf("No") 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; } int dx[8]={1,0,-1,0,1,1,-1,-1}; int dy[8]={0,1,0,-1,1,-1,1,-1}; ll gcd(ll a,ll b){ if(a < b)swap(a, b); if(b == 0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ ll g = gcd(a,b); return a / g * b; } ll factorial(ll n){ ll ans = 1; rep1(i, n){ ans *= i; ans %= mod; } return ans; } ll power(ll a, ll b){ ll ans = 1; a %= mod; while(b) { if(b & 1LL) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } vector<ll> FactorialInv, Factorial; void init_combination(ll MAX){ Factorial.resize(MAX + 1); FactorialInv.resize(MAX + 1); Factorial[0] = 1; for(int i = 1; i <= MAX; i++){ Factorial[i] = Factorial[i - 1] * i % mod; } FactorialInv[MAX] = power(Factorial[MAX], mod - 2); for(ll i = MAX - 1; i >= 0; i--) { FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod; } } ll combination(ll a, ll b){ if((a == b) || (b == 0)){ return 1; } if(a < b) return 0; if(b < 0) return 0; ll ans = Factorial[a] * FactorialInv[b] % mod; ans = ans * FactorialInv[a - b] % mod; return ans; } int main(){ ll n,ans = 0; cin >> n; vector<ll> a(0); for(ll i = 1; i * i <= n; ++i)if(n % 1 == 0){a.push_back(i - 1);a.push_back(n / i - 1);} rep0(i, a.size())if(a[i] != 0)if(n % a[i] == n / a[i])ans += a[i]; pf(ans); return 0; }
#include <queue> #include <iostream> #include <stdio.h> #include <algorithm> using namespace std; int map_max; int map[110][110]; int rows; int cols[110]; int howfar[110]; int far; int visited[110]; void get_map(); void print_map(); int search(int node); void print_result(); void check_result(); int main() { get_map(); for(int i=0;i<map_max;i++) { visited[i]=1000; } search(1); check_result(); print_result(); return 0; } void check_result() { for(int i=1;i<map_max;i++) { if(visited[i]==1000) { visited[i]=-1; } } } void print_result() { for(int i=0;i<map_max;i++) { std::cout << i+1 << " " << visited[i] << std::endl; } } void get_map() { int k; scanf("%d", &map_max); for(int i=0;i<map_max;i++) { scanf("%d", &k); scanf("%d", &cols[i]); for(int j=0;j<cols[i];j++) { map[i][j]=0; scanf("%d", &map[i][j]); } } return ; } void print_map() { for(int i=0;i<map_max;i++) { for(int j=0;j<cols[i];j++) { printf("%d", map[i][j]); } puts(""); } return ; } int search(int node) { far =1; int next =1, now,buf; visited[node-1]=0; queue<int> q; for(int i=0;i<cols[node-1];i++) { now = map[node-1][i]; q.push(now); visited[now-1]=visited[node-1]+1; } while(!q.empty()) { next = q.front(); q.pop(); for(int i=0;i<cols[next-1];i++) { now = map[next-1][i]; if(visited[now-1]==1000) { q.push(now); visited[now-1]=min(visited[next-1]+1, visited[now-1]); } } } return 0; }
0
20,451,390
#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>; ll ketasu(ll a){ ll num=1; while(a/10){ num++; a/=10; } return num; } int main() { ll n; cin>>n; ll a=sqrt(n); while(1){ if(n%a==0){ break; } a--; } ll b=n/a; cout <<a+b-2<<endl; }
#include "bits/stdc++.h" #define rep(i,n) for (int i=0; i<(n); ++i) using namespace std; using ll =long long; using P =pair<int,int>; int main(){ string s; cin >> s; ll l; l=s.size(); ll t; vector <ll> al(26,0); rep(i,l){ t=s[i]; ++al[t-97]; } ll ans=0; rep(i,26){ ans+=al[i]*(al[i]-1)/2; } cout << l*(l-1)/2-ans+1 << endl; return 0; }
0
34,615,819
#pragma GCC optimize("Ofast") #include "bits/stdc++.h" using namespace std; using ll = long long; using ull = unsigned long long; #define PI 3.141592 #define LL_INF 9000000000000000000 #define LL_MINF -9000000000000000000 #define INT_INF 2000000000 #define INT_MINF -2000000000 #define all(a) (a).begin(), (a).end() #define fi first #define se second const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int main(){ string S; cin >> S; int N = S.size(); for(int del = 1; del <= N - 2; del++){ int n = N - del; if(n % 2) continue; if(S.substr(0, n / 2) == S.substr(n/2, n/2)){ cout << n << endl; return 0; } } }
#include <bits/stdc++.h> #include <cmath> using namespace std; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define sz(x) ll(x.size()) typedef long long ll; typedef pair<int, int> P; const ll INF = 10e15; const ll MINF = -10e10; #define cmin(x, y) x = min(x, y) #define cmax(x, y) x = max(x, y) typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK; const int mod = 1000000007; int main() { int n; cin >> n; vector<P> reds(n); vector<P> blues(n); rep(i, n) { int a, b; cin >> a >> b; P p(a, b); reds[i] = p; } rep(i, n) { int a, b; cin >> a >> b; P p(a, b); blues[i] = p; } sort(blues.begin(), blues.end()); sort(reds.begin(), reds.end(), [](P i, P j) { return i.second > j.second; }); set<int> red_used; int ans = 0; for (P blue : blues) { for (int i = 0; i < n; i++) { P red = reds[i]; if (blue.first <= red.first || blue.second <= red.second) continue; if (red_used.find(i) != red_used.end()) continue; red_used.insert(i); ans++; break; } } cout << ans << endl; }
0
40,425,425
#include<cstdio> #include<cstdlib> #include<algorithm> #include<iostream> #include<queue> #include<vector> #include <bitset> #include <cmath> #include <limits> #include <iostream> #include<map> #include<tuple> using namespace std; #define INF 21000000000 #define MAX 210000 #define MOD 998244353 typedef long long ll; typedef pair<int,ll> P; typedef pair<pair<int,int>,int> p; typedef pair< pair<int,int>, int> p; #define bit(n,k) ((n>>k)&1) #define rad_to_deg(rad) (((rad)/2/M_PI)*360) int main(){ string s; cin>>s; if(s.substr(0,4)=="YAKI") cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <iostream> using namespace std; int main(){ int n,i,ans=1; char s,spre; cin >> n; cin >> spre; for(i=1;i<n;++i){ cin >> s; if(s==spre) continue; else{ ++ans; spre = s; } } cout << ans << endl; return 0; }
0
52,785,770
#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 <math.h> #include <cstdlib> #include <iomanip> #define rep(i,x) for(ll i=0;i<x;i++) #define all(a) (a).begin(),(a).end() using namespace std; using ld = long double; using ll = long long; const ll INF = 10010010010; typedef pair<ll, ll> P; using graph = vector<vector<ll>>; const ll mod = 1000000007; ll gcd(ll a, ll b) { if (a < b)swap(a, b); if (a % b == 0) return b; else return gcd(b, a % b); } bool isp(ll n) { bool res = true; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { res = false; break; } } return res; } int main() { string S; cin >> S; ll s = S.size(); bool ans = true; bool c = false; if(S[0] != 'A')ans = false; if(isupper(S[1]))ans = false; if(isupper(S[s - 1 ]))ans = false; for(int i = 2;i<s - 1;i++){ if(c == false && S[i] == 'C')c = true; else if(c == true && isupper(S[i]))ans = false; } if(c && ans)cout << "AC" << endl; else cout << "WA" << endl; }
#include<bits/stdc++.h> using namespace std; int parent(int i){ return i/2; } int left(int i){ return i*2; } int right(int i){ return i*2+1; } int main(){ int H, tree[100001]; scanf("%d",&H); for( int i = 1; i <= H; ++i){ scanf("%d",&tree[i]); } for( int i = 1; i <= H; ++i){ printf("node %d: key = %d, ",i,tree[i]); if(parent(i)>=1) printf("parent key = %d, ",tree[parent(i)]); if(left(i)<=H) printf("left key = %d, ",tree[left(i)]); if(right(i)<=H) printf("right key = %d, ",tree[right(i)]); putchar('\n'); } return 0; }
0
33,394,509
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int NIL = -1; const int INF = (1<<21); const long long MOD = 1e9+7; const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; int main() { int r, D, x; cin >> r >> D >> x; for (int i = 1; i <= 10; ++i) { int new_x = r * x - D; cout << new_x << endl; x = new_x; } }
#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; string ans = "Yes"; int x = 0; int y = 0; int t = 0; rep(i, n) { int it, ix, iy; cin >> it >> ix >> iy; int d = abs(ix-x) + abs(iy-y); if (d<=it-t && (d%2)==((it-t)%2)) { t = it; x = ix; y = iy; } else { cout << "No" << endl; return 0; } } cout << ans << endl; return 0; }
0
47,860,182
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; if (n==1) { cout<<"1"; } if (n==2) { cout<<"1"; } if (n==3) { cout<<"1"; } if (n==4) { cout<<"2"; } if (n==5) { cout<<"1"; } if (n==6) { cout<<"2"; } if (n==7) { cout<<"1"; } if (n==8) { cout<<"5"; } if (n==9) { cout<<"2"; } if (n==10) { cout<<"2"; } if (n==11) { cout<<"1"; } if (n==12) { cout<<"5"; } if (n==13) { cout<<"1"; } if (n==14) { cout<<"2"; } if (n==15) { cout<<"1"; } if (n==16) { cout<<"14"; } if (n==17) { cout<<"1"; }if (n==18) { cout<<"5"; } if (n==19) { cout<<"1"; } if (n==20) { cout<<"5"; } if (n==21) { cout<<"2"; } if (n==22) { cout<<"2"; } if (n==23) { cout<<"1"; } if (n==24) { cout<<"15"; } if (n==25) { cout<<"2"; } if (n==26) { cout<<"2"; } if (n==27) { cout<<"5"; } if (n==28) { cout<<"4"; } if (n==29) { cout<<"1"; } if (n==30) { cout<<"4"; } if (n==31) { cout<<"1"; } if (n==32) { cout<<"51"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define uint unsigned int #define ull unsigned long long typedef string str; typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef map<int, int> mii; typedef vector<int> vi; typedef vector<bool> vb; #define pb push_back #define fi first #define se second #define in insert #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) const int INF = 1e9 + 5; const int N = 2e5 + 1; int main(){ speed; int n, m; cin >> n >> m; map<int, mii > v; int ok = 0; for(int i = 0; i < m; ++i){ int x, y; cin >> x >> y; v[x][y] = 1; if(x == 1 && v[y][n]){ ok = 1; } if(y == n && v[1][x]){ ok = 1; } } if(ok){ cout << "POSSIBLE"; } else{ cout << "IMPOSSIBLE"; } }
0
20,416,476
#include <bits/stdc++.h> using namespace std; int main() { int a,b; cin >> a >> b; int c = (a + b)/2*2; int d = (a + b) - c; cout << (a + b )/2 + d << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) int main(){ string s; cin >> s; ll ans = 0; ll hd = 0, bk = s.size()-1; while(bk - hd > 0){ if(s[hd] == s[bk]){ hd++; bk--; }else{ if(s[hd] != 'x' && s[bk] != 'x'){ cout << -1 << endl; return 0; } if(s[hd] == 'x'){ ans++; hd++; } if(s[bk] == 'x'){ ans++; bk--; } } } cout << ans << endl; return 0; }
0
52,405,923
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #define MAXN 200000 using namespace std; int X[MAXN+5],W[MAXN+5]; int sum[2][MAXN+5],pos[MAXN+5]; int ans[MAXN+5]; int N,L,T; int main() { scanf("%d %d %d",&N,&L,&T); int T1=T; for(int i=0;i<N;i++) { scanf("%d %d",&X[i],&W[i]); pos[i]=X[i]; sum[0][i]=sum[0][max((i-1),0)]; sum[1][i]=sum[1][max((i-1),0)]; W[i]--; sum[W[i]][i]++; } for(int i=N;i<2*N;i++) { pos[i]=X[i%N]+L; sum[0][i]=sum[0][i-1]; sum[1][i]=sum[1][i-1]; sum[W[i%N]][i]++; } int cnt[2]={}; T*=2; cnt[0]=T/L*sum[0][N-1]; cnt[1]=T/L*sum[1][N-1]; T%=L; for(int i=0;i<N;i++) { if(W[i]==1) continue; int p=upper_bound(pos,pos+2*N,pos[i]+T)-pos; p--; int cntn=cnt[1]+sum[1][p]-sum[1][i]; ans[(i+cntn)%N]=(pos[i]+T1)%L; } for(int i=N;i<2*N;i++) { if(W[i%N]==0) continue; int p=lower_bound(pos,pos+2*N,pos[i]-T)-pos; int cntn; if(p>0) cntn=cnt[0]+sum[0][i-1]-sum[0][p-1]; else cntn=cnt[0]+sum[0][i-1]; ans[((i-cntn)%N+N)%N]=((pos[i]-T1)%L+L)%L; } for(int i=0;i<N;i++) printf("%d\n",ans[i]); return 0; }
#include<algorithm> #include<bitset> #include<cmath> #include<complex> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<iterator> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define D() #define INF 1000000000000 #define MOD 10000007 #define MAXR 100000 #define PB push_back #define MP make_pair #define F first #define S second #define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;} int main() { ll n; cin >> n; if (n % 2 == 0) { ll res = 0; ll div = 10; while (div <= n) { res += n / div; div *= 5; } cout << res << endl; } else { cout << 0 << endl; } return 0; }
0
7,885,468
#include<cstdio> #include<vector> #include<algorithm> #include<utility> #include<numeric> #include<iostream> #include<array> #include<string> #include<sstream> #include<stack> #include<queue> #include<list> #include<functional> #define _USE_MATH_DEFINES #include<math.h> #include<map> #define SENTINEL 1000000001 #define min(a,b) ((a)>(b)?(b):(a)) #define max(a,b) ((a)>(b)?(a):(b)) #define INF 200000000000 using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; struct OwnEdge { ll from, to, cost; OwnEdge() :from(-1), to(-1), cost(-1) {} OwnEdge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {} }; OwnEdge edges[10000]; ll tod[100][100]; int main() { cin.tie(0); ios::sync_with_stdio(false); int V, E; scanf("%d %d", &V, &E); for (int i = 0; i < V; i++)for (int j = 0; j < V; j++) { tod[i][j] = INF; } for (int i = 0; i < E; i++) { int s, t, d; scanf("%d %d %d", &s, &t, &d); edges[i] = OwnEdge(s, t, d); } for (int k = 0; k < V; k++) { tod[k][k] = 0; bool ns = false; for (int i = 0; i < V; i++) { for (int j = 0; j < E; j++) { OwnEdge t = edges[j]; if (tod[k][t.from] != INF&&tod[k][t.to]>(tod[k][t.from] + t.cost)) { tod[k][t.to] = (tod[k][t.from] + t.cost); if (i == (V - 1)) { ns = true; } } } } if (ns) { printf("NEGATIVE CYCLE\n"); return 0; } } for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (j == 0) { printf(tod[i][j] == INF ? "INF" : "%lld", tod[i][j]); } else { printf(tod[i][j] == INF ? " INF" : " %lld", tod[i][j]); } } printf("\n"); } return 0; }
#include <iostream> #include <vector> #include <queue> using namespace std; bool used[100000] = {}; vector<int> G[100000]; int nxt(int v){ for(int to : G[v]){ if(!used[to]) return to; } return -1; } int main(){ int n,d[100000] = {}; bool flag = false; cin >> n; for(int i = 0;i < n - 1;i++){ int a,b; cin >> a >> b; a--;b--; G[a].push_back(b); G[b].push_back(a); d[a]++; d[b]++; } queue<int> que; for(int i = 0;i < n;i++){ if(d[i] == 1) que.push(i); } while(!que.empty()){ int v = que.front(),nextv = nxt(v);que.pop(); if(used[v]) continue; if(nextv == -1){ flag = true; break; } used[v] = true; used[nextv] = true; for(int to : G[nextv]){ if(!used[to]){ d[to]--; if(d[to] == 1) que.push(to); } } } for(int i = 0;i < n;i++) if(!used[i]) flag = true; if(flag) cout << "First" << endl; else cout << "Second" << endl; return 0; }
0
79,774,243
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0; i < int(n); i++) #define REPD(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = a; i < int(b); i++) #define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--) #define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w) #define ALL(x) (x).begin(), (x).end() int dx[4] = { 1, 0, -1, 0 }; int dy[4] = { 0, 1, 0, -1 }; ll powmod(ll n, ll x) { vector<ll> vll(32); vll[0] = n; FOR(i, 1, 32) { vll[i] = (vll[i - 1] * vll[i - 1]) % MOD; } ll ret = 1; int cnt = 0; while (x > 0) { if (x & 1) { ret = (ret * vll[cnt]) % MOD; } x >>= 1; cnt++; } return ret; } long long fac[2000001]; struct Comb { Comb() { fac[0] = fac[1] = 1; for (int i = 2; i < 2000001; i++) { fac[i] = fac[i - 1] * i % MOD; } } long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; ll ret = fac[n]; ret = (ret * powmod(fac[k], MOD - 2)) % MOD; ret = (ret * powmod(fac[n - k], MOD - 2)) % MOD; return ret; } ll PERM(int n, int k) { if (n < k) return 0; ll ret = fac[n]; ret = (ret * powmod(fac[n - k], MOD - 2)) % MOD; return ret; } }; int main() { ll n, k; cin >> n >> k; ll ans = 0; Comb C; vector<ll> end(n+2,0); FOR(i,1,n+2){ end[i]=end[i-1]+n-i+1+MOD; end[i]%=MOD; } for (ll i = k; i <= n + 1; i++) { ll first=i*(i-1)/2; first%=MOD; ans += end[i]-first+MOD+1; ans %= MOD; } cout << ans << endl; }
#include <iostream> #include <string> #include <vector> using namespace std; struct Card { char suite; int num; }; vector<Card> selectionSort(vector<Card> A) { for (size_t i = 0; i < A.size() - 1; i++) { size_t minj = i; for (size_t k = i + 1; k < A.size(); k++) { if (A[k].num < A[minj].num) { minj = k; } } if (minj != i) { swap(A[minj], A[i]); } } return A; } vector<Card> bubbleSort(vector<Card> A) { bool flag = true; while (flag) { flag = false; for (size_t k = A.size() - 1; k > 0; --k) { if (A[k].num < A[k - 1].num) { swap(A[k], A[k - 1]); flag = true; } } } return A; } void printCards(vector<Card> v) { for (size_t i = 0; i < v.size(); i++) { if (i > 0) cout << " "; cout << v[i].suite << v[i].num; } cout << endl; } bool isStable(vector<Card> original, vector<Card> sorted) { for (size_t i = 0; i < sorted.size() - 1; i++) { for (size_t j = i + 1; j < sorted.size(); j++) { if (sorted[i].num != sorted[j].num) { break; } size_t original_i, original_j; for (size_t k = 0; k < original.size(); k++) { if (sorted[i].suite == original[k].suite && sorted[i].num == original[k].num) { original_i = k; break; } } for (size_t k = 0; k < original.size(); k++) { if (sorted[j].suite == original[k].suite && sorted[j].num == original[k].num) { original_j = k; break; } } if (original_i > original_j) { return false; } } } return true; } void printStability(vector<Card> original, vector<Card> sorted) { if (isStable(original, sorted)) { cout << "Stable" << endl; } else { cout << "Not stable" << endl; } } int main(int argc, char** argv) { vector<Card> A; size_t N; cin >> N; for (size_t i = 0; i < N; i++) { Card c; cin >> c.suite >> c.num; A.push_back(c); } vector<Card> C = bubbleSort(A); printCards(C); printStability(A, C); vector<Card> B = selectionSort(A); printCards(B); printStability(A, B); return 0; }
0
9,360,071
#include <cstdio> int main(){ int n, m; static int dict[256]; char k, v, x; while (scanf("%d\n", &n)){ if (!n) return 0; for (int i = 0; i<256; i++) dict[i] = i; for (int i = 0; i<n; i++){ scanf("%c %c\n", &k, &v); dict[(int)k] = (int)v; } scanf("%d\n", &m); for (int i = 0; i<m; i++){ scanf("%c\n", &x); printf("%c", dict[(int)x]); } printf("\n"); } }
#include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ll N,minimum=1000000000; cin>>N; vector<ll> A(N); for(ll i=0;i<N;i++){ cin>>A.at(i); minimum=min(minimum,A.at(i)); } while(true){ ll x=minimum,check=0,count=0; for(ll i=0;i<N;i++){ if(A.at(i)!=x || check>0){A.at(i)=A.at(i)%x;} if(A.at(i)==x){check++;} if(A.at(i)==0){count++;} else{minimum=min(minimum,A.at(i));} } if(count==N-1){break;} } cout<<minimum<<endl; }
0
35,316,573
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX = 100005; const int MOD = 1000000007; int 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; } } int 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; } signed main(){ int n; cin >>n; int a[n+1],b[n]={},k; for(int i=0;i<=n;i++){ cin>>a[i]; if(b[a[i]-1]==0) b[a[i]-1]=i+1; else k= i+1-b[a[i]-1]+1; } COMinit(); for(int i=1;i<=n+1;i++){ cout << (COM(n+1,i)+(MOD-COM(n+1-k,i-1)))%MOD<<endl; } return 0; }
#include <iostream> #include<iomanip> #include <string> #include<vector> #include<algorithm> #include<utility> #include<queue> #include<math.h> #include<stack> #include<set> #include<map> #define INF int(1e6+1) #define rep(i,n,m) for(int i=n;i<m;i++) using namespace std; int main() { long long int a, b,t; cin >> a >> b; if (a < b) { t = a; a = b; b = t; } long long int x,na=a,nb=b; while (nb) { x = nb; nb = na % nb; na = x; } cout << a * b / na << endl; }
0
95,453,291
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; int dx[] = {-1, 1, 0, 0}; int dy[] = { 0, 0, 1, -1}; int main(){ int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int dx = x2 - x1; int dy = y2 - y1; int x3 = x2 - dy; int y3 = y2 + dx; int x4 = x3 - dx; int y4 = y3 - dy; cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; #define rng(i,l,r) for(int i=int(l);i<int(r);i++) #define rep(i,r) rng(i,0,r) #define rrng(i,l,r) for(int i=int(r)-1;i>=int(l);i--) #define rrep(i,r) rrng(i,0,r) #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define F first #define S second #define bg begin() #define ed end() #define all(x) x.bg,x.ed #define si(x) int(x.size()) #define inf INT_MAX/2-100 #define infl LLONG_MAX/3 #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<' '<<#x<<' '<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u>bool chmax(t&a,u b){if(a<b)a=b;return a<b;} template<class t,class u>bool chmin(t&a,u b){if(b<a)a=b;return b<a;} template<class t>using vc=vector<t>; template<class t>using vvc=vector<vector<t>>; using pi=pair<int,int>; using pl=pair<ll,ll>; using vi=vc<int>; using vl=vc<ll>; ll readl(void){ ll x; cin>>x; return x; } int readi(void){ int x; cin>>x; return x; } string readstr(){ string s; cin>>s; return s; } vi readvi(int n,int off=0){ vi v(n); rep(i,n)v[i]=readi(),v[i]+=off; return v; } vl readvl(int n,int off=0){ vl v(n); rep(i,n)v[i]=readl(),v[i]+=off; return v; } template<class t> void print(t x,int suc=1){ cout<<x; if(suc==1)cout<<"\n"; if(suc==2)cout<<" "; } template<class t> void print(const vc<t>&v,int suc=1){ rep(i,si(v))print(v[i],i==int(si(v))-1?1:suc); } template<class t> bool inc(t a,t b,t c){ return !(c<b||b<a); } template<class t> void compress(vc<t>&v){ sort(all(v)); v.erase(unique(all(v)),v.ed); } template<class t> int lwb(const vc<t>&v,const t&a){ return lower_bound(all(v),a)-v.bg; } template<class t> struct Compress{ vc<t>v; Compress()=default; Compress(const vc<t>&x){ add(x); } Compress(const initializer_list<vc<t> >&x){ for(auto &p:x)add(p); } void add(const t&x){ v.eb(x); } void add(const vc<t>&x){ copy(all(x),back_inserter(v)); } void build(){ compress(v); } int get(const t&x)const{ return lwb(v,x); } vc<t>get(const vc<t>&x)const{ vc<t>res(x); for(auto &p:res)p=get(p); return res; } const t &operator[](int x)const{ return v[x]; } int size(){ return v.size(); } }; void Yes(bool ex=true){ cout<<"Yes\n"; if(ex)exit(0); } void YES(bool ex=true){ cout<<"YES\n"; if(ex)exit(0); } void No(bool ex=true){ cout<<"No\n"; if(ex)exit(0); } void NO(bool ex=true){ cout<<"NO\n"; if(ex)exit(0); } void orYes(bool x,bool ex=true){ if(x)Yes(ex); else No(ex); } void orYES(bool x,bool ex=true){ if(x)YES(ex); else NO(ex); } void Possible(bool ex=true){ cout<<"Possible\n"; if(ex)exit(0); } void POSSIBLE(bool ex=true){ cout<<"POSSIBLE\n"; if(ex)exit(0); } void Impossible(bool ex=true){ cout<<"Impossible\n"; if(ex)exit(0); } void IMPOSSIBLE(bool ex=true){ cout<<"IMPOSSIBLE\n"; if(ex)exit(0); } void orPossible(bool x,bool ex=true){ if(x)Possible(ex); else Impossible(ex); } void orPOSSIBLE(bool x,bool ex=true){ if(x)POSSIBLE(ex); else IMPOSSIBLE(ex); } ll n,m,vis[100005],ans,e,o,s,r; vl g[100005]; bool dfs(int v,int k){ bool res=true; vis[v]=k; s++; for(auto &i:g[v]){ if(vis[i]==0){ res&=dfs(i,k*-1); }else if(vis[i]==k){ res=false; } } return res; } int main(void){ cin.tie(0); ios::sync_with_stdio(0); cin>>n>>m; rep(i,m){ ll a,b; cin>>a>>b; g[--a].pb(--b); g[b].pb(a); } fill(vis,vis+n,0); r=n; rep(i,n){ if(vis[i]==0){ s=0; bool bd=dfs(i,1); if(s==1)ans+=r*2LL-1LL,r--; else if(bd)e++; else o++; } } ans+=o*o; ans+=e*o*2LL; ans+=e*e*2LL; print(ans); }
0
18,500,861
#include<bits/stdc++.h> using namespace std; #define AC ios::sync_with_stdio(0),cin.tie(0); #define ll long long int int main(){ AC string a,b; cin>>a>>b; int ans=100000; for(int i=b.size()-1;i<a.size();i++){ int j=i; int k=b.size()-1; int countt=0; if(a[j]!=b[k])countt++; while(k-- && j--){ if(a[j]!=b[k])countt++; } ans=min(countt,ans); } cout<<ans<<endl; }
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<queue> #include<cmath> #include<cstdio> #include<tuple> #include<bitset> #include<map> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<=n;++i) #define ALL(x) x.begin(),x.end() using ll = long long; using lint = long long; typedef pair<int,int> P; const lint inf=1e18+7; const int MOD=1000000007; int f(int a,int b){ int res=0; while(a>0){ ++res;a/=10; } int buf=0; while(b>0){ ++buf;b/=10; } return max(res,buf); } signed main(){ lint n;cin>>n; lint res=inf; rep1(i,100000){ if(n%i==0){ lint buf=f(i,n/i); res=min(res,buf); } } cout<<res<<"\n"; return 0; }
0
1,873,714
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define REPR(i,n) for(int i=n; i>-1; --i) #define ALL(a) (a).begin(),(a).end() #define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); } #define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; } #define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} } #define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} } #define Liny "Yes\n" #define Linn "No\n" #define LINY "YES\n" #define LINN "NO\n" #define umap unordered_map int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}} int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} } int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );} ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);} ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;} int main(){ int N,e; cin>>N; vector<int> ans; int cumu[N+1]; cumu[0]=0LL; for(int i=1;i<=N;++i){ cumu[i]=cumu[i-1]+i; ans.push_back(i); if(cumu[i]<N){continue;} else{ e = cumu[i]-N;break;} } for(int x:ans){ if(x!=e){printf("%d\n",x);} } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<string> vs; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) FOR(i, 0, n) #define pb push_back #define all(a) (a).begin(), (a).end() #define UNIQUE(v) v.erase(unique(all(v)), v.end()); #define fill(a, x) memset(a, x, sizeof(a)) #define zero(a) fill(a, 0) #define minus(a) fill(a, -1) #define dbg(x) cout << #x "=" << x << endl #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int n, D[MAX]; void print(int u) { int i, c; cout << "node " << u << ": "; cout << "parent = " << T[u].p << ", "; cout << "depth = " << D[u] << ", "; if (T[u].p == NIL) { cout << "root, "; } else if (T[u].l == NIL) { cout << "leaf, "; } else { cout << "internal node, "; } cout << "["; for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) { if (i) { cout << ", "; } cout << c; } cout << "]" << endl; } int rec(int u, int p) { D[u] = p; if (T[u].r != NIL) { rec(T[u].r, p); } if (T[u].l != NIL) { rec(T[u].l, p + 1); } } int main() { int i, j, d, v, c, l, r; cin >> n; rep(i, n) { T[i].p = T[i].l = T[i].r = NIL; } rep(i, n) { cin >> v >> d; rep(j, d) { cin >> c; if (j == 0) { T[v].l = c; } else { T[l].r = c; } l = c; T[c].p = v; } } rep(i, n) { if (T[i].p == NIL) { r = i; } } rec(r, 0); rep(i, n) { print(i); } return 0; }
0
92,284,437
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int main(){ int X, A, B; cin >> X >> A >> B; if (B - A > X) cout << "dangerous" << endl; else if (B - A > 0) cout << "safe" << endl; else cout << "delicious" << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < n; ++i) #define ALL(c) (c).begin(), (c).end() #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) #define DUMP(v) for(auto& x : v) cerr << x << " "; cerr << endl; using namespace std; using ll = long long; 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; } constexpr int INF = 1e9+5; constexpr long long INFLL = 1LL<<60; constexpr double eps = (1e-9); int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> c(n-1), s(n-1), f(n-1); rep(i, n-1) cin >> c[i] >> s[i] >> f[i]; for (int i = 0; i < n-1; i++) { ll ans = 0; for (int j = i; j < n-1; j++) { if (ans <= s[j]) { ans = s[j] + c[j]; } else { if (ans % f[j] == 0) ans += c[j]; else ans += (f[j] - ans % f[j]) + c[j]; } } cout << ans << endl; } cout << 0 << endl; return 0; }
0
34,160,942
#include <bits/stdc++.h> #define rep(i , n) for (int i = 0; i < (int)(n); i++) const int INF = 1<<29; using namespace std; using ll = long long; int main(){ int N; cin >> N; vector <string> S(N); vector <int> A(N , 0); for(int i = 0; i < N; i++){ string s; cin >> s; sort(s.begin() , s.end()); S[i] = s; } sort(S.begin() , S.end()); map <string , int> t; ll m = 0; for(int i = 0; i < N; i++){ m += t[S[i]]; t[S[i]]++; } cout << m << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define MIN(a,b) ((a)>(b)? (b): (a)) #define MAX(a,b) ((a)<(b)? (b): (a)) const long long INF = 1LL << 60; typedef unsigned long long ll; const long long MOD = 1000000000 + 7; int main() { int n, m; cin >> n >> m; int k; vector<int> mask(n, 0); rep(i, m) { cin >> k; rep(j, k) { int tmp; cin >> tmp; mask[i] |=(1<<tmp-1); } } vector<int> p(n); rep(i, m) { cin >> p[i]; } int out = 0; for (int bit = 0; bit < (1 << n); ++bit) { bool flag = true; rep(i, m) { int tmp = bit & mask[i]; if (__builtin_popcount(tmp)%2!=p[i]) { flag = false; break; } } if (flag) { out++; } } cout << out << endl; return 0; }
0
2,808,745
#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); map<int, int> init; map<int, int> fin; for (int i = 0; i < n; i++){ cin >> a[i]; init[a[i]] = i; } sort(a.begin(), a.end()); for (int i =0 ; i < n; i++){ fin[a[i]] = i; } int ans = 0; for (auto it = init.begin(); it != init.end(); it++){ if (it->second % 2 != fin[it->first] % 2) ans++; } cout << ans/2 << '\n'; return 0; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second #define task "tst" using namespace std; const ll N = 3e5 + 9; const ll inf = 1e9 + 7; typedef pair<ll,ll> LL; ll x,y,a,b,c,R[N],G[N],C[N],i,j; vector<ll> res; bool lf(ll x,ll y){ return x > y; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); } cin>>x>>y>>a>>b>>c; for (i = 1;i <= a;i++) cin>>R[i]; sort(R + 1,R + a + 1,lf); for (i = 1;i <= b;i++) cin>>G[i]; sort(G + 1,G + b + 1,lf); for (i = 1;i <= c;i++) cin>>C[i]; sort(C + 1,C + c + 1,lf); for (i = 1;i <= x;i++) res.push_back(R[i]); for (i = 1;i <= y;i++) res.push_back(G[i]); sort(res.begin(),res.end(),lf); i = res.size() - 1; j = 1; while(true){ if (i < 0||C[j] <= res[i]) break; res[i] = C[j]; j++; i--; } ll sum = 0; for (auto i : res) sum += i; cout<<sum; }
0
52,497,481
#include<bits/stdc++.h> #define ll long long int #define vec vector<ll> #define mat vector<vec> using namespace std; const ll mod=1000000007; const ll inf=LONG_LONG_MAX; ll dx4[4]={1,0,-1,0}; ll dy4[4]={0,-1,0,1}; ll dx8[8]={1,0,-1,1,-1,1,0,-1}; ll dy8[8]={1,1,1,0,0,-1,-1,-1}; string zero(ll a){ string t=to_string(a); while(t.size()<6){ t='0'+t; } return t; } int main(){ ll n,m; cin >> n >> m; ll p[m],y[m]; mat G; for(ll i=0;i<m;i++){ cin >> p[i] >> y[i]; G.push_back({y[i],p[i],i}); } sort(G.begin(),G.end()); ll city[n+1]={}; vector<string> ans(m); for(ll i=0;i<m;i++){ ll a=city[G[i][1]]+1; city[G[i][1]]++; string t=zero(G[i][1])+zero(a); ans[G[i][2]]=t; } for(ll i=0;i<m;i++)cout << ans[i] << endl; }
#include <bits/stdc++.h> #define ll long long #define pi (acos(-1)) #define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i) using namespace std; std::vector<unsigned ll> genprimevec(const unsigned ll N); int main() { int n; cin>>n;string s,t; cin>>s>>t; string ans; rep(i,n){ ans.push_back(s[i]); ans.push_back(t[i]); } cout<<ans<<endl; return 0; } /*author https: ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } std::vector<unsigned ll> genprimevec(const unsigned ll N) { std::vector<bool> is_prime(N + 1); for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; } std::vector<unsigned ll> P; for (unsigned ll i = 2; i <= N; i++) { if (is_prime[i]) { for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; } P.emplace_back(i); } } return P; }
0
94,914,562
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, from, to) for (int i = from; i < (to); ++i) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() using ll = long long; using vin=vector<int>; using vll=vector<ll>; using P = pair<int, int>; const int inf=1e9+7; const ll INF=1e18; template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chmax(T &a, T b) { a = max(a, b); } int main() { int n; cin>>n; vin a(n); rep(i,0,n){ cin>>a[i]; } int mn=0; rep(i,0,n-1){ rep(j,i+1,n){ mn=max(mn,abs(a[i]-a[j])); } } cout<<mn<<endl; }
#include<iostream> #include<unordered_map> #include<bitset> #include<math.h> #include<vector> #include<set> #include<algorithm> #include<ctype.h> #include<unordered_set> #include<string> #include<iomanip> #include<queue> #include<limits> #include<map> #include<stack> #include<iterator> #include<cstring> #include<deque> #define pi 3.141592653589793238 #include<chrono> #define MOD 1000000007 #define INF 999999999999999999 #define pb push_back #define ff first #define ss second #define mt make_tuple #define ll long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define f0 get<0> #define f1 get<1> #define f2 get<2> using namespace std; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } int main() { fast; ll T = 1, i, j; while (T--) { ll a ,b , c, d ,e; vector<ll> v(5); cin >> v[0]>> v[1] >> v[2] >> v[3] >> v[4]; sort(v.begin(), v.end()); ll ans = INF; do{ ll sum = 0; for(i = 0; i < 5 ;i++){ sum += v[i]; if(i == 4){ break; } sum += (10 - (v[i] % 10)) % 10; } ans = min(ans, sum); }while(next_permutation(v.begin(), v.end())); cout << ans; } return 0; }
0
95,216,709
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define test int t;cin>>t;while(t--) #define REP(i,n) for (int i = 1; i <= n; i++) #define MOD 1000000007 #define ll long long #define int ll #define pb push_back #define ii pair<int,int> #define llll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define vii vector<ii> #define vllll vector<llll> #define ff first #define ss second #define INF 1000000000 #define HINF 1000000000000000 #define mem(a,b) memset(a,b,sizeof(a)) #define deb(x) cout<<#x<<'='<<x<<endl const double pi = 3.14159265358979323846; ll power(ll a, ll b){ ll res=1; a=a%MOD; while(b>0){ if(b&1){res=(res*a)%MOD;b--;} a=(a*a)%MOD; b>>=1; } return res; } ll fermat_inv(ll y){return power(y,MOD-2);} ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);} int C(int n,int k) { int ans=1; if(k>n-k) k=n-k; for(int i=1;i<=k;i++) ans*=(n-i+1),ans/=i; return ans; } void solve() { int h,w,i=0,j=0,k=0,m,n,p,e,f=0,sum=0,cnt=0; cin>>n; for(i=1;i<=n;i++) sum+=i*(n-i+1); for(i=0;i<n-1;i++) { cin>>j>>k; if(k<j)swap(j,k); sum-=j*(n-k+1); } cout<<sum; } int32_t main() { fast { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int i, j; int h, w; cin >> h >> w; bool consecutive = true; vector<int> row_index(1, -1); vector<vector<char>> board(h, vector<char>(w)); for (i=0; i<h; i++) { for (j=0; j<w; j++) { cin >> board.at(i).at(j); } } for (i=0; i<h; i++) { consecutive = true; for (j=0; j<w; j++) { if (board.at(i).at(j) == '#') consecutive = false; } if (consecutive) { row_index.push_back(i); for (j=0; j<w; j++) { board.at(i).at(j) = 'n'; } } } for (i=0; i<w; i++) { consecutive = true; for (j=0; j<h; j++) { if (board.at(j).at(i) == '#') consecutive = false; } if (consecutive) { for (j=0; j<h; j++) { board.at(j).at(i) = 'n'; } } } bool row = true; for (i=0; i<h; i++) { row = true; for (j=0; j<w; j++) { for (int x : row_index) if (x == i) {row = false; break;} if (board.at(i).at(j) != 'n') { cout << board.at(i).at(j); } } if (row) cout << endl; } }
0
40,766,197
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 60; long long dp[100010]; long long h[100010]; template<class T> void chmin(T &a, T b) { if (a>b) { a = b; } } template<class T> inline void chmax(T &a, T b) { if (a<b) { a = b; } } int main() { int n; cin >> n; int m; cin >> m; for (int i = 0; i < 100010; i++) { dp[i] = -1; } int a[100010]; for (int i = 0; i < m; i++) { cin >> a[i]; dp[a[i]] = -10; } dp[0] = 1; for (int i = 1; i <= n; i++) { if (dp[i] == -10) continue; if (i == 1) dp[1] = 1; if (dp[i-1]==-10 && dp[i-2]==-10) { cout << 0 << endl; return 0; } else if (dp[i-1] == -10) { dp[i] = dp[i-2]; } else if (dp[i-2] == -10) { dp[i] = dp[i-1]; } else dp[i] = (dp[i-1]+dp[i-2])%1000000007; } cout << dp[n] << endl; }
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0) #define AfterDecimal(n) cout << fixed << setprecision(n); #define ll long long int #define ld long double #define all(a) a.begin(), a.end() #define pii pair<int, int> #define pll pair<ll, ll> #define bits(x) __builtin_popcount(x) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #ifdef LOCAL #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__) template<typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << "# "<< name << " = " << arg1 << '\n'; } template<typename Arg1, typename... Args> void __f(const char* names, Arg1 && arg1, Args &&... args){ const char* comma = strchr(names + 1 ,','); cout << "# "; cout.write(names, comma - names)<< " = " << arg1 << " | "; __f(comma + 1, args...); } #else #define debug(...) 36 #endif std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int ri(int a, int b) { return uniform_int_distribution<int>(a, b)(rng); } ll power(ll x, ll y, ll p){ ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } const ll INF = (ll)(8e18); const ll MOD = (ll)(1e9 + 7); const ll HMOD = (ll)4222234727; const ll Hashprime = (ll)31; const int maxn = 100100; int32_t main(){ IOS; #ifndef ONLINE_JUDGE #endif int T = 1; while(T--){ string s,t; cin >> s >> t; int n = int(s.length()); int m = int(t.length()); int ans = m; for(int i = 0; i < n - m + 1; i++){ int val = 0; for(int j = 0; j < m; j++){ if(s[j + i] != t[j]) val += 1; } ans = min(ans, val); } cout << ans << '\n'; } #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif }
0
74,360,630
#include <bits/stdc++.h> 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(b == 0) return a; return gcd(b, a % b); } using Graph = vector<vector<int>>; ll calc(ll a, ll b, ll p){ if(b == 0) return 1; else if(b%2 == 0){ ll d = calc(a,b/2,p); return (d*d)%p; } else if(b%2 == 1){ return (a * calc(a,b-1,p))%p; } } typedef pair<int,int> P; bool is_prime(int n){ if(n == 1) return false; for(int i = 2;i*i <= n;i++){ if(n%i == 0) return false; } return true; } int factorial(int a){ int res = 1; while(a){ res *= a; a--; } return res; } int rec(int m,int n,int N,int r){ if(N == 0) return 0; int k = N/m * n; r = N%m; int res = N + k; while(1){ k = k/m * n; res += k; r += k%m; if(k < m){ k += r; res += rec(m,n,k,r); } } } int main(){ int N,K; cin >> N >> K; if(K == 1) cout << 0 << endl; else if(N == K) cout << 0 << endl; else if(N > K) cout << N - K << endl; }
#include <bits/stdc++.h> #define pi 3.14159 using namespace std; typedef long long LL; const LL MOD = 1e9 + 7; const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f; #define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0); int main() { LL n,array1[2*N],i,T,counter=0,flag=0; cin>>n>>T; for(i=0;i<n;++i){ cin>>array1[i]; } LL works=array1[0]+T,begininig=0; for(i=1;i<n;++i){ if(array1[i]<=works){ works=array1[i]+T; } else{ counter+=works-begininig; works=array1[i]+T; begininig=array1[i]; } } printf("%lld",counter+works-begininig); return 0; }
0
58,609,838
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); } sort(vec.begin(), vec.end()); int a = vec.at(0); int b = vec.at(N-1); vector<int> P(b-a+1,0); int y = 0; for (int i = a; i < b+1; i++) { int x = 0; for (int j = 0; j < N; j++) { int t = (vec.at(j) - i) * (vec.at(j) - i); x += t; } P.at(y) = x; y ++; } sort(P.begin(), P.end()); cout << P.at(0) << endl; }
#include <bits/stdc++.h> using namespace std; bool cmp(long long a, long long b) { return a>b; } int main() { int n,m; cin>>n>>m; long long mx = -(99999999); long long arr[9999][3]; for(int i=1; i<=n; i++){ for(int j=0; j<3; j++)cin>>arr[i][j]; } for(int i=0; i<8; i++){ vector<long long>v; for(int j=1; j<=n; j++){ long long sum=0; for(int k=0; k<3; k++){ if((i/(1<<k))%2==0)sum+=arr[j][k]; else sum-=arr[j][k]; } v.push_back(sum); } sort(v.begin(),v.end(),cmp); long long ans=0; for(int i=0; i<m; i++){ ans+=v[i]; } mx = max(mx, ans); } cout<<mx<<endl; }
0
977,187
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { vector<int> same; string S, T; cin >> S >> T; int end = S.length() - T.length(); for (int i = 0; i <= end; ++i) { int counter = 0; for (int j = 0; j < T.length(); ++j) { if (S[i + j] == T[j]) ++counter; } same.push_back(counter); if (counter == T.length()) break; } cout << T.length() - *max_element(same.begin(), same.end()) << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <unordered_map> #include <vector> #include <string.h> #include <set> using namespace std; #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template<class T> void printvec(const vector<T>& v) { for (auto x : v) { cout << x << " "; } cout << endl; } template<class T> void printtree(const vector< vector<T> >& tree) { for (long long i = 0; i < tree.size(); ++i) { cout << i + 1 << ": "; printvec(tree[i]); } } template<class T, class U> void printmap(const map<T, U>& mp) { for (auto x : mp) { cout << x.first << "=>" << x.second << endl; } } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for(ll i = 0; i < n; ++i) #define all(s) s.begin(), s.end() #define fr first #define sc second #define mp make_pair #define pb push_back typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> triple; typedef double D; const ll INF = 1e9; const ll MOD = 1000000007; int main(int argc, char** argv) { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); ll m; cin >> m; ll n = 0; ll s = 0; rep(i, m) { ll d, c; cin >> d >> c; s += d * c; n += c; } ll initial = 9*n + s; ll last = 9 + ((s-1)%9) + 1; cout << (initial-last)/9 << endl; }
0
13,755,137
#include <bits/stdc++.h> #define mod 1000000007 #define INF LLONG_MAX #define ll long long #define ln cout<<endl #define Yes cout<<"Yes"<<endl #define NO cout<<"NO"<<endl #define YES cout<<"YES"<<endl #define No cout<<"No"<<endl #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using namespace std; ll dx[4]={1,0,-1,0}; ll dy[4]={0,1,0,-1}; typedef pair<ll,ll> P; bool comp(pair<ll, ll> a, pair<ll , ll> b) { if(a.first != b.first){ return a.first < b.first; } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll maxi=0,f=0,sum=0,mini=INF; string str,str1,str2; ll i; double h; ll n,x,m; ll a,b,d,c,k; cin>>n>>k; vector<P> p(n); rep(i,n){ cin>>a>>b; p[i]=P(a,b); } sort(all(p),comp); rep(i,n){ sum+=p[i].second; if(sum>=k){ cout<<p[i].first<<endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long INF = 1000000000000000000; int main(){ int N; cin >> N; vector<long long> a(N); for (int i = 0; i < N; i++){ cin >> a[i]; } long long tv = -100; long long fv = INF; while (fv - tv > 1){ long long mid = (tv + fv) / 2; vector<long long> b(N); for (int i = 0; i < N; i++){ b[i] = a[i] + mid; } long long cnt = 0; for (int i = 0; i < N; i++){ cnt += b[i] / (N + 1) - 1; } if (cnt >= mid){ tv = mid; } else { fv = mid; } } long long ans = tv; long long curr = tv; while (1){ vector<long long> b(N); for (int i = 0; i < N; i++){ b[i] = a[i] + curr; } long long cnt = 0; for (int i = 0; i < N; i++){ cnt += b[i] / (N + 1); } ans = curr - 1; if (cnt < curr && curr > 0 || curr == tv + 1000000){ break; } curr++; } cout << ans << endl; }
0
87,877,277
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll N,M;cin >> N >> M; vector<ll> A(N,0); vector<ll> B(N+1,0); for(int i=0;i<N;i++){ cin >> A[i]; B[i+1] = (A[i]+B[i])%M; } sort(B.begin(),B.end()); ll sum = 0; ll i = 0; for(int j=0;j<=N;j++){ if(j==N){ ll x = j - i + 1; sum += x*(x-1)/2; cout << sum << endl; return 0; } if(B[j]!=B[j+1]){ ll x = j - i + 1; sum += x*(x-1)/2; i = j + 1; } } }
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <queue> #include <utility> #include <map> #include <bitset> #include <numeric> #define ll long long using namespace std; using p = pair<ll, ll>; ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; ll comb(ll n, ll r){ ll child = 1, mother = 1; if(r<n/2){ for(ll i = 1; i <= r; i++){ ll a = n-i+1, b = i; child = child * a; mother = mother * b; if(child%mother==0){ child /= mother; mother = 1; } } } else if(r>=n/2){ for(ll i = 1; i <= n-r; i++){ ll a = n-i+1, b = i; child = child * a; mother = mother * b; if(child%mother==0){ child /= mother; mother = 1; } } } ll ans = child / mother; return ans; } int main(void){ ll n, p; cin >> n >> p; ll a = 0, b = 0; for(ll i = 0; i < n; i++){ ll c; cin >> c; if(c%2==0) a++; else b++; } ll ans = 0; if(p==1){ for(ll i = 1; i <= b; i+=2){ for(ll j = 0; j <= a; j++){ ans+=comb(b, i)*comb(a, j); } } } if(p==0){ for(ll i = 0; i <= a; i++) for(ll j = 0; j <= b; j+=2) ans+=comb(a, i)*comb(b, j); } cout << ans << endl; return 0; }
0
26,574,719
#include <iostream> int s,e;int main(){while((s+=(e=e%9+1)<2)<10)std::cout<<s<<'x'<<e<<'='<<s*e<<'\n';0;}
#include <bits/stdc++.h> using namespace std; const string YES = "POSSIBLE"; const string NO = "IMPOSSIBLE"; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } void solve(long long N, long long K, std::vector<long long> A) { long long gc = 0, ma = 0; for (int i = 0; i < N; i++) gc = gcd(A[i], gc), ma = max(ma, A[i]); if (K % gc) { cout << NO << endl; return; } if (K > ma) { cout << NO << endl; return; } cout << YES << endl; } int main() { long long N; scanf("%lld", &N); long long K; scanf("%lld", &K); std::vector<long long> A(N); for (int i = 0; i < N; i++) { scanf("%lld", &A[i]); } solve(N, K, std::move(A)); return 0; }
0
43,452,400
#pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << "\n"; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<ll,ll> Pll; typedef pair<int,int> Pin; ll INF = 1e16; int inf = 1e9; ll MOD = 1e9+7; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); string s; cin >> s; vector<string> p = {"dream", "dreamer", "erase", "eraser"}; REP(i, p.size()) reverse(ALL(p[i])); reverse(ALL(s)); int i = 0; while(i < s.size()) { int prev = i; REP(j, p.size()) { bool f = true; REP(k, p[j].size()) { f &= s[i + k] == p[j][k]; if (!f) break; } if (f) { i += p[j].size(); break; } } if (i == prev) { print("NO"); return 0; } } print("YES"); }
#include <bits/stdc++.h> using namespace std; int main() { int N ; cin >> N ; string b[N]; for ( int i=0 ; i<N ; i++){ cin >> b[i] ; } int M ; cin >> M ; string r[M]; for ( int i=0 ; i<M ; i++){ cin >> r[i] ; } int ben[N] ; int mx=0 ; for (int i=0 ; i <N ; i++){ ben[i]=0; } int count[N]; for (int i=0 ; i <N ; i++){ count[i]=0; } for (int i=0 ; i<N ; i++){ if (b[i] == "A"){ continue ; }else if (b[i] !="A"){ for (int j=i ; j<N ; j++){ if (b[i]==b[j]){ count[i]++; b[j] == "A"; } } for (int j=0 ; j<M ; j++){ if (b[i]==r[j]){ count[i]--; } } if (count[i] > 0){ ben[i]+=count[i]; } } mx = max(mx,ben[i]) ; } cout << mx << endl; }
0
46,492,419
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define repn(i,n) for(int i=1;i<=n;i++) #define LL long long #define pii pair <LL,LL> #define fi first #define se second #define pb push_back #define mpr make_pair using namespace std; const LL MOD=1e9+7; LL n,x,y,ans=0; int main() { cin>>n; repn(i,n) ans+=(LL)(1+i)*(LL)i/2; rep(i,n-1) { scanf("%lld%lld",&x,&y); if(x>y) swap(x,y); ans-=x*(n-y+1); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define pb push_back #define ll long long #define mem(x, val) memset(x, val, sizeof(x)) #define mk make_pair #define f(i,n) for(i = 0; i < n; i++) #define f1(i,n) for(i = 1; i <= n; i++) #define all(a) a.begin(),a.end() #define upp(v,val) upper_bound(v.begin(), v.end(), val) #define lower(v,val) lower_bound(v.begin(), v.end(), val) #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) #define dbg(x) cout << #x << " = " << x << endl #define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl #define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl #define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl #define jaldi_chal() ios_base::sync_with_stdio(false); cin.tie(NULL); #define S second #define F first #define fm(it,m) for(it = m.begin(); it != m.end(); it++) #define ct_set(n) __builtin_popcount(n) #define INF 0x3f3f3f3f #define endl '\n' #define mod 1000000007 #define PI 3.14159265 #define precision cout << setprecision(15) #define print_arr(a,n) for(int i = 0; i < n; i++) cout << a[i] << " "; #define print_vec(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ll gcd(ll a,ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { ll g = gcd(a, b); ll ans = (a * b) / g; return ans; } ll add(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; } ll sub(ll a, ll b) { a -= b; if (a < 0) { a += mod; } return a; } ll mul(ll a, ll b) { return (a * b) % mod; } vector <ll> primes; bool prime[10005]; void seive() { mem(prime, 1); prime[0] = 0; prime[1] = 0; for(ll i = 2; i <= 10000; i++) { if(prime[i] == 1) { for(ll j = i * i; j <= 10000; j += i) prime[j] = 0; } } } ll power(ll a, ll b) { ll ans = 1; while(b > 0) { if(b % 2 == 1) ans = (ans % mod * a % mod) % mod; a = (a * a) % mod; b = b / 2; } return ans; } template <typename T> std::string NumberToString ( T Number ) { std::ostringstream ss; ss << Number; return ss.str(); } string num_to_bits(ll n) { string ans = ""; while(n) { ans += (n % 2) + '0'; n /= 2; } reverse(all(ans)); return ans; } ll bits_to_num(string s) { ll ans = 0; for(ll i = 0; i < s.size(); i++) { ll x = s.size() - i - 1; ll val = pow(2LL, x); if(s[i] == '1') { ans = ans + val; } } return ans; } ll gcdExtended(ll a, ll b, ll *x, ll *y); ll modInverse(ll b, ll m) { ll x, y; ll g = gcdExtended(b, m, &x, &y); if (g != 1) return -1; return (x % m + m) % m; } ll modDivide(ll a, ll b, ll m) { a = a % m; ll inv = modInverse(b, m); return (inv * a) % m; } ll gcdExtended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; ll gcd = gcdExtended(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } ll fact[2005]; void factorials() { fact[0] = 1; for(ll i = 1; i <= 2002; i++) { fact[i] = (i * fact[i - 1]) % mod; } } ll nCr(ll n, ll r) { if(r > n) { return 0; } ll result = fact[n]; result = modDivide(result, fact[r], mod); return modDivide(result, fact[n - r], mod); } ll n, m; ll parent[100005]; ll find(ll i) { if(parent[i] == i) { return i; } else { return parent[i] = find(parent[i]); } } void Union(ll x, ll y) { ll px = find(x); ll py = find(y); parent[px] = py; } void solve() { cin >> n >> m; ll a[n + 1], i, j; for(i = 1; i <= n; i++) { cin >> a[i]; parent[i] = i; } for(ll i = 1; i <= m; i++) { ll x, y; cin >> x >> y; Union(x, y); } map <ll, vector <ll> > mp; for(i = 1; i <= n; i++) { parent[i] = find(i); if(parent[i] == i) { mp[i].pb(i); } else { mp[parent[i]].pb(i); } } ll ans = 0; for(auto it: mp) { vector <ll> indexes = it.S; vector <ll> values; for(i = 0; i < indexes.size(); i++) { values.pb(a[indexes[i]]); } map <ll, ll> curr; for(auto x: indexes) { curr[x]++; } for(auto x: values) { curr[x]++; } for(auto it: curr) { if(it.S == 2) { ans++; } } } cout << ans; } int main() { jaldi_chal() bool codechef = 0; ll t = 1; if(codechef) { cin >> t; } for(ll i = 1; i <= t; i++) { solve(); } return 0; }
0
49,068,676
#include <bits/stdc++.h> using namespace std; using lint = long long; using P = pair<int, int>; using vec = vector<lint>; using mat = vector<vector<int>>; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define endl "\n" constexpr int MOD = 1000000007; const int INF = 1 << 30; int main() { int n, k; cin >> n >> k; vec a(n); rep(i, n) cin >> a[i]; vec s(n+1); rep(i, n) s[i+1] = (s[i] + a[i]); vec t(n+1); rep(i, n+1) t[i] = (s[i] - i) % k; rep(i, n+1) t[i] = ((t[i] % k) + k) % k; lint res = 0; map<int, int> mp; queue<int> que; rep(i, n+1) { res += mp[t[i]]; mp[t[i]]++; que.push(t[i]); if (que.size() >= k) { mp[que.front()]--; que.pop(); } } cout << res << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; #define pii pair<int, int> #define pll pair<long long, long long> #define fi first #define se second #define mp make_pair #define pb push_back #define DEBUG 1 #define cerr if (DEBUG) cerr #define test cerr << "hi\n"; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rand(l, r) uniform_int_distribution<long long>(l, r)(rng) using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST; #define INF 0x3f3f3f3f3f3f3f3f #define MAXN 300005 #define MOD 1000000007LL void solve() { long long ans = 0; int n, m; cin >> n >> m; priority_queue<int> q; for (int i = 0, x; i < n; i++) { cin >> x; q.push(x); } for (int iter = 0; iter < m; iter++) { int x = q.top(); q.pop(); x /= 2; q.push(x); } while (q.size()) { ans += q.top(); q.pop(); } cout << ans << '\n'; } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); auto start_time = clock(); #endif ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; for (int no = 1; no <= t; no++) { solve(); } #ifdef LOCAL cerr << "TIME ELAPSED: " << double(clock() - start_time) / CLOCKS_PER_SEC << '\n'; #endif }
0
50,205,674
#include<bits/stdc++.h> using namespace std; int main(){ int n; int h[100005]; int dp[100005] = {}; cin>>n; for(int i=0;i<n;i++){ cin>>h[i]; } for(int i=1;i<n;i++){ if(i==1){ dp[i] = abs(h[i]-h[i-1]); } else{ dp[i] = min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]); } } cout<<dp[n-1]<<'\n'; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N; cin >> N; vector<int> C(N - 1); vector<int> S(N - 1); vector<int> F(N - 1); for (int i = 0; i < N - 1; i++) { cin >> C[i] >> S[i] >> F[i]; } for (int i = 0; i < N - 1; i++) { int time = 0; for (int j = i; j < N - 1; j++) { if (time < S[j]) { time = S[j]; } else if ((time - S[j]) % F[j] != 0) { time += F[j] - (time - S[j]) % F[j]; } time += C[j]; } cout << time << endl; } cout << 0 << endl; return 0; }
0
14,050,251
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { double w , h, x, y; cin>>w>>h>>x>>y; double ans =( w * h )/2; cout.precision(15); cout<<ans<<" "; if( w/2 == x && h/2 == y ) { cout<<1; } else cout<<0; }
#include<bits/stdc++.h> #define godspeed ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0); #define limit 1000000000000000000 #define mod 1000000007 #define llu long long unsigned #define ll long long #define ld long double #define fi first #define se second #define mp make_pair #define pb push_back #define rep(i,n) for(ll i=0; i<n; i++) #define rep1(i,a,b) for(ll i=a; i<b; i++) #define repV(i,n) for(ll i=0; i<v.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 llu i,j,n,k,x,mult=1; cin>>n; bool zero=0; vector<llu>v(n); for(i=0;i<n;i++) { cin>>v[i]; if(v[i]==0) zero=1; } if(zero) return cout<<0<<endl,0; for(i=0;i<n;i++) { if(limit/mult>=v[i]) { mult*=v[i]; } else return cout<<"-1"<<endl,0; } cout<<mult<<endl; return 0; }
0
51,161,000
#include <bits/stdc++.h> using namespace std; long long A[100005]; int K; bool doesItWork(long long num){ long long temp = num; for(int i = 0; i < K; i ++){ temp = temp/A[i]*A[i]; } return temp == 2; } int main(){ scanf("%d", &K); for(int i = 0; i < K; i ++){ scanf("%lld", &A[i]); } long long num = 2; for(int i = K-1; i >= 0; i --){ long long temp = 1+(num-1)/A[i]; num = temp*A[i]; } long long num2 = 2; for(int i = K-1; i >= 0; i --){ long long temp = 1+(num2-1)/A[i]; num2 = (temp+1)*A[i]-1; } if(doesItWork(num)){ printf("%lld ", num); long long lo = num; long long hi = 1LL << 61; while(lo < hi){ long long mid = (lo+hi+1)/2; if(doesItWork(mid)){ lo = mid; }else{ hi = mid-1; } } printf("%lld", lo); }else{ printf("-1"); } return 0; }
#include <algorithm> #include <cstdio> #include <cmath> #include <iostream> #include <queue> #include <string> #include <set> #include <vector> using namespace std; typedef long long ll; typedef pair<double, double> P; int n; double cos60 = cos(60.0 / 180.0 * M_PI); double sin60 = sin(60.0 / 180.0 * M_PI); void koch(int n, P p1, P p2) { if ( n == 0 ) { printf("%lf %lf\n", p1.first, p1.second); } else { P d = make_pair(p2.first - p1.first, p2.second - p1.second); P e = make_pair(d.first / 3.0, d.second / 3.0); P s = make_pair(p1.first + e.first, p1.second + e.second); P r = make_pair(cos60 * e.first - sin60 * e.second, sin60 * e.first + cos60 * e.second); P t = make_pair(s.first + r.first, s.second + r.second); P u = make_pair(s.first + e.first, s.second + e.second); koch(n - 1, p1, s); koch(n - 1, s, t); koch(n - 1, t, u); koch(n - 1, u, p2); } return; } int main() { P l = make_pair(0.0, 0.0); P r = make_pair(100.0, 0.0); scanf("%d", &n); koch(n, l, r); printf("%lf %lf\n", r.first, r.second); return 0; }
0
34,829,152
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using pll = pair < ll, ll >; #ifndef ONLINE_JUDGE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template < typename Arg1 > void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std :: endl; } template < typename Arg1, typename... Args > void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif #define pb push_back #define mp make_pair #define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0) const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10; int main(){ ll s, w; cin >> s >> w; if(w >= s) { cout << "unsafe\n"; } else { cout << "safe\n"; } return 0; }
#include <unordered_set> #include <unordered_map> #include <algorithm> #include <iostream> #include <iterator> #include <numeric> #include <sstream> #include <fstream> #include <cassert> #include <climits> #include <cstdlib> #include <cstring> #include <string> #include <cstdio> #include <vector> #include <bitset> #include <cmath> #include <queue> #include <tuple> #include <deque> #include <stack> #include <list> #include <map> #include <set> using namespace std; using ll=long long; typedef long long ll; typedef pair<int,int> ii; typedef pair<string,int> si; typedef pair<int,ii> iii; typedef vector <si> vsi; typedef vector <ii> vii; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <vll> vl2d; typedef vector <vi> vi2d; typedef vector <char> vc; typedef vector <bool> vb; typedef vector <string> vs; typedef map <string,vs> msvs; typedef map <string,int> msi; typedef map <char,int> mci; typedef map <int,int> mii; typedef map <long,long> ml; typedef map <string,string> mss; #define rep(i,a,n) for (ll i=a;i<n;i++) #define per(i,a,n) for (ll i=n-1;i>=a;i--) #define foreach(x,arr) for(auto& x:arr) #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair #define endl '\n' #define INF 1000000000LL #define MOD 1000000007 #define deb(x) cout<<#x<<": "<<x<<endl; #define printArray(arr) for(auto x: arr) { cout<<x<<"\n"; } #define printMatrix(mat) for(auto x: mat) { cout<<" "; printArray(x); cout<<endl; } #define printMap(mmap) for(auto p: mmap) { cout<< p.first<<": "<<p.second<<endl; } #define MIN(a,b) ((a)<(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b)) #define forch(ch,str) for(char& c : str) #define FILL(a,b) memset(a,b,sizeof(a)) #define append push_back #define nil nullptr #define guard(_condition) if (bool(_condition)){} #define count size() #define let const auto #define var auto #define startsWith(str) rfind(str, 0) #define prq priority_queue #define tostr(argument) to_string(argument) #define alphabet "abcdefghijklmnopqrstuvwxyz" void join(const vector<string>& v, char c, string& s) { s.clear(); for (vector<string>::const_iterator p = v.begin(); p != v.end(); ++p) { s += *p; if (p != v.end() - 1) s += c; } } unordered_map<int, vector<int>> graph; int n; ll mod = 1e9 + 7; pair<ll, ll> dfs(int v, int p) { ll b = 1, w = 1; foreach(n, graph[v]) { guard(n != p) else { continue; } let child = dfs(n, v); w = ((child.first + child.second) * w)%mod; b = (child.first * b)%mod; } return pair<ll,ll>(w, b); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; rep(i,0,n-1) { int s,d; cin>>s>>d; graph[s].push_back(d); graph[d].push_back(s); } var res = dfs(1,0); cout<<(res.first + res.second)%mod<<endl; return 0; }
0
19,418,872
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll, vl> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); ++i) #define rep2(i, n) for(ll i = 1; i <= ll(n); ++i) #define all(v) (v).begin(), (v).end() bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;} bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; const ll MAX = 1e9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); string S; cin >> S; ll w; cin >> w; for(ll i=0; w*i<=S.size()-1; i++) cout << S[w*i]; cout << newl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, c) for (int i = 0; i < (int)c; i++) int main() { int n; scanf("%d", &n); vector<int> a(n); rep(i, n) scanf("%d", &a[i]); a.insert(a.begin(), 0); a.insert(a.end(), 0); int cost = 0; rep(i, n + 1) { cost += abs(a[i] - a[i + 1]); } for(int i = 1; i < n + 1; i++) { int ans = 0; ans = cost + abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]); printf("%d\n", ans); } return 0; }
0
17,817,939
#include <algorithm> #include <iostream> #include <vector> #include <numeric> #include <algorithm> using namespace std; using ll = long long; int main() { ll N, SA{}, SB{}, SD, ans{}; cin >> N; vector<ll> A(N), B(N), D(N); for(ll &a: A) cin >> a, SA += a; for(ll &b: B) cin >> b, SB += b; for (int i = 0; i != N; ++i) { D[i] = A[i] - B[i]; } if (SA < SB) ans = -1; else { sort(begin(D),end(D)); int l = lower_bound(begin(D), end(D), 0) - begin(D); SD = accumulate(begin(D), begin(D) + l, 0ll); ans = l; for (int i = 1; N-i >= l; ++i) { if (SD>=0) break; ++ans; SD += D[N-i]; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define mp make_pair #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++) template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1<<30; const ll LINF = 1LL<<58; const int mod = 1000000007; map<ll, int> prime_factor(ll n) { map<ll, int> ret; for (int i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } int main() { int n; cin >> n; map<int, int> mp; for (int i = 1; i <= n; i++) { auto m = prime_factor(i); for (int j = 2; j < 101; j++) mp[j] += m[j]; } int p75 = 0, p25 = 0, p15 = 0, p5 = 0, p3 = 0; for (int i = 0; i < 100; i++) { if(mp[i] >= 74) p75++; if(mp[i] >= 24) p25++; if(mp[i] >= 14) p15++; if(mp[i] >= 4) p5++; if(mp[i] >= 2) p3++; } cout << p75 + p25 * (p3 - 1) + p15 * (p5 - 1) + p5 * (p5 - 1) * (p3 - 2) / 2 << endl; return 0; }
0
3,156,526
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c,d,e,f,g,h,i; cin>>a>>b>>c>>d>>e>>f>>g>>h>>i; int N; cin>>N; vector<int> aa(N); for(int j=0;j<N;j++){ cin>>aa.at(j); } for(int j=0;j<N;j++){ if(aa.at(j)==a){ a=0; } if(aa.at(j)==b){ b=0; } if(aa.at(j)==c){ c=0; } if(aa.at(j)==d){ d=0; } if(aa.at(j)==e){ e=0; } if(aa.at(j)==f){ f=0; } if(aa.at(j)==g){ g=0; } if(aa.at(j)==h){ h=0; } if(aa.at(j)==i){ i=0; } } int flag=0; if(a==0&&b==0&&c==0){ flag=1; } if(d==0&&e==0&&f==0){ flag=1; } if(g==0&&h==0&&i==0){ flag=1; } if(a==0&&d==0&&g==0){ flag=1; } if(b==0&&e==0&&h==0){ flag=1; } if(c==0&&f==0&&i==0){ flag=1; } if(a==0&&e==0&&i==0){ flag=1; } if(c==0&&e==0&&g==0){ flag=1; } if(flag==1){ cout<<"Yes"; }else{ cout<<"No"; } }
#ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wunused-result" #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <sstream> #include <numeric> #include <map> #include <set> #include <queue> #include <vector> using namespace std; typedef long long LL; static const LL INF = 1LL << 60; void solve(long long N, std::vector<long long> &a) { LL ans = 0; for (LL i = 0; i < N; ++i) { LL x = max(0LL, a[i] / (N + 1) - N); a[i] -= x * (N + 1); ans += x * (N + 1); } int index; while (index = max_element(a.begin(), a.end()) - a.begin(), a[index] >= N) { ++ans; for (LL i = 0; i < N; ++i) { a[i] += i == index ? -N : 1; } } cout << ans << endl; } int main() { long long N; std::cin >> N; std::vector<long long> a(N); for (int i = 0; i < N; i++) { std::cin >> a[i]; } solve(N, a); return 0; }
0
52,200,423
#include <bits/stdc++.h> const int N = 100005; int n, l, q, x[N], p[N][17]; int main() { std::ios::sync_with_stdio(0), std::cin.tie(0); std::cin >> n; for (int i = 0; i < n; ++i) std::cin >> x[i]; std::cin >> l >> q; for (int i = 0, j = 0; i < n; p[i++][0] = j) while (j + 1 < n && x[j + 1] - x[i] <= l) ++j; for (int i = 1; i < 17; ++i) for (int j = 0; j < n; ++j) p[j][i] = p[p[j][i - 1]][i - 1]; while (q--) { int l, r, ans = 1; std::cin >> l >> r, --l, --r; if (l > r) std::swap(l, r); for (int i = 16; ~i; --i) if (p[l][i] < r) ans += 1 << i, l = p[l][i]; std::cout << ans << '\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr ll ZERO = 0; constexpr int Inf = 1000000000; constexpr ll INF= 1e18; constexpr ll MOD = 1000000007; const double PI = 3.1415926535897; typedef pair<ll,ll> P; int N; string S; string k(int a,int b) { vector<int> ret(N + 2); ret.at(0) = a; ret.at(1) = b; for(int i = 1;i < N + 1;i++) { if(ret.at(i) == 1) { if(S.at(i - 1) == 'o') { ret.at(i + 1) = ret.at(i - 1); } else { if(ret.at(i - 1) == 1) { ret.at(i + 1) = 2; } else if(ret.at(i - 1) == 2) { ret.at(i + 1) = 1; } } } else { if(S.at(i - 1) == 'x') { ret.at(i + 1) = ret.at(i - 1); } else { if(ret.at(i - 1) == 1) { ret.at(i + 1) = 2; } else if(ret.at(i - 1) == 2) { ret.at(i + 1) = 1; } } } } if(ret.at(0) != ret.at(N) || ret.at(1) != ret.at(N + 1)) { return "-1"; } else { string ret2; for(int i = 1;i < N + 1;i++) { if(ret.at(i) == 1) { ret2 += 'S'; } else { ret2 += 'W'; } } return ret2; } } int main() { cin >> N; cin >> S; if(k(1,1) != "-1") { cout << k(1,1) << endl; } else if(k(1,2) != "-1") { cout << k(1,2) << endl; } else if(k(2,1) != "-1") { cout << k(2,1) << endl; } else if(k(2,2) != "-1") { cout << k(2,2) << endl; } else { cout << -1 << endl; } }
0
90,520,874
#include <iostream> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, i; cin >> n; int f[n]; f[0] = 1, f[1] = 1; for (i = 2; i <= n; ++i) { f[i] = f[i - 1] + f[i - 2]; } cout << f[n] << '\n'; return 0; }
#include <stdio.h> int main(){ int array[10][10]; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ scanf("%d", &array[i][j]); } } int brpKali; scanf("%d", &brpKali); int percobaan[100]; for(int k=0;k<brpKali;k++){ scanf("%d", &percobaan[k]); } for(int l=0;l<brpKali;l++){ for(int m=0;m<3;m++){ for(int n=0;n<3;n++){ if(percobaan[l]==array[m][n]){ array[m][n]=0; } } } } if(array[0][0]+array[1][1]+array[2][2]==0){ printf("Yes\n"); } else if(array[0][2]+array[1][1]+array[2][0]==0){ printf("Yes\n"); } else if(array[0][0]+array[0][1]+array[0][2]==0){ printf("Yes\n"); } else if(array[1][0]+array[1][1]+array[1][2]==0){ printf("Yes\n"); } else if(array[2][0]+array[2][1]+array[2][2]==0){ printf("Yes\n"); } else if(array[0][0]+array[1][0]+array[2][0]==0){ printf("Yes\n"); } else if(array[0][1]+array[1][1]+array[2][1]==0){ printf("Yes\n"); } else if(array[0][2]+array[1][2]+array[2][2]==0){ printf("Yes\n"); } else{ printf("No\n"); } return 0; }
0
65,749,668
#include <bits/stdc++.h> using namespace std; struct D{ int size; vector<int> num; D(){ size = 6; num = vector<int>{1,2,3,4,5,6}; } D(vector<int> _num){ size = _num.size(); num = _num; } void change(vector<int> idx){ auto ret(num); for(int i = 0; i < size; i++){ ret[i] = num[idx[i]]; } swap(ret,num); } void roll(char c){ vector<int> idx{0,1,2,3,4,5}; switch(c){ case 'S': idx = vector<int>{4,0,2,3,5,1}; break; case 'N': idx = vector<int>{1,5,2,3,0,4}; break; case 'W': idx = vector<int>{2,1,5,0,4,3}; break; case 'E': idx = vector<int>{3,1,0,5,4,2}; break; } change(idx); } void roll(int top, int front){ int topidx,frontidx; for(int i = 0; i < size; i++){ if(num[i] == top){ topidx = i; } } switch(topidx){ case 1: roll('N'); break; case 2: roll('W'); break; case 3: roll('E'); break; case 4: roll('S'); break; case 5: roll('S'); roll('S'); break; } vector<int> idx = {0,1,2,3,4,5}; for(int i = 0; i < size; i++){ if(num[i] == front){ frontidx = i; } } switch(frontidx){ case 1: break; case 2: idx = vector<int>{0,2,4,1,3,5}; break; case 3: idx = vector<int>{0,3,1,4,2,5}; break; case 4: idx = vector<int>{0,4,3,2,1,5}; break; } change(idx); } }; int main(){ vector<int> a(6); for(auto &e : a)cin >> e; D dice(a); int q; cin >> q; for(int i = 0; i < q; i++){ D temp = dice; int top,front; cin >> top >> front; temp.roll(top,front); cout << temp.num[2] << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define reps(i, f, n) for (ll i = (f); i < (n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define repv(v) for (auto it = (v).begin(); it != (v).end(); it++) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define pb push_back #define INIT \ cin.tie(0); \ ios::sync_with_stdio(false); template <class T> inline bool chmax(T& a, T b) { return a = (a < b) ? b : a; } template <class T> inline bool chmin(T& a, T b) { return a = (a > b) ? b : a; } ll const INF = 1LL << 60; ll const MOD = 1000000007; bool isOK(ll N, ll M, ll V, ll P, vector<ll>& A, ll x) { if (x < P) return true; ll now = A[x] + M; if (A[P - 1] > now) return false; ll score = 0; score += (P - 1) * M; score += (N - x) * M; reps(i, P - 1, x) { score += min(M, max(0LL, now - A[i])); } return score >= M * V; } int main() { INIT; ll N, M, V, P; cin >> N >> M >> V >> P; vector<ll> A(N); rep(i, N) cin >> A[i]; sort(ALL(A), greater<ll>()); ll ok = -1; ll ng = N; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (isOK(N, M, V, P, A, mid)) ok = mid; else ng = mid; } cout << ok + 1 << endl; return 0; }
0
11,989,773
#include<iostream> #include<string> using namespace std; int main() { string s,t; cin>>s>>t; string ans=t+s; cout<<ans; }
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; int main(void) { int64_t N, D, A; cin >> N >> D >> A; vector< pair<int64_t,int64_t> > monster(N); for(int i=0; i<N; i++) { cin >> monster[i].first >> monster[i].second; } sort(monster.begin(), monster.end()); int64_t ans = 0; int64_t damage = 0; queue< pair<int64_t,int64_t> > q; for(int i=0; i<N; i++) { while(!q.empty() && q.front().first < monster[i].first) { damage -= q.front().second; q.pop(); } monster[i].second -= damage; if(monster[i].second <= 0) continue; int64_t cnt = (monster[i].second + A-1) / A; ans += cnt; damage += cnt*A; q.emplace(monster[i].first + 2*D, cnt*A); } cout << ans << endl; return 0; }
0
29,776,343
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fi first #define se second #define pb push_back #define all(a) (a).begin(), (a).end() #define debug(a) cout << #a << " = " << a << " "; #define endl "\n" #define MOD (int) 1e9+7 #define inf (int) (1e18) void solve(){ ll n; cin>>n; string s; cin>>s; if(s.size()<=n){ cout<<s<<endl; } else { cout<<s.substr(0,n)<<"..."<<endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long int t=1; for(long int tt=1;tt<=t;tt++){ solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define bug printf("bug\n"); #define bug2(var) cout<<#var<<" "<<var<<endl; #define co(q) cout<<q<<endl; #define all(q) (q).begin(),(q).end() typedef long long int ll; typedef unsigned long long int ull; const int MOD = (int)1e9+7; const int MAX = 1e6; #define pi acos(-1) #define inf 1000000000000000LL #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int main() { FastRead int n; cin>>n; priority_queue<pair<int,int> >pq; set<int>s; map<int,int>mp; vector<int>v; for(int i=0;i<n;i++){ int a; cin>>a; mp[a]++; s.insert(a); v.push_back(a); } for(auto it:s){ pq.push({mp[it],it}); } while(!pq.empty()){ int cur=pq.top().first; int val=pq.top().second; if(cur==1) break; pq.pop(); if(cur>=3){ mp[val]-=3; mp[val]++; pq.push({mp[val],val}); } else if(cur==2){ mp[val]--; pq.push({mp[val],val}); cur=pq.top().first; val=pq.top().second; mp[val]--; pq.pop(); if(mp[val]) pq.push({mp[val],val}); } } cout<<pq.size()<<endl; return 0; }
0
33,771,378
#include <bits/stdc++.h> #define rep(i, a) for(int i = 0; i < a; i++) #define all(v) v.begin(), v.end() #define int long long using namespace std; signed main() { string s; cin >> s; rep(i, s.size()) { cout << s[i]; if(i == 3) cout << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> Pii; ll N, P; string S; ll pow_mod(ll n, ll k, ll mod) { if (k == 0) return 1; else if (k % 2 == 1) { return pow_mod(n, k-1, mod) * n % mod; } else { ll tmp = pow_mod(n, k/2, mod); return tmp * tmp % mod; } } int main() { cin >> N >> P >> S; if (P == 2 || P == 5) { ll ans = 0; for (int i = N-1; i >= 0; i--) { if ((S[i] - '0') % P == 0) { ans += (i+1); } } cout << ans << endl; } else { ll dp[N+1]; dp[0] = 0; dp[1] = (S[N-1] - '0') % P; for (ll i = 2; i <= N; i++) { dp[i] = (dp[i-1] + pow_mod(10, i-1, P) * (S[N-i] - '0') % P) % P; } map<ll, ll> mp; for (int i = 0; i <= N; i++) { mp[dp[i]]++; } ll ans = 0; for (auto itr = mp.begin(); itr != mp.end(); itr++) { ll val = itr->second; ans += val * (val-1) / 2; } cout << ans << endl; } return 0; }
0
9,973,137
#include <iostream> #include <cstring> #include <map> #include <iomanip> #include <algorithm> #include <cmath> #include <set> #include <vector> #include <queue> #include <list> #include <numeric> #include <stdio.h> #include <string> #include <cstdlib> #include <math.h> #include <stack> #include <climits> #include <bitset> #include <utility> using namespace std; typedef long long ll; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll gcd(ll x, ll y) { ll tmp = 0; if (x < y){ tmp=x; x=y; y=tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } ll lcm(ll x,ll y){ return x/gcd(x,y)*y; } const int MAX = 1e6+1; const ll MOD = 1e9+7; 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; } ll kaijo(ll k){ ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum%=1000000000+7; } return sum; } 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; } vector<bool> IsPrime; void sieve(size_t max){ if(max+1 > IsPrime.size()){ IsPrime.resize(max+1,true); } IsPrime[0] = false; IsPrime[1] = false; for(size_t i=2; i*i<=max; ++i) if(IsPrime[i]) for(size_t j=2; i*j<=max; ++j) IsPrime[i*j] = false; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) { } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; ll count(int n, int a){ ll bunshi = 1; for(int i = 0; i < a; i++){ bunshi*=(n-i); bunshi%=MOD; } ll bunbo = 1; for(int i = 1; i < a+1; i++){ bunbo*=i; bunbo%=MOD; } bunbo = modpow(bunbo,MOD-2,MOD); return (bunshi*bunbo)%MOD; } vector<ll> divisor(ll n) { vector<ll> ret; for(ll i = 1; i * i <= n; i++) { if(n % i == 0) { ret.push_back(i); if(i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } const ll INF = 1e18; int main(){ int d[10]; for(int i = 1; i <= 4; i++) d[i] = 0; for(int i = 0; i < 6; i++){ int z; cin>>z; d[z]++; } if(d[1]<=2&&d[2]<=2&&d[3]<=2&&d[4]<=2)cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[20]; int main() { int n,k; cin >> n >> k; ll ans = 1e18; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < (1 << n); i++) { int cnt = 0; for (int j = 0; j < n; j++) { if ((i >> j) & 1) cnt++; } if (cnt >= k) { ll h = 0; ll sum = 0; for (int j = 0; j < n; j++) { if ((i >> j) & 1) { if (a[j] <= h) { sum += h + 1 - a[j]; h++; } else { h = a[j]; } } else { if (a[j] > h) h = a[j]; } } ans = min(ans, sum); } } cout << ans << endl; return 0; }
0
70,206,801
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n; cin >> n; int result = (n - 2) * 180; cout << result << "\n"; return 0; }
#include<bits/stdc++.h> #define ALL(c) (c).begin(),(c).end() #define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i) using namespace std; #define int long long void solve(long long W, long long H, std::vector<long long> p, std::vector<long long> q){ vector<pair<int,int>> v; for(int i = 0; i < W; ++i) { v.push_back(make_pair(p[i], 0LL)); } for(int j = 0; j < H; ++j) { v.push_back(make_pair(q[j], 1LL)); } sort(ALL(v)); int res = 0; int a = W + 1, b = H + 1; for(int i = 0; i < v.size(); ++i) { if (v[i].second == 0) { res += v[i].first * b; a--; } else { res += v[i].first * a; b--; } } cout << res << endl; } signed main(){ long long W; scanf("%lld",&W); long long H; scanf("%lld",&H); std::vector<long long> p(W-1-0+1); for(int i = 0 ; i < W-1-0+1 ; i++){ scanf("%lld",&p[i]); } std::vector<long long> q(H-1-0+1); for(int i = 0 ; i < H-1-0+1 ; i++){ scanf("%lld",&q[i]); } solve(W, H, std::move(p), std::move(q)); return 0; }
0
45,215,449
#include <iostream> #include <vector> using namespace std; const long long INF = 1e18; vector<pair<long long, long long>> divisor_pair(long long n) { vector<pair<long long, long long>> v; for (long long i = 1; i * i <= n; ++i) { if (n % i == 0) v.emplace_back(i, n/i); } return v; } int digit(long long x) { int res = 0; while (x > 0) x /= 10, res++; return res; } int main() { long long n; cin >> n; auto d = divisor_pair(n); long long ans = INF; for (auto e : d) { long long now = max(digit(e.first), digit(e.second)); ans = min(ans, now); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } vector<int> dp(n, -1); function<int(int)> calc_dp = [&] (int i) { if (dp[i] != -1) { return dp[i]; } if (i <= 0) { return 0; } else if (i == 1) { dp[i] = abs(v[i] - v[i-1]); return dp[i]; } int min_cost = 1e9; for (int m = 0; m < k; ++m) { if (i-1-m < 0) break; int cost = abs(v[i] - v[i-1-m]) + calc_dp(i-1-m); min_cost = min(cost, min_cost); } dp[i] = min_cost; return dp[i]; }; cout << calc_dp(n-1) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; for (int i = 0; i < t; ++i) { solve(); } return 0; }
0
9,261,638
#include <stdio.h> #include <string.h> int main(){ char S [30]; char T [30]; char N [30]; int a, b; scanf("%s %s", &S, &T); scanf("%d %d", &a, &b); scanf("%s", &N); if (strcmp(S, N)==0) { printf("%d %d", a-1,b); } else if (strcmp(T,N)==0) { printf("%d %d", a,b-1); } return 0; }
#include <iostream> #include <iomanip> #include <algorithm> #include <string> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <vector> #include <list> #include <map> #include <set> #include <queue> #include <stack> #define INF (int)1e09 using std::cin; using std::cout; using std::endl; using std::setprecision; using std::fixed; using std::pair; using std::make_pair; using std::min; using std::max; using std::string; using std::vector; using std::list; using std::map; using std::set; using std::queue; using std::priority_queue; using std::stack; template <typename T> using Vec = vector<T>; typedef pair<int, int> PII; typedef pair<int, pair<int, int> > PIII; int main(void) { int h; int w; cin >> h >> w; string s; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> s; if (s == "snuke") { cout << (char)(j + 'A') << i + 1 << endl; } } } return 0; }
0
55,666,316
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0;i<n;i++) int main(){ int n, k; cin >> n >> k; vector<int> a(n); vector<int> c(n,n); rep(i,n){ cin >> a[i]; } rep(j,k){ vector<int> d(n+1); rep(i,n){ d[max(i-a[i],0)]++; d[min(i+a[i]+1,n)]--; } vector<int> e(n,d[0]); rep(i,n-1){ e[i+1]=e[i]+d[i+1]; } a=e; if (c==e){ break; } } rep(i,n-1){ cout << a[i] << ' '; } cout << a[n-1] << endl; return 0; }
#include <bits/stdc++.h> #define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)) #define rep(i, n) for (int i = 0; i < (n); ++i) #define precise(i) fixed << setprecision(i) using li = long long int; using uli = unsigned long long int; using namespace std; int main() { fastIO; string s; cin >> s; int alpha[26]{0}; for (auto ch : s) alpha[ch - 'a'] = 1; rep(i, 26) { if (alpha[i] != 1) { cout << (char)(i + 'a') << endl; return 0; } } cout << "None\n"; }
0
63,532,113
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define clr(a,b) memset(a,b,sizeof(a)) ll n,m,k,ans; char c[10005]; ll p,q,r; int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ cin>>c[i]; if(c[i]=='R')p++; if(c[i]=='G')q++; if(c[i]=='B')r++; } ans=p*q*r; for(int i=1;i<=n;i++){ for(int d=1;i+2*d<=n;d++){ int j=i+d,k=i+2*d; if(c[i]!=c[j]&&c[j]!=c[k]&&c[k]!=c[i])ans--; } } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll N,M,tmp,ans; cin>>N>>M; tmp = M; tmp -= (N*2); if(tmp < 0){ ll kake = M/2; ans = kake; } else{ ans = N; ans += (tmp/4); } cout<<ans<<endl; return 0; }
0
9,286,902
#include <bits/stdc++.h> using namespace std; bool solve(string S) { if (S[0] != 'A') return false; int N = S.size(); int con = 0; for (int i = 0; i < N; ++i) if (S[i] >= 'A' && S[i] <= 'Z') ++con; if (con != 2) return false; bool exist = false; for (int i = 2; i+1 < N; ++i) if (S[i] == 'C') exist = true; if (!exist) return false; return true; } int main() { string S; cin >> S; if (solve(S)) cout << "AC" << endl; else cout << "WA" << endl; }
#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>; typedef vector<int> vi; string divide[4] = {"dream", "dreamer", "erase", "eraser"}; int main() { string S; cin >> S; reverse(S.begin(), S.end()); for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end()); bool can = true; for (int i = 0; i < S.size();) { bool can2 = false; for (int j = 0; j < 4; ++j) { string d = divide[j]; if (S.substr(i, d.size()) == d) { can2 = true; i += d.size(); } } if (!can2) { can = false; break; } } if (can) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
0
59,724,690
#include <bits/stdc++.h> #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) const bool debug=false; #define DEBUG if(debug==true) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll MOD = 1000000007; int main(void) { ll n; cin>>n; ll val[n]; rep(i,n){ ll tmp; cin>>tmp; tmp--; val[tmp]=i+1; } ll a[n],b[n]; a[n-1]=val[n-1],b[n-1]=0; for(int i=n-2;i>=0;i--){ a[i] = a[i+1] +20001; b[i] = val[i]-a[i]; } for(int i=n-1;i>=0;i--){ b[i] -= b[0]; b[i] += 1; } rep(i,n){ cout << b[i]; if(i==n-1){ cout << endl; }else{ cout << " "; } } rep(i,n){ cout << a[i]; if(i==n-1){ cout << endl; }else{ cout << " "; } } return 0; }
#include<iostream> #include<algorithm> #include<string> #include<cstdlib> #include<map> #include<iomanip> #include<sstream> #include<vector> #include<stack> #include<math.h> #include<queue> #include<complex> #include<random> #include<ctime> #include<set> using namespace std; #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; const long long int mod=1000000007; const long long int INF=99999999999999999; long long int N,K,a[105],res=INF; int main() { cout << fixed << setprecision(18); cin>>N>>K; for(int i=0;i<N;i++){cin>>a[i];} for(int i=0;i<(1<<N-1);i++){ long long int tmp=1,mymax=a[0],money=0; for(int j=0;j<N-1;j++){ if(((1<<j)&i)==0){ if(mymax>=a[j+1]){ money+=(-a[j+1]+mymax)+1; mymax++; } tmp++; }else if(mymax<a[j+1]){ tmp++; } mymax=max(mymax,a[j+1]); } if(tmp>=K){res=min(res,money);} } cout<<res<<endl; }
0
87,322,611
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) constexpr int MOD=998244353; #define INF (1<<30) #define LINF (lint)(1LL<<56) #define endl "\n" #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define Flag(x) (1<<(x)) #define Flagcount(x) __builtin_popcount(x) #define pint pair<int,int> #define pdouble pair<double,double> #define plint pair<lint,lint> #define fi first #define se second typedef long long lint; int dx[8]={1,1,0,-1,-1,-1,0,1}; int dy[8]={0,1,1,1,0,-1,-1,-1}; const int MAX_N=2e5+5; int main(void){ int N; cin >> N; lint A[N]; rep(i,N) cin >> A[i]; lint dp[N]={}; dp[0]=1000; rep(i,N-1){ lint stk=dp[i]/A[i]; lint money=dp[i]%A[i]; dp[i+1]=max(dp[i],stk*A[i+1]+money); } cout << dp[N-1] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i,x) for(long long i=0;i<x;i++) #define repn(i,x) for(long long i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) vector<pair<string,P> >vec; void solve(long long N, vector<long long> p){ vector<ll> a(N), b(N); rep(i,N) { a[i] = (i+1)*N; b[i] = (N-i)*N; } rep(i,N) { a[p[i]] += i; } rep(i,N-1) { cout << a[i] << " "; } cout << a[N-1] << endl; rep(i,N-1) { cout << b[i] << " "; } cout << b[N-1] << endl; } int main(){ long long N; scanf("%lld",&N); vector<long long> p(N-1+1); for(int i = 0 ; i <= N-1 ; i++){ scanf("%lld",&p[i]); p[i]--; } solve(N, p); return 0; }
0
13,933,853
#include <iostream> #include <queue> using namespace std; int main(){ int n,i; float tmp,v1,v2; cin >> n; priority_queue<float,vector<float>,greater<float>> v; for(i=0;i<n;++i){ cin >> tmp; v.push(tmp); } while(1){ v1 = v.top(); v.pop(); v2 = v.top(); v.pop(); v.push((v1+v2)/2.0); if(v.size()==1) break; } cout << v.top() << endl; return 0; }
#include<bits/stdc++.h> #define pi acose(-1) typedef long long int ll; typedef double dl; using namespace std; const int mx = 1e2+5; int main() { int n, h1; cin>>n; if(n%2==1) { cout<<"No"<<endl; return 0; } char str[n+5]; for(int i=0; i<n; i++) { cin>>str[i]; } int cnt=0; for(int i=0; i<n/2; i++) { if(str[i]!=str[n/2+i]) { cout<<"No"<<endl; return 0; } } cout<<"Yes"<<endl; return 0; }
0
33,835,615
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef vector<pii> vpii; typedef vector<pil> vpil; typedef vector<pli> vpli; typedef set<int> si; typedef set<ll> sll; typedef map<int, int> mii; typedef map<ll, ll> mll; const double pi = acos(-1.0); const long long INF = 2e18; #define ff first #define ss second #define pb push_back #define mp make_pair #define sz size() #define in insert #define endl "\n" #define sqr(a) ((a) * (a)) #define jor(a) !(a&1) #define bjor(a) (a&1) #define all(a) a.begin(), a.end() #define mem(arr, b) memset(arr, b, sizeof(arr)) #define for0(i,b) for(int i=0;i<(b);i++) #define for1(i,b) for(int i=1;i<=(b);i++) #define forab(i,a,b) for(int i=(a);i<=(b);i++) #define forba(i,b,a) for(int i=(b);i>=(a);i--) #define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c)) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define fileRead freopen("input.txt", "r", stdin); #define fileWrite freopen("output.txt", "w", stdout); void print(int a[], int n){ for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl; } int main() { string s; cin>>s; int m=0; for0(i,s.sz){ m+=s[i]-'0'; } if(m%9==0) cout<<"Yes"; else cout<<"No"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = mod * mod; const int INF_N = 1e+9; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); typedef vector<int> vec; ll mod_pow(ll a, ll n, ll m) { ll res = 1; while (n) { if (n & 1)res = res * a%m; a = a * a%m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n%mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0)return modint(1); modint res = (a*a) ^ (n / 2); if (n % 2)res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 18; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } using mP = pair<modint, modint>; int dx[4] = { 0,1,0,-1 }; int dy[4] = { 1,0,-1,0 }; void solve() { int H, W, A, B; cin >> H >> W >> A >> B; rep(i, H){ rep(j, W){ if(i<B){ if(j<A) cout << 1; else cout << 0; }else{ if(j<A) cout << 0; else cout << 1; } } cout << endl; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
0
6,690,914
#include <iostream> #include <cstdio> #include <cstdlib> #include <iomanip> #include <cmath> #include <algorithm> #include <map> #include <set> #include <vector> #include <queue> #include <stack> #include <cstring> #include <string> #include <list> #include <bitset> using namespace std; typedef long long LL; typedef unsigned long long ULL; const LL mod=1e9+7; const double PI=acos(-1); const double EPS=1e-6; const int INF=0x3f3f3f3f; inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;} inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;} vector<int> E[100005]; int dfs(int pos,int fa){ int ans=0; for(int i=0;i<E[pos].size();i++){ if(E[pos][i]==fa) continue; ans^=(dfs(E[pos][i],pos)+1); } return ans; } int main(){ int n=readint(); for(int i=1;i<n;i++){ int u=readint(),v=readint(); E[u].push_back(v); E[v].push_back(u); } if(dfs(1,0)) printf("Alice\n"); else printf("Bob\n"); return 0; }
#include <iostream> #include <cmath> using namespace std; int test(double x1, double y1, double x2, double y2, double x3, double y3, double xp, double yp) { double xa = (x2 - x1); double ya = (y2 - y1); double xb = (x3 - x1); double yb = (y3 - y1); double xc = (xp - x1); double yc = (yp - y1); double d = 1.0 / (xa*yb - xb*ya); double k = d * (yb * xc - xb * yc); double m = d * (-ya * xc + xa * yc); return (k >= 0.0 && m >= 0.0)? 1 : 0; } int main(void) { double x1, y1, x2, y2, x3, y3, xp, yp; while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) { int tmp = 1; tmp *= test(x1, y1, x2, y2, x3, y3, xp, yp); tmp *= test(x2, y2, x1, y1, x3, y3, xp, yp); tmp *= test(x3, y3, x1, y1, x2, y2, xp, yp); cout << ((tmp ==1)? "YES" : "NO") << endl; } return 0; }
0
98,700,477
#include <bits/stdc++.h> using namespace std; int main(void) { int N,K,a,ans = 0; cin >> N >> K; map<int64_t,int> mp; for(int i=0;i<N;i++) { cin >> a; mp[a]++; } vector<int> ball(mp.size()); a = 0; for(auto m:mp) { ball[a] =m.second; a++; } sort(ball.begin(), ball.end()); for(int i=K;i<ball.size();i++) { ans += ball[i-K]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define initdp(a, b) for (int i = 0; i <= a; i++) for (int j = 0; j <= b; j++) dp[i][j] = -1; #define pb push_back #define pii pair<int, int> #define ll long long #define pll pair<ll, ll> #define all(arr) arr.begin(), arr.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repd(i, n) for (int i = n - 1; i >= 0; i--) #define fo(i, l, r) for (int i = l; i <= r; i++) #define inf 1000000001 #define inf1 1000000000000000001 #define mod 1000000007 #define pie 3.14159265358979323846 #define N 1000005 #define mid(l, r) l + (r - l) / 2 #define vec vector<int> #define vecl vector<ll> #define yes cout << "Yes" << endl; #define no cout << "No" << endl; #define umapi unordered_map<ll, ll> #define umapc unordered_map<char, int> #define endl "\n" #define pui pair<int, pair<int,int> > using namespace std; void solve(){ ll a; cin >>a; double b; cin >> b; int64_t ans = a*b; if( (b>= 9.9 && b <10 && a%1000 != 0) || b == 3.24 || b == 4.65 ) { if(ans > 0) { ans--; } } cout<<ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed<<setprecision(10); int t = 1; while (t--) { solve(); } }
0
53,188,523
#include <bits/stdc++.h> using namespace std; const long long int INF = 1LL<<60; const long long int Mod = 1000000007; using ll = long long int; using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using P = pair<int, int>; using PLL = pair<ll, ll>; using matrix = vector<vector<ll>>; #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define rp(i,N) for(ll i = 0; i < (ll)N; i++) #define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i) template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; } template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; } template<class T>T sqar(T x){ return x*x; } #define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) #define p_queue(v) priority_queue<v, vector<v>, greater<v> > template<class T> inline void princ(T x){cout<<x<<" ";}; template<class T> inline void print(T x){cout<<x<<"\n";}; template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } void solve(){ ll n,k; cin >> n >> k; Vi a(n); rp(i,n) cin >> a.at(i); Vi kind; sort(all(a)); ll ctr=1; rp(i,n-1){ if(a[i]==a[i+1]) ctr++; else{ kind.pb(ctr); ctr=1; } } kind.pb(ctr); sort(all(kind)); ll to_delete=kind.size()-k; ll ans=0; rp(i,to_delete){ ans+=kind[i]; } print(ans); return; } int main(){ cin.tie(0);ios::sync_with_stdio(false); std::cout<<std::fixed<<std::setprecision(30); solve(); return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<cstdio> #include<string> #include<stdio.h> #include<stdlib.h> #include<float.h> #include<tuple> #include<string.h> #include<iomanip> #include<stack> #include<queue> #include<map> #include<deque> using namespace std; #define ll long long #define rep(i,n) for(ll i=0;i<n;i++) #define ALLOF(c) (c).begin(), (c).end() #define Pa pair<ll,ll> const ll mod=1000000007; const ll INF=10e12; const ll inf=-1; ll ABS(ll a){return max(a,-a);} int main(void){ ll N,kaisu=0; cin>>N; vector<ll> A(N),B(N); rep(i,N) cin>>A.at(i); rep(i,N) cin>>B.at(i); rep(i,N) kaisu+=B.at(i)-A.at(i); ll needa=0,needb=0; rep(i,N){ if(A.at(i)>B.at(i)) needb+=A.at(i)-B.at(i); else if(A.at(i)<B.at(i)) needa+=(B.at(i)-A.at(i)+1)/2; } if(needa<=kaisu && needb<=kaisu) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
0
3,819,168
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; cout << ( (a[0]==a[1] &&a[1]==a[2])|| (a[1]==a[2] && a[2]==a[3]) ? "Yes" : "No" ) <<endl; }
#include<bits/stdc++.h> using namespace std; int main() { long long int x,y,z; long long int count=0; int arr[1000]; cin>>x; for(int i=0;i<x;i++){ cin>>arr[i]; } for(int i=0;i<x;i++){ int ck=i; for(int j=i;j<x;j++){ if(arr[j]<arr[ck]){ ck=j; } } swap(arr[i],arr[ck]); if(i!=ck){ count++; } } for(int i=0,ck=1;i<x;i++,ck++){ cout<<arr[i]; if(ck!=x){ cout<<" "; } } cout<<endl; cout<<count<<endl;; return 0; }
0
25,544,393
#include <iostream> #include <cstdio> #include <cstdlib> #include <string> int main() { std::string str; while(std::cin >> str) { if(str == "0") break; int sum = 0; for(int i = 0; str[i] != '\0'; ++i) { sum += str[i] - '0'; } std::cout << sum << std::endl; } return 0; }
#include <map> #include <string> #include <iostream> #include <algorithm> using namespace std; const int inf = 1012345678; int solve(string S) { int N = S.size(); map<int, int> dp; dp[0] = 0; int bit = 0; for (int i = 0; i < N; ++i) { bit ^= 1 << (S[i] - 'a'); int opt = (dp.find(bit) != dp.end() ? dp[bit] : inf); for (int j = 0; j < 26; ++j) { map<int, int>::iterator it = dp.find(bit ^ (1 << j)); if (it != dp.end()) { opt = min(opt, it->second + 1); } } if (opt != inf) dp[bit] = opt; } return (bit == 0 ? 1 : dp[bit]); } int main() { string S; cin >> S; cout << solve(S) << endl; return 0; }
0
69,393,658
#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 all(x) x.begin(),x.end() #define rep(i,j,n) for (int i = j; i < (int)(n); i++) #define _GLIBCXX_DEBUG #define MOD 1000000007 template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } signed main(){ string a,b,c; cin>>a>>b>>c; if(a[a.size()-1]==b[0] && c[0]==b[b.size()-1]) cout<<"YES"; else cout<<"NO"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep1(i, n) for (int i = 1; i <= (int)(n); ++i) #define rep11(i, n) for (int i = 1; i < (int)(n); ++i) #define repo(i, o, n) for (int i = o; i < (int)(n); ++i) #define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define pb(n) push_back(n) #define mp make_pair #define MOD 1002000007 #define INF LONG_LONG_MAX typedef pair<long long, long long> P; int main(){ long long n; long long m; cin>>n>>m; vector<pair<P,long long>>v(m); rep(i,m){ cin>>v[i].first.first>>v[i].first.second; } rep(i,m){ v[i].second=i; } sort(v.begin(),v.end()); vector<string> ans(m); long long j=1; rep(i,m){ long long p=v[i].first.first; string zen = to_string(p); while(6>zen.size()){ zen="0"+zen; } if(i!=0){ if(v[i-1].first.first==v[i].first.first){ j++; } else{ j=1; } } string bor= to_string(j); while(6>bor.size()){ bor="0"+bor; } ans[v[i].second]=zen+bor; } rep(i,m){ cout<<ans[i]<<endl; } }
0
48,831,789
#include <bits/stdc++.h> using namespace std; using ll=long long; ll mypow(ll x,ll n){ ll ret=1; while(n>0){ if(n&1==1){ ret *=x; } x *=x; n >>=1; } return ret; } int main() { ll N,M; cin >> N >>M; vector<ll> x(N),y(N),z(N); for(int i=0;i<N;i++){ cin >> x[i] >> y[i] >> z[i]; } ll ans =0; for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++){ ll temp=0; vector<ll> A(N); for(int s=0;s<N;s++){ A[s] = (mypow(-1,i)*x[s] + mypow(-1,j)*y[s]+mypow(-1,k)*z[s]); } sort(A.rbegin(),A.rend()); for(int s=0;s<M;s++){ temp += A[s]; } ans = max(ans,temp); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; static const int MAX = 500; int c[MAX], s[MAX], f[MAX]; int main(){ int n; cin >> n; for(int i = 0; i < n-1; i++){ cin >> c[i] >> s[i] >> f[i]; } for(int i = 0; i < n-1; i++){ int t = s[i] + c[i]; for(int j = i+1; j < n-1; j++){ if(t >= s[j]){ t = (t + f[j] - 1) / f[j] * f[j]; } else { t = s[j]; } t += c[j]; } cout << t << endl; } cout << 0 << endl; return 0; }
0
27,922,467
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL<<62 #define inf 1000000007 int main() { string s; cin>>s; ll ans=15-s.size(); for(ll i=0;i<s.size();i++){ if(s[i]=='o'){ ans++; } } cout << (ans>=8?"YES":"NO"); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define vout(x) rep(i,x.size()) cout << x[i] << " " template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; const int mod = 1e9+7; vll sum_bc; vll a, b, c; bool check(ll x, int k) { int num = 0; rep(i,a.size()) { num += sum_bc.end()-lower_bound(all(sum_bc),x-a[i]); } return num >= k; } int main() { int x, y, z, k; cin >> x >> y >> z >> k; a.resize(x); b.resize(y); c.resize(z); rep(i,x) cin >> a[i]; rep(i,y) cin >> b[i]; rep(i,z) cin >> c[i]; rep(i,y)rep(j,z) sum_bc.push_back(b[i]+c[j]); sort(all(sum_bc)); ll l = 0; ll r = inf_l; while (r-l > 1) { ll mid = (r+l)/2; if (check(mid,k)) l = mid; else r = mid; } vll ans_tmp; rep(i,x) { ll search = l - a[i]; for (auto ptr = lower_bound(all(sum_bc),search); ptr != sum_bc.end(); ptr++) { ans_tmp.push_back(*ptr+a[i]); } } sort(rall(ans_tmp)); vll ans; ans.assign(ans_tmp.begin(),ans_tmp.begin()+k); rep(i,ans.size()) printf("%lld\n",ans[i]); }
0
981,245
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int maxx=2000000000; int n; int p[110],dp[110][110]; int main (){ cin>>n; for(int i=1;i<=n;i++){ dp[i][i]=0; cin>>p[i-1]>>p[i]; } for(int len=2;len<=n;len++){ for(int i=1;i<=n-len+1;i++){ int j=i+len-1; dp[i][j]=maxx; for(int k=i;k<j;k++) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j]); } } cout<<dp[1][n]<<endl; return 0; }
#include <stdio.h> #include <string.h> int main(){ char s1[101], s2[101]; int taro=0,hana=0; int i,n; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s %s", s1, s2); if ( strcmp(s1, s2) == 0 ) { taro+=1; hana+=1; } else if ( strcmp(s1, s2) > 0 ) { taro+=3; } else if ( strcmp(s1, s2) < 0 ) { hana+=3; } } printf("%d %d\n",taro,hana); return 0; }
0
30,803,200
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int M; cin >> M; int g = M; for (int i=1; i<n; i++) { int num; cin >> num; M = max(M, num); g = __gcd(g, num); } if (k % g == 0 && k <= M) { cout << "POSSIBLE" << endl; } else { cout << "IMPOSSIBLE" << endl; } }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int ans=1; int x; for(int i=0;i<n;i++) { cin>>x; if(x==ans) ans++; } if(ans==1) cout<<-1<<endl; else cout<<n-ans+1<<endl; }
0
9,888,541
#include <bits/stdc++.h> using namespace std; #define int long long template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int MAX =3001; const int MOD =998244353; signed main(){ int n,x,m; cin>>n>>x>>m; int k=1,s[m+1];fill(s,s+m,MOD*MOD); s[m]=0; while(s[x]==MOD*MOD){ s[x]=k; k++; x=x*x%m; } int sx=s[x]; for(int i=m-1;i>=0;i--)s[i]=s[i+1]+(s[i]<=n)*i*(1+(sx<=s[i])*(n-s[i])/(k-sx)); cout<<s[0]<<endl; }
#include <iostream> #include <cmath> #include <vector> #include <map> #include <iomanip> #include <algorithm> #include <sstream> #include <string> #include <math.h> #include <set> #include <deque> using namespace std; typedef long long ll; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; int a[n]; for (int i = 0 ; i < n ; i++) cin >> a[i]; sort(a, a + n); int b = 0; for (int i = 0 ; i < n ; i++) if (a[i] != a[i + 1]) b++; int c[b] = {}, j = 0; for (int i = 0 ; i < n ; i++) { c[j]++; if (a[i] != a[i + 1]) j++; } if (b <= k) { cout << 0; return 0; } sort(c, c + b); int d = 0; for (int i = 0 ; i < b - k ; i++) d += c[i]; cout << d; }
0
80,927,912
#include "bits/stdc++.h" #define _overload(_1, _2, _3, _4, name, ...) name #define _rep1(Itr, N) _rep3(Itr, 0, N, 1) #define _rep2(Itr, a, b) _rep3(Itr, a, b, 1) #define _rep3(Itr, a, b, step) for (i64 (Itr) = a; (Itr) < b; (Itr) += step) #define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS) using namespace std; using llong = long long; string s; string ans; int main() { cin >> s; for (auto ch:s) { if (ch == 'B' && !ans.empty()) ans.pop_back(); else if (ch != 'B') ans.push_back(ch); } cout << ans << endl; return 0; };
#include <iostream> #include <vector> #include <string> using namespace std; int walking(vector<vector<char> > &walk, int a, int b, int &count){ walk[a][b] = '#'; if(walk[a-1][b] == '.'){ count++; walking(walk, a-1, b, count); } if(walk[a][b-1] == '.'){ count++; walking(walk, a, b-1, count); } if(walk[a+1][b] == '.'){ count++; walking(walk, a+1, b, count); } if(walk[a][b+1] == '.'){ count++; walking(walk, a, b+1, count); } return count; } int main(){ while(1){ int W, H, a=0, b=0, count=0; string str; vector<vector<char> > walk; cin>>W>>H; if((W == 0) && (H == 0)) break; walk.resize(H+2); for(int i=0;i<H+2;i++){ walk[i].resize(W+2); if((i == 0) || (i == H+1)){ for(int j=0;j<W+2;j++) walk[i][j] = '#'; }else{ walk[i][0] = '#'; walk[i][W+1] = '#'; } } for(int i=1;i<=H;i++){ cin>>str; for(int j=0;j<W;j++) walk[i][j+1] = str[j]; } for(int i=1;i<=H;i++){ for(int j=1;j<=W;j++){ if(walk[i][j] == '@'){ a = i; b = j; count++; } } } cout<<walking(walk, a, b, count)<<endl; } return 0; }
0
99,919,250
#include<iostream> #include<vector> using namespace std; int main() { int n,a; vector<int>number; int c[101] = { 0 }; for (int i = 0; i<100; i++){ cin >> a; c[a]++; } int max = 1; for (int i = 1; i <= 100; i++){ if (max == c[i]){ number.push_back(i); } else if (max<c[i]){ max = c[i]; number.clear(); number.push_back(i); } } for (int i = 0; i < number.size(); i++){ cout << number[i] << endl; } }
#include <iostream> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <cstring> #include <climits> using namespace std; #define ll long long #define FOR(i,n) for(int i=0;i<n;i++) #define sz(x) (int)(x.size()) #define all(x) (x).begin(),(x).end() template<typename tp> void read(tp &x) {cin >> x;} template<typename tp, typename... Args> void read(tp& x, Args&... args) {read(x);read(args...);} const int mxN = (int)1e5,INF = (int)1e9,MOD = (int)1e9+7; void solve() { int n; read(n); vector<int> a(n),b(n),c(n); FOR(i,n) { read(a[i]); c[i] = i+1; } FOR(i,n) read(b[i]); if(b == a) { cout << "0\n"; return; } int count = 0,flag = 0; do { if(!flag && (c==a || c==b)) { flag = 1,count++; continue; } if(flag)count++; if(flag && (c==a||c==b)) break; } while(next_permutation(all(c))); cout << count-1 << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int test = 1; while(test--) solve(); return 0; }
0
41,482,356
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() typedef long long ll; const int N = 1e5; const ll INF = 1e18; ll vt[N]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> vt[i]; } ll pref = 2; ll ans = vt[0] - 1; for (int pos = 1; pos < n; pos++) { if (vt[pos] == pref) { pref++; continue; } int res = (vt[pos] - 1) / pref; if (res == 0) continue; ans += res; } cout << ans; } int main() { ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); cout.setf(ios::fixed), cout.precision(2); solve(); }
#ifndef DEBUG #pragma GCC optimize("O3,unroll-loops") #pragma loop_opt(on) #endif #include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define FAST ; #else #define FAST ios::sync_with_stdio(0);cin.tie(0); #define endl '\n' #define cerr #endif #define _ <<' '<< #define Fr(i, s, e) for(auto i = s; i < e; ++i) #define All(v) v.begin(),v.end() #define Ft first #define Sd second using ll = long long; using pii = pair<int, int>; constexpr ll MOD = 1e9+7; signed main() { FAST; array<int,3> v; for(auto &x: v) cin >> x; sort(All(v)); int c = 0; Fr(i, 0, 2) { int x = (v[2]-v[i])/2; v[i] += x*2; c += x; } sort(All(v)); if (v[0] == v[2]-1) { if (v[0]==v[1]) c++; else c+=2; } cout << c << endl; }
0
91,690,420
#include <bits/stdc++.h> #define mod 1000000007 #define INF LLONG_MAX #define ll long long #define ln cout<<endl #define Yes cout<<"Yes"<<endl #define No cout<<"No"<<endl #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using namespace std; ll dx[4]={1,0,-1,0}; ll dy[4]={0,1,0,-1}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0; string str; cin>>n; vector<ll> v(n); rep(i,n+1) cin >> v[i]; sort(all(v)); ll pf=0; ll mf=0; rep(i,n){ if(v[i]<0) mf++; if(v[i]>0) pf++; } rep(i,n) sum+=abs(v[i]); if(pf==0) { sort(rall(v)); sum-=abs(v[0]*2); } if(mf==0) { sum-=abs(v[0]*2); } cout<<sum<<endl; if(n==2){ if(mf=0){ cout<<v[1]<<" "<<abs(v[0])<<endl; }else if(pf==0){ cout<<v[0]<<" "<<abs(v[1])<<endl; }else{ cout<<v[1]<<" "<<abs(v[0])<<endl; } return 0; } if(pf==1){ sort(rall(v)); rep(i,n-1){ cout<<v[i]<<" "<<v[i+1]<<endl; v[i+1]=v[i]-v[i+1]; } return 0; } if(mf==1){ rep(i,n-2){ cout<<v[i]<<" "<<v[i+1]<<endl; v[i+1]=v[i]-v[i+1]; } cout<<v[n-1]<<" "<<v[n-2]<<endl; return 0; } if(mf==0){ rep(i,n-2){ cout<<v[i]<<" "<<v[i+1]<<endl; v[i+1]=v[i]-v[i+1]; } cout<<v[n-1]<<" "<<v[n-2]<<endl; }else if(pf==0){ rep(i,n-1){ cout<<v[i]<<" "<<v[i+1]<<endl; v[i+1]=v[i]-v[i+1]; } }else{ sort(rall(v)); ll plus = v[0]; v.erase(v.begin()); sort(all(v)); a=v[0]; v.erase(v.begin()); sort(rall(v)); cout<<a<<" "<<v[0]<<endl; v[0]=a-v[0]; ll st; n=v.size(); rep(i,n-1){ cout<<v[i]<<" "<<v[i+1]<<endl; v[i+1]=v[i]-v[i+1]; st=i+1; if(v[i+2]<0) break; } cout<<plus<<" "<<v[st]<<endl; v[st]=plus-v[st]; n=v.size(); REP(i,st,n-1){ cout<<v[i]<<" "<<v[i+1]<<endl; v[i+1]=v[i]-v[i+1]; } } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) #define rep1(i,n) for(int i=1;i<=(int)n;i++) #define sp(n) cout << fixed << setprecision(n) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; using namespace std; int main(void){ int a,b,c;cin>>a>>b>>c; rep1(i,b){ int na=a*i; if(na%b==c){ cout<<"YES"<<endl; return 0; } } cout<<"NO"<<endl; }
0
55,357,082
#include<iostream> #include<algorithm> using namespace std; int main(){ int n; while(cin>>n,n){ int a[10000]; for(int i = 0;i < n;i++){ cin>>a[i]; } sort(a,a+n); int sum = 0; for(int i = 1;i < n-1;i++){ sum += a[i]; } sum /= n-2; cout<<sum<<endl; } return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iostream> #include <istream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <tuple> #include <iomanip> #include <climits> #include <fstream> #include <random> using namespace std; typedef long long ll; typedef unsigned long long ull; #define rep(i, n) for(int i = 0; i < (n); i++) #define revrep(i, n) for(int i = (n)-1; i >= 0; i--) #define pb push_back #define f first #define s second #define chmin(x, y) x = min(x, y); #define chmax(x, y) x = max(x, y); #define len(x) ((int)(x).size()) const ll INFL = 1LL<<60; const int INF = 1 << 30; const ll MOD = 1000000007; double EPS = 1e-10; vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0}; vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0}; void pres(double A){printf("%.9lf\n", A);} void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;} ll cnt_bit(ll x){return __builtin_popcountll(x);} ll pow_long(ll x, ll k){ ll res = 1; while(k > 0){ if(k % 2) res *= x; x *= x; k /= 2; } return res; } ll pow_mod(ll x, ll k){ ll res = 1; while(k > 0){ if(k % 2){ res *= x; res %= MOD; } x *= x; x %= MOD; k /= 2; } return res; } ll inverse(ll x){return pow_mod(x, MOD - 2);}; ll gcd(ll a, ll b){ if(b == 0) return a; return gcd(b, a % b); } ll lcm(ll x, ll y){ ll res = x / gcd(x, y); res *= y; return res; }; const int MAXcomb = 2000010; ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb]; void COMinit(){ fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAXcomb; 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 comb(int n, int k){ if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[k] % MOD * finv[n-k] % MOD; } ll disit(ll s, ll base = 10){ ll res = 0; while(s){ res++; s /= base; } return res; } void solve(){ int a, b, c; cin >> a >> b >> c; if(a <= b * c){ cout << "Yes" << endl; }else{ cout << "No" << endl; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
0
18,902,278
#include <bits/stdc++.h> using namespace std; int main() { vector<int> abc(3); cin >> abc[0] >> abc[1] >> abc[2]; sort(abc.begin(), abc.end()); abc.erase(unique(abc.begin(), abc.end()), abc.end()); cout << abc.size() << endl; return 0; }
#include<iostream> #include<iomanip> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<utility> #include<numeric> #include<algorithm> #include<cmath> #include<climits> using namespace std; using ll = long long; class Stream{ public: Stream(){ } void read(){ } template<typename First, typename... Rest> void read(First& first, Rest&... rest){ cin >> first; read(rest...); } template<typename T> void write_vec(vector<T>& v, char divider){ for(size_t i = 0; i < v.size(); i++){ cout << v[i] << divider; } } }; struct UF{ const int node_num; vector<int> parent; vector<int> size; UF(int N) : node_num(N), parent(N), size(N, 1) { for(int i = 0; i < N; ++i) parent[i] = i; } int root(int x){ if(parent[x] == x) return x; return parent[x] = root(parent[x]); } void unite(int x, int y){ int root_x = root(x); int root_y = root(y); if(root_x == root_y) return; parent[root_y] = root_x; size[root_x] += size[root_y]; } bool same(int x, int y){ int root_x = root(x); int root_y = root(y); return root_x == root_y; } int same_size(int x){ int root_x = root(x); return size[root_x]; } }; int main(){ Stream io; char c; io.read(c); switch(c){ case 'a': case 'i': case 'u': case 'e': case 'o': cout << "vowel"; break; default: cout << "consonant"; } return 0; }
0
10,666,893
#include<iostream> using namespace std; int main(){ int n,u,m,c; int b[1000][1000] = {}; int a[1000][1000] = {}; cin >> n; for(int i = 1;i <=n ;i++){ cin >> u >> m; for(int j = 1;j <= m;j++){ cin >> b[u][j]; } } for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ if(b[i][j] != 0){ c = b[i][j]; a[i][c] = 1; } if(j != n){ cout << a[i][j] << " "; }else{ cout << a[i][j] << endl; } } } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll solve(ll n, vector<ll> a) { ll res = 0; ll sum = 0; ll right = 0; for(ll left = 0;left<n; left++) { while(right < n && (sum ^ a[right]) == (sum + a[right])) { sum += a[right]; right++; } if(left == right) { res++; } else { res += (right - left); } sum -= a[left]; } return res; } int main() { ll n; cin >> n; vector<ll> a(n); for(ll i=0;i<n;i++) { cin >> a[i]; } cout << solve(n, a); }
0
39,122,180
#include<bits/stdc++.h> using namespace std; int main() { long long int a,b; cin>>a>>b; cout<<a-b+1; return 0; }
#include <iostream> #include<bits/stdc++.h> using namespace std; using ll =unsigned long long; using dl = long double; const ll m=1000000007; ll fac[1000001]; void pre(){ fac[0]=fac[1]=1; for(int i=2;i<=1000001;i++) { fac[i]=(fac[i-1]*1LL*i)%m; } } ll power(ll a,ll n){ ll res=1; while(n){ if(n%2) res = (res*1LL*a)%m; n/=2; a=(a*1LL*a)%m; } return res; } ll nCr(ll n,ll r){ ll res= fac[n]; res = (res*1LL*power(fac[r],m-2))%m; res= (res*1LL*power(fac[n-r],m-2))%m; return res; } int main() { pre(); ll x,y; cin>>x>>y; int z=max(x,y); int necr=x; int necc=y; ll ans=0; ll one = (2*y-x)/3; ll two = (2*x-y)/3; if(one<0||two<0||(2*y-x)%3!=0)cout<<0<<endl; else if(one+two==0||one+two<0||(2*x-y)%3!=0)cout<<0<<endl; else{ ll a= one; ll b= two; ll f=1;ll nos = a+b; cout<<nCr(nos,a); } return 0; }
0
37,802,326
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main(){ ios::sync_with_stdio(false); int a1,a2,a3; cin>>a1>>a2>>a3; int part1 = abs(a1-a2); int part2 = abs(a1-a3); int part3 = abs(a2-a3); int maxi = part1>part2?(part1>part3?part1:part3):(part2>part3?part2:part3); cout<<maxi<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define PRINT(s) cout << s << endl; #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define REP(i, n) FOR((i), 0, (n)) int main() { int k, s; cin >> k >> s; int limit = min(k, s) + 1; int count = 0; REP(x, limit) { if (2 * k + x < s) continue; REP(y, limit) { if (k + x + y < s || x + y > s) continue; count += 1; } } PRINT(count); }
0
31,558,265
#include <bits/stdc++.h> using namespace std; #define sci1(a) scanf("%d",&a) #define sci2(a,b) scanf("%d %d",&a,&b) #define sci3(a,b,c) scanf("%d %d %d",&a,&b,&c) #define scs(s) scanf("%s",s) #ifndef GET_MACRO #define GET_MACRO(__1,__2,__3,NAME,...) NAME #endif #define sci(...) GET_MACRO(__VA_ARGS__,sci3,sci2,sci1)(__VA_ARGS__) #define ll long long int main(){ ll n,m,i,j,*data1,*data2,*tdata,ans,t1,t2,t3,md=1000000007ll; data1=new ll[100000]; data2=new ll[100000]; tdata=new ll[100000]; scanf("%lld %lld",&n,&m); for(i=0;i<n;i++){ scanf("%lld",&tdata[i]); } sort(tdata,tdata+n); for(i=1;i<n;i++){ data1[i-1]=tdata[i]-tdata[i-1]; } for(i=0;i<m;i++){ scanf("%lld",&tdata[i]); } sort(tdata,tdata+m); for(i=1;i<m;i++){ data2[i-1]=tdata[i]-tdata[i-1]; } ans=0ll; n--; for(i=0;i<n;i++){ t1=((i+1)*(n-i))%md; ans+=((t1*data1[i])%md); ans%=md; } m--; t2=0; for(i=0;i<m;i++){ t1=((i+1)*(m-i))%md; t2+=((t1*data2[i])%md); t2%=md; } ans=(ans*t2)%md; printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main () { int N, M; cin >> N >> M; vector<int> memo(N); vector<int> A(M), B(M); for (int i = 0; i < M; i++) { cin >> A.at(i) >> B.at(i); if (A.at(i) == 1) { memo.at(B.at(i) - 1)++; } if (B.at(i) == 1) { memo.at(A.at(i) - 1)++; } } bool ok = false; for (int i = 0; i < M; i++) { if (A.at(i) == N) { if (memo.at(B.at(i) - 1) != 0) { ok = true; break; } } if (B.at(i) == N) { if (memo.at(A.at(i) - 1) != 0) { ok = true; break; } } } if (ok) { cout << "POSSIBLE" << endl; } else { cout << "IMPOSSIBLE" << endl; } }
0
98,625,002
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> #include <stack> #include <functional> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif #define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i) #define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i) #define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define all(x) (x).begin(), (x).end() template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <int,int> P; typedef long double ld; int main (void) { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> a(n); rep (i, n) cin >> a[i]; sort(all(a)); ll ai = a.back(); sort(all(a), [&](ll a, ll b) {return abs(ai - 2 * a) < abs(ai - 2 * b);}); cout << ai << " " << a[0] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (char c = 'a'; c <= 'z'; c++) { int left[s.length()], right[s.length()], x, a = 1, b = s.length(); left[0] = INT_MIN; right[s.length()-1] = INT_MIN; for (int i = 1; i < s.length(); i++) { if (s[i-1] == c) { left[i] = 1; } else { left[i] = left[i-1]+1; } } x = s.back() == c; for (int i = s.length()-2; i+1; i--) { x += s[i] == c; if (s[i+1] == c) { right[i] = 1; } else { right[i] = right[i+1]+1; } } while (a < b) { if (2*x > b-a+1) { cout << a << ' ' << b; return 0; } else if (s[a-1] == c && s[b-1] != c) { b--; } else if (s[a-1] != c && s[b-1] == c) { a++; } else if (s[a-1] != c && s[b-1] != c) { a++; b--; } else if (left[b-1] > right[a-1]) { b--; x--; } else { a++; x--; } } } cout << "-1 -1"; }
0
71,342,877
#include <bits/stdc++.h> #include <vector> #include <string.h> typedef long long ll; typedef long double lg; using namespace std; int main(){ ll n,k,x; cin>>n>>k; vector<ll>a; for(int i=0;i<n;i++){ cin>>x; a.push_back(x); } sort(a.begin(),a.end()); if(k>= n){ cout<<"0"<<endl; return 0; } ll sum=0; for(int i=0;i<n-k;i++) { sum += a[i]; } cout<<sum<<endl; return 0; }
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<set> #include<string> #include<cmath> #include<cassert> #include<map> #include<sstream> using namespace std; typedef long long ll; typedef ll int__; #define rep(i,j) for(int__ (i)=0;(i)<(j);(i)++) #define repeat(i,j,k) for(int__ i=(j);i<(k);(i)++) #define all(v) begin(v),end(v) typedef pair<ll,ll> pii; bool comp(const pii l,const pii r){ return l.second==r.second ? l.first<r.first : l.second<r.second; } int main() { while(true){ ll n;cin>>n; if(n==0)break; vector<pii> input(n); rep(i,n){ string s,e;cin>>s>>e; pii train; const char *s_char = s.c_str(); const char *e_char = e.c_str(); ll hour,minute,second; sscanf(s_char, "%lld:%lld:%lld",&hour,&minute,&second); train.second=hour*60*60+minute*60+second; sscanf(e_char, "%lld:%lld:%lld",&hour,&minute,&second); train.first=hour*60*60+minute*60+second; input[i]=train; } sort(all(input),comp); priority_queue<pii,vector<pii>,greater<pii> > que; ll ans=0; rep(i,n){ pii train=input[i]; while(que.size()>0 && train.second>=que.top().first){ que.pop(); } que.push(train); ans=max(ans,(ll)que.size()); } cout<<ans<<endl; } return 0; }
0
87,104,797
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i) #define equals(a, b) (fabs((a) - (b)) < EPS) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll mod = 1000000007; const int inf = 1e9 + 10; const ll INF = 1e18; const ld EPS = 1e-10; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; 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() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(25); int n; cin >> n; vector<ll> a(n), b(n); rep(i, n) cin >> a[i] >> b[i]; ll ans = 0; repr(i, n - 1) { if ((a[i] + ans) % b[i] != 0) { ans += b[i] - (a[i] + ans) % b[i]; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); int n , m; cin >> n >> m; vector<int> adj[n]; for (int i = 0 ;i < m ;i++) { int k; cin >> k; while (k--) { int s; cin >> s; adj[s - 1].push_back(i); } } vector<int> p(m); for (int i = 0 ;i < m ;i++) cin >> p[i]; int ans = 0; for (int i = 0 ;i < (1 << n) ;i++) { vector<int> cnt(m , 0); for (int j = 0 ;j < n ;j++) { if (i & (1 << j)) { for (int b : adj[j]) cnt[b]++; } } bool good = 1; for (int j = 0 ;j < m ;j++) good &= p[j] == cnt[j] % 2; ans += good; } cout << ans; }
0
92,804,305
#include <bits/stdc++.h> using namespace std; #define INF 1000007 #define MOD 1000000007 #define maxn 10001 #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) FOR(i, 0, n) const double PI = acos(-1); typedef pair<int, int> P; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int mpow(int N, int P, int M) { if (P == 0) return 1; if (P % 2 == 0) { int t = mpow(N, P / 2, M); return t * t % M; } return N * mpow(N, P - 1, M) % M; } int counter(int x) { if (x == 0) return 0; return counter(x >> 1) + (x & 1); } vector<bool> prime(maxn + 1, true); void prime_table(void) { prime[0] = false; prime[1] = false; for (int i = 2; i * i <= maxn; i++) { if (!prime[i]) { continue; } for (int j = i + i; j <= maxn; j += j + i) { prime[j] = false; } } } bool IsPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } vector<int> divisor(int n) { vector<int> ret; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i - 1); if (i * i != n) { ret.push_back((n / i) - 1); } } } sort(ret.begin(), ret.end()); return (ret); } int main() { string S; string T; cin >> S >> T; cout << T << S << endl; }
#include <cstdint> #include <iostream> #include <string> #include <algorithm> constexpr int32_t kMaxNumberOfMatrices = 100; constexpr int32_t kMaxNumberOfRowsAndCols = 100; void CallMatrixChainMultiplication(std::istream &input_stream); struct Matrix { int32_t number_of_rows{0}; int32_t number_of_columns{0}; }; struct LookUp { bool calculated{false}; int32_t mcm{INT32_MAX}; }; class MatrixChainMultiplication { public: MatrixChainMultiplication() noexcept; ~MatrixChainMultiplication() noexcept; void AddMatrix(const int32_t number_of_rows, const int32_t number_of_columns); int32_t CalculateMinMultiplyCount(); static int32_t GetMultiplyCount(const Matrix &a, const Matrix &b); static Matrix GetMultipliedMatrix(const Matrix &a, const Matrix &b); static Matrix GenerateMatrix(const int32_t number_of_rows, const int32_t number_of_columns); private: int32_t CalculateMcmRecursively(const int32_t start, const int32_t end); bool IsInvalidIndex(const int32_t index) const noexcept; bool IsInvalidArg(const int32_t start, const int32_t end) const noexcept; bool IsAlreadyCalculated(const int32_t start, const int32_t end) const; int32_t GetCalculatedResult(const int32_t start, const int32_t end) const; void StoreCalculatedResult(const int32_t start, const int32_t end, const int32_t mcm); MatrixChainMultiplication(const MatrixChainMultiplication &obj) = delete; MatrixChainMultiplication &operator=(const MatrixChainMultiplication &obj) = delete; MatrixChainMultiplication(MatrixChainMultiplication &&obj) = delete; MatrixChainMultiplication &operator=(MatrixChainMultiplication &&obj) = delete; private: int32_t number_of_matrices_; Matrix matrices_[kMaxNumberOfMatrices]; LookUp look_up_table_[kMaxNumberOfMatrices][kMaxNumberOfMatrices]; }; void CallMatrixChainMultiplication(std::istream &input_stream) { input_stream.tie(0); std::ios::sync_with_stdio(false); MatrixChainMultiplication *matrix_chain_multiplication = new MatrixChainMultiplication(); try { int32_t number_of_matrices; input_stream >> number_of_matrices; for (int32_t i = 0; i < number_of_matrices; ++i) { int32_t number_of_rows, number_of_columns; input_stream >> number_of_rows >> number_of_columns; matrix_chain_multiplication->AddMatrix(number_of_rows, number_of_columns); } const int32_t multiply_count = matrix_chain_multiplication->CalculateMinMultiplyCount(); std::cout << multiply_count << std::endl; } catch (...) { std::cerr << "ERROR: CallMatrixChainMultiplication()" << std::endl; throw; } delete matrix_chain_multiplication; } MatrixChainMultiplication::MatrixChainMultiplication() noexcept : number_of_matrices_(0) {} MatrixChainMultiplication::~MatrixChainMultiplication() noexcept {} void MatrixChainMultiplication::AddMatrix(const int32_t number_of_rows, const int32_t number_of_columns) { if (number_of_matrices_ >= kMaxNumberOfMatrices) { std::cerr << "ERROR: AddMatrix(): Number of matricis size exceeded a limit = " << kMaxNumberOfMatrices << std::endl; throw 1; } const int32_t store_index = number_of_matrices_; ++number_of_matrices_; matrices_[store_index] = GenerateMatrix(number_of_rows, number_of_columns); } int32_t MatrixChainMultiplication::CalculateMinMultiplyCount() { const int32_t count = CalculateMcmRecursively(0, number_of_matrices_ - 1); return count; } int32_t MatrixChainMultiplication::CalculateMcmRecursively(const int32_t start, const int32_t end) { int32_t mcm; if (start == end) { mcm = 0; } else if (IsInvalidArg(start, end)) { std::cerr << "ERROR: CalculateMcmRecursively(): Invalid arg start = " << start << ", end = " << end << std::endl; throw 1; } else { try { if (IsAlreadyCalculated(start, end)) { mcm = GetCalculatedResult(start, end); } else { mcm = INT32_MAX; for (int32_t i = start; i <= end - 1; ++i) { const int32_t temp_mcm = matrices_[start].number_of_rows * matrices_[i].number_of_columns * matrices_[end].number_of_columns + CalculateMcmRecursively(start, i) + CalculateMcmRecursively(i + 1, end); mcm = std::min(mcm, temp_mcm); } StoreCalculatedResult(start, end, mcm); } } catch (...) { std::cerr << "ERROR: CalculateMcmRecursively()" << std::endl; throw; } } return mcm; } bool MatrixChainMultiplication::IsInvalidIndex(const int32_t index) const noexcept { return ((index < 0) || (index > number_of_matrices_)); } bool MatrixChainMultiplication::IsInvalidArg(const int32_t start, const int32_t end) const noexcept { const bool is_invalid_start = IsInvalidIndex(start); const bool is_invalid_end = IsInvalidIndex(end); const bool is_invalid_order = (start > end); return is_invalid_start || is_invalid_end || is_invalid_order; } bool MatrixChainMultiplication::IsAlreadyCalculated(const int32_t start, const int32_t end) const { if (IsInvalidArg(start, end)) { std::cerr << "ERROR: IsAlreadyCalculated(): start = " << start << ", end = " << end << std::endl; throw 1; } return look_up_table_[start][end].calculated; } int32_t MatrixChainMultiplication::GetCalculatedResult(const int32_t start, const int32_t end) const { if (IsInvalidArg(start, end)) { std::cerr << "ERROR: GetCalculatedResult(): start = " << start << ", end = " << end << std::endl; throw 1; } return look_up_table_[start][end].mcm; } void MatrixChainMultiplication::StoreCalculatedResult(const int32_t start, const int32_t end, const int32_t mcm) { if (IsInvalidArg(start, end)) { std::cerr << "ERROR: GetCalculatedResult(): start = " << start << ", end = " << end << std::endl; throw 1; } look_up_table_[start][end].mcm = mcm; look_up_table_[start][end].calculated = true; } int32_t MatrixChainMultiplication::GetMultiplyCount(const Matrix &a, const Matrix &b) { if (a.number_of_columns != b.number_of_rows) { std::cerr << "ERROR: GetMultiplyCount(): Invalid a.number_of_columns = " << a.number_of_columns << ", b.number_of_rows = " << b.number_of_rows << std::endl; throw 1; } return a.number_of_rows * a.number_of_columns * b.number_of_columns; } Matrix MatrixChainMultiplication::GetMultipliedMatrix(const Matrix &a, const Matrix &b) { if (a.number_of_columns != b.number_of_rows) { std::cerr << "ERROR: GetMultipliedMatrix(): Invalid a.number_of_columns = " << a.number_of_columns << ", b.number_of_rows = " << b.number_of_rows << std::endl; throw 1; } const Matrix result = GenerateMatrix(a.number_of_rows, b.number_of_columns); return result; } Matrix MatrixChainMultiplication::GenerateMatrix(const int32_t number_of_rows, const int32_t number_of_columns) { Matrix mat; mat.number_of_rows = number_of_rows; mat.number_of_columns = number_of_columns; return mat; } int main(int argc, char *argv[]) { try { CallMatrixChainMultiplication(std::cin); } catch (...) { std::cerr << "ERROR: main()" << std::endl; } return 0; }
0
64,151,515
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (n); ++i) double const PI = 3.1415926535897932384626433; int main() { int a, b; cin >> a >> b; cout << (a - 1) * (b - 1) << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; using ll = long long; #define all(c) (c).begin(), (c).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pb(e) push_back(e) #define mp(a, b) make_pair(a, b) #define fr first #define sc second const ll INF = 1e9; const ll MOD = 1e9 + 7; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { int n; int coins[] = {500, 100, 50, 10, 5}; while (cin >> n, n) { int ans = 0; int m = 1000 - n; rep(i, 5) { ans += m / coins[i]; m %= coins[i]; } ans += m; cout << ans << endl; } return 0; }
0
55,784,453
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; long long MOD = 10000000000 + 7; int main(){ int N,M; cin >> N >> M; vector<ll> h(N); map<int,bool> m; for(int i = 0; i < N; i++){ cin >> h[i]; m[i] = true; } for(int i = 0; i < M; i++){ int tmp1, tmp2; cin >> tmp1 >> tmp2; tmp1--; tmp2--; if(h[tmp1] <= h[tmp2]){ m[tmp1] = false; } if(h[tmp2] <= h[tmp1]){ m[tmp2] = false; } } int ans = 0; for(int i = 0; i < N; i++){ if(m[i]) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int dice[6]; for (int i=0; i<6; i++) cin >> dice[i]; int q; cin >> q; for (int i=0; i<q; i++) { int x, y; cin >> x >> y; int ans; if (x == dice[0]) { if (y == dice[1]) ans = dice[2]; else if (y == dice[2]) ans = dice[4]; else if (y == dice[4]) ans = dice[3]; else if (y == dice[3]) ans = dice[1]; } else if (x == dice[1]) { if (y == dice[5]) ans = dice[2]; else if (y == dice[2]) ans = dice[0]; else if (y == dice[0]) ans = dice[3]; else if (y == dice[3]) ans = dice[5]; } else if (x == dice[2]) { if (y == dice[1]) ans = dice[5]; else if (y == dice[5]) ans = dice[4]; else if (y == dice[4]) ans = dice[0]; else if (y == dice[0]) ans = dice[1]; } else if (x == dice[3]) { if (y == dice[1]) ans = dice[0]; else if (y == dice[0]) ans = dice[4]; else if (y == dice[4]) ans = dice[5]; else if (y == dice[5]) ans = dice[1]; } else if (x == dice[4]) { if (y == dice[0]) ans = dice[2]; else if (y == dice[2]) ans = dice[5]; else if (y == dice[5]) ans = dice[3]; else if (y == dice[3]) ans = dice[0]; } else if (x == dice[5]) { if (y == dice[4]) ans = dice[2]; else if (y == dice[2]) ans = dice[1]; else if (y == dice[1]) ans = dice[3]; else if (y == dice[3]) ans = dice[4]; } cout << ans << endl; } return 0; }
0
84,067,980
#include <bits/stdc++.h> using namespace std; int main() { int N,total=0; cin >> N; while(N){ int l,r; cin >> l >> r; total += r-l+1; N--; } cout << total << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<P>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; using Graph = vector<VecP>; template <typename T> using Vec1 = vector<T>; template <typename T> using Vec2 = vector<Vec1<T> >; #define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i)) #define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i)) #define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i)) #define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i)) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define all(s) (s).begin(), (s).end() #define pb push_back #define mp make_pair #define fs first #define sc second template <typename T> bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;} template <typename T> bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;} template <typename T> ll pow2(const T n){return (1LL << n);} template <typename T> void cosp(const T n){cout << n << ' ';} template <typename T> void co(const T n){cout << n << '\n';} template <typename T1, typename T2> void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';} template <typename T> void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';} template <typename T> void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';} template <typename T> void ce(const T n){cerr << n << endl;} void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);} void setp(const ll n){cout << fixed << setprecision(n);} const ll INF = 1e9+1; const ll LINF = 1e18+1; const ll MOD = 1e9+7; const ld PI = acos(-1); const ld EPS = 1e-11; int main(void){ ll n; cin >> n; Vec t(n), a(n); rep(i, n) cin >> t[i]; rep(i, n) cin >> a[i]; Vec h(n); rep(i, n){ if(!i || t[i] != t[i-1]) h[i] = t[i]; } repr(i, n){ if(i == n-1 || a[i] != a[i+1]){ if(!h[i] || h[i] == a[i]) h[i] = a[i]; else{ co(0); return 0; } } } rep(i, n){ if(h[i] && t[i] < h[i] || a[i] < h[i]){ co(0); return 0; } } ll ans = 1; rep(i, n){ if(!h[i]){ ans *= min(a[i], t[i]); ans %= MOD; } } co(ans); return 0; }
0
54,633,754
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 4e3; int vis[N+10]; char str[N+10]; int main() { int n; scanf("%d",&n); scanf("%s",str+1); ll ans = 0; for(int i=2;i<n;i++){ if(str[i]=='R'){ memset(vis,0,sizeof vis); int cnt1 = 0,cnt2 = 0,minus = 0; for(int j=i+1;j<=n;j++){ if(str[j]=='G'){ cnt1++; vis[j-i] = 1; } } for(int j=i-1;j>0;j--){ if(str[j]=='B'){ cnt2++; if(vis[i-j]){ minus++; } } } ans += (cnt1*cnt2-minus); memset(vis,0,sizeof vis); cnt1 = 0,cnt2 = 0,minus = 0; for(int j=i+1;j<=n;j++){ if(str[j]=='B'){ cnt1++; vis[j-i] = 1; } } for(int j=i-1;j>0;j--){ if(str[j]=='G'){ cnt2++; if(vis[i-j]){ minus++; } } } ans += (cnt1*cnt2-minus); } if(str[i]=='G'){ memset(vis,0,sizeof vis); int cnt1 = 0,cnt2 = 0,minus = 0; for(int j=i+1;j<=n;j++){ if(str[j]=='B'){ cnt1++; vis[j-i] = 1; } } for(int j=i-1;j>0;j--){ if(str[j]=='R'){ cnt2++; if(vis[i-j]){ minus++; } } } ans += (cnt1*cnt2-minus); memset(vis,0,sizeof vis); cnt1 = 0,cnt2 = 0,minus = 0; for(int j=i+1;j<=n;j++){ if(str[j]=='R'){ cnt1++; vis[j-i] = 1; } } for(int j=i-1;j>0;j--){ if(str[j]=='B'){ cnt2++; if(vis[i-j]){ minus++; } } } ans += (cnt1*cnt2-minus); } if(str[i]=='B'){ memset(vis,0,sizeof vis); int cnt1 = 0,cnt2 = 0,minus = 0; for(int j=i+1;j<=n;j++){ if(str[j]=='R'){ cnt1++; vis[j-i] = 1; } } for(int j=i-1;j>0;j--){ if(str[j]=='G'){ cnt2++; if(vis[i-j]){ minus++; } } } ans += (cnt1*cnt2-minus); memset(vis,0,sizeof vis); cnt1 = 0,cnt2 = 0,minus = 0; for(int j=i+1;j<=n;j++){ if(str[j]=='G'){ cnt1++; vis[j-i] = 1; } } for(int j=i-1;j>0;j--){ if(str[j]=='R'){ cnt2++; if(vis[i-j]){ minus++; } } } ans += (cnt1*cnt2-minus); } } printf("%lld\n",ans); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; vector<int64_t> X(N), Y(N); vector<int64_t> XA, YA; for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; XA.emplace_back(X[i]); YA.emplace_back(Y[i]); } sort(XA.begin(), XA.end()); sort(YA.begin(), YA.end()); int64_t res = (XA[N - 1] - XA[0]) * (YA[N - 1] - YA[0]); for (int xi = 0; xi < N; xi++) { for (int xj = xi + 1; xj < N; xj++) { for (int yi = 0; yi < N; yi++) { for (int yj = yi + 1; yj < N; yj++) { int cnt = 0; int64_t lx = XA[xi], rx = XA[xj]; int64_t by = YA[yi], uy = YA[yj]; for (int i = 0; i < N; i++) { if (lx <= X[i] && X[i] <= rx && by <= Y[i] && Y[i] <= uy) cnt++; } if (cnt >= K) res = min(res, (rx - lx) * (uy - by)); } } } } cout << res << '\n'; return 0; }
0
1,374,102
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pq priority_queue #define debug(x) cerr << #x << ": " << x << endl; #define line() cerr << "---------------" << endl; int main() { int n; while (cin >> n, n) { int o = 1000 - n; int cnt = 0; while (o != 0) { if (o >= 500) { o -= 500; } else if (o >= 100) { o -= 100; } else if (o >= 50) { o -= 50; } else if (o >= 10) { o -= 10; } else if (o >= 5) { o -= 5; } else if (o >= 1) { o -= 1; } cnt++; } cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S,T; cin >> S >> T; if( S.size() < T.size() ){ cout << "UNRESTORABLE" << endl; return 0; } bool same = true; string ans = "UNRESTORABLE"; for(int i=0;i<=S.size()-T.size();i++){ for(int j=0;j<T.size();j++){ if( S.at(i+j) != T.at(j) && S.at(i+j) != '?' ){ same = false; } } if(same){ ans = S; for(int j=0;j<S.size();j++){ if(S.at(j) == '?') ans.at(j) = 'a'; } for(int j=0;j<T.size();j++){ ans.at(i+j) = T.at(j); } } same = true; } cout << ans << endl; return 0; }
0
9,364,235
#include "bits/stdc++.h" using namespace std; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; #define rep(i, begin, n) for (int i = begin; i < n; i++) #define repe(i, begin, n) for (int i = begin; i <= n; i++) #define repr(i, begin, n) for (int i = begin; i > begin - n; i--) #define repre(i, begin, end) for (int i = begin; i >= end; i--) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = 1000000007; const int MOD = 1000000007; const long long INF = 1000000000000000007; int N; map<int, int> mp; int main() { cin >> N; rep(i, 0, N) { int a; cin >> a; ++mp[a]; } int ans = 0; repe(i, -1, 100001) { int cnt = 0; cnt += mp[i - 1]; cnt += mp[i]; cnt += mp[i + 1]; chmax(ans, cnt); } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define int long long #define Rep(i, N) for(int i = 0; i < N; i++) typedef pair<int, int> Pi; #define fi first #define se second int mx[] = {1, 0, -1, 0}; int my[] = {0, 1, 0, -1}; signed main() { int W, H; char mas[25][25]; while(cin >> W >> H, W || H) { queue < Pi > que; int ans = 1; Rep(i, H) Rep(j, W) { cin >> mas[i][j]; if(mas[i][j] == '@') { que.push(Pi(i, j)); mas[i][j] = '#'; } } while(!que.empty()) { Pi d = que.front(); que.pop(); int y = d.fi, x = d.se; Rep(i, 4) { int ny = y + my[i], nx = x + mx[i]; if(ny < 0 || nx < 0 || ny >= H || nx >= W || mas[ny][nx] == '#') continue; ans++, mas[ny][nx] = '#'; que.push(Pi(ny, nx)); } } cout << ans << endl; } return 0; }
0
30,910,110
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> sequence; vector<int> LIS; int initial; cin >> initial; LIS.emplace_back(initial); for (int i = 1; i < n; ++i) { int a; cin >> a; auto it = lower_bound(begin(LIS), end(LIS), a); if (it == end(LIS)) { LIS.emplace_back(a); } else { *it = a; } } cout << LIS.size() << endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pb push_back #define mp make_pair #define all(a) begin(a),end(a) #define FOR(x,val,to) for(int x=(val);x<int((to));++x) #define FORE(x,val,to) for(auto x=(val);x<=(to);++x) #define FORR(x,arr) for(auto &x: arr) #define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x) #define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x) #define REE(s_) {cout<<s_<<'\n';exit(0);} #define GET(arr) for(auto &i: (arr)) sc(i) #define whatis(x) cerr << #x << " is " << (x) << endl; #define e1 first #define e2 second #define INF 0x7f7f7f7f typedef std::pair<int,int> pi; typedef std::vector<int> vi; typedef std::vector<std::string> vs; typedef int64_t ll; typedef uint64_t ull; #define umap unordered_map #define uset unordered_set using namespace std; using namespace __gnu_pbds; #ifdef _WIN32 #define getchar_unlocked() _getchar_nolock() #define _CRT_DISABLE_PERFCRIT_LOCKS #endif template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; } template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; } template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; } template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; } inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;} inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}} inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}} template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); } template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define N 1000001 int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n; sc(n); int a[n]; GET(a); sort(a,a+n); cout << a[n-1] << ' '; int bs = -1; int cr = -1; FOR(i,0,n-1){ int cc = min(abs(a[i]-1),abs(a[i]-a[n-1])); if(cc > bs){ cr = a[i]; bs = cc; } } cout << cr << '\n'; }
0
98,249,816
#include <bits/stdc++.h> using namespace std; int main() { int input1, input2; cin >> input1 >> input2; if((input1 /2)*2 == input1 || (input2 /2)*2 == input2) { cout << "Even" << endl; } else { cout << "Odd" << endl; } return 0; }
#include <iostream> #include <vector> #include <string> using namespace std; void fnInput(vector<string> &rvsSortBbl, vector<string> &rvsSortSel) { int nMaxSiz; cin >> nMaxSiz; rvsSortBbl.resize(nMaxSiz); rvsSortSel.resize(nMaxSiz); for (int i = 0; i < nMaxSiz; i++) { cin >> rvsSortBbl[i]; rvsSortSel[i] = rvsSortBbl[i]; } } void fnBubbleSort(vector<string> &rvsSortBbl) { int nSorting = 0; bool bSorting = true; while (bSorting) { bSorting = false; for (int j = rvsSortBbl.size() - 1; j > nSorting; j--) { if (rvsSortBbl[j].at(1) < rvsSortBbl[j - 1].at(1)) { swap(rvsSortBbl[j], rvsSortBbl[j - 1]); bSorting = true; } } nSorting++; } } void fnOutputBbl(const vector<string> &cnrvsSortBbl) { for (int i = 0; i < cnrvsSortBbl.size(); i++) { if (i) cout << " "; cout << cnrvsSortBbl[i]; } cout << endl; cout << "Stable" << endl; } void fnSelectionSort(vector<string> &rvsSortSel) { for (int nSorting = 0; nSorting < rvsSortSel.size() - 1; nSorting++) { int nMin = nSorting; bool bSorting = false; for (int j = nSorting + 1; j < rvsSortSel.size(); j++) { if (rvsSortSel[j].at(1) < rvsSortSel[nMin].at(1)) { nMin = j; bSorting = true; } } if (bSorting == true) swap(rvsSortSel[nSorting], rvsSortSel[nMin]); } } void fnOutputSel(const vector<string> &cnrvsSortSel, const vector<string> &cnrvsSortBbl) { string sSortEnd = "Stable"; for (int i = 0; i < cnrvsSortSel.size(); i++) { if (i) cout << " "; cout << cnrvsSortSel[i]; if (cnrvsSortSel[i] != cnrvsSortBbl[i]) sSortEnd = "Not stable"; } cout << endl; cout << sSortEnd << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); vector<string> vsSortBbl, vsSortSel; fnInput(vsSortBbl, vsSortSel); fnBubbleSort(vsSortBbl); fnOutputBbl(vsSortBbl); fnSelectionSort(vsSortSel); fnOutputSel(vsSortSel, vsSortBbl); return 0; }
0
38,399,757
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < ll(n); i++) int main() { int n, a, b; cin >> n >> a >> b; int x = 0, y = 0, z = 0; rep(i, n) { int p; cin >> p; if (p <= a) x++; else if (p <= b) y++; else z++; } cout << min({x, y, z}) << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; bool compare_by_b(pair<int, int> a, pair<int, int> b) { if(a.second != b.second){ return a.second > b.second; }else{ return a.first < b.first; } } int main(){ int n, m; cin >> n >> m; priority_queue<int> q; pair<int, int> p[n]; for(int i = 0; i < n; i++){ cin >> p[i].first >> p[i].second; p[i].first--; } sort(p, p + n); int now = 0; ll ans = 0; int cou = 0; for(int i = 0; i < m; i++){ cou = 0; for(int j = now; j < n; j++){ if(p[j].first == i){ q.push(p[j].second); cou++; }else{ now += cou; break; } } if(q.size() != 0){ ans += q.top(); q.pop(); } } cout << ans << endl; }
0
58,188,807
#include <iostream> #include <string> #include <vector> #include <queue> #include <iomanip> #include <algorithm> using namespace std; using ll = long long; using pint = pair<int, int>; int main() { int N, K, d; cin >> N >> K; vector<int> s(N, 0); for (int i = 0; i < K; ++i) { int d; cin >> d; for (int j = 0; j < d; ++j) { int A; cin >> A; s[A-1]++; } } int ans = 0; for (auto ss : s) { if (ss == 0) { ans++; } } cout << ans << endl; return 0; }
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<tuple> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define Per(i,sta,n) for(int i=n-1;i>=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int n; string s; int dp[200010],st[200010]; unordered_map<int,int> ma; void solve(){ cin >> s; n=s.length(); rep(i,n){ int k=(1 << (s[i]-'a')); st[i+1]=st[i]^k; } if (st[n]==0) { cout << 1 << endl; return; } ma[0]=0; rep(i,n){ int res=mod; if (ma.count(st[i+1])){ res=ma[st[i+1]]; } else ma[st[i+1]]=mod; rep(k,26){ int m=(1 << k); if (ma.count(st[i+1]^m)){ res=min(res,ma[st[i+1]^m]); } } dp[i+1]=res+1; ma[st[i+1]]=min(ma[st[i+1]],dp[i+1]); } cout << dp[n] << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
0
64,043,921