code1
stringlengths
54
12k
code2
stringlengths
65
12k
similar
int64
0
1
__index_level_0__
int64
2
101M
#include <iostream> #include<stdio.h> #define MAX 5000001 #define INFTY (1<<30) using namespace std; int n = 0, arr[MAX]; void swapNode(int index1, int index2) { int temp = arr[index1]; arr[index1] = arr[index2]; arr[index2] = temp; } void maxHeapify(int i) { int left = 2*i; int right = 2*i+1; int largest = i; if(left <= n && right <= n) { int larger = arr[left] > arr[right] ? left : right; largest = arr[largest] > arr[larger] ? largest : larger; }else if(left <= n) { largest = arr[largest] > arr[left] ? largest : left; }else if(right <= n) { largest = arr[largest] > arr[right] ? largest : right; } if(largest != i) { swapNode(i, largest); maxHeapify(largest); } } void insertKey(int i, int key) { if(key < arr[i]) return; arr[i] = key; while(i > 1 && arr[i/2] < arr[i]) { swapNode(i, i/2); i = i/2; } } int insert(int key) { n++; arr[n] = -INFTY; insertKey(n, key); } int extract() { if(n < 1) return -INFTY; int res = arr[1]; arr[1] = arr[n--]; maxHeapify(1); return res; } int main() { char com[10]; int key; while(1) { scanf("%s", com); if(com[0] == 'e' && com[1] == 'n') break; else if(com[0] == 'i') { scanf("%d", &key); insert(key); }else { printf("%d\n", extract()); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } long long abs(long long n) { if (n < 0) { n = -n; } return n; } int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } int main() { long long n; cin >> n; vector <long long> v(n); long long sum = 0; rep(i, n) { cin >> v.at(i); sum += v.at(i); } long long min = 2*(long long)pow(10, 9); long long tmp = 0; for (int i = 0; i < n-1; i++) { tmp += v.at(i); long long c = tmp-(sum-tmp); if (c < 0) { c = -c; } if (min > c) { min = c; } } cout << min << endl; }
0
98,666,274
#include <bits/stdc++.h> #define ll long long #define ld long double #define f(a, b) for (ll i = a; i <= b; i++) #define pb push_back #define pf push_front #define mp make_pair using namespace std; #define N 200005 const ll INF = 1000000000000000001; const ll MOD = 1000000007; void solve(){ ll a,b,c,d; cin >>a>>b>>c>>d; cout << max({a*c, a*d , b*c , b*d}) << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("out.txt","w",stdout); #endif solve(); return 0; }
#include <iostream> #include <cstdio> #include <stdio.h> #include <vector> #include <string> #include <cstring> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <utility> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cmath> #include <math.h> #include <tuple> #include <iomanip> #include <bitset> #include <functional> #include <cassert> #include <random> #define all(x) (x).begin(),(x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){ return f.second > s.second; } ll gcd(ll a, ll b){ if (b == 0)return a; return gcd(b, a % b); } ll lcm(ll a, ll b){ return a / gcd(a, b) * b; } ll conbinationMemo[100][100]; void cmemoInit(){ rep(i, 100){ rep(j, 100){ conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r){ if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if(r == 0 || r == n){ return 1; } else if(r == 1){ return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r){ r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } int main(void){ ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<pair<ll,ll>> vec; rep(i, n){ vec.push_back({a[i], i}); } sort(all(vec)); ll ans = 0; rep(i, n){ if(i % 2 != vec[i].second % 2) ans++; } cout << ans / 2 << endl; }
0
35,419,070
#include <iostream> using namespace std; int main(){ int a,b,c,n; cin >> n; for (;0<n;n--){ cin >> a >> b >> c; if (a*a+b*b == c*c) cout << "YES" << endl; else if (a*a+c*c == b*b) cout << "YES" << endl; else if (b*b+c*c == a*a) cout << "YES" << endl; else cout << "NO" << endl; } }
#include <bits/stdc++.h> using namespace std; using vvll = vector<vector<long long>>; constexpr long long INF = 1e18; vvll warshall_floyd(const vvll & Es){ vvll dist(Es); for (int k = 0; k < Es.size(); ++k){ for (int i = 0; i < Es.size(); ++i){ if (dist[i][k] == INF) continue; for (int j = 0; j < Es.size(); ++j){ if (dist[k][j] == INF) continue; if (dist[i][j] > dist[i][k] + dist[k][j]){ dist[i][j] = dist[i][k] + dist[k][j]; } } } } return dist; } int main() { cin.tie(0); ios::sync_with_stdio(false); int V, E; cin >> V >> E; vvll Es(V, vector<long long>(V, INF)); for (int i = 0; i < V; ++i) Es[i][i] = 0; while (E--){ int s, t; long long d; cin >> s >> t >> d; Es[s][t] = d; } auto dist = warshall_floyd(Es); for (int i = 0; i < V; ++i){ if (dist[i][i] < 0){ cout << "NEGATIVE CYCLE" << endl; return 0; } } for (const auto & row : dist){ if (row[0] == INF) { cout << "INF"; } else { cout << row[0]; } for (int i = 1; i < row.size(); ++i) { if (row[i] == INF) { cout << " INF"; } else { cout << ' ' << row[i]; } } cout << '\n'; } return 0; }
0
13,063,876
#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <set> #include <queue> #include <map> #include <string> #include <stack> #include <bitset> #define rep(i, a, b) for ( int i = (a); i < (b); i++ ) #define per(i, a, b) for ( int i = (b)-1; i >= (a); i--) #define pb push_back #define mp make_pair #define bg begin() #define en end() #define all(v) (v).begin(), (v).end() #define sz(v) (int) (v).size() using namespace std; typedef long long ll; static const long long MOD = 1000000007; ll ans = 10000000000000; ll a[20]; int n, k; int main(void) { cin >> n >> k; rep(i, 0, n) scanf("%lld", &a[i]); for (int i=0; i<(1<<n); i++) { if (__builtin_popcount(i)!=k) continue; ll s = 0, sum = 0; for (int j=0; j<n; j++) { if ((i>>j)&1){ if (a[j]>s) { s = a[j]; } else { s++; sum += s - a[j]; } } else { s = max(s, a[j]); } } ans = min(ans, sum); } cout << ans << "\n"; return 0; }
#include <iostream> #include <string> #include <vector> #include <unordered_map> using namespace std; string makeString(long long x, long long y) { return to_string(x) + " " + to_string(y); } int main() { long long h,w,n; cin >> h >> w >> n; long long x,y; unordered_map<string, long long> m; for(long long i=0; i<n;i++){ cin >> x >> y; for(int j=0; j<3; j++){ if(x-j < 1 || x-j > h-2) continue; for(int k=0;k<3;k++){ if(y-k < 1 || y-k > w-2) continue; string s = makeString(x-j,y-k); if(m.find(s) == m.end()) { m[s] = 1; }else { m[s]++; } } } } vector<long long> v; for(int i=0;i<9;i++){ v.push_back(0); } for(auto it = m.begin(); it != m.end(); it++){ v[it->second-1]++; } long long sum = (h-2)*(w-2); for(int i=0;i<9;i++){ sum -= v[i]; } cout << sum << endl; for(int i=0;i<9;i++){ cout << v[i] << endl; } }
0
69,300,320
#include<bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long ll; typedef pair<ll,ll> P; const ll mod=1000000007; const ll LINF=1LL<<60; const int INF=1<<30; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main(){ int n;cin>>n; ll ans; for(int i = 0; i < n; i++) { ll a;cin>>a; if(i == 0){ ans = __gcd(a,a); } else{ ans = __gcd(ans,a); } } cout << ans << endl; return 0; }
#include<algorithm> #include<bitset> #include<cmath> #include<complex> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<iterator> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define PRINT(message) cout<<message<<endl #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define INF 1000000000000 #define MOD 1000000007 #define MAXR 100000 int D, G; int answer = std::numeric_limits<int>::max(); vector<int> p, c; unordered_map<int, int> mp; int main(){ int n; cin>>n; int a[n+2]; a[0]=0; a[n+1]=0; FOR(i,0,n) cin>>a[i+1]; int sum[n+2]; sum[0]=0; FOR(i,0,n+1){ sum[i+1]=sum[i]+abs(a[i+1]-a[i]); } int sum2[n+2]; sum2[0]=0; FOR(i,0,n+1){ sum2[i+1]=sum2[i]+abs(a[n+1-i]-a[n-i]); } FOR(i,1,n+1){ cout<<sum[i-1]+sum2[n-i]+abs(a[i-1]-a[i+1])<<endl; } }
0
16,742,907
#include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; k--; cout << n - k << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define ALL(x) x.begin(),x.end() #define get_tp(t,i) get<i>(t) #define len(x) (ll)(x.size()) typedef long long ll; typedef pair<int,int> pii; typedef pair<long long,long long> pllll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef priority_queue<int, vector<int>, greater<int> > gpq; typedef priority_queue<int> pq; const int MOD=1000000007; const long double PI=3.1415926535897932; int main(){ int A,B; cin>>A>>B; if(A<=8 && B<=8){ cout<<"Yay!"<<endl; }else{ cout<<":("<<endl; } }
0
71,849,249
#include <stdio.h> int main(){ long long int N; long long int g = 1; scanf("%lld", &N); long long int h[N]={}; for(long long int i=0;i<N;i++){ scanf("%lld", &h[i]); } for(int j=0;j<N;j++){ if (h[j] == 0){ printf("0"); return 0; } } for(int k=0;k<N;k++){ if (h[k] <= 1000000000000000000/g){ g *= h[k]; } else { printf("-1"); return 0; } } printf("%lld",g); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for(ll i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for (ll i = ((int)(n)-1); i >= 0; --i) #define whole(x) (x).begin(),(x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using P = pair<ll, ll>; #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}; const ll INF = 4E+18; int main(){ int n, k; cin >> n >> k; vector<P> v(n); rep(i, n) cin >> v[i].first >> v[i].second; auto comp = [](P a, P b) { return a.second < b.second; }; sort(whole(v), comp); ll ans = INF; rep(i, n) rep(j, n) { if (j-i<k-1) continue; vector<P> tmp; for (int l=i; l<=j; l++) { tmp.push_back(v[l]); } sort(whole(tmp)); ll dy = v[j].second - v[i].second; int ii = 0; int jj = k-1; while (jj<tmp.size()) { ll dx = tmp[jj].first - tmp[ii].first; chmin(ans, dx*dy); ii++; jj++; } } cout << ans << endl; return 0; }
0
58,914,709
#include <iostream> #include <string> using namespace std; int main(){ string s, p; cin >> s >> p; s += s; if(s.find(p) < s.length()) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int i = 0;i < (n);i++) #define FOR(i, a, b) for(int i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-6; template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;} template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;} const int64 mod = 1e9+7; int main(void){ int64 N, A, B, C, X; while(cin >> N >> A >> B >> C >> X && (N || A || B || C || X)){ vector<int64> y(N); REP(i, N) cin >> y[i]; int32 in = 0; int32 cnt = 0; while(in < N){ if(X == y[in]){ in++; if(in == N) break; } X = (X*A+B)%C; cnt++; if(cnt > 10000) break; } if(cnt > 10000) cout << -1 << endl; else cout << cnt << endl; } }
0
16,672,903
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<iomanip> using namespace std; int main(){ long long n,a,b; cin>>n>>a>>b; long long ans=(n/(a+b))*a+min(n%(a+b),a); cout<<ans<<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 vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; const ll mod = 1e9+7; ll f(ll a){ if (a==-1) return 0; if (a%4==3) return 0; if (a%4==1) return 1; if(a%4==2) return 1^a; else return 0^a; } int main(){FIN ll l,r;cin>>l>>r; ll ans = f(l-1)^f(r); cout<<ans<<endl; return 0; }
0
69,484,706
#include <bits/stdc++.h> using namespace std; using ll = long long int; using P = pair<int, int>; #define roop(i, n) for(int i = 0;i < n;i++) int main(void){ string a, b, c; cin >> a >> b >> c; char d = a[0]-('a'-'A'); char e = b[0]-('a'-'A'); char f = c[0]-('a'-'A'); cout << d << e << f << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = int64_t; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; int main() { string s; cin >> s; vector<ll> vv(26); rep(i, s.size()) { vv[s[i]-'a']++; } ll ans = 0LL; rep(i, 26) { ans += (s.size()-vv[i])*vv[i]; } ans /= 2LL; ++ans; cout << ans << endl; }
0
25,881,220
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long A[N+1],B[N+1],answer=0; A[0] = 0; B[0] = 0; for (int i = 1; i <= N; i++) { cin >> A[i]; B[i] = B[i-1]^A[i]; A[i] += A[i-1]; } for (int r = 1, l = 1; r <= N; r++) { while (A[r]-A[l-1] != (B[r]^B[l-1]) && l++); answer += r-l+1; } cout << answer; }
#include <iostream> #include <string> using namespace std; int main(void) { int a; string s, p; cin >> s >> p; s += s; a = s.find(p); if (a==-1) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; }
0
61,795,175
#include<bits/stdc++.h> using namespace std; #define int long long const int N=100000+50; signed main(){ ios::sync_with_stdio(false); int h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k; int total=((h2*60)+m2)-((h1*60)+m1); total-=k; if(total<0){ total=0; } cout<<total; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < n; ++i) using namespace std; typedef long long ll; #define MODSIZE 1000000007 int main(){ int n; char s[100006]; int f = 0; int fi = -1; int en = -1; scanf("%s", s); n = strlen(s); int i; for(i = 0;i < n - 1;i++){ if(s[i] == s[i + 1]){ f = 1; fi = i + 1; en = i + 2; } } if(f == 0){ for(i = 0;i < n - 2;i++){ if(s[i] == s[i + 2]){ f = 1; fi = i + 1; en = i + 3; } } } printf("%d %d\n", fi, en); return 0; }
0
99,255,343
#include <iostream> #include <vector> #include <utility> #include <algorithm> #include <cmath> #include <string> #include <map> #define pb push_back #define mp make_pair using namespace std; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef unsigned long long ull; typedef long long ll; int main() { string s, t; cin >> s >> t; string sr = s; bool ok = false; do { if (sr == t) { ok = true; break; } rotate(sr.begin(), sr.begin()+1, sr.end()); } while (s != sr); if (ok) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; int main() { int n; int c[500], s[500], f[500]; cin >> n; for (int i = 0; i < n - 1; i++) { cin >> c[i] >> s[i] >> f[i]; } for (int i = 0; i < n - 1; i++) { int now = 0; for (int j = i; j < n - 1; j++) { if (now <= s[j]) { now = s[j] + c[j]; } else { int co1 = 0; for (;;) { co1 += f[j]; if (now - co1 <= s[j]) { now = s[j] + c[j] + co1; break; } } } } cout << now << endl; } cout << "0" << endl; return 0; }
0
10,508,090
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; vector<int >pos(26,0); for(int i=0;i<s.length();i++){ pos[s[i]-'a']++; } int yes = 1; for(int i=0;i<26;i++){ if(pos[i]>1){yes=0;break;} } if(yes==1)cout<<"yes"; else cout<<"no"; }
#include<iostream> using namespace std; int main(){ int x,y; while(1){ cin>>x>>y; if(x<y){ cout<<x<<" "<<y<<endl; } else if(x>y){ cout<<y<<" "<<x<<endl; } else if(x==y&&x!=0) { cout<<x<<" "<<y<<endl; } else if(x==0&&y==0) {break;} } return 0; }
0
67,631,520
#include <iostream> #include <algorithm> #include <bitset> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <cstring> #include <utility> #include <vector> #include <complex> #include <valarray> #include <fstream> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <climits> #include <random> #define _overload(a, b, c, d, ...) d #define _rep1(X, A, Y) for (int X = (A); X <= (Y);++X) #define _rep2(X, Y) for (int X = 0; X < (Y); ++X) #define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__) #define rrep(X, Y) for (int X = (Y-1); X >= 0; --X) #define all(X) (X).begin(),(X).end() #define len(X) ((int)(X).size()) #define mod(n, m) (((n)%(m)+(m))%(m)) #define fi first #define sc second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; const int INFINT = 1 << 30; const ll INFLL = 1LL << 60; const double EPS = 1e-10; const int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int N, M; int main() { cin >> N >> M; if (M % 2 == 0) { rep(i, M / 2) { cout << i + 1 << ' ' << M + 1 - i << endl; } rep(i, M / 2) { cout << M + 2 + i << ' ' << 2 * M + 1 - i << endl; } } else { rep(i, M / 2) { cout << 1 + i << ' ' << M - i << endl; } rep(i, (M + 1) / 2) { cout << M + 1 + i << ' ' << 2 * M + 1 - i << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 305; int n, K, h[maxn]; ll dp[maxn][maxn][maxn]; ll INF = 1e18; void amin(ll& a, ll b) { a = min(a,b); } ll f(int i, int j, int k) { if (i == n+1) return h[j]; ll& res = dp[i][j][k]; if (res >= 0) return res; res = INF; if (h[i] > h[j]) { amin(res,f(i+1,i,k)); if (k > 0) { amin(res,f(i+1,j,k-1)); } } else if (h[i] < h[j]) { amin(res,h[j]-h[i]+f(i+1,i,k)); if (k > 0) { amin(res,f(i+1,j,k-1)); } } else { amin(res,f(i+1,j,k)); } return res; } int main() { cin >> n >> K; for (int i = 1; i <= n; i++) { cin >> h[i]; } memset(dp,-1,sizeof dp); ll ans = f(1,0,K); cout << ans << '\n'; }
0
38,711,266
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #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 all(x) (x).begin(),(x).end() using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } struct edge { int to, cost; }; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> P; const int INF = 1e9; const int MOD = 1e9+7; const double EPS = 1.0e-10; const double PI = acos(-1.0); const int mx4[] = {0,1,0,-1}; const int my4[] = {1,0,-1,0}; const int mx8[] = {0,1,1,1,0,-1,-1,-1}; const int my8[] = {1,1,0,-1,-1,-1,0,1}; int main(){ int n,k; cin >> n >> k; if((n-2)*(n-1)/2 < k){ cout << -1 << endl; }else{ int tmp = (n-2)*(n-1)/2-k; cout << n-1+tmp << endl; for(int i = 2; i <= n; i++) cout << 1 << " " << i << endl; for(int i = 2; i <= n; i++){ if(tmp<=0) break; for(int j = i+1; j <= n; j++){ cout << i << " " << j << endl; if(--tmp<=0) break; } } } return 0; }
#include<bits/stdc++.h> using namespace std; const long long INF = 1000000000; typedef long long ll; #define writeln(n) cout<<n<<"\n" #define rep(i,n) for(int i=0; i<(n); ++i) typedef pair<int, int> P; typedef pair<string, int> Psi; int main() { cin.tie(0); ios::sync_with_stdio(false); int r,d,x;cin>>r>>d>>x; rep(i,10){ x = r*x-d; writeln(x); } }
0
6,207,948
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main(){ ll n,k; cin >> n >> k; ll p=n/k; ll q=0; if(k%2==0){ ll p=k/2; while(p<=n){ p+=k; q++; } } ll ans=q*q*q+p*p*p; cout << ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define P pair<ll, ll> #define FOR(i, n, m) for (ll i = n; i < (ll)m; i++) #define FORr(i, m, n) for (ll i = n; i >= (ll)m; i--) #define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++) #define sortAl(v) sort(v.begin(), v.end()) #define sortAlr(v) \ sort(v.begin(), v.end()); \ reverse(v.begin(), v.end()) #define cout(n) cout << fixed << setprecision(n) #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i < n; i++) #define all(v) v.begin(), v.end() 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 (int)(1e9 + 7) #define INF LLONG_MAX int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; if (N % K == 0) { cout << 0 << endl; } else { cout << 1 << endl; } return 0; }
0
5,849,657
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) int main(){ int A,B,m,x,y,c,mn=2e5; cin >> A >> B >> m; vector<int> a(A),b(B); rep(i,A)cin >> a.at(i); rep(i,B)cin >> b.at(i); rep(i,m){ cin >> x >> y >> c; mn=min(a.at(x-1)+b.at(y-1)-c,mn); } sort(a.begin(),a.end()); sort(b.begin(),b.end()); mn=min(mn,a.at(0)+b.at(0)); cout << mn << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) typedef int64_t Int; Int power(Int a, Int n){ Int MOD = 1e9+7; if(a == 0) return 0; if(n == 0) return 1; Int res = 1; while(n > 0){ if(n % 2 == 1) res = res * a % MOD; a = a * a % MOD; n /= 2; } return res; } int main(){ int N; cin >> N; vector<Int> A(N+1); rep(i,N+1) cin >> A[i]; if(N == 0 && A[0] != 1) {cout << -1 << endl; return 0;} vector<pair<Int,Int>> minmax_v(N+1); minmax_v[N] = {A[N], A[N]}; for(int d = N-1; d>=0; d--){ Int M = minmax_v[d+1].second + A[d]; Int m = max((Int)1, minmax_v[d+1].first/2 + A[d]); if(d < 30 && m > power(2,d)) {cout << -1 << endl; return 0;} minmax_v[d] = {m,M}; } vector<Int> v(N+1); Int ans = 1; v[0] = 1; rep1(d,N){ v[d] = min((v[d-1]-A[d-1]) * 2, minmax_v[d].second); if(d < 30) v[d] = min(v[d], power(2,d)); if(v[d] < A[d]) {cout << -1 << endl; return 0;} ans += v[d]; } cout << ans << endl; }
0
48,927,292
#include <iostream> #include <iomanip> #include <string> #include <sstream> #include <stdio.h> #include <string.h> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <cmath> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> using namespace std; int main(){ int N; cin >> N; double ans = 0.0,a; for(int i = 0;i < N;i++){ cin >> a; ans += 1.0/a; } ans = 1.0/ans; cout << fixed << setprecision(16) << ans << endl; }
#include <bits/stdc++.h> #include <stdio.h> int max(int a, int b) { return a > b ? a : b; } int main(void) { using namespace std; int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a.at(i); } int res = 0; for (int i = 0; i < n - 1; ++i) { for (int j = i + 1; j < n; ++j) { res = max(res, abs(a.at(j) - a.at(i))); } } cout << res << endl; return 0; }
0
12,034,528
#include <iostream> using namespace std; int main() { int t1 = 0; int t2 = 0; int t3 = 0; for (int i = 0; i < 10; i++) { int h; cin >> h; if (t1 < h) { t3 = t2; t2 = t1; t1 = h; } else if (t2 < h) { t3 = t2; t2 = h; } else if (t3 < h) { t3 = h; } } cout << t1 << endl; cout << t2 << endl; cout << t3 << endl; return 0; }
#include<stdio.h> #include<string.h> #include<math.h> #include<deque> #include<queue> #include<stack> #include<bitset> #include<string> #include<iostream> #include<algorithm> using namespace std; #define ll long long #define INF 0x3f3f3f3f #define clean(a,b) memset(a,b,sizeof(a)) #define mod 1000000 int shuzu[15][15]; int shuaxin[15]; bool biaoji[15]; int maxx[15]; int n; void prime(int x) { clean(biaoji,0); clean(shuaxin,INF); shuaxin[x]=0; for(int i=0;i<n;++i) { int can=-1; int min=INF; for(int j=0;j<n;++j) { if(biaoji[j]==0&&shuaxin[j]<min) { can=j; min=shuaxin[j]; } } if(can==-1) break; biaoji[can]=1; for(int j=0;j<n;++j) { if(biaoji[j]==0&&shuzu[can][j]+shuaxin[can]<shuaxin[j]) shuaxin[j]=shuzu[can][j]+shuaxin[can]; } } } int main() { int t; while(cin>>t&&t!=0) { n=0; clean(shuzu,INF); for(int i=0;i<t;++i) { int s,e,l; cin>>s>>e>>l; shuzu[s][e]=l; shuzu[e][s]=l; n=n>s?n:s; n=n>e?n:e; } n++; for(int i=0;i<n;++i) shuzu[i][i]=0; clean(maxx,0); for(int i=0;i<n;++i) { prime(i); for(int j=0;j<n;++j) maxx[i]=maxx[i]+shuaxin[j]; } int res=0,resl=maxx[0]; for(int i=0;i<n;++i) { if(maxx[i]<resl) { resl=maxx[i]; res=i; } } cout<<res<<" "<<resl<<endl; } }
0
23,535,363
#include<iostream> #include<string> #include<cctype> using namespace std; int main( ) { string str; int i; while( true ) { getline( cin, str ); if( '0' == str[0] ) { break; } int sum = 0; for( i=0; '\0'!=str[i]; i++ ) { if( isdigit( str[i] ) ) { sum += ( str[i]-'0' ); } } cout<<sum<<endl; } return 0; }
#include <iostream> #include <cmath> using namespace std; const int Max = 100; const int Min = -100; int main() { int W, H, x, y, r; cin >> W >> H >> x >> y >> r; if((W > 0 && W <= Max) && (H > 0 && H <= Max) && (r > 0 && r <= Max)) { if((0 <= (x-r)) && (0 <= (y-r)) && ((x+r) <= W) && ((y+r) <= H)) cout << "Yes"; else cout << "No"; cout << endl; } else cout << "No" << endl; return 0; }
0
16,474,813
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define MAXN 40005 #define eps 1e-12 using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } string s; int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif cin >> s; if(s.substr(0,4) == "YAKI") puts("Yes"); else puts("No"); }
#include<bits/stdc++.h> #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define all(x) (x).begin(),(x).end() #define mp make_pair #define pb push_back #define F first #define S second #define forN(i, n) for(int i = 0; i <n ; ++i) #define endl "\n" #define noob (main) typedef long long ll; using namespace std; typedef vector<ll> vi; const ll INF = 1e18; const ll MOD = 1e9 + 7; const int N = 1e7 +100 ; bool prime[N]; vector<ll>v; int noob(){ fastIO; int n ; cin>>n; string s; cin>>s; if(n%2){ cout<<"No"; return 0; } string s1 = s.substr(0,n/2); string s2 = s.substr(((n/2))); if(s1==s2){ cout<<"Yes"; } else cout<<"No"; }
0
56,357,485
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; #define rep(a,n) for(ll a = 0;a < n;a++) #define repi(a,b,n) for(ll a = b;a < n;a++) using namespace std; static const ll INF = 1e15; template<typename T> static inline void chmin(T & ref, const T value) { if (ref > value) ref = value; } template<typename T> static inline void chmax(T & ref, const T value) { if (ref < value) ref = value; } template <typename X, typename M> struct SegTreeLazyProportional { using FX = function<X(X, X)>; using FA = function<X(X, M)>; using FM = function<M(M, M)>; using FP = function<M(M, int)>; private: int n; FX query_Value_; FA merge_data_and_lazy_; FM updateLazy_; FP evaluateLazyLength_; const X defaultData_; vector<X> data_; const M defaultLazy_; vector<M> lazy_; public: SegTreeLazyProportional(int n_, FX query_value, FA merge_data_and_lazy, FM updateLazy, FP evaluateLazyLength, X defaultData, M defaultLazy) : n(), query_Value_(query_value), merge_data_and_lazy_(merge_data_and_lazy), updateLazy_(updateLazy), evaluateLazyLength_(evaluateLazyLength), defaultData_(defaultData), defaultLazy_(defaultLazy), data_(n_ * 4, defaultData_), lazy_(n_ * 4, defaultLazy_) { int x = 1; while (n_ > x) x *= 2; n = x; } void set(int i, X x) { data_[i + n - 1] = x; } void build() { for (int k = n - 2; k >= 0; k--) data_[k] = query_Value_(data_[2 * k + 1], data_[2 * k + 2]); } void update(int a, int b, M x) { update(a, b, x, 0, 0, n); } X query(int a, int b) { return query_sub(a, b, 0, 0, n); } private: void eval(int k, int len) { if (lazy_[k] == defaultLazy_) return; if (k < n - 1) { lazy_[k * 2 + 1] = updateLazy_(lazy_[k * 2 + 1], lazy_[k]); lazy_[k * 2 + 2] = updateLazy_(lazy_[k * 2 + 2], lazy_[k]); } data_[k] = merge_data_and_lazy_(data_[k], evaluateLazyLength_(lazy_[k], len)); lazy_[k] = defaultLazy_; } void update(int a, int b, M x, int k, int l, int r) { eval(k, r - l); if (a <= l && r <= b) { lazy_[k] = updateLazy_(lazy_[k], x); eval(k, r - l); } else if (a < r && l < b) { update(a, b, x, k * 2 + 1, l, (l + r) / 2); update(a, b, x, k * 2 + 2, (l + r) / 2, r); data_[k] = query_Value_(data_[k * 2 + 1], data_[k * 2 + 2]); } } X query_sub(int a, int b, int k, int l, int r) { eval(k, r - l); if (r <= a || b <= l) { return defaultData_; } else if (a <= l && r <= b) { return data_[k]; } else { X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return query_Value_(vl, vr); } } }; ll mpow(ll x, ll n, ll m) { ll ans = 1; x %= m; while (n != 0) { if (n & 1) ans = ans * x % m; x = x * x % m; n = n >> 1; } return ans; } SegTreeLazyProportional<ll, ll> RangeSetQueryMin(int n) { auto queryValue = [=](ll left, ll right) -> ll { return min(left, right); }; auto updateValue = [=](ll old, ll next) -> ll { return min(old, next); }; auto merge = [=](ll source, ll lazyValue) -> ll { return min(source, lazyValue); }; auto evaluate_lazy_length = [=](ll lazyValue, ll length) -> ll { return lazyValue; }; ll defaultValue_ = 0; SegTreeLazyProportional<ll, ll> rmq(n, queryValue, merge, updateValue, evaluate_lazy_length, std::numeric_limits<ll>::max(), 1e15); return rmq; } ll lpow(ll seed, int n) { ll c = 1; for (int i = 0; i < n; i++) { c *= seed; } return c; } ll naive(ll n) { ll two = 0; ll five = 0; while (n > 0) { ll c = n; while (c % 2 == 0) { c /= 2; two++; } while (c % 5 == 0) { c /= 5; five++; } n -= 2; } return min(two, five); } ll fast(ll n) { ll sum = 0; for (int i = 0; 10 * lpow(5, i) <= n; i++) { auto d = 10 *lpow(5, i); sum += n / d; } return sum; } int main() { ll n; cin >> n; if (n % 2 == 1) { cout << 0 << endl; return 0; } ll sum = fast(n); cout << sum << endl; return 0; }
#include <iostream> #include <map> #include <cmath> #include <ios> #include <iomanip> #include <algorithm> #include <queue> #include <stack> #include <numeric> using namespace std; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; template<class T> using VVV = V<VV<T>>; template<class T1, class T2> using P = pair<T1, T2>; using I = int; using D = double; using B = bool; using C = char; using S = string; using LL = long long; using LD = long double; using ULL = unsigned long long; using PII = P<I, I>; using VPII = V<PII>; using PLL = P<LL, LL>; using VPLL = V<PLL>; using VI = V<I>; using VVI = VV<I>; using VLL = V<LL>; using VVLL = VV<LL>; using VC = V<C>; using VVC = VV<C>; using VS = V<S>; using VVS = VV<S>; using VB = V<B>; using VVB = VV<B>; #define REP(type, i, n) for (type i = 0; i < (type)(n); ++i) #define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i) #define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i) #define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i) #define REPx(x, a) for(auto x : a) #define ALL(a) a.begin(), a.end() #define SORT(a) sort(ALL(a)) #define SORTR(a, type) sort(ALL(a), greater<type>()) #define SORTF(a, comp) sort(ALL(a), comp) #define REVERSE(a) reverse(ALL(a)) #define SIZE(a, type) ((type)(a).size()) #define bit_search(bit, n) REP(LL, bit, 1LL<<(n)) #define bit_check(bit, i) ((bit>>(i)) & 1) #define setpre(n) fixed << setprecision((n)) #define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0) #define MAX(a) *max_element(ALL(a)) #define MIN(a) *min_element(ALL(a)) #define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin()) #define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin()) #define INPUT(a) REPx(&x, a) cin >> x; #define INPUT2(a) REPx(&x, a) INPUT(x); #define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second; #define ENDL cout << endl; const int INF = 2e9; const LL MOD = 1e9+7; template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >; 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;} template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL} template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}} int main() { cin.tie(0); ios::sync_with_stdio(false); LL n, ans = 0; cin >> n; VLL A(n), B(n); REP(int, i, n) cin >> A[i] >> B[i]; REPR(int, i, n) if ((A[i]+ans) % B[i]) ans += B[i] - ((A[i]+ans) % B[i]); cout << ans << endl; return 0; }
0
66,003,342
#include <bits/stdc++.h> using namespace std; #define forn for (ll i = 0; i < n; i++) #define form for (ll j = 0; j < m; j++) #define NO cout << "NO\n"; #define YES cout << "YES\n"; #define pb push_back #define mp make_pair #define rep(i,a,b) for (ll i = a; i < b; i++) typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> pi; ll gcd(ll a, ll b){ ll r; while (b != 0){ r = a % b; a = b; b = r; } return a; } ll *calc_z(string s){ ll n = s.size(); ll *z = new ll[n] {0}; ll l = 0, r = 0; for (ll i = 1; i < n; i++){ if (r >= i) z[i] = min(z[i-l], r-i+1); while (z[i]+i < n && s[z[i]] == s[z[i]+i]) z[i]++; if (i + z[i] - 1 > r){ l = i; r = i+z[i]-1; } } return z; } ll find_lower(ll *a, ll n, ll v){ ll l = -1, r = n; while (r>l+1){ ll m = (l+r)/2; if (a[m] >= v) r = m; else l = m; } if (r == n) return n-1; if (a[r] == v) return r; return r == 0 ? 0 : r-1; } void init(){ } int bin(int *p, int n, int x){ int l = 0, r = n-1; while (r >= l){ int m = (l+r)/2; if (p[m] == x) return m; if (p[m] > x) r = m-1; else l = m+1; } return -1; } void solve(){ int n; cin >> n; int *a = new int[n]; int *m = new int[ (int) 1e6+1]; memset(m, 0, 1e6+1); forn{ cin >> a[i]; m[a[i]]++; } int c = 0; bool flag; forn{ flag = true; for (int j = 2; j*j<=a[i]; j++){ if (a[i] % j == 0){ if (m[j] || m[a[i]/j]){ flag = false; break; } } } if (a[i] == 1 && m[1] <= 1) c++; else if (m[1] == 0 && m[a[i]] == 1 && flag) c++; } cout << c << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c,k,k1=0; cin >> a >> b >> c >> k; while (a >= b){ b = b*2; k1++; } while (b >= c){ c = c*2; k1++; } if (k1 <= k) cout << "Yes\n"; else cout << "No\n"; return 0; }
0
65,475,718
#include <bits/stdc++.h> #define ll long long #define pi (acos(-1)) #define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i) using namespace std; std::vector<unsigned ll> genprimevec(const unsigned ll N); int main() { int n; cin>>n;string s,t; cin>>s>>t; string ans; rep(i,n){ ans.push_back(s[i]); ans.push_back(t[i]); } cout<<ans<<endl; return 0; } /*author https: ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } std::vector<unsigned ll> genprimevec(const unsigned ll N) { std::vector<bool> is_prime(N + 1); for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; } std::vector<unsigned ll> P; for (unsigned ll i = 2; i <= N; i++) { if (is_prime[i]) { for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; } P.emplace_back(i); } } return P; }
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <string> #include <sstream> #include <complex> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #define rep(i, n) for(int i = 0;i < n;i++) #define reprb(i, n) for(int i = n;i >= 0;i--) #define reps(i, m, n) for(int i = m;i < n;i++) #define repsb(i, m, n) for(int i = m;i >= n;i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) #define INF 999999999 using namespace std; vector<int> a; int main(int argc,char * argv[]) { int n,in,mi=0; while(true) { cin>>n; if(n==0) break; rep(i,n){ cin>>in; a.pb(in); mi=max(mi,in); } rep(i,n){ rep(j,n){ if(i!=j) mi=min(mi,abs(a[i]-a[j])); } } cout<<mi<<endl; a.clear(); } return 0; }
0
85,999,397
#include "bits/stdc++.h" using namespace std; typedef long long ll; double power(double a , ll b) { double ans = 1; while (b) { if (b & 1) { ans = ans * a; } a = a * a; b /= 2; } return ans; } int main() { int n, k; cin >> n >> k; vector<int> v(n + 1); for (int i = 0; i < n; ++i) { cin >> v[i]; } v[n] = k; sort(v.begin(),v.end()); vector<int> ans(n); for (int i = 1; i <= n; ++i) { ans[i - 1] = v[i] - v[i - 1]; } int g = 0; for (int i = 0; i < n; ++i) { g = __gcd(ans[i],g); } cout << g; }
#include<iostream> using namespace std; int main(){ int n; cin>>n; int b,f,r,v; int one[3][10]; int two[3][10]; int three[3][10]; int four[3][10]; for(int i=0;i<3;i++){ for(int j=0;j<10;j++){ one[i][j]=0; two[i][j]=0; three[i][j]=0; four[i][j]=0; } } for(int i=0;i<n;i++){ cin>>b>>f>>r>>v; if(b==1){ one[f-1][r-1]+=v; }else if(b==2){ two[f-1][r-1]+=v; }else if(b==3){ three[f-1][r-1]+=v; }else { four[f-1][r-1]+=v; } } for(int i=0;i<3;i++){ for(int j=0;j<10;j++){ if(one[i][j]<0)one[i][j]=0; if(two[i][j]<0)two[i][j]=0; if(three[i][j]<0)three[i][j]=0; if(four[i][j]<0)four[i][j]=0; } } for(int i=0;i<4;i++){ for(int j=0;j<3;j++){ for(int k=0;k<10;k++){ if(i==0) cout<<" "<<one[j][k]; else if(i==1)cout<<" "<<two[j][k]; else if(i==2)cout<<" "<<three[j][k]; else cout<<" "<<four[j][k]; } cout<<endl; } if(i<3)cout<<"####################"<<endl; } return 0; }
0
58,525,044
#include <bits/stdc++.h> #define mod 1000000007 #define INF LLONG_MAX #define ll long long #define ln cout<<endl #define Yes cout<<"Yes"<<endl #define NO cout<<"NO"<<endl #define YES cout<<"YES"<<endl #define No cout<<"No"<<endl #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using namespace std; ll dx[4]={1,0,-1,0}; ll dy[4]={0,1,0,-1}; typedef pair<ll,ll> P; bool comp(pair<ll, ll> a, pair<ll , ll> b) { if(a.first != b.first){ return a.first < b.first; } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll maxi=0,f=0,sum=0,mini=INF; string str,str1,str2; ll i; double h; ll n,x,m; ll a,b,d,c,k; cin>>n>>k; vector<P> p(n); rep(i,n){ cin>>a>>b; p[i]=P(a,b); } sort(all(p),comp); rep(i,n){ sum+=p[i].second; if(sum>=k){ cout<<p[i].first<<endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define whole(x) (x).begin(),(x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using P = pair<int, int>; #define debug(var) cerr << "[" << #var << "] " << var << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) const ll mod = 1000000007; const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1}; int main(){ int n; string s; cin >> n >> s; string ans = ""; vector<int> v(n); int z = 0; rep(i, n) { if (i==0) { if (s[i]=='(') v[i] = 1; else v[i] = -1; } else { if (s[i]=='(') v[i] = v[i-1] + 1; else v[i] = v[i-1] - 1; } chmin(z, v[i]); } rep(i, abs(z)) cout << '('; cout << s; rep(i, v[n-1]+abs(z)) cout << ')'; cout << endl; return 0; }
0
85,061,073
#include<iostream> using namespace std; #include <ctype.h> int main(){ char c; cin >> c; if (isupper(c)) c = 'A'; else c = 'a'; cout << c << endl; }
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <string> using namespace std; long long LCM(long long c,long long d){ long long res=d; if(c%d!=0)res=LCM(d,c%d); return res; } int main() { clock_t cTimeStart, cTimeEnd; cTimeStart = clock(); string str; cin>>str; int len=str.size(); for(int i=0;i<len;++i){ cout<<str[len-i-1]; } cout<<endl; cTimeEnd = clock(); return 0; }
0
11,985,232
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; ++i) #define per(i, a, b) for (int i = a; i >= b; i--) #define ll long long #define mset(s, _) memset(s, _, sizeof s) #define ALL(a) (a).begin(), (a).end() using namespace std; int main(void) { int L; cin >> L; double x = L / 3.0; double y = L / 3.0; double z = L / 3.0; printf("%.10lf", x * y * z); return 0; }
#include <iostream> int map[18][18]={}; int a,b; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); while(true){ std::cin>>a>>b; if(a==0&&b==0)break; int n; std::cin>>n; int x[41],y[41]; for (int i=0; i<n; ++i) { std::cin>>x[i]>>y[i]; map[x[i]][y[i]]=-1; } map[1][1]=1; for(int i=1;i<=a;++i) { for(int j=1;j<=b;++j) { if(map[i][j]==-1)continue; if(map[i-1][j]!=-1)map[i][j]+=map[i-1][j]; if(map[i][j-1]!=-1)map[i][j]+=map[i][j-1]; } } std::cout<<map[a][b]<<"\n"; for(int i=1;i<=a;++i) { for(int j=1;j<=b;++j) { map[i][j]=0; } } } return 0; }
0
82,784,501
#include <iostream> #include <string.h> using namespace std; char cStr[21]; bool input() { scanf("%s", cStr); return true; } void manage() { int i; char tmp; for (i = 0; i < (int)string(cStr).size() / 2; i++) { tmp = cStr[i]; cStr[i] = cStr[string(cStr).size() - i - 1]; cStr[string(cStr).size() - i - 1] = tmp; } } int main() { input(); manage(); printf("%s\n", cStr); return 0; }
#include"bits/stdc++.h" using namespace std; #define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++) #define rep(i,n) REP((i),0,(n)) using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using tp3 = tuple<int, int, int>; using Mat = vector<vector<ll>>; constexpr int INF = 1 << 28; constexpr ll INFL = 1ll << 60; constexpr int dh[4] = { 0,1,0,-1 }; constexpr int dw[4] = { -1,0,1,0 }; bool isin(const int H, const int W, const int h, const int w) { return 0 <= h && h < H && 0 <= w && w < W; } constexpr int SIZE = 26; using ALPHA = int; vector<ALPHA> parse_bits(const string& s) { const int len = s.size(); vector<ALPHA> res(len + 1, 0); rep(i, len) { int idx = s[i] - 'a'; ALPHA buf(1 << idx); res[i + 1] = res[i] ^ buf; } return res; } map<ALPHA, set<int>> compress(const vector<ALPHA>& bits) { map<ALPHA, set<int>> mp; rep(i, bits.size())mp[bits[i]].insert(i); return mp; } set<ALPHA> make_nexts(ALPHA bit) { set<ALPHA> st; rep(i, SIZE) { ALPHA buf(1 << i); bit ^= buf; st.insert(bit); bit ^= buf; } return st; } int solve(string s) { auto bits = parse_bits(s); auto mp = compress(bits); const int len = s.size(); vector<int> dp(len + 1, INF); dp[0] = 0; rep(i, len) { [&]() { auto itr = mp[bits[i]].upper_bound(i); if (itr != mp[bits[i]].end()) { int idx = *itr; dp[idx] = min(dp[idx], dp[i] + 0); } }(); [&]() { auto nexts = make_nexts(bits[i]); for (auto next : nexts) { if (mp.find(next) == mp.end())continue; auto itr = mp[next].lower_bound(i); if (itr != mp[next].end()) { int idx = *itr; dp[idx] = min(dp[idx], dp[i] + 1); } } }(); } int res = dp.back(); return res == 0 ? 1 : res; } int main() { string s; cin >> s; cout << solve(s) << endl; return 0; }
0
63,204,323
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> V; #define rep(i,e) for(ll i=0;i<e;i++ ) typedef pair<ll,ll> P; const ll mod = 1e9+7; const ll INF = INT64_MAX; ll i; int main(){ string A,B,C; cin>>A>>B>>C; if(A.at(A.length()-1)==B.at(0)&&B.at(B.length()-1)==C.at(0))cout<<"YES"; else cout<<"NO"; cout<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ALL(A) A.begin(),A.end() void ALLIN1_NUMBER(vector<ll>& V) { for(auto& x : V) { cin >> x; } } void ALLOUT2_WITHOUT_SPACE(vector<vector<ll>> V) { ll Vsize = V.size(); ll Visize = V[0].size(); for(ll i=0;i<Vsize;i++) { for(ll j=0;j<Visize;j++) { cout << V[i][j]; } cout << endl; } } template<class T> void OUT0(T N) { cout << N << endl; } static const double pi = acos(-1.0); double Cos(double D) { return cos(pi/180 * D); } pair<ll,ll> Graph(ll H, ll W, ll A, ll B) { for(ll i=H;i>=0;i--) { for(ll j=W;j>=0;j--) { if(A*H + (W-2*A)*i == B*W + (H-2*B)*j) { return make_pair(i,j); } } } return make_pair(-1,-1); } void Ans_OUT(ll H, ll W, ll A, ll B, pair<ll,ll> notA_notB) { if(notA_notB.first == -1) { OUT0("No"); } else { vector<ll> tate(H,A); for(ll i=0;i<notA_notB.first;i++) { tate[i] = W-A; } vector<ll> yoko(W,B); for(ll i=0;i<notA_notB.second;i++) { yoko[i] = H-B; } vector<vector<ll>> graph(H,vector<ll>(W,0)); for(ll i=0;i<H;i++) { for(ll j=0;j<W;j++) { if(tate[i]>0 && yoko[j]>0) { graph[i][j] = 1; tate[i]--; yoko[j]--; } } } ALLOUT2_WITHOUT_SPACE(graph); } } int main() { ll H,W,A,B; cin >> H >> W >> A >> B; pair<ll,ll> notA_notB = Graph(H,W,A,B); Ans_OUT(H,W,A,B,notA_notB); return 0; }
0
75,263,642
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<vector> #include<utility> #include<queue> #include<deque> #include<stack> #include<set> #include<map> #include<bitset> #include<string> #define mod 1000000007 typedef long long ll; using namespace std; ll S[100100]; int main(){ ll n,m; cin >> n >> m; ll A[100100]; S[0] = 0; for(int i=1;i<=n;i++){ cin >> A[i]; S[i] = (S[i-1] + A[i]) % m; } map<ll,ll> mp; ll ans = 0; mp[S[0]]++; for(int i=1;i<=n;i++){ mp[S[i]%m]++; } for(auto itr = mp.begin();itr != mp.end();itr++){ ans += itr->second * (itr->second - 1) / 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int H; cin >> H; vector<int> v(H + 1); for (int i = 1; i <= H; i++) { cin >> v[i]; } for (int i = 1; i <= H; i++) { int val = v[i]; int pa = -INT_MAX; int left = -INT_MAX, right = -INT_MAX; if (i * 2 <= H) { left = v[i * 2]; } if (i * 2 + 1 <= H) { right = v[i * 2 + 1]; } if (i / 2 > 0) pa = v[i / 2]; cout << "node " << i << ": key = " << val << ", "; if (pa != -INT_MAX) cout << "parent key = " << pa << ", "; if (left != -INT_MAX) cout << "left key = " << left << ", "; if (right != -INT_MAX) cout << "right key = " << right << ", "; cout << endl; } }
0
3,334,493
#include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <bitset> #include <queue> #include <iomanip> using namespace std; using ll = long long int; using i64 = int64_t; using P = pair<int, int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) const ll INF = 1LL << 60; int mod = (int)1e9 + 7; int main() { i64 n; cin >> n; i64 l[86 + 1]; l[0] = 2; l[1] = 1; for(int i = 2;i <= n;i++) l[i] = l[i-1] + l[i-2]; cout << l[n] << endl; }
#include<bits/stdc++.h> using namespace std; #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(12); #define randomINT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define newl cout<<"\n" #define DISP(as) for(auto it : as) cout<<it<<" ";newl; #define all(x) (x).begin(),(x).end() #define mset(x,val) memset(x,val,sizeof(x)) #define newl cout<<"\n" #define pb push_back #define mp make_pair #define f first #define s second #define dline cerr<<" #define deb1(x) cerr<<#x<<" = "<<x<<'\n'; #define deb2(x,y) cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n'; #define deb3(x,y,z) cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n'; typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll , ll> pll; typedef pair<ld, ld> pld; typedef unordered_map<ll, ll> um; typedef vector<pll> vpll; const ll MAX5 = 1e+5 + 7; const ll MAX7 = 1e+7 + 7; const ll MAXN = MAX7; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const ll MOD = 998244353; ll T = 1; ll n, q, x, K; string s,t; void MAIN() { cin>>s; vll cnt(26,0); for(auto ch : s) cnt[ch-'a']++; for(ll i=0;i<26;i++) { if(cnt[i]==0) { cout<<(char)(i+'a');return; } } cout<<"None"; } int main() { fastio; randomINT; while (T--) { MAIN(); } return 0; }
0
76,958,015
#include "bits/stdc++.h" using namespace std; int main() { long N, M, V, P; cin >> N >> M >> V >> P; vector<long> A(N); for (auto& x : A) { cin >> x; } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); long h = 1; while (h < N) { h *= 2; } long t = h / 2; long step = h / 2; while (step > 0) { if (t >= N) { step = step / 2; if (step == 0) { t--; break; } t -= step; continue; } long voted = N - t + P - 1; long box = 0; long flg = 1; for (int i = t - 1; i >= P - 1; i--) { box += A[t] + M - A[i]; if (A[t] + M - A[i] < 0) { flg = -1; break; } } voted = N - t + P - 1 + box / M; step = step / 2; if (voted >= V && flg==1) { t += step; } else { if (step == 0) { t--; break; } t -= step; } } cout << t + 1; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define all(x) (x).begin(),(x).end() #define cyes cout<<"YES"<<endl #define cno cout<<"NO"<<endl #define sp <<" "<< #define cst(x) cout<<fixed<<setprecision(x) #define pi 3.14159265359 #define mod 1000000007 template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using namespace std; using ll = long long; using ld = long double; using Graph = vector<vector<int>>; using que_a = priority_queue<int, vector<int>, greater<int> >; using que_d = priority_queue<int>; using pint = pair<int,int>; int main(){ int n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a.at(i); ll cnt = 0; rep(i,n-1){ cnt += a.at(i)/2; a.at(i) = a.at(i)%2; int temp; temp = min(a.at(i),a.at(i+1)); cnt += temp; a.at(i+1) -= temp; } cnt += a.at(n-1)/2; cout << cnt << endl; return 0; }
0
10,415,119
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <math.h> #include <set> using namespace std; #define ll long long int #define rep(i, n) for(int i = 0; i < n; i++) #define repp(i, n) for(int i = 1; i <= n; i++) #define sort(v) sort((v).begin(), (v).end()) using vi = vector<int>; const int MOD = 1e9 + 7; bool IsPrime(int num){ if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } int main() { int N, M; cin >> N >> M; bool frag; vector<string> A(N); vector<string> B(M); rep(i, N) cin >> A[i]; rep(i, M) cin >> B[i]; rep(i, N - M+1) { rep(j, N - M+1) { frag = true; rep(k, M) { if (A[i + k].substr(j, M) != B[k]) { frag = false; break; } } if (frag)break; } if (frag) break; } if (frag) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,n-1,0) #define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++) #define repl(i,n) REPL(i,0,n) #define all(v) v.begin(), v.end() const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; #define MAX_N 40 int main() { int N, K; cin >> N >> K; vector<ll> A(N), sum(N+1); rep(i, N) { cin >> A[i]; sum[i+1] = sum[i] + A[i]; } vector<ll> B; rep(l, N+1) REP(r, l+1, N+1) B.push_back(sum[r]-sum[l]); int M = B.size(); vector<vector<int>> D(M, vector<int>(MAX_N)); rep(k, MAX_N) { rep(i, M) { D[i][MAX_N-1-k] = (B[i]>>k)&1; } } vector<set<int>> vse(2); rep(i, M) vse[0].insert(i); ll ans = 0; ll pw = 1LL<<(MAX_N-1); int id = 1; rep(k, MAX_N) { vse[id].clear(); for(int i: vse[1-id]) { if(D[i][k]) vse[id].insert(i); } if(vse[id].size() >= K) { ans += pw; } else { vse[id].clear(); for(int i: vse[1-id]) vse[id].insert(i); } pw >>= 1; id = 1-id; } cout << ans << endl; return 0; }
0
26,007,388
#include <bits/stdc++.h> #include <algorithm> #include <functional> #include <map> #include <queue> #include <set> #include <stack> using namespace std; using ll = long long; using ull = unsigned long long; #define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i) #define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i) #define rep(i, n) REP(i, 0, n) #define rep2(i, n) REP2(i, 0, n) #define all(hoge) (hoge).begin(), (hoge).end() #define en '\n' using Edge = pair<int, long long>; using Graph = vector<vector<Edge>>; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<vector<ll>>> vvvl; typedef vector<string> vs; typedef vector<vector<string>> vvs; typedef pair<ll, ll> P; constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; using ld = long double; static const ld pi = 3.141592653589793L; template <class T> inline void print(T x) { cout << x << '\n'; } template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<string> s(n); vector<ll> t(n); rep(i,n) { cin >> s[i] >> t[i]; } string x; cin >> x; ll res = 0; bool f = false; rep(i,n) { if (s[i] == x) { f = true; continue; } if (f) res += t[i]; } print(res); return 0; }
#include <bits/stdc++.h> #define endl '\n' #define SORT(c) sort((c).begin(), (c).end()) #define SORTR(c) sort((c).begin(), (c).end(), greater<int>()) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; if (N >= 64) { cout << "64" << endl; } else if (N >= 32) { cout << "32" << endl; } else if (N >= 16) { cout << "16" << endl; } else if (N >= 8) { cout << "8" << endl; } else if (N >= 4) { cout << "4" << endl; } else if (N >= 2) { cout << "2" << endl; } else { cout << "1" << endl; } }
0
87,888,770
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define P pair<ll, ll> #define Graph vector<vector<ll>> #define fi first #define se second constexpr ll mod = 1000000007; constexpr ll INF = (1ll << 60); constexpr double pi = 3.14159265358979323846; template <typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;} template <typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;} int main(){ ll n,k;cin>>n>>k; cout<<abs((n+k-1)/k-n/k)<<endl; return 0; }
#include <bits/stdc++.h> #define ll long long int #define MOD 1000000007 #define P pair<ll,ll> #define INF 1000000000000000000 using namespace std; int main(void){ ll h, w, d; cin >> h >> w >> d; map<ll, P> m; for (ll i = 0; i < h; i++){ for (ll j = 0; j < w; j++){ ll a; cin >> a; m[a] = P(i, j); } } vector<vector<ll>> accsum(d, vector<ll>(h*w/d + 1, 0)); for (ll i = 0; i < d; i++){ for (ll j = 1; j < h*w/d + 1; j++){ P p = m[i + d*(j-1)]; P q = m[i + d*j]; accsum[i][j] = accsum[i][j-1] + abs(p.first - q.first) + abs(p.second - q.second); } } ll q; cin >> q; for (ll i = 0; i < q; i++){ ll l, r; cin >> l >> r; cout << accsum[l % d][r / d] - accsum[l%d][l/d] << endl; } return 0; }
0
60,782,416
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ll n; cin >> n; ll ans = 0; for (ll i = 1; i <= n; i++) ans += i * (i + 1) / 2; for (ll i = 1; i < n; i++) { ll a, b, c, d; cin >> c >> d; a = min(c, d); b = max(c, d); ans -= a * (n - b + 1); } cout << ans; }
#include<bits/stdc++.h> #include<math.h> using namespace std; #define ll long long int #define mp make_pair #define pb push_back #define MOD 1000000007 bool isvowel(char c) { if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') return true; return false; } ll isprime(ll n) { ll ans=1; for(ll i=2;i<=sqrt(n);i++) { if(n%i==0) ans = i; } return ans; } ll power(ll a,ll b,ll m) { if(b==0) return 1; if(b==1) return a%m; ll temp=power(a,b/2,m); if(b%2==0) return ((temp%m)*(temp%m))%m; else return ((((temp%m)*(temp%m))%m)*a%m)%m; } ll c(ll n, ll k) { ll C[n + 1][k + 1]; ll i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= min(i, k); j++) { if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = (C[i - 1][j - 1]%MOD + C[i - 1][j])%MOD; } } return C[n][k]%MOD; } ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } ll func(ll n) { ll ans=0; for(ll i=2;i*i<=n;i++) { if(n%i==0) { if(i/10==0) ans+=1+func(i)*func(n/i); else ans+=func(i)*func(n/i); } } return ans; } ll dp[2001][2001]; ll check(vector<pair<ll,ll> >v,ll l,ll r,ll i) { if(l>r) return 0; if(dp[l][r]!=-1) return dp[l][r]; ll ans=0; ll p1=v[i].first; ll p2=v[i].second; ans=max(p1*(p2-l)+check(v,l+1,r,i+1),p1*(r-p2)+check(v,l,r-1,i+1)); return dp[l][r]=ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; t=1; while(t--) { ll n,a,b; cin>>n>>a>>b; ll p=n/(a+b); ll ans=a*p; ans+=min(n%(a+b),a); cout<<ans<<endl; } }
0
93,708,122
#include <bits/stdc++.h> using namespace std; #define rep(i,n)for(int i=0;i<(n);i++) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back using ll = long long; using P = pair<int, int>; int main(){ int a, b; cin >> a >> b; vector<string> ans; int white = 0; int black = 0; rep(i,50){ string s = ""; if(i%2==0){ rep(j,100){ if(j%2==0){ if(a-1>white){ s += '.'; white++; }else s += '#'; }else s += '#'; } ans.push_back(s); }else{ rep(j,100) s += "#"; ans.push_back(s); } } rep(i,50){ string s = ""; if(i%2==1){ rep(j,100){ if(j%2==0){ if(b-1>black){ s += '#'; black++; }else s += '.'; }else s += '.'; } ans.push_back(s); }else{ rep(j,100) s += "."; ans.push_back(s); } } cout << 100 << " " << 100 << endl; for(auto s : ans) cout << s << endl; }
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++) #define reps(i,n) for(int i=1 , i##_len=(int)(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 all(x) (x).begin(), (x).end() #define F first #define S second #define mp make_pair #define pb push_back #define solve(a) ((a)?"Yes":"No") typedef vector<long long> V; typedef vector<V> VV; typedef pair<long long , long long> P; typedef vector<P> VP; 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 INFLL = 1LL<<62; const int INF = 1<<30; const double PI=acos(-1); int main(){ char n; map<char,char>tr; tr['A']='T'; tr['T']='A'; tr['C']='G'; tr['G']='C'; int ans=0; cin >>n; cout<<tr[n]<<endl; }
0
37,721,168
#include <bits/stdc++.h> using namespace std; using ll = long long; #define INF 0x6fffffff #define INFL 0x6fffffffffffffffLL long long gcd(long long m, long long n) { long long temp; if (n > m) swap(m , n); while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } int main() { ll b,c,d,w,h,i,j,k,l,m,n,x,y,z; ll ans = 0; string s; cin >> n; vector<ll> a(n); for(i=0;i<n;i++) cin >> a[i]; ans = gcd(a[0],a[1]); for(i=2;i<n;i++) { ans = gcd(ans,a[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() const int mod=1000000007,MAX=100003,INF=1<<30; int main(){ int N;cin>>N; vector<pair<ll,int>> A(N); for(int i=0;i<N;i++){ cin>>A[i].first; A[i].second=i; } sort(all(A)); reverse(all(A)); A.push_back(make_pair(0,-1)); vector<ll> cnt(N); int mini=INF; for(int i=0;i<N;i++){ if(A[i].first!=A[i+1].first){ int j=A[i].second; mini=min(mini,j); cnt[mini]+=(A[i].first-A[i+1].first)*(i+1); }else mini=min(mini,A[i].second); } for(int i=0;i<N;i++){ cout<<cnt[i]<<endl; } }
0
9,557,794
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using ld = long double; const int INF = (1<<30)-1; const long long LINF = (1LL<<62)-1; const long double PI = acos(-1.0L); const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, c, d; cin >> a >> b >> c >> d; if (abs(a-c) <= d || abs(a-b) <= d && abs(b-c) <= d) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> #include <vector> #include <queue> using namespace std; int main(){ string S; cin >> S; if(S[0] != 'A'){ cout << "WA" << endl; return 0; } int count_large_C = 0; int target_i = 0; for(int i=2; i<S.size()-1; i++){ if(S[i] == 'C'){ count_large_C += 1; target_i = i; } } if(count_large_C != 1){ cout << "WA" << endl; return 0; } for(int i=1; i<S.size(); i++){ if(i==target_i){continue;} if(S[i] >= 'a' && S[i] <= 'z'){ continue; }else{ cout << "WA" << endl; return 0; } } cout << "AC" << endl; return 0; }
0
47,892,803
#include <bits/stdc++.h> using namespace std; #define lli long long int #define uli unsigned long long int #define rep(i, m, n) for (lli i = m; i < (n); i++) #define repe(i, m, n) for (lli i = m; i <= (n); i++) #define ALL(x) (x).begin(), (x).end() #define SIZE(x) ((lli)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define _GLIBCXX_DEBUG const lli INF = 2147483647; const lli MINF = -2147483648; const lli LINF = 9223372036854775807; const lli MOD = 1000000007; const double PI = acos(-1); #define SORT(n) sort(n.begin(), n.end()) #define SORTR(n) sort(n.begin(), n.end(), greater<int>()) #define REV(n) reverse(n.begin(), n.end()) #define pb push_back #define eb emplace_back #define mp make_pair #pragma GCC optimize("Ofast") using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vlli = vector<lli>; using vvli = vector<vlli>; using vs = vector<string>; using vvs = vector<vs>; using vb = vector<bool>; using vvb = vector<vb>; using ll = long long; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ""); } return os; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); lli a, b, c, k, h, n, w, ans = 0, count = 0; string s, t; vector<pair<string, pair<lli, lli>>> pr; cin >> n >> c >> k; vlli d(n); rep(i, 0, n) { cin >> d[i]; } SORT(d); lli time = 0; rep(i, 0, n) { if (d[i] > time || count == c) { time = d[i] + k; ans++; count = 1; } else { count++; } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; int gcd(int a,int b) { while (b) { a %= b; swap(a,b); } return a; } int main() { int n,k; cin >> n >> k; int g = 0; vector<int> a(n); for (int i = 0;i < n;++i) cin >> a[i]; for (int i = 0;i < n;++i) g = gcd(a[i],g); bool ans = false; for (int i = 0;i < n;++i) if (a[i] >= k && (a[i]-k)%g == 0) ans = true; cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl; }
0
17,933,709
#include <bits/stdc++.h> using namespace std; int main() { int N, D, X, A; cin >> N >> D >> X; while (cin >> A) { int tmp = 1, cnt = 1; while (tmp + A <= D) tmp += A, cnt++; X += cnt; } cout << X << "\n"; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <cmath> #include <iomanip> #include <ctype.h> using namespace std; using ll = long long; using PAIR = pair<int, int>; using PAIRLL = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; #define TR "," #define rep(i,N) for(ll i=0;i<(ll)N;++i) #define repe(i,a,b) for(ll i=a;i<(ll)b;++i) #define all(v) v.begin(), v.end() #define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define INF 100000000 ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll waz = 76543217; ll inv(ll x) { if (x == 1) { return 1; } if (x == 0) { return 0; } else { ll a = (waz - inv(waz % x) * (waz / x)) % waz; if (a >= 0) { return a; } else { return waz + a; } } } void printVector(const vector<int>& vec) { for (int value : vec) { cout << value << " "; } cout << endl; } vector<ll> p; ll phi(ll x) { ll a = x; ll b = x; for (ll k = 0; k != p.size(); ++k) { if (a % p[k] == 0) { while (a % p[k] == 0) { a /= p[k]; } b = b / p[k] * (p[k] - 1); } if (a == 1) { break; } } return b; } bool my_compare(pair<string, int> a, pair<string, int> b) { if (a.first != b.first) { return a.first < b.first; } if (a.second != b.second) { return a.second > b.second; } else { return true; } } int main() { IO; ll N, K; cin >> N >> K; if (N >= K / 2) { if (K % 2 != 0) { ll a = N / K; cout << (ll)pow(a,3) << endl; } else { ll a = N / K; ll b = max((N - K / 2) / K + 1, (ll)0); cout << (ll)pow(a,3) + (ll)pow(b,3) << endl; } } else { cout << 0 << endl; } }
0
96,961,803
#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; ll gcd(ll a, ll b) { if (b==0) return a; else return gcd(b, a%b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll digit_sum(ll a){ ll ans=0; while(a>0){ ans+=a%10; a/=10; } return ans; } int main() { ll h,w; char a[110][110]; bool flag[110][110]={false}; bool flag2[110][110]={false}; cin>>h>>w; rep(i,h){ rep(j,w)cin>>a[i][j]; } rep(i,h){ ll tmp=0; rep(j,w){ if(a[i][j]=='#')tmp++; } if(tmp!=0){ rep(k,w){ flag[i][k]=true; } } } rep(i,w){ ll tmp=0; rep(j,h){ if(a[j][i]=='#')tmp++; } if(tmp!=0){ rep(k,h)flag2[k][i]=true; } } rep(i,h){ ll tmp=0; rep(j,w){ if(flag[i][j]&&flag2[i][j]){ cout<<a[i][j]; tmp++; } } if(tmp>0)cout<<endl; } return 0; }
#include <bits/stdc++.h> #include <iomanip> #include <math.h> #define rep(i,x) for(ll i = 0;i<x;i++) #define all(a) (a).begin(),(a).end() using ll = long long; using ld = long double; using namespace std; const ll INF = 1001001001; const ll mod = 1000000007; ll gcd(ll a,ll b){ if(a < b)swap(a,b); if(a % b == 0)return b; else return gcd(b,a%b); } bool isp(ll n){ bool res = true; if(n == 1)return false; else{ for(ll i = 2;i * i <= n;i++){ if(n % i == 0){ res = false; break; } } return res; } } int main() { string S; cin >> S; ll sa = INF; ll s = S.size(); rep(i,s - 2){ ll num = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + S[i + 2] - '0'; sa = min(sa,abs(num - 753)); } cout << sa << endl; }
0
45,220,622
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); i++) typedef long long int ll; typedef pair<int, int> P; ll s; int main() { cin >> s; cout << "0 0 1000000000 1 "; const ll m = 1e9; int x = (m - s % m) % m; int y = (s + x) / m; cout << x << " " << y; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int n; cin >> n; vector<int> a(n); vector<int> num(1000010); int g = 0; for (int i = 0; i < n; i++) { cin >> a[i]; g = gcd(a[i], g); num[a[i]]++; } int i; for (i = 2; i <= 1000010; i++) { int x = 0; for (int j = i; j <= 1000010; j += i) x += num[j]; if (x > 1) break; } if (i == 1000011) { cout << "pairwise coprime" << endl; return 0; } if (g == 1) { cout << "setwise coprime" << endl; } else { cout << "not coprime" << endl; } }
0
88,518,560
#include <iostream> #include <vector> #include <algorithm> #define rep(i, n) for(int i = 0; i < (int)(n); ++i) #define REP(i, n) for(int i = 1; i < (int)(n); ++i) using namespace std; int main() { string S; cin >> S; string ans = ""; rep(i, S.size()) { if (i % 2 == 0) ans.push_back(S[i]); } cout << ans << endl; return 0; }
#include<iostream> #include<algorithm> using namespace std; int main(){ int n,k; while( cin >> n >> k,n+k){ int a[n]; for(int i = 0;i < n;i++){ cin >> a[i]; } int sum = -500000; for(int i = 0;i < n-k+1;i++){ int s = 0; for(int j = i;j < i+k;j++){ s += a[j]; } sum = max(s,sum); } cout << sum << endl; } }
0
8,292,618
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(i = 0;i < n;++i) #define all(v) v.begin(), v.end() using ll = long long; struct UnionFind { int i; vector<int> par; vector<int> size; UnionFind(int n): par(n),size(n,1){ for(i = 0;i < n;++i){ par.at(i) = i; } } int root(int x){ if(par.at(x) == x){ return x; }else{ return par.at(x) = root(par.at(x)); } } void unite(int x, int y){ int rx = root(x); int ry = root(y); if(rx == ry){ return; }else{ if(size.at(rx) < size.at(ry)){ swap(rx,ry); } par.at(ry) = rx; size.at(rx) += size.at(ry); return; } } bool same(int x, int y){ int rx = root(x); int ry = root(y); return rx == ry; } int get_size(int x){ return size.at(root(x)); } }; int main() { ll i,j; ll n, q; cin >> n >> q; UnionFind uf(n); rep(i,q){ ll c; cin >> c; ll u,v; cin >> u >> v; if(c) cout << uf.same(u, v) << endl; else uf.unite(u,v); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(a, b) for (int i = 0; i < (b); ++i) template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } void solve(void) { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; vector<bool> f(n, true); const int INF = 1e9; int res = INF; while (n > 1) { auto mn = min_element(a.begin(), a.end()); vector<int> tmp; tmp.push_back(*mn); int dis = distance(a.begin(), mn); rep(i, n) { if (dis == i) continue; if (a[i] % *mn != 0) tmp.push_back(a[i] % *mn); else --n; } a = tmp; res = min(res, *mn); } cout << res << endl; } int main(void) { solve(); }
0
25,795,439
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vll = vector<long long>; constexpr long long mod = 1000000007; #define rep(i, n) for (int i = 0; i < n; i++) int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; map<int, int> mp; rep(i, n){ mp[a[i]] = 0; } if(mp.size()%2==0){ cout << mp.size() - 1 << endl; }else{ cout << mp.size() << endl; } }
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { char text[1001]; cin.get(text, 1001); int a, b, c; cin>>a; string operation; while(a--) { cin>>operation; if(operation == "print") { cin>>b>>c; cout.write(text + b, c - b + 1); cout<<endl; } else if(operation == "reverse") { cin>>b>>c; reverse(text + b, text + c + 1); } else { cin>>b>>c; for(int i = b; i <= c; i++) cin>>text[i]; } } return 0; }
0
99,335,040
#include <stdio.h> int main(){ int x, y, i = 1; while(1){ scanf("%d", &x); scanf("%d", &y); if(x == 0&& y == 0) break; if(x <= y) printf("%d %d\n",x ,y); else printf("%d %d\n",y ,x); i++; } return 0; }
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define ArraySizeOf(array) (sizeof(array) / sizeof(array[0])) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for(int i=1;i<n;i++) #define rev(i,n) for(int i=n-1;i>=0;i--) #define REV(i,n) for(int i=n-1;i>0;i--) #define req(i,n,m) for(int i=n;i<m;i++) #define REQ(i,n,m,l) for(int i=n;i<m;i+=l) #define _GLIBCXX_DEBUG int INF = 1e9 + 7; unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1) { unsigned day; if (dow < dow1) dow += 7; day = dow - dow1; day += 7 * n - 6; return day; } signed gcd(int x, int y) { if (y == 0)return x; return gcd(y, x % y); } signed lcm(int x, int y) { return x / gcd(x, y) * y; } unsigned DayToWeekNumber(unsigned day) { return (day - 1) / 7 + 1; } unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0) { return (dow0 + 35 + day - day0) % 7; } using namespace std; signed main() { int N, D, X; cin >> N >> D >> X; vector<int>A(N); int ans = X; rep(i, N) { cin >> A[i]; REQ(j, 1, D+1, A[i])ans++; } cout << ans << endl; }
0
92,505,157
#include <bits/stdc++.h> using namespace std; using ll=long long; const ll MOD=1000000007; int main() { int a,b; cin >> a >> b; if(a==b) cout << "Draw" << endl; else if(a!=1&&b!=1){ if(a<b) cout << "Bob" << endl; else cout << "Alice" << endl; } else{ if(a==1){ cout << "Alice" << endl; } else cout << "Bob" << endl; } }
#include <iostream> #include <cstdio> #include <set> using namespace std; int main(){ long long n; cin >> n; set<string> T; string pre_word; for(long long i = 0; i < n; i++){ string word; cin >> word; if(i == 0){ T.insert(word); pre_word = word; continue; } if(T.find(word) != T.end()){ printf("No\n"); return 0; } else{ if(word[0] != pre_word[pre_word.size()-1]){ printf("No\n"); return 0; } else{ T.insert(word); pre_word = word; } } } printf("Yes\n"); return 0; }
0
8,470,988
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define rep(i,m,n) for(int i=m;i<n;i++) ll mod=1e9+7; int main(){ int a,b; char c; cin>>a>>c>>b; if(c=='+') cout<<a+b<<endl; else cout<<a-b<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++) #define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++) #define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--) #define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--) #define ALL(x) (x).begin(), (x).end() const ll INF = 100100100100100100; const ll MOD = 1000000007; ll my_abs(ll a); ll a_n(ll a, ll n); ll my_gcd(ll a, ll b); ll inv(ll a); ll madd(ll a, ll b, ll c); ll msub(ll a, ll b); ll mtime(ll a, ll b, ll c); int main() { string a; cin >> a; ll n = a.size(); ll ans = 1 + n*(n-1)/2; vector<ll> num(26,0); rep(i, n) { ll tmp = ll(a[i]-'a'); num[tmp]++; } rep(i, 26) { ans -= num[i]*(num[i]-1)/2; } cout << ans << endl; return 0; } ll my_abs(ll a) { if(a >= 0) return a; else return -1 *a; } ll a_n(ll a, ll n) { if(n == 0) return 1; ll ret = a, count = 1; while(count * 2 < n) { ret *= ret; count *= 2; } if(count == n) return ret; else return (ret * a_n(a, n-count)); } ll my_gcd(ll a, ll b) { if(b == 0) return a; return my_gcd(b, a%b); } ll inv(ll a) { return a_n(a, MOD-2); } ll madd(ll a, ll b, ll c) { ll ret = (a+b) % MOD; return (ret+c) % MOD; } ll msub(ll a, ll b) { if(a < b) return (a-b+MOD) % MOD; else return (a-b) % MOD; } ll mtime(ll a, ll b, ll c) { ll ret = (a*b) % MOD; return (ret*c) % MOD; }
0
41,250,110
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(long long i=0;i<(long long)(n);i++) #define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++) #define repi(i, n) for(int i=0;i<(int)(n);i++) #define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define chmax(s, t) s=max(s,t); #define chmin(s, t) s=min(s,t); #define deg2rad(deg) (((deg)/360)*2*M_PI) #define rad2deg(rad) (((rad)/2/M_PI)*360) using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; const ll INF = (1LL<<60); const int INFi = (1<<29); bool is_prime(ll n){ if(n==1) return false; for(ll i=2;i*i<=n;i++){ if(n%i==0) return false; } return true; } vll enum_divisors(ll n){ vll l; for(ll i=1;i*i<=n;i++){ if(n%i==0){ l.push_back(i); if(n/i != i) l.push_back(n/i); } } sort(all(l)); return l; } vector<P> prime_factorize(ll n){ vector<P> l; for(ll i=2;i*i<=n;i++){ if(n%i!=0) continue; ll e = 0; while(n%i==0){ e++; n /= i; } l.push_back({i, e}); } if(n!=1) l.push_back({n, 1}); return l; } ll lcm(ll a, ll b){ return a*b/__gcd(a,b); } ll gcd(ll a, ll b){ return __gcd(a,b); } const ll CMAX = 1010000; const ll CMOD = 1e9+7; ll fac[CMAX], finv[CMAX], inv[CMAX]; void combinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < CMAX; i++) { fac[i] = fac[i - 1] * i % CMOD; inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD; finv[i] = finv[i - 1] * inv[i] % CMOD; } } ll comb(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD; } ll factorial(ll n){ const ll FMOD = 1e9+7; ll ret = n; for(ll i=n-1;i>0;i--){ ret*=i; ret%=FMOD; } return (ret?ret:1); } int main(){ string s; cin >> s; string ans = ""; rep(i, s.size()){ if(s[i]=='B'){ if(ans.size()!=0){ ans.erase(ans.size()-1); } } else{ ans.push_back(s[i]); } } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main() { int n[5],tmp; scanf("%d %d %d %d %d",&n[0],&n[1],&n[2],&n[3],&n[4]); for (int i=0; i<4; i++) { for (int j=0; j<4-i; j++) { if (n[j]<n[j+1]) { tmp = n[j]; n[j] = n[j+1]; n[j+1] = tmp; } } } cout << n[0] << " " << n[1] << " " << n[2] << " " << n[3] << " " << n[4] << endl; return 0; }
0
30,589,124
#include <bits/stdc++.h> using namespace std; bool isok(string s){ string t(s); reverse(t.begin(), t.end()); return s == t; } int main(){ string s; cin >> s; int n = (int)s.size(); bool ans = true; if(!isok(s)) ans = false; if(!isok(s.substr(0,n/2))) ans = false; if(!isok(s.substr(n/2+1))) ans = false; if(ans) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <iostream> using namespace std; int main() { long int K; cin >> K; string palabra; cin >> palabra; int lon= palabra.size(); if(lon>K){ for(int i=0; i<K; i++){ cout<<palabra[i]; } cout<<"..."; } else{ cout << palabra; } return 0; }
0
14,519,853
#include<stdio.h> #include<string.h> int main() { char a[20], b[20], c[20]; scanf("%s %s %s", &a, &b, &c); int al, bl; al = strlen(a)-1; bl = strlen(b)-1; if(a[al]==b[0] && b[bl]==c[0]) printf("YES"); else printf("NO"); }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long int #define pb push_back #define fi first #define se second #define ld long double #define vi vector<vector<ll> > using namespace std; const int MOD=1000000007; const int MOD2=998244353; const ll MAX=9187201950435737471; const int N=100005; const int INF=1e9; const long double PI=acos(-1); void solve(int T){ int a,b; cin>>a>>b; string s="",m=""; for(int i=0;i<a;i++){ s+=b+'0'; } for(int i=0;i<b;i++){ m+=a+'0'; } cout<<min(s,m)<<"\n"; } int main() { int T=1; for(int i=1;i<=T;i++){ solve(i); } return 0; }
0
59,315,883
#include <bits/stdc++.h> #define err(args...) {} #ifdef DEBUG #include "_debug.cpp" #endif using namespace std; using ll = long long; using ld = long double; template <typename T> using lim = numeric_limits<T>; template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; } template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; } bool is_perfect_square(ll n) { return ll(sqrt(n)) * ll(sqrt(n)) == n; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int q; cin >> q; while(q--) { ll a, b; cin >> a >> b; ll rt_ab = ll(sqrt(a * b)); if(is_perfect_square(a * b)) { cout << 2 * rt_ab - 2 - (a != b) << endl; } else { cout << 2 * rt_ab - ((a * b - 1) / rt_ab == rt_ab) - 1 << endl; } } return 0; }
#include<bits/stdc++.h> #define ll long long #define pb push_back long long int mod = (long long int)1000000007; using namespace std; int n; const int full=1000001; vector<int>adj[full]; bool vis[full]; int par[full]; int depth[full]; ll h[full]; ll l[full]; void dfs(int i) { vis[i]=1; for(int j=0;j<adj[i].size();j++) { if(h[i]<=h[adj[i][j]]) { l[i]=1; } if(vis[adj[i][j]]==0) { dfs(adj[i][j]); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int i,j,k; int n,m; cin>>n>>m; for(i=1;i<=n;i++) { cin>>h[i]; } for(i=0;i<m;i++) { int a,b; cin>>a>>b; adj[a].pb(b); adj[b].push_back(a); } for(i=1;i<=n;i++) { if(vis[i]==0) { dfs(i); } } int c=0; for(i=1;i<=n;i++) { if(l[i]==0) { c++; } } cout<<c; }
0
77,110,631
#ifndef LOCAL #pragma GCC optimize "-O3" #endif #include <bits/stdc++.h> typedef long long ll; typedef long long llong; typedef long double ld; typedef unsigned long long ull; using namespace std; bitset<17000> dp; void check(int x, vector<int> vv) { int sum = 0; for (int i: vv) sum += i; x += sum; for (int i = 0; i < vv.size(); ++i) vv[i] *= 2; dp.reset(); dp[0] = 1; for (int i: vv) dp |= (dp << i); if (!dp[x]) { cout << "No\n"; exit(0); } } string s; int x, y; vector<int> vv[2]; int main() { cin >> s >> x >> y; int cur = 0; while (cur < s.size() && s[cur] == 'F') --x, ++cur; int tp = 0; while (cur < s.size()) { ++cur; tp ^= 1; int cnt = 0; while (cur < s.size() && s[cur] == 'F') { ++cur; ++cnt; } vv[tp].push_back(cnt); } x = abs(x), y = abs(y); check(x, vv[0]); check(y, vv[1]); cout << "Yes\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int mx=0,ans; for(int i=0;i<=20;i++) { if(n< (1<<(i+1))) { cout << (1<<i) << endl; break; } } return 0; }
0
98,938,696
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int ans = 0; for ( int n = a; n <= b; n++ ) { string num = to_string(n); if ( num[0] == num[4] && num[1] == num[3] ) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int curr, tmp = -1, cnt = 0, max_c = 0; for (int i = 0; i < n; i++) { cin >> curr; if (curr <= tmp) { cnt++; } else { if (max_c < cnt) max_c = cnt; cnt = 0; } tmp = curr; } cout << max(max_c, cnt) << endl; return 0; }
0
5,281,665
#include <bits/stdc++.h> using namespace std; int main() {int a,b; cin >> a >> b; int c = a-b; if(c < 0)c = 0; cout << c << endl;}
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll) 1e15; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; pll p(0, 0); ll pt = 0; bool e = true; REP(i, N) { pll n; ll t; cin >> t >> n.first >> n.second; ll d = abs(n.first - p.first) + abs(n.second - p.second); if ((t - pt) - d < 0 || ((t - pt) - d) % 2 == 1) { e = false; } pt = t; p = n; } if (e) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
0
35,080,195
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back int main() { ll n, m; cin>>n>>m; ll mx=-1000,mn=1e7; for(ll i=0;i<m;i++) { ll a,b; cin>>a>>b; mx=max(a,mx); mn=min(b,mn); } if(mn-mx<0)cout<<0<<endl; else cout<<mn-mx + 1; }
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i < (n); i++) using namespace std; using ll = long long; int N,M; int DFS(vector<vector<int>> &load, int now, vector<bool> visited){ bool end=true; for(int i=1; i<=N; i++){ if(visited[i]==false){ end=false; } } if(end) return 1; int ret=0; for(int i:load[now]){ if(visited[i]) continue; visited[i]=true; ret += DFS(load, i, visited); visited[i]=false; } return ret; } int main(){ cin >> N >> M; vector<vector<int>> load(N+1,vector<int>()); rep(z,M){ int a,b; cin >> a >> b; load[a].push_back(b); load[b].push_back(a); } vector<bool> visited(N+1,false); visited[1] = true; int ans = DFS(load, 1, visited); cout << ans << endl; }
0
61,308,938
#include <iostream> using namespace std; int main(void){ int M,N; cin >> N >> M; int A[100]; int sum=0; for(int i=0; i<N; i++){ cin >> A[i]; sum += A[i]; } int count=0; for (int i=0; i<N; i++){ if (A[i]*4*M >= sum){ count++; } } if (count >= M){ cout << "Yes" << endl; } else{ cout << "No" << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++) template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}} int main(){ ll N, K; cin >> N >> K; set<ll>S; vector<P>v(N); priority_queue<ll, vector<ll>, greater<ll> >R; rep(i, N)cin >> v[i].second >> v[i].first; sort(v.begin(), v.end(), greater<P>()); ll sum = 0; rep(i, K){ ll d = v[i].first; ll t = v[i].second; sum += d; if(S.find(t) != S.end())R.push(d); S.insert(t); } ll ans = sum + S.size() * S.size(); for(ll i = K; i < N; i++){ ll d = v[i].first; ll t = v[i].second; if(S.find(t) != S.end())continue; if(!R.empty()){ ll r = R.top(); R.pop(); sum -= r; sum += d; S.insert(t); } chmax(ans, ll(sum + S.size() * S.size())); } cout << ans << endl; return 0; }
0
90,440,468
#include <bits/stdc++.h> using namespace std; int main() { int a, b; double c; cin >> a >> b; c = (a + b) / 2.0; if((a + b) % 2 == 1){ c = c + 0.5; } cout << c << endl; }
bool DBG = false; #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i) #define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i) #define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i) #define ALL(x) x.begin(),x.end() #define RALL(x) x.rbegin(),x.rend() #define fs first #define sd second #define couts(x) cout << (x) << (" ") #define coutn(x) cout << (x) << ("\n") #define dcouts(x) if(DBG) couts(x) #define dcoutn(x) if(DBG) coutn(x) #define endl "\n" #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define LBIT(x,a) (((x)>>(a))&1LL) #define IBIT(x,a) (((x)>>(a))&1) #define BCOUNT(x) (__builtin_popcount(x)) template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec){ for (auto &v : vec) is >> v; return is; } template<typename T1, typename T2> std::istream &operator>>(std::istream &is, std::pair<T1,T2> &p){is >> p.first >> p.second; return is; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::deque<T> &vec){ os << "deque["; for (auto v : vec) os << v << ","; os << "]"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template<typename T1, typename T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; } template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template<class T> using V = vector<T>; template<class T> using V2 = V<V<T>>; template<class T> using V3 = V<V2<T>>; using P = pair<ll,int>; template<class T> V<T> VF(V<T> v, function<T(T)> f){ int n = (int) v.size(); V<T> ret(n); for(int i=0; i<n; ++i) { T a = v[i]; ret[i] = f(a); } return ret; } template<class T, class U> V<U> VF2(V<T> v, function<U(T)> f){ int n = (int) v.size(); V<U> ret(n); for(int i=0; i<n; ++i) { T a = v[i]; ret[i] = f(a); } return ret; } template<class T> void VFS(V<T> &v, function<T(T)> f){ int n = (int) v.size(); for(int i=0; i<n; ++i) { T a = v[i]; v[i] = f(a); } return; } void solveii(){ int p; cin >> p; V<int> a(p); cin >> a; } void twoview(ll x){ cout << "0x"; IFOR(j,0,62){ cout << LBIT(x,j); } } void solve(){ int n; cin >> n; V<ll> a(n); cin >> a; ll s = 0, s2 = 0; for(auto x: a) {s ^= x; s2 |= x;} for(auto &x: a) x &= (~s); ll ans = 0; V<int> used(n, 0); int cnt = 0; IFOR(i,0,62){ if(cnt>=n) break; if( LBIT(s,i)==1 || LBIT(s2,i)==0 ) continue; bool able = false; int id = -1; FOR(j,0,n){ if( !used[j] && LBIT(a[j],i) ){ able = true; used[j] = 1; id = j; break; } } if(!able) continue; FOR(j,0,n){ if( j==id ) continue; if( LBIT(a[j],i) ) a[j] ^= a[id]; } } FOR(i,0,n){ if(used[i]) ans ^= a[i]; } ans <<= 1; ans += s; coutn(ans); } int main(void){ cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
0
11,465,715
#include <iostream> using namespace std; int main() { double x1,y1,x2,y2,x3,y3,xp,yp; double m,n; while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) { m = ((xp - x1) * (y3 - y1) - (yp - y1) * (x3 - x1)) / ((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)); n = ((xp - x1) * (y2 - y1) - (yp - y1) * (x2 - x1)) / ((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1)); if(m > 0 && n > 0 && m + n < 1) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <iostream> #include <fstream> #include <cstdio> #include <cmath> #include <vector> #include <string> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <bitset> #include <algorithm> #include <complex> #include <array> #include <iomanip> using namespace std; #define REP(i,n) for(int i=0; i<n; ++i) #define FOR(i,a,b) for(int i=a; i<=b; ++i) #define FORR(i,a,b) for (int i=a; i>=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<long double> VD; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VD> VVD; typedef pair<int,int> P; typedef pair<ll,ll> PL; template<typename T> void chmin(T &a, T b) { if (a > b) a = b; } template<typename T> void chmax(T &a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } ll lin() { ll x; scanf("%lld", &x); return x; } #define INF 1LL<<60 int main() { ll N; cin >> N; ll ans = 0; FOR(i, 1, N-1) { ans += ll(i); } cout << ans << endl; return 0; }
0
83,875,160
#include<bits/stdc++.h> using namespace std; typedef long long int lli; #define forn(i,n) for(int i=0;i<(int) n;i++) #define Forn(i,n) for(int i=1;i<=(int) n;i++) int main() { int n; cin>>n; string s; cin>>s; int i,j,c=1; if(n==1) { cout<<1; return 0; } for(i=1;i<n;i++) { if(s[i]!=s[i-1]) c++; } cout<<c; }
#include<bits/stdc++.h> using namespace std; #define int long long signed main(void){ int n,m; cin >> n >> m; bool flag = true; if( n % 2 == 1 ) { int cnt = 0; for(int a = 1,b = n; a < b; a++, b--){ cout << a << " " << b << endl; cnt++; if( cnt >= m ){ break;} } } else{ int cnt = 0; for(int a = 1, b = n; a < b; a++, b--){ if( b-a <= n/2 && flag){ a++; flag = false;} cout << a << " " << b << endl; cnt++; if( cnt >= m ){ break;} } return 0; } }
0
62,979,900
#include <bits/stdc++.h> using namespace std; int main() { char x, y; cin >> x >> y; if (x < y) cout << '<'; if (x > y) cout << '>'; if (x == y) cout << '='; }
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<iomanip> using namespace std; int main(){ int a,b; cin>>a>>b; for(int i=0;i<=2000;i++){ int x=i*0.08; int y=i*0.1; if(x==a&&y==b){ cout<<i<<endl; return 0; } } cout<<-1<<endl; return 0; }
0
68,787,148
#include<iostream> #include<vector> #include<queue> #include<stack> #include<map> #include<set> #include<string> #include<algorithm> #include<utility> #include<math.h> #include<cstdlib> #define rep(i, n) for(int i=0;i<n;i++) #define repb(i, a, b) for(int i=a;i<b;i++) using namespace std; typedef pair<int, int> P; typedef long long int ll; const int INF = 1<<30; int main(){ int n, k;cin>>n>>k; vector<P> sushi(n); rep(i, n){ int t, d;cin>>t>>d; sushi[i]=P(d, --t); } sort(sushi.begin(), sushi.end(), greater<P>()); vector<bool> include(n, false); vector<int> selected; ll kind=0LL; ll sum=0LL; rep(i, k){ P p=sushi[i]; if(!include[p.second]){ include[p.second]=true; kind++; }else{ selected.push_back(p.first); } sum += p.first; } sort(selected.begin(), selected.end(), greater<int>()); ll ans=sum+kind*kind; ll id=(ll)kind; while(!selected.empty() && id<n){ if(include[sushi[id].second]){id++;continue;} include[sushi[id].second] = true; sum -= selected.back();selected.pop_back(); sum += sushi[id].first; id++;kind++; ans = max(ans, sum+kind*kind); } cout<<ans<<endl; }
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; static const int MAX_LENGTH = 1000; int main(void) { int tmpSum; char *inputList = new char[MAX_LENGTH]; while(true) { scanf("%s", inputList); if(*inputList == '0') break; tmpSum = 0; for(int i=0; i < strlen(inputList); i++) { tmpSum += inputList[i] - '0'; } cout << tmpSum << endl; } return 0; }
0
17,038,594
#include<bits/stdc++.h> #define PI 3.141592653589 using namespace std; using ll = long long; template<typename T_char> T_char ToUpper(T_char cX){return toupper(cX);} int main(){ int h, w; cin >> h >> w; char buf[105]; for(int i=0; i<h; ++i){ cin >> buf; cout << buf << endl; cout << buf << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int N, K; cin >> N >> K; vector<int> h(N); for (int i = 0; i < N; i++) { cin >> h[i]; } sort(h.begin(), h.end(), greater<int>()); int ans = 0; for (int i = 0; i < N; i++) { if (h[i] < K) { break; } ans++; } cout << ans << endl; return 0; }
0
16,731,800
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i=0; i < (int)(n); i++) using ull = unsigned long long; using ll = long long; int main() { int N; cin >> N; int X[100010], Y[100010], ai; fill(X, X+100010, 0); fill(Y, Y+100010, 0); rep(i, N) { cin >> ai; if (i%2 == 0) X[ai]++; else Y[ai]++; } int onum0 = 0, onum1 = 0, enum0 = 0, enum1 = 0; int oi0 = 0, oi1 = 0, ei0 = 0, ei1 = 0; rep(i, 100001) { if (onum0 <= X[i]) { onum1 = onum0; oi1 = oi0; onum0 = X[i]; oi0 = i; } else if (onum1 <= X[i]) { onum1 = X[i]; oi1 = i; } if (enum0 <= Y[i]) { enum1 = enum0; ei1 = ei0; enum0 = Y[i]; ei0 = i; } else if (enum1 <= Y[i]) { enum1 = Y[i]; ei1 = i; } } int ans; if (oi0 != ei0) ans = N - onum0 - enum0; else ans = min(N - onum0 - enum1, N - onum1 - enum0); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 8005; vector<int> arr; int dp[MAXN][2*MAXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); string str; cin >> str; arr.push_back(0); for (int i = 0; i < (int)str.length(); i++) { if (str[i] == 'T') arr.push_back(0); else arr.back()++; } int N = arr.size(); int x, y; cin >> x >> y; if (arr.size() == 1) { if (x == arr[0]) { cout << "Yes\n"; } else { cout << "No\n"; } return 0; } x -= arr[0]; x += MAXN; y += MAXN; dp[0][MAXN] = dp[1][MAXN+arr[1]] = dp[1][MAXN-arr[1]] = 1; for (int pos = 2; pos < N; pos++) { for (int rem = 0; rem < 2*MAXN; rem++) { int &ret = dp[pos][rem]; ret = 0; if (rem + arr[pos] < 2*MAXN) ret |= dp[pos-2][rem+arr[pos]]; if (rem - arr[pos] >= 0) ret |= dp[pos-2][rem-arr[pos]]; } } if (N&1) { if (dp[N-1][x] && dp[N-2][y]) { cout << "Yes\n"; } else { cout << "No\n"; } } else { if (dp[N-1][y] && dp[N-2][x]) { cout << "Yes\n"; } else { cout << "No\n"; } } }
0
40,445,669
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<cmath> #include<cstdio> #include<queue> #include<deque> #include<map> #include<stack> #include<set> #include<utility> using namespace std; typedef pair<int,int> ii; typedef long long ll; typedef pair<ll,ll> P; typedef unsigned long long int ull; const ll MOD=1e9+7; int dy[]={1,0,-1,0}; int dx[]={0,1,0,-1}; const int MAXN=100000; const int MAXE=100000; const int MAXV=10000; const ll INF=1e18; int n,m; vector<ll> x(1000),y(1000),z(1000); ll solve(int a,int b,int c){ vector<ll> res(n); for(int i=0;i<n;i++){ res[i]=x[i]*(a?1:-1)+y[i]*(b?1:-1)+z[i]*(c?1:-1); } sort(res.begin(),res.end(),greater<ll>()); ll sum=0; for(int i=0;i<m;i++) sum+=res[i]; return sum; } int main(){ cin>>n>>m; for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i]; ll ans=0; for(int b=0;b<(1<<3);b++){ ans=max(ans,solve((b&1),((b>>1)&1),((b>>2)&1))); } cout<<ans<<endl; return 0; }
#include <iostream> #include <sstream> #include <string> #include <list> using namespace std; list<int>::iterator find_key(list<int>& li,int key) { list<int>::iterator li_itr = li.begin(); while(li_itr != li.end()) { if(*li_itr == key) { return li_itr; } ++li_itr; } return li.end(); } int main(void) { ios::sync_with_stdio(false); int n; list<int> li; cin >> n; for(int i=0;i<n;i++) { string command; cin >> command; int key; if(command == "insert") { cin >> key; li.push_front(key); } else if(command == "deleteFirst") { li.pop_front(); } else if(command == "deleteLast") { li.pop_back(); } else { cin >> key; list<int>::iterator erace_itr = find_key(li,key); if(erace_itr != li.end()) { li.erase(find_key(li,key)); } } } list<int>::iterator itr = li.begin(); while(itr != li.end()) { cout << *itr; ++itr; itr == li.end() ? cout << "" : cout << " "; } cout << endl; }
0
3,953,519
#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; int cnt = 0; for(int i = 1; i <= n; i++){ string s = to_string(i); if(s.size()%2 != 0) cnt++; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define REP(i,n) for(int i=0;i<n;++i) #define ALL(name) name.begin(),name.end() #define SORT(name) sort(name.begin(), name.end()) #define ZERO(p) memset(p, 0, sizeof(p)) #define MINUS(p) memset(p, -1, sizeof(p)) #if 1 # define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__) #else # define DBG(fmt, ...) #endif const ll LLINF = (1LL<<60); const int INF = (1LL<<30); const double DINF = std::numeric_limits<double>::infinity(); const int MOD = 1000000007; #define MAX_N 100010 signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int N; vector<int> V; cin >> N; V.resize(N); REP(i, N) { cin >> V[i]; } map<int, int> even, odd; REP(i, N) { if(i % 2 == 0) { even[V[i]]++; } else { odd[V[i]]++; } } vector< pair<int, int> > v_even, v_odd; for(auto& tmp : even) { v_even.push_back(make_pair(tmp.second, tmp.first)); } v_even.push_back(make_pair(0, -1)); for(auto& tmp : odd) { v_odd.push_back(make_pair(tmp.second, tmp.first)); } v_odd.push_back(make_pair(0, -1)); SORT(v_even); reverse(v_even.begin(), v_even.end()); SORT(v_odd); reverse(v_odd.begin(), v_odd.end()); int ans = N; int i_n = v_even.size(); if(i_n > 10) { i_n = 10;} int j_n = v_odd.size(); if(j_n > 10) { j_n = 10;} for(int i = 0; i < i_n; ++i) { for(int j = 0; j < j_n; ++j) { if(v_even[i].second != v_odd[j].second) { ans = min(ans, N - v_even[i].first - v_odd[j].first); } } } printf("%lld\n", ans); return 0; }
0
33,973,511
#include <bits/stdc++.h> #define REPI(x) for(int i=0;i<x;i++) #define REPJ(x) for(int j=0;j<x;j++) #define REPISE (s,e) for(int i=s,i<e;i++) #define REPJSE (s,e) for(int j=s,j<e;j++) typedef long long ll; using namespace std; int main () { int N,M,a,b,n; int pathes = 0; cin >> N >> M; vector<vector<int> > vvi(N+1); vector<bool> visited(N+1); queue<int> connected; vector<int> path(N+1); REPI(N+1){ visited[i] = false; path[i] = -1; } REPI(M) { cin >> a >> b; vvi[a].push_back(b); vvi[b].push_back(a); } connected.push(1); while(!connected.empty ()) { n = connected.front(); connected.pop (); if (visited[n]) continue; visited[n] = true; for (auto i = vvi[n].begin(); i != vvi[n].end (); i++) { if (path[(*i)] != -1) continue; path[(*i)] = n; pathes++; connected.push((*i)); } } if (pathes < N-1) cout << "No" << endl; else { cout << "Yes" << endl; for(int i=2;i<=N;i++) cout << path[i] << endl; } return 0; }
#include <iostream> using namespace std; int main() { int a,b; scanf("%d %d",&a,&b); while( a!=0 || b!=0) { for(int i=0;i<a;i++) { for(int j=0;j<b;j++) { cout << "#"; } cout << endl; } cout << endl; scanf("%d %d",&a,&b); } return 0; }
0
27,265,100
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; long long k; cin >> k; vector<long long> len(n + 1), pate(n + 1); len[0] = pate[0] = 1; for (int i = 1; i <= n; i++) { len[i] = 1 + len[i - 1] + 1 + len[i - 1] + 1; pate[i] = pate[i - 1] + 1 + pate[i - 1]; } auto rec = [&](auto rec, int m, long long k) { if (k == len[m]) return pate[m]; long long ans = 0; k--; if (k > 0) { long long l = min(k, len[m - 1]); ans += rec(rec, m - 1, l); k -= l; } if (k > 0) { ans++; k--; } if (k > 0) { long long l = min(k, len[m - 1]); ans += rec(rec, m - 1, l); k -= l; } return ans; }; cout << rec(rec, n, k) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define ALL(x) (x).begin(),(x).end() const int IINF = 1e9; const LL LINF = 1e18; const LL mod = 1e9+7; int main() { int H, W; cin >> H >> W; vector<vector<tuple<int, int, int, int>>> v(H, vector<tuple<int, int, int, int>>(W, make_tuple(0, 0, 0, 0))); vector<string> s(H); REP(i, H) { cin >> s[i]; } REP(i, H) { int left = -1; REP(j, W) { if(s[i][j] == '#') { left = j; }else{ v[i][j] = make_tuple(left, 0, 0, 0); } } int right = W; for(int j = W - 1;0 <= j;j--) { if(s[i][j] == '#') { right = j; }else{ int l; tie(l, ignore, ignore, ignore) = v[i][j]; v[i][j] = make_tuple(l, right, 0, 0); } } } REP(j, W) { int up = -1; REP(i, H) { if(s[i][j] == '#') { up = i; }else{ int l, r; tie(l, r, ignore, ignore) = v[i][j]; v[i][j] = make_tuple(l, r, up, 0); } } int down = H; for(int i = H - 1;0 <= i;i--) { if(s[i][j] == '#') { down = i; }else{ int l, r, u; tie(l, r, u, ignore) = v[i][j]; v[i][j] = make_tuple(l, r, u, down); } } } int res = -1; REP(i, H) { REP(j, W) { int l, r, u, d; tie(l, r, u, d) = v[i][j]; if(l < r && u < d) { res = max(res, (r - l) + (d - u) - 3); } } } cout << res << endl; return 0; }
0
49,430,955
#include <iostream> #include <map> #include <string> using namespace std; int main() { int i = 0, max_num = 0, max_length_string_num = 0, tmp_num = 0; map< string, int > input_word; string tmp, max_length_string, max_num_string; while ( cin >> tmp ) { input_word[tmp] = input_word[tmp] + 1; if ( tmp.length() > max_length_string_num ) { max_length_string = tmp; max_length_string_num = tmp.length(); } } map< string, int >::iterator it = input_word.begin(); while ( it != input_word.end() ) { tmp_num = (*it).second; if ( tmp_num > max_num ) { max_num_string = (*it).first; max_num = tmp_num; } ++it; } cout << max_num_string << " " << max_length_string << endl; return 0; }
#include<iostream> #include<cstdio> #include<cstring> template<typename T>inline void read(T &x) { char c=x=0; for(c=getchar();!isdigit(c);c=getchar()); for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48); } namespace Good_problem { typedef long long ll; const int N=101000,M=N*4; int begin[N],next[M],to[M]; int n,m,e; ll A,B,C; void add(int x,int y,bool k=1) { to[++e]=y; next[e]=begin[x]; begin[x]=e; if(k)add(y,x,0); } int col[N]; bool dfs(int p,int x) { if(col[p])return col[p]==x; col[p]=x; bool ret=1; for(int i=begin[p],q;i;i=next[i]) if(!dfs(q=to[i],3-x))ret=0; return ret; } void initialize() { read(n),read(m); for(int i=1,u,v;i<=m;i++) read(u),read(v),add(u,v); } void solve() { initialize(); A=B=C=0; for(int i=1;i<=n;i++) if(!col[i]) { if(!dfs(i,1))B++; else if(begin[i])A++; else C++; } printf("%lld\n",2*A*A+2*A*B+B*B+2*n*C-C*C); } } int main() { Good_problem::solve(); return 0; }
0
96,247,111
#include<bits/stdc++.h> #define Tp template<typename Ty> #define Ts template<typename Ty,typename... Ar> #define Reg register #define RI Reg int #define Con const #define CI Con int& #define I inline #define W while using namespace std; int n;I int gcd(CI x,CI y) {return y?gcd(y,x%y):x;} int main() { return scanf("%d",&n),printf("%d\n",360/gcd(360,n)),0; }
#include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std; int main(){ long long N, P; cin >> N >> P; string s; cin >> s; reverse(s.begin(), s.end()); long long len = s.size(); vector<long long> d(len+1); long long keta = 1; d[0] = 0; vector<long long> count(P+1, 0); count[0]++; for(long long i=0; i<len; ++i){ long long digit = (s[i] - '0'); long long a = (digit * keta) %P; d[i+1] = (d[i] + a) % P; keta *= 10; keta %= P; count[d[i+1]]++; } long long ans =0; if( P == 2 || P == 5){ for(long long i=0; i<len; ++i){ long long digit = (s[i] - '0'); if(digit % P == 0){ ans += len - i; } } }else{ for(long long i=0; i<P; ++i){ if(count[i] > 1){ ans += (count[i] * (count[i]-1) )/2; } } } cout << ans << endl; }
0
54,929,654
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; if (S == "a" || S == "e" || S == "i" || S == "u" || S == "o") cout << "vowel" << endl; else cout << "consonant" << endl; }
#include <bits/stdc++.h> using namespace std; bool answer(string &s){ if(s=="") return true; int l=s.size(); if(s.at(l-1)=='m'&&s.at(l-2)=='a'&&s.at(l-3)=='e'&&s.at(l-4)=='r'&&s.at(l-5)=='d') return answer(s.erase(l-5)); if(s.at(l-1)=='e'&&s.at(l-2)=='s'&&s.at(l-3)=='a'&&s.at(l-4)=='r'&&s.at(l-5)=='e') return answer(s.erase(l-5)); if(s.at(l-1)=='r'&&s.at(l-2)=='e'&&s.at(l-3)=='s'&&s.at(l-4)=='a'&&s.at(l-5)=='r'&&s.at(l-6)=='e') return answer(s.erase(l-6)); if(s.at(l-1)=='r'&&s.at(l-2)=='e'&&s.at(l-3)=='m'&&s.at(l-4)=='a'&&s.at(l-5)=='e'&&s.at(l-6)=='r'&&s.at(l-7)=='d') return answer(s.erase(l-7)); return false; } int main() { string s; cin >> s; if(answer(s)) cout << "YES" << endl; else cout << "NO" << endl; }
0
39,060,820
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cstdlib> #include<queue> using namespace std; #define rep(i, n) for(long int i = 0; i < n; i++) int main(){ long int x, y, z, k; cin >> x >> y >> z >> k; long int a[x], b[y], c[z]; rep(i, x) cin >> a[i]; rep(i, y) cin >> b[i]; rep(i, z) cin >> c[i]; long int a2[x*y]; long int idx = 0; rep(i, x){ rep(j, y){ a2[idx] = a[i] + b[j]; idx++; } } sort(a2, a2 + x * y, greater<long int>()); long int num = min(k, x * y); long int a3[num*z]; idx = 0; rep(i, num){ rep(j, z){ a3[idx] = a2[i] + c[j]; idx++; } } sort(a3, a3 + num * z, greater<long int>()); long int ans = 0; rep(i, k){ cout << a3[i] << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; #define int ll const int INF=(int)2e18; const int MOD = 1000000007; const int PEG = 998244353; long double pie=acos(-1); typedef vector< int > vi; typedef vector< string > vs; typedef vector< vi > vvi; typedef pair< int, int > pii; typedef vector< pii > vpii; #define X first #define Y second #define pb push_back #define sz(a) (ll)(a).size() #define all(a) (a).begin(),(a).end() #define F(i,a,b) for(ll i=a;i<=b;i++) #define RF(i,a,b) for(ll i=a;i>=b;i--) #define Fo(i,a,b,j) for(ll i=a;i<=b;i+=j) #define RFo(i,a,b,j) for(ll i=a;i>=b;i-=j) #define in(a,n) F(i,0,n-1)cin>>a[i] #define in1(a,n) F(i,1,n)cin>>a[i] #define out(a,n) F(i,0,n-1)cout<<a[i]<<" " #define out1(a,n) F(i,1,n)cout<<a[i]<<" " #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define popcount __builtin_popcountll #define pfy cout<<"YES" #define pfn cout<<"NO" #define pfn1 cout<<"-1" #define pf1 cout<<"1" #define nl cout<<"\n" #define watch(x) cout<<#x<<" is "<<x<<"\n" #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1>void __f(const char* name,Arg1&& arg1); template <typename Arg1,typename... Args>void __f(const char* names,Arg1&& arg1,Args&&... args); ll binpow(ll x,ll y,ll p); signed main() { #ifndef ONLINE_JUDGE #endif fast; int x; cin>>x; int mxn=1e5; F(a,0,mxn) { if(100*a>x)break; F(b,0,mxn) { if(100*a+101*b>x)break; F(c,0,mxn) { if(100*a+101*b+102*c>x)break; F(d,0,mxn) { if(100*a+101*b+102*c+103*d>x)break; F(e,0,mxn) { if(100*a+101*b+102*c+103*d+104*e>x)break; F(f,0,mxn) { if(100*a+101*b+102*c+103*d+104*e+105*f>x)break; if(100*a+101*b+102*c+103*d+104*e+105*f==x) { cout<<1; return 0; } } } } } } } cout<<0; return 0; } ll binpow(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { const char *comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1 << "\n"; __f(comma + 1, args...); }
0
41,303,019
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, M; cin >> N >> M; ll A, B; vector<vector<ll>> G(N); for (ll i=0; i<M; i++) { cin >> A >> B; A--; B--; G[A].push_back(B); G[B].push_back(A); } vector<ll> dist(N,-1); queue<ll> q; dist[0] = 0; q.push(0); vector<ll> ans(N); while(!q.empty()) { ll v = q.front(); q.pop(); for (ll nv : G[v]) { if (dist[nv] != -1) { continue; } dist[nv] = dist[v] + 1; ans[nv] = v+1; q.push(nv); } } for (ll i=1; i<N; i++) { if (dist[i]==-1) { cout << "No" << endl; exit(0); } } cout << "Yes" << endl; for (ll i=1; i<N; i++) { cout << ans[i] << endl; } }
#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
92,527,784
#include <iostream> #include <algorithm> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string str; int q; cin >> str; cin >> q; string cmd, p; int a, b; for (int i = 0; i < q; i++) { cin >> cmd; if (cmd == "print") { cin >> a >> b; cout << str.substr(a, (b-a+1)) << "\n"; } else if (cmd == "reverse") { cin >> a >> b; string sub = str.substr(a, (b-a+1)); reverse(sub.begin(), sub.end()); str = str.substr(0, a) + sub + str.substr(b+1); } else if (cmd == "replace") { cin >> a >> b >> p; str = str.substr(0, a) + p + str.substr(b+1); } } }
#include<iostream> using namespace std; int main() { string s, t; cin >> s >> t; t.pop_back(); if (s == t)cout << "Yes"; else cout << "No"; return 0; }
0
10,153,042
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define clr(v) v.clear() vector<ll>v; pair<ll,ll>p; map<ll,ll>mp; set<ll>st; deque<ll>dq; priority_queue<ll>pq; #define f(i,b) for(i=0;i<b;i++) #define f1(i,b) for(i=1;i<=b;i++) #define fr(i,b)for(i=b-1;i>=0;i--) ll mn=INT_MAX,mx=INT_MIN; ll n,m,tc,i,j,tmp,sum,cn,ans,res,pos,flag,l,x,k,dif; string s,str; ll a[200007],b[200007]; int main() { io; ll n,m; cin>>n>>m; cout<<(n-1)*(m-1); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = (0); i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define limit(x,l,r) max(l,min(x,r)) #define lims(x,l,r) (x = max(l,min(x,r))) #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl #define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ') #define showv2(v) rep(j,v.size()) showv(v[j]) #define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ') #define showt2(t,r,c) rep(j,r) showt(t[j],c) #define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second) #define printv(v) rep(i,v.size()) printf("%d\n", v[i]) #define printt(t,n) rep(i,n) printf("%d\n", t[i]) #define incl(v,x) (find(all(v),x)!=v.end()) #define incls(s,c) (s.find(c)!=string::npos) #define lb(a,x) distance((a).begin(),lower_bound(all(a),(x))) #define ub(a,x) distance((a).begin(),upper_bound(all(a),(x))) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bit(n,k) ((n>>k)&1) #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") #define uni(x) x.erase(unique(all(x)),x.end()) #define SP << " " << using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; using vb = vector<bool>; using vvb = vector<vb>; using P = pair<int, int>; using T = tuple<int, int, int>; using vp = vector<P>; using vt = vector<T>; const int mod = 1000000007; const double EPS = 1e-9; const int INF = (1<<30)-1; const ll LINF = (1LL<<62)-1; #define dame { puts("No"); return 0;} #define yn {puts("Yes");}else{puts("No");} inline int in() { int x; cin >> x; return x;} inline ll lin() { ll x; cin >> x; return x;} inline char chin() { char x; cin >> x; return x;} inline string stin() { string x; cin >> x; return x;} inline double din() { double x; cin >> x; return x;} template<typename T>inline ll suma(const vector<T>& a) { ll res(0); for (auto&& x : a) res += x; return res;} template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } char itoa(int n) { return n + '0';} ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} const int dx[4] = {1, 0,-1, 0}; const int dy[4] = {0, 1, 0,-1}; int main () { int n, m; cin >> n >> m; vvl dist(n,vl(n,LINF)); rep(i,n) dist[i][i] = 0; rep(i,m) { int s, t; ll d; cin >> s >> t >> d; dist[s][t] = d; } rep(k,n)rep(i,n)rep(j,n) { if (dist[i][k] == LINF || dist[k][j] == LINF) continue; chmin(dist[i][j], dist[i][k]+dist[k][j]); } bool negative = false; rep(i,n) { if (dist[i][i] < 0) negative = true; } if (negative) { puts("NEGATIVE CYCLE"); return 0; } rep(i,n) { rep(j,n) { if (dist[i][j] == LINF) cout << "INF"; else cout << dist[i][j]; if (j < n-1) cout << ' '; } cout << '\n'; } return 0; }
0
34,190,278
#include <bits/stdc++.h> using namespace std; int main() { int N, X, T; cin >> N >> X >> T; int count = N / X; if (N % X != 0) { count++; } cout << count * T << endl; return 0; }
#include <iostream> using namespace std; int main(){ int H[25565] = {0}; int W[25565] = {0}; int i; do{ cin >> H[i] >> W[i]; i++; }while(H[i-1] != 0 && W[i-1] != 0); i = 0; do{ for(int j=0;j<W[i];j++){ cout << "#"; } cout << endl; for(int j=0;j<H[i]-2;j++){ cout << "#"; for(int k=0;k<W[i]-2;k++){ cout << "."; } cout << "#" << endl; } for(int j=0;j<W[i];j++){ cout << "#"; } cout << endl << endl; i++; }while(H[i] != 0 && W[i] != 0); }
0
2,296,662
#include<bits/stdc++.h> #define rep(i, n) for (int i=0;i<(n);i++) using namespace std; typedef long long ll; int main(void){ int r, g, b, n; cin>>r>>g>>b>>n; int ans = 0; rep(i, 3001){ rep(j, 3001){ int k = n-(r*i+g*j); if(k%b == 0 && k>=0) ans++; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) typedef long long ll; using namespace std; const ll mod=1000000007; #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); ll n; cin>>n; ll a[n],d[n],sum=0; for(int i=0;i<n;i++){ cin>>a[i]; if(i){ d[i-1]=a[i]-a[i-1]; } sum+=a[i]; } d[n-1]=a[0]-a[n-1]; ll k=sum/(n*(n+1)/2); if(sum==k*(n*(n+1)/2)){ for(int i=0;i<n;i++){ if(d[i]<=k&&(d[i]-k)%n==0){ continue; } else{ cout << "NO"<<endl; return 0; } } cout << "YES"<<endl; } else{ cout << "NO"<<endl; } return 0; }
0
48,245,758
#include<bits/stdc++.h> #define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; int n,m; int main() { cin>>n; long long x=n*(n+1)/2; cout<<x<<endl; return 0; }
#include <cstdio> int m,nmin,nmax; int P[205]; int diff[205]; int main(){ while(scanf("%d%d%d",&m,&nmin,&nmax)&&m&&nmin&&nmax){ for(int i=1;i<=m;i++) scanf("%d",P+i); for(int i=1;i<=m-1;i++) diff[i]=P[i]-P[i+1]; int ans=nmax,difference=diff[ans]; for(int i=nmax;i>=nmin;i--) if (diff[i]>difference) ans=i,difference=diff[i]; printf("%d\n",ans); } return 0; }
0
1,478,624
#include <stdio.h> long long int fact(long long int n){ return (n==0)? 1 : n*fact(n-1); } int main(){ long long int n; scanf("%lld", &n); printf("%lld\n", fact(n)); }
#include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <cfenv> #include <cinttypes> #include <cstdint> #endif #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <chrono> #include <forward_list> #include <initializer_list> #include <random> #include <ratio> #include <regex> #include <system_error> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif #if __cplusplus >= 201402L #include <shared_mutex> #endif #define rep(i,n) for(ll i = 0;i < n;++i) #define all(v) v.begin(),v.end() using namespace std; using ll = long long; typedef pair<int,int> P; const int INF = 1001001001; const long double PI = (acos(-1)); const int mod = 1e9+7; const int vx[4] = {0,1,0,-1}; const int vy[4] = {1,0,-1,0}; ll gcd(ll x,ll y){ x = x%y; return x == 0 ? y : gcd(y,x); } ll lcm(ll x, ll y){ return x*y/gcd(x,y); } int main(){ int n; cin >> n; priority_queue<int> q; vector<int> a(n); rep(i,n) { cin >> a[i]; q.push(a[i]); } rep(i,n){ int t = q.top(); if(t == a[i]){ q.pop(); cout << q.top() << endl; q.push(t); }else{ cout << t << endl; } } return 0; }
0
68,760,117
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; set<string>s; string prev_word,word; cin>>word; s.insert(word); --n; bool ans = true; while(n--) { prev_word = word; cin>>word; if(s.count(word)!=0) ans = false; if(prev_word[prev_word.size()-1]!=word[0]) ans = false; s.insert(word); } if(ans) cout<<"Yes"; else cout<<"No"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long int INF = 1LL<<60; const long long int Mod = 1000000007; using ll = long long int; using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using P = pair<int, int>; using PLL = pair<ll, ll>; using matrix = vector<vector<ll>>; #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define rp(i,N) for(ll i = 0; i < (ll)N; i++) #define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i) template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; } template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; } template<class T>T sqar(T x){ return x*x; } #define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) #define p_queue(v) priority_queue<v, vector<v>, greater<v> > template<class T> inline void princ(T x){cout<<x<<" ";}; template<class T> inline void print(T x){cout<<x<<"\n";}; template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } int main(){ int n; cin >> n; vi v1((n+1)/2),v2(n/2); rp(i,n/2){ cin >> v1.at(i) >> v2.at(i); } if(n&1) cin >> v1.at((n-1)/2); priority_queue<P> que1,que2; sort(all(v1)); sort(all(v2)); int ctr=1; rp(i,(n+1)/2-1){ if(v1.at(i)==v1.at(i+1)) ctr++; else{ que1.push(mp(ctr,v1.at(i))); ctr=1; } } que1.push(mp(ctr,v1.back())); ctr=1; rp(i,n/2-1){ if(v2.at(i)==v2.at(i+1)) ctr++; else{ que2.push(mp(ctr,v2.at(i))); ctr=1; } } que2.push(mp(ctr,v2.back())); int t[2][2]; t[0][0]=que1.top().first; t[0][1]=que1.top().second; t[1][0]=que2.top().first; t[1][1]=que2.top().second; que1.pop(); que2.pop(); if(t[0][1]!=t[1][1]){ print(n-t[0][0]-t[1][0]); } else if(que1.empty()){ if(que2.empty()){ print(n/2); } else{ print(n/2-que2.top().first); } } else if(que2.empty()){ print((n+1)/2-que1.top().first); } else{ print(n-max(t[0][0]+que2.top().first,t[1][0]+que1.top().first)); } return 0; }
0
19,411,291
#include <bits/stdc++.h> using namespace std; int main(void){ long long int i=0,j,c=0,k; string s; cin >> s; k=s.size(); if(s[0]!='A' || s[1]<'a' || s[k-1]<'a' ) { cout << "WA" << endl; return 0; } for(i=2;i<k-1;i++) { if(s[i]=='C') { c++; if(c==2) { cout << "WA" << endl; return 0; } continue; } if(s[i]<'a') { cout << "WA" << endl; return 0; } } if(c==1) { cout << "AC" << endl; } else { cout << "WA" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; using vl = vector<ll>; using vvl = vector<vl>; using vp = vector<pair<int,int>>; #define FOR(i,a,b) for(ll i=a;i<b;i++) #define rep(i,n) FOR(i,0,n) const ll INF = 9223372036854775807; int main() { int n,m;cin >> n >> m; vector<pair<int,string>> in(m); vector<bool> TF(n+1,false); rep(i,m){ int a;string s; cin >> a >> s; pair<int,string> p; p.first = a; p.second = s; in[i]=p; } int wa = 0; int ac = 0; vector<int> numwa(n+1,0); rep(i,m){ if(TF[in[i].first]) continue; if(in[i].second == "WA") numwa[in[i].first]++; if(in[i].second == "AC") { ac++; TF[in[i].first] = true; wa += numwa[in[i].first]; } } cout << ac << " " << wa << endl; }
0
47,047,367
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < ll(n); i++) int main() { string s; cin >> s; int cnt = 0, k = s.size(); for(char c : s){ if (c == 'o') cnt++; } cnt += 15 - k; puts((cnt >= 8 ? "YES" : "NO")); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pa pair<int, int> #define pal pair<long long, long long> #define pali pair<long long, int> #define pad pair<double, double> #define pb push_back #define mp make_pair #define COUT(v) \ for (int64_t i = 0; i < (v).size(); ++i) \ { \ cout << v.at(i) << endl; \ } #define REP(i, n) for (int64_t i = 0; i < n; ++i) #define FOR(i, r, n) for (int64_t i = (r); i < n; ++i) #define VIN(v) \ for (int64_t i = 0; i < (v).size(); ++i) \ { \ cin >> (v).at(i); \ } typedef vector<bool> bvec; typedef vector<int> ivec; typedef vector<long long> lvec; typedef vector<double> dvec; typedef vector<pa> pavec; typedef vector<pali> palivec; typedef vector<pal> palvec; typedef vector<vector<bool> > bmat; typedef vector<vector<int> > imat; typedef vector<vector<long long> > lmat; typedef vector<string> svec; typedef vector<vector<string> > smat; const ll infll = (1LL << 60) - 1; const int inf = (1 << 30) - 1; const ll MOD = 1000000007; ll gcd(ll x, ll y) { ll r = x % y; if (r == 0) return y; else return gcd(y, r); } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } lvec mfactor(ll n) { bvec ip(n, true); lvec mf(n, -1); ip[0] = false; ip[1] = false; mf[0] = 0; mf[1] = 1; REP(i, n) { if (ip[i]) { mf[i] = i; for (ll j = i * i; j < n; j += i) { ip[j] = false; if (mf[j] == -1) mf[j] = i; } } } return mf; } palivec get_prime(ll n, const lvec &mf) { palivec plist; while (n != 1) { int cnt = 0; ll m = mf[n]; while (mf[n] == m) { cnt++; n /= m; } plist.pb(pali(m, cnt)); } return plist; } void COMinit(int m, lvec &fac, lvec &finv) { lvec inv(m); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < m; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll pow_mod(ll a, ll n) { ll x = 1; while (n > 0) { if (n & 1) { x = x * a % MOD; } a = a * a % MOD; n >>= 1; } return x; } ll COM(int n, int k, const lvec &fac, const lvec &finv) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll 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 main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; lvec a(n), s(n); map<int, int> mmap, mmap2; for (int i=0; i<n; i++){ cin >> a[i]; } s[0] = a[0]; for (int i=1; i<n; i++) s[i] = (s[i-1]+a[i]); ll ans=0; if(a[0]%k==1) ++ans; for (int i=1; i<n; i++){ mmap[(s[i-1]-i)%k]++; if(mmap.count((s[i]-i-1)%k)){ ans+=mmap[(s[i]-i-1)%k]; } if(i+1>k){ mmap2[(s[i-k]-(i-k+1))%k]++; if(mmap2.count((s[i]-i-1)%k)) { ans-=mmap2[(s[i]-i-1)%k]; } } if(s[i]%k == i+1) ++ans; } cout << ans << endl; }
0
100,495,990
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; long long count =0; for(int i=1; i<=sqrt(N); i++){ long long syou = N/i; if(N%i==0 && syou>2 && i<syou-1)count += syou-1; } cout << count << endl; }
#include <iostream> using namespace std; int main (){ while(true){ int n; cin >> n; int max=0; int min = 10000; int sum = 0; int x; int count =0; if(n==0)return 0; for(int i=0;i<n;i++){ cin >> x; if(min>x)min=x; if(max<x)max=x; sum = sum + x; count++; } int average; average = (sum -min -max)/(count-2); cout << average << endl; } }
0
33,426,966
#include<bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; int r,c; vector<vector<char>> grid; vector<vector<ll>> dp; void print() { for(int i=1; i<=r; i++){ for(int j=1; j<=c; j++){ cout << dp[i][j] << " "; } cout << '\n'; } cout << '\n'; } inline bool is_safe(int i, int j) { return (i>=1 && j>=1 && i<=r && j<=c && grid[i][j]!='#'); } void init() { grid.resize(r+1, vector<char>(c+1)); dp.resize(r+1, vector<ll>(c+1)); } void solve() { for(int i=1; i<=c; i++) { if(is_safe(1, i)) dp[1][i] = 1; else break; } for(int j=1; j<=r; j++) { if(is_safe(j, 1)) dp[j][1] = 1; else break; } for(int i=2; i<=r; i++){ for(int j=2; j<=c; j++){ if(is_safe(i, j)){ if(is_safe(i-1, j)) dp[i][j] = (dp[i][j] + dp[i-1][j])%mod; if(is_safe(i, j-1)) dp[i][j] = (dp[i][j] + dp[i][j-1])%mod; } } } cout << dp[r][c] << '\n'; } int main() { cin >> r >> c; init(); for(int i=1; i<=r; i++){ for(int j=1; j<=c; j++){ cin >> grid[i][j]; } } solve(); return 0; }
#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); string S,T; cin >> S >> T; map<char,int> s,t; rep(i,S.size()){ s[S[i]]++; t[T[i]]++; } vi cnt_s,cnt_t; for(auto x : s) cnt_s.push_back(x.second); for(auto x : t) cnt_t.push_back(x.second); sort(all(cnt_s)); sort(all(cnt_t)); if(cnt_s.size() != cnt_t.size()){ cout << "No"; return 0; }else{ rep(i,cnt_t.size()){ if(cnt_s[i] != cnt_t[i]){ cout << "No"; return 0; } } } cout << "Yes"; cout << "\n"; return 0; }
0
42,506,523
#include<stdio.h> #include<math.h> #include<algorithm> #include<queue> #include<deque> #include<stack> #include<string> #include<string.h> #include<vector> #include<set> #include<map> #include<bitset> #include<stdlib.h> #include<cassert> #include<time.h> #include<bitset> using namespace std; const long long mod=1000000007; const long long inf=mod*mod; const long long d2=(mod+1)/2; const long double EPS=1e-9; const long double PI=acos(-1.0); int ABS(int a){return max(a,-a);} long long ABS(long long a){return max(a,-a);} long double ABS(long double a){return max(a,-a);} int b[20]; int main(){ for(int i=0;i<4;i++){ int a;scanf("%d",&a);b[a]++; } if(b[1]&&b[9]&&b[7]&&b[4])printf("YES\n"); else printf("NO\n"); }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define pp pair<int,int> #define ll long long int inf=100000000; ll INF=100000000000000000; ll MOD=1000000007; int main() { int n; cin >> n; vector<int> a(n),v(n); int t=0; rep(i,n) {cin >> a.at(i);a.at(i)*=2;t+=a.at(i);} rep(i,n) {cin >> v.at(i);v.at(i)*=2;} vector<int> mv(2*t+1); mv.at(0)=0; int nt=0; int q=0; for(int i=1;i<t;i++){ nt++; if (nt==a.at(q) && v.at(q) >v.at(q+1)) {nt=0;q++;} mv.at(i)=min(mv.at(i-1)+1,v.at(q)); if (nt==a.at(q) && v.at(q) <=v.at(q+1)) {nt=0;q++;} } mv.at(t)=0; for (double i=t-1;i>0;i--){ mv.at(i)=min(mv.at(i+1)+1,mv.at(i)); } int ans=0; int o=0; for (int i=1;i<t+1;i++){ o++; ans+=(mv.at(2*i)+mv.at(2*i-1)); } double yy=ans; yy=yy/4; printf("%.10f\n", yy); }
0
67,468,703
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(a) (a).begin(),(a).end() #define MOD 1000000007 typedef long long int ll; const ll INF=(ll)1e18; int main(){ int N,A; cin >> N >> A; cout << N*N-A << endl; }
#include <iostream> #include <cmath> #include <algorithm> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(N, 0), B(N, 0); for (int i = 0; i < N; i++) cin >> A[i] >> B[i]; vector<int> C(M, 0), D(M, 0), I(M, 0); for (int i = 0; i < M; i++) { cin >> C[i] >> D[i]; I[i] = i + 1; } for (int i = 0; i < M; i++) for (int j = i + 1; j < M; j++) if (C[i] == C[j] && D[i] == D[j]) C.erase(C.begin() + j), D.erase(D.begin() + j), I.erase(I.begin() + j); for (int i = 0; i < N; i++) { long long int mini = 0, ans = 0; for (int j = 0; j < C.size(); j++) { int tmp = abs(A[i] - C[j]) + abs(B[i] - D[j]); if (j == 0) mini = tmp, ans = I[j]; else if (mini > tmp) mini = tmp, ans = I[j]; } cout << ans << endl; } }
0
56,175,164
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <string> #include <sstream> #include <complex> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <iomanip> #include <limits> using namespace std; typedef pair<long long, long long> P; vector<P> prime_factorize(long long n) { vector<P> res; for (long long p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } long long gcd(long long x, long long y) { if (y == 0) { return x; } else { return gcd(y, x % y); } } const int MOD = 1000000007; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, n) for (int i = 0; i < (n); i++) int main() { int n,m; cin>>n>>m; vector<vector<int> > G(n,vector<int>()); for(int i=0;i<m;i++){ int a,b; cin>>a>>b; a--,b--; G[a].push_back(b); G[b].push_back(a); } vector<int> dist(n,-1); vector<int> prev(n,-1); queue<int> que; que.push(0); dist[0]=0; while(!que.empty()){ int v=que.front(); que.pop(); for(auto nv:G[v]){ if(dist[nv]==-1){ dist[nv]=dist[v]+1; prev[nv]=v; que.push(nv); } } } cout<<"Yes"<<endl; for(int i=1;i<n;i++){ cout<<prev[i]+1<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=1000000007; #define INF 1LL<<30 #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() int main() { ll a,b; cin>>a>>b; ll fa,fb; if(a==0 && b==0){ cout<<0<<endl; return 0; } if(a==0 || a==1){ if(b%4==0) fb=b; else if(b%4==1) fb=1; else if(b%4==2) fb=b+1; else fb=0; cout<<fb<<endl; return 0; } a=a-1; if(a%4==0) fa=a; else if(a%4==1) fa=1; else if(a%4==2) fa=a+1; else fa=0; if(b%4==0) fb=b; else if(b%4==1) fb=1; else if(b%4==2) fb=b+1; else fb=0; ll ans=fb^fa; cout<<ans<<endl; }
0
26,579,525
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i,n) for(ll i=0;i<(n);i++) #define pll pair<ll,ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define lb(c,x) distance(c.begin(),lower_bound(all(c),x)) #define ub(c,x) distance(c.begin(),upper_bound(all(c),x)) 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=1e9+7; int main(){ vector<ll> ans(4); rep(i,3){ ll a,b; cin >> a >> b; a--; b--; ans[a]++; ans[b]++; } ll cnt_one=0,cnt_two=0; rep(i,4){ if(ans[i]==1) cnt_one++; if(ans[i]==2) cnt_two++; } if(cnt_one==2 && cnt_two==2) cout << "YES" << endl; else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; #define PI 3.1415926535897932384626433832795l #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define f first #define s second using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using vpii = vector<pair<int,int>>; using vpll = vector<pair<ll,ll>>; using pii = pair<int,int>; using pll = pair<ll,ll>; #define endl '\n' #define re return #define repz(i, a) for (ll i = 0; i < (a); i++) #define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i]; #define full(v) v.begin(),v.end() void solve() { int na, nb, m; cin >> na >> nb >> m; vi a(na); vi b(nb); vecin(na,a); vecin(nb,b); vi x(m); vi y(m); vi c(m); repz(i,m) { cin >> x[i] >> y[i] >> c[i]; } int ans = 0; ans = *min_element(full(a)) + *min_element(full(b)); for (int i = 0; i < m; i++) { ans = min(ans,a[x[i]-1]+b[y[i]-1]-c[i]); } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1; while (t--) { solve(); } }
0
44,440,991
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; int main(){ int n,d,x; cin>>n>>d>>x; for(int i=0;i<n;i++){ int a; cin>>a; x+=(d-1)/a+1; } cout<<x<<endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<long long, long long> pll; const ll MOD = 1e9 + 7; int N, K; int a[109]; ll dp[100009], pre[100009]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> N >> K; for (int i = 1; i <= N; i++) { cin >> a[i]; } dp[0] = 1; for (int i = 1; i <= N; i++) { for (int used = K; used >= 0; used--) { int t = dp[used]; int L = used + 1; int R = min(a[i] + used, K); pre[L] += t; pre[R + 1] -= t; } ll p = 0; for (int j = 0; j <= K; j++) { p += pre[j]; pre[j] = 0; dp[j] += p; dp[j] %= MOD; dp[j] += MOD; dp[j] %= MOD; } } cout << dp[K] << "\n"; }
0
54,624,879
#include <iostream> #include <complex> #include <sstream> #include <string> #include <algorithm> #include <deque> #include <list> #include <map> #include <numeric> #include <queue> #include <vector> #include <set> #include <limits> #include <cstdio> #include <cctype> #include <cmath> #include <cstring> #include <cstdlib> #include <ctime> using namespace std; #define REP(i, j) for(int i = 0; i < (int)(j); ++i) #define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i) #define SORT(v) sort((v).begin(), (v).end()) #define REVERSE(v) reverse((v).begin(), (v).end()) typedef complex<double> P; int main() { FOR(i, 1, 10) FOR(j, 1, 10) printf("%dx%d=%d\n", i, j, i * j); return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) #define all(c) (c).begin(),(c).end() #define pb push_back #define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0); using namespace std; namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};} template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";} template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";} void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);} typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9; int main(){ cin.tie(0); cin.sync_with_stdio(0); int h, w, n; cin >> h >> w >> n; vi a(n), b(n); map<int, vi> pt; rep(i, n){ cin >> a[i] >> b[i]; pt[a[i]].pb(b[i]); } for(auto &p : pt) sort(all(p.second)); vector<ll> ans(10); ans[0] = (h - 2) * (w - 2ll); set<pi> vis; auto cnt = [&](int y, int x){ if(vis.count(pi(y, x))) return -1; vis.emplace(y, x); int c = 0; for(int i = y; i <= y + 2; i++) if(pt.count(i)){ const vi &v = pt[i]; c += lower_bound(all(v), x + 3) - lower_bound(all(v), x); } return c; }; rep(i, n) for(int y = max(1, a[i] - 2); y <= h - 2 && y <= a[i] + 2; y++){ for(int x = max(1, b[i] - 2); x <= w - 2 && x <= b[i] + 2; x++){ int c = cnt(y, x); if(c < 0) continue; --ans[0]; ++ans[c]; } } for(ll i : ans) cout << i << endl; return 0; }
0
6,249,854
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<long long>a(n+1),b(n); for(int i = 0; i < n + 1; i++) cin >> a.at(i); for(int i = 0; i < n; i++) cin >> b.at(i); long long sum = 0ll; for(int i = 0; i < n; i++){ if(a.at(i) >= b.at(i)) sum += b.at(i); else{ sum += a.at(i); b.at(i) -= a.at(i); sum += min(a.at(i + 1),b.at(i)); a.at(i + 1) = max(0ll,a.at(i + 1) - b.at(i)); } } cout << sum; }
#include<bits/stdc++.h> #define ll long long int using namespace std; const ll mod=1000000007; const ll inf=1e18; int main(){ ll n; cin >> n; ll p[n]; for(int i=0;i<n;i++)cin >> p[i]; ll s=0; for(int i=0;i<n;i++){ if(p[i]==n)continue; ll a=i,b,c=i,d; ll q=0,r=0; while(a<n && p[a]<=p[i]){ a++; } if(a==n){ a--; q=1; } b=a+1; while(b<n && p[b]<=p[i]){ b++; } while(c>-1 && p[c]<=p[i]){ c--; } if(c==-1){ r=1; c++; } d=c-1; while(d>-1 && p[d]<=p[i]){ d--; } if(q==1){ s+=(a-i+1)*(c-d)*p[i]; } else if(r==1){ s+=(i-c+1)*(b-a)*p[i]; } else{ s+=((a-i)*(c-d)+(i-c)*(b-a))*p[i]; } } cout << s << endl; }
0
1,202,526
#include<bits/stdc++.h> using namespace std; #define ll long long const int mxK = 100; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; if (k>mxK) k = mxK; vector<int> a(n); for (int i=0; i!=n; ++i) cin >> a[i]; while (k--) { vector<int> b(n+1, 0); for (int i=0; i!=n; ++i) { int l=max(0,i-a[i]), r=min(n-1, i+a[i]); ++b[l]; --b[r+1]; } for (int i=0; i!=n; ++i) b[i+1]+=b[i]; a=b; } for (int i=0; i!=n; ++i) cout << (i==0?"":" ") << a[i]; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=1000000007; #define INF 1LL<<30 #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() int main() { int n; cin>>n; int m[n+1][n+1],p[n+1]; rep(i,n){ cin>>p[i]>>p[i+1]; m[i][i]=0; } m[n][n]=0; for(int l=2;l<=n;l++){ for(int i=1;i<=n-l+1;i++){ int j=i+l-1; m[i][j]=1000000; for(int k=i;k<j;k++){ m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]); } } } cout<<m[1][n]<<endl; }
0
49,113,191
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, c, k, o, per, bus; int a[N]; int main() { scanf("%d%d%d", &n, &c, &k); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); } sort(a + 1, a + n + 1); o = 1, per = a[1], bus = 1; for(int i = 2; i <= n; i++) { if(o < c && a[i] <= per + k) o++; else { bus++; per = a[i]; o = 1; } } printf("%d\n", bus); }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); } int a = vec.at(0); int x = 1; for (int i = 0; i < N; i++) { if (vec.at(0) == 2){ break; } else if (vec.at(a-1) == 2){ x ++; break; } else if(x == N){ x = -1; break; } else{ x ++; a = vec.at(a-1); } } cout << x << endl; }
0
59,362,880
#include <bits/stdc++.h> using namespace std; #define all(a)a.begin(),a.end() using ll=long long; const int INF = 1<<30; const ll INFll =1LL<<62; const int mod= int(1e9)+7; using P = pair<ll,ll>; using ld=long double; int main(){ int a,b,c,d;cin >>a>>b>>c>>d; if((a+b)>(c+d))puts("Left"); else if((a+b)==(c+d))puts("Balanced"); else puts("Right"); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <iomanip> #include <stack> #include <algorithm> #include <iostream> #include <string> #include <map> #include <queue> #include <stdio.h> #include <math.h> using namespace std; typedef long long ll; typedef vector<vector<int>> vvi; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<string>> vvs; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef pair<int, int> P; #define mp(x, y) make_pair(x, y) typedef queue<int> qi; typedef queue<string> qs; #define rep(i, n) for(int i=0; i<(n); ++i) #define repp(i, a, b) for(int i = (a); i <= (b); i++) #define repm(i, n) for(int i=n; i >= 0; i--) #define all(v) v.begin(), v.end() bool is_prime(int n) { bool res = true; if (n == 1) return false; else if (n == 2) return true; else { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { res = false; break; } } } return res; } int BinarySearch(vector<int> vec, int key) { int left = 0; int right = vec.size(); while (left < right) { int mid = (left + right) / 2; if (vec[mid] == key) return mid; else if (mid < key) left = mid - 1; else right = mid + 1; } return -1; } bool C(int x) { bool res = false; return res; } ll Binary_search() { ll ok = 1e10; ll ng = -1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (C(mid)) { ok = mid; } else { ng = mid; } } return ok; } int perm(int n, int r) { if (r == 1) return n; return n * perm(n - 1, r - 1); } int fact(int n) { if (n == 1) return 1; return fact(n - 1) * n; } int comb(int n, int r) { int a = min(n, r), b = max(n, r); return perm(a, b) / fact(a); } ll inv_mod(ll a, ll mod) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } ll fact_mod(ll n, ll mod) { ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod; return f; } ll pow_mod(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res; } ll comb_mod(ll n, ll r, ll mod) { if (r > n - r) r = n - r; if (r == 0) return 1; ll a = 1; for (int i = 0; i < r; i++) a = a * ((n - i) % mod) % mod; ll b = pow_mod(fact_mod(r, mod), mod - 2, mod); return (a % mod) * (b % mod) % mod; } const ll mod = 1000000007; int main() { int n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; vll s(n + 1); s[0] = 0; rep(i, n) s[i + 1] = s[i] + a[i]; map<ll, ll> mp; rep(i, n + 1) { ll m = s[i]; mp[m]++; } ll cnt = 0; for (auto m : mp) { ll j = m.second; cnt += (j - 1) * j / 2; } cout << cnt << endl; return 0; }
0
17,096,247
#include <bits/stdc++.h> using namespace std; int main() { int64_t K, A, B; cin >> K >> A >> B; int64_t ans = K + 1; if (B - A <= 2 || (1 + K) <= A) { cout << ans << endl; } else { int64_t plus = B - A, init = A - 1; cout << A + plus * ((K - init) / 2) + (K - init) % 2 << endl; } }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <map> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++) #define all(vecto) vecto.begin(), vecto.end() #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) typedef long long ll; void ans(bool qus) { if (qus == true) std::cout << "Yes" << std::endl; else std::cout << "No" << std::endl; } void Ans(bool qust) { if (qust == true) std::cout << "YES" << std::endl; else std::cout << "NO" << std::endl; } using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; if(a==b){ cout << c << endl; } else if(b==c){ cout << a << endl; } else cout << b << endl; }
0
77,838,516
#include <bits/stdc++.h> using namespace std; long long N, K; vector<long long> sumV(100001); int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(20) << fixed; string s; cin >> s; for(int i = 0; i < 19; i++){ if(i == 5 || i == 13){ cout << " "; } else{ cout << s[i]; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define all(x) (x).begin(),(x).end() const int mod=1000000007,MAX=1<<18,INF=1<<30; int main(){ string ans; cout<<"? 49999999999"<<endl; char a;cin>>a; if(a=='Y'){ for(int i=1;i<=4;i++){ cout<<"? "<<i<<"9999999999"<<endl; cin>>a; if(a=='Y'){ ans+='0'+i; break; } } }else{ for(int i=5;i<=9;i++){ cout<<"? "<<i<<"9999999999"<<endl; cin>>a; if(a=='Y'){ ans+='0'+i; break; } } } bool ok=true; while(ans.size()<=8){ cout<<"? "<<ans<<'4'; for(int j=0;j<13-ans.size();j++){ cout<<9; } cout<<endl; cin>>a; if(a=='Y'){ for(int i=0;i<=4;i++){ cout<<"? "<<ans<<i; for(int j=0;j<13-ans.size();j++){ cout<<9; } cout<<endl; cin>>a; if(a=='Y'){ if(i==0){ if(ans=="9"){ cout<<"? "<<10<<endl; cin>>a; if(a=='N'){ ok=false; break; }else{ ans+='0'; break; } }else{ string T=ans; T[T.size()-1]++; cout<<"? "<<T<<endl; cin>>a; if(a=='Y'){ ok=false; break; }else{ ans+='0'; break; } } }else{ ans+='0'+i; break; } } } if(!ok) break; }else{ for(int i=5;i<=9;i++){ cout<<"? "<<ans<<i; for(int j=0;j<13-ans.size();j++){ cout<<9; } cout<<endl; cin>>a; if(a=='Y'){ ans+='0'+i; break; } } } } if(ans=="100000000"){ cout<<"? "<<100000001<<endl; cin>>a; if(a=='N') ans+='0'; } cout<<"! "<<ans<<endl; }
0
17,817,330
#include <bits/stdc++.h> #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T& value, Ts&... args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T& value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T& value, const Ts&... args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; int main() { vector<int> v(5); rep(i, 5) cin >> v[i]; auto ceil10 = [](int x) { return (x + 9) / 10 * 10; }; sort(all(v), [&](int a, int b) { return ceil10(a) - a < ceil10(b) - b; }); int t = 0; rep(i, 5) t = ceil10(t) + v[i]; out(t); }
#pragma region header #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define int long long using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--) #define rev1(i, n) for(int i = (int)(n); i > 0; i--) #define pb push_back #define all(v) (v).begin(), (v).end() #define resort(v) sort((v).rbegin(), (v).rend()) #define vi vector<int> #define vvi vector<vector<int>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> using ll = long long; using P = pair<int, int>; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; constexpr ll mod = 1e9+7; constexpr int inf = INT32_MAX/2; constexpr ll INF = LLONG_MAX/2; constexpr long double eps = DBL_EPSILON; constexpr long double pi = 3.141592653589793238462643383279; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } ll fact(int i) { if (i == 0) return 1; return (fact(i - 1)) * i % mod; } ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b ; } int keta(ll n) { if(n == 0) return 1; int count = 0; while(n != 0) { n /= 10; count++; } return count; } ll ketasum(ll n) { ll sum = 0; while(n != 0) { sum += n % 10; n /= 10; } return sum; } #pragma endregion struct edge{int to,cost;}; vector<vector<edge>> G(100100); vi dist(100100,inf); bool bfs(int s) { queue<int> que; que.push(s); dist[s]=0; while(!que.empty()) { int v = que.front();que.pop(); for(auto e:G[v]) { if(dist[e.to]!=inf&&dist[e.to]!=dist[v]+e.cost) { return true; } if(dist[e.to]==inf) { dist[e.to]=dist[v]+e.cost; que.push(e.to); } } } return false; } signed main() { int n,m;cin >> n >> m; if(m==0) { printf("Yes\n"); return 0; } rep(i, m) { int a,b,cost;cin >> a >> b >> cost; a--;b--; G[a].pb({b,cost}); G[b].pb({a,-cost}); } rep(i, n) { if(dist[i]==inf) { if(bfs(i)) { printf("No\n"); return 0; } } } printf("Yes\n"); return 0; }
0
17,059,235