func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100100]; vector<vector<int> > b1; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (n < 3) { cout << 0; return 0; } for (int i = a[1] - 1; i <= a[1] + 1; i++) { for (int j = a[2] - 1...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int N = (int)(2e6 + 20); const int L = 1 << 6; const long long int M = (long long int)(1e9 + 7); const double E = 1e-7; int a[N]; int main() { ios_base::sync_with_stdio(0); long long int n, m; cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2020; vector<int> g[MAXN]; int maxDep = -1; void DFS(int v, int depth) { if (depth > maxDep) maxDep = depth; for (int i = 0; i < g[v].size(); i++) DFS(g[v][i], depth + 1); } int main() { int n, a; cin >> n; for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; bool f[110][110][2][60]; int main() { string str; cin >> str; int n = str.size(); int m; cin >> m; memset(f, 0, sizeof(f)); f[0][0][1][0] = 1; for (int i = 0; i < n; i++) { char ch = str[i]; for (int dist = 0; dist <= n; dis...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int p = n - a[0]; for (int i = 1; i < n; i++) { if (i & 1) { a[i] -= p; a[i] += (n * 1000000); a[i] = a[i] % n; if (a[i] != i) ...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v[1001]; int n, k, r; while (scanf( %d , &n) != EOF) { for (int i = 1; i <= n; i++) { v[i].clear(); scanf( %d , &k); while (k--) { scanf( %d , &r); v[i].push_back(r); } ...
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, i, e, f, g, n, m, k, l, r; long long go(long long x) { k = 1; n = 0; m = 0; for (long long i = 1;; i++) { if (x <= 0) return ((m * (m + 1)) % 1000000007 + (n * n) % 1000000007) % 1000000007; if (i % 2 == 1) { ...
#include <bits/stdc++.h> using namespace std; const int inf = 0; const double eps = 0; const int ms = 0; const int md = 0; const int MAX_N = 1e5 + 5; const int MAX_L = 20; const long long MOD = 1e9 + 7; const long long INF = 1e9 + 7; long long mpow(long long k) { long long ans = 1; while (k ...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int main() { int num, r; cin >> num >> r; vector<pair<int, int>> arr(num + 1); vector<bool> visited(r + 2, 0); for (int i = 1; i <= num; ++i) { cin >> arr[i].first >> arr[i].second; for (int j = arr[i].first; j <=...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mod1 = 998244353; const double pie = 3.1415926535; long long power(long long x, long long y) { if (y == 0) return 1; else { if (y % 2 == 0) return power(x * x, y / 2); else re...
#include <bits/stdc++.h> using namespace std; const int N = 100012, H = 20; vector<int> e[N], g[N]; stack<int> Z; int n, m, tot, tim, low[N], rea[N], f[N], d[N]; int fa[N][H], k; bool v[N]; void dfs(int fa, int now) { low[now] = rea[now] = tim++; v[now] = true; Z.push(now); int top = int...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; vector<vector<int>> g(N); bool isDeleted[N]; vector<int> res; void del(int s, int p) { res.push_back(s); isDeleted[s] = true; for (auto I : g[s]) { if (!isDeleted[I] && I != p) { del(I, s); } } } bool df...
#include <bits/stdc++.h> using namespace std; int main() { long long sum = 0; string s; cin >> s; s += a ; int now_number = 0, buf_number = 0, size_buf = 0, point = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] >= a && s[i] <= z ) { now_number = now_number * pow(10, size...
#include <bits/stdc++.h> using namespace std; const int maxn = 1024; int n; int a[maxn], b[maxn], c[maxn]; vector<int> g[maxn]; vector<pair<pair<int, int>, int> > ans; void add(int v, int u, int x) { ans.push_back({{v, u}, x}); } int gfs(int v, int par, int d) { if (g[v].size() == 1) return v; f...
#include <bits/stdc++.h> using namespace std; int main() { puts( INTERCAL ); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int t = 0, ans = 100000, a; for (int i = (0); i < (n); ++i) if (s[i] == T ) t++; for (int i = (0); i < (n); ++i) { a = 0; for (int j = (i); j < (i + t); ++j) { if (s...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; cin >> a[0]; int count = a[0]; int max = a[0]; for (int i = 1; i < n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { count = count + a[i] - a[i - 1]; if (max < count) max ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, M = 5; int cc[N][M], sz[N], k; long long ret[N], sum = 0; vector<int> adj[N]; long long dfs(int x, int p) { int t, v, j, u, i; sz[x] = 1; long long R = 0, temp; for (i = 0; i < adj[x].size(); ++i) { u = adj[x][i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0; for (int i = 0; i < n; i++) { int c; cin >> c; sum = sum + c; } n = n + 1; int count = 0; for (int j = 1; j <= 5; j++) { int flag = 0; int s = sum + j; if (s %...
#include <bits/stdc++.h> using namespace std; vector<long long> v; long long n, m, w, ai; long long cnt[300005]; bool go(long long mx) { memset(cnt, 0, sizeof cnt); long long use = m; long long add = 0; for (int i = 0; i < n; i++) { add += cnt[i]; long long curr = v[i] + add; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 200; int num[MAX], vis[MAX]; int main() { int n, m, a; while (scanf( %d %d , &n, &m) == 2) { memset(vis, 0, sizeof(vis)); for (int i = 0; i < m; i++) { scanf( %d , &a); for (int i = a; i <= n; i++) if (!v...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, inf = 9e8; int n, a[N]; array<int, 3> vals[N]; void compress(int arr[]) { vector<int> all; for (int i = 1; i <= n; i++) all.push_back(arr[i]); sort(all.begin(), all.end()); for (int i = 1; i <= n; i++) arr[i] = lower_bo...
#include <bits/stdc++.h> using namespace std; int mod = 1000000007; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int prime(long long int n) { long long int i; for (i = 2; i <= sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } lo...
#include <bits/stdc++.h> using namespace std; bool viz[105][105]; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int main() { cin.tie(0)->sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int T = 1; while (T--) { int n, m, x, y; cin >> n >> m >> x >> y; vector<pai...
#include <bits/stdc++.h> using namespace std; int main() { ; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { long long a, b, c; cin >> a >> b >> c; long long cnt = 0; while (1) { if (a > c || b > c) break; if ...
#include <bits/stdc++.h> using namespace std; const int N = 21, mod = 998244353; long long f[32][N][N][N][N][2][2], ans, lim; int n, m, x[7], y[7], pa, pb, pc, pd; int main() { scanf( %d%d , &n, &m), ******* f = 1, lim = (1 << n) - 1; for (int i = 1, ie = n; i <= ie; i++) scanf( %d%d , &x[i], &y...
#include <bits/stdc++.h> using namespace std; char s[200]; vector<pair<int, int> > v; int main() { scanf( %s , s); int len = strlen(s); pair<int, int> cur(0, 0); v.push_back(cur); for (int i = 0; i < len; i++) { if (s[i] == L ) { cur.first--; } else if (s[i] == R ) { ...
#include <bits/stdc++.h> using namespace std; const int MaxN = 100005; long long A[MaxN][(1 << (5))], B[MaxN][(1 << (5))], dp[MaxN][(1 << (5))]; const long long Inf = 1LL << 60; int main() { int N, M; scanf( %d%d , &N, &M); for (int i = 0; i < M - 1; i++) for (int j = 0; j < N; j++) { ...
#include <bits/stdc++.h> using namespace std; int n, cnt, a[2010], b[2010], bel[2010], ans[2010 * 2010 / 2][2]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) { scanf( %d , &b[i]); bel[b[i]] = i; } for (int i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; int main() { int n, page; cin >> n; vector<int> pages(7); for (int i = 0; i < 7; i++) { cin >> page; pages[i] = page; } int ans = 0; while (true) { n -= pages[ans]; if (n <= 0) { break; } ans = (ans...
#include <bits/stdc++.h> using namespace std; int n, q; int C[500001]; vector<pair<int, int> > P[500001]; int ans[500001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> C[i]; cin >> q; for (int i = 0; i < q; ++i) { int l, r...
#include <bits/stdc++.h> using namespace std; const int OO = 1e9; const double EPS = 1e-9; template <class T> void _db(const char* dbStr, T e) { cout << dbStr << = << e << endl; } template <class T, class... L> void _db(const char* dbStr, T e, L... r) { while (*dbStr != , ) cout << *dbStr++...
#include <bits/stdc++.h> using namespace std; long long xorsum[(1L << 16)]; long long deg[(1L << 16)]; int main(void) { long long n; cin >> n; queue<long long> q; long long td = 0; for (long long i = 0; i < n; i++) { cin >> deg[i] >> xorsum[i]; if (deg[i] == 1) { q.push(i...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e6 + 5; const int INF = (int)1e9 + 7; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int a, b, c, d; cin >> a >> b >> c >> d; if (a + b == c + d or a + c == b + d or a + d == c + b or...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); bool ok = false; for (int i = 0; i < n - 1; i++) { if (s[i] == A && s[i + 1] == B ) { for (int j = i + 2; j < n - 1; j++) { if (s[j] == B && s[j + 1] == A ) { ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long fpow(long long n, long long k, int p = ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e12 + 1, maxn = 2 * (1e5 + 5), mod = 1e9 + 7; const double eps = 1e-9; long long m, i, j, k, n, answer, t, l, r; string s; bool f(long long l0, long long r0, long long i0) { if (r0 - i0 + 1 < i0 - l0) { return 1; } if (r0...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const int mod = 1e9 + 7; const int N = 1e6 + 10; const long long INF = 1e18; long long power(long long x, long long y) { long long t = 1; while (y > 0) { if (y % 2) y -= 1, t = t * x % mod; else y /= 2...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n, m; int k[200010]; int rem[200010]; int idx[200010]; vector<int> special[200010]; vector<int> days[200010]; bool pos(const long long M) { long long coins = 0; memset(idx, 0, sizeof(idx)); for (int i = 0; i < n; i++) r...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:200000000 ) using namespace std; const int INF = (int)1E8; const long long INF64 = (long long)1E18; const double EPS = 1E-9; const double PI = acos((double)0) * 2; const int MAXN = 160; int n, cost[MAXN]; string s; bool read() { if (!(cin ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (b) { int tmp = a % b; a = b; b = tmp; } return a; } int main() { int a, b; cin >> a >> b; int k = gcd(a, b); if (abs(a / k - b / k) <= 1) cout << Equal n ; else if (a < b) ...
#include <bits/stdc++.h> using namespace std; long long const M = 1000000007; double const pi = acos(-1); long long const inf = 2e18; long long const N = 200001; long long comb(long long n) { if (n <= 0) return 0; return (n * (n - 1)) / 2; } int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; int n, m; long long int a[1004][1004]; long long int b[1005]; long long int c[1005]; long long int ci, cj; int main() { long long int i, j; scanf( %d %d , &n, &m); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf( %I64d , &a[i][j]); ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int mod = 1e9 + 7; long long int powmod(long long int a, long long int b) { long long int res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } re...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using tpl = tuple<int, int, int>; using pcc = pair<char, char>; const ll inf = 2e18; const ll mod = 1e9 + 7; int dr[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2}; ...
#include <bits/stdc++.h> using namespace std; int main() { int w, h; cin >> w >> h; int u1, d1, u2, d2; cin >> u1 >> d1 >> u2 >> d2; for (int i = h; i >= 0; i--) { w = w + i; if (i == d1 || i == d2) { if (i == d1) { w = w - u1; if (w < 0) { w =...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int N = 2 * maxn; int n, m, a[maxn]; int v[N]; void jl(int x) { for (int i = x; i < N; i += i & -i) { v[i]++; } } long long s(int x) { long long sum = 0; for (int i = x; i > 0; i -= i & -i) { sum +=...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; const int maxn = 1001000; const int mod = 1000000007; int a[maxn], f[maxn], r[maxn]; int main() { int n; scanf( %d , &n); for (int e = 1; e <= n; e++) scanf( %d , a + e); auto mul = [](int x...
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795; long long int inp() { long long int n = 0, s = 1; char c; for (c = getchar(); c < 48 || c > 58; c = getchar()) if (c == - ) s = -1; for (; c > 47 && c < 59; c = getchar()) n = n * 10 + c ...
#include <bits/stdc++.h> using namespace std; const int N = 1000100; const int M = 20; vector<int> g[N]; vector<int> gr[N]; vector<int> ord; int sp[N][M]; int tin[N]; int tout[N]; int timer; void pre_dfs(int v, int p = -1) { sp[v][0] = (p == -1 ? v : p); for (int i = 1; i < M; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s, i, l = 0, k = 0, j = 0, t = 0, p = 0, max = 0; cin >> n; int a[n]; for (i = 0; i < n; i++) { k++; cin >> a[i]; if (a[i] == 1) { l++; } if (a[i] == 2) { j++; } if (a[i] ==...
#include <bits/stdc++.h> using namespace std; int a, b, n; long long mod = 1000000007; vector<long long> factorial(1000005); bool excellent(long long z) { while (z != 0) { if (z % 10 != a && z % 10 != b) return false; z /= 10; } return true; } long long pow(long long a, long long p...
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; struct line { int a, b; line() {} line(int a, int b) : a(a), b(b) {} bool operator<(const line& o) const { return a < o.a; } friend line operator+(const line& first, const line& second) { if (second < first) return se...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; const int N = 4000090, M = 1000000007; int t[N]; void add(int x, int l, int r, int p, int v) { if (p > r or p < l) return; if (l == r) { t[x] += v;...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(); char c; vector<pair<char, char>> a; for (int i = 0; i < n; i++) if (s[i] != t[i]) { c = t[i]; for (int j = 0; j < n; j++) if (t[j] == c && s[j] == s[i] || ...
#include <bits/stdc++.h> using namespace std; double ans = 1; int p, d, h; int main() { cin >> p >> d >> h; int top = 0; int kh; for (int i = 1; i <= d; i++) { int x; cin >> x; top += x; if (i == h) { kh = x; } } if (top < p) { cout << -1; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; clock_t clk = clock(); int i, j; void solve(void); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int t = 1; while (t--) solve(); return 0; } int n, m, a, b; bool cnt; bool vis[1501][...
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); inline int cmp(double x, double y = 0, double tol = 1e-7) { return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; } struct point { double x, y; point(double x = 0, double y = 0) : x(x), y(y) {} point operator+(point q) {...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> arr(n); for (auto& x : arr) cin >> x; vector<int> p(m); for (int i = 0; i < m; i++) p[i] = i; vector<vector<int>> mp(m); ...
#include <bits/stdc++.h> using namespace std; int n, k, x, v[10001], w[10001], f[10001], g[10001], ans = -1; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d , &v[i]); for (int i = 1; i <= n; i++) { scanf( %d , &x); w[i] = v[i] - x * k; } for (int i = 1; i...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); if (n % 2 == 0) printf( Mahmoud ); else printf( Ehab ); }
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; map<string, long long> arr; for (long long i = 0; i < a; i++) { string s1; cin >> s1; arr[s1] = -i; arr.insert(pair<string, long long>(s1, -i)); } vector<pair<long long, string>> ar1; ...
#include <bits/stdc++.h> using namespace std; bool check[100]; int main() { int n; string s; cin >> n; cin >> s; int ans = 0; for (int x = 0; x < s.size(); ++x) { if (!check[s[x] - a ]) { ans++; check[s[x] - a ] = 1; } } cout << ((ans >= n) ? YES : ...
#include <bits/stdc++.h> using namespace std; int main() { int i, n, x, y, c; cin >> n >> x >> y; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; if (x > y) cout << n << endl; else { c = 0; for (i = 0; i < n; i++) if (a[i] <= x) c++; if (c % 2 == 1) c =...
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 5; const int K = 30; int p[N]; char s[N]; int get(int l, int r, int s) { l = max(l, s * K); if (l > r) return 0; return r / s - l / s; } int main() { scanf( %s , s); int n = strlen(s); for (int i = 0; i < n; +...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, k, link; cin >> n >> k; vector<int> ans(n + 1); for (int i = 1; i <= n; i++) { cin >> link; ans[i] = min(n, i + k) - max(1, i - k) + 1; if (link != 0) { ans[i] += ans[link] - max(0, (min(n, link + k) - ma...
#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--) { long long int n, x = 1, ans = 0, w = 0, q; string s; cin >> n; long long int p = pow(2, 32) - 1; stack<long long in...
#include <bits/stdc++.h> using namespace std; struct pawn { long long int r; long long int c; }; struct pawn b[100], w[100]; int main() { ios::sync_with_stdio(false); char a; long long int l = 0, h = 0; for (int i = 1; i <= 8; i++) { for (int j = 1; j <= 8; j++) { cin >> ...
#include <bits/stdc++.h> using namespace std; void MAIN() { long long N; cin >> N; string S = to_string(N); reverse(S.begin(), S.end()); int sz = (int)S.size(); long long ans = -2; for (int i = 0; i < (1 << sz); i++) { int i_c = i; if ((i_c >> (sz - 1) & 1) || (i_c >> (sz - 2...
#include <bits/stdc++.h> using namespace std; inline long long ispossible(vector<long long>& b, vector<long long>& p, int k, long long a) { int n = b.size(); if (k > p.size()) return -1; long long c = 0, s = 0, extra = 0; for (int i = n - k; i < n; i++) { c += p[i...
#include <bits/stdc++.h> inline int dist(int a, int b, int d) { assert(a % d && b % d); if (a >= 0) a /= d; else a = a / d - 1; if (b >= 0) b /= d; else b = b / d - 1; return abs(a - b); } int main() { int a, b, x1, y1, x2, y2; scanf( %d%d%d%d%d%d , &a, &b, ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using dd = long double; namespace { static bool constexpr dbg = 0; ll constexpr N = -1; ll n, a, b, c; void init() { cin >> n >> a >> b >> c; } void solve() { if (n == 1) cout << 0; else if (n...
#include <bits/stdc++.h> using namespace std; long long P[200020]; long long n, m; long long Mod = 998244353; long long Power(long long a, long long b) { if (b < 1) return 1; long long Tmp = Power(a, b / 2); Tmp = Tmp * Tmp % Mod; if (b & 1) Tmp = Tmp * a % Mod; return Tmp; } long long...
#include <bits/stdc++.h> using namespace std; int a[100100], id[100100], t, Ans, ans[100100], n, i, vis[100100], j, k; int flag; vector<int> vec[100100]; bool cmp(int u, int v) { return a[u] < a[v]; } int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &a[i]); id[i] = i;...
#include <bits/stdc++.h> const int N = 3e5 + 10; const int mod = 1e9 + 7; int n; std::vector<int> edge[N]; std::pair<int, int> v[N]; int q; std::pair<int, int> query[N]; int queue[N]; std::pair<int, int> range[N]; int father[N]; int degree[N]; int fastPower(int x, int y) { int ret = 1; f...
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n <= 2) cout << -1; else while (n--) cout << n + 1 << ; return 0; }
#include <bits/stdc++.h> using namespace std; int dp[5005][5005]; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> s; memset(dp, -1, sizeof dp); int ans = 0; for (int i = 0; i < s.size(); i++) { int can_rev = 0; int cur = 0; for (int j = i; j < s....
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); ; long long int t, i; cin >> t; while (t--) { long long int n, x, tt = 0; vector<pair<long long int, long long int>> v, v1; multimap<long long int, long long int> m,...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const long long inf = 1e15; const int mod = 1e6; void faster() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const long long N = 3e5 + 10; int n, m; string s; pair<long long, long long> p[N]; long long prefix[N...
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); long long n; cin >> n; long long nmax = 9999999999; while ((nmax / 2) >= n) nmax /= 10; int inc = nmax + 1; long long ans = 0; if (nmax == 0) { ans = (n * (n - 1)) / 2; cout ...
#include <bits/stdc++.h> char a[99]; char b[99]; int n; int c, d; int get(char p, char q, char r, char s) { if (p == r) return 0; if (p == ( ) { if (r == [ ) return -1; return 1; } else if (p == [ ) { if (r == ( ) return 1; return -1; } else { if (r == ( ) re...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int x = 0; int n; cin >> n; for (int i = 0; i < n; i++) { string statement; cin >> statement; if (statement.find( + ) != std::string::npos) { x += 1; } else { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, h, i, j, t, m, l, r, q; long long p = 0, k, w, z, x, y, d; string s = , st = , s1 = , s2 = ; q = 1; for (l = 0; l < q; l++) { int x1, y1, x2, y2; std::cin >> x1 >> y1 >> x2 >> y2 >> x >> y; p = x2 -...
#include <bits/stdc++.h> using namespace std; int dp[101][2]; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); ; int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; if (v[0] == 1) dp[0][0] = 0, dp[0][1] = 1; if (v[0] == 2)...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1E9; const long long LINF = (long long)1E18; int INP, AM; char BUF[(1 << 10) + 1], *inp = BUF; template <typename T> T gcd(T a, T b) { return (b == 0) ? abs(a) : gcd(b, a % b); } template <typename T> inline T lcm(T a, T b) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; template <typename... Args> void writeln(Args... args) { ((cout << args << ), ...); cout << endl; } template <typename... Args> void _db(Args... args) { ((cerr << args << ;; ), ...); ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e6 + 5; const long long MAXM = 4e7 + 5; const int MOD = 998244353; long long n, m, p; struct node1 { long long x, c; } a[MAXN], b[MAXN]; struct node2 { long long x, y, z; } c[MAXN]; struct node { long long l, r, val, m...
#include <bits/stdc++.h> using namespace std; int main() { int r, c, x, y; string s; cin >> r >> c >> x >> y; cin >> s; vector<int> visited(r * c + 1, 0); cout << 1 ; int t, n = s.size(); visited[c * (x - 1) + y] = 1; for (int i = 0; i < n - 1; i++) { if (s[i] == U && (...
#include <bits/stdc++.h> using namespace std; long long x, xxxxx = 0; string s, word; long long indx = 0, lmt; string v[100009], out = ; bool f_int = false; bool ok() { if (indx > lmt) return xxxxx = 1, false; bool o1, o2; o1 = o2 = false; if (v[indx] == int and indx != 1) { out ...
#include <bits/stdc++.h> using namespace std; const int inf = 5000; const int MAXN = 200, MAXE = 2 * MAXN; int src, snk, nNode, nEdge; int Q[MAXN], fin[MAXN], pro[MAXN], dist[MAXN]; int flow[MAXE], cap[MAXE], Next[MAXE], to[MAXE]; inline void init(int _src, int _snk, int _n) { src = _src, snk = _snk, ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:36777216 ) const int Nmax = 100100; const int Drection[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; int h, q; long long minV[55], maxV[55]; long long leftDown(long long L, int hg) { if (hg == h) return L; return leftDown(...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353, N = 5e5; int qmod1(const int &x) { return x >= mod ? x - mod : x; } int qmod2(const int &x) { return x + (x >> 31 & mod); } int qpower(int a, int b) { int ans = 1; for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) ans = ...
#include <bits/stdc++.h> using namespace std; const int N = 1005; const int mod = 1e9 + 7; int n, m; int c[N][N], fac[N], f[N][N][2][2], dp[N], g[N]; void Init() { scanf( %d%d , &n, &m); c[0][0] = 1; for (int i = 1; i <= n; i++) { c[i][0] = 1; for (int j = 1; j <= i; j++) { c...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (k >= (n - 1) * n / 2) { cout << no solution n ; } else { for (int i = 1; i <= n; i++) { cout << 0 << << i << n ; } } return 0; }
#include <bits/stdc++.h> using ll = long long; const int MV = 1e6; const int p10[] = {1, 10, 100, 1000, 10000, 100000}; int K, Q, F[6]; ll dp[MV]; ll val(int x) { ll f = 0; for (int i = 0; x; ++i, x /= 10) { int d = x % 10; if (d % 3 == 0) f += (ll)F[i] * d / 3; } return f; } ...
#include <bits/stdc++.h> int main() { int i, j, a = 0, b = 0, n, y; char x[10][10]; for (i = 0; i < 8; i++) scanf( %s , x[i]); for (i = 0; i < 8; i++) { n = 0; for (j = 0; j < 8; j++) { if (x[i][j] == B ) { n++; } } if (n == 8) a++; } for (i =...
#include <bits/stdc++.h> using namespace std; long long c[2000], d[2000]; long long u[2000], b[2000]; int main() { long long n, m, d; long long lpl = 0; cin >> n >> m >> d; for (int i = 0; i < m; i++) { cin >> c[i]; lpl += c[i]; } if (lpl == n) { cout << YES << endl; ...
#include <bits/stdc++.h> const int _ = 1e4 + 5; const long long INF = 1ll << 60; inline long long min(long long a, long long b) { return a < b ? a : b; } int n, c, s[_], t[_]; long long dp[2][_]; int main() { scanf( %d %d , &n, &c); for (int i = 1; i <= n; ++i) scanf( %d , s + i); for (int i = 1...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); srand(time(NULL)); ; int T = 1; cin >> T; while (T--) { int n, r = 0, c = 0; string s; cin >> n >> s; for (int i = 0; i < int(n); i++) r += s[i]...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string first, secound; string arr1[100], arr2[100], arr3[100], arr4[100]; int counter1 = 0, counter2 = 0, counter3 = 0, counter4 = 0; for (int i = 0; i < n; i++) { cin >> first >> secound; if (secound == ...