func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int t[35], mp[400][400], n; void dfs(int step, int x, int y, int dir) { if (step > n) return; if (dir == 0) { dfs(step + 1, x, y + t[step], 1 - dir); for (int i = 0; i < 400; i++) for (int j = 0; j < 400; j++) if (mp[i][j]) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000000; char a[MAXN + 10], b[MAXN + 10]; int main(void) { int n; scanf( %d%s%s , &n, a, b); int cnt[2][2]; for (int i = 0; i < (2); ++i) { for (int j = 0; j < (2); ++j) { cnt[i][j] = 0; } } n *= 2; fo...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, X, Y, Z, p; int x, y; while (scanf( %d%d%d%d%d%d , &n, &m, &X, &Y, &Z, &p) != EOF) { X %= 4; Y %= 2; Z %= 4; int tn = n; int tm = m; for (int i = 1; i <= p; i++) { n = tn; m = tm; ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int INF = 1e9 + 7; const int N = 4e5 + 7; const int M = 5e6 + 7; int vis[M]; int p[N]; int qt[N]; signed main() { ios::sync_with_stdio(false); int q, x, y; cin >> q >> x; set<pair<int, int>> vals; for (int ...
#include <bits/stdc++.h> using namespace std; int main() { double n, m; cin >> n >> m; printf( %.10lf n , n * pow(1.000000011, m)); return 0; }
#include <bits/stdc++.h> using namespace std; int n, x, l[60], r[60], ans; int main() { scanf( %d %d , &n, &x); for (int i = 1; i <= n; ++i) { scanf( %d %d , &l[i], &r[i]); } for (int i = 1; i <= n; ++i) { ans += (l[i] - r[i - 1] - 1) % x; ans += r[i] - l[i] + 1; } printf...
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 7, Mod = 1000000000 + 7; inline int Inc(int A, int B) { A += B; return A >= Mod ? A - Mod : A; } inline int Dec(int A, int B) { A -= B; return A < 0 ? A + Mod : A; } int n, m, A, B, Dpd[N][N], Dpr[N][N], Sumd[N][N], Sumr[N]...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) const long long INF = 1e9; const long long mod = 1e9 + 7; const long long LINF = 1e14; using namespace std; long long n, l; vector<long long> c; vector<int> b; int main() { std::ios::sync_with_stdio(false); cin >> n >> l; ...
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; int k = x % 4; if (k == 1) { cout << 0 << A << endl; } else if (k == 0) { cout << 1 << A << endl; } else if (k == 2) { cout << 1 << B << endl; } else { cout << 2 << A << endl; ...
#include <bits/stdc++.h> using namespace std; char arr[50][50]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { if ((i % 2 == 0 || ((i % 4 == 1 && j == m - 1) || (i % 4 == 3 && j == 0)))) arr[i][j] = # ; else...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } struct UnionFindTree { vector<long long> par, sz; UnionFindTree(long lon...
#include <bits/stdc++.h> using namespace std; long long int N = 100000, M = 100000; long long int MOD = 1000000007; void solve() { long long int n; cin >> n; long long int a[n + 1], b[n + 1]; for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = 0; i < n; i++) { b[i...
#include <bits/stdc++.h> using namespace std; int k, m; set<int> S; int pw[10]; void rec(int ind, int number, int value) { if (ind == 4) { if (value > k && value - k < 10000) { S.insert(number * 10000 + (value - k)); } if (k >= value && k - value < 10000) { S.insert(numbe...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; int main() { int cases; scanf( %d , &cases); while (cases--) { char str[1009]; int ret[9]; scanf( %s , str); int num = 0; int i; int cnt = 0; int flag = -1; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, r, mn, mx, x, cnt = 0, a = 1, b = 1; string s; cin >> n; for (i = 0; i < n; i++) { cin >> s; if (s == UR || s == DL ) a++; else if (s == UL || s == DR ) b++; else { a++...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; int n; pair<int, int> p[25]; int dis[25][25]; int dp[1 << 24 | 1]; int pre[1 << 24 | 1]; int main() { scanf( %d%d%d , &p[0].first, &p[0].second, &n); for (int i = 1; i <= n; ++i) { scanf( %d%d , &p[i].first, &p[i].second); ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1000001; long long n, l[MAXN], r[MAXN], id[MAXN], K; bool cmp(long long i, long long j) { return (l[i] / K == l[j] / K) ? ((l[i] / K & 1) ? (r[i] < r[j]) : (r[i] > r[j])) : (l[i] < l[j]); } int main() { ...
#include <bits/stdc++.h> using namespace std; const long long neutral = 0; class SegmentTree { vector<long long> a; int n; public: SegmentTree(long long* st, long long* en) { int sz = int(en - st); for (n = 1; n < sz; n <<= 1) ; a.assign(n << 1, neutral); for (int...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9; const long long INF = 1e15; template <class o> void qr(o& x) { char c = getchar(); x = 0; int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } ...
#include <bits/stdc++.h> template <class T> class _Fenwick { private: std::vector<T> sum; int _size; public: _Fenwick() { _size = 0; } void reset(int n) { _size = n; sum.clear(); sum.resize(n + 1); } void add(int x, T y) { while (x <= _size) { sum[x] ...
#include <bits/stdc++.h> using namespace std; int num[400005]; int tot = 0; set<int> st; int mp[20]; int freq[20]; long long push[20][20]; long long addp[20][1048576]; vector<int> pos[20]; long long sum[20]; int cnt[20]; long long memo[1048576]; long long cost(int mask, int ofst, int id) { ...
#include <bits/stdc++.h> using namespace std; vector<int> adj[200010]; long long int ans = 0LL; int odd = 0, sz[200010] = {}; void dfs(int cur, int par = -1, int ht = 0) { sz[cur]++; for (int u : adj[cur]) { if (u == par) continue; dfs(u, cur, ht ^ 1); sz[cur] += sz[u]; } if ...
#include <bits/stdc++.h> using namespace std; vector<int> adj[300003]; vector<int> adje[300003]; int d[300003]; int pickd[300003]; bool vis[300003]; int n, m; int x; int dfs1(int u) { int ans = 0; if (d[u] == -1) x = u; else if (d[u] == 1) ++ans; vis[u] = true; for (int...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { char ch = getchar(); x = 0; while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); } int n, m, mx, now, a[5200]; signed main() { read(n), read(m); int tmp = 0; for (int ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 5e3 + 10; vector<double> vd; int flag = 0; vector<int> check(double x, int sz) { vector<int> v; int cur = 0; double tot = x; while (v.size() < sz) { int o = tot / 10; cur += o; v.push...
#include <bits/stdc++.h> using namespace std; long long p[11]; int main() { string s; cin >> s; int n = s.size(); p[0] = 1; for (int i = 1; i < n; i++) p[i] = p[i - 1] * 9ll; long long ans = 1ll; for (char c : s) ans *= (long long)(c - 0 ); ans = max(ans, p[n - 1]); long long ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a; cin >> a; int sum = 0; char b[3] = { R , G , B }; for (int i = 1; i < n; i++) { if (a[i - 1] == a[i] && a[i] == a[i + 1]) { for (int j = 0; j < 3; j++) { if (b[j] != a[i]) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long r, i; int flag = 1; cin >> r; for (i = 1; i <= 1000000; i++) { if ((r - i * i - i - 1) > 0 && (r - i * i - i - 1) % (2 * i) == 0) { flag = 0; break; } } if (flag == 0) printf( %lld %lld n ,...
#include <bits/stdc++.h> using namespace std; int distance(int x1, int y1, int x2, int y2) { return (int)ceil(sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, x, q, cnt = 0; string t; char ch; map<char, vector<pa...
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; int maxP = 0; int maxQ = 0; for (int i = 0; i < k; i++) { int p = 0; int q = 0; cin >> p; cin >> q; if (p < q) { cout << Happy Alex << endl; return 0; } } cou...
#include <bits/stdc++.h> const int maxn = 4e5 + 10; const int maxm = 2e5 + 10; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const double eps = 1e-7; using namespace std; long long cnt[25][25], dp[1 << 21]; int n; vector<int> col[25]; int main() { ios::sync_with_stdio(false); ci...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long v; cin >> v; f...
#include <bits/stdc++.h> using namespace std; bool check(string new_l, string old_l) { int len_1; int col_izm; col_izm = 0; len_1 = new_l.length(); if (len_1 == old_l.length()) { for (int i = 0; i < len_1; i++) { if (new_l[i] == old_l[i]) { col_izm++; } else if ((...
#include <bits/stdc++.h> int cmp(const void *a, const void *b) { return *((int *)a) - *((int *)b); } int maximum(int a, int b) { if (a > b) { return a; } else { return b; } } int minimum(int a, int b) { if (a < b) { return a; } else { return b; } } int main() ...
#include <bits/stdc++.h> using namespace std; const int N = 5100; char Map[N][N]; int dp[N][N]; int main() { int i, j; int line, row; scanf( %d%d , &line, &row); for (i = 0; i < line; i++) scanf( %s , Map[i]); for (i = 0; i < line; i++) { for (j = row - 1; j >= 0; j--) { if (...
#include <bits/stdc++.h> using namespace std; long long s[1000005]; int main(void) { int n, d, ans = 0; cin >> n >> d >> s[1]; for (int i = 2; i <= n; ++i) { cin >> s[i]; int cnt = 0; if (s[i] <= s[i - 1]) cnt = (s[i - 1] - s[i] + d) / d; s[i] += cnt * d; ans += cnt; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx ) using namespace std; const double eps = 0.000001; const long double pi = acos(-1); const int maxn = 1e7 + 9; const int mod = 1e9 + 7; const long long MOD = 1e18 + 9; const long long INF ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; regex w( WUB ); cout << regex_replace(s, w, ); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long n, m, i, j; char x[2], y[2], t; cin >> n >> m; cin >> x[0]; for (i = 2; i < n; i++) cin >> t; cin >> x[1] >> y[0]; y[0] = (y[0] == ^ ) ? > : < ; for (j = 2; j < m; j++) cin >> t; cin >> y[1]; y[1] = (y[1] == ...
#include <bits/stdc++.h> using namespace std; long long MOD = int(1e9) + 7; int debug = 0; const int N = int(2e3) + 5; using namespace std; int a[N], b[N], p[N]; int main() { int i, j, n, t; ios::sync_with_stdio(false); cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3079; int r, c, n, k; vector<int> nx(maxn, -1), pv(maxn, -1), kth(maxn, -1); vector<vector<int> > my(maxn); class point { public: int x, y; }; bool cmp(point& a, point& b) { return (a.y == b.y ? a.x < b.x : a.y < b.y); } vector<poin...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 233; const int INF = numeric_limits<int>::max(); void read(int &x) { x = 0; char ch = getchar(); int f = 1; while (!isdigit(ch)) (ch == - ? f = -1 : 0), ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar...
#include <bits/stdc++.h> using namespace std; int n, k; int y; vector<pair<int, int> > p[3]; int dp[111][111][3]; bool check(int x, int t, int y) { for (int i = 0; i < p[y].size(); i++) { if (x >= p[y][i].first - 2 * t && x <= p[y][i].second - 2 * t) return false; } return true; } int ...
#include <bits/stdc++.h> using namespace std; namespace IO { const int sz = 1 << 15; char inbuf[sz], outbuf[sz]; char *pinbuf = inbuf + sz; char *poutbuf = outbuf; inline char _getchar() { if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf; return *(pinbuf++); } inline void _...
#include <bits/stdc++.h> using namespace std; template <typename T> std::ostream &operator<<(std::ostream &out, vector<T> &v) { for (typename vector<T>::size_type i = 0; i < v.size(); ++i) out << v[i] << ; out << n ; return out; } template <typename T> std::ostream &operator<<(std::os...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; struct node { int n; int i; node(int n, int i) : n(n), i(i) {} node() {} bool operator<(const node& n1) const { return n < n1.n; } bool is_happy() const { int a = n; while (a) { if (a % 10 != 7 && a ...
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; int qpow(long long a, long long b) { long long c = 1; while (b) { if (b & 1) c = c * a % Mod; if (b >>= 1) a = a * a % Mod; } return c; } int n; long long a; int p, q; int main() { scanf( %d , &n); ...
#include <bits/stdc++.h> using namespace std; long long int dx[4] = {-1, 0, 0, +1}; long long int dy[4] = {0, -1, +1, 0}; const long long int LINF = 1e18; const long long int INF = 1e9; const long long int mod = 1e9 + 7; long long int power(long long int a, long long int b, long long int m) { if (b ==...
#include <bits/stdc++.h> using namespace std; int n, a[105], b[105], c[105], tot, ans; char s[105]; int main() { scanf( %d , &n); scanf( %s , s + 1); for (int i = 1; i <= n; i++) { scanf( %d%d , &a[i], &b[i]); c[i] = s[i] - 0 ; if (c[i] == 1) tot++; } ans = tot; for (i...
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const int oo = 0x3f3f3f3f; template <typename T> inline void rd(T &x) { x = 0; int f = 1; char CH = getchar(); while (!isdigit(CH)) { if (CH == - ) f = 0; CH = getchar(); } while (isdigit(CH)) { ...
#include <bits/stdc++.h> const int MAXN = 100; char s[MAXN + 5]; int main() { int n, p, q; scanf( %d%d%d , &n, &p, &q); scanf( %s , s); for (int i = 0; p * i <= n; i++) { if ((n - p * i) % q == 0) { int j = (n - p * i) / q; printf( %d n , i + j); int pos = 0; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = 1; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (f) x = -x; } long long T, n, m, k; i...
#include <bits/stdc++.h> using namespace std; const int mxn(3e5 + 10), mxm(4e5 + 10); const long long modl(998244353); int nm, n, m, p, t, k; int ans; int a[mxn], b[mxn], c[mxn]; int main() { ios_base::sync_with_stdio(false); cin >> nm; while (cin >> n >> m) { ans = max(0, n + m - 3) / m...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 27; vector<vector<int>> g; int t, tin[N], tout[N], up[N][20], sz[N], d[N]; void dfs(int v, int p = 0, int dp = 0) { tin[v] = t++; d[v] = dp; sz[v] = 1; up[v][0] = p; for (int i = 1; i < 20; i++) up[v][i] = up[up[v][i - 1]][i...
#include <bits/stdc++.h> using namespace std; string s; int l, t, c, a; bool vis[26]; bool ok = false; int main() { cin >> s; l = s.size(); if (l < 26) { cout << -1 << endl; return 0; } for (int i = 0; i < l; ++i) { memset(vis, 0, sizeof vis); t = c = 0; for...
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); long long k; cin >> k; long long second = 2000 + k; long long ar[2000]; ar[0] = -1; for (long long int i = 1; i < 2000; i++) { if (second <= 1000000) { ar[i] = sec...
#include <bits/stdc++.h> using namespace std; vector<long long> blame(1002, 0); vector<bool> visited(1002, false); long long dfs(long long u) { if (visited[u]) return u; visited[u] = true; return dfs(blame[u]); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);...
#include <bits/stdc++.h> using namespace std; long long g; void ex_gcd(long long a, long long b, long long& x, long long& y) { if (!b) { g = a; x = 1, y = 0; } else { ex_gcd(b, a % b, y, x); y = y - a / b * x; } } int main() { long long a, b, c; scanf( %lld%lld%lld ...
#include <bits/stdc++.h> using namespace std; int n, m, x[300300], y[300300]; vector<int> graph[300300]; int counter, dfs_num[300300], dfs_low[300300], dfs_parent[300300]; vector<pair<int, int> > bs; void bridges(int u) { dfs_low[u] = dfs_num[u] = counter++; for (int v : graph[u]) { if (!dfs_n...
#include <bits/stdc++.h> using namespace std; int A[100005], D[100005], n, m, w, L[100005]; bool go(int h) { fill(L, L + n, 0); for (int i = 0; i < n; ++i) D[i] = max(h - A[i], 0); int pow = 0, cap = m, d; for (int i = 0; i < n; ++i) { pow -= L[i]; d = max(D[i] - pow, 0); if (d >...
#include <bits/stdc++.h> int main(void) { int t, n, d; scanf( %d , &t); while (t--) { scanf( %d %d , &n, &d); int i = 0; int flag = 1; while (i < n) { int te = d / (i + 1); te = te * (i + 1) == d ? te : te + 1; if (i + te <= n) { printf( YES n ); ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m1 = 0, m2 = 0; cin >> n; vector<vector<long long> > m(n, vector<long long>(n)); vector<int> a(n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> ...
#include <bits/stdc++.h> const long long maxm = 1e5 + 100; long long n, m; struct node { long long col[maxm * 4], tag[maxm * 4], sum[maxm * 4], siz[maxm * 4]; inline void pushup(long long o) { sum[o] = sum[(o << 1)] + sum[(o << 1) | 1]; col[o] = col[(o << 1)] == col[(o << 1) | 1] ? col[(o << 1...
#include <bits/stdc++.h> template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) { std::cout << name << = << arg1 << std::endl; } template <typename Arg1, typename... Args> void ZZ(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); std::cout.w...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 4; int n, m, a, b, ay[N], by[N], l[N], linkY[N << 1]; void read() { cin >> n >> m >> a >> b; for (int i = 1; i <= n; ++i) { cin >> ay[i]; } for (int i = 1; i <= m; ++i) { cin >> by[i]; } for (int i = 1; i <= m;...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops ) #pragma GCC target( avx,avx2,sse,sse2 ) using namespace std; using vi = vector<long long>; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); long long powmod(long long a, long long b, long long mod) { if (b == 0 || a ...
#include <bits/stdc++.h> using namespace std; int main() { long double n; cin >> n; long long m = sqrt(n); if (m * m == n) { cout << 2 * m; } else if ((long long)m * (long long)(m + 1) >= n) { cout << (long long)m + (long long)(m + 1); } else cout << (long long)2 * (long lo...
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, oo = 0, oz = 0, zo = 0, zz = 0; char s1[2000005], s2[2000005]; cin >> t; cin >> s1; cin >> s2; t = 2 * t; for (i = 0; i < t; i++) { if (s1[i] == 1 && s2[i] == 1 ) oo++; else if (s1[i] ==...
#include <bits/stdc++.h> using namespace std; int n, m, l, r, q; map<pair<int, int>, int> vi; int V[100005 << 2], ly[100005 << 2]; void push_down(int o) { if (ly[o]) { ly[o << 1] |= ly[o]; ly[o << 1 | 1] |= ly[o]; V[o << 1] |= ly[o]; V[o << 1 | 1] |= ly[o]; ly[o] = 0; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n == 1) cout << m; else if (n - m > m - 1 && n - m != 0) cout << m + 1; else cout << m - 1; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int main() { list<int> a; int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); a.push_back(x); } for (auto t = a.begin(); t != a.end(); t++) { auto s = t; s--; ...
#include <bits/stdc++.h> using namespace std; int n, m; int dp[800][800][10]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { int x, y; scanf( %d%d , &x, &y); dp[x][y][1]++; dp[y][x][1]++; } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } template <typename T> void add(T &a, T b) { a += b; if (a < 0) a += MOD; ...
#include <bits/stdc++.h> const bool debug = false; int triple[1 << 12][3]; int use[1 << 12]; int cost[1 << 12]; std::vector<int> gen_masks(int L) { std::vector<int> masks; masks.push_back(0); for (int i = 0; i < L; i++) { for (int j = 1; j < L; j++) { if (i + j * 2 >= L) continue; ...
#include <bits/stdc++.h> using namespace std; int n, k, a[100010], b[100010], c[100010]; void nhap() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d , &c[i]); int dem = 1; a[1] = c[1]; for (int i = 2; i <= n; i++) if (c[i] != a[dem]) { dem++; a[dem] = c[i]...
#include <bits/stdc++.h> using namespace std; int main(void) { long n, m, l, r; vector<long> a(100005); map<long, vector<long> >::iterator mi; vector<long>::iterator vi1, vi2; map<long, vector<long> > hash; scanf( %ld %ld , &n, &m); for (long i = 0; i < n; i++) { scanf( %ld , &a[i]...
#include <bits/stdc++.h> using namespace std; const int __SIZE = 1 << 18; char ibuf[__SIZE], *iS, *iT; template <typename T> inline void read(T &x) { char ch, t = 0; x = 0; while (!isdigit(ch = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n; int mx = 0; for (int i = 0; i < n; i++) { cin >> x >> y; mx = max(mx, (x + y)); } cout << mx << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int arr[n]; int unos = 0; for (int i = 0; i < n; i++) { scanf( %d , &arr[i]); if (arr[i]) unos++; } int fin = 0; for (int i = 0; i < n; i++) { int total = unos; for (int j = i; ...
#include <bits/stdc++.h> using namespace std; unsigned int n, i, f, p, s, rez; int main() { cin >> n; f = 1; for (i = 1; i <= n; i++) f = ((unsigned long long)f * i) % 998244353; f = ((unsigned long long)f * n) % 998244353; p = 1; s = 0; for (i = n; i >= 2; i--) { p = ((unsigned ...
#include <bits/stdc++.h> using namespace std; long long calc_2(int s) { if (s < 0) return 0; return 1LL * (s + 1) * (s + 2) / 2; } long long calc_3(int s) { if (s < 0) return 0; long long ans = 0; for (int i = 0; i <= s; i++) ans += calc_2(s - i); return ans; } int val[5]; int main...
#include <bits/stdc++.h> using namespace std; const int nmax = 26; int cost[nmax][3]; const int l = 0, m = 1, w = 2; map<pair<int, int>, pair<string, int> > myMap; pair<string, long long> global; bool ok = 0; void firstHalf(int a, int b, int c, string s) { if (myMap.count({a - b, b - c}) == 0 || myM...
#include <bits/stdc++.h> using namespace std; int a[10]; int main() { int ans = 0; for (int i = 0; i < 6; i++) scanf( %d , &a[i]); if (a[2] == a[4]) { swap(a[0], a[3]); swap(a[1], a[2]); swap(a[4], a[5]); } for (int i = a[0] + a[0] - 1 + 2, j = 0; j < max(a[1], a[5]); i += 2,...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; long long mn = 1e9, mx = -1e9; long long a[n]; for (int j = 0; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; class IntTree { public: IntTree(int size) : nodes_(4 * size + 10, 0), size_(size) {} void Set(int pos, char ch) { Set(0, 1, size_, pos, ch); } int Count(int left, int right) { int mask = Mask(0, 1, size_, left, right); return CountBits(mask); ...
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 155; int in[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> in[i][j]; } } ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e5 + 9; int n; int mp[9]; bool done[109]; vector<pair<long long, pair<long long, long long> > > v[109]; void dfs(int node) { done[node] = 1; for (int i = 0; i < v[node].size(); i++) { int u = v[node][i].first; int e = v[nod...
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 10; const long long INF = 1e18; int n, q; struct Edge { int u, v; long long w; Edge(int _u = 0, int _v = 0, long long _w = 0) : u(_u), v(_v), w(_w) {} }; vector<Edge> E; int E_size; vector<int> G[N]; int ptr[2 * N]; v...
#include <bits/stdc++.h> using namespace std; vector<long long int> a[100004]; int p[100004]; int v[100004]; long long int c[100004]; struct sajal { long long int add, sub, d; }; sajal d[100004]; int main() { long n; cin >> n; long x, y; for (long i = 1; i < n; i++) { cin >> ...
#include <bits/stdc++.h> using namespace std; int n, m, l, r, x; string s; int main() { cin >> n >> m; r = 0; l = n + 1; for (int i = 0; i < m; ++i) { cin >> s; cin >> s; cin >> s; if (s == left ) { cin >> s >> x; l = min(l, x); } else { cin...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string intial, code; cin >> intial >> code; int res = 0; for (int i = 0; i < n; i++) { int a = (((intial[i] - 0 ) - (code[i] - 0 )) + 10) % 10; int b = (((code[i] - 0 ) - (intial[i] - 0 )) + 10) % 10;...
#include <bits/stdc++.h> using namespace std; int e[100010]; int main() { int n, u, i, j = 3; double ans = 0; scanf( %d%d , &n, &u); for (i = 1; i <= n; i++) scanf( %d , &e[i]); for (i = 1; i <= n; i++) { while (j <= n && e[j] - e[i] <= u) j++; j--; if (j > i + 1) ans = max(a...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int temperature; long long int a12, b11; long long int solution; cin >> a12 >> b11; if (b11 == a12) { solution = 0; } else if (b11 > a12) { te...
#include <bits/stdc++.h> int a[26]; int w[256]; int n; int LIMIT = 1; int su[26], sv[26], sk[26]; int go(int lev) { if (a[lev] == n) { printf( %d n , lev); for (int i = 0; i < lev; i++) if (su[i] == -1) { printf( lea e%cx, [%d*e%cx] n , a + i + 1, 1 << sk[i], a + sv[i])...
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; long long ans = 0; for (int i = 2; i <= n; i++) for (int j = i + i; j <= n; j += i) ans += j / i; cout << ans * 4 << endl; }
#include <bits/stdc++.h> using namespace std; const int64_t INF = INT64_MAX / 4; const int64_t NINF = -INF; map<pair<int64_t, uint32_t>, int64_t> dp; int64_t grundy(int64_t pile, uint32_t pattern) { if (pile == 0) { return 0; } pair<int64_t, uint32_t> key = {pile, pattern}; auto fd = dp....
#include <bits/stdc++.h> using namespace std; long long p, q, b, t, g; long long gcd(long long a, long long b) { if (a < b) swap(a, b); while (b != 0) { a %= b; swap(a, b); } return a; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { ...
#include <bits/stdc++.h> #pragma GCC target( avx ) #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) using namespace std; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { long long A, B, C, D, E, F, N, K, M, Z, sum = 0, num = 0, flag = 0; string S, T; cin >> Z; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int k, n; cin >> n >> k; int x[n]; for (int i = 0; i < n; i++) { cin >> x[i]; } double m = -1, sum = 0; int c = 0; for (int i = 0; i < n; i++) { for (int j = i...
#include <bits/stdc++.h> using namespace std; long long powm(long long base, long long exp, long long mod = 1000000009) { long long ans = 1; while (exp) { if (exp & 1) ans = (ans * base) % mod; exp >>= 1, base = (base * base) % mod; } return ans; } long long ctl(char x, char an = a ...