func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int limB = 1 << 20; const int limN = 20; bool usdA[limB][limN], usdB[limB][limN]; int ansA[limB][limN], ansB[limB][limN]; int ja(int n, int k); int jb(int n, int k); int ja(int n, int k) { if (k == 2) return n; if (usdA[n][k]) return ansA[n][k]...
#include <bits/stdc++.h> int main() { long long n, m, i; scanf( %lld%lld , &n, &m); printf( YES n ); for (i = n; i < m; i += 2) printf( %lld %lld n , i, i + 1); printf( n ); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int ttt; cin >> ttt; for (long long int iq = 0; iq < ttt; ++iq) { long long int n, e = 0; cin >> n; long long int s = n % 10; while (n >= 10) { n ...
#include <bits/stdc++.h> using namespace std; vector<vector<char>> grid; vector<pair<int, int>> wind; int n, m; int k; int t; int w; unordered_map<char, pair<int, int>> charToDir; vector<pair<int, int>> dirs({pair<int, int>(1, 0), pair<int, int>(-1, 0), pair<int, int>(0,...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; long long int n, k; cin >> t; while (t--) { cin >> n >> k; if (n < k * k) { cout << NO << endl; continue; } else { if ((n % 2 == 1 && k % 2 == 1) || (n % 2 == 0 && k % 2 == 0)) ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; int n, m; vector<int> a; bool chk(int c) { int lst = a[0]; if (a[0] + c >= m) lst = 0; for (int ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; bool lt(double a, double b) { return a + eps < b; } bool gt(double a, double b) { return lt(b, a); } bool eq(double a, double b) { return !lt(a, b) && !gt(a, b); } bool lte(double a, double b) { return lt(a, b) || eq(a, b); } bool gte(...
#include <bits/stdc++.h> using namespace std; struct Node { Node() : vis(0), comp(-1) {} int vis; int comp; vector<int> adj; }; vector<int> vis; bool dfs(vector<vector<int> >& a, int u, string& res) { vis[u] = true; for (int i = 0; i < a.size(); i++) { if (i == u) continue; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 9; const int N = 333333; int fib[N][2], fibSum[N][2]; void PreSolve() { fib[1][0] = fib[2][1] = 1; for (int i = 3; i < N; ++i) { for (int j = 0; j < 2; ++j) { fib[i][j] = fib[i - 1][j] + fib[i - 2][j]; if (fib[i]...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch - 0 < 0 || ch - 0 > 9) { if (ch == - ) f = -1; ch = getchar(); } while (ch - 0 >= 0 && ch - 0 <= 9) { x = x * 10 + ch - 0 ; ch = getchar(); } retu...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, h; cin >> n >> m >> h; int a[105][105] = {0}; int x[105] = {0}, y[105] = {0}; for (int i = 1; i <= m; i++) cin >> x[i]; for (int i = 1; i <= n; i++) cin >> y[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <=...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; cout << 6 - n << n ; vector<bool> chk(6, false); for (int i = 0; i < n; i++) { string s; cin >> s; if (s[0] == p ) chk[0] = true; else i...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; const long long M = 1e12; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long long inf = -1e18; int n, arr[5], m; vector<int> vec, verr; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), c...
#include <bits/stdc++.h> int dx[] = {0, -1, 0, 1, -1, 1, -1, 1}; int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1}; const int MOD = 1e9 + 7, N = 2e5 + 5, oo = 2e9; const double pi = acos(-1); using namespace std; long long day[N], h[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
#include <bits/stdc++.h> using namespace std; bool debug = false; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; map<string, int> lesha; vector<int> v; int nxt[500035][16], sz, w[1 << 15][16]; const int maxk = 110; int dp[1 << 15][maxk]; void ii() { for (int s = 0; s < (1 << n); ...
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long INF = 1LL << 60; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; vector<long long> l(n), r(n), m(n); for (long long i = (long long)(0); i < (n); i++) { cin >> m[i]; }...
#include <bits/stdc++.h> const int N = 2e3 + 9; using namespace std; int n, dp[5][N], a[N], b[5] = {0, 1, 2, 1, 2}; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } for (int i = 1; i <= 4; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = max(...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; int hash[201] = {0}; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; v.push_back(mak...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; cin >> n >> m; long long int kmin = 0; long long int kmax = 0; long long int left; kmax = ((n - m + 1) * (n - m)) / 2; long long int j = n / m; left = n % m; kmin = (m - left) * ((j) * (j - 1) / 2) + l...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int row[n * m + 1], col[n * m + 1]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int a; cin >> a; col[a] = j; ...
#include <bits/stdc++.h> using namespace std; int t, tr, br, b, bl, tl; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> t >> tr >> br >> b >> bl >> tl; long long ans = 0; int k = min(tr, tl); ans += (2 * t + k) * ((long long)k); ans += 2 * (max(tr, tl) - k) * (t + k);...
#include <bits/stdc++.h> using namespace std; char str[100100]; int main() { long long n; int q; scanf( %I64d%d , &n, &q); int k = 0; long long tmp = n + 1; while (tmp % 2 == 0) tmp /= 2, k++; while (q--) { long long st; scanf( %I64d , &st); cin >> str; int L = ...
#include <bits/stdc++.h> using namespace std; vector<long long> divisors(long long n) { vector<long long> ans; for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) { ans.push_back(i); if (n / i != i) ans.push_back(n / i); } } ans.push_back(1); return ans; } ...
#include <bits/stdc++.h> using namespace std; int n, m, k; long long num[200005], rig[200005], lef[200005]; int main() { scanf( %d%d%d , &n, &m, &k); long long tmp = 0; for (int i = 1; i <= n; ++i) { scanf( %d , &num[i]); } int t = 1; while (m--) t *= k; for (int i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 2, maxm = 1000 * 1000 + 2; int n, m, q, parent[maxn], r[maxn], b[maxn]; pair<pair<long long, int>, pair<int, int> > v[maxm]; bool chek = false; int par(int x) { if (x == parent[x]) return x; int y = par(parent[x]); b[x] += b[p...
#include <bits/stdc++.h> using namespace std; int n, m, z = 1, k; int main() { cin >> n >> m; if (n > m + 1 || n * 2 + 2 < m) return cout << -1, 0; while (n || m) { if ((m > n && k < 2) || z == 0) m--, z = 1, k++; else n--, z = 0, k = 0; cout << z; } }
#include <bits/stdc++.h> using namespace std; int a, b; vector<int> res; int main() { scanf( %d%d , &a, &b); while (true) { res.push_back(b); if (b == a) break; if (b < a) { printf( NO ); return 0; } if (b % 2 == 0) b /= 2; else if (b % 10 == 1...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, k; cin >> n >> k; multiset<pair<long long, long long>> s; vector<tuple<long long, long long, long long>> v; long long i; for (i = 0; i < n; i++) { long long a, b, p; cin >> a >> b >> p; s.insert({(a...
#include <bits/stdc++.h> using namespace std; const int P = 998244353, N = 3e5; int n, L, C, r[N], A[N], B[N]; int g[N], g0[N], g1[N], g2[N]; int f0[N], f1[N], f2[N]; int q0[N], q1[N]; int t1[N], t2[N], t3[N], t4[N]; inline void Add(int &x, int y) { x += y; if (x >= P) x -= P; } inline int M...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; template <class T, class U> inline void add_self(T &a, U b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } template <class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; } template <class ...
#include <bits/stdc++.h> using namespace std; const char nl = n ; const int MAX_N = 100011; const long long INF = (1 << 29) + 123; const long long MOD = 1000000007; const long double PI = 4 * atan((long double)1); template <typename T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, cnt = 0; scanf( %d %d %d , &n, &m, &k); int p[n], s[n], c[k]; for (int i = 0; i < n; i++) scanf( %d , &p[i]); for (int i = 0; i < n; i++) scanf( %d , &s[i]); for (int i = 0; i < k; i++) scanf( %d , &c[i]); for (int i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int mx = 0; for (int i = 0; i < n; i++) { cin >> a[i]; mx = max(a[i], mx); } int cnt = 0; int maxcnt = 0; for (int i = 0; i < n; i++) { if (a[i] == mx) cnt++; els...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; int max = 0; int cur = 0; cin >> n; string students[n]; for (int i = 0; i < n; ++i) { cin >> students[i]; } for (int i = 0; i < 7; ++i) { cur = 0; for (int j = 0; j < n; ++j) { if (student...
#include <bits/stdc++.h> using namespace std; int rd(); int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); } int J(int x) { int sum = 0; for (int i = 1; i * i <= x; ++i) { if (x % i == 0 && gcd(i, x / i) == 1) { sum += i; sum += x / i; } } return sum; } co...
#include <bits/stdc++.h> using namespace std; const int N = 200010; const long long mod = 1000000007ll; int n, cnt; long long ans = 1; int to[N], vis[N], dep[N]; long long power(long long x, long long t) { long long ret = 1; for (; t; t >>= 1ll, x = x * x % mod) if (t & 1ll) ret = ret * x % ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; if (n == 1) { cout << 0; return 0; } int arr[n + 1]; for (int i = 0; i < n; i++) { cin >> arr[i]; } arr[n] = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 2001; const int INF = 1e9 + 1; struct T { int u, f, w, num; T(int u, int f, int w, int num) : u(u), f(f), w(w), num(num){}; T(){}; }; vector<T> G[N]; int n, m, s, t; bool used[N]; bool ist[N]; int parent[N]; pair<int, pair<int...
#include <bits/stdc++.h> using namespace std; struct edge { int flow; int next; int inv; int cap; int cost; }; const int N = 1100000; vector<edge> v[N]; int d[N]; int phi[N]; int from[N]; bool vis[N]; void add_edge(int x1, int x2, int x3, int x4) { edge x; x.next = x2; ...
#include <bits/stdc++.h> using namespace std; int n; int get(int x) { int t = log2(x); if ((1 << t) < x) t++; return (1 << t) - x; } unordered_map<int, int> to, pos; unordered_map<int, vector<pair<pair<int, int>, int> > > mp; int a[200005]; pair<pair<int, int>, int> num[200005]; int len = ...
#include <bits/stdc++.h> #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; template <class T> using vec = std::vector<T>; bool __hack = std::ios::sync_with_stdio(false); auto __hack1 = cin.tie(nullptr); struct Input { Input(istream &in) : in(&in) {} tem...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) #pragma comment(linker, /STACK:2000000 ) using namespace std; template <int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, Vector dimension must be greater than zero! ); templ...
#include <bits/stdc++.h> int max(int a, int b) { if (a > b) return a; else return b; } int main() { int n, m, p, r, x, y, c, i, j, zb, maxz; int max1, max2, max3, max4, minz; scanf( %d %d , &n, &m); scanf( %d , &c); for (i = 1; i <= c; i++) { scanf( %d %d , &x, &y); ...
#include <bits/stdc++.h> using namespace std; map<int, int> g; vector<vector<pair<long long, int> > > vec; const int MAXN = 100010; pair<long long, int> msum[MAXN][2]; bool cmp2(pair<long long, int> a, pair<long long, int> b) { return b.first < a.first; } int main() { int n, c, s; scanf( %d ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int c[N], ctr[N] = {0}; vector<pair<int, int> > candidates, edges; int main() { int n; cin >> n; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; edges.push_back({u, v}); } for (int i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; string s1, s2; set<char> st; vector<int> t[300]; int bin_search(char k, int ind) { int l = 0, r = t[k].size() - 1, m; while (l < r) { m = (l + r) / 2; if (ind == t[k][m]) return t[k][m]; if (ind < t[k][m]) r = m; else ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 300; int main() { string s; int h; cin >> h; cin >> s; int ans = s.size(); for (int i = 1; s[i]; i++) { if ((s[i] == U && s[i - 1] == R ) || (s[i] == R && s[i - 1] == U )) { s[i] = p ; --ans; ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 300010; vector<long long> arr[MAXN]; vector<pair<long long, long long>> holdqs[MAXN]; bool visited[MAXN]; long long answer[MAXN]; long long temp[MAXN]; long long n; void dfs(long long curr, long long par, long long level, long long a...
#include <bits/stdc++.h> using namespace std; char a[25][25]; int dp[40][1 << 20], n; bool vis[40][1 << 20]; int f(int xx, int st) { if (vis[xx][st]) return dp[xx][st]; int &res = dp[xx][st]; vis[xx][st] = true; if (xx == n * 2 - 2) { res = 0; } else { if (xx & 1) res =...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } const long long MAXN = 500010; const long long Mod ...
#include <bits/stdc++.h> using namespace std; mt19937 Rand(time(0)); const int maxn = 5e2 + 5; const long long maxc = 1e9 + 7; int n, m; vector<int> adj[maxn]; int d[maxn][maxn]; pair<int, int> trace[maxn][maxn]; vector<int> resOne, resN; void bfs() { queue<pair<int, int> > q; q.push(make_pa...
#include <bits/stdc++.h> using namespace std; const int N = 200 + 5; const int LEN = 1e6 + 10; int n, m, q; int a[N]; int b[N]; int f[N][N]; char ch[LEN]; int g[LEN], l; int xt[N * N], yt[N * N]; int dp[N][N]; int cnt, cir[N * N][10]; int lc[N * N]; int c0[N][N]; int bel[N][N]; int nx[N]...
#include <bits/stdc++.h> int b[1010]; double dp[1010][1010]; int main() { int n, m, i, j, x, y; double ans = 0; scanf( %d%d , &n, &m); for (i = 0; i < n; i++) scanf( %d , &b[i]); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (b[i] > b[j]) dp[i][j] = 1; ...
#include <bits/stdc++.h> int m, n, s; int main() { scanf( %d%d , &n, &m); int ans = 0; for (int i = 0; i <= 40; i++) for (int j = 0; j <= 40; j++) { if (i * i + j == n && j * j + i == m) ans++; } printf( %d n , ans); }
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int n; long long x1, x2; struct sss { long long val; int num; } a[maxn]; bool cmp(const sss &a, const sss &b) { return a.val > b.val; } void scanff() { scanf( %d%I64d%I64d , &n, &x1, &x2); for (int i = 1; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; struct state { int i, j, dp, cp; }; int di[] = {0, 1, 0, -1}; int dj[] = {1, 0, -1, 0}; state n[50][50][4][2]; state current; char b[50][51]; int r, c; int moves; void read() { cin >> r >> moves; for (int i = 0; i < r; i++) { cin >> b...
#include <bits/stdc++.h> #pragma GCC optimize Ofast,omit-frame-pointer,inline using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int mx = -INT_MAX; multiset<int> vs; for (int i = 0; i < n; i++) { int x; cin >> x; mx ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int main() { int n, m, t; cin >> n >> m >> t; int total = (n - 2) * (n - 1) / 2 + 1; if (total >= m && m >= n - 1) { m = m - n + 1; int cant = 0; if (t != 1) cant = 1; else cant = n; ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e6; const long long MOD = 1e9 + 7; const long long N = 1e6 + 7; const long long N_N = 1e3; const int INF = 1e9 + 228; const long double eps = 1e-12; long long n, a[N], ans, l, ans1; int main() { cin >> n; for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << { << p.first << , << p.second << } ; return os; } const int N = 2e6 + 5; const int oo = 1e9 + 7; int lp[N + 1]; vector<int> pr; void sieve() { fo...
#include <bits/stdc++.h> using namespace std; int n; const int maxn = 16; char tp[maxn]; int r[maxn], b[maxn]; int dp[1 << maxn][2][16 * 16 * 1]; int inf = (int)(1e9); int go(int msk, int R, int B, int x, int y) { x = min(x, n * n); y = min(y, n * n); if (msk == (1 << n) - 1) return 0; i...
#include <bits/stdc++.h> using namespace std; int solve(int i, int a, int b, int c) { if (i == 0) return a + b + c; if (i == 1) return max((a + b) * c, a + b * c); if (i == 2) return max(a * (b + c), a * b + c); return a * b * c; } int main() { ios::sync_with_stdio(0); cin.tie(0); in...
#include <bits/stdc++.h> using namespace std; int k; string s; vector<string> ans; bool all[26]; int main() { ios_base::sync_with_stdio(0); cin >> k >> s; string build = ; for (int i = 0; i < s.size(); ++i) if (!all[s[i] - a ]) { if (!build.empty()) ans.push_back(build); ...
#include <bits/stdc++.h> using namespace std; static const int mxn = 21; long long n, res; int m; struct Node { long long a; int b; bool operator<(const Node& c) const { return b > c.b; } } nodes[mxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (in...
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ; cerr << endl; } int n; vector<pair<int, int> > g[3005]; pair<int, int> es[3005]; int dfs(int v, int p) { int res = 0; for (in...
#include <bits/stdc++.h> using namespace std; long long a[500005], b[500005], dp[500005], t; vector<long long> c; void poisk_del(long long z) { for (int del = 2; del * del <= z; del++) { if (z % del == 0) c.push_back(del); while (z % del == 0) { z /= del; } } if (z != 1) c....
#include <bits/stdc++.h> using namespace std; int arr[1000000]; map<pair<int, int>, int> mp; int cnt[1000000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; long long ans = 0; for (int i = 0; i < n; i++) { cin >> arr[i + 1]; ans += arr[i + 1]...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:167772160 ) using namespace std; int n, i, j, a, b, x[100001], y[100001], v, k, uns[100001], p, q, w[6]; int findd(int l, int r, int xx) { int t; t = (l + r) / 2; if (l == r) { if (x[l] == xx) return l; else return ...
#include <bits/stdc++.h> using namespace std; int D[1 << 20], cnt[20][20]; bool chk[1 << 20]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ((void)0); ((void)0); ((void)0); int N, M; queue<int> Q; string s; cin >> N >> M >> s; for (int i = 1...
#include <bits/stdc++.h> using namespace std; bool compare(string &s1, string &s2) { return s1.size() < s2.size(); } void solve() { int n; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) cin >> s[i]; sort(s.begin(), s.end(), compare); for (int i = 0; i < n - 1; i++) if (s[...
#include <bits/stdc++.h> using namespace std; long long f[500500], fact[500500]; int C[2222][2222], used[500500], can[500500], a[500500]; int n, t, u; int main() { scanf( %d , &n); for (int i = 0; i <= n; i++) for (int j = 0; j <= i; j++) if ((j == 0) || (j == i)) C[i][j] = 1; ...
#include <bits/stdc++.h> #include <iostream> using namespace std; #define db cout << debugging... n ; #define db1(x) cout << #x << = << x << n #define db2(x, y) cout << #x << = << x << , << #y << = <<y << n #define db3(x, y, z) cout << #x << = << x << , << #y << = << y <<...
#include <bits/stdc++.h> using namespace std; int n; int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; char s[100002]; void Print(long long x) { printf( %lld n , x); exit(0); } bool ok(long long x1, long long y1, long long x2, long long y2, long long day) { return (abs(x2 - x1) + abs(y2 - ...
#include <bits/stdc++.h> using namespace std; int recur_depth = 0; const long long sz = 14, isz = 2e6 + 10, mod = 1e9 + 7; long long p[sz], win[sz][sz], scc[(1 << sz)], n; long long fastPow(long long x, long long n, long long MOD) { long long ret = 1; while (n) { if (n & 1) ret = (ret * x) % MOD...
#include <algorithm> #include <array> #include <bitset> #include <cctype> #include <chrono> #include <cmath> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iso646.h> #include <iterator> #include <list> #include <m...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int l, r; cin >> r >> l; v.push_back(make_pair(l, r)); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); int len = v.size(); ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16000000 ) using namespace std; long long mod = 998244353; long double inf = 1e9; long double eps = 1e-8; long double pi = acos(-1); ifstream in( input.txt ); ofstream out( output.txt ); int main() { ios_base::sync_with_stdio(0); cin.tie...
#include <bits/stdc++.h> using namespace std; const int N = 101010; int a[N]; int b[N]; int c[N]; int n; long long ans; void init() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %1d , a + i); c[i] = a[i]; } for (int i = 1; i <= n; i++) { scanf( %1d , b + i); ...
#include <bits/stdc++.h> using namespace std; const int N = 300010; class cmp { public: bool operator()(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { if (a.first == b.first) return a.second > b.second; return a.first < b.first; ...
#include <bits/stdc++.h> using namespace std; int a[100009], c[100009], b[100009], d[100009]; long long ksm(long long a, long long n, long long d) { long long ans; ans = 1; while (n > 0) { if (n % 2 == 1) ans = (ans * a) % d; a = a * a % d; n = n / 2; } return ans % d; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; long long s1[N], s2[N]; int p, q, n, b[N], d[N]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %I64d , &s1[i]), s1[i] += s1[i - 1]; for (int i = 1; i <= n; i++) scanf( %I64d , &s2[i]), s2[i] += s2[i - 1]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int len = 700, MAX = 1e7 + 10; int n, m, k, a[maxn]; int f[MAX], g[MAX]; long long ans[maxn]; struct query { int l, r, id; } q[maxn]; bool operator<(const query &a, const query &b) { if ((a.l - 1) / len != (b.l - 1)...
#include <bits/stdc++.h> using namespace std; bool G[30][30]; int main() { int T; scanf( %d , &T); while (T--) { int n, p; scanf( %d%d , &n, &p); memset(G, 0, sizeof(G)); for (int i = 0; i < n; ++i) G[i][(i + 1) % n] = G[(i + 1) % n][i] = G[i][(i + 2) % n] = ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, lg = 20, N = 1e5 + 5; int ans[N]; bool vis[N]; vector<pair<int, int> > g[N]; struct node { node *ch[11]; node *sp[lg]; int val, lvl, last; node() { memset(ch, 0, sizeof ch); memset(sp, 0, sizeof sp); val...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma comment(linker, /stack:200000000 ) using namespace std; const int mnx = 3e5 + 9; const int mod = 1e9 + 7; const long long inf = 1e15 + 4; long long binpow(long long a, int n) { long long res = 1; while (n) { if (n & 1) res = (re...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 or c > 9 ) { if (c == - ) f = -f; c = getchar(); } while (c >= 0 and c <= 9 ) { x = x * 10 + c - 0 ; c = getchar(); } return x * f; } struct E...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, count = 0; cin >> n >> m; char x; vector<int> r, c; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> x; if (x == S ) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[11] = {0}, i, maxx, c; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; if (i == 1) maxx = a[1]; else maxx = max(a[i], maxx); } printf( %d , maxx ^ a[n]); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, ans, temp; set<int> st; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; cin >> n >> m; ans = n + m; temp = 2; while (n) { n -= (temp % 6 != 0); st.insert(temp); temp += 2; } temp = 3; ...
#include <bits/stdc++.h> using namespace std; const int p = 1000 * 1000 * 1000 + 7; int main() { int n, m; vector<long long> fact(1000001); fact[0] = 1; for (int i = 1; i < 1000001; i++) fact[i] = (i * fact[i - 1]) % p; cin >> n >> m; vector<pair<int, int>> v(m); for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; string arr[10] = { 0 , 0 , 2 , 3 , 322 , 5 , 53 , 7 , 7222 , 7332 }; int main() { int x; cin >> x; char a[x]; string s; for (int i = 0; i < x; i++) { cin >> a[i]; if (a[i] != 0 && a[i] != 1 ) s += arr[a[i] - 0 ]; } ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, pair<long long, long long> > > edges; vector<long long> wt(100005); long long sz[100005], parent[100005]; long long ans = 0; long long n, m; void make_set() { for (long long i = 1; i <= n; i++) { sz[i] = 1; parent[i] = i;...
#include <bits/stdc++.h> const int P = (1 << 30) - 1; int a, b, c, p[2005], vis[2005]; std::unordered_map<long long, int> mmp[2005]; void sieve(int n) { vis[0] = vis[1] = 1; for (int i = 2; i <= n; ++i) { if (!vis[i]) p[++*p] = i; for (int j = 1; j <= *p && i * p[j] <= n; ++j) { vis[...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast , 3, inline ) using namespace std; string s, t; int n; void pairr() { if (cin >> t) { s += t; if (t == pair ) s += < , pairr(), s += , , pairr(), s += > ; } else { cout << Error occurred ; exit(0); } } int main(...
#include <bits/stdc++.h> using namespace std; string s; int m, ch[1002]; int gt(int bal, int prv, int st) { if (st == m) return ch[st] = 11; if (bal <= 0) { for (int i = 1; i <= 10; i++) { if (i != prv && s[i] == 1 && bal + i > 0) { int t = gt(bal + i, i, st + 1); if ...
#include <bits/stdc++.h> using namespace std; int n, a[10000], m, x, v[10000], sol[10000]; void g(int n) { for (int i = 2; i <= 1000; i++) { for (int q = i; q <= 1000; q++) { if (q % i != 0 && i * q <= 1000) v[i * q] = 1; } } } int main() { int k = 0; cin >> n; g(n); ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; char arr[] = { a , b , c , d , e , f , g , h , i , j , k , l , m , n , o , p , q , r , s , t , u , v , w , x...
#include <bits/stdc++.h> int n, m; int len[(1010)], val[(1010)], mxl[(1010)], cost[(1010)], dp[(1010)][(1010)]; char a[(1010)], b[(1010)][(1010)]; std::pair<int, int> lab[(1010)]; int main() { scanf( %s , a); m = strlen(a); std::reverse(a, m + a); for (int i = m; i < (1002) + 1; ++i) { a...
#include <bits/stdc++.h> using namespace std; long long s[200005], e[200005]; long long win(long long s, long long e) { if (e & 1) { if (s & 1) return 0; return 1; } if (s > e / 2) { if (s & 1) return 1; return 0; } if (s > e / 4) return 1; return win(s, e >> 2); ...
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(0); long long n, m; cin >> n >> m; vector<long long> a, b; vector<long long> sum1, sum2; long long prev = 0; for (int i = 0; i < n; i++) { long long x; cin >> x; prev += x; a.push...