func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; void solve() { int p, f; cin >> p >> f; if (f > p) swap(p, f); int cs, cw; cin >> cs >> cw; int s, w; cin >> s >> w; if (w > s) { swap(w, s); swap(cs, cw); } int maxv = 0; for (int...
#include <bits/stdc++.h> using namespace std; int t, n, m, l, a[100001], i, check, p, d; bool b[100001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> l; t = 0; fill(b + 1, b + 1 + n, false); for (i = 1; i <= n; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-6; vector<int> mp[105], ans; char s[105][105]; int len[105], tmp[30]; queue<int> q; bool solve(int x, int y) { for (int i = 0; i < len[x] && i < len[y]; i++) { if (s[x][i] != s[y][i]) { mp...
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, delta, x1, x2; cin >> a >> b >> c; delta = b * b - 4.0 * a * c; delta = sqrt(delta); x1 = (-b + delta) / (2.0 * a); x2 = (-b - delta) / (2.0 * a); if (x1 < x2) swap(x1, x2); cout << fixed << setprecision(8) <<...
#include <bits/stdc++.h> using namespace std; unsigned long long gcd(unsigned long long a, unsigned long long b) { if (b == 0) { return a; } return gcd(b, a % b); } int main() { unsigned long long n, m, k; cin >> n >> m >> k; unsigned long long h = 2 * n * m; if (h % k == 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); int c[n]; memset(c, 0, sizeof(c)); while (m--) { int x, y = 0, p = 0; for (int i = 0; i < n; i++) { scanf( %d , &x); if (x > y) { y = x; p = i; } ...
#include <bits/stdc++.h> using namespace std; int dp(int a, int b, int row) { if (row == 1 && a < 3 && b >= 3) { return -1; } if (row == 0 && a < 3 && b >= 3) { return 0; } if (row == 1 && a < 3 && b < 3) { return 1; } if (row == 0 && a < 3 && b < 3) { return 0; ...
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const long long linf = 1LL << 62; const int mod = 1e9 + 7; const int MAX = 510000; const int V = 100005; struct UnionFind { vector<long long> p; vector<long long> rank; vector<long long> cnt; UnionFind(long long n) { ...
#include <bits/stdc++.h> using namespace std; const int fx[] = {+1, -1, +0, +0}, fy[] = {+0, +0, +1, -1}; const long long mod = 1e9 + 7, INF = 1e18, mx = 1e6; int Case = 1, cas = 0; string S; struct exo { int Open, Close, SubLen; exo() {} exo(int a, int b, int c) { Open = a, Close = b, SubLen = ...
#include <bits/stdc++.h> using namespace std; int n, m, ans; vector<int> v[100010]; int main() { cin >> n >> m; for (int i = 1; i <= m; ++i) { int x, y; scanf( %d%d , &x, &y); v[x].push_back(y); v[y].push_back(x); } for (int i = 1; i <= n; ++i) ans += v[i].size() % 2; ...
#include <bits/stdc++.h> using namespace std; int main() { string s = , s1 = , tmp; cin >> tmp; s += tmp; cin >> tmp; reverse(tmp.begin(), tmp.end()); s += tmp; cin >> tmp; s1 += tmp; cin >> tmp; reverse(tmp.begin(), tmp.end()); s1 += tmp; s.erase(s.find( X ), 1);...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 150001; int t[MAX_N]; int main() { int n, k, q; cin >> n >> k >> q; for (int i = 0; i < n; ++i) { cin >> t[i]; } set<int> s; for (int i = 0; i < q; ++i) { int x, y; cin >> x >> y; if (x == 1) { ...
#include <bits/stdc++.h> using namespace std; struct node { int v, w; } a[100005]; bool cmp(node a, node b) { return a.v > b.v; } int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d%d , &a[i].v, &a[i].w); sort(a, a + n, cmp); int ma = a[0].w; for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; long long ll(long double x) { return x; } int main() { int n; cin >> n; while (n--) { long long a, b; cin >> a >> b; if (ceil((2 * a - b) / 3.0) == floor((2 * a - b) / 3.0) and ceil((2 * b - a) / 3.0) == floor((2 * b - a) / 3.0)...
#include <bits/stdc++.h> using namespace std; bool SR(int &x) { return scanf( %d , &x) == 1; } bool SR(long long &x) { return scanf( %lld , &x) == 1; } bool SR(double &x) { return scanf( %lf , &x) == 1; } bool SR(char *s) { return scanf( %s , s) == 1; } bool RI() { return true; } template <typename I, typ...
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 0, 1, -1}; const int dy[] = {1, -1, 0, 0}; int s[505][505]; queue<pair<int, int> > q; char c[505][505]; bitset<505> b[505]; int main(void) { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> (c[i] + 1); int x1,...
#include <bits/stdc++.h> using ll = long long; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t, n, x; cin >> t; int sum = 0; int cnt = 0; int item = 0; int s = 0; while (t--) { cin >> n >> x; cnt = 0...
#include <bits/stdc++.h> using namespace std; long long a[9], aa[9]; int c[9], cc[9]; int n; int ans; void dfs(int u, int cnt, int self) { if (u == n) { ans = min(ans, cnt + (self > 1)); return; } dfs(u + 1, cnt + cc[u] + (c[u] != 1), self + 1); for (int i = u + 1; i < n; i++) ...
#include<bits/stdc++.h> #define pii pair<int,int> #define fi first #define sc second #define pb push_back #define ll long long #define trav(v,x) for(auto v:x) using namespace std; const int N = 1e6 + 100; const ll mod = 998244353; int n, m, need; int sa[N], rnk[N]; ll fac[N], ifac[N]; ll...
#include <bits/stdc++.h> using namespace std; long long g(long long n, long long m) { long long ans = 0; for (long long x = 1; x <= n; x++) { long long minY = 5 - (x % 5); if (minY <= m) ans += (m - minY) / 5 + 1; } return ans; } long long gs(long long n, long long m) { long long...
#include <bits/stdc++.h> using namespace std; const int MAXN = 101; int N, Q, freq[11]; char commands[MAXN], commands2[MAXN]; void solve(int l, int r) { l--; r--; for (int i = 0; i < N; i++) commands2[i] = commands[i]; for (int i = 0; i < 10; i++) freq[i] = 0; int cur = l; int dir = 1;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100; int n, x, a; int f[MAXN + 1]; int main() { cin >> n >> x; memset(f, 0, sizeof f); for (int i = 0; i < n; i++) { cin >> a; f[a] = 1; } int ans = 0; for (int i = 0; i < x; i++) { if (f[i] == 0) ans++; ...
#include <bits/stdc++.h> const int maxx = 2e5 + 7; const int maxn = 1e9 + 7; using namespace std; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = s * 10 + ch - 0...
#include <bits/stdc++.h> using namespace std; const int ma = 35; int n, m, mat[ma][ma]; int main() { int t; scanf( %d , &t); int ans, one, zero; int sum, temp; int l, r; while (t--) { scanf( %d%d , &n, &m); one = zero = 0; for (int i = 1; i <= n; i++) for (int j...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); int freq[26]; int main() { string s; cin >> s; int mx = -1; char g = s[0]; for (int i = 0; i < s.size(); i++) { freq[s[i] - a ]++; if (s[i] >= g) { mx = max(mx, freq[s[i] - a ]); g = s[i...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1); const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int N = 2e5 + 5; int n, m; char a[N], b[N]; void solve() { scanf( %d , &n); scanf( %s , a + 1); scanf( %s , b + 1);...
#include <bits/stdc++.h> using namespace std; int p, x, y; queue<int> q; int mmap[100000]; bool check(int s) { int i = s / 50 % 475; for (int j = 0; j < 25; ++j) { i = (i * 96 + 42) % 475; if (26 + i == p) return true; } mmap[s] = 1; return false; } int main() { cin >> ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; int left0 = 0; for (int i = 0; i < n; i++) { if (s[i] == 0 ) { left0 = i + 1; } else { break; } ...
#include <bits/stdc++.h> using namespace std; struct no { long long i, h, m; }; long long dp[40][40][40]; char str[40]; no pre[40][40][40]; long long pw[19]; vector<char> ans; int main() { long long n; scanf( %lld , &n); scanf( %s , str + 1); pw[0] = 1; for (long long i = 1; i ...
#include <bits/stdc++.h> using namespace std; int n; long long a[5005]; void input() { scanf( %d , &n); for (int i = 0; i < n; i++) { int x; scanf( %d , &x); a[i + 1] = a[i] + x; } } void solve() { long long outx, outy, outz, ans; ans = outx = outy = outz = 0; for (...
#include <bits/stdc++.h> using namespace std; int main() { char s[18]; for (int i = 1; i <= 8; i++) { cin >> s; bool p = false; for (int j = 1; j < 8; j++) if (s[j] == s[j - 1]) { p = true; break; } if (p) { cout << NO ; return 0; ...
#include<bits/stdc++.h> using namespace std; #define inf 1999999999999999999 #define mod 1000000007 #define lb lower_bound #define ub upper_bound #define pb push_back #define pf push_front #define bn binary_search #define pq priority_queue #define int long long #define pii pair<int,int> #define ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 3; const long long OO = 0x3f3f3f3f3f3f3f3f; long long n, a, b; vector<int> primes, v; long long mem[N][3]; void fact(int num) { if (num % 2 == 0) primes.push_back(2); while (num % 2 == 0) num /= 2; for (int i = 3; i * i <= num; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int mx = (int)1e9; char an; void ask_query(int i, int j) { cout << ? << i << << j << endl; cin >> an; if (an == e ) exit(0); } int solbin(int l, int r) { if (r == l + 1) return r; int mid = (l + r) /...
#include <bits/stdc++.h> using namespace std; class Piece { public: int up[600]; int down[600]; vector<int> pcs; Piece() {} } pieces[20]; int x[600][600], w, h, p, u; void readPhoto() { cin >> h >> w >> p; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) cin >> x[i][j];...
#include <bits/stdc++.h> using namespace std; bool dp[5001][5001]; vector<int> bits[10001]; vector<pair<int, int> > cur; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, ans; cin >> s; int n = s.size(); dp[0][0] = 1; cur.push_back(make_pair(0, 0)); int cn...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin...
#include <bits/stdc++.h> using namespace std; int n, x; bool isp(int n) { if (n == 1) return false; for (long long i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; } int mpow(long long x, int k) { long long ans = 1; while (k > 0) { if (k & 1) ans = (ans * x) %...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 100; const int oo = 1e9 + 7; int N; int H[MAXN]; deque<int> dq; int L[MAXN], R[MAXN], l[MAXN], r[MAXN]; int d[MAXN]; vector<int> G[MAXN]; void Dijkstra(int u) { for (int i = (1), _b = (N + 1); i <= _b; ++i) d[i] = +oo; d[u]...
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; const long long INF = 1e12; const long long N = 1e6 + 10; vector<long long> G[100001]; long long n, m, match[100001], dist[100001]; bool bfs() { long long i, u, v, len; queue<long long> Q; for (i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; struct node { double x, y; } g[500]; int main() { int i, j, k, n, m; scanf( %d , &n); for (i = 0; i < n; ++i) { scanf( %lf%lf , &g[i].x, &g[i].y); } double maxx = 0; double m1, m2; for (i = 0; i < n - 1; ++i) for (j = i + ...
#include <bits/stdc++.h> using namespace std; int mb[3], cd[3]; int mn[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool chk() { if (mb[1] > 12) return 0; int i, j, k, tm; tm = mn[mb[1]]; if (mb[1] == 2 && !(mb[2] & 3)) tm++; if (tm < mb[0]) return 0; for (i = mb[2]; i < cd[2...
#include <bits/stdc++.h> using namespace std; const int N = 3000000 + 11; const int mod = 1e9 + 7; const int MAXN = 3000000 + 5; int n, m; int c[MAXN]; struct Node { int l, r; } a[MAXN]; int lowbit(int i) { return i & (-i); } long long sum(int x) { long long sum = 0; while (x) { su...
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int x = 0, f = 1; for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } inline void chkmax(int &x, int y) { x = x > y ? x : y...
#include <bits/stdc++.h> using namespace std; int a[4], i, n, x; int main() { for (cin >> n, i = 0; i < n; ++i) cin >> x, --x, a[0] += !x, a[1] = max(a[0], a[1] + x), a[2] = max(a[1], a[2] + !x), a[3] = max(a[2], a[3] + x); cout << a[...
#include <bits/stdc++.h> using namespace std; int maxn, n, t, x; int main() { cin >> n; for (int i = 1; i <= n; i++) { int in1, in2; cin >> in1 >> in2; x -= in1 - t; if (x < 0) x = 0; x += in2; maxn = max(maxn, x); t = in1; } cout << t + x << << maxn; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; pair<int, long long> operator+(const pair<int, long long> &A, const pair<int, long long> &B) { return {A.first + B.first, A.second + B.second}; } pair<int, long long> operator-(const pair<int, long long>...
#include <bits/stdc++.h> using namespace std; int compareAscending(const void *a, const void *b) { return (*(int *)a - *(int *)b); } int compareDecending(const void *a, const void *b) { return (*(int *)b - *(int *)a); } int compareFirst(const void *a, const void *b) { if (((pair<int, int> *)a)->...
#include <bits/stdc++.h> using namespace std; multimap<long long int, long long int> par; char en = n ; long long int inf = pow(10, 14); long long int mod = 1e9 + 7; long long int parent[2][500005]; long long int findRoot(long long int a, long long int which) { if (parent[which][a] == a) return a; ...
#include <bits/stdc++.h> using namespace std; int main() { long long t, i = 0, j, k, x, y, z, count = 0, p, flag = 0, ans = 0, sum = 0, l, n, m, max1, min1, pos, tmp, q; t = 1; while (t--) { long long n, r; scanf( %lld%lld , &n, &r); long double x[1005], y[1005]; ...
#include <bits/stdc++.h> using namespace std; const int N = 2005; const long double ep = 1e-10; struct pnt { long double x, y; pnt() { x = y = 0; } pnt(long double xx, long double yy) { x = xx, y = yy; } pnt operator+(pnt a) { return pnt(x + a.x, y + a.y); } void in() { int xx, yy; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; std::pair<long long, long long> go(long long m) { long long cur = 1; long long cur3 = 1; long long cur13 = 8; long long h = 0; long long num = 0; std::vector<long long> what; while (1) { while (h + cu...
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; #define pii acos(-1) #define sc(n) scanf( %d ,&n) #define sc2(n,x) scanf( %d%d ,&n,&x) #define pr(n) printf( %d ,n) #define scl(n) scanf( %I64d ,&n) #define scl2(n,m) scanf( %I64d%I64d ,&n,&m) ...
#include <bits/stdc++.h> using namespace std; vector<long long int> v(26, 0); long long int n, m; bool myFun(string &a, string &s, long long int i, long long int j) { if (i >= n && j >= m) { return true; } if (j >= m) { return false; } if (i >= n) { while (j < m) { ...
#include <bits/stdc++.h> int main() { int a, b, c, d, e, f; scanf( %d , &a); e = 0; for (b = 1; b <= a; b++) { for (c = b; c <= a; c++) { f = b ^ c; d = 0 ^ f; if (b + c > d && d <= a && d >= c) { e++; } } } printf( %d n , e); return 0;...
#include <bits/stdc++.h> using namespace std; int main() { int *xi, *di, n; cin >> n; xi = new int[n]; di = new int[n]; for (int i = 0; i < n; i++) cin >> xi[i] >> di[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (xi[i] + di[i] == xi[j] && xi[j] + di[j] == ...
#include <bits/stdc++.h> using namespace std; long long fact[200005]; long long extgcd(long long a, long long b, long long& x, long long& y) { long long d = a; if (b != 0LL) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } long lo...
#include <bits/stdc++.h> using namespace std; int n, m, k = 0, cl[105 * 35], link[105 * 35]; vector<int> g[105 * 35]; vector<pair<int, int> > has[105]; bool dfs(int u) { for (int i = 0; i < g[u].size(); ++i) { int v = g[u][i]; if (!cl[v]) { cl[v] = 1; if (link[v] == 0 || dfs(li...
#include <bits/stdc++.h> using namespace std; int a[100005]; int l[100005]; int r[100005]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } for (int i = 1; i <= n; i++) { l[i] = min(l[i - 1] + 1, a[i]); } for (int i = n; i >= 1; i--) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a, b; for (a = 0; a <= n / 1234567; a++) { for (b = 0; b * 123456 <= n - a * 1234567; b++) if ((n - (a * 1234567 + b * 123456)) % 1234 == 0) { cout << YES ; return 0; ...
#include <bits/stdc++.h> using namespace std; long long rdtsc() { long long tmp; asm( rdtsc : =A (tmp)); return tmp; } inline int myrand() { return abs((rand() << 15) ^ rand()); } inline int rnd(int x) { return myrand() % x; } void precalc() {} const int maxn = 1e4 + 10; int n; char s[ma...
#include <bits/stdc++.h> using namespace std; inline int L(int i) { return i << 1; } inline int R(int i) { return (i << 1) | 1; } inline long long max(long long a, long long b) { return a < b ? b : a; } inline long long min(long long a, long long b) { return a < b ? a : b; } inline int abs(int x) { return x...
#include <bits/stdc++.h> using namespace std; int a, b, n, i, j; int f[5001]; int dp[5001][5001]; char s[5003]; int main() { while (~scanf( %d%d%d , &n, &a, &b)) { scanf( %s , &s[1]); for (i = 1; i <= n; i++) f[i] = f[i - 1] + a; for (i = 1; i <= n; i++) { f[i] = min(f[i], f[i ...
#include <bits/stdc++.h> using namespace std; int n; int t[60], v[60]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &t[i]); for (int i = 1; i <= n; i++) scanf( %d , &v[i]); int nrOfStonesTakenAway = 0; for (int i = 1; i <= n; i++) { if (t[i] > v[i]) nrOfStones...
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, i, j, k, l; cin >> n >> a; long long arr[n + 2]; for (i = 1; i <= n; i++) { cin >> arr[i]; } long long pos; arr[n + 1] = a; sort(arr + 1, arr + n + 2); for (i = 1; i <= n + 1; i++) { if (arr[i]...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); int main() { int n, s; cin >> n >> s; int res = -1; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (y == 0) { if ...
#include <bits/stdc++.h> using namespace std; const int N = 1003; int n, k; bitset<N * 3> A, dp, dpt; int main() { scanf( %d%d , &n, &k); for (int a; k; k--) scanf( %d , &a), A[a] = 1; dp[1500] = 1; for (int __ = 1; __ <= 1009; __++) { dpt = 0; for (int i = 0; i < 3000; i++) ...
#include <bits/stdc++.h> using namespace std; long long n, fir; int main() { scanf( %lld , &n); fir = n; for (int i = 2; 1ll * i * i <= n; i++) if (n % i == 0) { fir = i; break; } for (; n != 1 && n % fir == 0; n /= fir) ; printf( %lld n , n == 1 ? fir : 1); ...
#include <bits/stdc++.h> using namespace std; int n, k; int a[110]; int b[110]; int dp[121000]; int main(int argc, char *argv[]) { cin >> n >> k; for (int i = 0; i < n; i += 1) { cin >> a[i]; } for (int i = 0; i < n; i += 1) { cin >> b[i]; } for (int i = 0; i < 121000; i ...
#include <bits/stdc++.h> using namespace std; map<long long, long long> m; long long f(string s) { long long ff[27] = {0}, ans = 0, i, j; for (i = 0; i < s.size(); i++) { ff[s[i] - a ]++; } for (i = 0; i < 26; i++) { if (ff[i] % 2) { ans |= (1LL << i); } } return...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; int result = n - m; if (k >= abs(result) && k != 0) { cout << ? << n ; } else { if (result > 0) cout << + n ; else if (result < 0) c...
#include <bits/stdc++.h> using namespace std; stack<char> st; char s[100005]; int main() { scanf( %s , s); int len = strlen(s); for (int i = 0; i < len; ++i) { if (st.empty() || st.top() != s[i]) st.push(s[i]); else st.pop(); } if (st.empty()) puts( Yes ); ...
#include <bits/stdc++.h> using namespace std; #define ll long long int n,m; char a[6][6]; bool used[6][6]; int ans; void dfs(int x,int y) { if(a[x][y]== * ) { ans++; } if(x==n&&y==m) { cout << ans; exit(0); } if(x+1<=n&&a[x+1][y]== ...
#include <bits/stdc++.h> using namespace std; int main() { iostream::sync_with_stdio(0); int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= 200; i++) { for (int j = b; j <= 200; j++) { for (int k = 1; k <= 200; k++) { if (a * 2 >= i && b * 2 >= j && c <= k && c * 2...
#include <bits/stdc++.h> using namespace std; int visit[100005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; char a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++...
#include <bits/stdc++.h> using namespace std; struct Edge { int from, to; Edge(int f, int t) : from(f), to(t) {} }; vector<Edge> edges; vector<int> G[100005]; int h[100005]; void add_edge(int from, int to) { edges.push_back(Edge(from, to)); int m = edges.size(); G[from].push_back(m - 1...
#include <bits/stdc++.h> using namespace std; int pot(int x, int y) { if (y == 0) { return 1; } else { return x * pot(x, y - 1); } } int bin(int x, int y) { if ((x == 0 && y != 0) || (y == 0 && x != 0)) { return 1; } else { return bin(x, y - 1) + bin(x - 1, y); } ...
#include <bits/stdc++.h> using namespace std; int i; long n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; map<string, int> mp; string s; while (n--) { cin >> s; mp[s]++; if (mp[s] > 1) { cout << YES << endl; } else...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans[52]; memset(ans, 0, sizeof(ans)); int flag = 0; for (int i = 0; i < n; ++i) { int arr[52]; memset(arr, 0, sizeof(arr)); for (int j = 0; j < n; ++j) { int k; cin >> k; ...
#include <bits/stdc++.h> int const MOD = 998244353; int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n, nopt; std::cin >> n >> nopt; std::vector<int> h; h.reserve(n + 1); h.resize(n); for (int& hi : h) std::cin >> hi; h.push_back(h[0]); std::vector<int> f{1}; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; int arr[maxn]; int main() { int T; cin >> T; while (T--) { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i]; for (int i = 0; i < n; ++i) { if (i % 2) { if (arr[i] > 0) arr[i]...
/* https://codeforces.com/blog/entry/87523 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 100000 int *ej[N], eo[N]; void append(int i, int j) { int o = eo[i]++; if (o >= 2 && (o & o - 1) == 0) ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]); ej[i][o] =...
#include <bits/stdc++.h> #ifdef ALGO #include el_psy_congroo.hpp #else #define DUMP(...) 1145141919810 #define CHECK(...) (__VA_ARGS__) #endif struct Dsu { std::vector<int> dsu; explicit Dsu(int size) : dsu(size) { std::iota(dsu.begin(), dsu.end(), 0); } int find(int x) { ...
#include <bits/stdc++.h> using namespace std; const long long maxm = 1e+18; vector<long long> prime; long long power(long long x, long long y) { long long res = 1; x = x % 1000000007; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; y = y >> 1; x = (x * x) % 1000000007; ...
#include <bits/stdc++.h> int g[(1 << 22)][4], f[23], n, m, a, b; void output(int v, int u) { if (u == 0) return; if (v == 0) return; output(g[v][1], u - 1); printf( %d , g[v][2]); } int cnt(int v) { int ret = 0; for (; v; v >>= 1) if (v & 1) ret++; return ret; } int main(v...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin...
#include <bits/stdc++.h> using namespace std; long long find_smallest_number_with_cumulative_sum_greater_or_equal_than_sum( long long sum) { long long lower = 0, upper = (long long)15E8, mid; while (lower < upper) { mid = (lower + upper) / 2; if (mid * (mid + 1) / 2 >= sum) upper =...
#include <bits/stdc++.h> using namespace std; int gcd(int A, int B) { if (B == 0) return A; else return gcd(B, A % B); } long long int mod_exponentiation(long long int base, long long int exponent, int modulus) { long long int result = 1; while (exp...
#include <bits/stdc++.h> using namespace std; const int N = 200006; vector<vector<int> > edges(N); vector<int> color; bool bipartite; vector<pair<int, int> > e; int n, m; void dfs(int node, int c) { color[node] = c; for (auto to : edges[node]) { if (color[to] == -1) { dfs(to, c ^ 1...
#include <bits/stdc++.h> using namespace std; int ask(string q, int x) { cout << q << << x << endl; int ret; cin >> ret; return ret; } int getclosestnode(vector<vector<int>> &adj, set<int> &me, int node) { bool visited[1001]; memset(visited, 0, sizeof visited); queue<int> q; ...
#include <bits/stdc++.h> using namespace std; struct arc_t { int u, v, c; arc_t(int _u, int _v, int _c) : u(_u), v(_v), c(_c) {} bool operator<(const arc_t& rhs) const { return c < rhs.c; } }; int pa[2001]; void set_init(int n) { for (int i = 1; i <= n; i++) pa[i] = i; } int set_find(int x...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3, Ofast , inline ) using namespace std; const long long mod = 1e9 + 7; const long long M = 1e8 + 5; const long long N = 6e5 + 5; char s[N]; bool check() { map<char, long long> mp; long long len = strlen(s + 1); long lon...
#include <bits/stdc++.h> using namespace std; const int maxx = 1e2 + 10; int a[maxx], b[maxx]; int n; inline bool check(int m) { int max1 = 0, max2 = 0; for (int i = 1; i <= n; i++) { if (a[i] && !b[i]) max1 += m; else if (a[i] && b[i]) max1 += 1, max2 += 1; else if (...
#include <bits/stdc++.h> using namespace std; int n; string s, ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; cin.ignore(numeric_limits<streamsize>::max(), n ); cin >> s; bool flag = true; int cnt = 0, max_cnt = 0; for (int i = 0; i < n - 1; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int FFTMOD = 1007681537; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { lo...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000010; int n, k; int C[MAXN]; void load() { scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %d , C + i); } bool A[MAXN]; int previ[MAXN]; int nexti[MAXN]; int last[MAXN]; void sito() { int x = 2; for (int i ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int n; cin >> n; if (n == 1 || n == 4 || n == 6 || n == 8 || n == 9 || n == 10 || n == 13 || n == 15) cout << 1 << endl; else cout << 0 << endl; retur...
#include <bits/stdc++.h> using namespace std; int p[100]; long long u, v; int MOD; void addmod(int &x, int y) { x = (x + y) % MOD; } int dfs(long long minx, long long maxx, long long left, long long right, long long state, int step) { if (left <= minx && maxx <= right) { int ret = 0; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long MAX = 105; long long n, m, x, y, z, k; struct Matrix { long long row, col; long long m[MAX][MAX]; }; Matrix Multiply(Matrix A, Matrix B) { Matrix ans; ans.row = A.row; ans.col = B.col; for ...
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : (-x); } template <class T> T sqr(T x) { return x * x; } const int maxn = 1000 * 1000 * 2; const int BUBEN = 40; long long fib[BUBEN]; int a[maxn]; int n; long long X, Y; long long P; st...