solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n, q; cin >> n >> q; unsigned long long int l = ceil((n * n) / 2); unsigned long long int k = l + 1; while (q--) { unsigned long long int a, b; cin >> a >> b; if ((a + b) % 2 == 0) { cout << (unsigned long long)((((unsi...
2
#include <bits/stdc++.h> using namespace std; int main() { double g,r; cin>>r>>g; cout<<g*2-r<<endl; }
0
#include<vector> #include<iostream> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) void solve(int q,vector<string> &a,vector<int> &b,vector<int> &c){ rep(i,a.size()){ int f = c[i]-b[i]+1; if (f <= q && q <= c[i]){ cout <<a[i] <<" " << q-f+1 << endl; ret...
0
#include <bits/stdc++.h> using namespace std; const int maxN = 1000000; pair<pair<int, int>, int> target[maxN], shot[maxN]; int res[maxN]; int sq(int x) { return x * x; } int ins(pair<int, int> sh, pair<int, int> ta) { return sq(sh.first - ta.first) + sq(sh.second) <= sq(ta.second); } int main() { int n, m; cin >...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, x; long long a[100007]; cin >> n >> x; for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long time = 0; long long i; for (i = 0; i < n; i++) { time += a[i] * x; if (x > 1) x--; } cout << time;...
2
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const int MOD = 1e9 + 7; int main() { string s; cin >> s; int len = s.length(); int l, r, qq, ans, ck; ans = 0; for (int i = 0; i < len - 1; i++) { l = r = qq = ck = 0; for (int j = i; j < len; j++) { if (s[j] == '(') { ...
3
#include <bits/stdc++.h> using namespace std; const int max_n = 300000; int a[max_n], b[max_n], p[max_n]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; } for (int i = 0; i < n; i++) { int t; scanf("%d", &t); t--; b[t] = i; } int res ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, p[maxn], in[maxn], out[maxn], T, st[maxn << 1][20], lg[maxn << 1] = {-1}, o[30] = {1}, node[maxn]; int op, x, y, d, q, dep[maxn]; vector<int> G[maxn]; void dfs(int u, int fa) { dep[u] = dep[fa] + 1; st[in[u] = ++T][0] = u; for (au...
6
#include <bits/stdc++.h> using namespace std; long long int min(long long int a, long long int b) { return a < b ? a : b; } long long int min(long long int a, long long int b, long long int c) { a = min(a, b); a = min(a, c); return a; } long long int max(long long int a, long long int b) { return a > b ? a : b; }...
1
#include <bits/stdc++.h> using namespace std; using namespace rel_ops; const double pi = acos(-1.0); const double eps = 1e-11; const int inf = 0x7FFFFFFF; template <class T> inline bool checkmin(T &a, T b) { return b < a ? a = b, 1 : 0; } template <class T> inline bool checkmax(T &a, T b) { return b > a ? a = b, 1 ...
1
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int a = N; string ans; if (a == 0) { ans = "0"; } while (a != 0) { if (a % 2 == 0) { ans = "0" + ans; } else { ans = "1" + ans; a--; } a /= -2; } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3f; const long long N = 1000000; long long n; long long r1, r2, r3, d; long long a[N + 1]; long long dp[N + 1]; long long x[N + 1], y[N + 1]; long long Sum[N + 1]; signed main() { cin >> n >> r1 >> r2 >> r3 >> d; for (long long i = ...
3
#include <bits/stdc++.h> using namespace std; long long dp[20][20]; int pre[50][50]; int a[50]; long long bin[20]; void print(int x, int y) { if (x == 0 && y == 0) return; if (pre[x][y] == 1) { print(x - 1, y); printf("M"); } else { print(x, y - 1); printf("H"); } } int main() { int n; bin[0...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; const int M = 1e9 + 7; const double eps = 1e-6; const double PI(acos(-1.0)); long long f[11][61][2049]; int q; long long b, l, r; int w[65], t; long long dfs(int pos, int lim, int state, int start) { if (pos < 1) return !state; if (!lim && !start ...
5
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:667772160") 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) { co...
3
#include <bits/stdc++.h> using namespace std; int n, c[210], p[210], d[210]; bool b[210], a[210][210]; int find(int k) { for (int i = 1; i <= n; i++) if (c[i] == k) if (d[i] == 0 && b[i]) return i; return n + 1; } int calc(int k) { memset(b, true, sizeof(b)); for (int i = 1; i <= n; i++) d[i] = p[i]; ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 5; const int mod = 1e9 + 7; int a[maxn]; pair<int, int> dp[1 << 21]; void add(int x, int id) { if (dp[x].first == -1) { dp[x].first = id; } else if (dp[x].second == -1) { if (dp[x].first == id) return; dp[x].second = id; if (dp[x]....
6
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int num) { bool flag = true; for (long long int i = 2; i <= num / 2; i++) { if (num % i == 0) { flag = false; break; } } return flag; } bool isPowerOfTwo(int n) { if (n == 0) return false; return (ceil(log2(n)) == floor...
1
#include <bits/stdc++.h> using namespace std; using LL = long long; const int N = 234567; vector <int> G[N]; int d[N], f[N], n, x, y; void dfs(int u, int p, int d[]) { for (auto v : G[u]) if (v != p) { d[v] = d[u] + 1; dfs(v, u, d); } } i...
0
#include <bits/stdc++.h> using namespace std; long long n; long long a[100005]; long long cnt[100]; int main() { scanf("%lld", &n); for (long long i = 1; i <= n; i++) { scanf("%lld", &a[i]); } for (long long i = 1; i <= n; i++) { for (long long j = 0; j < 60; j++) { if (a[i] & ((long long)1 << j))...
1
#include <bits/stdc++.h> using namespace std; long long ans, f[1000005], h[1000005], g[1000005], t; long long n, m, k; long long pow1(long long a, long long b) { long long t = 1; while (b) { if (b & 1) t = t * a % 1000000007; a = a * a % 1000000007; b = b >> 1; } return t; } long long C(long long a,...
4
#include <bits/stdc++.h> using namespace std; const long long dx[4] = {-1, 0, 0, 1}; const long long dy[4] = {0, -1, 1, 0}; void faster() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long n, m, k, b, x, y, ans, sum, a[456789], br[456789], sb, l, u, r, p, q, i, j; string s, t, str;...
1
#include<stdio.h> #include<algorithm> #include<math.h> #include<vector> using namespace std; const double EPS = 1e-10; const double INF = 1e+10; const double PI = acos(-1); int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; } inline double ABS(double a){return max(a,-a);} struct Pt { double x, y; Pt() ...
0
#include <bits/stdc++.h> using namespace std; using pii = pair<long long, long long>; using vi = vector<long long>; using vvi = vector<vi>; const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL; const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}, DY[9] = {-1, 0, 1, 0, -1, 1, 1,...
3
#include<bits/stdc++.h> using namespace std; const double EPS=1e-6; double evaluate(vector<double>&r){ double res=r[0]+r[r.size()-1]; for(int i=0;i+1<r.size();i++){ double h=(r[i]+r[i+1]); double s=abs(r[i]-r[i+1]); res+=sqrt(h*h-s*s); } return res; } double optimize(vector<do...
0
#include <bits/stdc++.h> using namespace std; int n, k, a, s, t; int no_of_days() { cin >> n >> k; while (n--) cin >> a, s += a / k, t += (a % k > 0); return (s + t + 1) / 2; } int main() { cout << no_of_days(); }
1
#include <bits/stdc++.h> using namespace std; int n, m, match[2010][2010], deg[2010][2010], xs[5] = {0, -1, 0, 1}, ys[5] = {1, 0, -1, 0}; string s[2100]; bool mark[2010][2010], mark2[2010][2010]; bool check(int i, int j) { if (i >= n || j >= m || i < 0 || j < 0 || s[i][j]...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:160777216") using namespace std; int i, j, n, m, k; int cnt = 0; int main() { int t; cin >> t; while (t--) { cin >> n; if (n == 1) { cout << "! " << 1 << " " << 1 << endl; continue; } int mn = 100; int mx = -100; for (i =...
2
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int a[128]; int main() { int n, cnt = 0, m = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i + 'a']; m = gcd(a[i + 'a'], m); cnt += a[i + 'a'] & 1; } string s = ""; if (cnt > 1) { puts...
5
#include <bits/stdc++.h> using namespace std; const int N = 5e6 + 10, P = 29, mod = 1e9 + 7; string s; int n, sum, degree[2 * N]; long long p[N]; long long pref_hash[N], suf_hash[N]; bool is_palindrome(int right) { return (pref_hash[right] * p[n - right]) % mod == (suf_hash[1] - suf_hash[right + 1] + mod) % ...
4
#include <bits/stdc++.h> using namespace std; const int N = 100005; int q, n, u, pre[N], suf[N], cnt[N]; long long pw[N], hsh[N]; char s[N]; long long get_hash(int l, int r) { return hsh[r] - hsh[l - 1] * pw[r - l + 1]; } bool cmp(int u, int v) { int mx = min(n - u, n - v); int le = 0, ri = mx; while (le <= ri) {...
2
#include <bits/stdc++.h> using namespace std; int main() { deque<long long> q; long long n, a, b; cin >> n; for (int i = 1; i <= n; i++) { if (n % i == 0) q.push_back((n / i) * 2 + i * 2); else { a = (n - (n % i)) / i; if (a < (n % i)) a += (n % i) * a, b = (n % i) % a; b = n % i...
2
#include <bits/stdc++.h> using namespace std; const int BOARD = 1e9; int N, M; vector<int> vertical; vector<int> horizontal; int main() { scanf("%d %d", &N, &M); vertical.resize(N); for (int &x : vertical) scanf("%d", &x); sort(vertical.begin(), vertical.end()); for (int i = 0; i < M; i++) { int x1, x2, y...
1
#include <bits/stdc++.h> using namespace std; const long long N = 2005, MOD = 1e9 + 7; int n, h; int a[N]; long long memo[N][N]; long long dp(int idx, int cnt) { if (cnt < 0) return 0; if (idx == n) return (cnt == 0); if (memo[idx][cnt] != -1) return memo[idx][cnt]; long long &ret = memo[idx][cnt] = 0; if (a[...
4
#include <bits/stdc++.h> using namespace std; const int inf = 0x3fffffff; const int maxn = 200005; double x, y, yw, xb, yb, r; int main() { scanf("%lf%lf%lf%lf%lf%lf", &y, &x, &yw, &xb, &yb, &r); x -= 1e-12; y += 1e-12; y += r; double xw = (yw - r - y) * xb / (2 * yw - 2 * r - yb - y); double xx = xw * (x -...
1
#include <bits/stdc++.h> using namespace std; const long long N = 300010; struct edge { long long nxt, to; } e[N << 1]; long long rt, n, m, r, tot, cnt, head[N], dep[N], fa[N], siz[N], son[N], dfn[N], w[N], a[N], top[N]; struct tree { long long sum, lz; } tr[N << 2]; inline long long read() { long long x = 0,...
5
#include "bits/stdc++.h" using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i], A[i]--; long long NOW = 0, ANS, MIN = 0; for (int i = 0; i < N - 1; i++) { if (A[i] > A[i + 1]) NOW += A[i + 1] + 1, MIN++; else NOW += A[i + 1] - A[i]; } ANS = NOW...
0
#include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; cout << n - k + 1; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10, D = 10 + 2, L = 20; int B; long long inv[L]; long long dp[2][N][D]; long long com(long long n, long long m) { n %= B; if (m < 0 || n < m) return 0; long long ret = n; for (int i = 1; i < m; ++i) ret = ret * (n - i) % B * inv[i + 1] % B; ret...
6
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 322; const long long LINF = 2e18 + 474; const int MAXN = 1e5 + 228; const int MOD = 1e9 + 7; const double eps = 1e-14; int n, k; int a[MAXN], l[MAXN]; void solve() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; l[1] = 1; for (int i ...
2
#include <bits/stdc++.h> using namespace std; int n, k; string str; int main() { while (cin >> n >> k) { cin >> str; int s = 0, sum = 0; int ans = 0; for (int i = 0; i < n; ++i) { if (str[i] == 'b') sum++; while (sum > k) if (str[s++] == 'b') sum--; ans = max(ans, i - s + 1);...
3
#include <bits/stdc++.h> using namespace std; vector<int> G[100]; pair<int, int> v[100]; bool visited[100]; void dfs(int u) { visited[u] = true; for (int v = 0; v < G[u].size(); v++) { if (!visited[G[u][v]]) dfs(G[u][v]); } } int main() { int N, cnt = 0; cin >> N; for (int i = 0; i < N; i++) cin >> v[i]...
3
#include <bits/stdc++.h> int main() { int n, k; int i, j, temp; scanf("%d %d", &n, &k); if (2 * k >= n) { printf("-1"); return 0; } printf("%d\n", n * k); for (i = 1; i <= n; i++) { for (j = i + 1; j <= k + i; j++) { temp = (j > n) ? (j % n) : j; printf("%d %d\n", i, temp); } ...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1000111000; int main() { int a, b, c, d, e; char x[100][10], s; scanf("%d%c", &a, &s); for (int b = 0, _d = (int)a - 1; b <= _d; ++b) { d = 0, e = 0; scanf("%[^\n]", &x[b][0]); scanf("%c", &s); c = 0; while (x[b][c] != '\0') c++; ...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<ll> a(n), b(m), v(35); for (int i = 0; i < n; i++) { cin >> a[i]; for (ll j = 0; j < 35; j++) if ((1LL << j) & a[i]) v[j]++; } f...
3
#include <bits/stdc++.h> long long mod = 1e9 + 7; long long inf = 1e18 + 3; using namespace std; long long powerexp(long long x, long long y, long long m = 1e9 + 7) { if (y == 0) return 1; long long p = powerexp(x, y / 2, mod) % mod; p = (p * p) % mod; return (y % 2 == 0) ? p : (x * p) % mod; } long long modinv...
3
#include <bits/stdc++.h> using namespace std; const int Maxn = 100010; const int inf = 2147483647; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = ge...
6
#include <bits/stdc++.h> using namespace std; set<string> out; string in; set<pair<int, string> > visited; void DP(int pos, string prev) { if (pos <= 5) return; pair<int, string> tmp = make_pair(pos, prev); if (visited.find(tmp) != visited.end()) return; visited.insert(tmp); string s = ""; if (pos >= 6) { ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") #pragma GCC optimize("fast-math") #pragma warning(disable : 4996) using namespace std; const int MAXN = 1000001...
2
#include <iostream> using namespace std; int main(){ int n; while(cin>>n){ if(n%2)cout<<(n+1)/2*n+1<<endl; else cout<<n/2*(n+1)+1<<endl; } }
0
#include <bits/stdc++.h> using namespace std; const int N = 20; const long long mod = 998244353; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int ask(int x1, int y1, int x2, int y2) { if (x1 < 1 || y1 < 1 || x2 < 1 || y2 < 1) return 0; cout << "? " << x1 << " " << y1 << " " << x2 << " " << y...
2
#include <bits/stdc++.h> using namespace std; string s; int n, open = 0, closed = 0; vector<int> res; int main() { cin >> s; n = s.length(); for (int i = 0; i < n; i++) { if (s[i] == '(') open++; else if (s[i] == ')') closed++, open--; else if (s[i] == '#') { res.push_back(1); ...
3
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); long long a, k, n[1000], m[1000], count = 0; set<long long> s; cin >> a >> k; for (int i = 0; i <= 1000; i++) { m[i] = 0; } for (int i = 0; i < a; i++) { cin >> n[i]; m[n[i]]++; s.insert(...
1
#include <bits/stdc++.h> using namespace std; int main() { int A, B, M; cin >> A >> B >> M; vector<int> a(A), b(B); int min_a = 1e9, min_b = 1e9; for (int &v:a) cin >> v, min_a = min(min_a, v); for (int &v:b) cin >> v, min_b = min(min_b, v); int mi = min_a + min_b; while (M--) { int x, y, c; cin >...
0
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10, mod = 199999; int n, p[M], de[M], fa[M]; vector<int> son[M], ans; void dfs(int x) { cout << x << ' '; if (son[x].empty()) return; int mx = n; for (auto v : son[x]) { if (de[v] > de[mx]) mx = v; } int pre = 0; for (auto v : son[x]) {...
6
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; int main(){ int n,t,x,h; double ans=0.0; cin>>n>>t; while(n--){ cin>>x>>h; ans=max(ans,(double)t*(double)h/(double)x); } printf("%.6lf\n",ans); }
0
#include<bits/stdc++.h> using namespace std; int main(){ int P, Q, R; cin>>P>>Q>>R; cout<<min(P + Q, min(Q + R, R + P)); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f); if (a * c * e < b * d * f) { cout << "Ron\n"; } else if (!c && d) { cout << "Ron\n"; } else if (!a && b && d) { cout << "Ron\n"; } else cout << "Hermione\n"; retu...
1
#include <iostream> using namespace std; int main(){ int n; cin >>n; for (int i=0;i<=25;i++){ for (int j=0;j<=25;j++){ if (4*i+7*j==n){ cout <<"Yes"; return 0; } } } cout <<"No"; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int ara[2005]; int ara2[2005]; for (int i = 0; i < n; i++) { cin >> ara[i]; ara2[i] = ara[i]; } sort(ara2, ara2 + n, greater<int>()); int ara3[2005]; ara3[ara2[0]] =...
1
#include <bits/stdc++.h> using namespace std; int n, m, k, d, t, tem1, tem2, tem3, tem4, y = 1, sum = 0, ans = 0; string s, c; map<int, int> p; int arr[30000 + 10]; int maxi = -1; int dp[30000 + 10][500 + 10]; int rec(int index, int st) { if (index > maxi) return 0; int der = p[st]; if (dp[index][der] != -1) retu...
3
#include <bits/stdc++.h> using namespace std; char in[120]; pair<pair<string,int>,int> p[110]; int main(){ int a;scanf("%d",&a); for(int i=0;i<a;i++){ int t;scanf("%s%d",in,&t); string tmp=in; p[i]=make_pair(make_pair(in,-t),i); } std::sort(p,p+a); for(int i=0;i<a;i++)printf("%d\n",p[i].second+1)...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e15 + 7; const long long N = 1e6; long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b; b = r; } return a; } long long fpow(long long n, long long k, long long p = MOD) ...
2
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string str, pal; cin >> str; vector<int> freq; freq.push_back(1); pal = str[0]; for (int i = 1; i < str.size(); i++) { if (str[i] != str[i - 1]) { freq.push_back(1); pa...
2
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) if (s[i] == 'r') cout << i + 1 << "\n"; for (int i = s.size() - 1; i > -1; i--) if (s[i] == 'l') cout << i + 1 << "\n"; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long n; long long get(long long x, long long len, int gg) { if (gg) { if ((x & 1) == gg) return x / 2 + 1; else { long long pos = x / 2; return get(pos, len / 2, gg ^ (len & 1)) + (len + 1) / 2; } } else { if ((x & 1) == gg) ...
2
#include <bits/stdc++.h> using namespace std; long long n, a[111111]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 0, x = -1; for (int i = 0; i < n; i++) if (a[i] == 1) { if (x != -1) { if (i - x <= 2) ans = ans + i - x; else ans = ans +...
2
#include <bits/stdc++.h> using namespace std; double a[100005], ans; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, p; cin >> n >> p; for (long long int i = 0; i < n; i++) { int l, r; cin >> l >> r; a[i] = 1.0 - (r / p - (l - 1) / p) * 1.0 / (r - l + 1) * 1.0; } for (long...
3
#include <bits/stdc++.h> using namespace std; int n; long long joy = 0; long long a[100000 + 7], b[100000 + 7]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) if (b[i] > 2 * a[i] || b[i] == 1) joy--; else { ...
2
#include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(int)(n); ++i) using namespace std; const double g = 9.8; const double EPS = 1e-8; namespace solver{ int n; double v, gx, gy; double x1[50], x2[50], y1[50], y2[50]; double calc_y(double vx, double vy, double x){ double t = x / vx; ...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; void sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio; struct FAIL { FAIL() { cout << "CHANGE!!!" ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, d, s, t, front = 0, rev = 0, sub, sum = 0; vector<int> v; cin >> n; for (int i = 0; i < n; i++) { cin >> d; v.push_back(d); sum += v[i]; } cin >> s >> t; if (s == t) cout << 0 << endl; else { if (s < t) for (int ...
1
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, a[1001]; char b[1001]; cin >> n; if (n == 1) a[0] = 1; if (n >= 2) { a[0] = 1; a[1] = 1; } for (j = 0; j <= n; j++) b[j] = 'o'; for (i = 2; i <= 16; i++) { a[i] = a[i - 2] + a[i - 1]; } for (j = 1; j <= 16; j++) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int t; cin >> t; for (int i = 0; i < t; i++) { int n, r, sum = 0; cin >> n >> r; for (int j = 0; j < n - 1; j++) { int temp; cin >> temp; sum += temp; } int ret = (r - sum) % n; whil...
1
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%lld", &x); return x; } inline string get() { char ch[2000010]; scanf("%s", ch); return ch; } inline void read(long long *a, long long n) { for (...
5
#include <bits/stdc++.h> using namespace std; struct Node { int count; array<Node*, 26> children, transitions; Node* pi; void insert(string::iterator c) { if (*c == 0) count++; else { auto& child = children[*c - 'a']; if (child == nullptr) child = new Node{}; child->insert(next(c...
6
#include <bits/stdc++.h> using namespace std; long long a, b, c; int main() { int q; cin >> q; while (q--) { cin >> a >> b >> c; cout << (a + b + c) / 2 << endl; } }
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s = ""; int cnt = 0; for (int i = 0; i < n - 2; i++) { string x; cin >> x; int k = s.length(); if (cnt < n - 4 && s[k - 1] == x[0]) { s += x[1]; ...
2
#include <bits/stdc++.h> using namespace std; vector<string> adj[201]; int visited[201]; vector<string> v; int dfs(int node, int dist) { visited[node] = 1; int m = dist; for (int child = 0; child < adj[node].size(); child++) { string temp = adj[node][child]; std::vector<string>::iterator it; it = std:...
1
#include <bits/stdc++.h> using namespace std; long long pw(long long n, long long p) { n %= 1000000007; if (!p) return 1; long long ans = (n * n) % 1000000007; if (p % 2) return (n * ((pw(ans, p / 2)) % 1000000007)) % 1000000007; else return pw(n * n, p / 2) % 1000000007; } int main() { long long n;...
1
#include <bits/stdc++.h> using namespace std; char str[100005]; int n, k; struct SAM { int next[100005 * 2][26], fa[100005 * 2], len[100005 * 2]; int last, cnt; int cntA[100005 * 2], A[100005 * 2]; long long num[100005 * 2], sz[100005 * 2]; void clear() { last = cnt = 1; fa[1] = len[1] = 0; memset...
2
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long inf64 = 1ll * inf * inf; const int X = 1e6 + 5; int prime[X]; void precalc() { fill(prime, prime + X, 1); prime[0] = prime[1] = 0; for (int i = 2; i * i < X; i++) { if (!prime[i]) continue; for (int j = i * i; j < X; j += i...
3
#include <stdio.h> #include <iostream> using namespace std; int main() { double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2; while(cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2){ if (((xb1 <= xa1 && xa1 <= xb2) || (xa1 <= xb1 && xb1 <= xa2)) && ((yb1 <= ya1 && ya1 <= yb2) || (ya1 <= yb1 && yb1 <= ya2))) { co...
0
#include <bits/stdc++.h> using namespace std; long long int tot; long long int maxx; long long int ans; long long int a[2050]; void dfs(long long int i, long long int curr) { long long int l, r; l = 2 * i; r = l + 1; if (maxx < curr) { maxx = curr; } if (l < tot) { dfs(l, curr + a[l]); dfs(r, cu...
2
#include <bits/stdc++.h> int read() { static int c, x; while ((c = getchar()) < 48) { } x = c & 15; while ((c = getchar()) >= 48) x = x * 10 + (c & 15); return x; } struct edge { int next, to; } e[100010 << 1]; int ans = 0; int head[100010], deg[100010], f0[100010], f1[100010]; inline void add(const int &...
4
#include <bits/stdc++.h> using namespace std; int n; int dp[2][60][60]; int q[60][60][60][60]; int ask(int a, int b, int c, int d) { if (q[a][b][c][d] != -1) return q[a][b][c][d]; cout << "? " << a << ' ' << b << ' ' << c << ' ' << d << '\n'; cout.flush(); int x; cin >> x; if (x == -1) exit(0); x = 1 ^ x;...
5
#include <iostream> #include <vector> using namespace std; typedef pair<int, int> P; const int MAX_SIZE = 50; const int MAX_TASK_SIZE = 1000; int R, C, M, a = 0; int p[MAX_SIZE][MAX_SIZE] = {}; char f[MAX_SIZE][MAX_SIZE]; int costs[3][MAX_SIZE][MAX_SIZE]; int move(P src, P des, int t) { if (src == des) { retur...
0
#include <bits/stdc++.h> int a[220001], b[220001], t[220001], c[220001]; void add(int index, int n, int val) { for (; index <= n; index += ((index) & (-index))) c[index] += val; } int getSum(int index) { int sum = 0; for (; index > 0; index -= ((index) & (-index))) sum += c[index]; return sum; } template <class...
4
#include <bits/stdc++.h> using namespace std; const long long maxn = 500005; const long long inf = 0x3f3f3f3f3f3f3f3f; const long long MOD = 100000007; const double eps = 1e-10; long long qpow(long long a, long long b) { long long tmp = a % MOD, ans = 1; while (b) { if (b & 1) { ans *= tmp, ans %= MOD; ...
2
#include<bits/stdc++.h> #define MN 400 #define mod 1000000007 using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m,a[MN+5],b[MN+5],sum[MN+5][MN+5],f[MN+5][MN...
0
#include <bits/stdc++.h> using namespace std; const int SIZE = 140; const int maxn = 20010; int n, m, p; int x[maxn], y[maxn], wa[maxn], wb[maxn], d[SIZE + 10][maxn], f[SIZE + 10][maxn]; vector<char> res; bitset<maxn> g[SIZE + 10]; int doit(int o, int n, int m) { int L = o * SIZE, R = min((o + 1) * SIZE, n - 1); ...
5
#include <iostream> using namespace std; int main(){ long long N, A, B; cin >> N >> A >> B; cout << N/(A+B) * A + min(N%(A+B), A) << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef pair< int , int > Pi; bool judge(int area){ //式変形だね!! //area - y = (2y + 1)x //(area - y) % (2y + 1) for(int y = 1; y < min< int >(100000, area); y++){ if((area - y) % (2 * y + 1) == 0) return true; } return false; } int main(){ int N, room[10000...
0
#include <iostream> #include <string> #include <vector> using namespace std; int main(){ int n,m; while(cin >> n >> m && n){ vector<pair<string, int> > v; int val=0; string str; int tmp; for(int i=0;i<n;i++){ cin >> str >> tmp; v.push_back(pair<...
0
#include <bits/stdc++.h> using namespace std; long long fpow(long long n, long long k, long long p = 1000000007) { long long r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } long long inv(long long a, long long p = 1000000007 - 1) { return fpow(a, p - 2, p); } long lo...
3
#include<cstdio> int main(){ int a,b; scanf("%d %d",&a,&b); if(a==1) a=14; if(b==1) b=14; if(a>b) printf("Alice\n"); else if(a<b) printf("Bob\n"); else printf("Draw\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int aaa = 0; int n, pown = 1, a[240005], indx, indy, p[240005], lvl[240005], timer, in[240005], out[240005], pw[4 * 240005], st, en, lc, oo, c[6], ans, q, typ; vector<int> v[240005], gg; pair<int, pair<int, int> > tt[2 * 240005], l[2 * 240005][19], r[2 * 24000...
6
#include <bits/stdc++.h> using namespace std; void solve(int test_number); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.setf(ios::fixed); cout.precision(9); cerr.setf(ios::fixed); cerr.precision(3); int n = 1; for (int i = 0; i < n; i++) { solve(i); } } pair<pair<int, int>...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class C> void mini(C &a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); } template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, c...
4
#include <bits/stdc++.h> using namespace std; int m, n; int abss(int a) { return a < 0 ? -a : a; } struct node { int x, y; }; vector<node> a[4][11]; bool cmp1(const node &a, const node &b) { return abss(a.x - 1) + abss(a.y - 1) < abss(b.x - 1) + abss(b.y - 1); } bool cmp2(const node &a, const node &b) { return ab...
5