code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
32
101M
#include <bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int N=s.size(); int zero=0,one=0; for(int i=0;i<N;i++){ if(s.at(i)=='0') zero++; else one++; } int ans=N-abs(zero-one); cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; #define int long long #define tc(t) int t; cin>>t; while(t--) #define f(n) for(int i=0;i<n;i++) #define endl "\n" int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin>>n>>m; vector<pair<int,string>>v(m); vector<pair<int,int>>dp(n,{0,0}); for(int i=0;i<m;i++){ int q; string verdict; cin>>q>>verdict; v[i]={q,verdict}; } int correct=0,penality=0; for(int i=0;i<m;i++) { int qn=v[i].first; string verdict=v[i].second; if(verdict=="WA") { if(dp[qn-1].second==0) {dp[qn-1].first++;} } else{ if(dp[qn-1].second==0) { dp[qn - 1].second = 1; correct++; penality+=dp[qn-1].first; } } } cout<<correct<<" "<<penality<<endl; }
0
11,799,638
#include <bits/stdc++.h> #include<iomanip> #define ll long long #define pb push_back #define mp make_pair #define MOD 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll a,b; cin >> a >> b; if(a%b) cout << a; else cout << -1; cout << "\n"; return 0; }
#include <iostream> #include <string> using namespace std; int main(){ string s,l,ss="#"; int a,now,nnow,cou; l="qwertasdfgzxcvb"; while(1){ cin>>s; if(s==ss)break; a=s.size(); if(l.find(s[0])==-1)now=0; else now=1; cou=0; for(int i=1;i<a;i++){ if(l.find(s[i])==-1)nnow=0; else nnow=1; if(now!=nnow){ cou++; now=nnow; } } cout << cou << endl; } return 0; }
0
74,058,059
#include <iostream> #include <vector> using namespace std; const int N_MAX = 100; bool P[N_MAX+1] = {false, false}; void sieve(int n) { fill(P+2, P+n+1, true); for (int i = 2; (long long)i*i <= n; ++i) { if (P[i]){ for (int j = i*i; j <= n; j += i) { P[j] = false; } } } } vector<pair<int,int>> prime_factorization_factorial(int n) { vector<pair<int, int>> v; for (int i = 2; i <= n; i++) { if (!P[i]) continue; int p = i, e = 0; while (p <= n) { e += n / p; p *= i; } v.emplace_back(i, e); } return v; } int main() { sieve(100); int n; cin >> n; int s[150] = {0}; auto v = prime_factorization_factorial(n); for (auto e : v) { s[e.second]++; } for (int i = 148; i >= 1; i--) { s[i] += s[i+1]; } int ans = 0; ans += s[4] * (s[4] - 1) / 2 * (s[2] - 2); ans += s[14] * (s[4] - 1); ans += s[24] * (s[2] - 1); ans += s[74]; cout << ans << endl; return 0; }
#include "bits/stdc++.h" #define pb push_back #define mp make_pair #define mt make_tuple #define endl '\n' #define F first #define S second #define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define cf ll testcases;cin>>testcases;while(testcases--) #define prn(x) if(x) cout<<"YES"<<endl; else cout<<"NO"<<endl; #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define minel(x) (*min_element(all(x))) #define maxel(x) (*max_element(all(x))) #define cou dbg=1;cout using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<ld> vd; typedef vector<pi> vp; ll dbg=0; template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p); template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p); template<typename A> istream& operator>>(istream& cin, vector<A> &v); int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; void solve(){ ll n; cin>>n; vi arr(n+1); for(ll i=1;i<=n;i++) cin>>arr[i]; vi dp(n+1,0); dp[2]=abs(arr[2]-arr[1]); for(ll i=3;i<=n;i++){ dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1])); } cout<<dp[n]<<endl; } int main(){ IO; solve(); return 0; } template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { if(dbg){ return cout << "(" << p.F << ", " << p.S << ")"; }else{ return cout<<p.F<<' '<<p.S; } dbg=0;} template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { if(dbg){ cout << "["; for(ll i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]"; }else{ for(ll i=0;i<v.size()-1;i++) cout<<v[i]<<' '; return cout<<v[v.size()-1]; dbg=0;} } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } template<typename A> istream& operator>>(istream& cin, vector<A> &v) { for(ll i=0;i<v.size()-1;i++) cin>>v[i]; return cin >> v[v.size()-1]; }
0
71,581,589
#include<bits/stdc++.h> using namespace std; typedef long long ll; #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<<29; const ll LINF = 1LL<<58; const int mod = 1000000007; int n; string table[310]; int check(int i){ for (int y = 1; y < n; y++) { for (int x = i; x - i < y; x++) { if(table[y][x % n] != table[x - i][(y + i) % n]) return 0; } } return 1; } int main(){ cin >> n; for (int i = 0; i < n; i++) cin >> table[i]; int ans = 0; for (int i = 0; i < n; i++) ans += check(i) * n; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; #define f first #define s second #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define rall(x) rbegin(x), rend(x) #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b); i >= (a); i--) #define R0F(i, a) ROF(i, 0, a-1) #define trav(x, a) for (auto& x: a) const int MX = 55; const int MOD = 1e9+7; const ll INF = 1061109567; const ld EPS = 1e-9; const ld PI = acos(-1); string arr[MX]; int it[MX]; string solve(string x, string y) { string res = ""; F0R(i,sz(x)) { F0R(j,sz(y)) { if (x[i] == y[j]) { res += x[i]; y[j] = ' '; break; } } } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N; cin >> N; F0R(i,N) { string x; cin >> x; arr[i] = x; } string res = arr[0]; FOR(i,1,N) { res = solve(res,arr[i]); } sort(all(res)); cout<< res << "\n"; }
0
43,904,004
#include<bits/stdc++.h> using namespace std; int main(){ int m,s,g,p[200]; while(cin>>m>>s>>g,m){ int ans=-1,an; for(int i=0;i<m;i++)cin>>p[i]; sort(p,p+m,greater<int>()); for(int i=g;i>=s;i--)if(ans<p[i-1]-p[i])ans=p[i-1]-p[i],an=i; cout<<an<<endl; } return 0; }
#include <iostream> #include <string> using namespace std; int mcxitoi(string s) { int res = 0; int t = 1; for (char c : s) { if (isdigit(c)) { t = c - '0'; } else { if (c == 'm') t *= 1000; else if (c == 'c') t *= 100; else if (c == 'x') t *= 10; res += t; t = 1; } } return res; } string sign(int x) { string res; if (x == 1) return res; res += '0' + x; return res; } string itomcxi(int x) { string res; if (x / 1000) res += sign(x / 1000) + "m"; x %= 1000; if (x / 100) res += sign(x / 100) + "c"; x %= 100; if (x / 10) res += sign(x / 10) + "x"; x %= 10; if (x) res += sign(x) + "i"; return res; } int main() { int n; cin >> n; while (n--) { string s1, s2; cin >> s1 >> s2; cout << itomcxi(mcxitoi(s1) + mcxitoi(s2)) << endl; } return 0; }
0
9,429,182
#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 whole(x) (x).begin(),(x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using P = pair<int, int>; #define debug(var) cerr << "[" << #var << "] " << var << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) const ll mod = 1000000007; const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1}; int main(){ int n; cin >> n; vector<string> w(n); rep(i, n) cin >> w[i]; string ans = "Yes"; rep(i, n-1) { if (w[i].back()!=w[i+1][0]) ans = "No"; } sort(whole(w)); rep(i, n-1) { if (w[i]==w[i+1]) ans = "No"; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >>n; vector<long long>a(n),b(n),c(n,0),d(n,0); for(int i=0;i<n;i++)cin>>a[i]; for(int i=0;i<n;i++)cin>>b[i]; for(int i=0;i<n;i++){ if(a[i]-b[i]<0)c[i]=a[i]-b[i]; else if(a[i]-b[i]>0)d[i]=a[i]-b[i]; } sort(c.begin(),c.end()); sort(d.rbegin(),d.rend()); long long count=0; long long sum=0; for(int i=0;i<n;i++){ if(c[i]==0)break; sum+=c[i]; count++; } for(int i=0;i<n;i++){ if(d[i]==0||sum>=0)break; sum+=d[i]; count++; if(sum>=0)break; } if(sum<0){ cout<<-1<<endl; }else{ cout<<count<<endl; } return 0; }
0
5,896,118
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, m, n) for (int i = m; i < n; i++) #define ALL(v) v.begin(), v.end() using ll = long long; using ull = unsigned long long; using namespace std; int main() { int N, result = 0; cin >> N; REP(i, N) { result += i+1; } cout << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pii pair<int , int> #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define MAXX 1005 int gcd(int a , int b){ while(a > 0 && b > 0){ if(a > b) a %= b; else b %= a; } return a + b; } int a , b , k; int main() { _FastIO; cin >> a >> b >> k; int n = gcd(a , b); vector<int> v; for(int i = 1; i * i <= n; i++){ if(n % i == 0){ v.push_back(i); if(i * i != n){ v.push_back(n / i); } } } sort(v.begin() , v.end()); reverse(v.begin() , v.end()); cout <<v[k - 1] << endl; return 0; }
0
12,530,373
#include<iostream> #include<string> #include<cstdio> #include<vector> using namespace std; int main(void) { string s; int h = 0; cin>>s; vector<int> dp(1<<26,1e9); dp[0] = 0; for(int i = 0;i < s.size();i++) { int bit = s[i] - 'a'; h = h ^ (1<<bit); for(int j = 0;j < 26;j++) { dp[h] = min(dp[h],dp[h^(1<<j)]+1); } } cout<<max(1,dp[h])<<endl; return 0; }
#include<iostream> using namespace std; int main(){ int n , a[10000] ; long min =0 , max = 0 , sum = 0 ; cin >> n ; cin >>a[1] ; min = a[1] ; max = a[1] ; sum = a[1] ; for (int i = 2 ; i <= n ; i = i + 1 ) { cin >>a[i] ; if ( min > a[i] ){ min = a[i] ; }else{ } if ( max < a[i] ){ max = a[i] ; }else{ } sum = sum + a[i] ; } cout << min << " " << max << " " << sum << endl; return 0; }
0
28,207,689
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { ll N, K; cin >> N >> K; vector<P> p; rep(i, N){ int a, b; cin >> a >> b; p.push_back(make_pair(a, b)); } sort(p.begin(), p.end()); ll now = 0; for (auto f : p){ int x = f.first; int y = f.second; now += y; if(now >= K){ cout << x << endl; break; } } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define rep(i,n) for(int i = 0;i < n;i++) #define NIL = -1; #define all(x) x.begin(),x.end() const ll INF = 1e9; const ll mod = 1e9 + 7; int digit(ll x) { if (x / 10 == 0) return 1; return digit(x / 10) + 1; } ll gcd(long long a,long long b) { if (a < b) swap(a,b); if (b == 0) return a; return gcd(b,a%b); } bool is_prime(long long N){ if (N == 1) return false; for (long long i = 2;i * i <= N;i++){ if (N % i == 0) return false; } return true; } ll lcm(ll a,ll b){ return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b); } double DegreeToRadian(double degree){ return degree * M_PI / 180.0; } int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; bool ok(string S, string T){ for (int i = 0;i < S.size();i++){ if (S[i] != '?' && S[i] != T[i]){ return false; } } return true; } int main(){ string s,t,out = "~"; cin >> s >> t; if (s.size() < t.size()){ cout << "UNRESTORABLE" << endl; return 0; } for (int i = 0;i <= s.size() - t.size();i++){ string tmp = s.substr(i, t.size()); if (ok(tmp, t)){ string rep = s; for (int j = 0;j < i;j++){ if (rep[j] == '?'){ rep[j] = 'a'; } } for (int j = i;j < i + t.size();j++){ rep[j] = t[j-i]; } for (int j = i + t.size();j < rep.size();j++){ if (rep[j] == '?'){ rep[j] = 'a'; } } out = min(out, rep); } } if (out == "~"){ cout << "UNRESTORABLE" << endl; } else { cout << out << endl; } }
0
53,243,601
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> p; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; s[5] = ' '; s[13] = ' '; cout << s << endl; }
#include <iostream> #include <vector> #include <algorithm> #include <iterator> #include <queue> #include <stack> #include <map> #include <set> #include <string> #include <cmath> using namespace std; #define MOD 1000000007 #define INF 1<<30 #define LINF (ll)1<<62 #define MAX 510000 #define rep(i,n) for(ll i=0; i<(n); i++) #define REP(i,a,b) for(ll i=(a); i<(b); i++) #define all(x) (x).begin(),(x).end() #define uni(q) unique(all(q)),q.end() using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll, ll> P; typedef vector<pair<ll, ll>> vpl; int main(){ ll match[10] = {0,2,5,5,4,5,6,3,7,6}; ll n,m; cin >> n >> m; vvl v(10); vl a(m); rep(i,m){ cin >> a[i]; v[match[a[i]]].push_back(a[i]); } sort(a.rbegin(), a.rend()); rep(i,10) sort(v[i].rbegin(), v[i].rend()); vl dp(n+1,0); rep(i,n){ if(i != 0 && dp[i]==0) continue; rep(j,m){ ll c = match[a[j]]; if(i+c<=n){ if(dp[i+c] <= dp[i]){ dp[i+c] = dp[i] + 1; } } } } ll index = n; vl ans; while(index != 0){ rep(i,m){ if(dp[index] - dp[index-match[a[i]]] == 1){ if(index-match[a[i]]!=0 && dp[index-match[a[i]]]==0) continue; ans.push_back(a[i]); index -= match[a[i]]; break; } } } for(auto i : ans) cout << i; cout << endl; }
0
87,460,081
#include <cstdio> #include <cstdint> #include <vector> #include <algorithm> using namespace std; uint32_t n; vector<uint32_t> v; void solve() { sort(v.begin(), v.end()); double ave = (v[0]+v[1])/2.0; for (int i=2;i<n;i++) { ave = (ave + v[i])/2.0; } printf("%lf\n", ave); } int main() { scanf("%d", &n); v.resize(n); for (int i=0;i<n;i++) { scanf("%d", &v[i]); } solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int main() { ll N,C,K; cin >> N >> C >> K; vector<ll> T(N); rep(i,N){ cin >> T.at(i); } ll bus = 0; sort(T.begin(),T.end()); for( ll p = 0;p<N;p++){ ll q = p; while(T.at(q) <= T.at(p) + K){ q++; if(q - p == C){ break; } if(q == N ){ break; } } bus++; p = q - 1; } cout << bus << endl; }
0
59,765,526
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { ll a,b,c; cin>>a>>b>>c; string s=""; s+=(a+'0'); s+=(b+'0'); s+=(c+'0'); sort(s.rbegin(),s.rend()); ll ans=((s[0]-'0')*10)+(s[1]-'0'); ll k=s[2]-'0'; cout<<ans+k<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; const int INF = 1 << 30; const ll LINF = 1ll << 50; const int NIL = -1; const int MAX = 10000; const int mod = 1000000007; const double pi = 3.141592653589; double T; int main(){ ll N, K; cin >> N >> K; vector<pll> v(N); ll t, d; for (int i = 0; i < N; i++) { cin >> t >> d; v[i] = pll(d, t); } sort(v.begin(), v.end(), greater<pll>()); priority_queue<ll> PQ; set<ll> S; ll sum = 0; ll kind = 0; for (int i = 0; i < K; i++) { sum += v[i].first; if (S.count(v[i].second) == 0) { S.insert(v[i].second); kind++; } else { PQ.push(-v[i].first); } } ll ans = sum + kind * kind; for (int i = K; i < N; i++) { if (PQ.empty()) break; if (S.count(v[i].second) == 0) { sum += PQ.top(); PQ.pop(); sum += v[i].first; kind++; S.insert(v[i].second); ans = max(ans, sum + kind * kind); } } cout << ans << '\n'; }
0
64,614,299
#include<bits/stdc++.h> #include<string> #include<vector> using namespace std; typedef pair<int, int>P; typedef long long ll; #define rep(i,n)for(ll i=0;i<n;++i) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll MOD = 1000000007; const ll INF = 1e16; const ll MAX_N = 5000100; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { if (x == 0 || y == 0)return 0; return (x / gcd(x, y) * y); } ll fac[MAX_N], finv[MAX_N], inv[MAX_N]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX_N; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll dx[8] = { 0,0,-1,1 }; ll dy[8] = { -1,1,0,0 }; ll dp[101010]; ll par[101010]; ll rank2[101010]; void init(ll n) { rep(i, n) { par[i] = i; rank2[i] = 0; } } ll find(ll x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y)return; if (rank2[x] < rank2[y]) { par[x] = y; } else { par[y] = x; if (rank2[x] == rank2[y]) { rank2[x]++; } } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } bool graph[101][101]; bool visit[101]; vector<ll> to[101010]; int main() { ll n; cin >> n; vector<ll>a(n); rep(i, n) { cin >> a[i]; a[i]--; } ll ans = 0; rep(i, n) { if (a[a[i]] == i)ans++; } ans /= 2; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) #define all(v) v.begin(),v.end() #define len(x) (ll)(x).length() using namespace std; typedef long long ll; typedef pair<int,int> P; const int INF=1e9; const ll INFS=1e18; const int MOD=INF+7; const int di[] = {-1,0,1,0}; const int dj[] = {0,-1,0,1}; const double PI=acos(-1); int main() { int n,m; cin>>n>>m; vector<int> h(n); rep(i,n) cin>>h[i]; vector<bool> ja(n,true); rep(i,m){ int a,b; cin>>a>>b; a--; b--; if(h[a]==h[b]){ ja[a]=false; ja[b]=false; } if(h[a]<h[b]){ ja[a]=false; } if(h[a]>h[b]){ ja[b]=false; } } int ans=0; rep(i,n){ if(ja[i]) ans++; } cout<<ans<<endl; }
0
56,879,646
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) typedef long long ll; typedef pair<int, int> P; const int INF = 100100100; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int main() { string S; cin >> S; ll ans = 0; ll cnt = 0; REP(i,S.size()){ if(S[i]=='B'){ cnt++; }else{ ans += cnt; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std ; int main(){ int a ; cin >> a ; long long int n[a] ; long long int sum = 0 ; for(int i=0;i < a;i++){ cin >> n[i] ; if(i > 0 && n[i] < n[i-1]){ sum += n[i-1] - n[i] ; n[i] = n[i-1] ; } } cout << sum << endl ; return 0 ; }
0
21,248,920
#include <iostream> #include <algorithm> #include<cmath> #include<cstring> #include<cstdio> #include<cstdlib> #include<vector> #include<iomanip> #include<ctime> #include<set> #include<map> #include<queue> #include<stack> #define sqr(x) ((x)*(x)) #define fz1(i,n) for ((i)=1;(i)<=(n);(i)++) #define fd1(i,n) for ((i)=(n);(i)>=1;(i)--) #define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++) #define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--) #define fz0k(i,n) for ((i)=0;(i)<(n);(i)++) #define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--) #define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++) #define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--) #define fzin fz1(i,n) #define fzim fz1(i,m) #define fzjn fz1(j,n) #define fzjm fz1(j,m) #define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++) #define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;} #define inc(x,y) {x+=(y);if(x>=mod)x-=mod;} #define dec(x,y) {x-=(y);if(x<0)x+=mod;} #define spln(i,n) (i==n?'\n':' ') using namespace std; long long n,m,i,j,a[200005],pre[200005],suf[200005],ans; int main() { scanf("%lld%lld",&n,&m); fz1(i,n){ scanf("%lld",&a[i]); pre[i]=pre[i-1]+max(a[i],0ll); } fd1(i,n){ suf[i]=suf[i+1]+max(a[i],0ll); } fz1(i,n){ a[i]+=a[i-1]; } fz1(i,n-m+1){ ans=max(ans,a[i+m-1]-a[i-1]+pre[i-1]+suf[i+m]); ans=max(ans,pre[i-1]+suf[i+m]); } cout<<ans<<endl; return 0; }
#include<iostream> #include<map> #include<vector> #include<array> const int DiceSizeFace = 6; using namespace std; using DiceSides = map<int, array<int, 4>>; using Labels = map<int, int>; int main() { DiceSides sides = { {1, {5, 3, 2, 4}}, {2, {1, 3, 6, 4}}, {3, {1, 5, 6, 2}}, {4, {1, 2, 6, 5}}, {5, {1, 4, 6, 3}}, {6, {5, 4, 2, 3}}, }; Labels label_to_value_list; Labels value_to_label_list; for(int i = 1; i <= DiceSizeFace; i++) { cin >> label_to_value_list[i]; value_to_label_list[label_to_value_list[i]] = i; } int question_size; cin >> question_size; for(int i = 0; i < question_size; i++) { int top_label, face_label; int top_value, face_value; cin >> top_value >> face_value; top_label = value_to_label_list[top_value]; face_label = value_to_label_list[face_value]; int right_label; for(int j = 0; j < sides[top_label].size(); j++) { if(sides[top_label][j] == face_label) { int right_labe_index = (j - 1 + sides[top_label].size()) % sides[top_label].size(); right_label = sides[top_label][right_labe_index]; break; } } cout << label_to_value_list[right_label] << endl; } }
0
47,100,006
#include<cstdio> int main(){ int a,b; while(1){ scanf("%d %d",&a,&b); if((a == 0)&&(b == 0)) break; if(a<b){ printf("%d %d\n",a,b); }else{ printf("%d %d\n",b,a); } } return 0; }
#include <bits/stdc++.h> #include <iostream> #include <queue> #include <stack> #include <vector> #include <string> #include <set> #include <map> #include <random> #define rep(i,n) for (int i = 0; i < (n); ++i) #define repp(i,n,m) for (int i = m; i < (n); ++i) #define repl(i,n) for (long long i = 0; i < (n); ++i) #define reppl(i,n,m) for (long long i = m; i < (n); ++i) using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PL = pair<long long, long long>; using Pxy = pair<double, double>; using T = tuple<int, int, bool>; const int INF = 1001001007; const int mod = 1000000007; const int MOD = 998244353; const ll inf = 1e18; template <typename AT> void printvec(vector<AT> &ar){ rep(i,ar.size()-1) cout << ar[i] << " "; cout << ar[ar.size()-1] << endl; } template <typename Q> void printvvec(vector<vector<Q>> &ar){ rep(i,ar.size()){ rep(j,ar[0].size()-1) cout << ar[i][j] << " "; cout << ar[i][ar[0].size()-1] << endl; } } template <typename S> bool range(S a, S b, S x){ return (a <= x && x < b); } void yes(){ cout << "Yes" << endl; } void no (){ cout << "No" << endl; } ll cel (ll a, ll b){ if (a % b == 0) return a / b; else return a / b + 1; } ll gcds(ll a, ll b){ ll c = a % b; while (c != 0){ a = b; b = c; c = a % b; } return b; } int main() { int n, m, x, y; cin >> n >> m >> x >> y; int xm = -200; rep(i,n){ int a; cin >> a; xm = max(xm,a); } int ym = 200; rep(i,m){ int b; cin >> b; ym = min(ym,b); } if (xm >= ym){ cout << "War" << endl; return 0; } bool t = true; repp(i,ym+1,xm+1){ if (x < i && i <= y){ cout << "No War" << endl; t = false; return 0; } } if (t) cout << "War" << endl; }
0
16,176,708
#include <bits/stdc++.h> using namespace std; int main () { long long n, m, d; cin >> n >> m >> d; long long k; if (n-1 < d+d || d == 0) { k = 0; } else { k = n-d-d; } long double a = (n+k)*(m-1); a /= n*n; printf("%.10Lf\n", a); }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, from, to) for (ll 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() #define pb push_back using ll = long long; using ld=long double; using vin=vector<int>; using vvin=vector<vin>; using vll=vector<ll>; using vvll=vector<vll>; using vst=vector<string>; using P = pair<ll,ll>; const int inf=1e9+7; const ll INF=9e18; const long double PI = acos(-1.0); template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;} template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;} template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } const int dx[4] = { 1, 0, -1, 0 }; const int dy[4] = { 0, 1, 0, -1 }; int main(){cout<<fixed<<setprecision(20); ll m; cin>>m; vll d(m),c(m); ll ans=0; rep(i,0,m){ cin>>d[i]>>c[i]; ans+=c[i]; } ll cnt=0; rep(i,0,m){ cnt+=d[i]*c[i]; while(cnt>=10){ ll c=cnt/10; ans+=c; cnt%=10; cnt+=c; } } cout<<ans-1<<endl; }
0
32,560,790
#include<stdio.h> void swap(int *a,int *b,int *c){ int temp=*a; *a=*b; *b=temp; (*c)++; } int main(){ int i,n,j,k,count=0,flag; int a[101]; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n-1;i++){ int min=a[i]; for(j=i+1;j<n;j++){ if(min>a[j]){ min=a[j]; flag=j; } } if(min<a[i]) swap(&a[i],&a[flag],&count); } for(i=0;i<n-1;i++){ printf("%d ",a[i]); } printf("%d\n",a[i]); printf("%d\n",count); }
#include<bits/stdc++.h> using namespace std; int a[101][101],num[101],dis[101]; bool vis[101]; int n,u,k,x,t=1; queue<int> q; int main(){ memset(a,0,sizeof(a)); memset(vis,false,sizeof(vis)); memset(dis,0x1f1f1f1f,sizeof(dis)); cin>>n; for (int i=0; i<n; i++){ cin>>u>>k; num[u]=k; int j=0; while (k--){ cin>>x; a[u][++j]=x; } } q.push(1); dis[1]=0; while (!q.empty()){ x=q.front(); q.pop(); vis[x]=true; for (int i=1; i<=num[x]; i++){ if (!vis[a[x][i]]){ dis[a[x][i]]=min(dis[a[x][i]],dis[x]+1); q.push(a[x][i]); } } } for (int i=1; i<=n; i++){ cout<<i<<' '; if (dis[i]==0x1f1f1f1f) dis[i]=-1; cout<<dis[i]<<endl; } return 0; }
0
70,143,224
#include<bits/stdc++.h> using namespace std; int lower_case(char x[],int n,bool b){ for(int i=0;i<n;i++) if(x[i]>=65&&x[i]<=90) {b=1;break;} return b;} int main(){ string s,t,u; int a,p; bool b = 0; cin>>s>>t; int n = s.length(),m=t.length(); int x1,x2; char x[n+1],y[m+1]; strcpy(x,s.c_str());strcpy(y,t.c_str()); x1=lower_case(x,n,b); x2=lower_case(y,m,b); if(x1==0&&x2==0&&n<=100&&m<=100&&n>=1&&m>=1){ cout<<t+s<<endl; } return 0;}
#include <bits/stdc++.h> #define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a) #define rep2(i, s, n) rep3(i, s, n, 1) #define rep(i, n) rep2(i, 0, n) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; int main(){ ll n; cin >> n; ll mid = sqrt(n); for(ll i=mid;i>0;i--){ if(i*(n/i)==n){ cout << i - 1 + n / i - 1 << endl; break; } } return 0; }
0
25,625,768
#include<iostream> #include<vector> #include<algorithm> #include<map> using namespace std; int main() { ios_base :: sync_with_stdio(0); cin.tie(0); int a, b, m; cin >> a >> b >> m; vector<int> p; int i; int minp, minq; for(i=0; i<a; i++){ int n; cin >> n; p.push_back(n); } vector<int> q; for(i=0; i<b; i++){ int n; cin >> n; q.push_back(n); } minp = *min_element(p.begin(), p.end()); minq = *min_element(q.begin(), q.end()); int ans = minp+minq; for(i=0; i<m; i++){ int j, k, l; cin >> j >> k >> l; j--, k--; ans = min(ans, p[j]+q[k]-l); } cout << ans << endl; return 0; }
#include "bits/stdc++.h" #define int long long #define endl '\n' using namespace std; typedef long long ll; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl; #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 1e9 + 7; const ll N = 2e5 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); signed main() { ios_base::sync_with_stdio(false); cin.tie(0); readc(n, a, b); readarr(p, n); int x = 0, y = 0, z = 0; FOR (i, 1, n) if (p[i] <= a) x++; else if (p[i] <= b) y++; else z++; cout << min({x, y, z}); }
0
53,420,911
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main(){ ll a, b, c; ll k; cin >> a >> b >> c >> k; int ans = 0; if(k % 2 == 0) ans = a - b; else ans = b - a; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> p(n), q(n), r(n); for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++) cin >> q[i]; iota (r.begin(), r.end(), 1); bool pf = true, qf = true; int a, b; for (int i = 1; pf || qf; i++) { if (p == r) { a = i; pf = false; } if (q == r) { b = i; qf = false; } next_permutation (r.begin(), r.end()); } cout << abs(a-b) << endl; }
0
73,535,704
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define ArraySizeOf(array) (sizeof(array) / sizeof(array[0])) #define res(i,n) for(int i=n;;i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for(int i=1;i<n;i++) #define rev(i,n) for(int i=n-1;i>=0;i--) #define REV(i,n) for(int i=n-1;i>0;i--) #define req(i,n,m) for(int i=n;i<m;i++) #define REQ(i,n,m,l) for(int i=n;i<m;i+=l) #define _GLIBCXX_DEBUG int INF = 1e9 + 7; int mod = 998244353; long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117; unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1) { unsigned day; if (dow < dow1) dow += 7; day = dow - dow1; day += 7 * n - 6; return day; } signed gcd(long long x, long long y) { if (y == 0)return x; return gcd(y, x % y); } signed lcm(long long x, long long y) { return x / gcd(x, y) * y; } unsigned DayToWeekNumber(unsigned day) { return (day - 1) / 7 + 1; } unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0) { return (dow0 + 35 + day - day0) % 7; } #define int long long using namespace std; signed ae(long long b, long long c) { if (c == 1)return b; return (ae(b, c - 1)*b)%mod; } signed main() { int N; cin >> N; vector<long long>D(N); vector<long long>count(N); long long A = 0; rep(i, N) { cin >> D[i]; count[D[i]]++; A = max(A, D[i]); } if (count[0] != 1||D[0]!=0) { puts ("0"); return 0; } long long ans = 1; REP(i, A + 1) { if (count[i] == 0) { puts("0"); return 0; } ans *= ae(count[i-1],count[i]); ans %= mod; } cout <<ans << endl; }
#include<algorithm> #include<bitset> #include<cassert> #include<cfloat> #include<climits> #include<cmath> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<map> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> #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 SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template<typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) { t = v; } template<typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) { for (auto& e : t) fill_v(e, v); } 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; } #define ARRAY_MAX 100005 const int INF = 1e9 + 7; const ll MOD = 1e9 + 7; int dx[4] = { 1,0,0,-1 }; int dy[4] = { 0,1,-1,0 }; typedef struct union_find{ vector<ll> pa; vector<ll> ra; vector<ll> siz; void init(ll n){ pa.resize(n); ra.resize(n); siz.resize(n); for(ll i = 0;i < n;i++){ pa[i] = i; ra[i] = 0LL; siz[i] = 1LL; } } ll find(ll x){ if(pa[x] == x){ return x; }else{ return pa[x] = find(pa[x]); } } void unite(ll x,ll y){ x = find(x); y = find(y); if(x == y){ return; } pa[y] = x; siz[x] += siz[y]; } bool same(ll x,ll y){ return find(x) == find(y); } }UF; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int n,m; cin >> n >> m; vector<int> p(n); for (int i = 0; i < n; i++) { cin >> p[i]; p[i]--; } UF tree; tree.init(n+10); for (int i = 0; i < m; i++) { int x,y; cin >> x >> y; x--; y--; if(x > y){ swap(x,y); } tree.unite(x,y); } int cnt = 0; for (int i = 0; i < n; i++) { if(tree.same(i,p[i])){ cnt++; } } cout << cnt << endl; return 0; }
0
93,338,145
#include <bits/stdc++.h> using namespace std; int main() { int N,Q; cin >> N >>Q; int64_t ans=-1; if(N==Q||Q==1) { cout << ans <<endl; } else { int co=1; ans=N; bool chk=true; while (chk) { if(!(ans%Q==0)) { chk=false; } else { co++; ans=ans*co; } if(abs(ans)>1e18) { cout << -1 <<endl; return 0; } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; #define Gene template< class #define Rics printer& operator, Gene c> struct rge{c b, e;}; Gene c> rge<c> range(c i, c j){ return {i, j};} struct printer{ ~printer(){cerr<<endl;} Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;} Rics(string x){cerr<<x;return *this;} Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";} Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));} Gene c >Rics(rge<c> x){ *this,"["; for(auto it = x.b; it != x.e; ++it) *this,(it==x.b?"":", "),*it; return *this,"]";} }; #define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer() #define dbg(x) "[",#x,": ",(x),"] " mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int my_rand(int l, int r) { return uniform_int_distribution<int>(l, r) (rng); } const int N = 1e5+100; vector<int> g[N]; int a[N]; long long dp[N]; void dfs(int u, int p) { if(g[u].size() == 1) { dp[u] = a[u]; return; } long long sum = 0; vector<long long> all; for(int v : g[u]) { if(v == p) continue; dfs(v, u); sum += dp[v]; all.push_back(dp[v]); } sort(all.begin(), all.end()); long long pairs = 0; if(all.size() >= 2) { long long mx = all.back(); long long other = sum-mx; if(other >= mx) pairs = sum/2; else pairs = other; } long long req_pair = sum-a[u]; if(req_pair >= 0 && req_pair <= pairs) { dp[u] = sum - 2*req_pair; } else { cout << "NO" << endl; exit(0); } } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } if(n == 2) { if(a[1] == a[2]) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; } int root = -1; for(int i = 1; i <= n; i++) { if(g[i].size() > 1) { root = i; break; } } dfs(root, -1); if(dp[root] == 0) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
0
99,933,976
#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> using namespace std; int main(){ int A,B,C,D; cin >> A >> B >> C >> D; if(abs(C-A) <= D){ cout << "Yes" << endl; } else if(abs(C-B) <= D && abs(A-B) <= D){ cout << "Yes" << endl; } else cout << "No" << endl; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; const ll MAX_N = 100010; int main() { ll n; cin >> n; vl a(n); rep(i, n) { cin >> a[i]; } sort(all(a)); ll M; vl x(n-1), y(n-1); if(a[n-1] <= 0) { M = a[n-1]; rep(i, n-1) { x[i] = M; y[i] = a[i]; M -= a[i]; } } else if(0 <= a[0]) { M = a[0]; rep(i, n-2) { x[i] = M; y[i] = a[i+1]; M -= a[i+1]; } x[n-2] = a[n-1]; y[n-2] = M; M = a[n-1] - M; } else { sort(rall(a)); ll k; rep(i, n) { if(a[i] < 0) { k = i; break; } } ll t = a[n-1]; rep(i, k-1) { x[i] = t; y[i] = a[i+1]; t -= a[i+1]; } M = a[0]; x[k-1] = M; y[k-1] = t; M -= t; exrep(i, k, n-2) { x[i] = M; y[i] = a[i]; M -= a[i]; } } out(M); rep(i, n-1) { cout << x[i] << " " << y[i] << "\n"; } re0; }
0
65,432,237
#include <iostream> #include <vector> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <iomanip> #include <numeric> #include <queue> #include <cmath> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> a, b; for (int i = 0; i < n; i++) { string s; cin >> s; a.push_back(s); } for (int i = 0; i < m; i++) { string s; cin >> s; b.push_back(s); } for (int i = 0; i + m - 1 < n; i++) { for (int j = 0; j + m - 1 < n; j++) { int flag = 1; for (int x = 0; x < m; x++) { for (int y = 0; y < m; y++) { if (b[x][y] != a[i + x][j + y]) { flag = 0; break; } } } if (flag == 1) { cout << "Yes" << endl; return 0; } } } cout << "No" << endl; }
#include <iostream> #include <algorithm> using namespace std; bool isRTri(int a, int b, int c) { return a * a + b * b == c * c; } int main() { int n; cin >> n; for (int k = 1; k <= n; k++) { int a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); bool r = isRTri(a[0], a[1], a[2]); cout << (r ? "YES" : "NO") << endl; } return 0; }
0
17,869,200
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if(a % b == 0) { return b; } else { return gcd(b, a % b); } } int lcm(int a, int b){ return a * b / gcd(a, b); } int main() { int x; int ans; cin >> x; cout << lcm(360, x) / x << endl; }
#include <iostream> #include <algorithm> #include <cmath> #include <set> #include <string> #include <vector> #include <iomanip> #include <map> using namespace std; #define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); typedef long long ll; typedef long double ld; const ll SIZE = 1e5 * 3 + 10; int main() { fastInp; ll m, k; cin >> m >> k; ll nms = (1ll << m), x = 0; if (k == 0) { for (int i = 0; i < nms; i++) { cout << i << " " << i << " "; } return 0; } for (int i = 0; i < nms; i++) { if (k != i) { x ^= i; } } if (x != k) { cout << "-1"; return 0; } for (int i = 0; i < nms; i++) { if (k != i) cout << i << " "; } cout << k << " "; for (int i = nms - 1; i >= 0; i--) { if (k != i) cout << i << " "; } cout << k << " "; return 0; }
0
97,160,360
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define INF 1145141919810893364 #define PI 3.141592653589 typedef pair<int,int> PP; typedef long long ll; #define int ll #define setdouble setprecision #define REP(i,n) for(int i=0;i<(n);++i) #define OREP(i,n) for(int i=1;i<=(n);++i) #define RREP(i,n) for(int i=(n)-1;i>=0;--i) #define GOODBYE do { cout << "Impossible" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl signed main(void){ int N; int a; vector<int> A; int B[114]={}; cin >> N; REP(i,N){ cin >> a; A.push_back(a); B[a]++; } sort(A.begin(),A.end()); int K=A[N-1]; if(B[K]<2)GOODBYE; for(int i=K;i>(K+1)/2;i--){ B[i]-=2; if(B[i]<0)GOODBYE; } B[(K+1)/2]--;if(K%2==1){B[(K+1)/2]--;} if(B[(K+1)/2]<0)GOODBYE; REP(i,N){ if(i<=(K+1)/2 && B[i]>0)GOODBYE; } cout << "Possible" << endl; return 0; }
#include "bits/stdc++.h" #define REP(i,num) for(int i=0;i<(num);++i) #define LOOP(i) while(i--) #define ALL(c) c.begin(),c.end() #define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl; #define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;} using namespace std; using ll = long long; constexpr ll atcoder_mod = 1e9+7; template<typename T=int> T in(){T x; cin >> x; return (x);} template<typename T=int,typename C=vector<T>> C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);} void vout(){cout << endl;} template<typename Head,typename... Tail> void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);} void out(){cout << endl;} template<typename Head,typename... Tail> void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);} class ConnectNodeInfo{ vector<vector<pair<ll,ll>>> graph; public: ConnectNodeInfo(int node_num){ graph.resize(node_num); } void AddNonDirectionalConnection(ll u,ll v,ll w){ graph[u].emplace_back(v,w); graph[v].emplace_back(u,w); } void AddDirectionalConnection(ll u,ll v,ll w){ graph[u].emplace_back(v,w); } vector<pair<ll,ll>>& operator[](ll index){ return graph[index]; } size_t size(){return graph.size();} }; class Dijkstra{ using Point = pair<ll,ll>; vector<ll> dist; public: void CalcShortestPath(int start,ConnectNodeInfo& connect){ dist.resize(connect.size(),1LL<<60); dist[start] = 0; priority_queue<Point,vector<Point>,greater<Point>> Q; Q.emplace(0,start); while(!Q.empty()){ auto p = Q.top(); Q.pop(); int v = p.second; if(dist[v]<p.first){ continue; } for(auto e:connect[v]){ if(dist[e.first]>dist[v]+e.second){ dist[e.first] = dist[v]+e.second; Q.emplace(dist[e.first],e.first); } } } } ll GetDistance(int i){ return dist[i]; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); int N=in(); ConnectNodeInfo connect(N); REP(i,N-1){ int a=in()-1,b=in()-1,c=in(); connect.AddNonDirectionalConnection(a,b,c); } int Q=in(),K=in()-1; Dijkstra Dij; Dij.CalcShortestPath(K,connect); LOOP(Q){ int x=in()-1,y=in()-1; out(Dij.GetDistance(x)+Dij.GetDistance(y)); } return 0; }
0
97,059,801
#include <iostream> using namespace std; int fib(int n){ int ans[45] = {1,1},i; for(i=2;i<=n;i++){ ans[i] = ans[i-1]+ans[i-2]; } return ans[n]; } int main() { int n; cin >> n; cout << fib(n) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12); #define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define newl cout<<"\n" #define DISP(as) for(auto it : as) cout<<it<<" ";newl; #define all(x) (x).begin(),(x).end() #define mset(x,val) memset(x,val,sizeof(x)) #define newl cout<<"\n" #define pb push_back #define mp make_pair #define f first #define s second #define dline cerr<<" #define deb1(x) cerr<<#x<<" = "<<x<<'\n'; #define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n'; #define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n'; typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll , ll> pll; typedef pair<ld, ld> pld; typedef unordered_map<ll, ll> um; typedef vector<pll> vpll; const ll MAX5 = 1e+5 + 7; const ll MAX7 = 1e+7 + 7; const ll MAXN = MAX7; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const ll MOD = 1e+9 + 7; ll T = 1; ll n, x, m, y, k; string s, t; void MAIN() { cin >> n; vll a(n); for (ll i = 0; i < n; i++) cin >> a[i]; ll cou = 0; while (*max_element(all(a)) > 0) { for (ll i = 0; i < n; i++) { if((i == 0 || a[i-1]==0) && a[i]) { cou++; } } for(ll i=0;i<n;i++) { if(a[i]) a[i]--; } } cout<<cou; } int main() { fastio; randomINT; while (T--) { MAIN(); } return 0; }
0
81,881,909
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef vector<string> VS; typedef pair<int, int> P; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define EXIST(m,v) (m).find((v)) != (m).end() #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL<<60; constexpr long long MOD = 1000000007; #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } void Main(){ int k, a, b; cin >> k >> a >> b; FOR(i, a, b+1) if(i % k == 0) { cout << "OK" << en; return; } cout << "NG" << en; return; } int main(void){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; REP(_,t) Main(); return 0; }
#include <cstdio> #include <iostream> #include <cassert> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <cmath> #include <deque> #include <unordered_map> #define IOS ios_base::sync_with_stdio(0); cin.tie(0) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; const int MAXN = 234567; vector<int> G[MAXN]; int main() { int N; scanf("%d", &N); for (int i = 0; i < N - 1; i++) { int u, v; scanf("%d %d", &u, &v); if (v < u) swap(u, v); G[u].push_back(v); } LL ans = 0; for (int i = 1; i <= N; i++) { LL len = (N - i + 1); ans += len * (len + 1) / 2; } for (int i = 1; i <= N; i++) { for (int j : G[i]) { ans -= (LL)i * (N - j + 1); } } printf("%lld\n", ans); return 0; }
0
89,564,696
#include<iostream> #include<vector> using namespace std; int main(){ int ans = 0; int N; std::cin >> N; vector<int> tako(N); for(int i = 0; i < N; i++){ std::cin >> tako[i]; } for(int i = 0; i < N-1; i++){ for(int j = i+1; j < N; j++){ ans = ans + tako[i]*tako[j]; } } std::cout << ans; }
#include <bits/stdc++.h> #define long long long int using namespace std; const long MOD = 1000000007; long power(long a, long b) { long res = 1; while (b > 0) { if (b & 1) { res *= a; res %= MOD; } a *= a; a %= MOD; b >>= 1; } return res; } int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<long> cnt(k + 1); for (int d = 1; d <= k; d++) { cnt[d] = power(k / d, n); } for (int d = k; d >= 1; d--) { for (int x = 2; d * x <= k; x++) { cnt[d] -= cnt[d * x]; if (cnt[d] < 0) cnt[d] += MOD; } } long res = 0; for (int d = 1; d <= k; d++) { res += d * cnt[d]; res %= MOD; } cout << res << "\n"; return 0; }
0
85,580,659
#include <cstdio> #include <cstring> using namespace std; #define MAX_L 16 int table[MAX_L + 1][MAX_L + 1]; bool wall[MAX_L + 1][MAX_L + 1]; int a, b, n; int main(){ while(1){ scanf("%d%d", &a, &b); if(a == 0 && b == 0) return 0; scanf("%d", &n); int in_x, in_y; memset(wall, 0, sizeof(wall)); for(int i = 0; i < n; i++){ scanf("%d%d", &in_x, &in_y); wall[in_x][in_y] = true; } memset(table, 0, sizeof(table)); table[1][1] = 1; for(int y = 1; y <= b; y++){ for(int x = 1; x <= a; x++){ if(wall[x][y] || (x == 1 && y == 1)) continue; table[x][y] = table[x - 1][y] + table[x][y - 1]; } } printf("%d\n", table[a][b]); } }
#include<bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; using Pii = pair<int, int>; using Pll = pair<ll, ll>; #define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i) #define ALL(x) (x).begin(),(x).end() #define pb push_back ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} 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; } char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int main(){ int n; cin >> n; string s; cin >> s; int k; cin >> k; char x = s[k-1]; REP(i, 0, n){ if(s[i] != x){ s[i] = '*'; }else{ continue; } } cout << s << endl; }
0
10,300,775
#include<stdio.h> int main(){ int angka, digitBelakang, digitTengah, digitAwal; scanf("%d", &angka); digitBelakang = angka % 10; digitTengah = (angka - digitBelakang) / 10 % 10; digitAwal = (angka - digitBelakang) / 100 % 10 ; if (digitBelakang == 7){ puts ("Yes"); } else if (digitTengah == 7){ puts ("Yes"); } else if (digitAwal == 7){ puts ("Yes"); } else { puts ("No"); } return 0; }
#include <iostream> #include <cstdio> using namespace std; int n; bool flag; int a[15] = { 0, 111, 222, 333, 444, 555, 666, 777, 888, 999 }; int main() { scanf("%d", &n); flag = n > a[n / 100]; printf("%d\n", a[n / 100 + flag]); return 0; }
0
32,350,652
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<iomanip> using namespace std; int main(){ int a[5]; int x=0,tmp=0; int sum=0; for(int i=0;i<5;i++){ cin>>a[i]; if(a[i]%10==0){ sum+=a[i]; }else{ sum+=(a[i]/10+1)*10; x=10-a[i]%10; } tmp=max(x,tmp); } cout<<sum-tmp<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, pair<int, int> > p; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; string S; cin >> N >> S; int left, right; left = 0; right = 0; int la = 0; for(int i = 0; i < N; i++) { if(S[i] == '(') left++; else { if(left > 0) left--; else la++; } } string ans = ""; for(int i = 0; i < la; i++) ans += '('; ans += S; for(int i = 0; i < left; i++) ans += ')'; cout << ans << endl; }
0
52,851,405
#include <iostream> #include <stdlib.h> #include <string.h> using namespace std; int main() { int n,flag=1,i; char str[200]; cin>>str; n=strlen(str); if(n%2) n--; else n-=2; while(flag) { flag=0; for(i=0;i<n/2;i++) { if(str[i]!=str[(n/2)+i]) { n=n-2; flag=1; continue; } } } cout<<n; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long struct union_find{ vector<int> par; vector<int> rank; union_find(int sz){ par.resize(sz); rank.assign(sz,0); for(int i=0;i < sz;i++) par[i]=i; } int find(int a){ if(par[a]==a) return a; else return par[a] = find(par[a]); } void unite(int a,int b){ int root_a,root_b; root_a = find(a),root_b = find(b); if(rank[root_a]>rank[root_b]){ par[root_b] = root_a; }else if(rank[root_a]<rank[root_b]){ par[root_a] = root_b; }else{ rank[root_a]++; par[root_b] = root_a; } } bool same(int a,int b){return find(a)==find(b);} }; int main(){ int n,q; cin >>n>>q; union_find tree(n); for(int i=0;i<q;i++){ int com,x,y; cin >>com>>x>>y; if(com == 0){ tree.unite(x,y); }else{ int ans = tree.same(x,y); cout << ans << endl; } } }
0
10,023,850
#include <bits/stdc++.h> using ll = long long; using namespace std; const int INFint = 1e9+1; const ll INFll = (ll)1e18+1; ll MOD=1e9+7; int main(){ string s; cin>>s; ll N = int(s.size()); ll cnt[30] = {0}; for(int i(0);i<N;i++){ cnt[s[i]-'a']++; } ll ans(N*(N-1)/2+1); for(int i(0);i<30;i++){ ans -= (cnt[i]*(cnt[i]-1)/2); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(long long i=(l);i<(r);++i) #define REP(i,n) FOR(i,0,n) #define REPS(i,n) FOR(i,1,n+1) #define RFOR(i,l,r) for(long long i=(l);i>=(r);--i) #define RREP(i,n) RFOR(i,n-1,0) #define RREPS(i,n) RFOR(i,n,1) #define int long long #define mp make_pair #define pb push_back #define eb emplace_back #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const int INF=1e18; const int MOD=1e9+7; signed main(){ int n,m;cin>>n>>m; map<int,int>memo; REP(i,m){ int a,b;cin>>a>>b;a--;b--; memo[a]++;memo[b]++; } for(auto v:memo){ if(v.second%2==1){ cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; }
0
35,324,691
#include <bits/stdc++.h> using namespace std; int n, p; int main(){ cin >> n; for(int i=1; i<n; ++i){ if(i * (i + 1) / 2 >= n){ p = i; break; } } for(int i=1; i<=p; ++i){ if(i == p * (p + 1) / 2 - n) continue; cout << i << "\n"; } if(n == 1) cout << 1 << "\n"; if(n == 2) cout << 2 << "\n"; }
#include <iostream> #include <queue> using namespace std; int H,W; char A[1007][1007]; int D[1007][1007]; int vx[4] = {0,-1,0,1}; int vy[4] = {1,0,-1,0}; int bfs(){ int ans = 0; queue<pair <int,int> > Q; for(int y = 1; y< H+1;y++){ for(int x = 1;x < W+1;x++){ if(A[x][y] == '#'){ D[x][y] = 0; Q.push(make_pair(x,y)); } } } pair <int,int> p; while(!Q.empty()){ p = Q.front(); Q.pop(); for(int i = 0;i < 4;i++){ int nx = p.first + vy[i]; int ny = p.second + vx[i]; if(nx >= 1 && nx <= W && ny >= 1 && ny <= H && A[nx][ny] == '.'){ Q.push(make_pair(nx,ny)); D[nx][ny] = D[p.first][p.second] + 1; A[nx][ny] = '#'; if(D[p.first][p.second] + 1 > ans){ ans = D[p.first][p.second] + 1; } } } } return ans; } int main(){ cin >> H >> W; for(int y = 1; y< H+1;y++){ for(int x = 1;x < W+1;x++){ cin >> A[x][y]; } } int ans = bfs(); cout << ans << endl; }
0
47,990,967
#include <iostream> #include <cstdlib> #include <cstdio> #include <vector> #include <algorithm> #include <set> #include <cstring> #include <cmath> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--) #define rREP(i, k, n) for (int i = (int)(n) - 1; i >= k; i--) #define debug(x) cerr <<#x << ": " << x << endl; #define fi first #define se second #define vi vector<int> #define pb push_back #define mp make_pair #define pcnt __builtin_popcount typedef long long ll; const ll inf = 900900900100100100; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; const int MID = 255; using namespace std; int main(){ ll n,x,a,b,c; while(cin >> n >> a >> b >> c >> x,n) { int f = 0; int y[110] = {}; rep(i,n) cin >> y[i]; int k = 0; rep(i,10001) { if(x == y[k]) k += 1; if(k >= n) break; x = (a * x + b) % c; f++; } if(f > 10000) cout << -1 << endl; else cout << f << endl; } return 0; }
#include <iostream> using namespace std; #define MAX 10005 struct Node { int v, p, h; }; Node node[MAX]; int findSet(int x) { int now, p, result; now = x; p = node[now].p; while (now != p) { now = p; p = node[now].p; } result = p; p = x; while (p != result) { now = p; p = node[now].p; node[now].p = result; } return result; } void unite(int x, int y) { int a = findSet(x); int b = findSet(y); if (a == b) return; if (node[a].h > node[b].h) { node[b].p = a; } else if (node[a].h < node[b].h) { node[a].p = b; } else { node[b].p = a; node[a].h++; } } int main(void) { int n, p, com, x, y; cin >> n >> p; for (int i = 0; i < n; i++) { node[i].v = i; node[i].p = i; node[i].h = 0; } while (p--) { cin >> com >> x >> y; if (com == 0) { unite(x, y); } else { if (findSet(x) == findSet(y)) { cout << 1 << endl; } else { cout << 0 << endl; } } } }
0
1,789,532
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int n,k; string s; cin>>n>>s>>k; k--; rep(i,n) if(s[i]!=s[k]) s[i]='*'; cout<<s<<'\n'; return 0; }
#include <iostream> #include <queue> #include <vector> #include <string> #include <algorithm> #include <cmath> using namespace std; using ll=long long; #define rep(i,a,b) for(ll i=a;i<ll(b);i++) #define repr(i,a,b) for(ll i=a;i>=ll(b);i--) #define endl "\n" #define ALL(x) x.begin(),x.end() #define ALLR(x) x.rbegin(),x.rend() #define INF 1e9 #define DEBUG(x) cout<<"debug: "<<x<<endl int n, m; int main() { cin >> n >> m; vector<int> graph[n]; rep(i, 0, m){ int a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } queue<int> q; vector<int> ans(n, -1); q.push(0); while (q.size()) { int i = q.front(); q.pop(); for(auto x : graph[i]){ if(ans[x] != -1) continue; ans[x] = i; q.push(x); } } cout << "Yes" << endl; rep(i, 1, n){ cout << ans[i]+1 << endl; } return 0; }
0
55,675,710
#include <iostream> #include <cstdio> using namespace std; int main() { while (1) { int h, w; cin >> h >> w; if (h == 0 && w == 0) { break; } for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { printf("#"); } printf("\n"); } printf("\n"); } return 0; }
#include <bits/stdc++.h> #define debug(x) cerr << #x << " " << x << "\n" #define debug_with_space(x) cerr << #x << " " << x << " " using namespace std; typedef long long ll; typedef pair <ll, ll> pii; typedef pair <ll, pii> muchie; const ll NMAX = 61 * 200; const ll INF = (1LL << 60); const ll MOD = 1000000007; const ll BLOCK = 101; ll calc(ll x){ ll z = sqrt(x); while(z * (z + 1) > x) z--; return z; } int main() { ll sum = 0,n,d = 2; cin >> n; while(d * d <= n){ ll exp = 0; while(n % d == 0){ n /= d; exp++; } ll rez = calc(exp * 2); sum += rez; d++; } if(n > 1){ sum += calc(2); } cout << sum; return 0; }
0
6,009,806
#include <bits/stdc++.h> using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using P = pair<int, int>; ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; } ll LCM(ll a, ll b) { return a/GCD(a, b)*b; } ll w, h; struct pqdata { ll cost; char x; bool operator<(const pqdata &r) const { return cost < r.cost; } }; int main() { cin >> w >> h; vector<pqdata> pqvec; for(int i = 0; i < w; ++i) { pqdata indata; cin >> indata.cost; indata.x = 'p'; pqvec.emplace_back(indata); } for(int i = 0; i < h; ++i) { pqdata indata; cin >> indata.cost; indata.x = 'q'; pqvec.emplace_back(indata); } sort(pqvec.begin(), pqvec.end()); int pqlen = pqvec.size(); int pnow = h+1; int qnow = w+1; ll ans = 0; for(int i = 0; i < pqlen; ++i) { if(pqvec.at(i).x == 'p') { ans += pqvec.at(i).cost*pnow; qnow--; }else { ans += pqvec.at(i).cost*qnow; pnow--; } } cout << ans << endl; }
#include <iostream> #include <string> using namespace std; int main(){ while (1) { string s; cin >> s; if (s == "-") break; int n; cin >> n; while (n) { n--; int h; cin >> h; string b1 = s.substr(0, h); string b2 = s.substr(h); s = b2 + b1; } cout << s << endl; } return 0; }
0
82,532,346
#include <bits/stdc++.h> using namespace std; using LL = long long; int main(){ LL N, A, B; scanf("%lld %lld %lld", &N, &A, &B); LL ans = max(0LL, (N - 2) * (B - A) + 1); printf("%lld\n", ans); return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <utility> #include <queue> #include <string> #include <climits> using namespace std; #define MAX_N 101 int main() { vector<vector<int> > A(MAX_N, vector<int>(MAX_N, 0)); int i, k, u, v, n; cin >> n; for (i = 1; i <= n; i++) { cin >> u >> k; while (k--) { cin >> v; A[u][v] += 1; } } for (i = 1; i <= n; i++) { for (k = 1; k <= n; k++) { if (k > 1) cout << " "; cout << A[i][k]; } cout << endl; } return 0; }
0
58,931,995
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int s=0; int x=n; while(x>0){ s+=x%10; x/=10; } cout<<(n%s==0?"Yes":"No")<<endl; }
#include<bits/stdc++.h> #define int long long using namespace std; const double eps=1e-8; int read() { int s=0; char c=getchar(),lc='+'; while (c<'0'||'9'<c) lc=c,c=getchar(); while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar(); return lc=='-'?-s:s; } void write(int x) { if (x<0) { putchar('-'); x=-x; } if (x<10) putchar(x+'0'); else { write(x/10); putchar(x%10+'0'); } } void print(int x,char c='\n') { write(x); putchar(c); } bool eq(double x,double y) { return fabs(x-y)<eps; } signed main() { int n=read(),ans=0; for (int l=1,r;l<=n;l=r+1) { int k=n/l; r=n/k; if (l<=n/k-1&&n/k-1<=r&&eq(n/k,double(n)/double(k))) ans+=n/k-1; } print(ans); return 0; }
0
41,376,097
#include <bits/stdc++.h> using namespace std; int main() { int N,A,B; cin >> N >> A >> B; int ua=0,ab=0,ob=0; for(int i=0;i<N;i++){ int x; cin >> x; if(x<=A)ua++; else if(x>=B+1)ob++; else ab++; } cout << min({ua,ab,ob}); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> P; typedef pair<int,int> Pi; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define fi first #define se second #define PI (acos(-1)) 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; } template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";} template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";} template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){ int len=d.size(); rep(i,len){ s<<d[i];if(i<len-1) s<<" "; } return s; } template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){ int len=d.size(); rep(i,len){ s<<d[i]<<endl; } return s; } template<typename T> ostream& operator<<(ostream& s,const set<T>& v){ s<<"{ "; for(auto itr=v.begin();itr!=v.end();++itr) { if (itr!=v.begin()) {s<< ", ";} s<<(*itr); } s<<" }"; return s; } template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){ s<<"{"<<endl; for(auto itr=m.begin();itr!=m.end();++itr){ s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl; } s<<"}"<<endl; return s; } const ll mod=1e9+7; const ll inf=1e15; const int INF=1e9; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,a,b; cin>>n>>a>>b; int cnt=(b-a)%2; if(cnt%2==0){ cout<<"Alice"<<endl; }else{ cout<<"Borys"<<endl; } }
0
55,284,141
#include<iostream> #include<stdio.h> #include<cmath> using namespace std; int main(){ double x1,x2,y1,y2; cin >> x1 >> y1 >> x2 >> y2; cout << fixed << sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) << endl; }
#include<bits/stdc++.h> using namespace std; int o[100]; int u[200]; int root(int s){ while(o[s]>=0) s=o[s]; return u[s]; } void merge(int x, int y){ x = root(x); y = root(y); if(x == y) return; o[x]+=o[y]; o[y]=x; } bool same(int x,int y){ return root(x) == root(y); } int main(){ string str; for(int i=0;i<26;i++){ o[i+'a']=-1; u[i+'a']=i+'a'; } merge('q','w');merge('q','e');merge('q','r');merge('q','t');merge('q','a');merge('q','s');merge('q','d');merge('q','f');merge('q','g');merge('q','z');merge('q','x');merge('q','c');merge('q','v');merge('q','b'); merge('y','u');merge('y','i');merge('y','o');merge('y','p');merge('y','h');merge('y','j');merge('y','k');merge('y','l');merge('y','n');merge('y','m'); while(cin>>str,str!="#"){ int ans=0; for(int i=0;i<str.size()-1;i++){ if(!same(str[i],str[i+1])){ ans++; } } cout<<ans<<endl; } return 0; }
0
60,512,457
#include <iostream> #include <iomanip> #include <limits> #include <string> #include <vector> #include <algorithm> #include <stdio.h> #include <cmath> #include <functional> #define big ((long long)(1e9) + 7) using namespace std; typedef unsigned long long ull; typedef long long ll; #define DBG(x) cerr << #x << ": " << (x) << " (L" << __LINE__ << ")" << endl; ll max_ll(ll a, ll b) { if (a < b) { a = b; } return a; } int main() { string s; cin >> s; vector<ll> a; ll nl = 0; ll nr = 0; if (s.at(0) == '<') { nl++; for(ll i = 1;i < s.size();i++) { if(s.at(i-1) != s.at(i) && nl != 0 && nr != 0) { a.push_back(max_ll(nl,nr)); if(nl >= nr && nr >= 2) { a.push_back(nr-1); } else if(nl <= nr && nl >= 2) { a.push_back(nl-1); } nl = 0; nr = 0; } if(s.at(i) == '<') nl++; else nr++; } } else { bool flag = true; nr++; for(ll i = 1;i < s.size();i++) { if(flag && s.at(i-1) != s.at(i)) { a.push_back(max_ll(nl,nr)); nl = 0; nr = 0; flag = false; } if(s.at(i-1) != s.at(i) && nl != 0 && nr != 0) { a.push_back(max_ll(nl,nr)); if(nl >= nr && nr >= 2) { a.push_back(nr-1); } else if(nl <= nr && nl >= 2) { a.push_back(nl-1); } nl = 0; nr = 0; } if(s.at(i) == '<') nl++; else nr++; } } a.push_back(max_ll(nl,nr)); ll ans = 0; for(ll i = 0;i < a.size();i++) { ans += a[i]*(a[i]+1)/2; } cout << ans << endl; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define F first #define S second #define int long long #define ll long long #define pb push_back using namespace std; using namespace __gnu_pbds; typedef tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int mod = 1e9 + 7; const int N = 2000000; set < int > ms; int used[N], t[N], color[N], r[N], cv, v[N], s[N], u[N], n, m, val[N]; pair < int, int > p[N]; vector < pair < int, int > > g[N]; pair < int, int > ans[N]; int res[N]; main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < (1 << n); i++){ cin >> ans[i].F; } for (int j = 0; j < n; j++){ for (int i = 0; i < (1 << n); i++){ if (!((1 << j) & i)){ int x = ans[i | (1 << j)].F; int y = ans[i | (1 << j)].S; int t = ans[i].F; int z = ans[i].S; multiset < int > s; s.insert(-x); s.insert(-y); s.insert(-t); s.insert(-z); auto it = s.begin(); ans[i | (1 << j)].F = -(*it); it++; ans[i | (1 << j)].S = -(*it); } } } for (int i = 1; i < (1 << n); i++){ res[i] = max(ans[i].F + ans[i].S, res[i - 1]); cout << res[i] << endl; } }
0
18,774,035
#include <algorithm> #include <bitset> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #include <cctype> #include <cmath> using namespace std; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define blank(ans) cout << (ans) << " "; #define mp(p, q) make_pair(p, q) #define mt(p, q, r) make_tuple(p, q, r) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef string str; typedef vector<ll> vll; typedef vector<ld> vd; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<str> vs; typedef vector<vector<ll>> vvll; typedef vector<vector<ld>> vvd; typedef vector<vector<bool>> vvb; typedef vector<vector<char>> vvc; typedef vector<vector<str>> vvs; typedef vector<pair<ll, ll>> vpll; typedef vector<tuple<ll, ll, ll>> vtlll; const ld PI = acos(-1.0); const ll MAX = 9000000000000000000; const ll MIN = -9000000000000000000; const ld DMAX = 4500; const ld DMIN = -4500; const ll MOD = 1000000007; template <typename T> void fin(T a) { cout << a << endl; exit(0); } void Main() { ll a, p; cin >> a >> p; p += a * 3; fin(p / 2); } int main() { cout << fixed << setprecision(20); Main(); return 0; }
#include<iostream> #include<cmath> #include<algorithm> #include<vector> #include<queue> #include<cstring> using namespace std; int main(){ long long inf=10000000000; int v,e; cin >> v >> e; long long dp[v][v]; for(int i=0;i<v;i++){ for(int j=0;j<v;j++){ dp[i][j]=inf; } } for(int i=0;i<e;i++){ long long s,t,d; cin >> s >> t >> d; dp[s][t]=d; } for(int i=0;i<v;i++)dp[i][i]=0; for(int k=0;k<v;k++){ for(int i=0;i<v;i++){ for(int j=0;j<v;j++){ if(dp[i][k]==inf || dp[k][j]==inf); else dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]); } } } int a=0; for(int i=0;i<v;i++)if(dp[i][i]<0)a++; if(a!=0)cout << "NEGATIVE CYCLE" << endl; else{ for(int i=0;i<v;i++){ if(dp[i][0]==inf)cout << "INF" ; else cout << dp[i][0] ; for(int j=1;j<v;j++){ if(dp[i][j]==inf)cout << " "<<"INF" ; else cout << " " <<dp[i][j]; } cout << endl; } } }
0
31,551,127
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cctype> #include<math.h> #include<string> #include<string.h> #include<stack> #include<queue> #include<vector> #include<utility> #include<set> #include<map> #include<stdlib.h> #include<iomanip> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define LINF (ll)INF*INF #define MOD 1000000007 #define rep(i,n) for(int i=0;i<(n);i++) #define loop(i,a,n) for(int i=a;i<(n);i++) #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) #define int ll typedef vector<int> vi; typedef vector<string> vs; typedef pair<int,int> pii; typedef vector<pii> vp; int gcd(int a, int b){ if(b==0) return a; return gcd(b,a%b); } int lcm(int a, int b){ return a/gcd(a,b)*b; } signed main(void) { int n,k; cin >> n >> k; cout << n - k + 1 << endl; }
#include<stdio.h> #include<string.h> int n,m; char s1[100],s2[100]; char hash[2000]; char output[20000000]; int main(){ int i; while(1){ for( i = 0; i < 1000; i++ ) hash[i] = 0; scanf("%d",&n); if(!n)break; for( i = 0; i < n; i++ ){ scanf("%s%s",s1,s2); hash[(int)s1[0]] = s2[0]; } scanf("%d",&m); for( i = 0; i < m; i++ ){ s1[0] = '\0'; scanf("%s",s1); if( hash[s1[0]] ){ char s[3] = {hash[(int)s1[0]],'\0'}; strcat(output,s); } else{ strcat(output,s1); } } printf("%s\n",output); output[0] = '\0'; } return 0; }
0
64,291,698
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (int)(n); ++i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { int mod=1000000007; int n,m,k; cin >> n>>m>>k; bool ex=false; rep(i,n+1){ rep(j,m+1){ if(i*j+(n-i)*(m-j)==k){ ex=true; } } } if(ex){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
#include <iostream> #include <string> int main(){ std::string O, E; std::cin >> O >> E; std::string S, Sout; S = O + E; int N = S.size(); for (int i=0; i<N; i++){ if (i % 2 == 0){ Sout = Sout + O.at(i/2); } else{ Sout = Sout + E.at(i/2); } } std::cout << Sout << std::endl; }
0
55,291,874
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(int argc, const char *argv[]) { vector<int> p(3); cin >> p[0] >> p[1] >> p[2]; sort(p.begin(), p.end(), greater<int>()); cout << p[0] * 10 + p[1] + p[2] << endl; return 0; }
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<utility> #include<tuple> #include<map> #include<queue> #include<set> #include<stack> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define BIL ((ll)1e9) #define MOD ((ll)1e9+7) #define INF (1LL<<60) #define inf (1<<29) int main(int argc,char* argv[]){ int n; cin >> n; vector<int> b(n-1); for(auto &x:b)cin >> x; vector<int> a(n,0); a[0]=b[0]; a[1]=b[0]; for(int i=0;i<n-1;i++){ if(b[i]>=max(a[i],a[i+1])){ a[i+1]=b[i]; }else if(b[i]<max(a[i],a[i+1])){ a[i]=b[i]; a[i+1]=b[i]; } } int sum=0; for(int i=0;i<n;i++){ sum += a[i]; } cout << sum << endl; return 0; }
0
57,572,846
#include <bits/stdc++.h> using namespace std; int nth_bit(int64_t num, int n){ return (num >> n) & 1; } int main(){ int M, K; cin >> M >> K; if(M == 1){ if(K == 0){ cout << "0 0 1 1" << endl; }else{ cout << -1 << endl; } return 0; } int MX = 1<<M; if(K >= MX){ cout << -1 << endl; return 0; } vector<int> ans; for(int i=0; i<MX; i++) if(i != K) ans.push_back(i); ans.push_back(K); for(int i=MX-1; i>=0; i--) if(i != K) ans.push_back(i); ans.push_back(K); for(int i=0; i<2*MX; i++) cout << ans[i] << " \n"[i==2*MX-1]; return 0; }
#include <bits/stdc++.h> #include <numeric> using namespace std; #define ll long long #define mod107 1000000007 #define rep(i, n) for (int i = 0; i < n; ++i) using Graph = vector<vector<int>>; #define grepq priority_queue<double, std::vector<double>, std::greater<double>> #define all(v) v.begin(), v.end() #define PI acos(-1) const ll INF = 10010001010; const int inf = 1000034000; typedef vector<ll> vecl; typedef vector<int> veci; typedef tuple<string, int, int> TUP; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int N; cin >> N; string S, T; cin >> S >> T; int ans = 2 * N; bool ok = true; int itr = 0; for (int i = N;i < 2 * N;i++) { string s = S.substr(i - N); string t = T.substr(0,2 * N - i); if (s == t) { ans -= s.size(); break; } } cout << ans << endl; }
0
53,408,757
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define rep(i,m,n) for(int i=m;i<n;i++) ll mod=1e9+7; int main(){ int a,b; char c; cin>>a>>c>>b; if(c=='+') cout<<a+b<<endl; else cout<<a-b<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second #define pb push_back #define mp make_pair #define mod 1000000007 #define vlli vector<ll> #define vi vector<int> #define vs vector<string> #define vplli vector< pair< ll, ll> > #define plli pair< ll, ll > #define vps vector< pair< string, string> > #define vpi vector< pair< int, int> > #define all(x) x.begin(), x.end() #define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define forn(i, a, n) for (ll i = a; i < n; i++) #define scan(arr, a, n) for (ll i = (a); i < (n); i++) cin >> (arr)[i]; #define print(arr, a, n) for (ll i = (a); i < (n); i++) cout << (arr)[i] << " "; ll add(ll x, ll y) { ll res = x + y; return (res >= mod ? res - mod : res); } ll mul(ll x, ll y) { ll res = x * y; return (res >= mod ? res % mod : res); } ll sub(ll x, ll y) { ll res = x - y; return (res < 0 ? res + mod : res); } ll power(ll x, ll y) { ll res = 1; x %= mod; while (y) { if (y & 1) res = mul(res, x); y >>= 1; x = mul(x, x); } return res; } ll mod_inv(ll x) { return power(x, mod - 2); } int main(){ fast; #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif ll n, m; cin >> n >> m; ll a[n], x = 0; for (int i = 0; i < m; i++) { cin >> a[i]; x += a[i]; } ll z = n - x; cout << max(z, -1ll) << endl; }
0
99,857,763
#include<algorithm> #include<iostream> #include<vector> #include<string> #include<cstring> using namespace std; #define REP(i, a,b) for(i=a;i<b;i++) #define output(x) cout<<x<<endl; typedef long long int ll; int main() { ll i, j, k, l, m, sum, flag,ans,W,H,N; sum = 0; flag = 0; cin >> N; vector<ll>A(N); REP(i, 0, N) { cin >> A[i]; } j = 1; sum += A[0] - 1; REP(i, 1, N) { if (A[i] == j + 1) { j++; } else { sum += (A[i] - 1) / (j + 1); } } output(sum); return 0; }
#include <bits/stdc++.h> #include <cmath> using namespace std; int main(){ int n,h; cin >> n >> h; vector<int> hai(n),hei(n); for(int i = 0; i < n; i++){ cin >> hai[i]; hei[i] = 0; } int sum = 0; int a, b; for(int i = 0; i < h; i++){ cin >> a >> b; hei[a -1] = max(hei[a-1], hai[b-1]); hei[b-1] = max(hei[b-1], hai[a-1]); } for(int i = 0; i< n; i++){ if(hai[i] > hei[i]){ sum++; } } cout << sum << endl; }
0
53,816,775
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define erep(i,a,n) for(int i = a;i<=n;i++) typedef long long ll; #define int long long #define vint vector<int> #define vvint vector<vector<int>> #define vstring vector<string> #define vdouble vector<double> #define vll vector<ll>: #define vbool vector<bool> #define INF 1101010101010101010 #define MOD 1000000007 #define P = pair<int,int>; 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; } signed main(){ int a,b; cin >> a >> b; if(a - b > 0) cout << a - b << endl; else cout << 0 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> Pair; typedef vector<ll> vll; typedef vector<vector<ll>> Graph; typedef vector<string> vs; typedef vector<pair<ll, ll>> Pll; typedef queue<ll> qll; #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 REPA(i,a) for(ll i=0;i<(ll)(a.size());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 COUT(a) cout << (a) << endl; #define ENDL(a) cout << endl; #define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl; #define pb push_back #define paired make_pair #define ALL(a) (a).begin(),(a).end() #define SORT(a) sort((a).begin(),(a).end()) #define RSORT(a) sort((a).rbegin(), (a).rend()) #ifdef _DEBUG #define debug(x) cout << "[debug] " << #x << ": " << x << endl #else #define debug(x) #endif template <typename T> void debugV(const vector<T> v) { #ifdef _DEBUG rep(i, v.size()) { cout << i << ":" << v[i] << " "; } cout << endl; #else (void)v; #endif } const unsigned int BIT_FLAG_0 = (1 << 0); const unsigned int BIT_FLAG_1 = (1 << 1); const unsigned int BIT_FLAG_2 = (1 << 2); const unsigned int BIT_FLAG_3 = (1 << 3); const unsigned int BIT_FLAG_4 = (1 << 4); const unsigned int BIT_FLAG_5 = (1 << 5); const unsigned int BIT_FLAG_6 = (1 << 6); const unsigned int BIT_FLAG_7 = (1 << 7); const unsigned int BIT_FLAG_8 = (1 << 8); const unsigned int BIT_FLAG_9 = (1 << 9); const unsigned int BIT_FLAG_10 = (1 << 10); const unsigned int BIT_FLAG_11 = (1 << 11); constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr double PI=3.14159265358979323846; constexpr int MOD = 1000000007; void Main() { ll n, m; cin >> n >> m; ll left = 1, right = n; REP(i, m) { ll l, r; cin >> l >> r; if (left < l) { left = l; } if (r < right) { right = r; } } ll ans = right - left + 1; if (ans < 1) { COUT(0); } else { COUT(ans); } } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); }
0
70,600,064
#include <functional> #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <random> #include <bitset> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> typedef long long ll; using namespace std; const ll MOD = 1000000007LL; int main() { int n; cin >> n; vector<int> a(n); map<int, ll> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } ll ans = 0; for (auto p : mp) { ans += p.second * (p.second - 1) / 2; } for (int i = 0; i < n; i++) { cout << ans - mp[a[i]] + 1 << endl; } return 0; }
#include <iostream> #include <vector> #include <tuple> using namespace std; int main(void) { int N, M; cin >> N >> M; vector< vector<int> > wf(N, vector<int>(N, 1000000000)); vector< tuple<int,int,int> > edge; while(M--) { int a, b, c; cin >> a >> b >> c; --a; --b; wf[a][b] = c; wf[b][a] = c; edge.emplace_back(a, b, c); } for(int k=0; k<N; k++) { for(int i=0; i<N; i++) { for(int j=0; j<N; j++){ wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]); } } } int ans = 0; for(auto e: edge) { int a = get<0>(e); int b = get<1>(e); int c = get<2>(e); if(wf[a][b] != c) { ans++; } } cout << ans << endl; return 0; }
0
10,732,602
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> V; #define rep(i,e) for(ll i=0;i<e;i++ ) typedef pair<ll,ll> P; const ll mod = 1e9+7; const ll INF = INT64_MAX; ll i; int main(){ string A,B,C; cin>>A>>B>>C; if(A.at(A.length()-1)==B.at(0)&&B.at(B.length()-1)==C.at(0))cout<<"YES"; else cout<<"NO"; cout<<endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long using vvll = vector<vector<ll>>; ll mod =1e9+7; template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;} template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int ctoi(char c) {return c-'0';} ll gcd(ll a,ll 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;} bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}} string reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;} ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;} int main() { ll n,k; cin >> n >>k; vector<ll>loop(n),value(n); for(int i=0;i<n;i++){ cin >> loop.at(i); loop.at(i)--; } for(int i=0;i<n;i++){ cin >> value.at(i); } ll ans = -1e17; for(int i=0;i<n;i++){ ll kei =0; vector<ll>memo; memo.push_back(0); ll next = loop.at(i); for(int j=0;j<k;j++){ next = loop.at(next); if(j==0)next=loop.at(i); kei+=value.at(next); memo.push_back(kei); if(memo.size()>1){ memo.at(memo.size()-1)=max(memo.at(memo.size()-1),memo.at(memo.size()-2)); } ans = max(ans,kei); if(next==i){ if(kei<0)break; else{ ll kai = j+1; ll check = k/kai*kei + memo.at(k%kai); ans = max(check,ans); check = ((k/kai)-1)*kei+memo.at(memo.size()-1); ans = max(check,ans); break; } } } } cout<<ans<<endl; }
0
13,404,404
#include<iostream> using namespace std; int main() { int n, y, m, d; int totalDays = 999*(5*19+5*20) + 333*5; cin>>n; for(int i=0; i<n; i++) { int ans = totalDays; cin>>y>>m>>d; for(int a=1; a<=y; a++) { if(a != y) { for(int b=1; b<=10; b++) { if(a%3==0 || b%2==1) { ans -= 20; } else { ans -= 19; } } } else { for(int b=1; b<m; b++) { if(a%3==0 || b%2==1) { ans -= 20; } else { ans -= 19; } } ans -= d-1; } } cout<<ans<<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()) 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; } template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; } template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; } template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} } constexpr int INF = 1e9+5; constexpr long long INFLL = 1LL<<60; constexpr double eps = (1e-9); void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) { if (rest == 0) { f(indexes); } else { if (s < 0) return; recursive_comb(indexes, s - 1, rest, f); indexes[rest - 1] = s; recursive_comb(indexes, s - 1, rest - 1, f); } } void foreach_comb(int n, int k, std::function<void(int *)> f) { int indexes[k]; recursive_comb(indexes, n - 1, k, f); } ll calc_cost(const vector<ll>& a, const vector<int>& t) { ll ans = 0; ll m = 0; auto it = t.begin(); for (int i = 0; i < a.size(); i++) { if (i == *it) { if (a[i] <= m) { ans += (m+1) - a[i]; m = m + 1; } else { m = a[i]; } it++; } else { m = max(m, a[i]); } } return ans; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll ans = INFLL; foreach_comb(n, k, [&](int* indexes) { vector<int> t; for (int i = 0; i < k; i++) t.push_back(indexes[i]); sort(t.begin(), t.end()); chmin(ans, calc_cost(a, t)); }); cout << ans << endl; return 0; }
0
66,368,220
#include <bits/stdc++.h> using namespace std; int main () { int a,b,c; cin >> a >> b >> c; int count=3; if (a==b && b==c) { cout << 1 << endl; return 0; } if (a==b) --count; if (b==c) --count; if (a==c) --count; cout << count << endl; return 0; }
#include<iostream> #include<string> using namespace std; int main() { int n; string t_cade,h_cade; int t_point=0,h_point=0; cin >>n; for(int i=0;i<n;i++) { cin>>t_cade>>h_cade; if(t_cade==h_cade) { t_point++; h_point++; }else { int index=0; while (t_cade[index] == h_cade[index]) { index++; } if(t_cade[index] > h_cade[index]) { t_point+= 3; }else { h_point += 3; } } } cout<<t_point<<" "<< h_point<<endl; return 0; }
0
78,369,922
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using u32 = uint32_t; using vi = vector<int>; using vvi = vector<vi>; using vb = vector<bool>; using vvb = vector<vb>; using vl = vector<ll>; using vvl = vector<vl>; using vd = vector<double>; using vvd = vector<vd>; #define MAXC(c, x) (c = max(c, x)) #define MINC(c, x) (c = min(c, x)) #define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i) #define ALL(c) (c).begin(), (c).end() #define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i) #define TEN(x) ((ll)1e##x) const ll mod = TEN(9) + 7; const ll INF = 1e9; int main() { #ifdef INPUT_FROM_FILE ifstream cin("sample.in"); ofstream cout("sample.out"); #endif cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(50); string s; cin >> s; ll n = s.size(); vector<int> tbl(1 << 26, -2); tbl[0] = -1; ll alp = 0; vl dp(n + 1, TEN(10)); dp[0] = 0; REP(i, n) { alp ^= 1 << (s[i] - 'a'); if (__builtin_popcountll(alp) == 0) { dp[i + 1] = 1; } else { REP(j, 26) { ll c = 1 << j; if (c & alp == 0) continue; if(tbl[alp ^ c] != -2) MINC(dp[i + 1], 1 + dp[tbl[alp ^ c] + 1]); } } if (tbl[alp] == -2 || dp[tbl[alp] + 1] > dp[i + 1]) tbl[alp] = i; } cout << dp[n] << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; const double pi = 3.141592653589793238462643383279; const int INF = 1000000000; const ll LINF = 100000000000000000; const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC"; const string abc = "abcdefghijklmnopqrstuvwxyzabc"; const ll MOD = 1000000007; const int MAX = 1200000; struct edge { ll to; ll cost; }; struct UnionFind { vector<int> UF; vector<int> SIZE; UnionFind(int N) : UF(N), SIZE(N, 1) { for(int i = 0; i < N; i++) { UF.at(i) = i; } } int root(int x) { if (UF.at(x) == x) { return x; } return UF.at(x) = root(UF.at(x)); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) { return; } if (SIZE.at(rx) < SIZE.at(ry)) { UF.at(rx) = ry; SIZE.at(ry) += SIZE.at(rx); SIZE.at(rx) = 0; } else { UF.at(ry) = rx; SIZE.at(rx) += SIZE.at(ry); SIZE.at(ry) = 0; } } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } int size(int x) { return SIZE.at(root(x)); } }; int ctoi(char c){ if (c == '0') return 0; if (c == '1') return 1; if (c == '2') return 2; if (c == '3') return 3; if (c == '4') return 4; if (c == '5') return 5; if (c == '6') return 6; if (c == '7') return 7; if (c == '8') return 8; if (c == '9') return 9; return -1; } char to_char(int i){ if (i == 0) return '0'; if (i == 1) return '1'; if (i == 2) return '2'; if (i == 3) return '3'; if (i == 4) return '4'; if (i == 5) return '5'; if (i == 6) return '6'; if (i == 7) return '7'; if (i == 8) return '8'; if (i == 9) return '9'; return ' '; } int main() { cout << fixed << setprecision(16); int N; cin >> N; ll ans = 1; bool ok = false; for (int i = 0; i < N; i++) { ll A; cin >> A; if (A == 0) { ok = false; ans = 0; break; } if (ans > (1000000000000000000 / A)) { ok = true; ans = 0; } else { ans *= A; } } if (ok) { cout << -1 << endl; } else { cout << ans << endl; } }
0
86,912,300
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef long long ll; const int MOD = 1000000007; const ll INF = (ll) 1e18; int main() { int N; cin >> N; string s; cin >> s; rep(i,2){ rep(j,2){ vector<int>now(N,-1); now[0]=i; now[1]=j; for(int k=2;k<N;k++){ if((s[k-1]=='x')^(now[k-1]==1)){ now[k]=(now[k-2]^1); } else{ now[k]=now[k-2]; } } bool ok=true; ok&=(((s[N-1]=='x')^(now[N-1]==1))^(now[N-2]==now[0])); ok&=(((s[0]=='x')^(now[0]==1))^(now[N-1]==now[1])); if(ok){ rep(k,N){ cout << (now[k]==1?"W":"S") << (k==N-1?"\n":""); } return 0; } } } cout << -1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define forin(in, n) for(int i=0; i<n; i++) cin>>in[i] #define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl #define rep(i, n) for(int i=0; i<(n); i++) int main(){ int N; cin >> N; int X[N]; ll sum = 0; for (int i = 0; i < N; i++) { cin >> X[i]; sum += X[i]; } ll ans1 = 0; ll ans2 = 0; for (int i = 0; i < N; i++) { ll t1 = (sum + N - 1) / N - X[i]; ll t2 = sum / N - X[i]; ans1 += t1 * t1; ans2 += t2 * t2; } cout << min(ans1, ans2) <<endl; }
0
23,950,966
#include<bits/stdc++.h> using namespace std ; const int A_MAX = 1000005 ; int main() { int N ; cin >> N ; vector<int> A(A_MAX+1) ; vector<int> C(A_MAX+1), cnt(A_MAX+1); for(int i = 1 ; i <= N ; i++) { cin >> A.at(i) ; C.at(A.at(i))++ ; } int ans = 0 ; for(int i = 1 ; i <= A_MAX ; i++){ for(int j = i ; j <= A_MAX ; j += i ){ cnt.at(j) += C.at(i) ; } } for(int i = 1 ; i <= A_MAX ; i++ ){ if(cnt.at(i) == 1 && C.at(i) ){ ans += C.at(i) ; } } cout << ans << endl ; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; int mod = 1e9 + 7; int main() { string s1, s2; cin >> s1 >> s2; int n = (int)s1.size(); int m = (int)s2.size(); if (n > m) { cout << "GREATER"; return 0; }else if (n < m) { cout << "LESS"; return 0; } for (int i = 0; i < n; ++i) { if (s1[i] > s2[i]) { cout << "GREATER"; return 0; } if (s1[i] < s2[i]) { cout << "LESS"; return 0; } } cout << "EQUAL"; }
0
32,878,555
#ifndef ___Class_Union_Find #define ___Class_Union_Find #include <vector> #include <utility> #include <algorithm> using namespace std; class Union_Find { private: vector<int> data; public: Union_Find(unsigned size_) : data(size_, -1) { } void unite(int x, int y); bool same(int x, int y); int root(int x); }; void Union_Find::unite(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[x] < data[y]) { swap(x, y); } data[x] += data[y]; data[y] = x; } } bool Union_Find::same(int x, int y) { return root(x) == root(y); } int Union_Find::root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } #endif #include <iostream> using namespace std; int n, q, com, x, y; int main() { cin >> n >> q; Union_Find u(n); for (int i = 0; i < q; i++) { cin >> com >> x >> y; if (com == 0) { u.unite(x, y); } if (com == 1) { cout << (u.same(x, y) ? 1 : 0) << endl; } } return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> #include <cmath> #define pi 3.14159265358979323846264338327950 int main() { int N; std::cin >> N; std::vector<double> v(N); for (auto& r : v) std::cin >> r; std::sort(v.begin(), v.end()); double ans = v[0]; for (int i = 1; i < N; ++i) ans = (ans + v[i]) / 2; std::cout << ans << std::endl; return 0; }
0
72,185,422
#include <iostream> using namespace std; int main(void){ string s; long long k; cin >> s; cin >> k; long t = 0; char c = '1'; for(long i = 0;i < s.size();i++){ if(s[i] == '1'){ t++; }else{ c = s[i]; break; } } if(t >= k){ cout << '1' << endl; }else{ cout << c << endl; } }
#include <stdio.h> #include <math.h> #include<bits/stdc++.h> using namespace std; #define int long long int int i,j,k,m; main() { int c=0; int k,s;cin>>k>>s; for(i=0;i<=k;i++) { for(j=0;j<=k;j++) { int f=i+j; if((s-f)>=0&&(s-f)<=k) c++; } } cout<<c<<endl; }
0
70,374,935
#include <bits/stdc++.h> #define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++) #define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } #define pb push_back #define mp make_pair #define F .first #define S .second #define pll pair<ll,ll> using ll=long long; using ld=long double; const ll INF = 1LL<<60; const ll mod=1e9+7; const ll mod2= 998244353; using namespace std; ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } map<ll,ll> w; ll n,x,m; ll fc(ll st,ll p){ ll pos=0; ll t=st; ll ans=0; while(pos<p){ ans+=t; t=t*t; t%=m; pos++; } return ans; } int main(){ ll ans=0; cin>>n>>x>>m; ll pos=0; ll t=x,st=0,e=0,now; while(w[t]==0&&pos<n){ w[t]=pos; ans+=t; t=t*t; t%=m; pos++; now=t; e=w[t]; st=pos-w[t]; } if(t==1)ans+=n-pos; else if(t!=0&&pos<n) { ll num=n-e; ll b=fc(x,e); ans=b+(ans-b)*(num/st)+fc(now,num%st); } cout<<ans<<endl; }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) #define all(c) (c).begin(),(c).end() #define pb push_back #define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0); using namespace std; namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};} template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";} template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";} void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);} typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9; int n, a[100010]; vector<vi> e; ll maxpair(vector<ll> v){ if(v.size() < 2) return 0; ll res = 0; while(v.size() > 1){ sort(all(v)); res += min(v[v.size() - 1], v[v.size() - 2]); ll d = abs(v[v.size() - 1] - v[v.size() - 2]); v.pop_back(); v.pop_back(); v.pb(d); } return res; } ll maxpair2(vector<ll> v){ ll res = 0; sort(all(v),greater<ll>()); while(v[1] > 0){ res++; v[0]--; v[1]--; sort(all(v),greater<ll>()); if(res > 1000) break; } return res; } ll rec(int c, int p){ ll sum = 0; vector<ll> v; for(int i : e[c]) if(i != p) v.pb(rec(i, c)); if(v.empty()) return a[c]; sum = accumulate(all(v), 0ll); ll mxp = max(maxpair(v), maxpair2(v)); bool ng = sum < a[c] || sum - mxp > a[c]; if(ng){ cout << "NO" << endl; exit(0); } return 2 * a[c] - sum; } int main(){ cin.tie(0); cin.sync_with_stdio(0); cin >> n; rep(i, n) cin >> a[i]; e.resize(n); rep(i, n - 1){ int j, k; cin >> j >> k; j--; k--; e[j].pb(k); e[k].pb(j); } int p = -1; rep(i, n) if(e[i].size() > 1) p = i; if(p < 0){ cout << (a[0] != a[1] ? "NO" : "YES") << endl; return 0; } cout << (rec(p, p) ? "NO" : "YES") << endl; return 0; }
0
78,485,899
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<map> #include<set> #include<utility> #include<cmath> using namespace std; int main(){ int N; double v[100]; cin >> N; for (int i = 0; i < N; i++){ cin >> v[i]; } sort(v, v + N); double ans = (v[0] + v[1])/2; for(int i = 2; i < N; i++){ ans = (ans + v[i]) /2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long test; test=1; while(test--) { long a,b; cin>>a>>b; if(a==b)cout<<"Draw"; else if(a==1 || b==1) { if(a==1)cout<<"Alice"; else cout<<"Bob"; } else { if(a>b)cout<<"Alice"; else cout<<"Bob"; } } }
0
13,677,428
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; void xinf(int x,int y,int W,int H,bool xy[][101]){ for(int i = 0;i <= x;i++){ for(int j = 0;j <= H;j++){ xy[i][j] = false; } } } void xsup(int x,int y,int W,int H,bool xy[][101]){ for(int i = x+1;i <= W;i++){ for(int j = 0;j <= H;j++){ xy[i][j] = false; } } } void yinf(int x,int y,int W,int H,bool xy[][101]){ for(int i = 0;i <= W;i++){ for(int j = 0;j <= y;j++){ xy[i][j] = false; } } } void ysup(int x,int y,int W,int H,bool xy[][101]){ for(int i = 0;i <= W;i++){ for(int j = y+1;j <= H;j++){ xy[i][j] = false; } } } int main(void) { int W,H,N,cnt = 0,x,y,a; bool xy[101][101]; cin >> W >> H >> N; for(int i = 0;i <= W;i++){ for(int j = 0;j <= H;j++){ xy[i][j] = true; } } rep(i, N){ cin >> x >> y >> a; switch (a) { case 1: xinf(x,y,W,H,xy); break; case 2: xsup(x,y,W,H,xy); break; case 3: yinf(x,y,W,H,xy); break; default: ysup(x,y,W,H,xy); break; } } for(int i = 1;i <= W;i++){ for(int j = 1;j <= H;j++){ if(xy[i][j] == true) cnt++; } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const ll INF = (1LL << 60) * (-1); template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int n; cin >> n; int a[n+10][3]; rep(i, n) rep(j, 3) cin >> a[i][j]; ll dp[n+10][3] = {0}; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j != k) chmax(dp[i+1][k], dp[i][j] + a[i][k]); } } } ll ans = 0; rep(i, 3) chmax(ans, dp[n][i]); cout << ans << endl; return 0; }
0
52,673,943
#include<iostream> #include<cstring> #include<cstdio> int main() { char a[10],b[10],c[10]; scanf("%s %s %s",a,b,c); printf("%c%c%C\n",toupper(a[0]),toupper(b[0]),toupper(c[0])); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, D; cin >> N >> D; vector<vector<int>> data(N, vector<int> (D)); for(int i = 0; i < N; i++) { for(int j = 0; j < D; j++) { cin >> data.at(i).at(j); } } int count = 0; for(int i = 0; i < N - 1; i++) { for(int j = i + 1; j < N; j++) { int sum = 0; for(int k = 0; k < D; k++) { sum += pow(data.at(i).at(k) - data.at(j).at(k), 2); } for(int k = 1; k * k <= sum; k++) { if(k * k == sum) { count++; } } } } cout << count << endl; }
0
58,909,727
#include<bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long ll; typedef pair<ll,ll> P; const ll mod=1000000007; const ll LINF=1LL<<60; const int INF=1<<30; const int MAX = 510000; ll fac[MAX],finv[MAX],inv[MAX]; void COMinit(){ fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } ll COM(int n,int k){ if(n < k){ return 0; } if (n < 0 || k < 0){ return 0; } return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } int main(){ int n,K;cin>>n>>K; COMinit(); if (K > COM(n - 1,2)) cout << -1 << endl; else{ vector<vector<bool>> g(n + 1,vector<bool> (n + 1,false)); int m = 0; for(int i = 2; i <= n; i++) { g[1][i] = true; m++; } for(int i = 2; i <= n; i++) { for(int j = i + 1; j <= n; j++) { g[i][j] = true; m++; } } for(int i = 0; i < K; i++) { bool flag = true; for(int j = 2; j <= n; j++) { for(int k = j + 1; k <= n; k++) { if (g[j][k] && flag){ g[j][k] = false; flag = false; m--; } } } } cout << m << endl; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if (g[i][j])cout << i << " " << j << endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; ll mm=1000000000;ll MM=mm+7; #define rep(i, n) for(int i=0;i<n;i++) #define PI 3.141592653589793 int main(){ string s; cin >>s; int n=s.size(); if(n==26){ int chk=5000; for(int i=24;i>=0;i--){ int a=s.at(i); int b=s.at(i+1); if(a<b){ chk=i; break; } } if(chk==5000)cout <<-1 << endl; else{ int m=26-chk; vector<char> l(m); rep(i,m){ l.at(i)=s.at(chk+i); } sort(l.begin(),l.end()); rep(i,chk){ cout << s.at(i); } rep(i,m){ if(l.at(i)==s.at(chk)){ cout << l.at(i+1) << endl; } } } } else{ set<char> l; rep(i,n){ l.insert(s.at(i)); } char ans; rep(i,26){ int k='a'+i; if(l.count(char(k))){} else{ ans=char(k); break; } } cout << s << ans << endl; } }
0
79,588,310
#include <bits/stdc++.h> #define Fast cin.tie(0), ios::sync_with_stdio(0) #define All(x) x.begin(), x.end() #define louisfghbvc int t; cin >> t; while(t--) #define sz(x) (int)(x).size() using namespace std; typedef long long LL; typedef pair<LL, LL> ii; typedef vector<LL> vi; template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; } template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cerr << "\n"; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } const int N = 1e3+5; void solve(){ string s, t; cin >> s >> t; int n = sz(s), m = sz(t); int mn = m; for(int i = 0; i+m-1 < n; ++i){ int ch = 0; for(int j = 0; j < m; ++j){ if(s[i+j] != t[j]){ ch++; } } mn = min(mn, ch); } cout << mn << "\n"; } int main() { Fast; solve(); return 0; }
#include <iostream> #include <algorithm> #include <complex> #include <utility> #include <vector> #include <string> #include <queue> #include <tuple> #include <cmath> #include <bitset> #include <cctype> #include <set> #include <map> #include <numeric> #include <functional> #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); } template<class itr> void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template<class itr> void array_output(itr start,itr goal){ string ans = "",k = " "; for (auto i = start;i != goal;i++) ans += to_string(*i)+k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e18; const ll MOD = 1000000007; typedef pair<ll,ll> P; const ll MAX = 100005; constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1}; constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,d,a,x,h; cin >> n >> d >> a; ll cnt = 0; vector<ll> damage(n+1,0); vector<P> monster(n); rep(i,n){ cin >> x >> h; monster[i] = P(x,h); } SORT(monster); rep(i,n){ ll heart = monster[i].second-damage[i],x = monster[i].first,b; if (heart <= 0){ damage[i+1] += damage[i]; continue; } if (heart%a == 0){ b = heart; cnt += heart/a; } else{ b = (heart/a+1)*a; cnt += heart/a+1; } ll k = lower_bound(all(monster),P(x+2*d,INF))-monster.begin(); damage[i] += b; damage[k] -= b; damage[i+1] += damage[i]; } PRINT(cnt); }
0
85,672,162
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; int a,b; string s; int main(void){ cin>>a>>b>>s; for(int i=0;i<a+b+1;i++){ if(i==a){ if(s[i]!='-'){ cout<<"No"<<endl; return 0; } }else{ if(s[i]=='-'){ cout<<"No"<<endl; return 0; } } } cout<<"Yes"<<endl; }
#include <bits/stdc++.h> #define rep(i, a, b) for(int i = a; i < b; i++) #define Rep(i, a, b) for(int i = a; i <= b; i++) #define repr(i, a, b) for(int i = a; i >= b; i--) #define _GLIBCXX_DEBUG #define Vl vector<ll> #define Vs vector<string> #define Vp vector<pair<ll, ll>> #define ld long double using ll = long long; #define ALL(v) (v).begin(),(v).end() #define endl "\n" #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define co(x) cout << x << endl #define coel cout << endl #define pb push_back #define sz(v) ((ll)(v).size()) using namespace std; const double pi = acos(-1.0); const ll MOD = 1e9 + 7; const ll INF = 1LL << 60; #define pp pair<ll, pair<ll, ll>> #define fi first #define se second void print(Vl vec){ rep(i, 0, sz(vec)){ if(i) cout << " "; cout << vec[i]; } coel; } set<ll> makec(){ set<ll> c; c.insert(1); ll a = 6; while(a <= 100000){ c.insert(a); a *= 6; } ll b = 9; while(b <= 100000){ c.insert(b); b *= 9; } return c; } int main() { ll n; cin >> n; set<ll> c = makec(); Vl dp(n+1, INF); dp[0] = 0; rep(i, 0, n){ for(auto j : c){ if(i + j > n) continue; chmin(dp[i+j], dp[i]+1); } } co(dp[n]); return 0; }
0
61,350,091
#include<iostream> #include<cmath> #include<cstdio> #include<vector> #include<set> #include<map> #include<stack> #include<queue> #include<utility> #include<algorithm> #include<cstring> #include<sstream> #include <iomanip> using namespace std; typedef long long ll ; typedef double db; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector< pair<int,int> > vii; const double pi = 2*acos(0) ; #define pf printf #define sf scanf #define pb(a) push_back(a) #define mp make_pair #define fi first #define se second #define for0(i,n) for(ll i=0;i<n;i++) #define for1(i,n) for(int i=1;i<=n;i++) #define forab(i,a,b) for(int i=a;i<=b;i++) #define lcm(a, b) ((a)*((b)/gcd(a,b))) #define sq(a) (a)*(a) #define nw "\n" #define abs(x) fabs(x) #define pcase(z,x) cout<<"Case "<<z<<": "<<x<<"\n" int main() { ll n,p,t; cin>>n; map<ll,ll>m; for0(i,n){ cin>>p; m[p]++; } ll x=0,y=0; for(auto it:m){ if(it.se>=2){t=it.fi ; x = max(x,t); } } m[x] -= 2; for(auto it:m){ if(it.se>=2){t=it.fi; y = max(y,t);} } ll ans = x*y; cout<<ans<<nw; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";} template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;} template<class T>void chmin(T&a,const T&b){if(a>b)a=b;} template<class T>void chmax(T&a,const T&b){if(a<b)a=b;} int nextInt() { int x; scanf("%d", &x); return x;} bool possible(ll A, ll B, ll K) { ll s = max(1LL, K/2 - 100); ll t = min(K/2 + 100, K); ll p = 0; for (ll i = s; i <= t; i++) { ll x = i; ll y = K+1-i; if (x >= A) x++; if (y >= B) y++; chmax(p, x * y); } return p < A*B; } int main2() { int Q = nextInt(); while(Q-->0) { ll A = nextInt(); ll B = nextInt(); ll lo = 0; ll hi = 2 * max(A, B) + 10; while (hi - lo > 1) { ll mid = (hi + lo) / 2; if (possible(A, B, mid)) lo = mid; else hi = mid; } cout << lo << endl; } return 0; } int main() { for (;!cin.eof();cin>>ws) main2(); return 0; }
0
94,635,273
#include <bits/stdc++.h> using namespace std; #define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define INFINITO 1000000000 #define ll long long #define vi vector<int> #define pb push_back #define pii pair<int, int> #define mp make_pair #define ff first #define ss second #define all(x) x.begin(), x.end() #define fo(i, n) for( int i = 0; i < n; i++ ) int main() { string s; ll k; cin >> s >> k; int ult1 = 0; int dif; for ( int i = 0; i < (int) s.size(); i++ ) { if ( s[i] != '1' ) { dif = s[i] - '0'; break; } ult1++; } cout << (k <= ult1 ? 1 : dif) << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n); for(int i = 0; i < n; ++i) { int num; cin >> num; a[i] = num; b[i] = num; } sort(a.begin(), a.end()); int max = a[n-1]; int next; bool dup = false; for(int i = n-2; i >=0; --i) { if(a[i] == max) { dup = true; } else { next = a[i]; break; } } for(int i = 0; i < n; ++i) { if(b[i] != max) { cout << max << endl; } else { if(dup) cout << max << endl; else cout << next << endl; } } }
0
80,269,524
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define PI acos(-1) typedef long long ll; ll gcd(ll x,ll y){ if(y==0) return x; else return gcd(y,x%y); } ll lcm(ll x,ll y){ return x/gcd(x,y)*y; } int main(){ int n; cin>>n; vector<int> a(n); rep(i,n){ cin>>a[i]; } int ans=0; int tmp=0; for(int i=0;i<n-1;i++){ if(a[i]>=a[i+1]){ tmp++; } else{ tmp=0; } ans=max(ans,tmp); } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define MAX 100000 #define NIL -1 #define MOD 1000000007 typedef int _loop_int; #define rep(i,n) for(int i = 0; i < n; i++) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define debug(x) cout<<#x<<": "<<x<<endl #define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;} inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);} #define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; } template<class T> inline void print(const T& x){cout << setprecision(12) << x << endl;} template<class T, class... A> inline void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const long long INF = 1LL<<60; int main() { ll n, a, b; cin >> n >> a >> b; ll ans = n / (a+b) * a; n %= (a+b); if(n>=a) { print(a+ans); } else { print(ans+n); } return 0; }
0
85,072,551
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) int main(){ ll N; cin >> N; vector<ll> t(N+1, 0), x(N+1, 0), y(N+1, 0); rep(i, 0, N) cin >> t[i+1] >> x[i+1] >> y[i+1]; rep(i, 0, N){ ll dx = abs(x[i+1] - x[i]); ll dy = abs(y[i+1] - y[i]); ll dt = t[i+1] - t[i]; if((dy + dx) % 2 != dt % 2 || dx + dy > dt){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> #include <algorithm> #include <functional> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define DEBUG #define PI 3.141592653589793238462643383279 #define _GLIBCXX_DEBUG #ifdef DEBUG #define s(...) show(__VA_ARGS__); #define sl(...) show(__VA_ARGS__);cout<<endl; #else #define s(...) #define sl(...) #endif void show() {} template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);} #define REP(i, n) for(ll i = 0; i < n; i++) #define REPR(i, n) for(ll i = n; i >= 0; i--) #define FOR(i, m, n) for(ll i = m; i < n; i++) #define REP1(i, n) for(ll i = 1; i <= n; i++) #define REPR1(i, n) for(ll i = n; i >= 1; i--) #define FOR1(i, m, n) for(ll i = m; i <= n; i++) const ll INF = LLONG_MAX; const ull MOD = 1000000007; #define VEC(type,A,N) vector<type> A(N) #define VECi(type,A,N,i) vector<type> A(N,i) #define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M)) #define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i)) #define ALL(v) v.begin(), v.end() ll frac(ll k){ int s = 1; for (ll i=1; i<=k; ++i)s *= i; return s; } ll gcd(ll a, ll b){ if (a%b==0)return(b); else return(gcd(b, a%b)); } ll lcm(ll a,ll b){ return a*b/gcd(a,b); } ll antidiv(ll N,ll C,ll D){ return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D)); } vector<ll> yakusuu(ll N){ vector<ll> ret; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { ret.push_back(i); if (i * i != N) ret.push_back(N / i); } } sort(ret.begin(), ret.end()); return ret; } int main(){ ll N,K,R,Si,P; string S; cin>>N>>K>>R>>Si>>P>>S; ll cnt=0; REP(i,K){ S+='?'; } REP(i,S.length()){ if(S[i]=='r'){ cnt+=P; }else if(S[i]=='s'){ cnt+=R; }else if(S[i]=='p'){ cnt+=Si; } if(S[i]==S[i+K]){ S[i+K]='?'; } } cout<<cnt; cout<<endl; return 0; }
0
86,544,501
#include <iostream> #include <iomanip> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <algorithm> #include <cstdio> #include <utility> #include <string> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <numeric> using namespace std; typedef uint64_t u64; typedef int64_t s64; typedef uint32_t u32; typedef int32_t s32; typedef vector<s32> vs32; typedef vector<u32> vu32; typedef vector<s64> vs64; typedef vector<u64> vu64; const double PI=3.14159265358979323846; #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define MIN(x, y) ((x) > (y) ? (y) : (x)) #define rep(i, N) for(int i = 0; i < N; ++i) #define CEIL(x, y) (((x) + (y) - 1) / (y)) #define MOD 1000000007ULL #define IN(l, r, x) ((l) <= (x) && (x) < (r)) int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; string ans{s}; rep (i, s.size()) { if (s[i] == 'A') ans[i] = 'T'; else if (s[i] == 'T') ans[i] = 'A'; else if (s[i] == 'G') ans[i] = 'C'; else ans[i] = 'G'; } cout << ans << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define SORT(c) sort((c).begin(),(c).end()); #define pb push_back #define MP make_pair #define pii pair<int,int> #define pcc pair<char,char> #define pic pair<int,char> #define pci pair<char,int> #define VS vector<string> #define VI vector<int> #define pi 3.141592653589793 #define ll long long #define ull unsigned long long #define w(x) int x;cin>>x;while(x--) #define fast ios_base::sync_with_stdio(0) #define sz size() typedef unsigned long long UL; template<typename T>inline T S(T a) { return a*a; } template<class T>inline string tostring(T a) { ostringstream os(""); os << a; return os.str(); } template<typename T>inline ll tolong(T a) { ll res; istringstream os(a); os>>res; return res; } template<typename T>inline T gcd(T a, T b) { if (b == 0)return a; else return gcd(b, a % b); } template<typename T>inline T bigmod(T a, T b, T m) { if (b == 0)return 1; else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m; else return (a % m*bigmod(a, b - 1, m)) % m; } const int inf = (int)1e9 + 5; const ll linf = (ll)1e16 + 5; const ll modd = (ll)1e9 + 7; const int mod = 10000007; void pr (int f) { if(f==1) cout<<"YES\n"; else cout<<"NO\n"; } map<int,int>mp; multiset<string> st; multiset<string> :: iterator it; deque <char> q ; int vis [1000]; int main() { fast ; ll n ; cin >> n; cout <<((n)*(n+1))/2<<endl; }
0
1,207,239
#include <iostream> #include <vector> #include <string> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <algorithm> #include <cstdlib> #include <cstdio> #include <functional> #include <numeric> #include <cmath> #include <climits> #include <limits> #include <cfloat> #include <iomanip> #include <sstream> #include <cstring> #include <cctype> #include <fstream> #include <ctime> #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() #define NIL -1 using namespace std; struct node{ int id; int d; }; node v[105]; bool vis[105]; vector<int> g[105]; void bfs (int u ) { vis[u] = true; v[u].d = 0; queue<node> que; que.push (v[u] ); while (!que.empty() ){ node cur = que.front(); que.pop(); int id = cur.id; int d = cur.d; rep (j, g[id].size() ){ int next = g[id][j]; if (!vis[next] ){ vis[next] = true; v[next].d = d + 1; que.push (v[next] ); } } } } int main() { memset (vis, false, sizeof (vis ) ); ios_base::sync_with_stdio(0); int n; cin >> n; rep (i, n+1 ) g[i].clear(); rep (i, n+1 ) v[i].id = i, v[i].d = NIL; rep (i, n ){ int id; cin >> id; int k; cin >> k; while (k-- ){ int v; cin >> v; g[id].push_back (v ); } } bfs (1 ); for (int i = 1; i <= n; i++ ){ cout << v[i].id << ' ' << v[i].d << endl; } return 0; }
#include <iostream> #include <string> #include <array> #include <algorithm> #include <vector> #include <string> #include <set> #include <cctype> #include <map> #include <stdio.h> #include <string.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") \ #define FOR(i,l,r) for(size_t i=(l);i<(r);++i) #define REP(i,n) FOR(i,0,n) using namespace std; int main() { int n; bool ans = true; string prev,cur; map<string,bool> mp; cin >> n; REP(i,n){ cin >>cur; if(i == 0) { prev = cur; mp[cur] = true; } else{ if((prev[prev.length()-1] != cur[0])||(mp.count(cur) != 0)){ ans = false; break; }else{ prev = cur; mp[cur] = true; } } } cout << ((ans)?"Yes":"No"); }
0
97,318,856
#include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr int Inf = 1000000000; constexpr ll INF= 1e18; constexpr ll MOD = 1000000007; const double PI = 3.1415926535897; typedef pair<ll,int> P; int main() { int N; cin >> N; vector<vector<char>> vec(N,vector<char>(N)); for(int i = 0;i < N;i++) { for(int j = 0;j < N;j++) { cin >> vec.at(i).at(j); } } int ret = 0; for(int i = 0;i < N;i++) { bool ret1 = true; for(int j = 0;j < N;j++) { for(int k = 0;k < N;k++) { int A,B; if(k + i >= N) { A = k + i - N; } else { A = k + i; } if(j - i < 0) { B = j - i + N; } else { B = j - i; } if(vec.at(j).at(k) != vec.at(A).at(B)) { ret1 = false; } } } bool ret2 = true; for(int j = 0;j < N;j++) { for(int k = 0;k < N;k++) { int A,B; if(k - i < 0) { A = k - i + N; } else { A = k - i; } if(j + i >= N) { B = j + i - N; } else { B = j + i; } if(vec.at(j).at(k) != vec.at(A).at(B)) { ret2 = false; } } } if(i == 0 && ret1 == true) { ret += N; } if(i != 0 && ret1 == true) { ret += N - i; } if(i != 0 && ret2 == true) { ret += N - i; } } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; int const 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; } int dp[1001][1001]; int main(){ cin.tie(0); ios::sync_with_stdio(false); string s1,s2; cin>>s1>>s2; fill(dp[0],dp[1001],MOD); for (int i = 0; i < s1.size(); i++)dp[i][0]=i; for (int i = 0; i < s2.size(); i++)dp[0][i]=i; for (int i = 0; i < s1.size(); i++){ for (int j = 0; j < s2.size(); j++){ chmin(dp[i+1][j+1],min(dp[i][j]+(s1[i]!=s2[j]?1:0),min(dp[i+1][j]+1,dp[i][j+1]+1))); } } cout<<dp[s1.size()][s2.size()]<<'\n'; }
0
91,513,563
#include <bits/stdc++.h> using namespace std; #define int long long #define ii pair<int,int> #define fi first #define sc second #define all(x) (x).begin(),(x).end() int get(int a, int b, int x) { int l = ((a - 1) / x + 1) * x; int r = b / x * x; return (r - l) / x + 1; } int lcm(int a, int b) { return a / __gcd(a, b) * b; } void MAIN() { int a, b, c, d; cin >> a >> b >> c >> d; cout << (b - a + 1) - get(a, b, c) - get(a, b, d) + get(a, b, lcm(c, d)) << '\n'; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int T = 1; while (T--) MAIN(); }
#include<bits/stdc++.h> using namespace std; const long long int modu=1e9+7; #define endl '\n' #define ll long long int #define vi vector<int> #define vl vector<ll> #define inp(x) for(auto &t:x) cin>>t; #define itr vector<int>::iterator #define debug(a) cout << #a << "=" << a << ' '<<endl; #define out(x) for(auto &t:x) cout<<t<<" "; cout<<endl; #define ff first #define ss second #define pb push_back #define initialize(a,v) for(int i=0;i<a.size();++i) a[i]=v; #define all(x) x.begin(),x.end() #define mpt(mp) for(auto it=mp.begin();it!=mp.end();it++) #define trav(x) for(int i=0;i<(int)x.size();++i) #define mkp(a,b) make_pair(a,b) #define sz(x) (int)x.size() int noofdig(int N) { return floor(log10(N))+1; } ll f(ll a) { return 0; } void pre() { } void solve() { ll n; cin>>n; vl a(n); inp(a) ll mx=-1; ll ans=0; for(int i=0;i<n;++i) { mx=max(mx,a[i]); ans+=abs(a[i]-mx); } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; while(t--) { solve(); } }
0
78,803,774
#include <iostream> using namespace std; int main() { int t , x; double ans; cin >> t >> x; ans = (double)t / (double)x; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define INF 2e18 #define eps 1e-9 #define FastRead ios_base::sync_with_stdio(0);cin.tie(0) #define fRead freopen("input.txt","r",stdin) #define fWrite freopen("output.txt","w",stdout) #define LL long long #define ull unsigned long long #define PI acos(-1.0) #define pb push_back #define mk make_pair #define pii pair<int,int> #define pLL pair<LL,LL> #define ff first #define ss second #define all(a) a.begin(),a.end() #define SQR(a) ((a)*(a)) #define min3(a,b,c) min(a,min(b,c)) #define max3(a,b,c) max(a,max(b,c)) #define min4(a,b,c,d) min(min(a,b),min(c,d)) #define max4(a,b,c,d) max(max(a,b),max(c,d)) #define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e)) #define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e)) #define vi vector <int> #define vL vector <LL> #define LB(a,x) (lower_bound(all(a),x)-a.begin()) #define UB(a,x) (upper_bound(all(a),x)-a.begin()) #define prec(n) fixed << setprecision(n) #define MEM(a,x) memset(a,x,sizeof(a)) #define SORT(v) sort(v.begin(),v.end()) #define REV(v) reverse(v.begin(),v.end()) #define Unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define ROF(i,a,b) for(int i=a;i>=b;i--) #define REP(i,b) for(int i=0;i<b;i++) #define IT(it,x) for(it=x.begin();it!=x.end();it++) map<string,int>mp; vector<string>v; int main() { int n; cin>>n; while(n--) { string s; cin>>s; sort(all(s)); mp[s]++; v.pb(s); } LL ans=0; Unique(v); for(int i=0; i<v.size(); i++) { LL cnt=mp[v[i]]; ans+=((cnt-1)*cnt)/2; } cout<<ans; }
0
38,121,143
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> 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(int i=0;i<x;i++) #define repn(i,x) for(int 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()) int n,a[300005],cnt[300005]; ll rui[300005],num[300005]; int main(){ scanf("%d",&n); rep(i,n){ scanf("%d",&a[i]); cnt[a[i]]++; } rep(i,300005){ rui[cnt[i]]+=cnt[i]; num[cnt[i]]++; } for(int i=1;i<=300004;i++){ rui[i] += rui[i-1]; num[i] += num[i-1]; } repn(k,n){ int lb = 0, ub = n/k+1; while(ub-lb > 1){ int mid = (lb+ub)/2; ll sum = rui[mid] + (num[300004]-num[mid]) * mid; if(sum >= mid * k) lb = mid; else ub = mid; } printf("%d\n",lb); } }
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define repr(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) for(int i=0;i<n;i++) #define invrepr(i,a,b) for(int i=b-1;i>=a;i--) #define invrep(i,n) invrepr(i,0,n) #define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr) #define P pair<int,int> const int MOD=1e9+7; const int INF=1e9; const double PI=acos(-1); const int MAX=200010; ll binary_power(ll a, ll n) { if (n==0) return 1; ll k=binary_power(a,n/2); if (n%2==0) return k*k; else return k*k*a; } int main() { ios_base::sync_with_stdio(false); int n,p; cin >> n >> p; int odd=0,even=0; rep(i,n) { int a; cin >> a; if (a%2==0) ++even; else ++odd; } ll ans; if (odd==0) { if (p==0) ans=binary_power(2,n); else ans=0; } else { ans=binary_power(2,n-1); } cout << ans << endl; return 0; }
0
3,992,887
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair< ll, ll > Pi; #define rep(i,n) for(int i=0;i<(n);i++) #define rep2(i,n) for(int i=1;i<=(n);i++) #define rep3(i,i0,n) for(int i=i0;i<(n);i++) #define pb push_back #define mod 1000000007 const ll INF = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) {return a/gcd(a,b)*b;} #define all(x) x.begin(), x.end() #define mp make_pair bool compare(Pi a, Pi b) { if(a.first != b.first){ return a.first < b.first; }else{ return a.second < b.second; } } bool In_map(ll y,ll x,ll h,ll w){ if(y<0 || x<0 || y>=h || x>=w){ return 0; }else{ return 1; } } const vector<ll> dx{1,0,-1,0}; const vector<ll> dy{0,1,0,-1}; int main() { ll A,B; cin >>A>>B; if(A%3==0||B%3==0 || (A+B)%3==0){ cout<<"Possible"<<endl; }else{ cout << "Impossible" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, M; cin >> N >> M; ll A, B; vector<vector<ll>> G(N); for (ll i=0; i<M; i++) { cin >> A >> B; A--; B--; G[A].push_back(B); G[B].push_back(A); } vector<ll> dist(N,-1); queue<ll> q; dist[0] = 0; q.push(0); vector<ll> ans(N); while(!q.empty()) { ll v = q.front(); q.pop(); for (ll nv : G[v]) { if (dist[nv] != -1) { continue; } dist[nv] = dist[v] + 1; ans[nv] = v+1; q.push(nv); } } for (ll i=1; i<N; i++) { if (dist[i]==-1) { cout << "No" << endl; exit(0); } } cout << "Yes" << endl; for (ll i=1; i<N; i++) { cout << ans[i] << endl; } }
0
93,135,803
#include <iostream> using namespace std; int main() { int N; cin >> N; int i; cin >> i; cout << N - i + 1 << endl; return 0; }
#include<iostream> #include<unordered_map> #include<algorithm> #include<vector> #include<string> #include<string.h> #include<unordered_set> using namespace std; vector<int> prime_sieve(int n) { int* arr = new int[n+1]; int i, p; for (i = 0; i <= n; ++i) { arr[i] = i; } for (i = 2; i <= n; ++i) { if (arr[i] != 0) { for (p = arr[i] * arr[i]; p <= n; p += arr[i]) { arr[p] = 0; } } } vector<int> primes; for (i = 2; i <= n; ++i) { if (arr[i] != 0) { primes.push_back(arr[i]); } } return primes; } int min(int a, int b) { return a < b ? a : b; } int main() { int n; cin >> n; if (n < 1200) { cout << "ABC"; } else { cout << "ARC"; } }
0
90,273,187
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define int long long #define inf 1000000007 #define LINF 100000000000000007LL #define ll long long using namespace std; signed main(){ int n; cin>>n; cout<<0<<endl; string st; cin>>st; if( st == "Vacant" )return 0; int ok = 0, ng = n; while( ng - ok > 1 ){ int mid = (ok+ng) / 2; cout<<mid<<endl; string resp; cin>>resp; if( resp == "Vacant" ) return 0; if( ( resp == st && mid%2 == 0 ) || ( resp != st && mid % 2 == 1 ) ){ ok = mid; } else{ ng = mid; } } cout<<ng<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define lli long long #define all(i) i.begin(),i.end() #define rall(i) i.rbegin(),i.rend() #define rep0(i,j) for(int i=0;i<j;i++) #define rep1(i,j) for(int i=1;i<=j;i++) #define rep0d(i,j) for(int i=j-1;i>=0;i--) #define MOD 1000000007 #define MAX (lli)1e12 typedef pair<lli, lli> p; class Graph{ int V; vector<list<p>> adj; const int INF = (int)1e6; public: Graph(lli V): adj(V){ this->V = V; } void addEdge(int u, int v, int w){ adj[u].push_back(make_pair(v, w)); } lli edgeNum(){ lli sum=0; rep0(i,V)sum+=adj[i].size(); return sum; } bool route(lli from, lli to){ vector<lli> vec(V, -1); dfs(1,from,vec); return vec[to] >= 0; } void dfs(lli ed, lli num, vector<lli>& vec){ for(auto e: adj[num]){ if(vec[e.first] != -1)continue; vec[e.first] = num; dfs(ed+1, e.first, vec); } } vector<int> bfs(int n){ queue<int> q; vector<int> vec(V,-1); q.push(n); vec[n]=0; while(!q.empty()){ int p=q.front(); q.pop(); for(auto e:adj[p]){ if(vec[e.first]==-1){ q.push(e.first); vec[e.first] = e.second + vec[p]; } } } return vec; } vector<int> shortestPath(int src){ priority_queue< p, vector <p> , greater<p> > pq; vector<int> dist(V, INF); pq.push(make_pair(0, src)); dist[src] = 0; while (!pq.empty()) { int u = pq.top().second; pq.pop(); list<p>::iterator i; for (auto i = adj[u].begin(); i != adj[u].end(); ++i) { int v = i->first; int weight = i->second; if (dist[v] > dist[u] + weight) { dist[v] = dist[u] + weight; pq.push(make_pair(dist[v], v)); } } } for(int i=0;i<V;i++)if(dist[i]==INF)dist[i]=-1; return dist; } }; struct BIT{ vector<lli> tab; BIT(int n):tab(n+1){ rep0(i,n+1)tab[i]=0; } void add(int p, lli num){ for(++p;p<tab.size();p+=p&-p)tab[p]+=num; } lli sum(int p){ lli ans=0; for(++p;p>0;p-=p&-p)ans+=tab[p]; return ans; } void debug(){ rep0(i,tab.size())cout << tab[i] << ' '; cout << endl; } }; p operator-(const p & l,const p & r) { return {l.first-r.first,l.second-r.second}; } bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) { return left.first < right.first; } bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) { return left.second < right.second; } void dfs(lli ed, lli num, vector<map<lli,lli>>& vec){ lli n=1; for(auto e: vec[num]){ if(n == ed)n++; if(e.second != -1)continue; vec[num][e.first] = n; vec[e.first][num] = n; dfs(n, e.first, vec); n++; } } lli gcd(lli a, lli b){ if(a < b)return gcd(b, a); lli temp; while((temp = a%b)){ a=b; b=temp; } return b; } struct nCr{ vector<lli> f, rf; lli count=0; nCr(lli num): f(num), rf(num){ count = num; f[0] = 1; rep1(i, num) f[i] = (f[i - 1] * i) % MOD; rep0(i, num+1) rf[i] = inv(f[i]); } lli inv(lli x) { lli res = 1; lli k = MOD - 2; lli y = x; while (k) { if (k & 1) res = (res * y) % MOD; y = (y * y) % MOD; k /= 2; } return res; } lli C(lli n, lli k) { if(k > n || k<0)return 0; lli a = f[n]; lli b = rf[n-k]; lli c = rf[k]; lli bc = (b * c) % MOD; return (a * bc) % MOD; } }; struct UF{ vector<int> par,size; UF(int N) : par(N), size(N, 1){ rep0(i,N)par[i] = i; } int root(int x){ if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y){ int rx = root(x); int ry = root(y); if(rx == ry) return; par[rx] = ry; size[rx] += size[ry]; } bool same(int x, int y){ int rx = root(x); int ry = root(y); return rx == ry; } int getSize(int x){ return size[x]; } }; int main(){ lli h, w, a, b; cin >> h >> w >> a >> b; vector<int> temp(w); rep0(i,a)temp[i]=1; rep0(i,w-a)temp[i+a]=0; rep0(i,b){ rep0(j,w)cout << temp[j] ; cout << endl; } rep0(i,w)temp[i]=1^temp[i]; rep0(i,h-b){ rep0(j,w)cout << temp[j] ; cout << endl; } }
0
92,817,777
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N, M; cin >> N >> M; vector<pair<ll, ll>> drink(N); for (int i = 0; i < N; i++) cin >> drink[i].first >> drink[i].second; sort(drink.begin(), drink.end()); ll ans = 0; for (int i = 0; i < N; i++) { if (drink[i].second < M) { ans += drink[i].first * drink[i].second; M -= drink[i].second; } else { ans += drink[i].first * M; break; } } cout << ans << endl; }
#include <bits/stdc++.h> #include <iostream> #include <ctime> using namespace std; #define _LL long long #define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++) #define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++) int main() { string s; cin >> s; _LL k; cin >> k; int l = s.length(); bool pre = false; _LL count = 0; _LL c1 = 0; rep(i, l) { if(i == 0) continue; if( pre ) { pre = false; continue; } if(s[i - 1] == s[i]) { pre = true; count++; } } if( pre || s[l - 1] != s[0] || k == 1) { cout << count * k; } else { c1 = count; pre = true; count = 1; rep(i, l) { if(i == 0) continue; if( pre ) { pre = false; continue; } if(s[i - 1] == s[i]) { pre = true; count++; } } if( pre ) { cout << (count + c1) * (k / 2) + c1 * (k % 2); } else { cout << c1 + (k - 1) * count; } } return 0; }
0
82,959,719
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) SORT(var); REVERSE(var) #define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed #define endl '\n' const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; void solve(istream& cin, ostream& cout) { int r; cin >> r; cout << r * r << endl; } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); return 0; } #endif
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (long long i = 0; i < N; i++) using ll = long long; const int MAX = 1000000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } 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 long long INF = 1LL << 60; ll calc(ll d, ll s, ll c, ll f) { if (d < s) { return d + (s - d) + c; } if (d % f == 0) { return d + c; } ll tmp = d % f; return d + c - tmp + f; } int main() { ll N; cin >> N; vector<ll> C(N); vector<ll> S(N); vector<ll> F(N); rep(i, N - 1) { cin >> C[i] >> S[i] >> F[i]; } rep(i, N - 1) { ll d = S[i] + C[i]; for (ll j = i + 1; j < N - 1; j++) { d = calc(d, S[j], C[j], F[j]); } cout << d << endl; } cout << 0 << endl; return 0; }
0
8,058,180
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) int main() { ll n, k; cin >> n >> k; vector<ll> a(n), d(n + 1); rep(i, n) cin >> a[i]; rep(i, n) { d[i + 1] = d[i] + a[i]; d[i + 1] %= k; } map<ll, ll> mp; ll ans = 0; queue<ll> que; rep(r, n + 1) { ll t = (d[r] - r) % k; if (t < 0) t += k; ans += mp[t]; mp[t]++; que.push(t); if (que.size() >= k) { mp[que.front()]--; que.pop(); } } cout << ans << '\n'; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <functional> #include <cmath> #include <map> #include <string> #define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++) #define rep(i,n) reps(i,0,n) using namespace std; using ll = long long; int main(){ string s; cin >> s; int len = s.length()-7; rep(i,7){ if( s.substr(0,i) + s.substr(i+len,7-i) == "keyence"){ cout << "YES"<< endl; return 0; } } cout << "NO" << endl; return 0; }
0
45,503,381
#include<bits/stdc++.h> #define MAX 100001 using namespace std; struct Struct { int Left; int Right; int Dist; }; int Total,Have; Struct Array[2*MAX]; int Fa[MAX]; int Dis[MAX]; inline int Find(int X) { if(X!=Fa[X]) { register int Fax; Fax=Fa[X]; Fa[X]=Find(Fa[X]); Dis[X]+=Dis[Fax]; } return Fa[X]; } int main(void) { register int i; cin>>Total>>Have; for(i=1;i<=Have;i++) { cin>>Array[i].Left>>Array[i].Right>>Array[i].Dist; } for(i=1;i<=Total;i++) { Fa[i]=i; } for(i=1;i<=Have;i++) { register int Fl,Fr; Fl=Find(Array[i].Left); Fr=Find(Array[i].Right); if(Fl==Fr&&Dis[Array[i].Left]-Dis[Array[i].Right]!=Array[i].Dist) { cout<<"No"<<endl; return 0; } if(Fl!=Fr) { Fa[Fl]=Fr; Dis[Fl]=Array[i].Dist+Dis[Array[i].Right]-Dis[Array[i].Left]; } } cout<<"Yes"<<endl; return 0; }
#include <bits/stdc++.h> #include <math.h> #define rep(i, n) for(int i = 0; i < (n); i++) #define rrep(i, n) for(int i = 0; i <= (n); i++) using namespace std; typedef long long ll; const ll INF = 1LL<<62; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> vector<T> make_vec(size_t a){ return vector<T>(a); } template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){ return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } using Graph = vector<vector<int>>; typedef pair<int, int> P; const int MOD = 1000000007; int main(){ string S; cin >> S; int n = S.size(); int ans = 0; int red_count = 0; int blue_count = 0; rep(i,n){ if (S[i] == '0') red_count++; else blue_count++; while (red_count >= 1 && blue_count >= 1){ ans += 2; red_count--; blue_count--; } } cout << ans << endl; }
0
95,209,334
#include "bits/stdc++.h" using namespace std; int main() { long t,x; cin>>t; float sum=0.0; for(int i=1;i<=t;i++) { cin>>x; sum+=1.0/x; } cout<<fixed<<setprecision(10)<<1.0/sum<<endl; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define REP(var, a, b) for (int var = (a); var < (b); var++) #define rep(var, n) for (int var = 0; var < (n); ++var) #define ALL(c) (c).begin(), (c).end() #define rALL(c) (c).rbegin(), (c).rend() ll MOD = 1000000007; const ll INF = 1LL << 62; int main() { ll n, k; cin >> n >> k; vl a(n); rep(i, n) cin >> a[i]; if (n == 1) { if (a[0] >= k) { cout << 0 << endl; } else { cout << 1 << endl; } return 0; } vector<bitset<5001>> dp1(n), dp2(n); vvl dp3(n, vl(5001, 0)); dp1[0][0] = 0; if (a[0] < k) { dp1[0][a[0]] = 1; } REP(i, 1, n) { if (a[i] < k) { dp1[i][a[i]] = 1; } rep(v, k) { dp1[i][v] = max(dp1[i][v], dp1[i - 1][v]); if (v - a[i] >= 0) { dp1[i][v] = max(dp1[i][v], dp1[i - 1][v - a[i]]); } } } dp2[n - 1][0] = 0; dp3[n - 1][0] = 0; if (a[n - 1] < k) { dp2[n - 1][a[n - 1]] = 1; REP(v, 1, k) { dp3[n - 1][v] = dp3[n - 1][v - 1] + dp2[n - 1][v]; } } for (int i = n - 2; i >= 0; i--) { if (a[i] < k) { dp2[i][a[i]] = 1; } rep(v, k) { dp2[i][v] = max(dp2[i][v], dp2[i + 1][v]); if (v - a[i] >= 0) { dp2[i][v] = max(dp2[i][v], dp2[i + 1][v - a[i]]); } } dp3[i][0] = dp2[i][0]; REP(v, 1, k) { dp3[i][v] = dp3[i][v - 1] + dp2[i][v]; } } ll ans = 0; ll tmp = dp3[1][k - 1]; if (k - a[0] - 1 >= 0) { tmp -= dp3[1][k - a[0] - 1]; } if (a[0] < k && tmp == 0) ans++; if (a[n - 1] <= k - 1) { ll cnt = 0; REP(v, max(0LL, k - a[n - 1]), k) { if (dp1[n - 2][v]) { cnt++; break; } } if (a[n - 1] < k && cnt == 0) { ans++; } } REP(i, 1, n - 1) { if (a[i] >= k) continue; ll cnt = 0; rep(v, k) { if (dp1[i - 1][v] || v == 0) { ll tmp = dp3[i + 1][k - 1 - v]; if (k - v - a[i] - 1 >= 0) { tmp -= dp3[i + 1][k - a[i] - v - 1]; } else if (v > 0 && k - a[i] >= v) { cnt++; continue; } if (tmp > 0) { cnt++; } } } if (cnt == 0) { ans++; } } cout << ans << endl; return 0; }
0
28,796,614
#include <cmath> #include <iostream> #include <vector> #include <queue> #include <deque> #include <map> #include <set> #include <stack> #include <tuple> #include <bitset> #include <algorithm> #include <functional> #include <utility> #include <iomanip> #define typeof(x) __typeof__(x) #define int long long int #define mod(x) ((x % MOD) + MOD) % MOD #define rep(i,a,b) for(int i=(a);i<(b);++i) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i) #define ALL(c) (c).begin(),(c).end() #define SIZE(c) (int)((c).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define SORT(c) sort(ALL(c)) #define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin()) #define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin()) #define COUNT(c,x) (int)(UB(c,x)-LB(c,x)) #define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end()); #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl; using namespace std; typedef pair<int,int> P; struct edge { int to, cost; }; const int INF = 1e18; const int MOD = 1e9+7; template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) { int len = v.size(); for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << " "; } return s; } signed main() { int K; cin >> K; int x = K / 50, y = K % 50; vector<int> a(50, 49 + x - y); rep(i, 0, y) { a[i] += 51; } cout << 50 << endl; cout << a << endl; return 0; }
#include <bits/stdc++.h> #define F(i,j,k) for(int i=(j);i<=(k);++i) #define _F(i,j,k) for(int i=(j);i<(k);++i) #define D(i,j,k) for(int i=(j);i>=(k);--i) #define _D(i,j,k) for(int i=(j);i>(k);--i) #define rep(it,s) for(__typeof(s.begin()) it=s.begin();it!=s.end();++it) #define Rep(a,s) for(auto a:s) #define PB push_back #define MP make_pair #define FF first #define SS second typedef long long ll; typedef unsigned long long ull; using namespace std; template<class Type>ll quick_pow(Type x,Type y,Type Mod){ ll res=1; while(y){ if(y&1)res=res*x%Mod; x=x*x%Mod,y>>=1; } return res; } template<class Type>ll inv(Type x,Type Mod){return quick(x,Mod-2,Mod);} namespace IO{ template <class T> inline void read(T &x){ x=0;int f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar(); x*=f; } }; using namespace IO; ll solve(ll x,ll y){ if(x>y)swap(x,y); if(y%x==0)return (2*(y/x)-1)*x; else return 2*(y/x)*x+solve(y%x,x); } int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif ll n,x; cin>>n>>x; cout<<n+solve(x,n-x)<<endl; return 0; }
0
73,285,937
#include <bits/stdc++.h> #include <regex> using namespace std; typedef long long int ll; typedef pair<int, int> P; #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100000 #define PB push_back #define MP make_pair #define F first #define S second #define Z class #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); #define VAR(type, ...) \ type __VA_ARGS__; \ MACRO_VAR_Scan(__VA_ARGS__); template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First &first, Rest &... rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC_ROW(type, n, ...) \ std::vector<type> __VA_ARGS__; \ MACRO_VEC_ROW_Init(n, __VA_ARGS__); \ for (int w_ = 0; w_ < n; ++w_) \ { \ MACRO_VEC_ROW_Scan(w_, __VA_ARGS__); \ } template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); } template <typename First, typename... Rest> void MACRO_VEC_ROW_Init(int n, First &first, Rest &... rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; } template <typename First, typename... Rest> void MACRO_VEC_ROW_Scan(int p, First &first, Rest &... rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define MAT(type, c, m, n) \ std::vector<std::vector<type>> c(m, std::vector<type>(n)); \ for (auto &R : c) \ for (auto &w : R) \ std::cin >> w; template <typename T> void MACRO_OUT(const T t) { std::cout << t; } #define OUT(...) MACRO_OUT(__VA_ARGS__); #define SP std::cout << " "; #define TAB std::cout << "\t"; #define BR std::cout << "\n"; #define ENDL std::cout << std::endl; #define YES() printf("YES\n") #define NO() printf("NO\n") #define isYES(x) printf("%s\n", (x) ? "YES" : "NO") #define Yes() printf("Yes\n") #define No() printf("No\n") #define yes() printf("yes\n") #define no() printf("no\n") #define ln cout << '\n' template <Z A> void pr(A a) { cout << a; ln; } template <Z A, Z B> void pr(A a, B b) { cout << a << ' ' << b << endl; } template <typename T> T square(T x) { return x * x; } template <class T> T GCD(T a, T b) { T r; while (a) r = b, b = a, a = r % a; return b; } template <class T> T LCM(T a, T b) { return a / GCD(a, b) * b; } #define chmax(x, y) (x = max(x, y)) #define chmin(x, y) (x = min(x, y)) #define rep(i, n) for (ll i = 0; i < (n); i++) #define repe(i, n) for (ll i = 0; i <= (n); i++) #define repd(i, n) for (ll i = n; i > 0; i--) #define repde(i, n) for (ll i = n; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i < (b); i++) #define FORE(i, a, b) for (ll i = a; i <= (b); i++) #define FORD(i, a, b) for (ll i = a; i >= (b); i--) #define FORA(i, I) for (const auto &i : I) #define ALL(x) x.begin(), x.end() typedef vector<int> vi; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vi> vvi; typedef vector<ll> vl; #define ERASE(x) x.erase(unique(ALL(x)), x.end()); bool yes = 0; bool boo = 0; int mx = -100000, mn = 100000; int sum = 0; int ans = 0; int co = 0; int main() { VAR(int, N); map<string, int> mp1, mp2; rep(i, N) { VAR(string, s); mp1[s]++; } int M; cin >> M; rep(i, M) { VAR(string, s); mp2[s]++; } int ans = 0; for (auto mp : mp1) { string s = mp.first; int n = mp.second; ans = max(ans, n - mp2[s]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rev(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define rev2(i, s, n) for (int i = (int)(n) - 1; i >= (int)(s); i--) #define bitrep(i, n) for (int i = 0; i < (1 << (int)(n)); i++) #define bitrep2(i, s, n) for (int i = (s); i < (1 << (int)(n)); i++) const int di[8] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dj[8] = {0, 1, 0, -1, -1, 1, 1, -1}; using ll = int64_t; #define all(v) v.begin(), v.end() using vi = vector<int>; using vvi = vector<vector<int>>; using vu = vector<size_t>; using vvu = vector<vector<size_t>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vc = vector<char>; using vvc = vector<vector<char>>; using vs = vector<string>; using vvs = vector<vector<string>>; #define fi first #define sj second using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; #define lcm(a, b) a / __gcd(a, b) * b #define dist(a, b) sqrt(pow(a.fi - b.fi, 2) + pow(a.sj - b.sj, 2)) #define println(x) cout << x << endl #define Yes println("Yes") #define No println("No") #define YES println("YES") #define NO println("NO") void dfs(int n, vector< vector<int> >& ki, vector<int>& c, vector<bool>& seen) { seen[n] = true; rep(i, ki[n].size()) { if (seen[ki[n][i]] == false) { c[ki[n][i]] += c[n]; dfs(ki[n][i], ki, c, seen); } } } int main() { int n, q; cin >> n >> q; vector< vector<int> > ki(n, vector<int>()); rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; ki[a].push_back(b); ki[b].push_back(a); } vector<int> c(n, 0); rep(i, q) { int p, x; cin >> p >> x; p--; c[p] += x; } vector<bool> seen(n, false); dfs(0, ki, c, seen); rep(i, n) { cout << c[i]; if (i == n - 1) cout << endl; else cout << " "; } }
0
61,493,826
#include<bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(long long i=(l);i<(r);++i) #define REP(i,n) FOR(i,0,n) #define REPS(i,n) FOR(i,0,n+1) #define int long long #define mp make_pair #define pb push_back #define eb emplace_back const int MOD=1e9+7; const int INF=1e18; signed main(){ int A,c; char b; cin>>A>>b>>c; if(b=='+')cout<<A+c<<endl; else cout<<A-c<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin >> a >> b; int ans=0; if(abs(a)>abs(b)){ ans+=abs(a)-abs(b); if(a>0) ans++; if(b>0) ans++; }else if(abs(a)<abs(b)){ ans+=abs(b)-abs(a); if(a<0) ans++; if(b<0) ans++; }else{ ans=1; } cout << ans << endl; return 0; }
0
8,539,082
#include <iostream> #include <vector> #include <string> #include <list> #include <queue> #include <algorithm> #define rep(i, n) for(i = 0; i < (n); i++) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define MOD 1000000007 #define PI 3.14159265358979323846 #define INF 1 << 30 using namespace std; typedef long long ll; typedef pair<int, int> pp; int main(void) { int num, i, r, g, b, k; cin >> r >> g >> b >> k; while (g <= r) { g <<= 1; k--; } while (b <= g) { b <<= 1; k--; } if (k < 0) printf("No\n"); else printf("Yes\n"); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { int t=1; while(t--) { ll n; cin>>n; ll a[n+5]; map<ll,ll>cnt; for(ll i=1; i<=n; i++) { cin>>a[i]; cnt[a[i]]++; } ll ans=0; vector<ll>v; sort(a+1,a+n+1); for(ll i=n; i>=1; i--) { if(cnt[a[i]]>=4) { ans=max(ans,(a[i]*a[i])); } if(v.size()>=2) { ans=max(ans,v[0]*v[1]); } if(cnt[a[i]]>=2&&v.size()<2) v.push_back(a[i]); cnt[a[i]]=0; } cout<<ans<<endl; v.clear(); cnt.clear(); } }
0
9,963,993
#include <iostream> #include <string> #include <cstring> #include <stack> #include <queue> #include <cctype> #include <algorithm> #include <vector> #include <map> #include <set> #include <cmath> #include <stdlib.h> #include <tuple> #include <iomanip> #include <iterator> #include <stdio.h> #include <fstream> #include <time.h> using namespace std; const double PI = 3.14159265358979323846; const long long int MOD = 1000000000 + 7; struct UnionFind { vector<int> parent; UnionFind(int N) : parent(N) { for (int i = 0; i < N; i++) { parent[i] = -1; } } int root(int i) { if (parent[i] < 0) { return i; } return (parent[i] = root(parent[i])); } bool unite(int from, int to) { int rx = root(from); int ry = root(to); if (rx != ry) { parent[ry] += parent[rx]; parent[rx] = ry; return true; } else { return false; } } bool same(int x, int y) { return root(x) == root(y); } int treeSize(int x) { return -parent[root(x)]; } }; long long int modpow(long long int base, long long int pow, long long int mod) { if (pow == 1) { return base; } else if (pow == 0) { return 1; } if (pow % 2 == 0) { auto temp = modpow(base, pow / 2, mod); return (temp * temp) % mod; } else { return (base * modpow(base, pow - 1, mod)) % mod; } } long long int moddiv(long long int X, long long int Y, long long int mod) { auto fermatDiv = modpow(Y, mod - 2, mod); return (X * fermatDiv) % mod; } long long modCombination(long long left, long long right, long long int mod) { long long answer = 1; if (left > right) { for (long long i = 0; i < right; i++) { answer = (answer * (left - i)) % mod; answer = moddiv(answer, (i + 1), mod); } } return answer; } bool IsPrime(long long N) { if (N == 1) { return false; } for (long long i = 2; i * i <= N; i++) { if (N % i == 0) { return false; } } return true; } vector<pair<long long, long long> > prime_factorize(long long N) { vector<pair<long long, long long> > res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({ a, ex }); } if (N != 1) res.push_back({ N, 1 }); return res; } long long euclid(long long a, long long b) { if (a > b) { long long temp = b; b = a; a = temp; } if (b % a == 0) { return a; } else { return euclid(a, b - a); } } long long gcd(long long a, long long b) { if (b > a) { long long temp = b; b = a; a = temp; } long long c = a % b; if (c == 0) { return b; } else { return gcd(b, c); } } int main() { int N; cin >> N; string s; cin >> s; auto c_str = s.c_str(); vector<int> r, g, b(N); int bTotal = 0; for (int i = 0; i < N; i++) { if (c_str[i] == 'R') { r.push_back(i); } else if (c_str[i] == 'G') { g.push_back(i); } else { b[i] = 1; bTotal++; } } int rCount = r.size(); int gCount = g.size(); long long totalCount = 0; for (int i = 0; i < rCount; i++) { int rIndex = r[i]; for (int j = 0; j < gCount; j++) { int gIndex = g[j]; totalCount += bTotal; int indexDiff = abs(gIndex - rIndex); int upperIndex = (rIndex > gIndex) ? rIndex : gIndex; int lowerIndex = (rIndex < gIndex) ? rIndex : gIndex; if (lowerIndex - indexDiff >= 0 && b[lowerIndex - indexDiff] == 1) { totalCount--; } if (upperIndex + indexDiff < N && b[upperIndex + indexDiff] == 1) { totalCount--; } if ((upperIndex - lowerIndex) % 2 == 0 && b[lowerIndex + ((upperIndex - lowerIndex) / 2)] == 1) { totalCount--; } } } cout << totalCount << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;++i) #define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++) #define ALL(a) (a).begin(),(a).end() using namespace std; using ll = long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 62; const int INF = 1e9 + 7; int main(){ ll n, m; cin >> n >> m; map<ll, ll> mp; ll ans = 0; ll sum = 0; rep(i, n){ ll a; cin >> a; sum += a; if(sum % m == 0)ans++; if(mp.count(sum % m) > 0){ ans += mp[sum % m]; mp[sum % m]++; } else { mp[sum % m] = 1; } } cout << ans << endl; }
0
25,716,360
#include<iostream> #include<algorithm> using namespace std; long long int cara(long long int x); int main() { int h, n; cin >> h >> n; int i, a; for (i = 0; i < n; i++) { cin >> a; h = h - a; if (h <= 0) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; } long long int cara(long long int x) { int i = 0; if (x == 1) { return 1; } else { return 1 + 2 * cara((long long int)(x / 2)); } }
#include <iostream> #include <vector> #include <string> #include <sstream> using namespace std; int exec(); class Line { public: string line; int i, n; Line(string _line) { line = _line; i = 0; read(); } int read() { stringstream ss; ss << line[i]; ss >> n; } bool next() { ++i; if(i == line.size()) return false; read(); return true; } int get() { return n; } }; int main() { int n; cin >> n; for(int i = 0; i < n; ++i) exec(); return 0; } int exec() { vector<vector<char> > chars = {{'.', ',', '!', '?', ' '}, {'a', 'b', 'c'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}, {'j', 'k', 'l'}, {'m', 'n', 'o'}, {'p', 'q', 'r', 's'}, {'t', 'u', 'v'}, {'w', 'x', 'y', 'z'}}; int n, count; string line; cin >> line; Line pattern(line); while(true) { count = 0; while(!(n = pattern.get())) if(!pattern.next()) { cout << endl; return 0; } while(pattern.next(), pattern.get()) ++count; cout << chars[n - 1][count % (chars[n - 1].size())]; } return 0; }
0
89,285,578
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> #include <iomanip> #include <cstdlib> #include <algorithm> #include <numeric> #include <stdio.h> #include <vector> #include <map> #include <queue> using namespace std; typedef long long ll; using Graph = vector<vector<ll>>; #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) int main() { ll D; cin >> D; string out = "Christmas"; if(D==24) out = "Christmas Eve"; else if(D==23) out = "Christmas Eve Eve"; else if(D==22) out = "Christmas Eve Eve Eve"; cout << out << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; string s; string strd(int n){ string x; while(n){ int d=n%10; x+=(d+'0'); n/=10; } reverse(x.begin(),x.end()); return x; } void digit() { cin>>s; ll sum=0; for(int i=0;i<s.size();i++){ char a=(char)s[i]; int d=(int) a-'0'; sum+=d; } if(sum%9==0)cout<<"Yes\n"; else cout<<"No\n"; } int main() { ll n; cin>>n; ll a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } ll d=0; for(ll i=1;i<n;i++){ if(a[i-1]>a[i]){ d+=a[i-1]-a[i] ; a[i]=a[i-1]; } } cout<<d<<endl; }
0
7,926,351
#include <bits/stdc++.h> #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() #define LL long long #define pii pair<int,int> #define pll pair<LL,LL> using namespace std; int N=105; char inter(string s){ LL n = stol(s); if(N<=n&&to_string(N)<=to_string(n))return 'Y'; if(N>n&&to_string(N)>to_string(n))return 'Y'; return 'N'; } bool ask(string s){ cout<<"? "<<s<<endl; cout.flush(); char res;cin>>res; return (res=='Y'); } void ans(string s){ cout<<"! "<<s<<endl; cout.flush(); } int main(){ string num=""; while(true){ int left=-1,right=9; while(true){ int center=(left+right)/2; if(num.size()==0&&center==0){ num="1"; break; } string nine=""; REP(i,17-num.size())nine+="9"; if(!ask(num + to_string(center)+nine))left=center; else{ if(center==0){ string _s =to_string(stoi(num)*10-1); if(!ask(_s)^_s.size()==num.size()){ ans(num); return 0; } } right =center; } if(center==(left+right)/2){ num+=to_string(right); break; } } } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define mtv(kit) cout<<#kit<<" - "<<kit<<"\n"; #define ff first #define ss second #define pb push_back #define rep(i,a,b) for(i=a;i<b;i++) #define pii pair<ll , ll> #define all(x) x.begin(),x.end() #define nl "\n" #define ump unordered_map void doit(){ ll n, i, k, ans = 0; cin >> n >> k; vector<ll>v(n); rep(i,0,n)cin >> v[i]; sort(all(v)); rep(i,0,n-k)ans += v[i]; cout << ans << nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; for(ll i = 1; i <= t; i++){ doit(); } }
0
93,796,840
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define watch(x) cout << (#x) << " is " << (x) << endl #define debug cout << "hi" << endl using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long ,long long>pll; ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));} ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));} bool cmp(int a,int b){return a>b;} const ll mod = 1e9 + 7; const int INF32 = 1<<30; const ll INF64 = 1LL<<60; const ld pi = 3.141592653589793; long long modpow(long long n, long long k, long long mod) { if (k == 0) return 1; long long r = modpow(n * n % mod, k >> 1, mod); if (k & 1) r = r * n % mod; return r; } void solve(){ int n; string s; cin >> n >> s; int ans = 0; for(char i = '0';i<='9';i++){ for(char j = '0';j<='9';j++){ for(int k = '0';k<='9';k++){ bool oki = 0,okj = 0,okk = 0; for(int z = 0;z<n;z++){ if(s[z]==i&&oki==0) {oki = 1;continue;} if(s[z]==j&&oki==1&&okj==0) {okj = 1;continue;} if(s[z]==k&&oki==1&&okj==1&&okk==0){okk = 1;continue;} } if(oki&&okj&&okk) ans++; } } } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define int long long #define fr(i,a,b) for(int i = a ; i <= b ; ++i) #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define pb push_back #define fst first #define snd second using namespace __gnu_pbds; using ordered_set = tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll;typedef pair<int, int> pii; typedef vector<int> vi;typedef long double ld; template<class T> using min_heap = priority_queue<T,vector<T>,greater<T>>; template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);} template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));} template<typename T> void remdup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)), v.end()); } template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;} void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); } #ifdef np #include "C:\Users\navodit\Desktop\mycodes\pr.h" #else #define trace(...) #endif #define MOD 1000000007 void solve(){ int n , m ; cin >> n >> m; cout << (n*(n-1)+m*(m-1))/2 << endl; } signed main() { unsyncIO(); int tt =1 ; rep(i,0,tt) solve(); #ifdef np cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
0
85,807,891
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); int n,a; cin>>n>>a; cout<<n*n-a; return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <map> #include <cmath> #include <string> #include <sstream> #include <iomanip> #include <complex> using namespace std; #define ll long long #define vvi vector< vector<int> > #define vi vector<int> #define All(X) X.begin(),X.end() #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define REP(i,n) for(int i=0;i<(int)(n);i++) #define pb push_back #define pii pair<int,int> #define mp make_pair #define pi 3.14159265359 #define shosu(X) fixed << setprecision(X) ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} int n,s; int c; void search(int a,int sum,int before){ FOR(i,before,10){ if(sum+i>s) continue; if(a<n) search(a+1,sum+i,i+1); else if(sum+i==s) { c++; } } } int main(){ while(1){ cin >> n >> s; c = 0; if(n==0&&s==0) break; search(1,0,0); cout << c << endl; } }
0
72,667,519
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<(n); ++i) using namespace std; using ll = long long int; template <class T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto i = v.begin(); i != v.end(); i++) { os << *i << " "; } return os; } void solve(long long N, std::string S){ int l = 0; int r = 0; for(auto c : S) { if(c == '(') l++; if(c == ')') { if(l > 0) l--; else r++; } } rep(i,r) std::cout << '('; std::cout << S; rep(i,l) std::cout << ')'; std::cout << std::endl; } int main(){ long long N; scanf("%lld",&N); std::string S; std::cin >> S; solve(N, S); return 0; }
#include <iostream> using namespace std; const int MAX_N = 200; int yakusu[201]; int main(void){ int N; cin >> N; for(int i=1;i<=MAX_N;i++){ for(int j=i;j<=MAX_N;j+=i){ yakusu[j]++; } } int ans = 0; for(int i=1;i<=N;i++){ if(yakusu[i] == 8 && i % 2 == 1){ ans++; } } cout << ans; }
0
6,665,712
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; ll mm=1000000000;ll MM=mm+7; #define rep(i, n) for(int i=0;i<n;i++) #define PI 3.141592653589793 int main(){ int n,m; cin >> n >>m; VI k(m),p(m); vector<VI> s(m,VI(n)); rep(i,m){ cin >> k.at(i); rep(j,k.at(i)){ cin >> s.at(i).at(j); } } rep(i,m)cin >> p.at(i); int cnt=0; for(int bit=0;bit < (1<<n);bit++){ set<int> chk; rep(k,n){ if(bit & (1<<k)){ chk.insert(k+1); } } bool a=true; rep(i,m){ int cntt=0; rep(j,k.at(i)){ if(chk.count(s.at(i).at(j)))cntt++; } if(cntt%2!=p.at(i)){ a=false; break; } } if(a)cnt++; } cout << cnt << endl; }
#include <iostream> using namespace std; const int INF = 1 << 28; int n; int memo[101][101]; int r[102]; int dfs(int i, int j){ int res = INF; if(memo[i][j] != -1) return memo[i][j]; if(i == j){ return 0; } for(int k = i; k < j; ++k){ res = min(res, dfs(i,k) + dfs(k + 1, j) + r[i] * r[k + 1] * r[j + 1]); } return memo[i][j] = res; } int main() { cin >> n; fill((int*)memo, (int*)(memo + n), -1); for(int i = 0; i < n; ++i){ cin >> r[i] >> r[i + 1]; } cout << dfs(0, n-1) << endl; }
0
53,958,007
#include <iostream> #include <string> using namespace std; int main() { string a, b, c; cin >> a >> b >> c; size_t as = a.size(); size_t bs = b.size(); if (a[as - 1] == b[0] && b[bs - 1] == c[0]) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include<stdio.h> int main() { int i,j,n,a[100000],z; scanf("%d",&n); if(n>0&&n<=9) { printf("%d\n",n); } else if(n>=10&&n<=99) { printf("9\n"); } else if(n>=100&&n<=9999) { if(n<=999) { z = (n-100)+10; printf("%d\n",z); } else if(n>999) { printf("909\n"); } } else if(n>=10000&&n<=100000) { if(n<=99999) { z = 910 + (n-10000); printf("%d\n",z); } else if(n==100000) { printf("90909\n"); } } }
0
9,944,766