code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
1
101M
#include<bits/stdc++.h> #define watch(x) cout << (#x) << " is " << (x) << endl #define endl "\n" typedef long long ll; using namespace std; int static fast = [](){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }(); int main() { ll x, y; cin >> x >> y; if (x % y == 0) { cout << -1 << endl; } else { vector<ll> cand = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; for(auto val: cand) { if ((x*val) % y != 0) { cout << (x*val) << endl; return 0; } } return 0; } return 0; }
#include<bits/stdc++.h> #include <atcoder/dsu> using namespace std; using namespace atcoder; #define all(a) a.begin(),a.end() #define F first #define S second #define pb push_back #define ll long long #define vi vector<int> #define pi pair<int,int> #define mp make_pair #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int mod=1e9+7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int mul(int a,int b) { return ((a)*1ll*(b))%mod; } void add(int &a,int b) { a+=b; if(a>=mod)a-=mod; } int sub(int a,int b){ a-=b; if(a<0){ a+=mod; } return a; } int powz(int a,int b){ int res=1; while(b){ if(b&1){ res=mul(res,a); } b/=2; a=mul(a,a); } return res; } template <typename A, typename B> istream& operator>>(istream& input,pair<A,B>& x) { input>>x.F>>x.S; return input; } template <typename A> istream& operator>>(istream& input,vector<A>& x) { for(auto& i:x) input>>i; return input; } template<typename A> ostream& operator<<(ostream& output,vector<A>& x) { for(auto& i:x) output<<i<<' '; return output; } const int N=1000002; void solve(){ int n,q; cin>>n>>q; dsu d(n); while(q--){ int tmp; cin>>tmp; int x,y; cin>>x>>y; if(tmp==0){ d.merge(x,y); } else{ if(d.same(x,y)){ cout<<1; } else{ cout<<0; } cout<<'\n'; } } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int tc=1; for(int _=0;_<tc;_++){ solve(); if(_!=tc-1) cout<<"\n"; } }
0
7,548,059
#include <bits/stdc++.h> #define int long long #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define pb push_back #define F first #define S second using namespace std; typedef pair<int,int> P; const int MOD=1000000007; int INF=100100100100100; signed main(){ int n,m;cin>>n>>m; string s[100],t[100]; rep(i,n)cin>>s[i]; rep(i,m)cin>>t[i]; bool flag=false; rep(i,n-m+1){ rep(j,n-m+1){ bool po=true; rep(k,m){ rep(l,m){ if(s[i+k][j+l]!=t[k][l]){ po=false;k=m,l=m; } } } if(po){ flag=true; i=n,j=n; } } } if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF=1LL<<60; const int inf=(1<<30)-1; const int mod=1e9+7; int dx[8]={1,0,-1,0,-1,-1,1,1}; int dy[8]={0,1,0,-1,-1,1,-1,1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,m,x;cin >> n >> m >> x; vector<int> c(n); vector<vector<int>> a(n,vector<int>(m)); REP(i,n){ cin >> c[i]; REP(j,m){ cin >> a[i][j]; } } int ans=inf; REP(t,1<<n){ vector<int> b(m); int res=0; REP(i,n){ if(t&(1<<i)){ res+=c[i]; REP(j,m){ b[j]+=a[i][j]; } } } bool f=true; REP(i,m){ if(b[i]<x) f=false; } if(f) chmin(ans,res); } cout << (ans==inf?-1:ans) << endl; }
0
90,625,904
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) #define all(a) a.begin(), a.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; int main(){ int W, H; cin >> W >> H; vector<pair<ll, int>> vec(W + H); rep(i, W){ cin >> vec[i].first; vec[i].second = 1; } rep(i, H){ cin >> vec[i + W].first; vec[i + W].second = -1; } sort(all(vec)); ll vert = H + 1, side = W + 1; ll ans = 0; rep(i, W + H){ if(vec[i].second == 1){ ans += vec[i].first * vert; side--; } else { ans += vec[i].first * side; vert--; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long int takahasi,nakahasi,hikuhasi,K; cin>>takahasi>>nakahasi>>hikuhasi>>K; if(K%2==0){ K=2; }else if(K%2==1){ K=1; } if(takahasi==nakahasi==hikuhasi){ cout<<0<<endl; return 0; } for(int i=1;i<=K;i++){ long long int a=takahasi; long long int b=nakahasi; takahasi=nakahasi+hikuhasi; nakahasi=a+hikuhasi; hikuhasi=a+b; if(takahasi-nakahasi>=1000000000000000000){ cout<<"Unfair"<<endl; } } cout<<takahasi-nakahasi<<endl; }
0
97,150,750
#include<bits/stdc++.h> using namespace std; int main() { int n, a, ali, bor; string ans; cin >> n; cin >> ali; cin >> bor; ans = "Alice"; a =((bor-1)-ali)%2; if(a == 0) ans = "Borys"; cout << ans << endl; return 0; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<math.h> #include<map> using namespace std; using ll = long long; int main() { int a,b,c,K; bool flag = false; cin >> a >> b >> c >> K; for(int i=0;i<=K;i++){ for(int j=0;j<=K;j++){ for(int k=0;k<=K;k++){ int x = a * (1 << i), y = b * (1 << j), z = c * (1 << k); if(i + j + k <= K && x < y && y < z) flag = true; } } } if(flag == true){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
0
19,214,966
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s; cin >> s; s[5] = ' '; s[13] = ' '; cout << s << endl; return 0; }
#include <iostream> #include <iomanip> #include <string> #include <stack> #include <vector> #include <math.h> #include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <map> #include <set> #include <queue> #include <list> #include <regex> using namespace std; using pii = pair<int,int>; using ll=long long; using ld=long double; #define pb push_back #define mp make_pair #define stpr setprecision #define cYES cout<<"YES"<<endl #define cNO cout<<"NO"<<endl #define cYes cout<<"Yes"<<endl #define cNo cout<<"No"<<endl #define rep(i,n) for(ll i=0;i<(n);++i) #define Rep(i,a,b) for(ll i=(a);i<(b);++i) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define rRep(i,a,b) for(int i=a;i>=b;i--) #define crep(i) for(char i='a';i<='z';++i) #define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;}); #define ALL(x) (x).begin(),(x).end() #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define endl '\n' int ctoi(const char c){ if('0' <= c && c <= '9') return (c-'0'); return -1; } ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));} ll lcm(ll a,ll b){return a*b/gcd(a,b);} constexpr ll MOD=1000000007; constexpr ll INF=1000000011; constexpr ll MOD2=998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS=10e-8; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;} template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;} template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;} template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for(auto i=begin(v); i != end(v); ++i){ if(i !=begin(v)) os << ' '; os << *i; } return os; } int main(){ ll N,l,r,mid,key=0; cin >> N; string S,T; cout << 0 << endl; cin >> S; if(S=="Vacant"){ return 0; } l=0,r=N; while(1){ mid=(l+r)/2; cout << mid << endl; T.clear(); cin >> T; if(T=="Vacant"){ return 0; } else if(T==S){ if(abs(mid-key)%2==1){ if(key<=l){ r=mid; key=r; } else{ l=mid; key=l; } } else{ if(key<=l){ l=mid; key=l; } else{ r=mid; key=r; } } } else{ if(abs(mid-key)%2==1){ if(key<=l){ l=mid; key=l; } else{ r=mid; key=r; } } else{ if(key<=l){ r=mid; key=r; } else{ l=mid; key=l; } } } S=T; } }
0
24,403,876
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const ll INF = 1LL << 60; const ll MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } template <class C> void print(const C &c, std::ostream &os = std::cout) { std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " ")); os << std::endl; } int main() { ll n; cin >> n; vvi edges(n); for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; a--, b--; edges[a].push_back(b); edges[b].push_back(a); } vector<bool> used(n, false); function<void(int, int)> dfs = [&](int c, int p) { for (auto &v : edges[c]) { if (v == p) continue; dfs(v, c); } if (!used[c] && p != -1 && !used[p]) { used[c] = used[p] = true; } }; dfs(0, -1); bool match = true; for (int i = 0; i < n; ++i) { if (!used[i]) { match = false; break; } } if (match) { cout << "Second" << "\n"; } else { cout << "First" << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define lli long long int #define uli unsigned long long int #define INF 999999999999999999 #define rep(i,m,n) for(lli i = m;i < n;i++) #define rrep(i,m,n) for(lli i=m-1;i>=n;i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(),N.end()),N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(),n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(25) << S << endl #define Vec(K,L,N,S) vector<L> K(N,S) #define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S)) #define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S))) #define pint pair<lli,lli> #define paf(L,R) pair<L,R> #define mod 1000000007 #define MAX 510000 #define ALL(a) a.begin(),a.end() #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) int main(){ lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T; cin >> N; Out((N-1)/2); }
0
83,491,184
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (long long i = 0; i < N; i++) using ll = long long; const string YES = "Yes"; const string NO = "No"; void solve(long long H, long long W, std::vector<std::string> s) { vector<pair<ll, ll>> dir{pair<ll, ll>(-1, 0), pair<ll, ll>(1, 0), pair<ll, ll>(0, -1), pair<ll, ll>(0, 1)}; rep(i, H) { rep(j, W) { if (s[i][j] == '#') { bool ok = false; rep(k, 4) { ll tmpi = i + dir[k].first; ll tmpj = j + dir[k].second; if (!(tmpi < 0 || tmpi > H - 1 || tmpj < 0 || tmpj > W - 1)) { if (s[tmpi][tmpj] == '#') { ok = true; } } } if (!ok) { cout << "No" << endl; return; } } } } cout << "Yes" << endl; return; } int main() { long long H; scanf("%lld", &H); long long W; scanf("%lld", &W); std::vector<std::string> s(H); for (int i = 0; i < H; i++) { std::cin >> s[i]; } solve(H, W, std::move(s)); return 0; }
#include <iostream> #include <list> #include <string> #include <algorithm> using namespace std; void output(list<int> a); int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); int n; int entersuji; cin >> n; list<int> suji; std::string command; for(int i=0 ; i < n; i++){ cin >> command; if(command == "insert"){ cin >> entersuji; suji.insert(suji.begin() , entersuji); } if(command == "delete"){ cin >> entersuji; list<int>::iterator itr = std::find(suji.begin(), suji.end(), entersuji); if( itr != suji.end()){ suji.erase(itr); } } if(command == "deleteLast"){ suji.pop_back(); } if(command == "deleteFirst"){ suji.pop_front(); } } list<int>::iterator It = suji.begin(); std::cout << *It; for(++It; It !=suji.end() ; ++It ){ std::cout << " "<< *It; } cout << endl; return 0; }
0
40,002,559
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; using Graph = vector<vector<int>>; #define MOD 1000000007 #define MOD2 998244353 #define INF ((1<<30)-1) #define LINF (1LL<<60) #define EPS (1e-10) typedef long long ll; typedef pair<ll, ll> P; int main(){ int n, k; cin >> n >> k; string s; cin >> s; vector<int> r; r.push_back(0); for(int i = 1; i < n; i++){ if (s[i] != s[i-1]) r.push_back(i); } int ans = 0; int m = r.size(); rep(i, r.size()){ int tmp, cnt; if (s[r[i]] == '0'){ if (2 * k + i > m - 1) tmp = n; else tmp = r[2 * k + i]; cnt = tmp - r[i]; } else { if (2 * k + i + 1 > m - 1) tmp = n; else tmp = r[2 * k + i + 1]; cnt = tmp - r[i]; } ans = max(ans, cnt); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef long long unsigned llu; typedef pair<long long, long long> pll; const long long inf = 2000000000000000000LL; #define pi acos(-1.0) #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define shesh "\n" #define ff first #define ss second #define pb push_back #define bp pop_back #define pf push_front #define fp pop_front #define ub upper_bound #define lb lower_bound #define all(x) x.begin(), x.end() #define debug(x) cout<<"debug "<<x<<"\n" #define mest(a,b) memset(a,b,sizeof(a)) int main() { fast; llu ans=5000000000000000000; ll t,n,m,i,j,l,k,temp,flag,x,y,x1,x2,y1,y2; cin>>n>>k; vector<pair<ll,ll> >v; vector<ll>X,Y; for(i=0; i<n; i++) { cin>>x>>y; v.pb({x,y}); X.pb(x); Y.pb(y); } for(j=0; j<n; j++) { for(x=j+1; x<n; x++) { for(y=0; y<n; y++) { for(t=y+1,temp=0; t<n; t++) { x1=min(X[j],X[x]); x2=max(X[j],X[x]); y1=min(Y[y],Y[t]); y2=max(Y[y],Y[t]); for(l=0,temp=0; l<n; l++) { if(v[l].ff>=x1 && v[l].ff<=x2 && v[l].ss>=y1 && v[l].ss<=y2) temp++; } if(temp>=k) { if(ans>((llu)abs(x1-x2))*((llu)abs(y1-y2))) ans=((llu)abs(x1-x2))*((llu)abs(y1-y2)); } } } } } cout<<ans; return 0; }
0
9,493,151
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <cmath> #include <limits> #include <queue> #include <iomanip> #include <set> template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;} template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;} using namespace std; #define ALL(X) X.begin(),X.end() using ll = long long int; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vvll> vvvll; const int MOD=1000000007; const int INTMAX=2147483647; const ll LLMAX=9223372036854775807; int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; cout<<s.substr(0,4)+" "+s.substr(4,8)<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int Mod = 1e9 + 7, Nmax = 1e5 + 5; ll fact[Nmax], ifact[Nmax]; int ap[Nmax], n, i, x, rest; ll comb(int n, int k) { if(n < k) return 0; return fact[n] * ifact[k] % Mod * ifact[n-k] % Mod; } ll power(ll a, int b) { if(!b) return 1; if(b&1) return a * power(a*a%Mod, b/2) % Mod; return power(a*a%Mod, b/2); } int main() { cin.sync_with_stdio(false); fact[0] = ifact[0] = 1; cin >> n; for(i=1; i<=n+1; ++i) { cin >> x; if(ap[x]) rest = n + 1 - (i - ap[x] + 1); else ap[x] = i; fact[i] = fact[i-1] * i % Mod; } ifact[n+1] = power(fact[n+1], Mod-2); for(i=n; i; --i) ifact[i] = ifact[i+1] * (i+1) % Mod; for(i=1; i<=n+1; ++i) cout << (comb(n+1, i) - comb(rest, i-1) + Mod) % Mod << '\n'; return 0; }
0
63,877,075
#include<iostream> #include<string> using namespace std; int main() { char a, b; cin >> a >> b; if (a > b) cout << ">"; else if (a < b) cout << "<"; else cout << "="; }
#include <iostream> #include <iomanip> #include <cmath> using namespace std; struct point{ double x,y; public: point(const point &p):x(p.x),y(p.y){} point():x(0),y(0){} point(double x,double y):x(x),y(y){} double get_x()const{ return x; } double get_y()const{ return y; } point& operator=(const point &p){ x = p.x; y = p.y; return *this; } point operator+(const point &p)const{ return point(x+p.x,y+p.y); } point operator-(const point &p)const{ return point(x-p.x,y-p.y); } point operator*(const double k)const{ return point(k*x,k*y); } double norm()const{ return sqrt(x*x+y*y); } double dist(const point &p)const{ return (*this-p).norm(); } void show()const{ cout << setprecision(6) << x << " " << y << endl; } }; void print_kochcurve(const point &p1,const point &p2,int n); int main(){ int n; cin >> n; point p1(0,0),p2(100,0); p1.show(); print_kochcurve(p1,p2,n); return 0; } void print_kochcurve(const point &p1,const point &p2,int n){ if(n==0){ p2.show(); return; } point s,t,u; s = (p1*2.0 + p2)*(1./3); t = (p1 + p2*2.0)*(1./3); u = (p1 + p2)*(1./2); double len = p1.dist(s)*sqrt(3)/2; point v = p2-p1; point tmp(-v.get_y(),v.get_x()); tmp = tmp*(1./tmp.norm()); u = u + tmp*len; print_kochcurve(p1,s,n-1); print_kochcurve(s,u,n-1); print_kochcurve(u,t,n-1); print_kochcurve(t,p2,n-1); }
0
89,893,214
#include <bits/stdc++.h> #define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i)) #define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<int, lint> pil; typedef pair<lint, int> pli; typedef pair<lint, lint> pll; template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;} template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;} template<class T> T div_floor(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>=0 ? a/b : (a+1)/b-1; } template<class T> T div_ceil(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>0 ? (a-1)/b+1 : a/b; } constexpr lint mod = 1e9+7; constexpr lint INF = mod * mod; constexpr int MAX = 100010; int main(){ int h, w, d; scanf("%d%d%d", &h, &w, &d); string s = "RGBY"; int K = h+w; char grid[K+1][K+1]; for(int i=0; i<=K; i+=d)for(int j=0; j<=K; j+=d){ char c = s[i/d%2*2 + j/d%2]; for(int x=0; x<d && i+x<=K; ++x)for(int y=0; y<d && j+y<=K; ++y){ grid[i+x][j+y] = c; } } rep(i, h){ rep(j, w) printf("%c", grid[i+j][i-j+w]); printf("\n"); } }
#include<iostream> #include<cstring> const int MAX_STR = 35; const int MAX_NUM_OF_STR = 1010; using namespace std; int main(){ int cnt = -1, len = 0, tango = 0; char str[MAX_NUM_OF_STR][MAX_STR], max[MAX_STR], maxlen[MAX_STR]; while(cin >>str[tango]){ int tmpcnt = 0; for(int i = 0; i <= tango; i++){ if(strcmp(str[i], str[tango]) == 0){ tmpcnt++; } } if(cnt < tmpcnt){ strcpy(max, str[tango]); cnt = tmpcnt; } if(strlen(str[tango]) > (unsigned)len){ len = strlen(str[tango]); strcpy(maxlen, str[tango]); } tango++; } cout <<max <<" " <<maxlen <<endl; return 0; }
0
5,553,469
#include<iomanip> #include<limits> #include<thread> #include<utility> #include<iostream> #include<string> #include<algorithm> #include<set> #include<map> #include<vector> #include<stack> #include<queue> #include<cmath> #include<numeric> #include<cassert> #include<random> #include<chrono> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll,ll> pll; typedef pair<int,int> pi; #define F first #define S second #define MK make_pair const ll E=1e17+7; const ll MOD=1000000007; bool done[110000]={}; int main(){ ll k; cin>>k; priority_queue<pll,vector<pll>,greater<pll>> q; q.push({1,1}); ll ans=-1; while(!q.empty()){ pll p=q.top(); q.pop(); if(done[p.S]){continue;} done[p.S]=true; if(p.S*10%k==0){ans=p.F; break;} if((p.S+1)%k==0){ans=p.F+1; break;} q.push({p.F+1,(p.S+1)%k}); if(p.S*10%k!=p.S){ q.push({p.F,p.S*10%k}); } } cout<<ans<<endl; return 0; }
#include<stdio.h> int main() { int a,b,c,d,e; scanf("%d%d%d",&a,&b,&c); if(a==b && a==c ) printf("1"); else if(a==b && a!=c) printf("2"); else if(a==c && a!=b) printf("2"); else if(b==c && b!=a) printf("2"); else if(a!=b && a!=c) printf("3"); return 0; }
0
83,090,766
#include <stdio.h> int main(){ int a[5]; for(int i=0;i<5;i++) scanf("%d",&a[i]); for(int i=0;i<5;i++){ for(int j=i+1;j<5;j++){ if(a[i]<a[j]){ a[i]^=a[j]; a[j]^=a[i]; a[i]^=a[j]; } } } for(int i=0;i<5;i++){ if(i) printf(" "); printf("%d",a[i]); } printf("\n"); return 0; }
#include <bits/stdc++.h> #define pi 3.14159 using namespace std; int main() { int n,i,x,d,c=1,s=0; int ans=INT_MAX; cin>>n; int a[n],b[n]; for(i=0;i<n;i++) cin>>a[i]; for(int t = 0; t < n - 1; t++) { int s1 = 0, s2 = 0; for (int i = 0; i < n; i++) { if (i <= t) s1 += a[i]; else s2 += a[i]; } ans = min(ans, abs(s1 - s2)); } cout<<ans<<endl; }
0
89,156,024
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cassert> #include <functional> #include <algorithm> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <bitset> using namespace std; using llong = long long; llong n, k; llong a[16]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } llong ans = 1ll << 60ll; for (int i = 0; i < (1 << n); i++) { bitset<16> s(i); if (s.count() < k) continue; llong x = 0; llong maxv = 0; for (int j = 0; j < n; j++) { if (s[j] && a[j] <= maxv) { x += maxv - a[j] + 1; maxv += 1; } else { maxv = max(maxv, a[j]); } } ans = min(ans, x); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct Atack { int power; int magic; }; int main() { int H, N; cin >> H >> N; vector<Atack> atack(N); int A, B; for (int i = 0; i < N; i++) { cin >> atack[i].power; cin >> atack[i].magic; } long dp[H+1]; for (int i = 1; i <= H; i++) { dp[i] = 1e13; for (int j = 0; j < N; j++) { if (atack[j].power >= i) { dp[i] = min((long)atack[j].magic, dp[i]); } else { dp[i] = min(dp[i - atack[j].power] + atack[j].magic, dp[i]); } } } cout << dp[H]; }
0
51,421,143
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ string a, b, ans="H"; cin >> a >> b; if(a!=b) ans = "D"; cout << ans << endl; }
#include <climits> #include <iostream> #include <string> #include <cmath> using namespace std; using Int = long long int; using UInt = unsigned long long int; class NumberString { public: static UInt Digits(Int number) { return to_string(number).length(); } }; int main(void) { Int n; cin >> n; Int sq = sqrt(n); Int ans = INT_MAX; for (Int i = 1; i <= sq; ++i) { if (n % i != 0) { continue; } Int len = NumberString::Digits(max(i, n / i)); ans = min(ans, len); } cout << ans << endl; return 0; }
0
52,307,711
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<n; i++) const int dx[] = {1, 0}; const int dy[] = {0, 1}; int a, b; int n; int x, y; bool maze[22][22]; inline bool check(int hx, int hy){ return 0 <= hx && hx < a && 0 <= hy && hy < b; } int main() { while(cin >> a >> b, a){ rep(i, a) rep(j, b) maze[i][j] = false; cin >> n; rep(i, n){ cin >> x >> y; maze[x - 1][y - 1] = true; } int res = 0; queue<pair<int, int> > que; que.push(make_pair(0, 0)); while(!que.empty()){ pair<int, int> top = que.front(); que.pop(); int hx = top.first; int hy = top.second; if(hx == a - 1 && hy == b - 1){ res += 1; continue; } rep(k, 2){ int nx = hx + dx[k]; int ny = hy + dy[k]; if(!check(nx, ny)) continue; if(maze[nx][ny]) continue; que.push(make_pair(nx, ny)); } } cout << res << endl; } return 0; }
#include <cstdio> #include <cstdlib> #define MAX 2000001 #define NIL -1 typedef struct { int size; int S[MAX]; } Heap; int Left(int i) { return 2 * i; } int Right(int i) { return (2 * i + 1); } int Parent(int i) { return i / 2; } void increaseKey(Heap *H, int i, int key) { if (key < H->S[i]) { printf("too small key"); } else { H->S[i] = key; while (1 < i && H->S[Parent(i)] < H->S[i]) { int p = Parent(i); int tmp = H->S[p]; H->S[p] = H->S[i]; H->S[i] = tmp; i = p; } } } void MaxHeapify(Heap *H, int i) { int l = Left(i); int r = Right(i); int largest = i; if ( l <= H->size && H->S[i] < H->S[l]) largest = l; if ( r <= H->size && H->S[largest] < H->S[r]) largest = r; if (largest != i) { int tmp = H->S[i]; H->S[i] = H->S[largest]; H->S[largest] = tmp; MaxHeapify(H, largest); } } void extractMax(Heap *H) { if (H->size < 1) { printf("over flow\n"); } else { int max = H->S[1]; printf("%d\n", max); H->S[1] = H->S[H->size]; H->size--; MaxHeapify(H, 1); } } void insert(Heap *H, int k) { H->size++; H->S[H->size] = NIL; increaseKey(H, H->size, k); } int main () { Heap *H = (Heap *)malloc(sizeof(Heap)); H->size = 0; for (;;) { char c[10]; int k; scanf(" %s %d", c, &k); if (c[0] == 'i') { insert(H, k); } else if (c[0] == 'e' && c[1] == 'x') { extractMax(H); } else { break; } } return 0; }
0
13,402,405
#include <bits/stdc++.h> using namespace std; int main() { int N, K, S; cin >> N >> K >> S; for(int i=0;i<K;i++){ cout << S << " "; } if(S==1e+9) S=0; for(int i=K;i<N;i++){ cout << (S+1) << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; using dou =long double; string yes="yes"; string Yes="Yes"; string YES="YES"; string no="no"; string No="No"; string NO="NO"; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) #define brep(n) for(int bit=0;bit<(1<<n);bit++) #define erep(i,container) for (auto i : container) #define irep(i, n) for(ll i = n-1; i >= (int)0; i--) #define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++) #define reprep(i,j,h,w) rep(i,h)rep(j,w) #define all(x) (x).begin(),(x).end() #define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i]; #define pb push_back #define pf push_front #define query int qq;std::cin >> qq;rep(qqq,qq) #define lb lower_bound #define ub upper_bound #define fi first #define se second #define itn int #define mp make_pair #define sum(a) accumulate(all(a),0ll) #define keta fixed<<setprecision #define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a)) #define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a))); #define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) )); #define case std::cout <<"Case #" <<qqq+1<<": " #define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); #define as assign #define ffor for(;;) #define ppri(a,b) std::cout << a<<" "<<b << std::endl #define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl #define aall(x,n) (x).begin(),(x).begin()+(n) #define ssum(a) accumulate(a,0ll) #define gre(n) greater<n>() typedef long long ll; typedef pair<int,int> P; typedef pair<ll,ll> PL; const int INF = 1000000000; const double dINF = 1000000000; const ll INF64 = 922337203685477580ll; const ll MOD = 1000000007ll; const dou pi=3.141592653589793*2; int main(){ int n; std::cin >> n; int h=n,w=n; vvvector(a,char,n,n,n,0); reprep(i,j,n,n)std::cin >> a[0][i][j]; rrep(ii,1,n){ reprep(i,j,n,n){ a[ii][i][(j+ii)%n]=a[0][i][j]; } } int ans=0; rep(ii,n){ bool b=1; rep(i,n)rep(j,n){ if(a[ii][i][j]!=a[ii][j][i])b=0; } if(b)ans+=n; } std::cout << ans << std::endl; }
0
45,215,437
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) vector<ll> ans; void dfs(int d, ll now){ ans.push_back(now); if(d==10) return; for(int j = -1; j<=1; j++){ int add = (now % 10) + j; if(add>=0 && add <= 9) dfs(d+1, now*10+add); } } int main(){ for(int i=1; i<=9; i++){ dfs(1,(ll)i); } sort(ans.begin(),ans.end()); int k; cin>>k; cout<<ans[k-1]<<endl; }
#include <iostream> using namespace std; int main() { int n; int count = 0; cin >> n; for (int i = 1; i <= n; i++) { int num = i, digit = 0; while (num != 0) { num /= 10; digit++; } if (digit % 2 == 1) count++; } cout << count << endl; return 0; }
0
53,357,680
#include<iostream> #include<iomanip> #include<vector> #include<stack> #include<queue> #include<set> #include<string> #include<algorithm> #include<math.h> #include<unordered_set> using namespace std; const int MAX = 500; int H, W, d; char getColor(int x, int y) { x = (x + W) / d; y = (y + H) / d; if (y & 1) { if (x & 1)return 'R'; else return 'G'; } else { if (x & 1)return 'B'; else return 'Y'; } } int main() { cin >> H >> W >> d; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { int y = i + j; int x = i - j; cout << getColor(x, y); } cout << endl; } return 0; }
#include <iostream> #include <cstdio> #include <cmath> using namespace std; class triangle { private: double a, b, C, S, L, h; public: triangle(double edge1, double edge2, double angle); ~triangle(){;} void calc_area(); void calc_around(); void calc_height(); void print_(); }; triangle::triangle(double edge1, double edge2, double angle) { a = edge1; b = edge2; C = angle; } void triangle::calc_area() { S = (a * b * sin(C)) / 2; } void triangle::calc_around() { L = a + b + sqrt(pow(a, 2.0) + pow(b, 2.0) - 2 * a * b * cos(C)); } void triangle::calc_height() { h = b * sin(C); } void triangle::print_() { printf("%lf\n", S); printf("%lf\n", L); printf("%lf\n", h); } int main(int argc, char const *argv[]) { int count = 3; double input[3]; for (int i = 0; i < count; ++i) { cin >> input[i]; } triangle abc(input[0], input[1], M_PI * input[2] / 180); abc.calc_area(); abc.calc_around(); abc.calc_height(); abc.print_(); return 0; }
0
51,788,265
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int mod = 1000000007; int n, m; cin >> n >> m; vector<int> a(n + 1); vector<int> dp(n + 2, 0); for (int i = 0; i < m; i++) { int buf; cin >> buf; a[buf] = 1; } dp[n] = 1; for (int i = n - 1; i >= 0; i--) { if (a[i]) { continue; } dp[i] = (dp[i + 1] + dp[i + 2]) % mod; } cout << dp[0] << endl; }
#include "bits/stdc++.h" using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef long long LL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<VVLL> VVVLL; typedef pair<LL, LL> PLL; typedef vector<PLL> VPLL; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define FORL(i,a,b) for(LL i=(a);i<(b);++i) #define REPL(i,n) FORL(i,0,n) #define SIZE(a) int((a).size()) #define ALL(a) (a).begin(),(a).end() const double EPS = 1e-10; const double PI = acos(-1.0); template<typename T> void vprint(vector<T> v) { for(auto x : v) { cerr << x << " "; } cerr << endl; } template<typename T> void vvprint(vector<vector<T>> vv) { REP(i, SIZE(vv)) { REP(j, SIZE(vv[i])) { cerr << vv[i][j] << " "; } cerr << endl; } } template<typename T1, typename T2> void vpprint(vector<pair<T1, T2>> vp) { REP(i, SIZE(vp)) { cerr << vp[i].first << ", " << vp[i].second << endl; } } template<typename T1, typename T2> void mprint(map<T1, T2> m) { for(auto x : m) cerr << x.first << ", " << x.second << endl; } void yesno(bool flg) { cout << (flg ? "Yes" : "No") << endl; } template <typename Iterator> inline bool next_combination(const Iterator first, Iterator k, const Iterator last) { if ((first == last) || (first == k) || (last == k)) return false; Iterator itr1 = first; Iterator itr2 = last; ++itr1; if (last == itr1) return false; itr1 = last; --itr1; itr1 = k; --itr2; while (first != itr1) { if (*--itr1 < *itr2) { Iterator j = k; while (!(*itr1 < *j)) ++j; iter_swap(itr1,j); ++itr1; ++j; itr2 = k; rotate(itr1,j,last); while (last != j) { ++j; ++itr2; } rotate(k,itr2,last); return true; } } rotate(first,k,last); return false; } inline double get_time_sec(void){ return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000; } template<typename T> T lcm(T a, T b) { return (a / __gcd(a, b)) * b; } template<typename T> map<T, T> prime_list(T n) { map<T, T> ret; for(T i = 2; i*i <= n; i++) { if(n % i == 0) { ret[i] = 0; while(n % i == 0) { n /= i; ret[i]++; } } } if(n != 1) ret[n]++; return ret; } #define MOD 1000000007 LL mypow(LL a, LL n) { if(n == 0) return 1; if(n == 1) return a % MOD; if(n % 2 == 1) return (a * mypow(a, n-1)) % MOD; LL t = mypow(a, n/2); return (t * t) % MOD; } #define FACT_SZ 100010 VLL _fact, _inv; bool _fact_flg = true; void _fact_init() { _fact = VLL(FACT_SZ); _inv = VLL(FACT_SZ); _fact[0] = 1; FOR(i, 1, FACT_SZ) _fact[i] = (_fact[i-1] * i) % MOD; _inv[FACT_SZ-1] = mypow(_fact[FACT_SZ-1], MOD - 2); for(int i = FACT_SZ - 2; i >= 0; i--) { _inv[i] = ((i + 1) * _inv[i + 1]) % MOD; } } LL mycomb(LL n, LL k) { if(_fact_flg) { _fact_flg = false; _fact_init(); } if(n < k) return 0; return (((_fact[n] * _inv[k]) % MOD) * _inv[n-k]) % MOD; } VLL par, rnk, sz; int root(int x) { if(par[x] == x) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { x = root(x); y = root(y); return x == y; } void unite(int x, int y) { x = root(x); y = root(y); if(rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if(rnk[x] == rnk[y]) rnk[x]++; } } #define INF 1e15 typedef tuple<LL, LL, LL> T; int main(void) { LL h, w; cin >> h >> w; VVLL b(h, VLL(w, 0)); REP(i, h) { string s; cin >> s; REP(j, w) if(s[j] == '#') b[i][j] = 1; } VVLL dst(h, VLL(w, INF)); dst[0][0] = b[0][0]; priority_queue<T, vector<T>, greater<T>> q; q.push(make_tuple(dst[0][0], 0, 0)); VVI done(h, VI(w, 0)); while(!q.empty()) { auto t = q.top(); q.pop(); LL sy = get<1>(t), sx = get<2>(t); LL dy[] = {1, 0}; LL dx[] = {0, 1}; REP(i, 2) { LL ty = sy + dy[i], tx = sx + dx[i]; if(ty >= h || tx >= w) continue; if(done[ty][tx]) continue; if(dst[ty][tx] > dst[sy][sx] + (!b[sy][sx] && b[ty][tx])) { dst[ty][tx] = dst[sy][sx] + (!b[sy][sx] && b[ty][tx]); q.push(make_tuple(dst[ty][tx], ty, tx)); } } done[sy][sx] = 1; } cout << dst[h-1][w-1] << endl; }
0
37,149,648
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; vector<int> e[N]; queue<int> Q; int n,deg[N]; bool del[N],white[N]; void erase(int x){ del[x]=1; for (int i=0;i<e[x].size();i++){ int v=e[x][i]; if (del[v]) continue; deg[v]--; if (deg[v]==0) puts("First"),exit(0); if (deg[v]==1) Q.push(v); } } int main() { scanf("%d",&n); for (int i=1;i<n;i++){ int u,v; scanf("%d%d",&u,&v); e[u].push_back(v); e[v].push_back(u); deg[u]++;deg[v]++; } for (int i=1;i<=n;i++) if (deg[i]==1) Q.push(i); while (!Q.empty()){ int v=Q.front();Q.pop(); del[v]=1; for (int i=0;i<e[v].size();i++){ int u=e[v][i]; if (del[u]) continue; erase(u); } } puts("Second"); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vi = vector<int>; #define _GLIBCXX_DEBUG #define IO_STREAM cin.tie(0);ios::sync_with_stdio(false) #define all(x) x.begin(),x.end() #define rep(i,sta,end) for(int i=sta;i<end;++i) #define lcm(a,b) (a)/__gcd((a),(b))*(b) #define pb push_back const ll INF = 1000000000000000; const ll MOD = 1000000007; const double PI = acos(-1); #define DBG(a,b,c,d) signed main(){ IO_STREAM; ll A,B; cin>>A>>B; ll ans; ans=lcm(A,B); cout<<ans<<endl; return 0; }
0
36,720,584
#include<iostream> using namespace std; int main(){ int x; int n = 1; cin >> x; while(x!=0) { cout << "Case " << n << ": " << x << endl; n = n+1; cin >> x; } return 0; }
#include<iostream> #include<string.h> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<map> #include<bitset> #include<set> #include<climits> #include<math.h> #include<stdlib.h> #define lli long long int #define pb push_back #define mp make_pair #define pii pair<int , int > #define pll pair<lli , lli > #define wht while (t--) #define fu( i , a , n ) for ( int i = (int)a ; i <=(int)n ; i++ ) #define fd( i , n , a ) for (int i = (int)n ; i >=(int)a ;i--) #define rep(i,n) for ( int i = 0 ; i < (int)n; i++) #define fst ios_base::sync_with_stdio(false);cin.tie(NULL); #define sz size() #define ln length() #define ps printf(" ") #define pn printf("\n") #define pi(n) printf("%d" , n ) #define pl(n) printf("%lld" , n ) #define ii(n) scanf("%d" , &n) #define il(n) scanf("%lld" , &n ) #define lb lower_bound #define ub upper_bound #define bs binary_search #define ALL(V) V.begin(), V.end() #define ic(n) cin>>n #define pr printf #define inf 99999999 using namespace std ; int main() { fst; int n ; cin >> n; int arr[n]; for(int i = 0 ; i < n ;i++ ) { cin>> arr[i]; } int ans = 0; sort(arr , arr + n ); for (int i = 1 ; i <= 100004; i++ ) { int ind = lower_bound(arr, arr + n , i)- arr; if ((n - ind) == (ind ) ) ans++; } cout << ans; }
0
29,958,424
#include <bits/stdc++.h> #define REP(i,n) for (int i = 0; i <(n); ++i) #define REP2(i,x,n) for (int i = x; i <(n); ++i) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using P = pair<int,int>; static const double PI = acos(-1); int main(){ string s, t; cin >> s >> t; s += s; REP(i,t.size()){ bool ok = true; REP(j,t.size()){ if(s[i+j] != t[j]) ok = false; } if(ok) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> int main() { for(;;) { int n, m, p; std::cin >> n >> m >> p; if (n == 0 && m == 0 && p == 0) { break; } std::vector<int> xs(n); for(int i = 0; i < n; ++i) { std::cin >> xs[i]; } int sum = 0; for(int x : xs) { sum += x; } if (xs[m-1] == 0) { printf("0\n"); } else { int res = sum * (100 - p) / xs[m-1]; printf("%d\n", res); } } }
0
56,625,800
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int N,M; cin>>N>>M; vector<string> A(N),B(M); for(string &S:A)cin>>S; for(string &S:B)cin>>S; for(int i=0;i+M<=N;i++) for(int j=0;j+M<=N;j++){ for(int k=0;k<M;k++) for(int l=0;l<M;l++) if(A[i+k][j+l]!=B[k][l])goto home; puts("Yes"); return 0; home:; } puts("No"); }
#include <iostream> #include <string> using namespace std; int main(){ int H,K,W; cin >> H >> W >> K; string c[H]; int count=0; for(int i=0;i<H;i++){ cin >> c[i]; } for(int bit_l=0; bit_l < (1<<H); ++bit_l){ for(int bit_c=0; bit_c < (1<<W); ++bit_c){ int black=0; for(int i=0;i<H;++i){ for(int j=0;j<W;++j){ if(!((bit_l & (1<<i)) || (bit_c & (1<<j)) || c[i][j]=='.')){ ++black; } } } if(black==K){ ++count; } } } cout << count << endl; }
0
82,011,807
#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++) int main() { LL n; cin>>n; LL mx=INF; for(LL i=1;i*i<=n;i++) { if(n%i==0) { mx=min(mx,n/i+i-2); } } cout<<mx; }
#include <bits/stdc++.h> #include <iostream> #include<math.h> using namespace std; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main() { char c; cin >> c; if (c == 'A') { cout << 'T' << endl; } else if (c == 'G') { cout << 'C' << endl; } else if (c == 'T') { cout << 'A' << endl; } else if (c == 'C') { cout << 'G' << endl; } return 0; }
0
21,038,058
#include <iostream> #include <iomanip> #include <algorithm> #include <vector> #include <set> #include <map> #include <math.h> #include <string> #include <numeric> #include <queue> #include <cstdio> #include <cstring> #define ll long long #define rep(i,n) for(ll i=0;i<n;++i) #define rep1(i,n) for(ll i=1;i<n;++i) #define mrep(i,n) for(ll i=n;i>=0;--i) #define all(a) (a).begin(),(a).end() #define vl vector<ll> #define vvl vector<vector<ll> > #define vb vector<bool> #define vvb vector<vector<bool> > #define pl pair<ll,ll> #define inf 1001001001001001000 #define mod 998244353 #define pi 3.1415926535 using namespace std; struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } }__init; int main(void) { ll n,m; cin>>n>>m; if(min(n,m) == 1){ if(max(n,m)==1) cout<<1<<endl; else cout<<(max(n,m)-2)<<endl; } else{ cout<<(n-2)*(m-2)<<endl; } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for(long long i=0; i<n; i++) #define REPR(i, n) for(long long i=n-1; i>=0; i--) #define FOR(i, m, n) for(long long i=m; i<=n; i++) #define FORR(i, m, n) for(long long i=m; i>=n; i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VSORTR(v) sort(v.rbegin(), v.rend()); #define ALL(v) (v).begin(),(v).end() #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; using ll = long long; using ull = unsigned long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; const ll mod = 1e9+7; const ll inf = 1e15; ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;} int main(){FIN ll n;cin>>n; vll c(n-1), s(n-1), f(n-1); REP(i,n-1){ cin>>c[i]>>s[i]>>f[i]; } FOR(i,0,n-2){ ll sum = c[i] + s[i]; FOR(j, i+1, n-2){ if (sum < s[j]) sum = s[j]+c[j]; else{ sum += (f[j]- (sum % f[j])) % f[j]; sum += c[j]; } } cout<<sum<<endl; } cout<<0<<endl; return 0; }
0
9,929,433
#include <iostream> #include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.1415926535897932384626433832795l #define F first #define S second #define mp make_pair #define f(i,n) for(int i=0;i<n;i++) #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define sort(v) sort((v).begin(),(v).end()) #define rsort(v) sort((v).rbegin(),(v).rend()) #define gcd(a,b) __gcd((a),(b)) #define minn(v) *min_element(v.begin(), v.end()); #define maxx(v) *max_element(v.begin(), v.end()); #define print(x) cout<<(x)<<endl; #define sum(v)+x accumulate(v.begin(), v.end(),x); typedef pair<int,int> pii; typedef vector<int> vi; struct type{ int k, i, j; }; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int findSubarray(int arr[], int n, int k) { int window_sum = 0; int min_window = INT_MAX; int last = 0; for (int i = 0; i < n; i++) { window_sum += arr[i]; if (i + 1 >= k) { if (min_window > window_sum) { min_window = window_sum; last = i; } window_sum -= arr[i + 1 - k]; } } int sum=0; for(int i=last-k+1;i<=last;i++) { sum+=arr[i]; } return sum; } int nextpermutation(vi v) { vi t=v; sort(t); int x=0; while(true) { x++; if(t==v) { return x; } next_permutation(all(t)); } } signed main() { fastio; string s,t; cin>>s>>t; cout<<t<<""<<s<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int a, b, x; cin >> a >> b >> x; double pi = acos(-1); if(x >= a*a*b/2){ double c = a, d = b, e = x; printf("%.10f",atan(2.0*(c*c*d - e)/(c*c*c)) * 360.0 / (2.0*pi)); } else{ double c = a, d = b, e = x; printf("%.10f",atan(d*d*c/(2*e)) * 360.0 / (2.0*pi)); } }
0
29,906,875
#include <iostream> using namespace std; int main(){ int x, n; n = 1; while (1) { cin >> x; if (x == 0) { break; } cout << "Case " << n << ": " << x << endl; n++; } return 0; }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> using namespace std; #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i ) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef pair<int,int> pint; typedef pair<ll,int> pli; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; #define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0])) int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll a[n] = {0}; for(int i = 0;i < n;i++){ cin >> a[i] ; } stable_sort(a,a + n); ll count = 0; for(int i = 0;i < n;i++){ count += a[i]; } cout << a[0] <<" " << a[n - 1] << " " << count << endl; }
0
55,699,225
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <set> #include <vector> #include <queue> #include <stack> #include <map> #include <cmath> #include <bitset> #include <fstream> using namespace std; #define pi pair<int,int> #define mp(x,y) make_pair(x,y) #define fi first #define se second #define pl pair<long long,long long> #define pb push_back #define vi vector<int> #define ll long long const int MAXN=200005,mod=1e9+7; int w[(1<<26)+5]; char t[MAXN]; int main () { int a,b,c,d,e,f,k,q,m,res; scanf("%s", t); m=1<<26; for (a=1; a<m; a++) w[a]=1000000; w[0]=0; b=0; res=0; for (a=0; t[a]; a++) { c=(1<<(t[a]-'a')); b^=c; d=w[b]+1; for (c=0; c<26; c++) { e=b^(1<<c); d=min(d,w[e]+1); } res=d; w[b]=min(w[b],res); } printf("%d", res); return 0; }
#include <bits/stdc++.h> using namespace std; class UnionFindDS{ private: vector<int> p, h, sz; int num; public: UnionFindDS(int N){ p.assign(N,0); for (int i=0; i<N; i++) p[i] = i; h.assign(N,0); sz.assign(N,1); num = N; } int numSets(){ return num; } int findSet(int i){ return p[i] == i ? i : p[i] = findSet(p[i]); } int sizeSet(int i){ return sz[findSet(i)]; } bool isSameSet(int i, int j){ return findSet(i) == findSet(j); } void unionSet(int i, int j){ int x = findSet(i), y = findSet(j); if (x == y) return; num--; if (h[x] > h[y]){ p[y] = x; sz[x] += sz[y]; } else { p[x] = y; sz[y] += sz[x]; h[y] += (h[y] == h[x]); } } }; int N, M, op, p, q; int main(){ ios_base::sync_with_stdio(false); cin >> N >> M; UnionFindDS uf(N); for (int i=0; i<M; i++){ cin >> op >> p >> q; if (op == 0){ uf.unionSet(p,q); } else{ if (uf.isSameSet(p,q)) cout << 1 << endl; else cout << 0 << endl; } } return 0; }
0
20,016,352
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= (n); i++) #define repi(i, a, b) for (int i = (a); i < (b); i++) #define all(a) (a).begin(), (a).end() #define bit(b) (1ull << (b)) using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using f64 = double; using f80 = long double; using pii = pair<i32, i32>; using vi32 = vector<i32>; using vu32 = vector<u32>; using vi64 = vector<i64>; using vu64 = vector<u64>; using vf64 = vector<f64>; using vf80 = vector<f80>; using vstr = vector<string>; using vpii = vector<pii>; using vvi32 = vector<vi32>; using vvu32 = vector<vu32>; using vvi64 = vector<vi64>; using vvu64 = vector<vu64>; using vvf64 = vector<vf64>; using vvf80 = vector<vf80>; template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; } template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; } char board[110][110]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); int A, B; cin >> A >> B; vector<string> board(100); rep(i, 100) { if (i < 50) { board[i] = string(100, '#'); } else { board[i] = string(100, '.'); } } rep(i, A - 1) { int y = ((i * 2) / 100) * 2; int x = (i * 2) % 100; board[y][x] = '.'; } rep(i, B - 1) { int y = 99 - ((i * 2) / 100) * 2; int x = (i * 2) % 100; board[y][x] = '#'; } cout << 100 << " " << 100 << endl; rep(i, 100) { cout << board[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> P; vector<P> prime_factorize(int N){ vector<P> ans; for(int a = 2; a*a <= N; a++){ if(N % a == 0){ int ex = 0; while(N%a == 0){ ex++; N /= a; } ans.push_back(P(a, ex)); } } if(N != 1) ans.push_back(P(N, 1)); return ans; } int main(){ int n; scanf("%d", &n); vector<int> a(n), data(1e6+1, 0); for(int i = 0; i < n; i++){ scanf("%d", &a[i]); auto vec = prime_factorize(a[i]); for(int j = 0; j < vec.size(); j++){ data[vec[j].first]++; } } bool check = true; for(int i = 2; i < data.size(); i++){ if(data[i] >= 2) check = false; } if(check){ cout << "pairwise coprime" << endl; return 0; } int g = a[0]; for(int i = 1; i < n; i++) g = __gcd(g, a[i]); if(g == 1){ cout << "setwise coprime" << endl; return 0; } cout << "not coprime" << endl; }
0
14,692,251
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL<<62 #define inf 1000000007 char a[302][302],b[302][302]; int main() { ll n; cin>>n; for(ll i=0;i<n;i++){ for(ll j=0;j<n;j++){ cin>>a[i][j]; } } ll ans=0; for(ll B=0;B<n;B++){ for(ll i=0;i<n;i++){ for(ll j=0;j<n;j++){ ll nex=j+B; nex%=n; b[i][nex]=a[i][j]; } } bool ch=true; for(ll i=0;i<n;i++){ for(ll j=0;j<n;j++){ if(b[i][j]!=b[j][i]){ ch=false; } } } if(ch){ ans+=n; } } cout <<ans; return 0; }
#include <iostream> #include <vector> int main() { while (true) { int m, nmin, nmax; std::cin >> m >> nmin >> nmax; if (m == 0) { break; } std::vector<int>ps; ps.resize(m); for (int i = 0; i < m; i++) { std::cin >> ps.at(i); } int maxgap = -1; int ans = -1; for (int i = nmin; i <= nmax; i++) { int gap = ps.at(i - 1) - ps.at(i); if (gap >= maxgap) { maxgap = gap; ans = i; } } std::cout << ans << std::endl; } return 0; }
0
85,194,209
#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <ctype.h> #include <math.h> #include <stack> #include <string> #include <string.h> using namespace std; double PI = 3.1415926535897932; long mod = 1000000007; const long INF = 1e9 + 1; int main() { long n,a,b; cin >> n >> a >> b; long sum = n / (a+b) * a; sum += min(n % (a+b), a); cout << sum << endl; }
#include<iostream> using namespace std; int main(){ int cnt=0; int n, x; cin >> n >> x; while(!(n==0 && x==0)){ cnt=0; for(int i=1;i<=x/3 && i<=n;++i){ for(int j=i+1;j<=x/2 && j<=n;++j){ int k=x-i-j; if(k>j && k<=n){ ++cnt; } } } cout<<cnt<<"\n"; cin >> n >> x; } }
0
876,881
#include <bits/stdc++.h> using namespace std; int main() { double R; double G; cin >> R >> G; double performance = 2 * G -R; cout << performance << endl; }
#include <iostream> #include <iomanip> using namespace std; int main() { int n,x; int count=0; while(1){ cin >> n >> x; if(n==0 && x==0){ break; } int i,j,k; for(i=1;i<(n-1);i++){ for(j=i+1;j<n;j++){ for(k=j+1;k<=n;k++){ if(i+j+k==x){ count++; break; } } } } cout << count << endl; count = 0; } return 0; }
0
16,759,790
#include <bits/stdc++.h> #include <stack> using namespace std; int main() { int h,w,m; cin >> h >> w >> m; vector<int> hcnt(h,0); vector<int> wcnt(w,0); int hm = 0; int wm = 0; set<pair<int,int>> bomb; int cnt = -1; for(int i=0; i<m; i++){ int y; int x; cin >> y >> x; y--; x--; bomb.insert(make_pair(y,x)); hcnt[y]++; wcnt[x]++; if(hcnt[y] > hm) hm = hcnt[y]; if(wcnt[x] > wm) wm = wcnt[x]; } vector<int> hn; vector<int> wn; for(int i=0; i<h; i++){ if(hcnt[i] == hm) hn.push_back(i); } for(int i=0; i<w; i++){ if(wcnt[i] == wm) wn.push_back(i); } for(int i=0; i<hn.size(); i++){ for(int j=0; j<wn.size(); j++){ if(bomb.count(pair<int,int>(hn[i],wn[j]))) continue; cout << hm + wm << endl; return 0; } } cout << hm + wm -1 << endl; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <numeric> #include <cmath> #include <iomanip> #include <cstdio> #include <set> #include <map> #include <list> #include <cstdlib> using namespace std; #define mod (1e9 + 7) #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) x.begin(), x.end() typedef long long ll; void solve1() { int x; cin >> x; bool f = false; for(int i = 1; i <= 1000; i++) { if(x >= 100*i && x <= 105*i) { f = true; break; } } if(f) { cout << 1 << endl; } else { cout << 0 << endl; } } int main() { solve1(); }
0
63,417,928
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<cstdio> #include<climits> #include<cmath> #include<cstring> #include<string> #include<complex> #include<cfloat> #include<cassert> #define f first #define s second #define mp make_pair #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) #define ALL(c) (c).begin(), (c).end() #define EPS (1e-10) using namespace std; typedef unsigned int uint; typedef long long ll; typedef complex<double> P; #define PI (3.1415926535) #define EPS (1e-10) int main(){ int n; while(cin>>n){ ll f = 1ll; do{ f *= n; }while(--n!=0); cout << f << endl; } return 0; }
#include<iostream> using namespace std; int main(){ int a,b; cin>>a>>b; if(a==b) cout<<"Draw"<<endl; else{ if(a==1) cout<<"Alice"<<endl; else if(b==1) cout<<"Bob"<<endl; else{ if(a>b) cout<<"Alice"<<endl; else cout<<"Bob"<<endl; } } }
0
87,712,898
#include <iostream> using namespace std; typedef long long ll; #define rep(i,n) for((i)=0;(i)<(n);(i)++) #define repp(i,n) for((i)=1;(i)<=(n);(i)++) int main(){ ll i,n,k,c[100010]={0},a,b,cnt=0; cin >> n >> k; rep(i,n){ cin >> a >> b; c[a] += b; cnt += b; } repp(i,100000){ k -= c[i]; if(k<=0){ cout << i << endl; return 0; } } return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define REP(i,n) FOR(i,0,(n)) class BTwoColorsCardGame { public: void solve(std::istream& in, std::ostream& out) { int n; in >> n; vector<string> s(n); REP(i,n) in >> s[i]; int m; in >> m; vector<string> t(m); REP(i,m) in >> t[i]; map<string, int> a; REP(i,n){ a[s[i]]++; } REP(i,m){ a[t[i]]--; } out << max(0ll, max_element(a.begin(),a.end(),[](pair<string, int> b, pair<string, int> c){return b.second < c.second;})->second) << endl; } }; signed main() { ios::sync_with_stdio(false); cout.tie(0); cout << fixed; BTwoColorsCardGame solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
0
85,865,877
#include<bits/stdc++.h> #define l(i,a,n)for(int i=a;i<n;i++) #define pb push_back #define in insert #define mp make_pair #define lw(v) sort(v.begin(),v.end()); #define hi(v) sort(v.begin(),v.end(),greater<long long>()); #define all(v) v.begin(),v.end() #define filein freopen ("input.txt", "r", stdin) #define fileout freopen ("output.txt", "w", stdout) using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0; vector<long long>v; vector<long long>u; set<long long>s; std::vector<int>::iterator it; string s1,s2,s3,s4; cin>>n>>m>>k; cout<<min(n+m,min(n+k,m+k))<<endl; }
#include<bits/stdc++.h> using namespace std; #define LL long long #define DD double #define Pb push_back #define Bp pop_back #define Pf push_front #define Fp pop_front #define Ub upper_bound #define Lb lower_bound #define In insert #define All(x) x.begin(), x.end() #define mem(a, b) memset(a, b, sizeof(a)) #define fast ios_base::sync_with_stdio(0);cin.tie(0) #define X first #define Y second #define mx1 10 #define mx2 110 #define mx3 1010 #define mx4 10010 #define mx5 100010 #define mx6 1000010 typedef vector<LL> Vl; typedef vector<DD> Vd; typedef vector<bool> Vb; typedef vector<Vl> VVl; typedef pair<LL, LL> Pll; typedef pair<DD, DD> Pdd; typedef vector<Pll> Vpl; typedef vector<Pdd> Vpd; typedef queue<LL> Ql; typedef stack<LL> Sl; typedef deque<LL> Dl; LL _set(LL N, LL pos) {return N = N | (1 << pos);} LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);} bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));} bool _upper(char a) {return a >= 'A' && a <= 'Z';} bool _lower(char a) {return a >= 'a' && a <= 'z';} bool _digit(char a) {return a >= '0' && a <= '9';} LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1}; LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1}; int main() { int n, m; cin >> n >> m; if(n > m) swap(n, m); if(n == 1){ if(m == 1) return cout << 1 << '\n', 0; return cout << m - 2 << '\n', 0; } if(n == 2) return cout << 0 << '\n', 0; cout << 1ll * (n - 2) * (m - 2) << '\n'; return 0; }
0
37,075,380
#include<iostream> #include<string> using namespace std; void shuffle( string& s ) { char temp = s[0]; for( int i = 0; i < s.size() - 1; i++ ) { s[i] = s[i+1]; } s[s.size()-1] = temp; } int main() { string str; int m; int h; while( cin >> str ) { if( str == "-" ) break; cin >> m; for ( int i = 0; i < m; i++) { cin >> h; for( int i = 0; i < h; i++ ) { shuffle(str); } } cout << str << endl; } return 0; }
#include <stdio.h> #include <iostream> using namespace std; long long a[100010]; long long mask[61]; int main() { int n;scanf("%d",&n); for (int i=0;i<n;++i) scanf("%lld",&a[i]); long long ans=0; long long tmp=0; for (int i=0;i<n;++i) tmp^= a[i]; ans=tmp; tmp= (1LL << 61)-1-tmp; for (int i=0;i<n;++i) a[i]&=tmp; tmp=0; for (int i=0;i<n;++i) { for (int j=60;j>=0;--j) { if ( (a[i]&(1LL<<j))==0 ) continue; if ( !mask[j] ){ mask[j]=a[i]; break; } a[i]^=mask[j]; } } for (int i=59;i>=0;--i) { if (mask[i] && (tmp^mask[i])>tmp) tmp^=mask[i]; } printf("%lld\n",ans+(tmp*2)); }
0
84,954,370
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define endl '\n' int t=1; void solve(){ int n,l; cin >> n >> l; for(int i=0;i<=n;i++){ if((l+2*i)==4*n){cout << "Yes" <<endl;return;} } cout << "No" <<endl; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif for(int i=1;i<=t;i++){ solve(); } return 0; }
#include <bits/stdc++.h> #include <cstdlib> #include <cmath> #define rep(i,n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; int main(){ ll n; ll a; ll b; ll x = 0; ll y = 0; ll ans = 0; cin >> n >> a >> b; x = n % (a+b); y = n / (a+b); if (x > a){ ans = y * a + a; } if (x <= a){ ans = y * a + x; } cout << ans; return 0; }
0
86,142,222
#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 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(){ ll N; cin >> N; VL A(N); REP(i,N) cin >> A[i]; ll sum = 0; REP(i,N) sum += A[i]; if(sum % (N*(N+1)/2) != 0){ cout << "NO" << en; return; } ll k = sum / (N*(N+1)/2); VL m(N); REP(i,N){ ll d = A[(i+1)%N] - A[i]; if(k-d<0 || (k-d)%N!=0){ cout << "NO" << en; return; } m[(i+1)%N] = (k-d) / N; } sum = 0; REP(i,N) sum += m[i]; cout << (sum==k ? "YES" : "NO") << en; return; } int main(void){ cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; REP(_,t){ Main(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N=2e5+100; const int mod=1e9+7; typedef long long ll; typedef pair<int,int> pa; map<ll,int>mp; int main() { ios::sync_with_stdio(0);cin.tie(0); int n,m;cin>>n>>m; mp[0]=1; ll sum=0,ans=0; for(int i=1;i<=n;i++){ ll x;cin>>x; sum=(sum+x)%m; ans+=mp[sum]; mp[sum]++; } cout<<ans<<endl; return 0; }
0
32,837,676
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; #define rep(i,s,n) for(int i = s; i < (int)(n); i++) int main() { int n; ll x = 1000; cin >> n; vector<int>a(n); rep(i,0,n) cin >> a[i]; rep(i,0,n-1) if(a[i] < a[i+1]) x = x%a[i]+(x/a[i])*a[i+1]; cout << x << endl; }
#include <iostream> using namespace std; int N; int ma; int main() { cin >> N; for(int i = 1;i <= N;i++) { if((i + 1) * i / 2 >= N) { ma = i; break; } } for(int i = ma;i >= 1;i--) { if(N - i >= 0) { cout << i << endl; N -= i; } } return 0; }
0
29,242,818
#include <iostream> #include <cstdio> #include <vector> #include <iomanip> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <map> #include <set> #include <cmath> using namespace std; int main() { long long A; long long B; long long C; long long D; cin >> A >> B >> C >> D; cout << max(max(B*C, A*D), max(A*C, B*D)) << endl; return 0; }
#include <iostream> #include <cstring> using namespace std; int main(){ int n; cin>>n; int data[101][101]; memset(data,0,sizeof(data)); int id,num,rout; for(int i=0;i<n;i++){ cin>>id>>num; id--; for(int j=0;j<num;j++){ cin>>rout; data[id][rout-1]=1; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(j) cout<<" "; cout<<data[i][j]; } cout<<endl; } return 0; }
0
7,977,247
#include<stdio.h> using namespace std; int x,y,z = 0; int main() { scanf("%d %d", &x, &y); while (1) { if (x == 0 && y == 0) { break; } if (x > y) { z = x; x = y; y = z; } printf("%d %d\n", x, y); scanf("%d %d", &x, &y); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; int calc(int nowTime, int s, int f){ if(nowTime <= s) return s - nowTime; else { int div = (nowTime + f-1)/f; return (div*f - nowTime); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<int> C(N-1), S(N-1), F(N-1); for(int i = 0; i < N-1; ++i) cin >> C[i] >> S[i] >> F[i]; for(int j = 0; j < N; ++j){ int nowTime = 0; for(int i = j; i < N-1; ++i){ nowTime += calc(nowTime, S[i], F[i]); nowTime += C[i]; } cout << nowTime << '\n'; } return 0; }
0
18,390,602
#include<iostream> int main(){ int h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,k; std::cin >>h0>>h1>>h2>>h3>>h4>>h5>>h6>>h7>>h8>>h9; if (h8>h9) k=h8, h8=h9, h9=k; if (h7>h8) k=h7, h7=h8, h8=k; if (h8>h9) k=h8, h8=h9, h9=k; if (h6>h7) k=h6, h6=h7, h7=k; if (h7>h8) k=h7, h7=h8, h8=k; if (h8>h9) k=h8, h8=h9, h9=k; if (h5>h7) k=h5, h5=h7, h7=k; if (h7>h8) k=h7, h7=h8, h8=k; if (h8>h9) k=h8, h8=h9, h9=k; if (h4>h7) k=h4, h4=h7, h7=k; if (h7>h8) k=h7, h7=h8, h8=k; if (h8>h9) k=h8, h8=h9, h9=k; if (h3>h7) k=h3, h3=h7, h7=k; if (h7>h8) k=h7, h7=h8, h8=k; if (h8>h9) k=h8, h8=h9, h9=k; if (h2>h7) k=h2, h2=h7, h7=k; if (h7>h8) k=h7, h7=h8, h8=k; if (h8>h9) k=h8, h8=h9, h9=k; if (h1>h7) k=h1, h1=h7, h7=k; if (h7>h8) k=h7, h7=h8, h8=k; if (h8>h9) k=h8, h8=h9, h9=k; if (h0>h7) k=h0, h0=h7, h7=k; if (h7>h8) k=h7, h7=h8, h8=k; if (h8>h9) k=h8, h8=h9, h9=k; std::cout << h9 <<"\n"<< h8 <<"\n"<< h7 <<"\n"; return 0; }
#include <vector> #include <map> #include <set> #include <cmath> #include <iostream> #include <algorithm> #include <queue> #include <iomanip> #include <list> #include <string> typedef char SINT8; typedef short SINT16; typedef int SINT32; typedef long long SINT64; typedef double DOUBLE; #define MAX(a,b) ((a)>(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b)) #define ABS(a) ((a)>(0)?(a):-(a)) #define rep(i,a,b) for(SINT64 (i)=SINT64(a);(i)<SINT64(b);(i)++) #define rrep(i,a,b) for(SINT64 (i)=SINT64(a);(i)>=SINT64(b);(i)--) #define put(a) cout << (a) << endl #define puts(a) cout << (a) << " " #define putr(a) rep(testIncrement,0,a.size()) {puts(a[testIncrement]);} cout << endl #define putrr(a) rep(Incr1,0,a.size()) {rep(Incr2,0,a[Incr1].size()) {puts(a[Incr1][Incr2]);} cout<<endl;} cout<<endl; #define INF 1000000001 #define MOD 1000000007 #define INF64 1000000000000000001 #define PI (acos(-1)) #define F first #define S second #define Pii pair<SINT32,SINT32> #define Pll pair<SINT64,SINT64> #define Piii pair<SINT32,pair<SINT32,SINT32>> #define Plll pair<SINT64,pair<SINT64,SINT64>> #define Vll(a,b,c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c)) #define Vlll(a,b,c,d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d))) using namespace std; int main() { SINT64 N; cin >> N; vector<SINT64> sum1(100005); vector<SINT64> sum2(100005); rep(i,0,N) { SINT64 a; cin >> a; if ((i % 2) == 0) { sum1[a]++; } else { sum2[a]++; } } SINT64 ma1 = 0; SINT64 sma1 = 0; SINT64 ma2 = 0; SINT64 sma2 = 0; SINT64 num1 = 0; SINT64 num2 = 0; rep(i,0,100005) { if (ma1 < sum1[i]) { sma1 = ma1; ma1 = sum1[i]; num1 = i; } else { if (sma1 < sum1[i]) { sma1 = sum1[i]; } } if (ma2 < sum2[i]) { sma2 = ma2; ma2 = sum2[i]; num2 = i; } else { if (sma2 < sum2[i]) { sma2 = sum2[i]; } } } if (num1 != num2) { put(N-ma1-ma2); } else { SINT64 ans = MIN(N-ma1-sma2,N-ma2-sma1); put(ans); } return 0; }
0
67,383,135
#include<bits/stdc++.h> using namespace std; int main(){ int n; int maxs,mins,sum; while(cin>>n,n){ sum=0; maxs=0; mins=2000; for(int i=0,tmp;i<n;i++){ cin>>tmp; sum+=tmp; maxs=max(maxs,tmp); mins=min(mins,tmp); } sum-=mins; sum-=maxs; cout<<sum/(n-2)<<endl; } }
#include "omp.h" #include <iostream> #include <iomanip> #include <string> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <vector> #include <cassert> #include <fstream> #include <algorithm> #include <list> #include <random> #include <ctime> #include <random> #include <bitset> #include <unordered_set> #include <cassert> #include <list> #include <functional> using namespace std; typedef long long ll; typedef long double ld; const int sze = 1 << 15, INF = 1e9 + 10; pair<int, int> ans; ld cnt = 0; signed main() { int n; cin >> n; vector<int> values(n); for (int i = 0; i < n; ++i) cin >> values[i]; sort(values.begin(), values.end()); int l = -1, r = n; while (r - l > 1) { int m = (l + r) >> 1; if (values[m] * 2 >= values[n - 1]) r = m; else l = m; } if (l == -1) cout << values[n - 1] << ' ' << values[r]; else if (r == n) cout << values[n - 1] << ' ' << values[l]; else { if (values[n - 1] - values[r] > values[l]) cout << values[n - 1] << ' ' << values[r]; else cout << values[n - 1] << ' ' << values[l]; } return 0; }
0
18,532,455
#include<bits/stdc++.h> using namespace std; int a[2005],n,k; const int mod=1e9+7; int calc(int K){ return (1ll*K*(K+1)/2)%mod; } signed main(){ cin>>n>>k; for(int i=1;i<=n;++i) cin>>a[i]; int ans=0; for(int i=1;i<=n;++i){ for(int j=1;j<i;++j) if(a[j]>a[i]) ans=(ans+calc(k))%mod; else if(a[j]<a[i]) ans=(ans+calc(k-1))%mod; } cout<<ans; return 0; }
#include <cstdio> #include <iostream> #include <vector> #include <math.h> using namespace std; int H, M, N; int go[4][2]; bool K[1002][1002]; int score[1002][1002]; int C[11][2]; int ans = 0; void saiki(int sx, int sy, int s){ if(K[sx][sy]){ if(score[sx][sy] > s){ score[sx][sy] = s; for(int i = 0; i < 4; i++){ saiki(sx + go[i][0], sy + go[i][1], s + 1); } } } } int main(){ go[0][0] = 1; go[0][1] = 0; go[1][0] = 0; go[1][1] = -1; go[2][0] = -1; go[2][1] = 0; go[3][0] = 0; go[3][1] = 1; for(int i = 0; i <= H + 1; i++){ for(int j = 0; j <= M + 1; j++){ score[i][j] = 2147483640; K[i][j] = false; } } scanf("%d%d%d", &H, &M, &N); for(int i = 0; i < H; i++){ char str[M + 1]; scanf("%s", str); for(int j = 0; j < M; j++){ if(str[j] == '.'){ K[i + 1][j + 1] = true; }else if(str[j] == 'X'){ K[i + 1][j + 1] = false; }else if(str[j] == 'S'){ C[0][0] = i + 1; C[0][1] = j + 1; K[i + 1][j + 1] = true; }else{ C[str[j] - '0'][0] = i + 1; C[str[j] - '0'][1] = j + 1; K[i + 1][j + 1] = true; } } } for(int i = 0; i < N; i += 2){ for(int j = 1; j <= H; j++){ for(int k = 1; k <= M; k++){ if(K[j][k]){ score[j][k] = 2147483640; }else{ score[j][k] = -2147483640; } } } saiki(C[i + 1][0], C[i + 1][1], 0); int aa = score[C[i][0]][C[i][1]]; int bb; if(i + 2 < N){ bb = score[C[i + 2][0]][C[i + 2][1]]; ans += bb; } ans += aa; } printf("%d\n", ans); return 0; }
0
84,684,855
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC ii mer(int a, int b) { int op = 0; while (1) { ++op; if (a + b < 10) return mp(a+b,op); else tie(a,b) = mp((a+b)/10, (a+b)%10); } } ii mr[10][10]; ii mem[10][60]; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) mr[i][j] = mer(i, j); for (int c = 0; c < 10; ++c) { mem[c][0] = mp(c, 0); for (int i = 1; i < 60; ++i) { auto t = mr[mem[c][i - 1].f][mem[c][i - 1].f]; mem[c][i] = mp(t.f, t.s + mem[c][i - 1].s * 2); } } int n; cin >> n; int ans = 0; vector <int> ar; for (int i = 0; i < n; ++i) { int d, k; cin >> d >> k; int c = d; --k; for (int j = 0; j < 60; ++j) { if ((k >> j) & 1) { ii add = mem[d][j]; auto t = mr[c][add.f]; ans += t.s; ans += add.s; c = t.f; } } ar.app(c); } int cur = ar[0]; for (int i = 1; i < ar.size(); ++i) { ii t = mr[cur][ar[i]]; cur = t.f; ans += t.s; } cout << ans << endl; }
#include <iostream> #include <string> #include <cstring> #include <sstream> #include <fstream> #include <vector> #include <algorithm> #include <stack> #include <queue> #include <chrono> #include <numeric> #include <set> #define _USE_MATH_DEFINES #include <cmath> #include <math.h> #include <iomanip> #include <list> using namespace std; double const PI = atan(1.0) * 4; class cPoint { double mx; double my; public: cPoint() {} cPoint(double x, double y) : mx(x), my(y) { } cPoint operator+(const cPoint& obj2) { return cPoint(mx + obj2.mx, my + obj2.my); } cPoint operator-(const cPoint obj2) { return cPoint(mx - obj2.mx, my - obj2.my); } cPoint operator*(const double& d) { return cPoint(mx * d, my * d); } cPoint operator/(const double& d) { if (d != 0.0) { return cPoint(mx / d, my / d); } return cPoint(0.0, 0.0); } bool operator==(const cPoint& obj2) { if (mx == obj2.mx && my == obj2.my) return true; return false; } void operator()(const double& a, const double& b) { mx = a; my = b; } double getLength(const cPoint& obj) { return sqrt(obj.mx * obj.mx + obj.my * obj.my); } cPoint gen(const cPoint& obj1, const cPoint& obj2, const double& angle, const double mul = 1.0) { cPoint temp = obj2; temp = temp - obj1; double length = getLength(temp); temp.mx = length * mul * cos(angle / 180.0 * PI); temp.my = length * mul * sin(angle / 180.0 * PI); return temp; } void display(ostream& out) { out << mx << " " << my; } }; ostream& operator<<(ostream& o, cPoint& d) { d.display(o); return o; } class cKochCurve { int mn; cPoint m_p1, m_p2; list<cPoint> lpPoints; public: cKochCurve(int n) : mn(n) { m_p1(0.0, 0.0); m_p2(100.0, 0.0); lpPoints.push_front(m_p1); lpPoints.push_back(m_p2); calc(n, m_p1, m_p2, 0); } void calc(int, cPoint, cPoint, double); void output(); }; void cKochCurve::calc(int n, cPoint p1, cPoint p2, double angle) { if (n == 0) return; list<cPoint>::iterator ilpp; for (list<cPoint>::iterator it = lpPoints.begin(); it != lpPoints.end(); ++it) { if (*it == p1 && it != lpPoints.end()) { list<cPoint>::iterator it2 = it; ++it2; if (*it2 == p2) { ilpp = it2; break; } } } cPoint s, t, u; s = p1 + (p2 - p1) * (1.0 / 3.0); t = p1 + (p2 - p1) * (2.0 / 3.0); u = s + t.gen(s, t, angle + 60.0); lpPoints.insert(ilpp, s); lpPoints.insert(ilpp, u); lpPoints.insert(ilpp, t); calc(n - 1, p1, s, angle); calc(n - 1, s, u, angle + 60); calc(n - 1, u, t, angle - 60); calc(n - 1, t, p2, angle); } void cKochCurve::output() { for (list<cPoint>::iterator it = lpPoints.begin(); it != lpPoints.end(); ++it) { cout << fixed << setprecision(8) << *it << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; cin.ignore(); cKochCurve ckc(n); ckc.output(); return 0; }
0
12,596,181
#include<iostream> #include <vector> #include <cmath> #include <algorithm> #include <utility> #include <map> using namespace std; int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } int main() { long N,K; cin >> N >> K; vector<long> longlist(N); long num = 0; for (long i = 0; i < N; i++) { cin >> num; longlist[i] = abs(num-K); } long n, a, b; n = longlist.size(); a = longlist[0]; for (long i = 1; i < n; i++) { b= longlist[i]; a = gcd(a, b); } cout << a << endl; return 0; }
#include <iostream> #include <algorithm> using namespace std; int main(){ int N; cin >> N; int t[N+1]; int x[N+1]; int y[N+1]; t[0] = x[0] = y[0] = 0; for(int i = 0; i < N; i++) { cin >> t[i+1] >> x[i+1] >> y[i+1]; } bool flag = true; for(int i = 0; i < N; i++){ int dt = t[i+1] - t[i]; int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]); if(dist > dt) flag = false; if(dt%2 != dist%2) flag = false; } if(flag) cout << "Yes" << endl; else cout << "No" << endl; }
0
21,287,584
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100 + 10; int f[N][N]; char a[N][N]; void upd(int &x,int y){ x = min(x,y); } int main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++) cin>>(a[i]+1); memset(f,0x7f,sizeof(f)); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ if(i==1&&j==1) f[i][j] = (a[1][1]=='#'); if(a[i][j]=='#'){ upd(f[i+1][j],f[i][j]); upd(f[i][j+1],f[i][j]); } else{ upd(f[i+1][j],f[i][j]+(a[i+1][j]=='#')); upd(f[i][j+1],f[i][j]+(a[i][j+1]=='#')); } } cout<<f[n][m]<<endl; }
#include <iostream> #include <cstdio> #include <map> #include <queue> #include <string> #include <cstring> #include <set> #include <vector> using namespace std; #define ll long long const int maxx = 2005; const ll mod = 1e9+7; int a[maxx],b[maxx]; ll dp[maxx][maxx]; int n,m; int main(){ cin>>n>>m; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=m;i++) scanf("%d",&b[i]); for(int i=1;i<=n;i++){ ll cnt = 0; for(int j=1;j<=m;j++){ cnt += dp[i-1][j] , cnt %= mod; if(a[i] == b[j]){ dp[i][j] = cnt + 1 , dp[i][j] %= mod; }else{ dp[i][j] = dp[i-1][j]; } } } ll ans = 1; for(int i=1;i<=m;i++){ ans += dp[n][i] , ans %= mod; } cout<<ans<<endl; return 0; }
0
50,445,342
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int x = 0, t = 0; std::cin >> x >> t; if (x > t) std::cout << x - t << std::endl; else std::cout << 0 << std::endl; return 0; }
#include<bits/stdc++.h> using namespace std; using Int = long long; #include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T, typename E> struct SkewHeap{ typedef function<T(T, E)> F; typedef function<E(E, E)> G; typedef function<bool(T,T)> C; F f; G g; C c; E e; SkewHeap(F f,G g,C c,E e):f(f),g(g),c(c),e(e){} struct Node{ Node *l,*r; T val; E add; Node(T val,E add):val(val),add(add){l=r=NULL;} }; void eval(Node *a){ if(a->add==e) return; if(a->l) a->l->add=g(a->l->add,a->add); if(a->r) a->r->add=g(a->r->add,a->add); a->val=f(a->val,a->add); a->add=e; } T top(Node *a){ return f(a->val,a->add); } Node* push(T v){ return new Node(v,e); } Node* meld(Node *a,Node *b){ if(!a) return b; if(!b) return a; if(c(top(a),top(b))) swap(a,b); eval(a); a->r=meld(a->r,b); swap(a->l,a->r); return a; } Node* pop(Node* a){ eval(a); auto res=meld(a->l,a->r); free(a); return res; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); using Heap=SkewHeap<int, int>; Heap::F f=[](int a,int b){return a+b;}; Heap::G g=[](int a,int b){return a+b;}; Heap::C c=[](int a,int b){return a<b;}; Heap heap(f,g,c,0); auto base=heap.push(0); string s; while(cin>>s,s!="end"){ int x; if(s=="insert"){ cin>>x; auto v=heap.push(x); base=heap.meld(base,v); } if(s=="extract"){ x=heap.top(base); base=heap.pop(base); cout<<x<<endl; } } return 0; }
0
38,669,623
#include <bits/stdc++.h> using namespace std; #define long long int signed main(){ int a,b,c,k; cin>>a>>b>>c>>k; while(k--){ if(b<=a)b*=2; else if(c<=b)c*=2; } if(b>a&&c>b)cout<<"Yes"; else cout<<"No"; }
#include<bits/stdc++.h> using namespace std; #define int long long int int32_t main() { int n; cin>>n; vector<pair<int,int>> red(n),blue(n); for(int i=0;i<n;i++) cin>>red[i].second>>red[i].first; for(int i=0;i<n;i++) cin>>blue[i].first>>blue[i].second; sort(red.begin(),red.end()); sort(blue.begin(),blue.end()); int ans=0; for(int i=0;i<n;i++) { for(int j=n-1;j>=0;j--) { if(!(blue[i].first>red[j].second && blue[i].second>red[j].first))continue; ans++; red[j].first=INT_MAX; red[j].second=INT_MAX; break; } } cout<<ans<<endl; }
0
10,301,801
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array #define vi vector<int> #define INF 1000000000 int main() { ios::sync_with_stdio(0); cin.tie(0); int S, W; cin >> S >> W; string safety = W >= S ? "unsafe" : "safe"; cout << safety << endl; return 0; }
#include<bits/stdc++.h> using namespace std; char a; int kotae[26],b; int main(void){ while(1){ if(scanf(" %c",&a) == EOF)break; for(int j=0;j<26;j++){ if(a=='a'+j ||a=='A'+j){ kotae[j]+=1; } } } for(int i=0;i<26;i++){ cout<<(char)('a'+i)<<" : "<<kotae[i]<<endl; } }
0
99,350,594
#include <iostream> #include <vector> using namespace std; int gcd(int x, int y){ if(x < y) swap(x, y); if(x % y == 0) return y; return gcd(y, x % y); } int main(){ int N; cin >> N; vector<int> A(N); for(int i = 0; i < N; i++) cin >> A[i]; int g = A[0]; for(int i = 1; i < N; i++){ g = gcd(g, A[i]); } cout << g << endl; }
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize (2) #pragma G++ optimize (2) #include <bits/stdc++.h> #include <algorithm> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define wuyt main typedef long long ll; #define HEAP(...) priority_queue<__VA_ARGS__ > #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > template<class T> inline T min(T& x, const T& y) { return x > y ? y : x; } template<class T> inline T max(T& x, const T& y) { return x < y ? y : x; } ll read() { ll c = getchar(), Nig = 1, x = 0; while (!isdigit(c) && c != '-')c = getchar(); if (c == '-')Nig = -1, c = getchar(); while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar(); return Nig * x; } #define read read() const ll inf = 1e15; const int maxn = 2e5 + 7; const int mod = 1e9 + 7; #define start int wuyt() #define end return 0 #define N 1005 map<ll, ll>mp; int n; ll m; start{ n = read,m = read; ll num,sum = 0,ans = 0; mp.clear(); mp[0]++; for (int i = 1; i <= n; i++) { num = read; sum += num; sum %= m; ans += mp[sum]; mp[sum]++; } printf("%lld\n",ans); end; }
0
22,365,465
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) typedef long long ll; typedef pair<ll,ll> P; int main(){ ll w, h; cin >> w >> h; ll p, q; priority_queue<P,vector<P>,greater<P>> que; rep(i,w) { cin >> p; que.push(P(p,0)); } rep(i,h) { cin >> q; que.push(P(q,1)); } ll ans = 0; ll n = 0; p = w + 1; q = h + 1; while(!que.empty()){ P a = que.top(); que.pop(); if(a.second == 0) { ans += a.first*q; p--; } else { ans += a.first*p; q--; } } cout << ans << endl; return 0; }
#pragma GCC optimize ("-O2") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define ll long long #define ld long double #define pb push_back #define mp make_pair #define pii pair<int,int> #define all(a) (a).begin(),(a).end() #define clz(a) __builtin_clz(a) #define ctz(a) __builtin_ctz(a) #define popc(a) __builtin_popcount(a) #define rep(i,a,b) for(int i=a;i<b;i++) #define rfor(i,a,b) for(int i=a; i>=b; i--) #define debug(x) cerr << #x << " = " << x << endl; #define F first #define S second #define endl '\n' #define SIZE 1000005 #define deci(n) cout<<fixed<<setprecision(n) #define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update> const ld PI = acos(-1.0); const int INF = 0x3f3f3f3f; const ll lul2 = 998244353; const ll lul = 1000000007; void mod(ll &x) { if(x>=lul) x-=lul; if(x<0) x+=lul; } ll _gcd(ll a, ll b) { if(b == 0) return a; return _gcd(b,a%b); } ll expo(ll n, ll p) { if(p == 0) return 1; ll x = expo((n*n)%lul, p/2)%lul; if(p&1) return (x*n)%lul; return x; } ll ans = 0, sum = 0; unordered_map<ll,ll> ma; void solve() { ll n,m; cin>>n>>m; rep(i,0,n) { ll x; cin>>x; sum=(sum+x)%m; ma[sum]++; } for(auto i:ma) { if(i.F == 0) ans+=(i.S*i.S+i.S)/2; else ans+=(i.S*i.S-i.S)/2; } cout<<ans; } int main() { FAST; int t; t=1; rep(i,1,t+1){ solve(); } return 0; }
0
57,000,441
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; const int INF=1e9; const int MOD=1e9+7; int main(){ int N; cin >> N; int p[N]; for(int i=0;i<N;i++){ cin >> p[i]; p[i]--; } int a[N]; int b[N]; int r[N]; for(int i=0;i<N;i++){ r[p[i]]=i+1; } for(int i=0;i<N;i++){ a[i]=N*(i+1); b[i]=N*(N-i-1)+r[i]; } for(int i=0;i<N;i++){ cout << a[i] << " "; } cout << endl; for(int i=0;i<N;i++){ cout << b[i] << " "; } cout << endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vll = vector<long long>; using vp = vector<pair<int, int>>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using vvll = vector<vector<long long>>; 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 (b<a) {a=b; return 1;} return 0;} struct Sieve { int n; vector<int> f, primes; Sieve(int n=1) : n(n), f(n+1) { f[0] = f[1] = -1; for (long long i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (long long j = i*i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x;} vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<pair<int, int>> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; Sieve sieve(n); map<int, int> mp; for (int i = 1; i <= n; ++i) { auto f = sieve.factor(i); for (auto p : f) { mp[p.fi] += p.se; } } vi cnt(100, 0); for (auto p : mp) { cnt[p.se]++; } int over2 = 0; int over4 = 0; int over14 = 0; int over24 = 0; int over74 = 0; rep(i, 100) { if (i >= 2) over2 += cnt[i]; if (i >= 4) over4 += cnt[i]; if (i >= 14) over14 += cnt[i]; if (i >= 24) over24 += cnt[i]; if (i >= 74) over74 += cnt[i]; } int ans = over24 * (over2 - 1) + over14 * (over4 - 1) + (over2 - 2) * over4 * (over4 - 1) / 2 + over74; cout << ans << endl; }
0
87,577,059
#include<bits/stdc++.h> #define ll long long #define ld long double #define all(v) v.begin(),v.end() #define pb push_back #define rep(p,a,b) for(ll p=a ; p<b ; p++) #define F first #define S second using namespace std; ll lcm(ll a,ll b) { return a*b/__gcd(a,b); } int main() { ll t,i,j,k,ans,n,m; t=1; while(t--) { cin>>n>>m; ll lc = 1; vector<ll> v(n); rep(p,0,n){cin>>v[p];lc = lcm(lc,v[p]);} ll val = ((v[0] ^ (v[0]-1))+1)/2; bool flag=true; rep(p,1,n) { if(val != ((v[p] ^ (v[p]-1))+1)/2){flag=false;break;} } if(flag) { lc/=2; ans = (m/lc) - (m/(2*lc)); cout<<ans; }else cout<<"0"; } return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846; typedef long long ll; const double EPS = 1e-9; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<ll, ll> P; const ll INF = 10e17; #define cmin(x, y) x = min(x, y) #define cmax(x, y) x = max(x, y) #define ret() return 0; double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; } std::istream &operator>>(std::istream &in, set<int> &o) { int a; in >> a; o.insert(a); return in; } std::istream &operator>>(std::istream &in, queue<int> &o) { ll a; in >> a; o.push(a); return in; } bool contain(set<int> &s, int a) { return s.find(a) != s.end(); } typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK; bool is_kaibun(vector<int> &hs, int i, int j) { int k = hs[j] ^(i == 0 ? 0 : hs[i - 1]); int f = __builtin_popcount(k); return f <= 1; } int solve2(string s) { int n = s.size(); vector<int> hs(n, 0); rep(i, n) { if (i == 0) { char c = s[i]; int j = c - 'a'; int next = 1 << j; hs[0] = next; } else { char c = s[i]; int j = c - 'a'; int next = hs[i - 1] ^(1 << j); hs[i] = next; } } vector<int> dp(n, -1); auto set = [&](int i, int k) { if (dp[i] == -1) dp[i] = k; else cmin(dp[i], k); }; for (int j = 0; j < n; j++) { for (int i = 0; i <= j; i++) { if (is_kaibun(hs, i, j)) { set(j, (i == 0 ? 0 : dp[i - 1]) + 1); } } } return dp[n - 1]; } int solve(string s) { int n = s.size(); vector<int> hs(n, 0); rep(i, n) { if (i == 0) { char c = s[i]; int j = c - 'a'; int next = 1 << j; hs[0] = next; } else { char c = s[i]; int j = c - 'a'; int next = hs[i - 1] ^(1 << j); hs[i] = next; } } vector<int> dp(n, -1); map<int, int> cache; cache[0] = -1; rep(i, n) if (cache.find(hs[i]) == cache.end()) cache[hs[i]] = i; auto set = [&](int i, int k) { if (dp[i] == -1) dp[i] = k; else cmin(dp[i], k); }; auto get = [&](int i) { if (i == -1) return 0; return dp[i]; }; for (int i = 0; i < n; i++) { { dp[i] = get(i - 1) + 1; int current = hs[i]; int j = cache[current]; set(i, get(j) + 1); } rep(a, 26) { int current = (1 << a) ^hs[i]; if (cache.find(current) == cache.end() || cache[current] >= i) continue; int j = cache[current]; set(i, get(j) + 1); } if (dp[i] < dp[cache[hs[i]]]) { dp[cache[hs[i]]] = dp[i]; } } return dp[n - 1]; } int a() { queue<string> q; q.push(""); while (!q.empty()) { string s = q.front(); q.pop(); if (!s.empty()) { int sa = solve(s); int sb = solve2(s); if (sa != sb) { cout << s << endl; return 0; } } rep(i, 5) { int c = 'a' + i; string t = s; t.push_back(c); q.push(t); } } } int main() { string s; cin >> s; cout << solve(s) << endl; }
0
42,435,312
#include <bits/stdc++.h> using namespace std; int main() { int A, B, sum, x; cin >> A >> B; sum = 0; x = A; for(int i = 0; i <= B - A; i++ ){ int a, b, c, d; a = x / 10000; b = (x % 10000) / 1000; c = (x % 100) / 10; d = x % 10; if(a == d && b == c ){ sum = sum + 1; } x = x + 1; } cout << sum << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <climits> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long long LL; int main() { int N; cin >> N; int vmin = 1e9; for (int c6 = 0; c6 <= N/6; c6++) { for (int c9 = 0; c9 <= N/9; c9++) { int x = N - c6 * 6 - c9 * 9; if (x < 0) continue; int a = c6; int y = 0; while (a > 0) { y += a % 6; a /= 6; } int b = c9; int z = 0; while (b > 0) { z += b % 9; b /= 9; } vmin = min(vmin, x + y + z); } } cout << vmin << endl; }
0
89,543,334
#include <bits/stdc++.h> #define rep(i,n)for(long long i=0;i<(long long)(n);++i) #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; 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 ll MOD=1e9+7; const ll INF=1e18; const int MAX=510000; const double pi=acos(-1); int dx[8] = {1,0,-1,0,1,1,-1,-1}; int dy[8] = {0,1,0,-1,-1,1,1,-1}; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll m; cin >> m; vector<ll>b(n); ll bi=1; rep(i,n){ cin >> b[i]; b[i]/=2; bi=lcm(bi,b[i]); } bool ok = true; ll cnt=0; rep(i,n){ ll num=0; while(b[i]%2==0){ num++; b[i]/=2; } if(i==0){ cnt=num; } else{ if(cnt!=num)ok=false; } } if(ok) cout << (m/bi+1)/2 << endl; else cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define rep(i, n) for(int i = 0; i < n; i++) #define REP(i, a, b) for(int i = a; i < b; i++) #define all(x) x.begin(), x.end() #define fi first #define se second #define pb push_back #define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl #define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1<<30) - 1; const ll LINF = (1LL<<60) - 1; void solve() { int h, w, m; cin >> h >> w >> m; vector<int> H[h + 1], W[w + 1]; int hmax = 0, wmax = 0; map<pii, bool> mp; while(m--) { int i, j; cin >> i >> j; mp[pii(i, j)] = 1; H[i].pb(j); chmax(hmax, (int) H[i].size()); W[j].pb(i); chmax(wmax, (int) W[j].size()); } vector<int> HM, WM; rep(i, h + 1) if (H[i].size() == hmax) HM.pb(i); rep(i, w + 1) if (W[i].size() == wmax) WM.pb(i); int ans = hmax + wmax - 1; for(auto i : HM) for(auto j : WM) { if (!mp[pii(i, j)]) { ans++; cout << ans << endl; return; } } cout << ans << endl; } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
0
60,699,242
#include <bits/stdc++.h> using namespace std; int main(){ int64_t a, b, c, d; cin >> a >> b >> c >> d; int64_t ans = b - a + 1; int64_t l = lcm(c, d); ans -= (b / c - a / c + (a % c == 0)); ans -= (b / d - a / d + (a % d == 0)); ans += (b / l - a / l + (a % l == 0)); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define MOD 1000000007 #define ALL(obj) (obj).begin(),(obj).end() 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; bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){ return firstElof.first < secondElof.first; } bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){ return firstElof.second < secondElof.second; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; struct edge{ ll from,to,cost; }; typedef vector<vector<edge> > G; ll gcd(ll a,ll b){ if (a%b==0)return(b); else return(gcd(b,a%b)); } ll x[1010000]; ll fib(ll b){ if (b==1)return 0; if (b==2)return 0; if (b==3)return 1; if (x[b]!=-1)return x[b]; x[b]=(fib(b-1)+fib(b-2)+fib(b-3))%10007; return x[b]; } int main() { ll n; cin >> n; ll a[n]; for (ll i=0;i<n;i++)cin >> a[i]; sort(a,a+n); ll ans=1,c=0; for (ll i=1;i<n;i++){ if (a[i-1]!=a[i])ans++; else{ c++; } } if (c%2)ans--; cout << ans << endl; return 0; }
0
60,037,459
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define reps(i,n) for(int i=1;i<(int)(n);i++) typedef long long ll; using namespace std; int main() { string s1,s2,s3; cin>>s1>>s2>>s3; cout<<char('A'+(s1[0]-'a'))<<char('A'+(s2[0]-'a'))<<char('A'+(s3[0]-'a'))<<endl; return 0; }
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; #define double long double #define int long long #define pb push_back #define pii pair<int,int> #define vi vector<int> #define vii vector<pii> #define mi map<int,int> #define mii map<pii,int> #define all(a) (a).begin(),(a).end() #define sz(x) (int)x.size() #define endl "\n" #define repp(i,a,b) for(int i=a;i<b;i++) #define rep(i,a,b) for(int i=a;i<=b;i++) #define brep(i,a,b) for(int i=a;i>=b;i--) #define deb1(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl #define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl; #define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl; #define PI 3.1415926535897932384626 #define F first #define S second #define clr(x,y) memset(x, y, sizeof(x)) #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int N= 5000 + 5; const int MOD=1e9 + 7; int val[N]; int a[N]; int n,k; int solve(int idx) { int mp[N]; clr(mp,0); int cost = 0; int len = 0; vi v; while(mp[idx]==0) { mp[idx]=1; idx = a[idx]; cost += val[idx]; v.pb(val[idx]); len++; } int ans = 0; int times = k/len; int left = k%len; int flag = 0; if(cost>0) { flag = 1; ans = cost*times; } if(flag==1) { int cur = 0; int sum = 0; int temp = ans; while(left>0) { idx = a[idx]; sum += val[idx]; cur = max(cur,sum); left--; } ans += cur; sum = 0; cur = INT_MAX; for(int j=v.size()-1;j>=0;j--) { sum += v[j]; cur = min(sum,cur); } if(cur<0) temp -= cur; ans = max(ans,temp); } else { clr(mp,0); int kk = k; int cur = INT_MIN; int sum = 0; while(kk>0 && mp[idx]==0) { mp[idx] = 1; idx = a[idx]; sum += val[idx]; cur = max(cur,sum); kk--; } ans += cur; } return ans; } int32_t main() { IOS; int T=1; std::cout << std::fixed << std::setprecision(12); while(T--) { cin >> n >> k; rep(i,1,n) cin >> a[i]; rep(i,1,n) cin >> val[i]; int ans = INT_MIN; rep(i,1,n) ans = max(ans,solve(i)); cout << ans; } }
0
45,629,212
#include <bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using bll = boost::multiprecision::cpp_int; using bdouble = boost::multiprecision::cpp_dec_float_100; #include <boost/math/tools/minima.hpp> #endif #ifdef LOCAL_DEV void debug_impl() { std::cerr << std::endl; } template<typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head << (sizeof...(tail) ? "," : ""); debug_impl(tail...); } #define debug(...) { std::cerr << "(" << #__VA_ARGS__ << ") ="; debug_impl(__VA_ARGS__);} #else #define debug(...) {} #endif #ifdef LOCAL_TEST #define BOOST_STACKTRACE_USE_ADDR2LINE #define BOOST_STACKTRACE_ADDR2LINE_LOCATION /usr/local/opt/binutils/bin/addr2line #define _GNU_SOURCE #include <boost/stacktrace.hpp> namespace std { template<typename T> class dvector : public std::vector<T> { public: dvector() : std::vector<T>() {} explicit dvector(size_t n, const T& value = T()) : std::vector<T>(n, value) {} dvector(const std::vector<T>& v) : std::vector<T>(v) {} dvector(const std::initializer_list<T> il) : std::vector<T>(il) {} dvector(const typename std::vector<T>::iterator first, const typename std::vector<T>::iterator last) : std::vector<T>(first, last) {} dvector(const std::string::iterator first, const std::string::iterator last) : std::vector<T>(first, last) {} T& operator[](size_t n) { try { return this->at(n); } catch (const std::exception& e) { std::cerr << boost::stacktrace::stacktrace() << std::endl; return this->at(n); } } const T& operator[](size_t n) const { try { return this->at(n); } catch (const std::exception& e) { std::cerr << boost::stacktrace::stacktrace() << std::endl; return this->at(n); } } }; } class dbool { private: bool boolvalue; public: dbool() : boolvalue(false) {} dbool(bool b) : boolvalue(b) {} dbool(const dbool &b) : boolvalue(b.boolvalue) {} operator bool&() { return boolvalue; } operator const bool&() const { return boolvalue; } }; template<typename T> std::ostream& operator<<(std::ostream& s, const dvector<T>& v) { for (int i = 0, len = v.size(); i < len; ++i){ s << v[i]; if (i < len - 1) s << "\t"; } return s; } template<typename T> std::ostream& operator<<(std::ostream& s, const dvector< dvector<T> >& vv) { for (int i = 0, len = vv.size(); i < len; ++i){ s << vv[i] << std::endl; } return s; } template<typename T> std::ostream& operator<<(std::ostream& s, const std::set<T>& se) { s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; } template<typename T> std::ostream& operator<<(std::ostream& s, const std::multiset<T>& se) { s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; } template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::map<T1, T2>& m) { s << "{" << std::endl; for (auto itr = m.begin(); itr != m.end(); ++itr){ s << "\t" << (*itr).first << " : " << (*itr).second << std::endl; } s << "}"; return s; } template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::pair<T1, T2>& p) { return s << "(" << p.first << ", " << p.second << ")"; } #define vector dvector #define bool dbool class SIGFPE_exception : std::exception {}; class SIGSEGV_exception : std::exception {}; void catch_SIGFPE(int e) { std::cerr << boost::stacktrace::stacktrace() << std::endl; throw SIGFPE_exception(); } void catch_SIGSEGV(int e) { std::cerr << boost::stacktrace::stacktrace() << std::endl; throw SIGSEGV_exception(); } signed convertedmain(); signed main() { signal(SIGFPE, catch_SIGFPE); signal(SIGSEGV, catch_SIGSEGV); return convertedmain(); } #define main() convertedmain() #endif using ll = long long; constexpr int INF = 1e9; constexpr ll MOD = (ll)1e9 + 7; constexpr double EPS = 1e-9; constexpr ll dx[4] = {1LL, 0LL, -1LL, 0LL}; constexpr ll dy[4] = {0LL, 1LL, 0LL, -1LL}; constexpr ll dx8[8] = {1LL, 0LL, -1LL, 0LL, 1LL, 1LL, -1LL, -1LL}; constexpr ll dy8[8] = {0LL, 1LL, 0LL, -1LL, 1LL, -1LL, 1LL, -1LL}; #define rep(i, n) for(ll i=0, i##_length=(n); i< i##_length; ++i) #define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i) #define rrep(i, n) for(ll i=(n)-1; i>=0; --i) #define rrepeq(i, n) for(ll i=(n) ; i>=1; --i) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() void p() { std::cout << '\n'; } template<typename Head, typename... Tail> void p(Head head, Tail... tail) { std::cout << head << (sizeof...(tail) ? " " : ""); p(tail...); } template<typename T> inline void pv(std::vector<T> &v) { for(ll i=0, N=v.size(); i<N; i++) std::cout << v[i] << " \n"[i==N-1]; } template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; } template<typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; } template<typename T> inline bool chmax(T &a, T b) { return a < b && (a = b, true); } template<typename T> inline bool chmin(T &a, T b) { return a > b && (a = b, true); } template<typename T> inline void uniq(std::vector<T> &v) { v.erase(unique(v.begin(), v.end()), v.end()); } inline ll up(ll bit, ll i) { return bit | (1<<i); } inline ll down(ll bit, ll i) { return bit & ~(1<<i); } inline ll inverse(ll bit, ll i) { return bit ^ (1<<i); } inline bool isup(ll bit, ll i) { return (bit & (1<<i)); } inline bool isdown(ll bit, ll i) { return !(bit & (1<<i)); } void solve() { string S; cin>>S; ll N=S.size(); vector<ll> hash(N,0); ll t=0; rep(i,N){ t=inverse(t,S[i]-'a'); hash[i]=t; } if(__builtin_popcount(hash.back())<=1){ p(1);return; } vector<int> dp(1<<26,INF); dp[0]=0; rep(i,N){ int minval=INF; ll x,invhash; x=0; invhash=x^hash[i]; chmin(minval,dp[invhash]+1); rep(j,26){ x=1<<j; invhash=x^hash[i]; chmin(minval,dp[invhash]+1); } chmin(dp[hash[i]],minval); } p(dp[hash[N-1]]); } signed main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define INF (INT_MAX / 2) #define INFL (INT64_MAX /2) typedef pair<int, int> P; int main() { int n,m; cin >> n >> m; vector<int> a(m+1),b(m+1); rep(i,m) { cin >> a[i] >> b[i]; } vector<vector<int>> possible(n+1); rep(i,m) { possible[a[i]].push_back(b[i]); possible[b[i]].push_back(a[i]); } vector<int> d(n+1,INF), ans(n+1); d[1] = 0; queue<int> que; que.push(1); while (!que.empty()) { int a = que.front(); que.pop(); rep(i, possible[a].size()) { if (d[possible[a][i]] > d[a] + 1) { d[possible[a][i]] = d[a] + 1; ans[possible[a][i]] = a; que.push(possible[a][i]); } } } bool bo = false; rep(i,n) { if (d[i+1] == INF) { cout << "No" << endl; break; } bo = true; } if (bo) { cout << "Yes" << endl; rep (i,n-1) { cout << ans[i+2] << endl; } } }
0
32,848,676
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using namespace std; template <typename T> using vec = std::vector<T>; int main() { ll N, K; cin >> N >> K; vec<ll> P(N); rep(i, N) cin >> P[i], --P[i]; vec<ll> C(N); rep(i, N) cin >> C[i]; ll ans = -1e18; rep(i, N) { vec<ll> cycle; ll now = i; ll sm = 0; while (true) { sm += C[now]; cycle.push_back(sm); now = P[now]; if (now == i) break; } ll tmp = -1e18; ll sz = cycle.size(); rep(j, sz) { if(K<j+1) break; ll roop = (K - j - 1) / sz; if (sm > 0) { tmp = sm * roop + cycle[j]; } else { tmp = cycle[j]; } ans = max(ans, tmp); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; void solve() { int row,col,mod=1e9+7; cin>>row>>col; string arr[row]; for(int i=0;i<row;i++) { cin>>arr[i]; } vector<vector<long long int>>dp(row,vector<long long int>(col,0)); dp[0][0]=1; for(int i=1;i<col;i++) if(arr[0][i]!='#') dp[0][i]=dp[0][i-1]; for(int i=1;i<row;i++) if(arr[i][0]!='#') dp[i][0]=dp[i-1][0]; for(int i=1;i<row;i++) { for(int j=1;j<arr[i].size();j++) { if(arr[i][j]!='#') dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod; } } cout<<dp[row-1][col-1]; } int main() { int test; test=1; while(test--) { solve(); } return 0; }
0
39,578,853
#include <bits/stdc++.h> #define BIT(n) (1LL << (n)) #define REP(i, n) for (int i = 0; i < n; i++) #define REPB(i, n) for (int i = 0; i < BIT(n); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n) #define FORS(i, m, n) for (int i = m; i <= n; i++) #define DEBUG(x) cerr << #x << ": " << x << "\n" #define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n" #define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n" #define PRINTALL(V) \ for (auto v : (V)) { \ cerr << v << " "; \ } \ cerr << "\n"; #define ALL(v) v.begin(), v.end() #define fst first #define snd second #define mp make_pair #define pb push_back #define epb emplace_back #define int long long #define pint pair<int, int> #define ld long double using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <class T> using vec = std::vector<T>; template <class T> void print(const T &x) { cout << x << "\n"; } const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF; const double EPS = 1e-10, PI = acos(-1.0); const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; signed main() { cin.tie(0), ios::sync_with_stdio(false); cout << fixed << setprecision(10); int N, X; cin >> N >> X; int ans = N; int a = max(X, N - X); int b = min(X, N - X); while (1) { if (a % b == 0) { ans += b * (2 * (a / b) - 1); print(ans); return 0; } else { ans += b * 2 * (a / b); int tmp = a % b; a = b; b = tmp; } } }
#include <iostream> #include <algorithm> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <queue> #include <cmath> #include <bitset> #include <complex> #include <functional> #include <numeric> #define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for(int i=(a);i<(n);++i) #define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i) #define REP(i, n) for(int i=0;i<int(n);++i) #define RREP(i, n) for(int i=int(n)-1;i>=0;--i) #define IN(a, x, b) (a<=x && x<b) #define OUT(a, x, b) (x<a || b<=x) template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; } template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; } #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const int MOD = 1000000007; const int INF = 1e18; const double PI = acos(-1); using namespace std; signed main() { int N, M; cin >> N >> M; vector<int> u(M), v(M), d(M); vector<vector<int>> dist(N, vector<int>(N, INF)); REP(i, N) dist[i][i] = 0; REP(i, M){ cin >> u[i] >> v[i] >> d[i]; u[i]--; v[i]--; dist[u[i]][v[i]] = d[i]; dist[v[i]][u[i]] = d[i]; } REP(k, N) REP(i, N) REP(j, N){ chmin(dist[i][j], dist[i][k]+dist[k][j]); } int ans = 0; REP(k, M){ bool flag = false; REP(i, N) REP(j, N){ if(dist[i][j] == dist[i][u[k]]+d[k]+dist[v[k]][j]) flag = true; } if(flag) ans++; } cout << M-ans << endl; return 0; }
0
42,029,785
#include<bits/stdc++.h> using namespace std; using i64 = long long; using u64 = unsigned long long; const int mod = (int)1e9+7; void __print() {cerr << "]\n";} template<typename T, typename... V> void __print(T t, V... v) { cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);} #define dbg(x...) cerr << "[" << #x << "] = ["; __print(x); int n, q; vector<int> adj[210000]; i64 incr_val[210000]; int visited[210000]; i64 ans[210000]; void dfs(int u, i64 par_val) { if(visited[u]) return; visited[u] = true; i64 val = par_val + incr_val[u]; ans[u] = val; for(int to : adj[u]) { dfs(to, val); } } int main() { scanf("%d%d", &n, &q); for(int i = 0; i < n-1; i++) { int x, y; scanf("%d%d", &x, &y); adj[x].push_back(y); adj[y].push_back(x); } while(q--) { int x; i64 y; scanf("%d%lld", &x, &y); incr_val[x] += y; } dfs(1, 0); for(int i = 1; i <= n; i++) printf("%lld ", ans[i]); puts(""); }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define PI 3.1415926535897932384626433832795028841971693993 using ll = long long; const int INF = 1e9; const int MOD = 1e9+7; int main(){ int n,ans=0; string s; cin>>n>>s; ll a=0,b=0,c=0; rep(i,n){ if(s[i]=='R') a++; else if(s[i]=='G') b++; else c++; } ll sum=a*b*c; rep(i,n){ for(int j=i+1;j<n;j++){ int k=2*j-i; if(n<=k) continue; if(i>=j||j>=k||i>=k) continue; if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i]) sum--; } } cout<<sum<<endl; }
0
40,516,171
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main(){ string s; cin >>s; int w; cin >>w; string t = " "; for(int i = 0; i < s.size(); i+=w){ t += s[i]; } cout << t << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,j,n) for(int i=(j);i<(n);i++) #define per(i,n,j) for(int i=(n);i>=(j);i--) using ll=long long; using namespace std; 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 ll INF=1LL<<60; string s; int main(){ cin>>s; string ans=""; rep(i,0,s.size()){ if(ans!=""){ if(s[i]=='0') ans=ans+"0"; else if(s[i]=='1') ans=ans+"1"; else ans.pop_back(); } else{ if(s[i]=='0') ans=ans+"0"; else if(s[i]=='1') ans=ans+"1"; } } cout<<ans<<"\n"; return 0; }
0
58,835,917
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int main() { string S; cin >> S; set<char> st; rep(i, S.size()) st.insert(S[i]); for (int i = 0; i < 26; i++) { if (!st.erase((char)('a' + i))) { cout << (char)('a' + i) << endl; return 0; } } cout << "None" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <boost/multiprecision/cpp_int.hpp> using boost::multiprecision::cpp_int; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vs = vector<string>; using vld = vector<ld>; using vvld = vector<vld>; typedef pair<ll, ll> P; #define bit(n) (1LL << (n)) #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < n; i++) #define REP(i, n) for (ll i = 1; i < n; i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++) template <class T> inline void chmax(T& a, T b) { a = std::max(a, b); } template <class T> inline void chmin(T& a, T b) { a = std::min(a, b); } #define mod (ll)(1e9 + 7) const long long INF = 1LL << 60; signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll n, m; cin >> n >> m; vvll g(n); rep(i, m) { ll a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } rep(i, n) sort(all(g[i])); vll v; rep(i, n) v.push_back(i); ll ans = 0; do { bool ok = true; rep(i, n - 1) { if (!binary_search(all(g[v[i]]), v[i + 1])) { ok = false; break; } } if (ok) ans++; } while (next_permutation(v.begin() + 1, v.end())); cout << ans << endl; return 0; }
0
78,415,011
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, ans, L1, L0; cin >> N; L1=1; L0=2; ans=1; for(int i=2; i<=N; i++){ ans = L1 + L0; L0=L1; L1=ans; } cout << ans << endl; }
#include <bits/stdc++.h> #define ub(b,val) upper_bound(b+1,b+n+1,val)-b #define ll long long using namespace std; const int N = 1e5 + 123, MAXN = 1e9; ll n, m, v, p; ll a[N], b[N], ans, c[N]; bool check (int in) { ll k = 0, id = (n - p + 1); if (b[in] + m < b[id])return 0; k += (p - 1) * 1ll * m + (in - 1) * 1ll * m; for (int i = in;i <= id;i ++) { k += m + b[in] - b[i]; } return (k >= m * v); } int main () { ios_base::sync_with_stdio (0), cin.tie (0), cout.tie (0); cin >> n >> m >> v >> p; for (int i = 1;i <= n;i ++) { cin >> a[i]; b[i] = a[i]; }sort (b + 1, b + n + 1); int l = 1, r = n, id = -1; while (l <= r) { int mid = (l + r) / 2; if (check (mid)) { r = mid - 1; id = mid; }else { l = mid + 1; } } cout << (id == -1 ? 0 : (n - id + 1)); }
0
80,588,677
#include <iostream> using namespace std; int main(){ int a; for(int i=1 ;;i++){ cin>>a; if (a==0){ return 0; } cout << "Case "<< i <<":"<<" "<<a<< endl; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); string s;cin>>s; for(int i=0;i<s.size();i++) { if(s[i]=='B') { if(i>0) { s.erase(i-1, 2); i-=2; } else { s.erase(i, 1); i--; } } } cout<<s<<"\n"; }
0
62,041,246
#include <iostream> #include <string> #include <vector> #include <iomanip> #define rep(i, n) for (int i = 0; i < (n); ++i) using std::cin; using std::cout; using std::endl; using std::string; using std::vector; int main() { long double T, X; cin >> T >> X; cout << std::fixed << std::setprecision(7) << T / X << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i=0; i<(int)(n); i++) using ll = long long; int main() { int n; cin >> n; vector<int> a(n),b(n); rep(i,n) { cin >> a[i]; b[i] = a[i]; } sort(b.begin(), b.end()); for (int i = 0; i < n; i++) { bool f = false; for (int j = n-1; j >= 0; j--) { if (f || a[i] != b[j]) { cout << b[j] << endl; break; } else if (!f) { f = true; } } } return 0; }
0
27,420,371
#include<bits/stdc++.h> using namespace std; int main(){ long long k,a,b; cin >> k >> a >> b; if(b-a>2){ if(k<=a)cout << k+1 << endl; else{ cout << b + (b-a)*((k-a-1)/2) + (k-a+1)%2 << endl; } } else{cout << k+1 << endl;} return 0; }
#include <iostream> #include <sstream> #include <stack> #include <iomanip> #include <string> #include <algorithm> #include <functional> #include <cstdlib> #include <map> #include <set> #include <vector> #include <utility> #include <queue> #include <cmath> #define BEGIN(x) x.begin() #define END(x) x.end() #define ALL(x) BEGIN(x), END(x) #define PAIR make_pair #define VEC(type) vector<type > #define FOR(i, A, B) for(auto i = (A);i != (B); i++) #define FORD(i, A, B) for(auto i = (A);i != (B); i--) #define READRANGE(begin, end) FOR(it, begin, end) cin >> *it #define READVEC(V) READRANGE(BEGIN(V), END(V)) using namespace std; typedef long long lint; typedef pair<int, int> Pii; typedef pair<int, lint> Pil; typedef pair<lint, lint> Pll; typedef pair<lint, int> Pli; void io_init() { ios_base::sync_with_stdio(false); cin.tie(NULL); }; int main(int argc, char **argv) { io_init(); int N; double total = 0; const double btc_to_jpy = 380000; cin >> N; FOR(i, 0, N) { double val; string type; cin >> val >> type; if (type == "JPY") total += val; else total += val * btc_to_jpy; } cout << fixed << setprecision(6) << total << endl; return 0; };
0
15,113,225
#include <bits/stdc++.h> using namespace std; using LL = long long; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) const int MAX = 101010; LL A[MAX], B[MAX], ACUM[MAX]; int main(){ int N; scanf("%d", &N); rep(i, N + 1) scanf("%lld", &A[i]); rep(i, 101010) ACUM[i + 1] = ACUM[i] + A[i]; bool ok = true; B[0] = 1 - A[0]; if(B[0] < 0) ok = false; repx(i, 1, N + 1){ B[i] = min(2 * B[i - 1] - A[i], ACUM[N + 1] - ACUM[i + 1]); if(A[i] + B[i] < B[i - 1] || A[i] + B[i] > 2 * B[i - 1] || B[i] < 0){ ok = false; break; } } LL ans = 0; rep(i, N + 1) ans += (A[i] + B[i]); printf("%lld\n", ok ? ans : -1); return 0; }
#include<iostream> #include<stdio.h> #include<vector> #include<float.h> #include<iomanip> #include<algorithm> #include<string> #include<cstring> #include<math.h> #include<cmath> #include<sstream> #include<set> #include<map> #include<queue> #include <cassert> #include <cmath> #include<cstdint> #define INF 1e9 #define rep(i,n)for(int i=0;(i)<(int)(n);i++) #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++) #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i; #define vec(type,n) vector<type>(n) #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n)) #define ALL(a) (a).begin(),(a).end() using namespace std; using ll = long long; using Graph = vector<vector<int>>; using P = pair<int,int>; vector<int>bitSearch(int bit,int n){ vector<int>S; rep(i,n)if(bit&(1<<i))S.push_back(i); return S; } int d[5*100000+1]; int main(){ string s;cin>>s; string t,u,v; ll k;cin>>k; int n = s.size(); vector<bool>f(n,false); char c = s[0]; set<char>set; rep(i,n){ set.insert(s[i]); } if(set.size()==1){ ll r = s.size()*k/2; cout<<r; return 0; } rep(i,n){ if(c != s[i])break; t.push_back(c); f[i] = true; } reverse(ALL(s)); c = s[0]; rep(i,n){ if(f[n-i-1])break; if(c != s[i])break; v.push_back(c); f[n-i-1] = true; } reverse(ALL(s)); reverse(ALL(v)); rep(i,n){ if(f[i])continue; u.push_back(s[i]); } int ts = t.size()/2; int us = 0; c = u[0]; int cnt = 1; rep(i,u.size()){ if(i==0)continue; if(c != u[i]){ us += cnt/2; c = u[i]; cnt = 1; continue; } cnt++; } us += cnt/2; cnt = 1; c = v[0]; int vs = 0; rep(i,v.size()){ if(i==0)continue; if(c != v[i]){ vs += cnt/2; c = v[i]; cnt = 1; continue; } cnt++; } vs += cnt/2; string vt = v+t; cnt = 1; c = vt[0]; int vts = 0; rep(i,vt.size()){ if(i==0)continue; if(c != vt[i]){ vts += cnt/2; c = vt[i]; cnt = 1; continue; } cnt++; } vts += cnt/2; ll res = ts+us*k+vts*(k-1)+vs; cout<<res; }
0
41,256,611
#include <bits/stdc++.h> using namespace std; #define MAX 100002 #define NIL -1 int n, D[MAX]; struct node{ int p, l, r; }; node T[MAX]; void printTree(){ for(int i=0;i<n;++i){ printf("node %d: parent = %d, depth = %d, ",i,T[i].p,D[i]); if(T[i].p == NIL) printf("root, ["); else{ if(T[i].l == NIL) printf("leaf, ["); else printf("internal node, ["); } for(int j=T[i].l;j != NIL;){ printf("%d",j); j = T[j].r; if(j != NIL){ printf(", "); } else break; } printf("]\n"); } } void recDepth(int pos, int depth){ D[pos] = depth; if(T[pos].l != NIL){ recDepth(T[pos].l,depth+1); } if(T[pos].r != NIL){ recDepth(T[pos].r,depth); } } int main(){ scanf("%d",&n); for(int i=0;i<n;++i){ T[i].l = T[i].p = T[i].r = NIL; D[i] = 0; } int id, num_child, child_id, sib, root; for(int i=0;i<n;++i){ cin >> id >> num_child; for(int j=0;j<num_child;++j){ cin >> child_id; if(j==0) T[id].l = child_id; else T[sib].r = child_id; sib = child_id; T[child_id].p = id; } } for(int i=0;i<n;++i){ if(T[i].p==NIL) root=i; } recDepth(root,0); printTree(); return 0; }
#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<int> a(n+2); int sum = 0; rep(i, n) { cin >> a[i+1]; } rep(i, n+1) { sum += abs(a[i]-a[i+1]); } rep(i, n) { int ans = sum; ans -= abs(a[i+1]-a[i]); ans -= abs(a[i+1]-a[i+2]); ans += abs(a[i]-a[i+2]); cout << ans << endl; } return 0; }
0
6,187,912
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { char c; cin >> c; cout << (char)((int)c + 1); return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int main(){ int n; cin >>n; vector<int> vec(n); for(int i=0;i<n;i++) cin >> vec[i]; if(n%2 == 0){ for(int i=n-1;i>0;i -= 2){ cout << vec[i] << " "; } for(int i=0;i<n-1;i += 2){ cout << vec[i] << " "; }cout << endl; }else { for(int i=n-1;i>=0;i -= 2){ cout << vec[i] << " "; } for(int i=1;i<n;i += 2){ cout << vec[i] << " "; } cout << endl; } }
0
9,938,652
#include <iostream> #include <string> #include <cstring> #include <fstream> #include <random> #include <cmath> #include <iomanip> #include <climits> #include <cstdlib> #include <algorithm> #include <vector> #include <map> #include <deque> #include <map> #include <set> #include <unordered_set> #include <queue> #include <stack> #include <list> #include <unordered_map> #include <bitset> #include <sstream> #include <new> #include <typeinfo> #include <iterator> #include <cassert> using ll = long long; using ull = unsigned long long; constexpr ll mop = 1000000007; constexpr ll mop2 = 998244353; using namespace std; constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN; constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX; int main() { ll numNode, numEdge; cin >> numNode >> numEdge; vector<bool> discovered( numNode + 1, false ); vector<vector<ll>> adjacentList(numNode + 1); for( ll i = 0; i < numEdge; i++ ) { ll a, b; cin >> a >> b; adjacentList[a].push_back( b ); adjacentList[b].push_back( a ); } ll largestGroupSize = 0; for( ll i = 1; i <= numNode; i++ ) { if( discovered[i] == true ) { continue; } ll tmpGroupSize = 0; queue<ll> Q; Q.push( i ); discovered[i] = true; tmpGroupSize++; while( !Q.empty() ) { ll nowNode = Q.front(); Q.pop(); for( auto adjacent : adjacentList[nowNode] ) { if( discovered[adjacent] == false ) { Q.push( adjacent ); discovered[adjacent] = true; tmpGroupSize++; } } } if( tmpGroupSize > largestGroupSize ) { largestGroupSize = tmpGroupSize; } } cout << largestGroupSize << endl; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define INF 1e18 #define EPS 1e-9 #define MOD 1000000007 #define F first #define S second #define all(x) begin(x), end(x) using ll = long long; using ull = unsigned long long; using ui = unsigned int; using ld = long double; #define int long long template<typename T> ostream& operator<<(ostream &stream, vector<T> v) { for (const auto &it : v) stream << it << " "; return stream; } template<typename T1, typename T2> ostream& operator<<(ostream &ostream, pair<T1, T2> p) { ostream << p.first << " " << p.second; return ostream; } template<typename T> void swap(T &a, T &b) { T t = a; a = b; b = t; } void swap(int &a, int &b) { int t = a; a = b; b = t; } int GCD(int a, int b) { if (!b) return a; return GCD(b, a % b); } int LCM(int a, int b) { return (a * b) / GCD(a, b); } int modpow(int x, int n, int m = MOD) { if (n == 0) return 1 % m; long long u = modpow(x, n / 2, m); u = (u * u) % m; if (n % 2 == 1) u = (u * x) % m; return u; } void solve(int tc) { int n, m; cin >> n >> m; char a[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j]; int dp[n + 1][m + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if (!i || !j) { dp[i][j] = 0; continue; } if (i == 1 && j == 1) { dp[i][j] = 1; continue; } dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; if (a[i - 1][j - 1] == '#') dp[i][j] = 0; dp[i][j] %= MOD; } } cout << dp[n][m]; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; for (int i = 1; i <= t; i++) { solve(i); } return 0; }
0
66,342,900
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <iomanip> #include <functional> #include <bitset> #include <limits> #include <cstdio> #include <cmath> #include <cassert> #include <random> #ifdef DEBUG #include "library/Utility/debug.cpp" #else #define debug(...) #endif #define rep(i,n) for(int i=0;i<(n);++i) #define EL '\n' #define print(i) std::cout << (i) << '\n' #define all(v) (v).begin(), (v).end() using lnt = long long; constexpr lnt INF = 2e18; int main() { int n; std::cin >> n; std::vector<std::vector<int> > g(n); rep(i,n-1) { int a,b; std::cin >> a >> b; a--;b--; g[a].emplace_back(b); g[b].emplace_back(a); } auto dfs = [&] (auto f, int i, int par) -> int { int p=1; for(auto to:g[i]) { if(to==par) continue; int o=f(f,to,i); if(o==-1) return -1; if(o==1) p++; } if(p>2) return -1; return p%2; }; int ans=dfs(dfs,0,-1); if(ans==1||ans==-1) print("First"); else print("Second"); }
#include <bits/stdc++.h> using namespace std; #ifdef ARTEM #define deb(x) x #else #define deb(x) const int LIMIT = 2 * int(1e5) + 123; #endif void solve(); int main() { solve(); } void solve() { int n, l; cin >> n >> l; vector<string> s(n); for(int i = 0; i < n; i++) cin >> s[ i ]; sort(s.begin(), s.end()); for(string i : s) cout << i; }
0
11,616,294
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define ll long long #define pi pair<int,int> #define pl pair<ll,ll> #define pd pair<double,double> #define ld long double #define pld pair<ld,ld> #define lg length() #define sz size() #define vi vector<int> #define vl vector<ll> #define vp vector<pi> #define vpl vector<pl> #define pb push_back #define INF 1000000005 #define LINF 1000000000000000005 int a,b,c; int32_t main(){ ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cin >> a >> b >> c; if(a==b && b==c) cout << "Yes"; else cout << "No"; }
#include <iostream> #include <vector> #include <algorithm> #include <numeric> int main() { int K, N; std::cin >> K >> N; std::vector<int> A(N); for (int i = 0; i < N; i++) { std::cin >> A[i]; } std::vector<int> diff(N); for (int i = 0; i < N - 1; i++) { diff[i] = A[i+1] - A[i]; } diff[N-1] = (K + A[0]) - A[N-1]; std::sort(diff.begin(), diff.end(), std::greater<int>()); int ans = std::accumulate(diff.begin() + 1, diff.end(), 0); std::cout << ans << std::endl; return 0; }
0
58,919,980
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define _GLIBCXX_DEBUG #define INF 1e8 typedef long long int ll; const double PI = acos(-1); using Graph = vector<vector<int>>; int main() { ll n, a, b; cin >> n >> a >> b; ll ans = (n / (a + b)) * a; if ((n % (a + b)) >= a) ans += a; else ans += (n % (a + b)); cout << ans << endl; }
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0; i < int(n); i++) #define vi vector<int> #define all(x) (x).begin(),(x).end() #define INF (1<<30)-1 using ll = long long; using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; } template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; } int main(){ cin.tie(0), ios::sync_with_stdio(false); int h,w; cin >> h >> w; vector<string> s(h); rep(i,h) cin >> s[i]; vector<vi> dp(h,vi(w,INF)); dp[0][0] = (s[0][0] == '#'); rep(i,h){ rep(j,w){ if(0 <= j-1){ if(s[i][j-1] != s[i][j]) chmin(dp[i][j],dp[i][j-1]+1); else chmin(dp[i][j],dp[i][j-1]); } if(0 <= i-1){ if(s[i-1][j] != s[i][j]) chmin(dp[i][j],dp[i-1][j]+1); else chmin(dp[i][j],dp[i-1][j]); } } } if(s[h-1][w-1] == '#') dp[h-1][w-1]++; cout << dp[h-1][w-1]/2; cout << "\n"; return 0; }
0
21,034,828
#ifdef LOCAL_JUDGE #define _GLIBCXX_DEBUG #endif #include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <iomanip> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <math.h> #include <cmath> #include <bitset> using namespace std; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const long long INF = 100100100100; const long long MOD = 1000000007; typedef pair<long long,long long> P; long long mod_pow(long long N, long long M) { if (M == 0) return 1; long long res = mod_pow((N * N) % MOD, M / 2); if (M & 1) res = (res * N) % MOD; return res %= MOD; } long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } int main() { string S;cin >> S;long long N = S.size(); long long ans = 0; long long Bcount = 0; for(int i = 0;i<N;i++){ if(S.at(i) == 'B') Bcount++; else ans += Bcount; } cout << ans << endl; }
#include<iostream> #include<queue> #include<limits> #include<algorithm> #include<vector> #include<cmath> #include<math.h> #include<iomanip> #include<deque> #include<stack> #include<string> #include<string.h> #include<map> #include<set> #include<unordered_map> #include<utility> #define ll long long #define tc(t) while(t--) #define V vector #define Vp vector< pair<int,int> > #define pb push_back #define UM unordered_map #define IT iterator #define F first #define S second #define forn(i, n) for (int i = 0; i < int(n); i++) #define PQ priority_queue #define _FI ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; char ar[140000]; vector<ll> SieveOfEratosthenes(ll n) { vector<ll> result; bool prime[n+1]; memset(prime, true, sizeof(prime)); int count=1; for (ll p=2; p*p<=n; p++) { if (prime[p] == true) { for (ll i=p*p; i<=n; i += p) { prime[i] = false; } count++; } } for (ll p=2; p<=n; p++) if (prime[p]) { result.push_back(p); } return result; } vector<ll> Divisors (ll n) { vector<ll> res; for(ll i=1;i<=sqrt(n);i++) { if(n%i==0) { if(n/i==i) { res.pb(i); } else { res.pb(i); res.pb(n/i); } } } return res; } ll Div(ll n) { for(ll i=2;i<=sqrt(n);i++) { if(n%i==0) return i; } return n; } int a[4][2]={ {1,0}, {1,-1}, {1,1}, {2,0} } ; bool validPoint(int x,int y, int N) { return (x>=0 && x<N && y>=0 && y<N); } int main() { _FI int t=1; tc(t) { int n,m; cin>>n>>m; V<int> arr(m,0); int sum=0; forn(i,m) { cin>>arr[i]; sum+=arr[i]; } if(sum<=n) { cout<<n-sum<<endl; } else { cout<<-1<<endl; } } return 0; }
0
56,388,163
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c; int kyori; string kekka = "No"; cin >> a >> b >> c >> kyori; if(abs(c - a) <= kyori) kekka = "Yes"; if(abs(c - b) <= kyori && abs(b - a) <= kyori) kekka = "Yes"; cout << kekka; }
#include <iostream> #include <cstdint> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cctype> #include <cassert> #include <climits> #include <string> #include <bitset> #include <cfloat> #include <unordered_set> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<vector<int>> vvi; typedef vector<vector<char>> vvc; typedef vector<vector<string>> vvs; typedef vector<vector<ll>> vvll; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rrep(i, n) for (ll i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (ll i = (n)-1; i >= 0; --i) #define mes(a) cout << (a) << endl #define dmes(a, b) cout << (a) << " " << (b) << endl #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define Rev(a) reverse(a.begin(), a.end()) #define MATHPI acos(-1) #define itn int int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; 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; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-19; signed main() { ll n, k; cin >> n >> k; ll r = 0; r = pow(n/k,3); if (k % 2 == 0) { r += pow(n/(k/2) - n/k, 3); } mes(r); }
0
78,860,812
#include<bits/stdc++.h> #define swap(type,a,b) {type t; t=a; a=b; b=t;} #define forN(i,n) for(int i=0;i<n;i++) #define forS(i,start,n) for(int i=start;i<n;i++) #define ll long long #define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}} #define DOUBLE fixed << setprecision(15) using namespace std; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<string> vs; typedef pair<int,int> pii; typedef vector<pair<int,int>> vpii; int gcd(int,int); int main(){ int n,m,cnt=0; string s; cin >> n; vi a(n); forN(i,n){ cin >> a[i]; } int p=0; forN(i,n){ p=gcd(p,a[i]); } cout << p<<endl; } int gcd(int x, int y){ int a=x,b=y; if(a==0||b==0) return max(a,b); if(a<b) swap(int,a,b); int tmp; while((tmp=a%b)!=0){ a=b;b=tmp; } return b; }
#include <numeric> #include <bits/stdc++.h> #include <utility> #include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <math.h> #include <string> #define ll long long #define ull unsigned long long #define make(type,x) type x; cin>>x #define make2(type,x,y) type x,y; cin>>x>>y #define fr(x,y) for(long long x=0;x<y;x++) #define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i] #define M (ll)1000000007 #define MM (ll) 1e8 #define INF (ll) 1e18 # define IOS ios_base::sync_with_stdio(false); cin.tie(NULL) using namespace std; template <typename T> T modpow(T base, T exp, T modulus) { base %= modulus; T result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result; } bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){ return a.second<b.second; } struct cmp { bool operator() (const pair<int, int> &a, const pair<int, int> &b) const { int lena = a.second - a.first + 1; int lenb = b.second - b.first + 1; if (lena == lenb) return a.first < b.first; return lena > lenb; } }; struct c_h { size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); x ^= FIXED_RANDOM; return x ^ (x >> 16); } }; ll calcpow(ll x, ll y) { ll temp; if(y == 0) return 1; temp = calcpow(x, y / 2); if (y % 2 == 0) return temp * temp; else { if(y > 0) return x * temp * temp; else return (temp * temp) / x; } } ll gcd(ll a, ll b){ if(b==0) return a; return gcd(b,a%b); } ll egcd(ll a, ll b, ll &x,ll &y){ if(b==0){ x=1; y=0; return a; } ll x1; ll y1; ll g=egcd(b,a%b,x1,y1); x=y1; y=x1-y1*(a/b); return g; } bool isprime(ll a){ bool flag=1; for(ll i=2;i*i<=a;i++){ if(a%i==0) {flag=0; break;} } return flag; } ll dx8[8]={1,0,-1,0,1,-1,1,-1}; ll dy8[8]={0,1,0,-1,1,-1,-1,1}; ll dx4[4]={0,0,1,-1}; ll dy4[4]={1,-1,0,0}; int main(){ IOS; make2(ll,n,x); makevec(ll,a,n); ll g=abs(a[0]-x); fr(i,n) g=gcd(g,abs(x-a[i])); cout<<g<<endl; return 0; }
0
76,466,623
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vector<int>>; using vll = vector<ll>; using vvll = vector<vector<ll>>; const double eps = 1e-10; const int MOD = 1000000007; const int INF = 1000000000; const ll LINF = 1ll<<50; template<typename T> void printv(const vector<T>& s) { for(int i=0;i<(int)(s.size());++i) { cout << s[i]; if(i == (int)(s.size())-1) cout << endl; else cout << " "; } } int main() { cin.tie(0); cout << fixed << setprecision(10); int n; cin >> n; vector<ll> a(n); for(int i=0;i<n;++i) { cin >> a[i]; } ll cnt = 0; while(1) { ll su = 0; for(int i=0;i<n;++i) { su += a[i]/n; } vector<ll> div(n); for(int i=0;i<n;++i) { div[i] = a[i]/n; } for(int i=0;i<n;++i) { cnt += div[i]; a[i] -= div[i]*n; a[i] += su - div[i]; } bool ok = true; for(int i=0;i<n;++i) { if(a[i] > n-1) { ok = false; break; } } if(ok) break; } cout << cnt << endl; }
#include<iostream> #include<vector> #include<cstdio> #include<string> #include<algorithm> #include<map> #include<set> #include<cmath> #include<deque> #include<queue> using namespace std; using ll = long long; const int INF = 1001001001; const ll LLINF = 1001001001001001001; const int MOD = 1000000007; #define rep(i,n) for (int i = 0; i < (n); ++i) int main() { int n, m, x; cin >> n >> m >> x; vector<ll> cost(n); vector<vector<ll>> a(n); rep (i,n) { cin >> cost[i]; rep (j,m) { int tmp; cin >> tmp; a[i].push_back(tmp); } } vector<ll> tot(m); rep (i,n) { rep (j,m) { tot[j] += a[i][j]; } } rep (i,m) { if (tot[i] < x) { cout << -1 << endl; return 0; } } ll result = LLINF; for (int bit = 0; bit < pow(2, n); bit++) { vector<int> book; int tbit = bit; int count = 0; while (tbit > 0) { if (tbit & 1) { book.push_back(count); } count++; tbit >>= 1; } ll tcost = 0; vector<int> score(m); for (int b : book) { rep (i,m) { score[i] += a[b][i]; } tcost += cost[b]; } bool isOk = true; rep (i,m) { if (score[i] < x) isOk = false; } if (isOk) result = min(result, tcost); } cout << result << endl; }
0
92,325,487
#include<iostream> #include<map> #include<vector> #include<algorithm> #include<cmath> #include<climits> #include<ctime> #include<cstring> #include<numeric> #define ALL(v) (v).begin(),(v).end() #define REP(i,p,n) for(int i=p;i<(int)(n);++i) #define rep(i,n) REP(i,0,n) #define dump(a) (cerr << #a << "=" << (a) << endl) #define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl; using namespace std; int W,H; void dfs(vector<string> &field, vector<vector<bool> > &move,int now_x, int now_y) { int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; if(now_x < 0 || now_x >= W || now_y < 0 || now_y >= H){ return; } if(field[now_y][now_x] == '#'){ return; } if(move[now_y][now_x]){ return; } move[now_y][now_x] = true; rep(i,4){ dfs(field, move, now_x+dx[i], now_y+dy[i]); } return; } int main() { while(cin >> W >> H && W && H) { vector<string> field(H); vector<vector<bool> > move(H, vector<bool>(W,false)); rep(y,H){ cin >> field[y]; } pair<int, int> start; rep(y,H){ rep(x,W){ if(field[y][x] == '@'){start = make_pair(x,y);} } } dfs(field, move, start.first, start.second); int count=0; rep(y,H){ rep(x,W){ if(move[y][x]){ count++; } } } cout << count << endl; } return 0; }
#include<cstdio> #include<string> #include<list> using namespace std; list<int>L; int main() { int N; int d; char command[20]; scanf("%d",&N); for(int i=0;i<N;i++){ scanf("%s",command); if(command[0]=='i'){ scanf("%d",&d); L.push_front(d); } else if(command[6]=='F'){ L.pop_front(); } else if(command[6]=='L'){ L.pop_back(); } else if(command[0]=='d'){ scanf("%d",&d); for(list<int>::iterator it=L.begin();it!=L.end();it++) { if(d==*it){ L.erase(it); break; } } } } int i=0; for(list<int>::iterator it=L.begin();it!=L.end();it++){ if(i++)printf(" "); printf("%d",*it); } printf("\n"); return 0; }
0
28,507,862
#include <iostream> using namespace std; int main(){ int D, T, S; cin >> D >> T >> S; if (S*T >= D) cout << "Yes"; if (S*T < D) cout << "No"; cout << "\n"; }
#include <bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long ll; typedef pair<int,int> pii; const int N = 2e5 + 228; ll dp[N][3], a[N][3]; int main() { #ifdef LOCAL_RUN freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2]; for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (j == k) continue; dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]); } } } cout << max(max(dp[n][0], dp[n][1]), dp[n][2]); return 0; }
0
88,087,136
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N; cin >> N; ll ans = 0; ll i = 1; while (i * i < N - i) { if ((N - i) % i == 0) ans += (N - i) / i; i++; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false), cin.tie(0); int q; cin >> q; for(int i = 0; i < q; i++) { ll a, b; cin >> a >> b; if(a > b) swap(a, b); if(a == b) { cout << 2 * (a - 1) << endl; } else if (a + 1 == b) { cout << 2 * (a - 1) << endl; } else { ll c = sqrt(a * b); if(c * c == a * b) c--; if(c * (c + 1) < a * b) { cout << 2 * c - 1 << endl; } else { cout << 2 * c - 2 << endl; } } } }
0
77,525,393
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define in freopen("input.txt", "r", stdin) #define out freopen("output.txt", "w", stdout) #define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int main() { ios #ifndef ONLINE_JUDGE in; out; #endif int n; cin>>n; if (n/100*5 >= n%100) cout<<1<<endl; else cout<<0<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int t, k; int check[4]; for(int i = 0; i < 4; i++){ check[i] = 0; } for(int i = 0; i < 3; i++){ cin >> t >> k; check[t - 1]++; check[k - 1]++; } int flag_1 = 0; int flag_2 = 0; for(int i = 0; i < 4; i++){ if(check[i] == 1){ flag_1++; }else if(check[i] == 2){ flag_2++; }else{ break; } } if(flag_1 == 2 && flag_2 == 2){ cout << "YES" << endl; }else{ cout << "NO" << endl; } }
0
73,869,796
#include <bits/stdc++.h> using namespace std; #define ll long long template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} void solve() { int n; cin >> n; vector<string> s(n); vector<int> c(26, 100), count(26); for(int i=0; i<n; ++i) { cin >> s.at(i); vector<int> count(26); for(int j=0; j<s.at(i).size(); ++j) { count.at(s.at(i).at(j)-'a')++; } for(int j=0; j<26; ++j) { if(c.at(j) > count.at(j)) { c.at(j) = count.at(j); } } } for(int i=0; i<26; ++i) { char ans = i+'a'; if(c.at(i)) { for(int j=0; j<c.at(i); ++j) { cout << ans; } } } cout << '\n'; return; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int T=1; while(T--) solve(); return 0; }
#include "bits/stdc++.h" using namespace std;typedef long long lint;typedef vector<lint> liv; #define all(v) v.begin(),v.end() #define linf 1152921504606846976 #define MAXN 100010 #define md 1000000007 #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1,_2,_3,_4,name,...) name #define _getname3(_1,_2,_3,name,...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for(lint i=0;i<n;++i) #define _rep2(i,n) for(lint i=0;i<n;++i) #define _rep3(i,a,b) for(lint i=a;i<b;++i) #define _rep4(i,a,b,c) for(lint i=a;i<b;i+=c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for(lint i=n-1;i>=0;--i) #define _rrep2(i,n) for(lint i=n-1;i>=0;--i) #define _rrep3(i,a,b) for(lint i=b-1;i>=a;--i) #define _rrep4(i,a,b,c) for(lint i=a+(b-a-1)/c*c;i>=a;i-=c) template<class T> istream& operator>>(istream& is,vector<T>& vec); template<class T,size_t size> istream& operator>>(istream& is,array<T,size>& vec); template<class T,class L> istream& operator>>(istream& is,pair<T,L>& p); template<class T> ostream& operator<<(ostream& os,vector<T>& vec); template<class T,class L> ostream& operator<<(ostream& os,pair<T,L>& p); template<class T> istream& operator>>(istream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; } template<class T,class L> istream& operator>>(istream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; } template<class T,class L> ostream& operator<<(ostream& os,pair<T,L>& p){ os<<p.first<<" "<<p.second;return os; } inline void in(){} template <class Head,class... Tail> inline void in(Head&& head,Tail&&... tail){ cin>>head;in(move(tail)...); } template <class T> inline bool out(T t){ cout<<t<<'\n';return 0; } inline bool out(){ cout<<'\n';return 0; } template <class Head,class... Tail> inline bool out(Head head,Tail... tail){ cout<<head<<' ';out(move(tail)...);return 0; } 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); } #define rep(...) _vcppunko4((__VA_ARGS__,_trep4,_trep3,_trep2,_rep1))((__VA_ARGS__)) #define rrep(...) _vcppunko4((__VA_ARGS__,_trrep4,_trrep3,_trrep2,_rrep1))((__VA_ARGS__)) #define each(v) for(auto &i:v) #define lin(...) lint __VA_ARGS__;in(__VA_ARGS__) #define stin(...) string __VA_ARGS__;in(__VA_ARGS__) #define vin(type,name,size) vector<type> name(size);in(name) #define fi i.first #define se i.second #define YES(c) cout<<((c)?"YES\n":"NO\n"),0 #define Yes(c) cout<<((c)?"Yes\n":"No\n"),0 #define inf linf int main(){ lin(n); vin(lint,a,n); lint ans=a[0]-1,l=2; rep(i,1,n){ ans+=(a[i]-1)/l; if(a[i]==l)++l; }cout<<ans<<endl; }
0
58,463,305
#include <bits/stdc++.h> #define rep(i , n) for(int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; int main (){ string s; cin >> s; int c = 0; for(int i = 1; i < s.size() / 2;i++){ if(s.substr(0 , i) == s.substr(i , i)){ c = 2 * i; } } cout << c << endl; }
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; typedef long long ll; typedef long double ld; const long long INF = 1e18; # define len(x) ((int)(x).size()) # define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) # define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i) # define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i) # define rreps(i, n) for(int i=((int)(n)); i>0; --i) # define foreps(i, m, n) for(int i = m;i < n;i++) # define ALL(x) (x).begin(), (x).end() # define rall(x) (x).rbegin(), (x).rend() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int main() { ll n; cin >> n; vector<i64> v(n); map<int, int> odd, even; rep(i, n) { if (i % 2 == 0) { cin >> v[i]; even[v[i]]++; } else { cin >> v[i]; odd[v[i]]++; } } ll ev = 0, ev1 = 0, od = 0, od1 = 0; ll e1 = 0, e2 = 0, o1 = 0, o2 = 0; ll cnt = 0; for (auto itr = odd.begin(); itr != odd.end(); itr++) { if (itr->second > cnt) { cnt = itr->second; od = itr->first; } } o1 = cnt; cnt = 0; for (auto itr = odd.begin(); itr != odd.end(); itr++) { if (itr->second > cnt && itr->first != od) { cnt = itr->second; od1 = itr->first; } } o2 = cnt; cnt = 0; for (auto itr = even.begin(); itr != even.end(); itr++) { if (itr->second > cnt) { cnt = itr->second; ev = itr->first; } } e1 = cnt; cnt = 0; for (auto itr = even.begin(); itr != even.end(); itr++) { if (itr->second > cnt && itr->first != ev) { cnt = itr->second; ev1 = itr->first; } } e2 = cnt; if (ev == od) { cout << min(n - e1 - o2, n - e2 - o1) << endl; } else { cout << n - e1 - o1 << endl; } }
0
48,870,347
#include <bits/stdc++.h> #include <climits> #ifdef atclib #include <atcoder/all> #endif #ifdef local #include "dbg-macro/dbg.h" #endif #ifdef boost #include <boost/multiprecision/cpp_int.hpp> #endif #define p std::pair #define ll long long #define ld long double #define ull unsigned long long #define vi std::vector<int> #define pi std::pair<int, int> #define mp std::make_pair #define stdabs std::abs #define all(x) (x).begin(), (x).end() #define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i) #define vec std::vector #define oreq |= #define npm next_permutation #define Yes std::cout << "Yes" << std::endl #define No std::cout << "No" << std::endl #define YES std::cout << "YES" << std::endl #define NO std::cout << "NO" << std::endl const int dx4[4] = {1, 0, -1, 0}; const int dy4[4] = {0, 1, 0, -1}; const int dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1}; template <class T> inline bool chmax(T& a__, T b__) { if (a__ < b__) { a__ = b__; return 1; } return 0; } template <class T> inline bool chmin(T& a__, T b__) { if (a__ > b__) { a__ = b__; return 1; } return 0; } using namespace std; std::vector<unsigned ll> genprimevec(const unsigned ll N); ll extgcd(ll a, ll b, ll& x, ll& y); ll nCr(ll n__, ll r__); void stat(); template <typename T> T fact(T num__); unsigned long long modpow(int x__, int n__, long long mod__); template <typename T> void debug(const T& t__); constexpr ll mod10_9p7 = 1000000000 + 7; int main() { stat(); int n; cin >> n; int cur = 0, cx = 0, cy = 0; rep(i, n) { int t, x, y; cin >> t >> x >> y; if (abs(cx - x) + abs(cy - y) > t - cur) { No; return 0; } else { int sub = t - cur; int temp=abs(cx-x)+abs(cy-y); if ((sub-temp) % 2 != 0) { No; return 0; } cur=t; cx=x; cy=y; } } Yes; return 0; } ll extgcd(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1, y = 0; return a; } ll d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } std::vector<unsigned ll> genprimevec(const unsigned ll N) { std::vector<bool> is_prime(N + 1); for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; } std::vector<unsigned ll> P; for (unsigned ll i = 2; i <= N; i++) { if (is_prime[i]) { for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; } P.emplace_back(i); } } return P; } void stat(){ #ifdef local rep(i__, 2){std::cout << "local" << std::endl; } #endif #ifdef hacks rep(i__, 2) { std::cout << "boost" << std::endl; } #endif } ll nCr(ll n__, ll r__) { ll num__ = 1; for (ll i__ = 1; i__ <= r__; i__++) { num__ = num__ * (n__ - i__ + 1) / i__; } return num__; } template <typename T> T fact(T num__) { if (num__ == 1) { return 1; } return num__ * fact(num__ - 1); } unsigned long long modpow(int x__, int n__, long long mod__) { long long ret__ = 1; for (long long i__ = 0; i__ < n__; ++i__) { ret__ = ret__ * x__ % mod__; } return ret__; } template <typename T> void debug(const T& t__) { #ifdef local dbg(t__); #endif }
#include <iostream> #include <algorithm> #include <cmath> #include <climits> #include <vector> #include <cstring> #include <set> #include <map> #include <stack> #include <queue> #include <unordered_map> #include <unordered_set> #include <string.h> #include <iomanip> using namespace std; #define int long long #define ull unsigned long long #define F first #define S second #define nl "\n" #define ld long double #define div 1000000007 #define pi 3.14159265358979323846 #define pb push_back bool ans=0; void f(int a,int b,int c,int k) { if(a<b && b<c) { ans=1; return; } if(k==0) { return; } f(2*a,b,c,k-1); f(a,2*b,c,k-1); f(a,b,2*c,k-1); } void solve() { int a,b,c,k;cin>>a>>b>>c>>k; f(a,b,c,k); if(ans) cout<<"Yes"<<nl; else cout<<"No"<<nl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int t=1; while(t--) { solve(); } return 0; }
0
41,912,452
#include <bits/stdc++.h> #define ll long long using namespace std; const int MOD = 1000000007; int main() { int n; cin >> n; ll arr[n]; for(int i = 0;i < n;i++) cin >> arr[i]; sort(arr, arr + n); if(arr[n - 1] <= n - 1){ cout << 0; return 0; } ll k = 0; ll res = 0; for(int i = n - 1;i >= 1;i--){ ll op = (arr[i] - arr[i - 1]) / (n + 1); res += op * (n - i); for(int j = i;j < n;j++) arr[j] -= op * (i + 1); for(int j = 0;j < i;j++) arr[j] += op * (n - i); } if(arr[0] >= n){ ll op = (arr[0] - (n - 1)); res += n * op; for(int i = 0;i < n;i++) arr[i] -= op; } while(arr[n - 1] >= n){ arr[n - 1] -= n; for(int j = 0;j < n - 1;j++) arr[j]++; for(int j = n - 1;j >= 1 && arr[j] < arr[j - 1];j--) swap(arr[j], arr[j - 1]); res++; } cout << res; }
#include<bits/stdc++.h> using namespace std; int main () { char S[100]; int si = 0; string com; cin >> com; for (int i = 0; i < (int)com.size(); i ++) { char c = com[i]; if (c == '0') { S[si] = '0'; si ++; } if (c == '1') { S[si] = '1'; si ++; } if (c == 'B') { si = max(si - 1, 0); } } for (int i = 0; i < si; i ++) { cout << S[i]; } cout << endl; }
0
61,856,050
#include <iostream> #include <cstdio> #include<cctype> #include<cstring> using namespace std; int main() { char str[1001]; while (1) { scanf("%s",str,1001); int sum = 0; if (strcmp(str,"0")==0) { break; } else { for (int i = 0; i < strlen(str); i++) { sum += (str[i] - '0'); } } printf("%d\n", sum); } return 0; }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for (int i=0;i<(int)(n);i++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yn(ans) if(ans)printf("Yes\n");else printf("No\n") #define YN(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} int main(){ string s; cin>>s; int x1=0,x2=0,n=0; vector<pair<char,int>> t; rep(i,s.length()){ if(s[i]!='x'){ n++; t.push_back(make_pair(s[i],i)); } } if(n==0){ out(0); return 0; } int counter=0; for(int i=0;i<n;i++){ counter+=(t[i].first==t[n-1-i].first); } if(counter!=n){ out(-1); return 0; } int ans=0,l=0,r=s.length()-1; while(l<r){ if(s[l]==s[r]){ l++; r--; }else if(s[l]=='x'&&s[r]!='x'){ ans++; l++; }else if(s[l]!='x'&&s[r]=='x'){ ans++; r--; } } out(ans); }
0
41,373,412
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ int n, m; scanf("%d %d", &n, &m); vector<vector<int> > data(100010); for(int i = 0; i < n; i++){ int a, b; scanf("%d %d", &a, &b); data[a].push_back(b); } priority_queue<int> que; int ans = 0; for(int i = 0; i <= m; i++){ for(int j = 0; j < data[i].size(); j++) que.push(data[i][j]); if(que.empty()) continue; ans += que.top(); que.pop(); } printf("%d\n", ans); }
#include <bits/stdc++.h> #define rep(i,n)for(long long i=0;i<(long long)(n);i++) #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef pair<ll, ll> P; 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 ll MOD=1e9+7; const ll INF=1e18; const int MAX=510000; const double pi=acos(-1); int dx[8] = {1,0,-1,0,1,1,-1,-1}; int dy[8] = {0,1,0,-1,-1,1,1,-1}; int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<ll>a(n+1); rep(i,n+1) cin >> a[i]; vector<ll>ans(n+1); vector<P>m(n+1); for(int i = n; i >= 0; i--){ if(i==n)m[i]=P(a[i],a[i]); else{ ll mi = a[i] + (m[i+1].first+1)/2; ll ma = a[i] + m[i+1].second; m[i] = P(mi,ma); } } if(1 < m[0].first || m[0].second < 1 ){ cout << -1 << endl; return 0; } rep(i,n+1){ if(i == 0)ans[0] = 1; else{ ans[i] = min(2*(ans[i-1]-a[i-1]),m[i].second); } } ll res = 0; rep(i,n+1) res += ans[i]; cout << res << endl; return 0; }
0
47,998,066
#include <bits/stdc++.h> typedef struct Node { Node *left, *right; int data; } Node; Node base; void Node_init() { base.right = &base; base.left = &base; return; } void Node_insert(int x) { Node *node = new Node(); node->data = x; node->right = base.right; node->left = &base; base.right->left = node; base.right = node; return; } void Node_delete(int x) { Node *node = base.right; while( node != &base ) { if( node->data == x ) { node->right->left = node->left; node->left->right = node->right; delete node; return; } node = node->right; } return; } void Node_deleteFirst(void) { Node *node = base.right; node->right->left = node->left; node->left->right = node->right; delete node; return; } void Node_deleteLast(void) { Node *node = base.left; node->right->left = node->left; node->left->right = node->right; delete node; return; } void Node_print(void) { Node *node = base.right; while( node != &base ) { if( node->right == &base ) { printf("%d\n", node->data); return; } else { printf("%d ", node->data); } node = node->right; } return; } int main(void) { int N; char str[256]; int x; Node_init(); std::cin >> N; for(int i = 0; i < N; ++i) { scanf("%s", str); if( strcmp(str,"insert") == 0 ) { scanf("%d", &x); Node_insert(x); } else if( strcmp(str, "delete") == 0 ) { scanf("%d", &x); Node_delete(x); } else if( strcmp(str, "deleteFirst") == 0 ) { Node_deleteFirst(); } else if( strcmp(str, "deleteLast") == 0 ) { Node_deleteLast(); } else { std::cout << "Error : " << str << std::endl; exit(1); } } Node_print(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s; cin >> s; for (int tmp = 0; tmp < (1 << 3); tmp++) { bitset<3> bs(tmp); int sum = s.at(0) - '0'; string formula = to_string(sum); for (int i = 0; i < (int)s.size() - 1; i++) { int n = s.at(i + 1) - '0'; string sign; if (bs.test(i) == 1) { sum += n; sign = "+"; } else { sum -= n; sign = "-"; } formula += sign + to_string(n); } if (sum == 7) { cout << formula << "=7" << endl; return 0; } } return 0; }
0
93,560,304
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int X[100010] = {}; for(int i = 0; i < N; i++) cin >> X[i]; int L, Q; cin >> L >> Q; int A[100010][18] = {}; for(int i = 0; i < N; i++){ int a = upper_bound(X, X+N, X[i] + L) - X; A[i][0] = a - 1; } for(int j = 1; j < 18; j++){ for(int i = 0; i < N; i++){ A[i][j] = A[A[i][j-1]][j-1]; } } for(int q = 0; q < Q; q++){ int a, b; cin >> a >> b; a--; b--; if(a > b) swap(a, b); int now = a; int ans = 0; for(int i = 17; i >= 0; i--){ if(A[now][i] >= b) continue; now = A[now][i]; ans += (1 << i); } cout << ans + 1 << endl; } }
#include <iostream> #include <cmath> using namespace std; int main(void) { int n; double x[4],y[4]; double degree[2]; cin >> n; for(int i = n ; i > 0 ; i--){ cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]; degree[0] = (y[1] - y[0]) / (x[1] - x[0]); degree[1] = (y[3] - y[2]) / (x[3] - x[2]); if(degree[0] == degree[1]) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
0
76,664,718
#include<iostream> using namespace std; int main() { int64_t X,Y ; cin>>X>>Y ; int64_t ans=(X>Y?X-Y:Y-X) ; if(ans<=1) cout<<"Brown"<<endl ; else cout<<"Alice"<<endl ; return 0 ; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rrep(i,n) for(int i=(int)(n-1);i>=0;i--) #define FOR(i,n,m) for(int i=n;i<=(int)(m);i++) #define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--) #define all(x) (x).begin(),(x).end() #define sz(x) int(x.size()) typedef long long ll; const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; const double PI=3.14159265358979323846; using namespace std; vector<int> dy={1,0,-1,0}; vector<int> dx={0,1,0,-1}; 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...)); } double dist(pair<double,double> a, pair<double,double> b) { double ax,ay,bx,by; tie(ax,ay)=a; tie(bx,by)=b; return sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by)); } int main() { int n; cin>>n; vector<pair<double,double>> xy(n); rep(i,n) { double x,y; cin>>x>>y; xy[i]={x,y}; } sort(all(xy), [](const auto &p1, const auto &p2) { return atan2l(p1.second, p1.first) < atan2l(p2.second, p2.first); }); rep(i,n) xy.push_back(xy[i]); double ans=0; rep(left,n) { FOR(k,1,n) { double x=0,y=0; rep(i,k) { x+=xy[left+i].first; y+=xy[left+i].second; } ans=max(ans,dist({0,0},{x,y})); } } cout<<fixed<<setprecision(12)<<ans<<endl; }
0
70,153,606
#include <bits/stdc++.h> using namespace std; int main(){ int a,b; cin >> a >> b; cout << (a+b+1)/2; }
#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 int MOD = 1000000007; const ll INF = 1LL<<60; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using Graph = vector<vector<int>>; typedef pair<int, int> P; int main(){ ll N, H; cin >> N >> H; vector<ll> A, B; A = B = vector<ll>(N,0); rep(i,N){ cin >> A[i] >> B[i]; } ll max_a = 0; rep(i,N){ max_a = max(max_a, A[i]); } sort(B.begin(), B.end(), greater<ll>()); ll ans = INF; rep(i,N){ H -= B[i]; ll a_count = 0; if (H > 0){ a_count = (H+(max_a-1))/ max_a; } ans = min(ans, a_count+i+1); } cout << ans << endl; }
0
68,262,146
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { string num; cin >> num; for(int i=0; i<num.size(); i++) { if(num[i] == '7') { cout << "Yes"; return 0; } } cout << "No"; }
#include<iostream> #include<vector> using namespace std; int main(){ int n,a,b,c,x; vector<int>y; while(cin>>n>>a>>b>>c>>x){ if(n+a+b+c+x==0)break; int cnt=0,ans=-1; for(int i=0;i<n;i++){ int tmp; cin>>tmp; y.push_back(tmp); } for(int i=1;i<=10001;i++){ if(y[cnt]==x)cnt++; if(cnt==y.size()){ ans=i-1; break; } x=(a*x+b)%c; } if(x!=-1)cout<<ans<<endl; else cout<<-1<<endl; y.clear(); } return 0; }
0
93,487,514
#include<bits/stdc++.h> #define rep(i,n,m) for(int i = (n); i <(m); i++) using namespace std; using ll = long long; int main() { int n; cin >> n; vector<ll> cumsum(n + 1); cumsum[0] = 0; rep(i, 0, n) { int a; cin >> a; cumsum[i + 1] = a + cumsum[i]; } ll ans = 1000000000000000; rep(i, 1, n) ans = min(ans, abs(2 * cumsum[i] - cumsum[n])); cout << ans << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <math.h> #include <cmath> using namespace std; #define int long long #define endl "\n" #define all(v) v.begin(),v.end() #define fir first #define sec second #define m_p make_pair #define rep(i,n) for(int i=0; i<(int) (n); i++) #define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i]; #define vecout(v) for(int i=0; i<v.size(); i++)cout<<v[i]<<" "; cout<<endl; #define LLU long long unsigned const double pai = 3.1415926535897; const int mod = 1000000007; const int INF = 2000000015; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; int jousu(int x00, int y00) { int z00 = 1; for (int i = 0; i < y00; i++) { z00 *= x00; } return z00; } int keta(int x00) { int z00 = x00; int w00 = 0; while (z00 != 0) { z00 /= 10; w00++; } return w00; } int krag(double xx) { return INF - (int)(INF - xx); } int b_s(vector<int>&vecxx, int xx) { if (xx <= vecxx[0]) { return 0; } if (vecxx.back() < xx) { return vecxx.size(); } int aa1 = 0, aa2 = vecxx.size() - 1, aa3; while (aa1 + 1 < aa2) { aa3 = (aa1 + aa2) / 2; if (vecxx[aa3] >= xx) { aa2 = aa3; } else { aa1 = aa3; } } return aa2; } void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int modinv(int a, int m) { int b = m, u = 1, v = 0; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int modpow(int a, int n) { int res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int gcd(int xx, int yy) { int p = xx; int q = yy; if (q > p)swap(p, q); while (p % q != 0) { p %= q; swap(p, q); } return q; } int lcm(int xx, int yy) { return xx * yy / gcd(xx, yy); } bool prime(int xx) { int a = xx; for (int i = 2; i * i <= xx; i++) { if (xx % i == 0) { return 0; } } return 1; } signed main() { int n, k, a = 1, t = 0,ans=0; string s; char c; vector<int>vec,vec2; cin >> n >> k >> s; c = s[0]; if (c == '0') { vec.push_back(0); } for(int i=1; i<n; i++) { if (c != s[i]) { vec.push_back(a); a = 0; c = s[i]; } a++; } vec.push_back(a); if (c == '0') { vec.push_back(0); } k = min(k, (int)(vec.size() - 1) / 2); rep(i, vec.size()) { vec2.push_back(t); t += vec[i]; } vec2.push_back(t); for (int i = 0; i < vec2.size() - k * 2-1; i += 2) { ans = max(ans, vec2[i + k * 2 + 1] - vec2[i]); } cout << ans << endl; }
0
22,592,278
#include<bits/stdc++.h> using namespace std; int main() { int N, M; int count = 0; int count_max = -100; string search_word; cin >> N; vector<string> s(N); for (int i = 0; i < N; i++) { cin >> s.at(i); } cin >> M; vector<string> t(M); for (int i = 0; i < M; i++) { cin >> t.at(i); } for (int i = 0; i < N; i++) { count = 0; search_word = s.at(i); for (int j = 0; j < N; j++) { if (s.at(j) == search_word) { count++; } } for (int j = 0; j < M; j++) { if (t.at(j) == search_word) { count--; } } if (count > count_max) { count_max = count; } } for (int i = 0; i < M; i++) { count = 0; search_word = t.at(i); for (int j = 0; j < N; j++) { if (s.at(j) == search_word) { count++; } } for (int j = 0; j < M; j++) { if (t.at(j) == search_word) { count--; } } if (count > count_max) { count_max = count; } } if (count_max < 0) { count_max = 0; } cout << count_max << endl; return 0; }
#include<iostream> #include<string> typedef struct dictionary{ struct dictionary *A, *C, *G, *T; bool a, c, g, t; } dictionary; void insert(void); void find(void); void init(dictionary*); dictionary *Dic; int main(){ int n; std::string func, ins="insert", fin="find"; init(Dic = new dictionary); std::cin >> n; for(int i=0; i<n; i++){ std::cin >> func; if(func == ins) insert(); else if(func == fin) find(); } return 0; } void insert(void){ std::string in; dictionary *n, *temp=Dic; std::cin >> in; for(int i=0; i<in.length() ; i++){ switch(in[i]){ case 'A': if(temp->A == NULL) init(n = new dictionary), temp->A = n; if(i == in.length()-1) temp->a = true; temp = temp->A; break; case 'C': if(temp->C == NULL) init(n = new dictionary), temp->C = n; if(i == in.length()-1) temp->c = true; temp = temp->C; break; case 'G': if(temp->G == NULL) init(n = new dictionary), temp->G = n; if(i == in.length()-1) temp->g = true; temp = temp->G; break; case 'T': if(temp->T == NULL) init(n = new dictionary), temp->T = n; if(i == in.length()-1) temp->t = true; temp = temp->T; break; default: break; } } } void find(void){ std::string in; dictionary *temp=Dic; std::cin >> in; for(int i=0; i!=in.length() ; i++){ switch(in[i]){ case 'A': if(temp->A == NULL || (in[i+1] == '\0' && !temp->a)){ std::cout << "no" << std::endl; return; } temp = temp->A; break; case 'C': if(temp->C == NULL || (in[i+1] == '\0' && !temp->c)){ std::cout << "no" << std::endl; return; } temp = temp->C; break; case 'G': if(temp->G == NULL || (in[i+1] == '\0' && !temp->g)){ std::cout << "no" << std::endl; return; } temp = temp->G; break; case 'T': if(temp->T == NULL || (in[i+1] == '\0' && !temp->t)){ std::cout << "no" << std::endl; return; } temp = temp->T; break; default: break; } } std::cout << "yes" << std::endl; } void init(dictionary *n){ n->A = n->C = n->G = n->T = NULL, n->a = n->c = n->g = n->t = false; }
0
69,496,432
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define dump(x) cout << x << endl typedef int64_t Int; using namespace std; using Graph = vector<vector<Int>>; const double pi = M_PI; const Int MOD = 1000000007; int main() { int n, k; cin >> n >> k; if (n % k == 0) { cout << 0 << endl; } else { cout << 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n,m; cin >> n >> m; priority_queue<long long> que; for (int i = 0; i < n; i++){ long long ai; cin >> ai; que.push(ai); } for (int i = 0; i < m; i++){ long long t; t=que.top(); que.pop(); que.push(t/2); } long long ans=0; while(!que.empty()){ ans+=que.top(); que.pop(); } cout << ans << endl; }
0
55,411,398
#include <stdio.h> int main (void) { int i, j; for (i = 1; i < 10; i++) { for (j = 1; j < 10; j++) { printf("%dx%d=%d\n", i, j, i * j); } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1000000007; const ld PI = acos(-1); const ld EPS = 0.0000000001; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define rep(i, n) for(ll i=0; i<(ll)(n); i++) #define repd(i, n) for(ll i=n-1; 0<=i; i--) #define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++) #define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--) #define ALL(x) x.begin(), x.end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; string YES[2] = {"NO", "YES"}; string yes[2] = {"No", "Yes"}; int main(){ ll n; cin >> n; vector<ll> v(n, 0); rep(k, n){ ll x=k+1; for(int i=1; i*i<=x; i++){ if(x%i==0){ v[k] += 1; if(x/i!=i) v[k] += 1; } } } ll res=0; rep(i, n){ if(i%2) continue; res += v[i]==8; } cout << res << endl; }
0
33,828,805