solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { re...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 1000005; inline int read() { int res, ok = 1; char ch; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') ok = -1; res = ch - '0'; for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar(...
5
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } long long n, a[300005], l[300005], r[...
2
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); long long f = 1; while (!isdigit(ch)) { if (ch == '-') f *= -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } x *= f; } template <typename T...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, *a, tmp; cin >> n; a = new int[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { for (int b = 0; b < n; b++) { if (a[i] < a[b]) { tmp = a[b]; a[b] = a[i]; a[i] = tmp; } ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int temp[n], a[n + 1]; for (int i = 0; i < n; i++) { cin >> temp[i]; } sort(temp, temp + n, greater<int>()); int ei = n / 2, j = 2; for (int i = 0; i < ei; i++) { a[j] = temp[i]; j += 2; } j = 1; sort...
2
#include <iostream> #include <string> using namespace std; int main(void){ string str,tmp,command; int q,a,b; cin>>str>>q; for(int i=1;i<=q;i++){ cin>>command>>a>>b; if(command=="print"){ cout<<str.substr(a,b-a+1)<<endl; }else if(command=="reverse"){ tmp=...
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 666; int n,m,a[N],b[N],d[N][N],f[N][N]; int e[N],c[N],s[N]; int solve(int x,int y){ int i,j,k,z=d[x][y],o,u,r; memset(e,0,sizeof(e)); memset(c,0,sizeof(c)); memset(s,0,sizeof(s)); for(i=1;i<=n;i=i+1) if(d[x][i]+d[y][i]==z) e[d[x]...
4
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const long long mod = 998244353; const long long INF = 1e9 + 7; const int base = 131; const double eps = 0.000001; const double pi = 3.1415926; int n, m, k; int a[200010], b[2010]; int dp[200010],...
6
#include <bits/stdc++.h> using namespace std; long long cnt, prime[100], pcnt; long long flg; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long search(long long a, long long b) { if (!b) return 0; long long d = gcd(a, b); a /= d; b /= d; long long minn = 1ll << ...
5
#include<iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) /* 大文字を小文字に変換 */ char tolower(char c) {return (c + 0x20);} /* 小文字を大文字に変換 */ char toupr(char c) {return (c - 0x20);} // if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A'; /* string s = "abcdefg" s.sub...
0
//ほぼstandard answer #include<iostream> using namespace std; class Cube{ public: int f[6]; Cube(){} void roll_z(){ roll(1, 2, 4, 3);} //横向き void roll_y(){ roll(0, 2, 5, 3);} //サイコロの番号は+1 void roll_x(){ roll(0, 1, 5, 4);} void roll(int i, int j, int k, int l){ int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k...
0
#include<bits/stdc++.h> using namespace std; int main(){ long N;cin>>N; if(N%2==1){cout<<0;return 0;} long ans=0,t=10; for(int i=0;(N/t)>0;i++){ans+=N/t;t*=5;} cout<<ans; }
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 501; const int INF = 1e9; int dp[MAX_N][MAX_N]; int main() { int n; scanf("%d", &n); vector<int> a(n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); dp[i][i] = 1; } for (int i = 0; i + 1 < n; i++) { if (a[i] == a[i + 1]) d...
4
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<cmath> #include<cstring> #include<queue> #include<stack> #include<cstdio> #include<sstream> #include<iomanip> #include<assert.h> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loo...
0
#define _USE_MATH_DEFINES #include<cstdio> #include<iostream> #include<vector> #include<algorithm> #include<queue> #include<stack> #include<cmath> #include<climits> using namespace std; struct Team{ char name; int win, lose; bool operator < (const Team &a) const{ return (win == a.win) ? lose < a.lose : win > a.wi...
0
#include<iostream> using namespace std; int main(){ long long int n,t; cin>>n>>t; string s; cin>>s; int ans = 0; int b=1; for(int i =0;i<s.size();i++){ b=1; if(s[i]>='0'&&s[i]<='9'){ int a = s[i]-'0'; for(int j =0;j<a;j++){ b*=n; if(b<0||b>1000000000){ cou...
0
#include <bits/stdc++.h> using namespace std; const int N = 200010; vector<int> a[N], b[N]; int da[N], db[N]; int id[N], q[N << 1], dph[N << 1], dfn = 0; int dp[N << 1][20], lg2[N << 1]; int n, x, y; void dfsb(int x, int fx) { id[x] = ++dfn; q[dfn] = x; db[x] = db[fx] + 1; dph[dfn] = db[x]; for (int...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; int flag = 1; scanf("%d%d%d", &a, &b, &n); for (int i = 0; i < 10; i++) { if ((a * 10 + i) % b == 0) { printf("%d", a * 10 + i); flag = 0; for (int j = 1; j <= n - 1; j++) printf("0"); break; } } if (flag...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); string nap; int k; cin >> nap >> k; nap += "1"; int n = nap.size(); int odp = 0; for (int i = 0; i < k; ++i) { char a, b; cin >> a >> b; int x = 0, y = 0; for (int j = 0; j < n; ++j) { if (nap[...
3
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); ...
5
#include <bits/stdc++.h> using namespace std; int a[101][101]; int main() { int n; int cur; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cur = abs(n / 2 + 1 - i) + abs(n / 2 + 1 - j); if (cur <= n / 2) cout << "D"; else cout << "*"; } cout...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = 1e18; const ll mod = 1e9 + 7; string s, t, z; set<int> alph[26]; void init() { z = ""; for (int i = 0; i < 26; i++) { alph[i].clear(); } } int to_int(char c) { return int(c) - int('a'); } void input() { cin >> s; cin >> t; ...
3
#include <bits/stdc++.h> using namespace std; int n,m; char str[200050]; const int mod = 1000000007; int dp[200050]; int main() { scanf("%d%d",&n,&m); scanf("%s",str + 1); bool c1 = 0,c2 = 0; for(int i = 1;i <= m; ++ i) { c1 |= str[i] == 'R'; c2 |= str[i] == 'B'; } int p = 1; int lim; if(c1 && c2) { ...
0
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> istream &operator>>(istream &in, pair<T1, T2> &P) { in >> P.first >> P.second; return in; } template <class T1, class T2> ostream &operator<<(ostream &out, const pair<T1, T2> &P) { out << "(" << P.first << ", " << P.second << ")"; retur...
5
#include <bits/stdc++.h> using namespace std; struct data { int arr[15]; int n; int l; int r; int x; int ans; }; void print_bits(int a) { cout << a << " = " << bitset<32>(a) << endl; } void is_good_problemset(unsigned int bitmask, data *dat) { int minV = INT32_MAX, maxV = 0, sum = 0, count = 0; for (int...
2
#include <bits/stdc++.h> using namespace std; const long long Mod = 1e9 + 7; const double pi = 2 * acos(0.0); int arr[3]; int main() { int d; for (int i = 0; i < 3; i++) { cin >> arr[i]; } sort(arr, arr + 3); cin >> d; int ans = max(d - (arr[1] - arr[0]), 0) + max(d - (arr[2] - arr[1]), 0); cout << an...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x, achou; scanf("%d", &n); vector<int> v1; vector<int> v2; vector<int> v3; for (i = 0; i < n; i++) { scanf("%d", &x); v1.push_back(x); } sort(v1.begin(), v1.end()); for (i = 0; i < n - 1; i++) { scanf("%d", &x); v2.pu...
2
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << " " << e2 << " " << e3 << endl; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int levels = 0; int cur = 1; int dif = 1; while (N >= cur) { N -= cur; levels++; dif++; cur += dif; } cout << levels << endl; }
1
#include <bits/stdc++.h> using namespace std; int L[1005], R[1005], A[1005]; int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int n, i, j, k, x, y, z, r, l; cin >> n; for (i = 1; i <= n; ++i) cin >> L[i]; for (i = 1; i <= n; ++i) cin >> R[i]; x = n; z = n; queue<int> q; whil...
3
#include <bits/stdc++.h> using namespace std; bool s1[10][10], s2[10][10]; bool can[10]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { int x, y; scanf("%d%d", &x, &y); s1[x][y] = 1; s1[y][x] = 1; } for (int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x...
2
#include <stdio.h> #include <iostream> #include <vector> #include <list> #include <cmath> #include <fstream> #include <algorithm> #include <string> #include <queue> #include <set> #include <map> #include <complex> #include <iterator> #include <cstdlib> #include <cstring> #include <sstream> using namespace std; #defin...
0
#include<iostream> #include<cstdio> using namespace std; int main(void){ int w,costs=4280; while(scanf("%d",&w) && w+1){ costs=4280; do{ if(w<=10){ w=0; costs-=1150; }else if(w<=20){ costs-=(w-10)*125; w=10; }else if(w<=30){ costs-=(w-20)*140; w=20; }else{ costs-=(w-30)*160;...
0
#include <bits/stdc++.h> using namespace std; const int N = 100005; int main() { int n; while (scanf("%d", &n) + 1) { if (n & 1) printf("black\n"); else printf("white\n1 2\n"); } return 0; }
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1, K = 500, mod = 998244353; const char ans[2][5] = {"No\n", "Yes\n"}; int n, m, q, tot; int a[N], pw[N], inv[N]; struct node { int *s, len; node() { s = NULL, len = 0; } inline int val() { return s[len]; } inline int calc(int x) { return 1ll...
6
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> struct SegmentTreeItLazy { T neutro = 0; int size, height; vector<T> st, delUp; vector<bool> upd; SegmentTreeItLazy(int n, T val) { st.resize(2 * n, val); delUp.resize(n); upd.resize(n); size = n; height = size...
3
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, s, x[100001], y[100001], min = 99, dem0 = 0; cin >> n >> s; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; if (n == 1 && x[i] < s) min = y[i]; if ((x[i] + (y[i] * 1.0 / 100)) <= s) { if (y[i] < min && y[i] > 0) mi...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int n; long long k, ans = 0, a[N]; int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]); sort(a + 1, a + n + 1); int l = 1, r = n; while (l < r) { if (l < n - r + 1) { if (k >= l * (a[l + 1] - a[l...
5
#include <iostream> using namespace std; int main() { long long int n, h, w; cin >> n >> h >> w; cout << ((n-h)+1)*((n-w)+1) << '\n'; }
0
#include <bits/stdc++.h> using namespace std; int MOD = 1000000007; int main() { long long int a, b, t; cin >> a >> b >> t; long long int s[] = {a, b, b - a, -a, -b, a - b}; cout << (s[(t - 1) % 6] % MOD + MOD) % MOD; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> types(n); vector<int> parents(n); vector<int> deg(n, 0); for (int i = 0; i < n; i++) cin >> types[i]; for (int i = 0; i < n; i++) { cin >> parents[i]; parents[i]--; if (parents[i] != -1) { deg[parents...
2
#include <cstdio> #include <iostream> using namespace std; int main() { int n, s; scanf("%d", &n); for (int i = 0; i < n; i++){ scanf("%d", &s); printf("Case %d:\n", i + 1); for (int j = 0; j < 10; j++){ printf("%d\n", s = s * s / 100 % 10000); } } return (0); }
0
#include <bits/stdc++.h> using namespace std; string arr[2][1000 * 100 + 10]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[0][i] >> arr[1][i]; if (arr[1][i] < arr[0][i]) swap(arr[1][i], arr[0][i]); } int k, ans = 1; cin >> k; string prv = arr[0][k - 1]; for (int i = 0; ...
3
#include<iostream> #include<string> using namespace std; int main(){ string s; string ans[1000]; int n = -1; int r,k = 0; getline(cin,s); for(int i=0;i<s.size();i++){ if(s[i] == ' ' || s[i] == ',' || s[i] == '.'){ if(i-1-n > 2 && i-1-n < 7){ for(int j=n+1;j<i;j++) ans[k] += s[j]; k++; n ...
0
#include <bits/stdc++.h> #define maxn 3030 #define ll long long using namespace std; const ll mod=1e9+7; ll dp[maxn][maxn],times=1,ans; int a[maxn],n,T,x,y; void qpow(int k){ ll base=2; while(k){ if(k&1) times=(times*base)%mod; base=base*base%mod; k>>=1; } } int main(){ scanf("%d%d",&n,&T); for(int i=1;...
0
#include <bits/stdc++.h> using namespace std; class Coord { public: int x; int y; Coord(int _x, int _y) : x(_x), y(_y) {} Coord() {} }; const int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1, -1, 1, 0, -1, 0, 1}; const int n = 8; char a[8][8]; bool mark[8][8]; queue<Coord> q; queue<Coord> ...
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double eps = 1e-8; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; const double pi = acos(-1.0); const int MAX = 1000000000; class TheGridDivTwo { public: }; int arr[100001]; vector<int> cur, res; int totalAnd, n; int main() { ...
3
#include <bits/stdc++.h> using namespace std; int n, m, fa[100005], to[100005], ont[100005], pv[100005], opt[100005], ar[100005], cl[100005], fg[100005], sm[100005]; int vis[100005], tim; vector<int> G[100005], E[100005]; void dfs(int u) { for (int v : E[u]) dfs(v), sm[u] += sm[v]; if (!ont[u]) pv[u] += sm[u]; ...
5
#pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("O3", "omit-frame-pointer","inline") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include <bits/stdc++.h> using namespace std; /***********************************************/ /* Dear online judge: * I've read the pro...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 2005; const int MOD = 1e9 + 7; int n; char s[2][10]; int main() { while (scanf("%d %s %s", &n, s[0], s[1]) != EOF) { if (s[1][0] == 'w') { if (n <= 4 || n == 7) cout << 52 << endl; else cout << 53 <...
1
#include <bits/stdc++.h> using namespace std; long long v[100005][3]; long long a, b, c, sum, dif, x, ansx, ansy, ansz; long long a1, a2, b1, b2, c1, c2, s1, s2; long long l, r, mid; int n; const long long inf = 1ll << 62; long long div2(long long x) { if (x < 0) return (x - 1) / 2; else return x / 2; } int...
3
#include <bits/stdc++.h> using namespace std; int main() { int m, x, n, ans = 0; cin >> n >> m; cin >> x; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (x == min(min(i, j), min(n - i + 1, m - j + 1)) && (i + j) % 2 == 0) ans++; cout << ans; return 0; }
2
#include <bits/stdc++.h> using namespace std; long long n; long long t[200010]; set<long long> st; int main() { scanf("%lld", &n); for (long long i = (long long)(0); i < (long long)(n); i++) scanf("%lld", t + i); long long res = 1; st.insert(0); for (long long i = (long long)(0); i < (long long)(n); i++) ...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000009; long long md(long long n) { if (n >= mod) return n % mod; return n; } long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res;...
1
#include <bits/stdc++.h> using namespace std; const int K = 20; int n, q, l; int x[100000]; int d[K][100000]; void pre() { int j = 0; for (int i = 0; i < n; ++i) { while (j < n && x[j] - x[i] <= l) { ++j; } d[0][i] = j - 1; } for (int k = 1; k < K; ++k) { for (int i = 0; i < n; ++i) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, ans = 0; cin >> n >> m; string a[100]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { for (int j = 0; j < m - 1; j++) { int k = 'f' * 'a' * 'c' * 'e'; int l = a[i][j] * a[i + 1][j] * a[i]...
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007, MX = (1 << 20); long long fact[MX]; long long POW(long long x, long long y) { if (y == 1) return x; long long ret = POW(x, y / 2); ret *= ret; ret %= MOD; if (y % 2) ret *= x; return ret % MOD; } long long inverse(long long a, l...
5
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; cout << (s.size() + 1) * 25 + 1; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { long long N,A,B; cin >> N >> A >> B; long long M,m,a; a=0; M=(N-2)*B; m=(N-2)*A; cout << max(M-m+1,a) << endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 4; long long n; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; long long temp = n; int d = 0; while (temp) { d++; temp /= 10; } int ans = (d - 1) * 9; long long a = 0; for (int i = 0; i < d - 1; ++i...
2
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false...
6
#include <bits/stdc++.h> using namespace std; mt19937 rng(static_cast<unsigned int>( chrono::steady_clock::now().time_since_epoch().count())); template <typename num_t> inline void add_mod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a >= m) a -= m; if (a < 0) a += m; } template <typenam...
5
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int main() { std::ios::sync_with_stdio(false); long long n, k; int a, b, c, d; cin >> n >> k; cin >> a >> b >> c >> d; vector<int> path; if (n <= 4 || k <= n) { cout << -1 << endl; return 0; } cout << a << " " << c << " ...
2
#include <bits/stdc++.h> using namespace std; void Yahia74() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); } const int N = 1e5 + 74, M = 1e5 + 74, OO = 0x3f3f3f3f; int main() { Yahia74(); int a, b, c, d; cin >> a >> b >> c >> d; if (a != d) { cout << 0; } else { if (c > 0 && a ...
1
#include <bits/stdc++.h> int main() { long long int n, m, k, l, a, b; scanf("%lld%lld%lld%lld", &n, &m, &k, &l); b = (l + k + m - 1) / m; if (b * m > n) printf("-1"); else printf("%lld", b); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 0, k = 0; double max1 = 0.0f; long long sum = 0, sum2 = 0; cin >> n >> k >> m; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } sort(v.begin(), v.end()); sum2 = sum; int t = m; double s = 0...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long tt, nn, mm, i, j, k, l, m, n, a, b, c, d; cin >> tt; while (tt--) { string a; cin >> nn; cin >> a; long long maxi = nn; for (i = 0; i < nn; i++) { i...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 111; int k, n, A[N], res; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> k; cin.ignore(); getline(cin, s); n = 0; int a = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == ' ' || s[i] == '-') { n++; ...
4
#include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> #define REP(i,n) for (int i=1;i<=(n);++i) #define FOR(i,a,b) for (int i=(a);i<=(b);++i) #define ROF(i,a,b) for (int i=(a);i>=(b);--i) #define FEC(p,u) for (edge*p=head[u];p;p=p->nxt) using namespace std; ty...
0
#include <bits/stdc++.h> using namespace std; int main() { string xx, yy; cin >> xx; bool dd = false; int l = 0, r = 0; for (int i = 0, _n = xx.length(); i < _n; i++) { if (xx[i] == '|') dd = true; else if (dd) r++; else l++; } cin >> yy; int goal = (r + l + yy.length()), i...
1
#include<bits/stdc++.h> using namespace std; int main() { int d; cin >> d; int c[26]; for (int i = 0; i < 26; i++) cin >> c[i]; int s[d][26]; for (int i = 0; i < d; i++) { for (int j = 0; j < 26; j++) { cin >> s[i][j]; } } int t[d]; for (int i = 0; i < d; i++) { cin >> t[i]; t[i]--; } int last[...
0
#include <bits/stdc++.h> using namespace std; int main() { int k; scanf("%d", &k); int maxn = 0; for (int i = 1; i <= k; i++) { int x; scanf("%d", &x); if (x >= 500001) { maxn = max(maxn, 1000000 - x); } if (x <= 500000) { maxn = max(maxn, x - 1); } } printf("%d\n", maxn)...
2
#include<bits/stdc++.h> using namespace std; int n,a[100000],b[100000]; int main() { cin>>n; for (int i=0,k=1;i<n;i++,k*=-1) cin>>b[i+1],a[1]+=k*b[i+1]; for (int i=2;i<=n;i++) a[i]=2*b[i-1]-a[i-1]; for (int i=1;i<=n;i++) cout<<a[i]<<" \n"[i==n]; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; int main() { int n; scanf("%d", &n); int ans = 0; while (n--) { int x1, x2, gftxdtrtfhyjfctrxujkvbhyjice, y2; scanf("%d%d%d%d", &x1, &gftxdtrtfhyjfctrxujkvbhyjice, &x2, &y2); ans += (x2 - x1 + 1) * (y2 - gftxdtrtfhyjfctrxujk...
1
#include <iostream> #include <algorithm> #include <cmath> #include <functional> using namespace std; int main() { int n, a, b, c, d[10000]; cin >> n; cin >> a >> b; cin >> c; for(int i = 0; i < n; i++) cin >> d[i]; int pizza = c; int best = c / a; sort(d, d + n, greater<int>()); for(int i = 0; i < n; i++...
0
// C - Base -2 Number #include <bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; string ans = ""; int p = -2; while(N != 0){ int r = N % p; N /= p; if(r < 0){ r -= p; N++; } ans = to_string(r) + ans; } if(ans == "") ans = "0"; cout<< ans <<endl; }
0
#include <bits/stdc++.h> using namespace std; const int cupe = 5; int main() { int n, a[cupe], sum = 0, ans = 0; cin >> n; for (int i = 1; i < 5; ++i) a[i] = 0; for (int i = 0; i < n; ++i) { int temp; cin >> temp; sum += temp; ++a[temp]; } if (sum == 1 || sum == 2 || sum == 5) { cout << ...
5
#include <iostream> using namespace std; const int SIZE = 90; int board[SIZE][SIZE]; int n,m; int dfs(int y, int x){ int dx[] = {0, -1, 1, 0}, dy[] = {-1, 0, 0, 1}; int nx, ny, max = 0, tmp; board[y][x] = 0; for(int i = 0;i < 4;++i){ nx = x + dx[i]; ny = y + dy[i]; if (0 <= nx && 0 <= ny && nx < m && ny < ...
0
#include <bits/stdc++.h> using namespace std; int dx[4] = {0, -1, 1, 0}; int dy[4] = {1, 0, 0, -1}; char let[4] = {'D', 'L', 'R', 'U'}; int g[1010][1010]; int dist[1010][1010]; int used[1010][1010]; int pr[1010][1010]; vector<char> ans; queue<pair<int, int> > q; pair<int, int> start; char second[1010]; int n, m, k; int...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 3000000; int highest[MAXN]; int bids[MAXN]; vector<int> bidded[MAXN]; vector<int> V; int bid[MAXN]; set<int> ppl; set<pair<int, int> > active_ppl; int calculate(int person, int lo, int hi) { int q = upper_bound(bidded[person].begi...
4
#include <bits/stdc++.h> using namespace std; long long N, K; const long long MD = 998244353; class CombinatoricHelper { private: long long MD; public: int lim; long long quickPower(long long base, long long pw) { if (pw == 0) return 1; if (pw == 1) return base; long long ret = quickPower(base, pw ...
5
#include <bits/stdc++.h> using namespace std; long long n, x, a[100010], m = 1e12, h, v, k; int main() { cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> a[i]; m = min(m, a[i]); } for (int i = x; i >= 1; i--) { if (a[i] == m) { k = a[i]; a[i] = v; h = i; break; } else...
3
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long Int; #define rep(i, n) for(int i=0; i<n; ++i) #define srt(A) sort(A.begin(), A.end(), greater<Int>()) int main(){ Int X, Y, Z, K; cin >> X >> Y >> Z >> K; vector<Int> A(X), B(Y), C(Z), res; rep(i, X) cin >> A[i...
0
#include <bits/stdc++.h> using namespace std; const int64_t N = 2e5 + 5; const int64_t INF = 1e18 + 7; const int64_t MOD = 1e9 + 7; int64_t n, m; int64_t dp[N]; bool good[N]; vector<pair<int64_t, int64_t>> v; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int64...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long test, ans[3][200005] = {0}; cin >> test; while (test--) { long long n, a, b, i, j, k, wan = 1, tw = 2; string s; cin >> n >> a >> b; cin >> s; ans[1][0] =...
3
#include <bits/stdc++.h> using namespace std; int T, n; int main() { scanf("%d", &T); while (T--) { scanf("%d", &n); int resp = (n / 7) + (n % 7 == 0 ? 0 : 1); printf("%d\n", resp); } return 0; }
1
#include <bits/stdc++.h> #define REP(i,n,N) for(int i=n;i<N;i++) #define p(S) cout<<S<<endl using namespace std; bool isPrime(int x){ int d=5; for(int i=6;i<x;i+=d){ d=7-d; if(x%i==0){ return false; } } return true; } int main(){ int N; while(cin>>N&&N!=1){ int d=5; cout<<N<<":"; for(int i=6;i<=N...
0
#include <bits/stdc++.h> const char dl = '\n'; const long double eps = 0.00000001; const long long MOD = 1e9 + 7; const double PI = 3.141592653589793238463; using namespace std; void debug() { cout << endl; } template <typename H, typename... T> void debug(H p, T... t) { std::cout << p << " "; debug(t...); } string...
1
#include <bits/stdc++.h> using namespace std; const int N = 1 << 21; int tests, current_case; int n, m, k, a[N]; pair<int, int> b[N]; int arr[N << 1]; void message(int current_case) { fprintf(stderr, "Case %d solved!\n", current_case); } bool check(int cnt) { int i, j, days = 0, sz = 0, last; i = 1; j = m - cnt...
4
#include<bits/stdc++.h> using namespace std; #define ll long long #define f(i,x,n) for (int i = x;i < n;++i) const int md = 1e9 + 7; int p[200001]; int pw(int x, int p) { if (!p)return 1; int t = pw(x, p >> 1); t = (ll)t*t%md; if (p & 1)t = (ll)t*x%md; return t; } int ch(int n, int r) { return (ll)p[n] * pw(p[n...
0
#include <bits/stdc++.h> using namespace std; long long n, sm[5201][5201]; string s; int to_digit(char ch) { if (isdigit(ch)) { return ch - '0'; } return ch - 'A' + 10; } vector<long long> get_factor(long long x) { vector<long long> ret; for (long long i = 1; i * i <= x; i++) { if (x % i == 0) { ...
4
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 10, C = 500; int n, state[N], lion[N]; vector<int> adj[N], headj[N]; map<int, int> edgeIdx[N]; void add_edge(int u, int v) { adj[u].push_back(v); edgeIdx[u][v] = adj[u].size() - 1; if (((int)(adj[u]).size()) < C) lion[v] += state[u]; else if ...
4
#include <iostream> #include <algorithm> using namespace std; int main(void){ int n; cin>>n; cout<<(n<1200?"ABC":"ARC"); }
0
#include <bits/stdc++.h> int cmp(const void *a, const void *b) { return (*(int *)a) - (*(int *)b); } int cmp1(const void *a, const void *b) { return (((int *)a)[0]) - (((int *)b)[0]); } int main() { double H, L; scanf("%lf %lf", &H, &L); double ans = (L * L - H * H) / (2.0 * H); printf("%.8lf\n", ans); }
2
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *t = buf; inline int fetc...
3
#include <bits/stdc++.h> using namespace std; int max_digit(long long n) { int large = 0, rem = 0; while (n > 0) { rem = n % 10; n = n / 10; if (rem > large) { large = rem; } } return large; } int main() { long long n; cin >> n; long long i = 0; while (n != 0) { n = n - max_dig...
3
#include<cstdio> #include<queue> #include<algorithm> #define ll long long using namespace std; const int N=1e5+5; int n,nx,ny,nz,i,v[N]; ll sum,fx[N],fy[N],ans; struct arr{int k,x,y;}a[N]; bool operator < (arr A,arr B){return A.k>B.k;} int read(){ char c=getchar();int k=0;for (;c<48||c>57;c=getchar()); for (;c>47&&c...
0
#include <bits/stdc++.h> using namespace std; using ui64 = unsigned long long; using i64 = long long; using ui32 = unsigned int; using Double = long double; template <class T> inline T Abs(const T& x) { return x < 0 ? -x : x; } template <class T> inline T Sqr(const T& x) { return x * x; } template <class T> void Pr...
5
#include <bits/stdc++.h> using namespace std; template <typename X> inline X sqr(const X& a) { return a * a; } int nxt() { int x; cin >> x; return x; } int main() { int n = nxt(), m = nxt(); vector<int> a(n); generate(a.begin(), a.end(), nxt); while (m--) { int l = nxt() - 1, r = nxt(), x = nxt() - ...
2