func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> int q[1000001] = {0}, p[1000001] = {0}; int main() { int n, i, a, b, j; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d%d , &a, &b); q[a] = b; ++p[a]; --p[b]; } i = 0; while (p[++i] != 1) ; j = q[0]; while (j && i) { p...
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 10, M = 2000 + 10; int n, m, s, t; int h[N], ecnt, nxt[M], v[M]; bool mp[N][N]; int dis[2][N], ans; void _add(int x, int y) { nxt[++ecnt] = h[x]; v[ecnt] = y; h[x] = ecnt; mp[x][y] = 1; } queue<int> que; void dijkstra...
#include <bits/stdc++.h> int n, arr[100]; bool vis[100]; int Cycle(int st) { int l = 1; int node = arr[st]; vis[st] = true; while (node != st) { if (vis[node]) return -1; l++; vis[node] = true; node = arr[node]; } return l; } long long GCD(long long a, long long...
#include <bits/stdc++.h> using namespace std; int n, k, l, r, sum, sk; int a[1010]; int main() { while (scanf( %d%d%d%d%d%d , &n, &k, &l, &r, &sum, &sk) != EOF) { if (n != k) { int s1, s2; s1 = sum - sk; s2 = sk; int tmp1, tmp2; tmp1 = s1 / (n - k); tmp2...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k; scanf( %d , &t); while (t--) { scanf( %d %d , &n, &k); if (n == k || n == 1 || n == 2) { cout << Alice n ; continue; } if (k % 3) { if (!(n % 3)) { cout << Bob n ; ...
#include <bits/stdc++.h> using namespace std; int fun(string x) { if (x.size() > 7) return 1000005; int n = 0; for (int i = 0; i < x.size(); i++) { n *= 10; n += (x[i] - 0 ); } return n; } bool f(string s) { if (s.size() > 1 && s[0] == 0 || s.size() > 7) return false...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clo...
#include <bits/stdc++.h> using namespace std; const int S = 100009; vector<int> in[S]; vector<int> out[S]; bool viz[S]; int moa[S]; vector<int> topol; vector<int> rang[S]; void dfs(int a) { if (viz[a]) return; viz[a] = 1; for (auto u : out[a]) dfs(u); topol.push_back(a); } void sfd...
#include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e18; struct node { int x, y; node *L; node *R; int val; int mx; node(int xx, int yy) { L = nullptr; R = nullptr; x = xx; y = rand(); ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pii = array<ll, 3>; vector<vector<pii>> adj; vi sz, parent; int fill(int cur, int par = -1) { parent[cur] = par; for (auto [v, _, __] : adj[cur]) if (v != par) sz[cur] += fill(v, cur); sz[cu...
#include <bits/stdc++.h> using namespace std; const int maxn = 2 * 100100; int a[maxn], logTable[maxn], rmq[50][maxn]; int minPos(int i, int j) { int k = logTable[j - i]; int x = rmq[k][i]; int y = rmq[k][j - (1 << k) + 1]; return a[x] <= a[y] ? a[x] : a[y]; } int main() { int n; sca...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, t; cin >> n >> m; string s[100 + 10]; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < n; i++) { t = s[i][0]; for (int j = 0; j < m; j++) { if (s[i][j] != t) { cout << NO...
#include <bits/stdc++.h> using namespace std; const int maxN = 100 * 1000 + 5; int Q; map<int, int> POS; struct range { int s, e; long long siz; long long mod[5]; range(int s = -1, int e = -1) : s(s), e(e) { memset(mod, 0, sizeof mod); siz = 0; } } t[1 << 18]; inline void b...
#include <bits/stdc++.h> using namespace std; template <class T> inline void gmin(T &x, const T &y) { x = x > y ? y : x; } template <class T> inline void gmax(T &x, const T &y) { x = x < y ? y : x; } template <class T> inline bool Gmin(T &x, const T &y) { return x > y ? x = y, 1 : 0; } ...
#include<bits/stdc++.h> using namespace std; int main(){ int T; cin>>T; while(T--){ long long int N; cin>>N; int sum1=0,i=1,count=0; while(true){ sum1+=i;count++; if(sum1>=N){break;} i+=2; } ...
#include <bits/stdc++.h> using namespace std; const long long N = (long long)(5 * 1e5 + 10); void precision(long long a) { cout << setprecision(a) << fixed; } long long expo(long long a, long long b, long long m) { long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a...
#include <bits/stdc++.h> using namespace std; int N, P[1005], D[1005]; int main() { scanf( %d , &N); for (int i = 1; i <= N; i++) { scanf( %d , &P[i]); } D[1] = 1; for (int i = 2; i <= N; i++) { int p = P[i]; D[i] = 1; for (int j = p; j < i; j++) { D[i] += D[j] ...
#include <bits/stdc++.h> using namespace std; int n, m; char mp[103][103]; int main() { int i, j, cnt; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %s , mp[i]); cnt = 0; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) if (mp[i][j] == . ) break; if (j != n) cnt++; ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1 << 30; const long long Inf = 1ll << 60ll; namespace io { char buf[(1 << 23)], *p1 = buf, *p2 = buf, c; long long f; template <typename T> T read() { T x = 0; f = 0; c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, (1 << 2...
#include <bits/stdc++.h> using namespace std; long long int lsone(long long int p) { return (p & -p); } string s1, s2; int main() { std::ios::sync_with_stdio(false); cin >> s1; cin >> s2; if (s1 == s2) cout << -1; else cout << max(s1.size(), s2.size()); }
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; int main() { ios::sync_with_stdio(false); long long int MOD = 1000000007LL; string start, end; int k; while (cin >> start >> end >> k) { const int N = static_cast<int>(start.size()); pair<long long int, long lon...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int MOD = 1000000007; int bcj[200010], siz[200010]; stack<pii> res; void init(int n) { for (int i = (0); i < (n + 2); i++) bcj[i] = i, siz[i] = 1; } int groot(int n) { return (bcj[n] == n) ? n : g...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[150], i, j, best, ans = 10000; cin >> n; for (i = 0; i < n; ++i) cin >> a[i]; for (i = 1; i < n - 1; ++i) { best = 0; for (j = 1; j < n; ++j) if (j != i) best = max(best, a[j] - a[j - 1]); else ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100000; int n, MOD, l, r; int egcd(int x, int y, int &a, int &b) { if (y == 0) { a = 1, b = 0; return x; } int g = egcd(y, x % y, b, a); b -...
#include <bits/stdc++.h> using namespace std; using ll = long long; int const nmax = 100000; int const modulo = 1000000007; struct Edge { int to; int cost; }; vector<Edge> g[1 + nmax], g2[1 + nmax]; int seen[1 + nmax], seen2[1 + nmax]; void dfs(int node, bool &fatal, int acc) { seen[node] ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int j = 0; j < t; j++) { int n; cin >> n; if (n % 4 == 0) cout << YES << endl; else cout << NO << endl; } }
#include <bits/stdc++.h> using namespace std; long long mul(long long a, long long b, long long M) { return a * b % M; } long long add(long long a, long long b, long long M) { return (a + b) % M; } vector<vector<long long> > eye(int n) { vector<vector<long long> > I(n, vector<long long>(n)); for (int i ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int N = 100010; char s[N]; int fac[N], inv[N], sum[N]; long long mpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } retur...
#include <bits/stdc++.h> using namespace std; const int N_MAX = 300010; struct Point { int x, y; }; Point points[N_MAX]; int nPoint; void outerInit() { ios::sync_with_stdio(false); cin.tie(nullptr); auto fi = new ifstream( test.inp ); if (*fi) { cin.rdbuf(fi->rdbuf()); } } ...
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } vector<long long in...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 7; long long tam(long long x) { long long r = 0; while (x > 0) { x /= 10; r++; } return r; } map<long long, long long> r[15]; long long pre[15]; int32_t main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; bool Primality(long long n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (long long i = 3; i * i <= n; i = i + 2) if (n % i == 0) return false; return true; } int main() { long long n; cin >>...
#include <bits/stdc++.h> using namespace std; bool p[10000001]; long h[10000001]; struct S { long a, c; } s[1000000]; int n; int k; long a[1000001]; int binl(int x) { if (x == 2) return 0; if (x > s[k - 1].a) return -1; int mid = (0 + k - 1) / 2; int l = 0, r = k - 1; while (l ...
#include <bits/stdc++.h> using namespace std; const int mxn = 1e3 + 5; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } struct data { int U; int V; int idx; }; vector...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, k, sum = 0, cnt = 0, a[101]; cin >> n >> m; vector<long long int> o; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } for (i = 0; i < m; i++) { cin >> j; j--; sum -= a[j]; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 10; int n, m, k; int fa[MAXN]; int visit[MAXN]; vector<int> res; struct node { int x, y, id; double w; node() {} node(int x_, int y_, double w_, int id_) { x = x_; y = y_; w = w_; id = id_; ...
#include <bits/stdc++.h> using namespace std; double gen(double x, double y, double z) { return log(log(x)) + z * log(y); } double gen(double x, double y) { return log(log(x)) + log(y); } vector<pair<double, string> > genall(double x, double y, double z) { vector<pair<double, string> > r; if (x > 1.) { ...
#include <bits/stdc++.h> using namespace std; void run(); int main() { ios::sync_with_stdio(0); run(); } int n; int v[5001]; char s[5001]; int grundy[5001]; void run() { cin >> s; n = strlen(s); vector<int> blob; for (int i = 0; i < n; i++) if (0 < i and i + 1 < n and s[i...
#include <bits/stdc++.h> using namespace std; int pa[5009], siz[5009], occ[5009], tots = 0; bool yay; vector<pair<int, pair<int, int> > > edges; int finder(int node) { if (pa[node] != node) { return pa[node] = finder(pa[node]); } return node; } void uniter(int x, int y) { x = finder(...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s, s1; cin >> s >> s1; string s2; cin >> s2; map<char, char> m; for (long long i = 0; i < 26; i++) { m[s[i]] = s1[i]; } string ans = ...
#include <bits/stdc++.h> using namespace std; int arr[3000000]; long long fadd[3000000]; long long carry[3000000]; long long tot[3000000]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; int nsize = 2 * n + 1; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; long long n, sx, sy, dx, dy, t; struct matrix { long long m[8][8]; matrix() { memset(m, 0, sizeof(m)); } }; matrix mul(matrix a, matrix b) { matrix tmp; for (int i = 1; i <= 6; i++) for (int k = 1; k <= 6; k++) if (a.m[i][k]) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 400007; int n, I, cnt = 0, ret = -1; int a[maxn], s[maxn]; int ck() { int ans = 1; for (int i = 1; i <= 8 * I / n; ++i) { ans *= 2; if (ans > cnt) return -1; } return ans; } int main() { scanf( %d%d , &n, &I); ...
#include <bits/stdc++.h> using namespace std; int n; string ss; int dp[200005][4]; char s[] = { R , G , B }; int calc(int u, int c) { if (u == n) return 0; if (dp[u][c] != -1) return dp[u][c]; int ret = n; for (int i = 0; i < 3; i++) { if (i == c) continue; if (s[i] == ss[u]) ...
#include <bits/stdc++.h> using namespace std; int n, Q; int cnt_bad = 0; bool bad[2][100100]; int main() { scanf( %d%d , &n, &Q); memset(bad, 0, sizeof(bad)); for (int i = 0; i < Q; i++) { int x, y; scanf( %d%d , &x, &y); x--, y--; if (bad[x][y]) { bad[x][y] = 0; ...
#include <bits/stdc++.h> using namespace std; int n, x, fr, x0, L, R, len, l[4000], f[4000]; string s1[4000], s2[4000], ss, p, p1; int main() { ios::sync_with_stdio(0); cin >> n; for (int i = (1); i <= (n); i++) { cin >> s1[i]; l[i] = s1[i].length() - 1; } for (int i = (1); i <= ...
#include <bits/stdc++.h> using namespace std; const int64_t N = 1e3 + 3; const int64_t mod = 998244353; int64_t f[N][2][2][2 * N]; int64_t more(int64_t x, int64_t y, int64_t u, int64_t v) { if (x == y) { if (u != x || v != y) return 1; return 0; } if (u != x && v != y) return 2; re...
#include <bits/stdc++.h> int main() { int NumOfStudent; int NumOfTeams; int ones = 0, twos = 0, threes = 0; int i, k, l, j, c, m, n, p; int a[5000]; scanf( %d , &NumOfStudent); for (i = 0; i < NumOfStudent; i++) { scanf( %d , &a[i]); } for (i = 0; i < NumOfStudent; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, m, a[10][110], b[410]; int main() { while (~scanf( %d%d , &n, &m)) { memset(a, 0, sizeof(a)); for (int i = 1; i <= min(m, 2 * n); i++) { if (i & 1) { a[1][(i + 1) >> 1] = i; } else { a[4][i >> 1] = i; ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int N = 142123; int n, a, b, c, d, s, ce; long long ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> a >> b >> ce >> d; for (int i = 1; i <= n; ++i) { s = a + b + i; c = s - a - ce; ...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; char s[1010]; int n, fa[2010], val[2010], pw2[2010], ans = 0; inline int getf(int x) { if (x == fa[x]) return x; int f = getf(fa[x]); val[x] ^= val[fa[x]]; fa[x] = f; return f; } inline int merge(int x, int y, int...
#include <bits/stdc++.h> using namespace std; int read() { int a = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) { a = a * 10 + c - 48; c = getchar(); } return a; } const double pi = acos(-1); struct comp { double x, y; comp(double _x ...
#include <bits/stdc++.h> using namespace std; const int N = 15; const int M = 11005; const int mo1 = 317503; const int mo2 = 1000000007; const int BAS = 2333; const int P = 3000005; int n, m, k, Hash[N], bel[N], tot, matching[M][N][2], temp_matching[N][2], bin[N]; long long ans, jc[N]; vector<...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { int n; cin >> n; vector<long long int> a(n); for (long long int i = 0; i < n; i++) cin >> a[i]; sort((a).begin(), (...
#include <bits/stdc++.h> using namespace std; int main() { int k = 0; cin >> k; int maxi = 0; for (int i = 0; i < k; i++) { int inp; cin >> inp; maxi = max(maxi, inp); } cout << max(0, maxi - 25) << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 20; int ans, a, m, n; long long ps0[N], ps1[N], arr[N], inf = 1e10 + 100; int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n >> arr[0]; arr[n] = inf; ps0[0] = 0; for (int i = 1; i < n; i++) { cin >> arr[i]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6 + 100; const long long inf = (1ll << 60); const int mod2 = (int)998244353; const int mod = (int)1e9 + 7; int n, m; struct query { int type; int x1, y1, x2, y2; long long v; } Q[maxn]; struct fenwick { long long a[1...
#include <bits/stdc++.h> using namespace std; int n, tans, a[100005], qaq[100005], que[1 << 15]; bool vis[1 << 15]; struct node { int x, y, z; } ans[100005 << 1]; struct node2 { int ty, lst, pos; } pre[1 << 15]; void ins(int x, int y, int z) { a[x] ^= 1, a[y] ^= 1, a[z] ^= 1; ans[++tans]...
#include <bits/stdc++.h> using namespace std; int di[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dj[] = {1, -1, 0, 0, -1, 1, 1, -1}; const double PI = 3.14159265359, EPS = 1e-9; const int N = 1000006, M = 1000006, Mod = 1000000007; vector<int> adj[N]; pair<int, int> tree[4 * N]; int n; string str; void bui...
#include <bits/stdc++.h> int main() { int n, x, i, min = 0; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &x); min += 15; if (min >= x) min = x; else break; } if (i == n) min += 15; if (min >= 90) printf( 90 n ); else printf( %d ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int n, k; cin >> n >> k; string ans; ans += to_string(k); if (k == 10 && n == 1) { cout << -1; return 0; } int bound = n - 1; if (k == 10) bound--; f...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < 7; i++) { cin >> arr[i]; } int day = 1; int i = 0; while (n > 0) { n = n - arr[i]; i++; if (n > 0) { day++; } if (day > 7) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000; const int INF = 1e9 + 7; int le, ri, tot, cpt[60][60], fir[maxn], sec[maxn]; struct MCMF { struct Edge { int from, to, cap, cost; Edge() {} Edge(int from, int to, int cap, int cost) : from(from), to(to), cap(c...
#include <bits/stdc++.h> using namespace std; int main() { int n, d = 2, m = 4127, f = 0, c = 0; cin >> n; while (n--) { int a, b; cin >> a >> b; if (f == 0) { f = 1; m = a; } else { if (a < m) m = a; } if (b != a) c = 1; if (a > m) d = 0...
#include <bits/stdc++.h> using namespace std; const int MAXN = (1 << 20) + 10; const double PI = acos(-1); double dp[MAXN]; int N; double L, R; double x[22], y[22], a[22]; int main() { memset(dp, 0, sizeof(dp)); scanf( %d%lf%lf , &N, &L, &R); for (int ni = 0; ni < N; ni++) { scanf( %lf...
#include <bits/stdc++.h> #pragma GCC optimization( O3 ) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t) { int n, m; cin >> n >> m; vector<pair<int, int>> v; vector<int> orig; for (int i = 0; i < m...
#include <bits/stdc++.h> using namespace std; bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) return 0; } return 1; } int main() { int n; vector<int> ans; cin >> n; for (int i = 2; i <= n; ++i) { if (prime(i)) { for (int j = i; j <= n; j *= ...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; const double eps = 0.0001; void swap(double &a, double &b) { double t = a; a = b; b = t; } int main() { double x1, x2, x3; double y1, y2, y3; double a1, a2, a3; ...
#include <stdio.h> // #include <iostream> #include <algorithm> // #include <cmath> // #include <string> // #include <string.h> // #include <vector> // #include <bits/stdc++.h> using namespace std; // const int INF32 = 2000000000; // const int INF64 = 2000000000000000000; // const int MOD17 = 10...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000 * 1000 * 1000 + 7; long long n, k; vector<long long> ans; long long positive(long long n) { n %= mod; (n < 0) && (n += mod); return n; } long long gcd(long long a, long long b, long long &x, long long &y) { if (a == 0...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; vector<int> adj[105]; int n, k, dp[105][50], tmp[50]; void dfs(int u, int p) { dp[u][0] = dp[u][k + 1] = 1; for (int x = 0; x < adj[u].size(); x++) { int v = adj[u][x]; if (v == p) continue; dfs(v, u); memse...
#include <bits/stdc++.h> using namespace std; void Fast_IO() { ios::sync_with_stdio(0); cin.tie(0); } long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { if (a == 0 || b == 0) return 0; return ((a / gcd(a, ...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - 0 ; ch = getchar(); } return x * f; } int n,...
#include <bits/stdc++.h> using namespace std; char s[1000005]; int cnt[11] = {0}; int m[7] = {1869, 8196, 8916, 8691, 6198, 1689, 1968}; int main() { scanf( %s , s); int len = strlen(s); int n = len; for (int i = 0; i < len; i++) cnt[s[i] - 0 ]++; if (cnt[0] + 4 == n) { printf( 1869...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, L = 0, R = 0; string key; cin >> n; cin >> key; for (i = 0; i < n; i++) { if (key[i] == L ) L++; else R++; } cout << abs(R + L) + 1 << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100086; int z[maxn], n, m, num, order[maxn][2], last[maxn], ans[maxn], len, in[maxn]; bool flag, ok[maxn]; char s[2]; int main() { scanf( %d %d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %s , s); scanf( %d , &num); ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 10; const long long MOD = 998244353; long long sq(long long x) { return x * x % MOD; } long long qpow(long long a, long long b) { return b ? sq(qpow(a, b / 2)) * (b & 1 ? a : 1) % MOD : 1; } long long inv(long long x) { return qpow(...
#include <bits/stdc++.h> using namespace std; const int N = 103, M = 998244353; const int mod = M - 1; struct matrix { int row, col; int a[N][N]; matrix() { memset(a, 0, sizeof a); } matrix(int r, int c) : row(r), col(c) { memset(a, 0, sizeof a); } matrix operator*(const matrix &p) { a...
#include <bits/stdc++.h> int32_t get_economy(std::vector<int32_t> joined_roots, int32_t** tree) { if (joined_roots.size() == 1) return 0; int32_t res = joined_roots.size() - 1; std::vector<int32_t> join_lists[26]; for (int32_t i = 0; i < joined_roots.size(); i++) for (int32_t j = 0; j < 26; j++)...
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__) #else #define DEBUG(...) 6 #endif template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << ( << p.first << , << p.second << ) ;} templa...
#include <bits/stdc++.h> using namespace std; template <class T> bool setmax(T &_a, T _b) { if (_a < _b) { _a = _b; return true; } return false; } inline void Boost() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { int n, k; cin >> n...
#include <bits/stdc++.h> using namespace std; int n, m, k, u, v, a[200005], el, ans; vector<int> adj[200005]; queue<int> q; bool vis[200005]; int depth[200005], depthn[200005]; int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; int n, m; struct BIT { long long val[500005]; void add(int x, int w) { for (; x <= m; x += x & -x) val[x] += w; return; } long long sum(int x) { long long sum = 0; for (; x; x -= x & -x) sum += val[x]; return sum; } ...
#include <bits/stdc++.h> using namespace std; int main() { int l, max, min, r, k, i, flag = 0, ans = 0, temp = 0, pos = 0, neg = 0, cnt = 0, d = 0, size; char s[109]; for (int j = 0; j < 100; j++) { cin.getline(s, 105); if (strlen(s) == 0) { break; ...
#include <bits/stdc++.h> using namespace std; class CElections { public: struct person { long long p, c; }; int n, m; person arr[3100]; vector<long long> parties[3100]; long long sol(int votes) { int total_votes_needed = votes - (int)parties[0].size(); vector<long long> ...
#include <bits/stdc++.h> using namespace std; int dp[int(1e2) + 10][int(1e2) + 10]; vector<pair<int, int> > com[int(1e2) + 10]; int n, m, s, e; int ans[int(1e2) + 10], tt[int(1e2) + 10]; bool mark[int(1e2) + 10]; int dfs(int v, int tail) { if (v == tail) return ans[v]; if (mark[v]) return tt[v]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, b, mn1 = 1000000, mn2 = 0, temp; cin >> n >> m >> b; for (int i = 0; i < n; i++) { int x; cin >> x; mn1 = min(mn1, x); } for (int i = 0; i < m...
#include <bits/stdc++.h> using namespace std; long long a[100009]; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; if (n > 1) { cout << 1 << << n - 1 << endl; for (int i = 1; i <= n - 1; i++) if (a[i] == 0) cout << (long long)(n - 1) * n << ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, rm, fr = 1, l, r, li = 0, ri = 0, c = 0; cin >> n >> m >> k; if (n == 1) { cout << m << endl; return 0; } l = k - 1; r = n - k; rm = m - n; while (1) { if (c + li + ri + 1 <= rm) { c += ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int arr[n]; map<long long int, bool> mp; deque<long long int> dq; for (long long int i = 0; i < n; i++) { cin >> arr[i]; mp[arr[i]] = false; } for (long long int i = 0;...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; int a, b, p; string second; void solve() { cin >> a >> b >> p >> second; int n = (int)(second).size(); ll t = 0; for (int i = 0; i < n;) { int c = 0; t += seco...
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; vector<long long int> dp(2e5 + 1, 1); int main() { long long int t, q = 1, n, k; ; while (q--) { for (long long int i = 1; i < 2e5 + 1; i++) dp[i] = ((dp[i - 1] % 998244353) * 10) % 998244353; cin >> n; for (i...
#include <bits/stdc++.h> using namespace std; template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } int nextInt() { int x = 0, p = 1; char c; do { c = getchar(); } while (c <= 32); if (c == - ) { p = -1; c = getchar(); } while (c >= 0 && c <...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long result = n / 2; if (n & 1) { result -= n; } cout << result << endl; return 0; }
#include <bits/stdc++.h> long long n, k, l, m, ans; struct mat { long long a[3][3]; } A, B; inline mat operator*(mat x, mat y) { mat c; memset(c.a, 0, sizeof c.a); for (int k = (0), __ = (2); k < __; ++k) for (int i = (0), __ = (2); i < __; ++i) for (int j = (0), __ = (2); j < __; ...
// Author : deetav // Happy stalking ! ^_^ #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #include <bits/stdc++.h> using namespace std; #define endl n int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 5e5; struct team { long long t, w, id; } a[maxn]; priority_queue<long long> Qf; priority_queue<pair<long long, long long> > Qb; long long n, i, j, x, y, z, ans, T, W; bool cmpw(team a, team b) { return a.t > b.t || (a.t == b.t && a...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } char str[5]; int main() { int t = 0, x = 0; scanf( %d , &t); for (int i = 0; i < t; i++) { cin >> str; if (strcmp(str, ++X ) == 0 || strcmp(str, X++ ) == 0) { ...
#include <bits/stdc++.h> using namespace std; struct keycompare { bool operator()(const pair<long long, long long>& v, const long long& k) { return (v.first < k); } bool operator()(const long long& k, const pair<long long, long long>& v) { return (k < v.first); } }; long long mod1 = ...
#include <bits/stdc++.h> using namespace std; const int oo = 2e9; const int N = 1e6; int n; string s, x = BGR ; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n >> s; int k = oo; string ans; do { int cnt = 0; string t = s; ...