func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; struct st { long long int num; long long int big; } w[200001]; bool cmp(st a, st b) { return a.big < b.big; } int main() { std::ios::sync_with_stdio(false); long long int n, i; char p; while (cin >> n) { queue<long long int> q; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int INF = 1e9; const long long mod = 1e9 + 7; int n, a, b, v; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { cin >> n >> a >> b >...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, logn = 20, inf = 2e5 + 10; int L[maxn * logn], R[maxn * logn], sum[maxn * logn]; int root[maxn]; int sz = 1, rt = 1; int copy(int v, int &u) { L[sz] = L[v]; R[sz] = R[v]; sum[sz] = sum[v]; return u = sz++; } void ad...
#include <bits/stdc++.h> using namespace std; long long num[100005], sorted[100005]; long long prenum[100005], presorted[100005]; int main() { int n, q, l, r, op; cin >> n; for (__typeof(n) i = 0; i < n; i++) { cin >> num[i]; sorted[i] = num[i]; } sort(sorted, sorted + n); pr...
#include <bits/stdc++.h> using namespace std; int root; void addEdge(vector<int> adj[], int u, int v) { if (u == -1) { root = v; return; } adj[u].push_back(v); } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<int> res; int n...
#include <bits/stdc++.h> constexpr double EPS = 1e-9; using namespace std; int sz = 0; int n, m; vector<vector<pair<int, int>>> ss; bool vis[51][51]; string grid[51]; void dfs(int r, int c) { vis[r][c] = 1; ss[sz].push_back({r, c}); for (int i = 0; i < n; i++) { if (grid[i][c] == # &...
#include <bits/stdc++.h> using namespace std; int n; set<int> S[100001]; int main() { scanf( %d , &n); set<int> s; int x, k; for (int i = 0; i < n; ++i) { scanf( %d%d , &x, &k); if (x && S[k].find(x - 1) == S[k].end()) { puts( NO ); return 0; } S[k].insert...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5, inf = 1e9 + 7; long long n, k, i, j; long long C[N], f[3][N]; pair<long long, long long> A[N]; inline long long util(long long a, long long b, long long c) { return f[c][a] - f[c][b]; } signed main() { ios_base::sync_with...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 1; int n, rt, tot, sz[maxn], bel[maxn], in[maxn], out[maxn], seg[maxn << 1 | 1]; vector<pair<int, int> > e[maxn]; set<int> sp[maxn]; long long ans; void dfs(int u, long long dis, int ori) { sz[u] = 1; ans += dis; bel[u] ...
#include <bits/stdc++.h> using namespace std; map<long long, int> cnt; int lp[100005]; long long p[100005][102]; void sieve() { for (int i = 2; i <= 100000; i++) { if (!lp[i]) { lp[i] = i; for (int j = i + i; j <= 100000; j += i) if (!lp[j]) lp[j] = i; } } } i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k, num = 0; cin >> n >> k; vector<pair<int, int> > a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; a[i].first = -a[i]...
#include <bits/stdc++.h> long long gcd(long long A, long long B) { return A > B ? gcd(B, A) : A ? gcd(B % A, A) : B; } long long lcm(long long A, long long B) { return A / gcd(A, B) * B; } long long pow(long long A, long long B, long long P) { if (!B) return 1 % P; if (B == 1) return A % P; long...
#include <bits/stdc++.h> using namespace std; int a[1000001]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } int m; cin >> m; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; a[x + 1] += a[x] - y; a[x - 1] += y - 1; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5010; int v[MAXN], n, k; int vec[1000100][12]; bool vis[1000100]; void crivo() { for (int i = 1; i <= 1000001; i++) { set<int> s; for (int j = 0; j <= 1000000; j += i) { for (int t = 1; t <= 11; t++) { int at = ...
#include <bits/stdc++.h> using namespace std; int a[1505]; int main() { ios::sync_with_stdio(false), cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } bool isEven = true; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int p = 1; for (int i = 0; i < 5; i++) { p *= n - i; } cout << p * (p / 120); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long INF = 1e18L + 7; template <class n, class second> ostream &operator<<(ostream &p, pair<n, second> x) { return p << < << x.first << , << x.second << > ; } template <class n> auto operator<<(ostream &p, n y) -...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200200; int n, k, cnt[MAXN]; long long ans; bool f[MAXN]; vector<int> g[MAXN]; void dfs(int v, int p = -1) { cnt[v] = f[v]; for (const int &u : g[v]) if (u != p) dfs(u, v), cnt[v] += cnt[u]; } void solve(int v, int p = -1) { ...
#include <bits/stdc++.h> using namespace std; int r, c; string str_col[1000006]; string str_dir[1000006]; vector<int> e[1000006], rev[1000006]; int col[1000006], vis[1000006], vis2[1000006]; int cyc_len, black_cnt; inline int id(int x, int y) { return c * x + y; } vector<int> st; int got[1000006]; ...
#include <bits/stdc++.h> using namespace std; int main() { float a1, b1, c1, a2, b2, c2; cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; if (!b1 && !b2) { if ((!a1 && c1) || (!a1 && c2)) { cout << 0 << endl; return 0; } if ((!c1 && !c2) || (!a1 && !a2) || c1 / a1 == c2 / a2) {...
#include <bits/stdc++.h> using namespace std; long long n, m; vector<vector<long long> > a, b, orig; bool swapd = false; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; orig.resize(n); for (long long i = 0; i < n; i++) { orig[i].resize...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const double PI = acos(-1.0); const double epsilon = PI / 180.0; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; ...
#include <bits/stdc++.h> using namespace std; using namespace chrono; const int infinity = (int)1e9 + 42; const int64_t llInfinity = (int64_t)1e18 + 256; const int module = (int)1e9 + 7; const long double eps = 1e-8; mt19937_64 randGen(system_clock().now().time_since_epoch().count()); inline void raiseE...
#include <bits/stdc++.h> using namespace std; long long cum[(int)1e6], input[(int)1e6], k, ans; char c; int sz, t; map<long long, vector<int>> pos; int main() { cin >> sz >> k; for (int i = 0; i < sz; i++) { scanf( %c%d , &c, &t); input[i] = t; if (i == 0) { cum[0] = t; ...
#include <bits/stdc++.h> const double pi = acos(-1); const int MOD = 1e9 + 7; const long long INF = 1e18 + 7; const int MAXN = 1e3 + 5; const double eps = 1e-9; using namespace std; long long a[MAXN], dist[MAXN]; pair<long long, long long> loc[MAXN]; int par[MAXN]; long long cost(int x, int y, long ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, oo = inf; inline long long read() { register long long x = 0, f = 1; register char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ...
#include <bits/stdc++.h> using namespace std; int sum[100010], ans[100010]; int data[100010]; bool sign[100010]; int main() { int n, m, c; while (scanf( %d %d %d , &n, &m, &c) == 3) { for (int i = 1; i <= n; i++) { scanf( %d , &ans[i]); } for (int i = 1; i <= m; i++) { ...
#include <bits/stdc++.h> using namespace std; vector<int> v[1000005]; int n, ar[100005]; int main() { cin >> n; set<int> st; for (int i = 0; i < n; i++) { cin >> ar[i]; st.insert(ar[i]); v[ar[i]].push_back(i + 1); } vector<int> fr(st.begin(), st.end()); int mx = 0, l = ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; struct Edge { int to, next; } e[N << 1]; int in[N], head[N], sz; int del[N], leg[N]; int cnt[N]; int res, n; void addedge(int u, int v) { e[sz].to = v; e[sz].next = head[u]; head[u] = sz++; } void init() { mems...
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); int a[t], b[t], c[t]; for (int i = 0; i < t; i++) scanf( %d %d %d , &a[i], &b[i], &c[i]); for (int i = 0; i < t; i++) { if (a[i] == b[i] && b[i] == c[i]) { printf( YES n ); printf( %d %d %d n , a[i], a[i], a[i]); ...
#include <bits/stdc++.h> using namespace std; struct query { long long int l; long long int r; long long int i; }; query Q[200001]; long long int arr[200001]; long long int f[1000001]; long long int ans[200001]; long long int cnt; bool compare(query a, query b) { if ((a.l / 448) != (b....
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, a = 0; cin >> n; int* arr = new int[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (int j = 0; j < n; j++) { cout << arr[j] << ; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } int j, x; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (a[i] != a[n - j - 1]) { x = n - 1 - j - i; break; ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const int Max = 3e5 + 10; int n; char mp[11][11]; int main() { for (int i = 1; i <= 10; i++) { scanf( %s , mp[i] + 1); } bool ok = false; for (int i = 1; i <= 10 && !ok; i++) { ...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const long long mod = (long long)1e9 + 7; const double eps = (double)1e-9; const double pi = acos(-1.0); const int dx[] = {0, 0, 1, 0, -1}; const int dy[] = {0, 1, 0, -1, 0}; const int N = 100500; int n, ans, a[N], dp[N]; int ma...
#include <bits/stdc++.h> using namespace std; long double PI = 3.14159265359; long double DEL = 1e-10; int mod = 1000000007; long long fpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int cnt = 0; std::vector<int> v; for (int i = n - 1; i > 0; --i) { if (a[i] != 10000) { for (int j = i - ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<pair<long long, long long>> a(n); vector<long long> ord(n); for (long long i = 0; i < n; i++) { cin >> a[i].first; a[i].second =...
#include <bits/stdc++.h> using namespace std; int main(void) { string second[5] = { Danil , Olya , Slava , Ann , Nikita }; int sum = 0; string t; cin >> t; for (int i = 0; i < 5; i++) { int pos = t.find(second[i], 0); while (pos != string::npos) { sum++; pos = t.f...
#include <bits/stdc++.h> using namespace std; int a[102] = {0}; int main() { int n, m, i, ans = 0, x, l, r, num, mid; cin >> n >> m; for (i = 0; i < m; i++) { cin >> x; a[x]++; } sort(a + 1, a + 101); l = 1; r = 10000; while (l <= r) { num = 0; mid = (l + r)...
#include <bits/stdc++.h> using namespace std; const int mxn = 110; int i, j, k; int x, y, z, xx, xy, xz, yx, yy, yz; int m, n, p; char a[mxn]; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %s , a); m = strlen(a); if (a[0] != a[m - 1]) { a[0] = a[m - 1]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int k = 0; int sum = 0; for (int i = 2; i <= n - 1; i++) { int z = n; while (z >= i) { sum += z % i; z = z / i; } sum += z; k++; } for (int i = 2; i <= n - 1; ...
#include <bits/stdc++.h> using namespace std; queue<int> q; vector<int> v[200001]; set<pair<int, int> > se; int mdis, node; void dfs(int x, int l, int p) { if (l > mdis) { mdis = l; node = x; } for (int y : v[x]) { if (y == p) continue; dfs(y, l + 1, x); } } int m...
#include <bits/stdc++.h> using namespace std; int main() { int t, m, n, z, s, q, p; cin >> t; while (t--) { cin >> n >> m; int a[n][m], z = 200, s = 0, p = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> a[i][j]; if (a[i][j] < 0) { ...
#include <bits/stdc++.h> using namespace std; vector<long long int> x; vector<vector<int> > adjList; vector<bool> visited; long long int ans = 0; long long int add(long long int a, long long int b) { return (a + b) % 1000000007; } long long int mul(long long int a, long long int b) { return (a *...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 9; const int mod = 1e9 + 7; int32_t main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; if (n % m == 0) cout << YES n ; else cout << NO n ; } return 0; }
#include <bits/stdc++.h> using namespace std; long long read() { long long k = 1, x = 0; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) k = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + (c - 48); c = getchar(); } ret...
#include <bits/stdc++.h> using namespace std; int A[1000010]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; string s; cin >> s; int la = -1e9, ha = 1e9, lb = -1e9, hb = 1e9; multiset<int> fg; for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; vector<long long> v; cin >> n; long long a = 1; while (a * (a + 1) / 2 <= n) v.push_back(a * (a + 1) / 2), a++; for (long long i = 1; i * (i + 1) / 2 <= n; i++) { int cur = n - i * (i + 1) / 2; if (binary_sea...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; long long int ans = pow(2, n); for (int i = 1; i <= n / 2 - 1; i++) { ans += pow(2, i); } for (int i = n / 2; i <= n - 1; i++) { ans -=...
#include <bits/stdc++.h> using namespace std; bool primes[1000007]; void sieve(int n) { for (long long i = 2; i <= n; i++) { if (primes[i]) continue; for (long long j = i * i; j <= n; j += i) { primes[j] = 1; } } } int main() { int n; cin >> n; sieve(1e6); whi...
#include <bits/stdc++.h> using namespace std; int dis[200009]; int con[200009]; bool cmp(int a, int b) { return a < b; } int main() { int i, p, j, n, t, y; int x; long long int nail; scanf( %d , &n); for (i = 0; i <= n - 1; i++) scanf( %d , &dis[i]); sort(dis, dis + n, cmp); nail =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long mas[n]; long long sum = 0; for (int i = 0; i < n; i++) { cin >> mas[i]; sum += mas[i]; } sort(mas, mas + n); int k; cin >> k; int c; while (k > 0) { cin >> c; cou...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; int killed[100000], val[100000]; int main() { ios::sync_with_stdio(0); int n, ans = 0; vector<int> S(1, 0); cin >> n; killed[0] = -1; for (int i = 0; i < n; i++) cin >> val[i]; for (int i = 1; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:400000000 ) int n, t; int H; string s; int ok(int rest, int last) { int time = 0; for (int i = 0; i < (last + 1); i++) { time++; if (time > t) return 0; if (time + (last - i) * 2 <= t) return 1; if ...
#include <bits/stdc++.h> using namespace std; const long long int N = 2e6, OO = 1e17, M = 1e9 + 7; pair<long long, long long> p[N]; long long dp[N]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long n; cin >> n; for (int i = 0; i < n; i++) { cin >> p[i].first >...
#include <bits/stdc++.h> using namespace std; int sum = 0; vector<vector<int>> mat; vector<string> mat2; void f1(vector<string>& ans, int f, string s) { if (f == 0) return; string s1 = to_string(f) + + s; ans.push_back(s1); sum += f * s.length(); vector<int> temp(2, 0); temp[0] = f...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int s1[n]; int s2[n]; for (int i = 0; i < n; i++) cin >> s1[i]; for (int i = 0; i < n; i++) cin >> s2[i]; for (int i = 0; i < n; i++) s1[i]--, s2[i]--; int arr[n]; for (int i = 0; i < n; i++) { arr[...
#include <bits/stdc++.h> using namespace std; using ll = long long; int MOD; struct modint { private: int v; static int minv(int a, int m) { a %= m; assert(a); return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a); } public: modint() ...
#include <bits/stdc++.h> using namespace std; int main() { char ch; string s1, s2; int S = 1, H = 2, D = 3, C = 4; int T = 10, J = 11, Q = 12, K = 13, A = 14; cin >> ch >> s1 >> s2; if (s1[1] == ch && s2[1] != ch) cout << YES n ; else if (s1[1] == s2[1]) { if (s1[0] == A &...
#include <bits/stdc++.h> using namespace std; void solve(string s) { int n = s.size(); s = # + s; vector<int> pi(n + 1); pi[0] = 0, pi[1] = 0; for (int i = 2; i <= n; i++) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j + 1]) j = pi[j]; if (s[i] == s[j + 1]) j++; pi[i]...
#include <bits/stdc++.h> using namespace std; int n; string txt, ans; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> txt; for (int i = 0; i < n - (2 + (n & 1)); i++) { if ((i & 1) == 0 && i) ans += - ; ans += txt[i]; } if (n > 3) ans += - ; f...
#include <bits/stdc++.h> using namespace std; const int maxn = 50015; const int INF = 0x3f3f3f3f; struct edge { int to, capacity, rev; long long cost; edge() {} edge(int to, int _capacity, long long _cost, int _rev) : to(to), capacity(_capacity), cost(_cost), rev(_rev) {} }; struct M...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int INF = 1e9 + 7; const int N = 2e5 + 7; const int M = 5e6 + 7; int a[N], f[N], ans[N]; int get(int x) { int k = ceil(sqrt(abs(x) * 1.00)); for (int i = 2; i <= k; i++) while (x % (i * i) == 0) x /= i * i; retur...
#include <bits/stdc++.h> using namespace std; long long int dp[100000 + 10]; vector<int> ma[100000 + 10]; int a[100000 + 10]; long long int dp1[100000 + 10]; long long int gcd(long long int x, long long int y) { return y == 0 ? x : gcd(y, x % y); } long long int lcm(long long int x, long long int y)...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; inline long long bigmod(long long B, long long P) { long long R = 1; while (P > 0) { if (P & 1) { R = (R * B) % mod; } P >>= 1; B = (B * B) % mod; } return R; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 2e5 + 7; const double eps = 0.00000001; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <typename ...
#include <bits/stdc++.h> using namespace std; long long K, N; string A, B; bool valid[1001]; long long dp[100002][2]; int main() { ios::sync_with_stdio(0); cin >> A >> B >> K; N = A.size(); dp[0][0] = 1, dp[0][1] = 0; for (int i = 1; i <= K; ++i) { dp[i][0] = (N - 1) * dp[i - 1][1]...
#include <bits/stdc++.h> int n, m; using namespace std; vector<int> used(5005, 0); vector<int> used2(5005, 0); int jlo1 = 3; vector<int> a; long long res = 0; vector<vector<int>> graph(5005, a); vector<int> b; vector<vector<int>> graph1(5005, b); int q = 0; bool flag = false; void dfs(int p) {...
#include <bits/stdc++.h> using namespace std; const int N = 100010; vector<int> vec[N], fenw[N]; int n, k, x[N], r[N], f[N], id[N], rev[N]; void update(int who, int p, int v) { while (p < fenw[who].size()) fenw[who][p] += v, p += p & -p; } int pref(int who, int p) { int ret = 0; while (p) ret ...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> void pr(const pair<T1, T2>& x); template <class T, size_t SZ> void pr(const array<T, SZ>& x); template <class T> void pr(const vector<T>& x); template <class T> void pr(const set<T>& x); template <class T1, class T2> void ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; long long mx = 0; vector<long long> ans(n); for (long long i = 0; i < n; i++) { long long cnt = a[i], mn = a[i]; vector<l...
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int> > v; vector<int> tail; int getIdx(int l, int r, int key) { while (l < r) { int mid = (l + r) / 2; if (tail[mid] < key) r = mid; else l = mid + 1; } return r; } int LIS() { int lengt...
#include <bits/stdc++.h> using namespace std; void fast(); int main() { fast(); int n, cookies[105] = {0}; cin >> n; int sum = 0; for (int i = 0; i < n; ++i) { cin >> cookies[i]; sum += cookies[i]; } int cnt = 0; for (int i = 0; i < n; ++i) { int cook = sum; ...
#include <bits/stdc++.h> using namespace std; struct st { long long n, v; bool operator<(const st &other) const { return v < other.v; } }; template <typename T> string ts(T val) { std::ostringstream oss; oss << val; return oss.str(); } int main() { ios_base::sync_with_stdio(0); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int K = 1048576; int n; long long t[2][2 * K]; vector<int> g[N]; int T[N]; long long h[N], x[N], dp[N]; long long total; void build() { for (int i = 0; i < 2 * K; i++) t[0][i] = t[1][i] = 0; } void upd(int id, long lo...
#include <bits/stdc++.h> using namespace std; int z[1000005]; string s; void z_function() { int n = (int)s.length(); for (int i = 0; i < n; i++) z[i] = 0; for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[i + z[i]...
#include <bits/stdc++.h> using namespace std; using ll = long long; using lll = __int128_t; const int N = 105; int n; vector<int> v[N]; void del(int x, int y) { v[x].erase(find(v[x].begin(), v[x].end(), y)); v[y].erase(find(v[y].begin(), v[y].end(), x)); } int f[N], rk[N]; lll dfs(int pos, i...
#include <bits/stdc++.h> using namespace std; void solve() { long long x, n; cin >> x >> n; int pp = n % 4; long long z; if (pp == 0) z = 0; else if (pp == 1) z = -n; else if (pp == 2) z = 1; else z = n + 1; long long dre = x % 2 == 0 ? 1 : -1; x += dr...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)(1e5 + 123); vector<int> gg[MAXN], gb[MAXN]; bool was[MAXN], been[MAXN]; int cnt = 0; void dfs(int v) { cnt++; was[v] = been[v] = true; for (auto to : gg[v]) { if (was[to]) continue; dfs(to); } } int main() {...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; string s; cin >> s; char arr[n + 10]; if (n % 2 == 1) { int temp = n / 2; int j = 0; int k = 1; for (int i = 0; i < (int)s.size(); i+...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, a[N], pre[N], suf[N]; char ans[N]; struct Fenwick { int n, c[N]; void init(int _n) { n = _n; memset(c, 0, sizeof(c[0]) * (n + 1)); } void upd(int i, int v) { while (i <= n) { c[i] = max(c[i], ...
#include <bits/stdc++.h> using namespace std; struct po { int x, id, st; } a[444444]; int n, m, i, j, x, y, t, k, ans[111111], id; bool cmp(po a, po b) { if (a.x == b.x) { return a.st < b.st; } return a.x < b.x; } int main() { cin >> n >> m; for (i = 1; i <= n; i++) { s...
#include <bits/stdc++.h> using namespace std; vector<int> fac; void solve() { long long int n, s, c = 0; cin >> n; vector<long long int> a, o; for (long long int i = 0; i < n; i++) { cin >> s; a.push_back(s); } for (long long int i = 0; i < n; i++) { cin >> s; o.pus...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<vector<int> > adj(n, vector<int>(n, 0)); set<int> s; int x; for (int i = 2; i < n + 1; i++) { cin >> x; adj[x - 1][i - 1] = 1; s.inser...
#include <bits/stdc++.h> using namespace std; int main() { long long b, d, s, res = 0; cin >> b; cin >> d; cin >> s; long long val = max(b, max(d, s)) - 1; if (val > b) res += val - b; if (val > d) res += val - d; if (val > s) res += val - s; cout << res; }
#include <bits/stdc++.h> using namespace std; struct node { bool flag; vector<int> op; }; map<string, node> def; map<char, int> op; void del_space(string tmp) { int x = tmp.find_first_not_of( ); tmp.erase(0, x); x = tmp.find_last_not_of( ); tmp.erase(x + 1, tmp.length()); str...
#include <bits/stdc++.h> using namespace std; long long ans = 0; int n, m, x, y; int main() { while (scanf( %d%d%d%d , &n, &x, &m, &y) == 4) { if (x > y) { n ^= m ^= n ^= m; x ^= y ^= x ^= y; } ans = n + 1; int l, r; for (int i = 1; i <= m; ++i) { l = y ...
#include <bits/stdc++.h> using namespace std; long long paw[30]; void pw() { paw[0] = 1; for (int i = 1; i < 20; i++) paw[i] = 10 * paw[i - 1]; } long long rev(long long a) { long long ret = 0; vector<int> v; while (a > 0) { v.push_back(a % 10); a /= 10; } for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int count = 0, k = 0, res = 0; string s; cin >> s; for (int i = 0; i < s.length(); i++) { count = count + (s[i] - 0 ); } for (int i = 0; i < s.length(); i++) { i...
#include <bits/stdc++.h> using namespace std; int main() { int xp, nb; cin >> xp >> nb; cout << min(xp, min(nb, (xp + nb) / 3)); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n, c[N][N]; struct node { int v, pos; } a[N]; inline bool cmp(node x, node y) { return x.v > y.v; } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , &a[i].v), a[i].pos = i; sort(a + 1, a + n + 1, cm...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:33554432 ) using namespace std; int P[1 << 18]; int B[1 << 18]; int C[1 << 18]; int S[1 << 18]; long long R[1 << 18]; vector<pair<int, int> > E[1 << 18]; int gMark, gS; int Parent(int a) { if (P[a] == a) return a; return P[a] = Parent(...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; vector<long long> v; void lucky(long long x) { queue<long long> q; q.push(x); while (x < 1e9) { x = q.front(); q.pop(); x *= 10; q.push(x + 4); q.push(x + 7); v.push_back(x + 4); v.push...
#include <bits/stdc++.h> using namespace std; void pairsort(long long a[], long long b[], long long n) { pair<long long, long long> pairt[n]; for (long long i = 0; i < n; i++) { pairt[i].first = a[i]; pairt[i].second = b[i]; } sort(pairt, pairt + n); for (long long i = 0; i < n; i++)...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000LL * 1000 * 1000 + 7; const int INF = 1000 * 1000 * 1000; const long long base = 1e18; const int MAXN = 600000; const double EPS = 1e-9; const double PI = acos(-1.); long long binPow(long long a, long long x) { long long res = 1...
#include <bits/stdc++.h> using namespace std; int t, s, p; int main() { scanf( %d %d %d , &t, &s, &p); int l = t; int x1 = 0, x2 = s; int co = 1; while (x1 < l) { x1 = x1 + p; x2 = x2 + p - 1; if (x1 >= l && x2 >= l) break; else if (x1 >= x2) { x1 = 0; ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int u, v; cin >> u >> v; if (u > v) printf( NO n ); else if (u == v) ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long m, n; cin >> m >> n; long ar[n], br[n]; for (int i = 0; i < n; i++) { cin >> ar[i] >> br[i]; } int tmp; for (int i = 0; i < n; i++) { for (int j = 0; j < n...
#include <bits/stdc++.h> using namespace std; int n; int inp[200200]; int sum[200200]; char str[200200]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d , &inp[i]); scanf( %s , str); int len = strlen(str); reverse(inp, inp + n); reverse(str, str + len); sum[n]...