solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long n, m, ll[1000010], rr[1000010]; long long a[1000010], b[1000010], c[1000010]; double ans[1000010]; inline long long read() { long long cnt = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } wh...
17
#include <bits/stdc++.h> using namespace std; char s[505][505]; long long dp[3][505][505]; int query(int l, int r1, int c1, int r2, int c2) { if (r1 <= r2 && c1 <= c2) return dp[l][r2][c2] - dp[l][r1 - 1][c2] - dp[l][r2][c1 - 1] + dp[l][r1 - 1][c1 - 1]; return 0; } int main() { int n, m, k; scanf...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 500; int nbr[MAXN][MAXN]; const int INF = 1e9; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; while (m--) { int a, b; cin >> a >> b; a--; b--; nbr[a][b] = 1; nbr[b][a] = 1; } vector<int> d[2]; d[0] ...
8
#include <bits/stdc++.h> using namespace std; int n, m, N; int lx[3210], ly[3210]; int G[3210][3210]; const int inf = 1 << 29; bool x[3210], y[3210]; int match[3210]; bool dfs(int k) { x[k] = true; for (int i = 0; i < N; i++) { if (!y[i] && lx[k] + ly[i] == G[k][i]) { y[i] = true; if (match[i] == -1...
14
#include <bits/stdc++.h> using namespace std; int n, p, c[300005], a[300005]; vector<int> u[300005]; int main() { scanf("%d%d", &n, &p); for (int i = 1; i <= n; i++) { int x, y; scanf("%d%d", &x, &y); u[x].push_back(y); u[y].push_back(x); a[x]++; a[y]++; } for (int i = 1; i <= n; i++) c[...
11
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long n, m, len; vector<long long> mx, mn, bpos; vector<deque<long long>> b; void to_front(long long x) { long long pos = find(b[bpos[x]].begin(), b[bpos[x]].end(), x) - b[bpos[x]].begin(); m...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int ans = 0; cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; if (x % k == 0) { ans += (x / k); } else { ans += (x / k) + 1; } } if (ans % 2 == 0) { ans = ans / 2; } else { ans = ans /...
3
#include <bits/stdc++.h> using namespace std; int main() { string binary; while (cin >> binary) { bool found = false; for (int i = 0; i < binary.size(); i++) if (binary[i] == '0') { found = true; binary.erase(binary.begin() + i); break; } if (!found) binary.erase(bina...
3
#include <bits/stdc++.h> using namespace std; int main() { int an = 0, sg = 0; string s; cin >> s; for (int u = 0; u < s.size() - 1; u++) { if (s[u] != s[u + 1] && s[u] == 'V') { s[u] = '$'; s[u + 1] = '$'; an++; u++; } } for (int u = 0; u < s.size() - 1; u++) { if ((s[u]...
3
#include <bits/stdc++.h> int main(void) { int q; scanf("%d", &q); while (q-- > 0) { long long int n, m, i = 0, s = 0; scanf("%I64d %I64d", &n, &m); for (i = m; i <= 10 * m; i = i + m) { s = s + i % 10; } s = s * (n / m / 10); for (i = m; i <= (n / m % 10) * m; i = i + m) { s = ...
4
#include <bits/stdc++.h> using namespace std; inline void Move(set<pair<int, int> > &X, set<pair<int, int> > &Y, set<pair<int, int> > &AX, set<pair<int, int> > &AY, pair<int, int> p) { X.erase(p); Y.erase({p.second, p.first}); AX.insert(p); AY.insert({p.second, p.first}); } int...
21
#include <bits/stdc++.h> using namespace std; const long long maxx = 790; const long long maxn = 1000000 + 7; const long long mod = 1e9 + 7; const long long maxs = 500000 + 7; const long long maxm = 400000 + 7; const long long maxk = 1008 + 7; const long long maxw = 100 + 7; const long long maxh = 100 + 7; const double...
16
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; long long p = 1e9 + 7; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; set<long long> s; s.insert(0); s.insert(1); for (long l...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 200; int n, m, ans; const int MAXV = 200, MAXE = 5000; const int INF = 0x3f3f3f3f; namespace network_flow { int deg[MAXV]; int h[MAXV], tot = 1, S, T; int nxt[MAXE], ver[MAXE], val[MAXE], cost[MAXE]; void add(int x, int y, int z, int c) { nxt[++tot] = h[x...
21
#include <bits/stdc++.h> using namespace std; int flg[5100][5100] = {0}; int main() { string s; cin >> s; int n = s.length(); for (int l = 0; l < n; l++) { int fff = 0, cnt = 0; for (int r = l; r < n; r++) { if (s[r] == '?' || s[r] == '(') cnt++; else cnt--; if (cnt < 0...
10
#include <bits/stdc++.h> using namespace std; void solve() { long long i, j, flag = 0; long long n, s; cin >> n >> s; long long a[n], sum = 0; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } if (sum < s) { cout << "-1\n"; return; } sort(a, a + n); while (s != 0) { long long...
4
#include <bits/stdc++.h> using namespace std; double dp[110][300010]; int main() { cout << fixed << setprecision(20); int n, m; scanf("%d%d", &n, &m); if (m == 1) { puts("1"); return 0; } dp[0][131072 + 0] = m - 1; int A, second = 0; for (int i = (0); i < (n); ++i) { scanf("%d", &(A)); s...
15
#include <bits/stdc++.h> double eps = 1e-10; using namespace std; int mx[300005], ans[300005], cnt[300005], n, q, cent[300005], par[300005]; vector<int> g[300005]; void dfs(int v, int p = 0) { par[v] = p; int MAX = -1, center; for (int i = 0; i < g[v].size(); i++) { int to = g[v][i]; if (to == p) continue...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n, a[maxn]; map<vector<int>, int> mp; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < 32768; i++) { vector<int> V; for (int j = 1; j <= n; j++) { int cnt = 0; fo...
16
#include <bits/stdc++.h> using namespace std; int gi() { int x = 0, w = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') w = 0, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return w ? x : -x; } const ...
26
#include <bits/stdc++.h> using namespace std; int numDay(int x) { if (x == 1 || x == 3 || x == 5) return 31; if (x == 7 || x == 8 || x == 10 || x == 12) return 31; if (x == 2) return 28; return 30; } int n, m; int main() { ios::sync_with_stdio(false); cin >> m >> n; int sn = numDay(m); n = 8 - n; sn -...
0
#include <bits/stdc++.h> using namespace std; const int maxV = 90010; const int maxN = 2e5 + 10; const int MOD = 1e9 + 7; const long long INF = 1000000000000000010LL; const int inf = 1e9 + 10; vector<int> p; int a[maxN]; int u[maxN]; char s[maxN]; int n, k; int main() { scanf("%d %d\n", &n, &k); scanf("%s", s); f...
15
#include <bits/stdc++.h> using namespace std; int n; vector<vector<pair<int, int> > > edges, edges2; vector<int> special; bool seen[100010]; bool seen2[100010]; bool reach[100010]; bool isSpecial[100010]; int best = -1; void MST(const vector<vector<pair<int, int> > >& edges, vector<vector<pair<int, int> > >& M...
10
#include <bits/stdc++.h> using namespace std; char str[1000 + 100][110], a[100]; bool vis[110]; bool dp[1100][26]; int main() { int n; scanf("%d%s", &n, a); for (int i = 0; i < n; i++) { if (a[i] != '*') vis[a[i] - 'a'] = 1; } int m; scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%s", str[i...
7
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; inline int mo(int x) { if (x >= MOD) return x - MOD; return x; } struct pot { long long x, y; pot() {} pot(long long _x, long long _y) : x(_x), y(_y) {} inline friend pot operator-(const pot &a, const pot &b) { return (pot){a.x - b.x...
21
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; long long qx, qy, kx, ky, dx, dy; cin >> qx >> qy; cin >> kx >> ky; cin >> dx >> dy; int k = 0; if ((qx - kx) > 0) { if ((qx - dx) < 0) k = 1; } if ((qx - kx) < 0) { if ((qx - dx) > 0) k = 1; } if ((qy - ky...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5, MAXP = 7; int n, p, k; struct node { int a, s[MAXP]; bool operator<(const node &oth) const { return a > oth.a; } } pe[MAXN + 5]; long long dp[MAXN + 5][1 << MAXP]; int popcount(int S) { int Cnt = 0; for (int i = 0; i < MAXP; i++) Cnt += (S >> i...
15
#include <bits/stdc++.h> using namespace std; const int len = 1e5 + 9; const long long mod = 1e9 + 7; const unsigned long long seed = 131; int main() { long long n; cin >> n; long long ans = 0; for (int i = 2; i <= n; ++i) { long long x = n / i; ans += (x - 1) * (x + 2) / 2; } cout << ans * 4 << end...
10
#include <bits/stdc++.h> using namespace std; inline int lowbit(int x) { return x & (-x); } int f[400010]; string S[4]; int ord[3] = {0, 1, 2}; int ans = 2147483647; inline string skr(string a, string b) { string T = a + '$' + b; int n = a.length(); int m = b.length(); int Len = n + m + 1; f[0] = -1; int j ...
14
#include <bits/stdc++.h> using namespace std; const int N = 21; long long n, a[N + 2], b[N + 2], tot, sum, A[(1 << 10) + 2], B[(1 << 10) + 2]; int f[(1 << N) + 2]; int ta, tb, all; void _get(long long q[], int l, int r, int &tp) { int len = r - l + 1; for (int s = 0; s <= (1 << len) - 1; s++) { long long sum = ...
23
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int u = 0; int c, p; for (int a = 0; a < s.length(); a++) { c = 0; p = 0; if (s[a] == 'C') { c = 1; } else if (s[a] == 'P') { p = 1; } for (int b = 0; b < 5; b++) { if (a == s.length()) { ...
1
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf("%d", A + i); } int N, M; long long a, b, c, d, A, B, C[1 << 20]; void add(long long a, long long b) { C[M++] = a + b, B += a - b; } int main(void) { scanf("%d", &N); for (int i(0); i < N; i++) { scanf("%ll...
21
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <cmath> #include <algorithm> #include <cstdlib> #include <cstring> #include <unordered_set> using namespace std; const double eps=1e-12; typedef long long ll; double v,res; void solve(double c,double m,double p,int t,double to...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int **a = new int *[n]; for (int i = 0; i < n; ++i) a[i] = new int[m]; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; for (int i = 0; i < m; ++i) for (int j = i; j < m; ++j) { for (int ...
7
#include <bits/stdc++.h> using namespace std; const int inf = 1000 * 1000 * 1000 + 17; const string names[7] = {"Anka", "Chapay", "Cleo", "Troll", "Dracul", "Snowy", "Hexadecimal"}; int n, aa[3]; map<string, int> M; int A[7][7]; string S1, S2, st; int ff(vector<int>& G) { int res = 0...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long int n, sum = 0, count = 0, m, flag = 1, ans = 0, k; cin >> n >> k; if (k == 1) { cout << n; return 0; } vector<long long int> v, c, d; m = n; while (m) { ans ...
5
#include <bits/stdc++.h> using namespace std; const long long maxN = 3e5 + 12; const long long INF = 2e9 + 12; long long n, a[maxN], dp[maxN]; map<long long, long long> f, s, mrk; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; long long x = 0, mx = -INF; for (long long i =...
6
#include <bits/stdc++.h> using namespace std; int hsh[1000005], a[1000005]; long long bit[1000005]; void update(int ind, int val) { while (ind < 1000005) { bit[ind] = bit[ind] + val; if (bit[ind] >= 1000000007) bit[ind] -= 1000000007; ind += (ind & -ind); } } long long query(int ind) { long long ret =...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; bool bila[MAXN]; int arr[MAXN]; bool was[MAXN]; vector<int> vect; int main() { int n, kkk = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; bila[arr[i]] = 1; } for (int i = 1; i <= n; i++) if (!bila[i]) vect.push_ba...
4
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b, long long mod) { if (b == 0 || a == 1) { if (mod == 1) return 0; else return 1; } if (b % 2 == 0) { long long k = powmod(a, b / 2, mod); return (k * k) % mod; } else { long long k = powmod(a,...
1
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N], b[N]; int main() { int i, n, m, k; while (scanf("%d%d%d", &n, &m, &k) != EOF) { for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = 1; i <= m; i++) scanf("%d", &b[i]); sort(a + 1, a + n + 1); sort(b + 1, b + m + 1); ...
8
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000 + 24; vector<int> vec; int marker[MAX_N][MAX_N]; int main() { int n, m; int closed = 0, beautiful = 0; cin >> n >> m; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; marker[y][x]++; marker[y][0]++; } for (int i = 0; ...
3
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int n, a[200005], t, pos[200005], ans; struct node { int l, r; } q[200005], now; void solve(int l, int mid, int r) { if (mid - l < r - mid) { for (int i = l; i < mid; i++) if (mid < pos[a[mid] - a[i]] && pos[a[mid] - a[i]] <= r) ans+...
14
#include <bits/stdc++.h> using namespace std; void solve(long long L, long long R) { if (R < 2 * L) { assert(false); } cout << L << ' ' << 2 * L << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long first, second; cin >> fir...
0
#include <bits/stdc++.h> using namespace std; const int N = 100010, M = 12; long long ans; int n, mod; long long cm[M], cx[M], cy[M]; struct comb { int mod, phi, p, c, maxn; int cj[N], f[N], num[N], fi[N]; int pow[40]; int power(int x, int y) { int ret = 1; for (; y; y >>= 1, x = 1ll * x * x % mod) { ...
21
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res *= a; b /= 2; a *= a; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, b; cin >> n >> b; unordered_map<long long, long l...
9
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e18; const int N = (int)2e6 + 17; int xs[N]; int n; vector<int> blocks[2]; bool field[2][N]; int prefSum[2][N]; long long t; long long dp[2][N]; int par[2][N]; int bst[2]; long long bstVal[2]; vector<int> shifts; vector<pair<int, int> > sho...
22
#include <bits/stdc++.h> using namespace std; inline int rei() { int x; cin >> x; return x; } inline long long rel() { long long x; cin >> x; return x; } inline string res() { string x; cin >> x; return x; } long long mod; int LowestPrimeFactor[100001]; int LowestPrimeFactorN[100001]; int LowestPrimeF...
19
#include <bits/stdc++.h> using namespace std; const int N = 500010; int inf = 1e9; int mod = 1e9 + 7; vector<int> z_function(string &s) { int n = (int)s.length(); vector<int> z(n); for (int i = 1, l = 0, r = 0; i < n; i++) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[...
19
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, sol = 1, p = 0, ant, t = 2, s; cin >> n >> m >> k; if (k == -1 && n % 2 != m % 2) cout << 0; else if (n == 1 || m == 1) cout << 1; else { s = 2; while (n != 1) { p = 0; t = s; while (p <= n - 1) { ...
10
#include <bits/stdc++.h> using namespace std; const int MX = (1 << 18); int cel(int a, int b) { int ret = (a + b - 1) / b; ret = max(ret, 1); return ret; } struct QUERY { int x, y, cost, type; QUERY() {} QUERY(int x, int y, int cost, int type) : x(x), y(y), cost(cost), type(type) {} }; bool operator<(...
13
#include <bits/stdc++.h> using namespace std; long long a[8][3]; inline long long sqr(long long a) { return a * a; } inline long long sm(long u, long v1, long v2) { return (a[v1][0] - a[u][0]) * (a[v2][0] - a[u][0]) + (a[v1][1] - a[u][1]) * (a[v2][1] - a[u][1]) + (a[v1][2] - a[u][2]) * (a[v2][2] - a...
12
#include <bits/stdc++.h> using namespace std; long long mod = (int)1e9 + 9; long long modPow(long long x, long long k) { long long res = 1; for (x %= mod; k; k >>= 1) { if (k & 1) res = (res * x) % mod; x = (x * x) % mod; } return res; } long long modInv(long long x) { return modPow(x, mod - 2); } int m...
10
#include <bits/stdc++.h> using namespace std; char B[1 << 26], *S = B, C; long long X, F; inline long long read() { for (F = 1; (C = *S++) < '0' || C > '9';) if (C == '-') F = -1; for (X = C - '0'; (C = *S++) >= '0' && C <= '9';) X = (X << 3) + (X << 1) + C - '0'; return X * F; } long long s[300000 + 5][3...
22
#include <bits/stdc++.h> using namespace std; int n, a, b, c, d, bd, cd, BB, CC, C, CB, r, Ansb, Ansc, ANS; string s1, s2; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> s2 >> s1; for (int i = 0; i < n; i++) { if (s1[i] == '0' && s2[i] == '0') a++; if (s1[i] == '0' && ...
10
#include <bits/stdc++.h> int a[4]; char ans[2000010]; int check(int f, int s) { if (f > a[0] || s > a[1]) { return 0; } return 1; } void solve() { int i, f, s; if (abs(a[2] - a[3]) > 1 || a[2] > a[0] || a[3] > a[1]) { printf("-1\n"); return; } if (a[2] == a[3]) { for (i = f = s = 0; f <= a...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (cin >> n >> m) { if (min(n, m) & 1) puts("Akshat"); else puts("Malvika"); } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int *p = new int[n + 1]; int *q = new int[n + 1]; int *sum = new int[n + 1]; int *plabel = new int[n + 1]; int *qlabel = new int[n + 1]; int *alabel = new int[n + 1]; int *result = new int[n + 1]; map<int, int> pmap; map<i...
12
#include <bits/stdc++.h> using namespace std; void solve() { long long n, i, x, y; cin >> n; for (i = 1; i < 100000; i++) { x = i * i - n; if (x <= 0) continue; y = sqrt(x); if (y * y == x) { long long z = i / y, zz = i / (y + 1); if (z > zz) { cout << i << " " << z << '\n'; ...
9
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int res; set<pair<pair<int, int>, pair<int, int> > > mem[30]; int fst(int h, int l, int r) { int p = (l >> h) << h; while (p < l) p += (1 << h); if (p <= r) return p; return -1; } void go(int h, int l1, int r1, int l2, int r2) { if (h...
16
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 123; const int mod = (int)1e9 + 7; const long long INF = (long long)1e18 + 7; const long double EPS = 1e-6; const long double pi = 3.1415926535897932384626433832; void IOS() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); } void so...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; int mn = -1, mx = -1; while (t--) { char c; int x, y; cin >> c >> x >> y; if (c == '+') { mn = max(mn, min(x, y)); mx = max(mx, max(x, y)); } e...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int n, cnt, mn, tot, rt, ans1; double sum, sumd, ans2; double w[maxn], val[maxn << 1], sd[maxn << 1]; int to[maxn << 1], head[maxn], nxt[maxn << 1], vis[maxn], siz[maxn]; inline int rd() { int ret = 0, f = 1; char gc = getchar(); while (gc < '...
22
#include <bits/stdc++.h> using namespace std; int F[200200], dist[200200], st[600600][25], LOG[600600]; vector<int> E, L, edges[200200]; void dfs(int u, int par, int level) { E.push_back(u); L.push_back(level); if (F[u] == 0) F[u] = L.size(); dist[u] = level; for (int i = 0; i < edges[u].size(); ++i) { in...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long int n; cin >> n; vector<vector<long long int> > v(5, vector<long long int>(n)); for (int i = 0; i < n; i++) for (int j = 0; j < 5; j++) cin...
2
#include <bits/stdc++.h> using namespace std; int n, m; string s[1000005]; vector<int> del; vector<int> del2; void sol(int L, int R) { int pos = lower_bound(del.begin(), del.end(), L + 1) - del.begin(); if (pos != del.size()) { int val = del[pos]; if (val <= R) { cout << "NO" << endl; return; ...
9
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int maxn = 3e5 + 10; const int inf = 0x3f3f3f3f; int qu[maxn], a[maxn], n, mi[maxn], head, tail, ans[maxn]; void _push(int pos) { while (head <= tail && a[pos] >= a[qu[tail]]) { tail--; } qu[++tail] = pos; } int get_pos(int u) { ...
12
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int n, k; const int maxN = 2 * (int)1e4 + 100; vector<pair<long long, long long> > cht[4 * maxN]; struct pt { long long x, y; pt(long long _x, long long _y) { x = _x; y = _y; } pt() {} }; vector<pt> all[4 * maxN]; bool del(const pt...
22
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], pos = 1; for (int j = 0; j < n; j++) { cin >> a[j]; } sort(a, a + n); for (int i = 0; i < n; i++) { if (a[i] >= pos) pos++; } cout << pos - 1 << endl; return 0; }
2
#include<iostream> #include<vector> #include<stdio.h> #include<algorithm> #include<string.h> #include<math.h> ...
0
#include <bits/stdc++.h> const int N = 205, M = N * N; int n, m, f[M], cid[M], id[N][N], mod, ans, count; std::string s[N]; void no() { std::cout << "0\n", std::exit(0); } int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); } void link(int x, int y) { if (find(x) == find(y)) no(); f[find(x)] = find(y); } vo...
24
#include <bits/stdc++.h> using namespace std; const int64_t mod = 1e9 + 7; int64_t bpow(int64_t x, int64_t n) { if (n == 0) { return 1; } if (n % 2 == 0) { return bpow(x * x % mod, n / 2); } else { return x * bpow(x, n - 1) % mod; } } int64_t get(vector<int64_t> a, int64_t n, int64_t z) { a[0] =...
11
#include <bits/stdc++.h> using namespace std; long long t; long long MOD = 1000000007; void solve() { int n; cin >> n; string s; cin >> s; for (int i = n - 1; i >= 0; i--) { if (s[i] == '0') { if (i < n / 2) { cout << i + 2 << " " << n << " " << i + 1 << " " << n << "\n"; return; ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, minn, i, flag, maxx; flag = 0; cin >> n; long long int *ar; ar = new long long int[n]; for (i = 0; i < n; i++) { cin >> ar[i]; } minn = ar[0]; if (minn != 0) { cout << 1 << endl; return 0; } maxx = ar[0]; for (i ...
2
#include <bits/stdc++.h> using namespace std; string s; int t; int pref[27][(int)2e5 + 10]; int cnt[27]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> t; int n = s.size(); cnt[s[0] - 'a']++; pref[s[0] - 'a'][0] = cnt[s[0] - 'a']; for (int i = 1; i < n; ++i) { cnt[s[...
10
#include <bits/stdc++.h> using namespace std; map<string, int> S, hit, miss; map<string, int> played; set<string> teams; struct team { string name; int points; int diff; int goals; }; bool operator<(team a, team b) { if (a.points != b.points) return a.points > b.points; if (a.diff != b.diff) return a.diff >...
10
#include <bits/stdc++.h> long long S, N, K, x, F[2005], W[2005]; int main() { scanf("%I64d%I64d", &N, &K); for (int i = 1; i <= N; i++) for (int j = i + 1; j <= N; j++) { scanf("%I64d", &x); S += x < 0 ? 0 : x; if (x >= 0) { F[i] += x, F[j] += x, W[i]++, W[j]++; } } if (K !...
16
#include <bits/stdc++.h> using namespace std; const int MAXA = 1e5 + 10; int n, Mx = 0; pair<int, int> a[MAXA]; bool check(int x) { if (x > Mx + 15) return 1; long long currSize = 1LL; for (int i = 1; i <= n; i++) { int temp = x - a[i].first; if (temp > 15) continue; long long cur = 1LL; while (te...
8
#include <bits/stdc++.h> using namespace std; vector<int> id; vector<int> Zloz(vector<int>& a, vector<int>& b) { int n = a.size(); vector<int> wyn(n); for (int i = 0; i < n; ++i) wyn[i] = a[b[i]]; return wyn; } vector<int> Skladaj(vector<int>& p, int w) { if (w == 0) return id; if (w % 2 == 0) { vector<...
18
#include <bits/stdc++.h> using namespace std; void fun() { long long n, m; cin >> n >> m; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { if (i != 0) a[i] += a[i - 1]; } for (int i = 0; i < n; i++) { if (i - m >= 0) a[i] += a[i - m]; } f...
7
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> void pr(const pair<T1, T2>& x); template <class T, size_t SZ> void pr(const array<T, SZ>& x); template <class T> void pr(const vector<T>& x); template <class T> void pr(const set<T>& x); template <class T1, class T2> void pr(const map<T1, T2>& ...
9
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = 3.1415926535897932384626433832795; template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x...
20
#include <bits/stdc++.h> using namespace std; inline long long read() { long long X = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar(); return X * w; } const long long N = 1000000 + 10; ...
13
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int i = 0; i < q; i++) { long long n; cin >> n; int cnt = 0; while (n > 1) { if (n % 2 != 0 && n % 3 != 0 && n % 5 != 0) { cnt = -1; break; } if (n % 5 == 0) { n = n / 5; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int tc, o; scanf("%d", &tc); for (o = 1; o <= tc; o++) { long long n, m, a, b, c, d, e, f, g, p, q, r, fr, sc, tr, sz, tz, sz1, sz2, i, j, k, mx = -9, mn = 999999999999; string str, ttr, ntr; long long x = 0, y = 0, cnt = 0, res = -3, ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, M = 20; int par[M][maxn], d[maxn]; vector<int> adj[maxn]; void dfs(int v, int p) { par[0][v] = p; for (int i = 1; i < M; i++) par[i][v] = par[i - 1][par[i - 1][v]]; for (int u : adj[v]) { if (u == p) continue; d[u] = d[v] + 1; df...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int m = ceil((1.0 * (n + 1)) / 2); int x = 0; int y = 1; cout << m << endl; for (int i = 0; i < n; i++) { if (i < m) cout << ++x << " " << y; else { cout << x << " " << ++y; } cout << endl; } }
3
#include <bits/stdc++.h> using namespace std; const int dirx[4] = {0, 1, 0, -1}; const int diry[4] = {1, 0, -1, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); ; long long int t, n, x; cin >> t; while (t--) { cin >> n; vector<int> odd, even; for (int i = 0; i < n; i++) { cin >> x...
3
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int a, b; cin >> a >> b; unsigned long long int x = min(a, b); unsigned long long int out = 1; for (unsigned long long int i = 1; i <= x; i++) { out = out * i; } cout << out; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N]; vector<int> pos[22]; struct node { int x, y; node() {} node(int a, int b) { x = a; y = b; } bool operator<(const node &b) const { return x < b.x; } }; int main() { int n; while (scanf("%d", &n) != EOF) { set<int> re...
8
#include <bits/stdc++.h> using namespace std; int main() { long long int s, x; cin >> s >> x; long long int i, c = 1, f = 0; long long int a = (s - x) / 2; if ((s - x) % 2 != 0) cout << 0; else { for (i = 0; i < 64; i++) { long long int x1 = ((x >> i) & 1); long long int a1 = ((a >> i) &...
9
#include <bits/stdc++.h> using namespace std; string isgood(long long x) { string s = ""; while (x > 0) { if (x % 2 == 0) { s += "0"; } else { s += "1"; } x /= 2; } reverse(s.begin(), s.end()); return s; } int main() { long long a, b, C = 0, W = 0, pos, pos2; bool d = 1; cin ...
5
#include <bits/stdc++.h> using namespace std; const int N = 500000, A_I = 1 << 20; int n; int a[N + 1], b[N + 1]; vector<pair<int, pair<int, int> > > nei[A_I]; vector<int> reg[A_I]; vector<bool> ban[A_I]; int now[A_I]; vector<int> pa; void dfs(int x = a[1]) { for (int &i = now[x]; i < nei[x].size(); i++) if (!ban...
17
#include <bits/stdc++.h> using namespace std; namespace { template <int MOD> class IntMod { static_assert(0 < MOD and MOD <= numeric_limits<int>::max() / 2, "MOD out of range"); int val; public: IntMod() : val(0) {} IntMod(int64_t x) : val(static_cast<int>(x % MOD)) { if (val < 0) val += M...
21
#include <bits/stdc++.h> using namespace ::std; int INF = 2e9; int main() { ios::sync_with_stdio(false); ifstream fin("input.txt"); int n, k; cin >> n >> k; vector<long long> arr(n); long long sum = 0, mi = INF; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; if (((arr[i] - arr[0])...
1
#include <bits/stdc++.h> using namespace std; int64_t mod = 1e9 + 7; int64_t mult(int64_t n, int64_t k) { if (k == 1) { return n % mod; } else { if (k % 2 == 0) { int64_t ans = mult(n, k / 2); return (ans % mod + ans % mod) % mod; } else { int64_t ans = mult(n, k / 2); return ((a...
6
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int solve() { long long n; cin >> n; if (n == 1) return 1; long long curr_len = 1; long long curr_sum = 1; int ans = 0; while (curr_sum <= n) { n -= (curr_sum); curr_len = (2 * curr_len) + 1; curr_sum = (curr_len * (curr_len + 1)...
4
#include <bits/stdc++.h> const int N = 1000001; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, c; cin >> n >> m >> c; int a[n + 1]; fill(a, a + n + 1, c + 10); while (m--) { int e; cin >> e; if (e <= c / 2) { for (int i = 1;...
12
#include <bits/stdc++.h> using namespace std; constexpr long N = 200005; map<long, long> cnt; tuple<long, long, long> healths[N * 2]; long max_health[N], start_health[N], regen[N]; bool used[N]; set<long> update[N]; int main() { long n, m; long bounty, increase, damage; scanf("%d%d%d%d%d", &n, &m, &bounty, &incre...
17