solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int n, d; string s; int main() { cin >> n; cin >> s; for (int i = 0; i < s.size(); ++i) { if (s[i] == s[i + 1]) ++d; } cout << d; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; const int MAXN = 1005; const int MAXS = 11005; const long long MOD = 1e9 + 7; int n; int A[MAXN]; long long dp[MAXN][2 * MAXS]; int in(int x) { if (x < 0) return (-x + MAXS); return x; } void input() { cin >> n; for (int i = 1; i <= n; i++) ...
15
#include <bits/stdc++.h> using namespace std; int TestMillerRabin[12] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; long long mulmod(long long a, long long b, long long p) { long long x = 0, y = a % p; while (b > 0) { if (b % 2 == 1) x = (x + y) % p; y = (1LL * y * 2) % p; b = b / 2; } return x % ...
12
#include <bits/stdc++.h> using namespace std; int a[200010]; string s; vector<int> vec[200010]; int tot; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } cin >> s; s = '#' + s; for (int i = 1; i <= n; i++) { if (s[i] != s[i - 1]) { ++tot; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int a[300000]; for (int i = 0; i < N; i++) cin >> a[i]; sort(a, a + N); long long res = 0; for (int i = 0; i < N - 1; i++) res += (long long)(i + 2) * (long long)a[i]; res += (long long)N * (long long)a[N - 1]; cout << res << ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1005; const int K = 52; const int M = 200010; const int mod = int(1e9) + 7; void solve() { int t; scanf("%d", &t); for (int i = 0; i < t; ++i) { int n; scanf("%d", &n); vector<int> v; for (int j = sqrt(2 * n) + 1; j >= 2; --j) { if ...
11
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> arr(n); for (long long i = 0; i < n; i++) cin >> arr[i]; long long c1 = 0, c0 = 0; for (long long i = 0; i < n; i++) { if (arr[i] == 0) c0++; else if (arr[i] == 1) c1++; } long long ...
1
#include <bits/stdc++.h> using namespace std; vector<long long> g; vector<long long> doing; void win() { for (int i = 0; i < doing.size(); i++) { if (i % 2 == 0) { cout << "RUN "; } else { cout << "JUMP "; } cout << doing[i] << endl; } } int main() { long long n, m, s, d, a; cin >> n...
8
#include <bits/stdc++.h> using namespace std; int main() { int q, w, e, r, t, v; long long a[200001]; double y, c, s[200001]; cin >> q >> t >> y; a[0] = 0; s[0] = 0; for (w = 1; w <= q; w++) { scanf("%d", &e); s[w] = (s[w - 1] + e / ((double)t)) / y; a[w] = a[w - 1] + e; } cin >> v; for ...
7
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <utility> #include <limits> #include <math.h> #include <stdio.h> #include <string.h> #include<ioma...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct segment_tree { vector<long long> st; segment_tree(int n) : st(4 * n) {} void update(int node, int b, int e, int p, long long v) { if (b == e) st[node] += v, st[node] %= mod; else { int m = (b + e) >> 1; i...
15
#include <bits/stdc++.h> using namespace std; template <class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os << "(" << v.first << ", " << v.second << ")"; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = int(0); i <= int((static_cas...
9
#include <bits/stdc++.h> using namespace std; bool can[35][75 * 31][75]; int num[75]; int nnum[75]; int w[75][75]; int nx[35][75 * 31][75]; int ncnt[75]; struct th { int id, nnum; bool operator<(const th &a) const { return nnum < a.nnum; } } p[75]; int main() { int m; scanf("%d", &m); for (int i = 1; i <= m; ...
20
#include <bits/stdc++.h> using namespace std; int n, x, y, allVis, mask[28], d[28][28], memo[16777220]; pair<int, int> coord[28]; bool visited(int i, int vis) { return mask[i] & vis; } void DP() { for (int vis = allVis - 1; vis >= 0; vis--) { memo[vis] = 160001; for (int i = 1; i <= n; i++) { if (!visit...
12
#include <bits/stdc++.h> using namespace std; int const N = 1e6 + 1; int n; map<int, int> x, y; map<pair<int, int>, int> fr; vector<pair<int, int> > v; int main() { scanf("%d", &n); for (int i = 0, l, r; i < n; ++i) { scanf("%d%d", &l, &r); ++x[l]; ++fr[{l, r}]; ++y[r]; v.push_back({l, r}); } ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long l1, l2, r1, r2, k, sum = 0; cin >> l1 >> r1 >> l2 >> r2 >> k; long long l, r; l = max(l1, l2); r = min(r1, r2); sum = r - l + 1; if (k >= l && k <= r) sum = sum - 1; if (sum < 0) sum = 0; cout << sum; }
3
#include <bits/stdc++.h> using namespace std; bool cek(long long n, long long num) { long long a = (num % 5) / 1; num -= num % 5; long long b = (num % 10) / 5; num -= num % 10; long long c = (num % 50) / 10; num -= num % 50; long long d = num / 50; num -= num; if (a + b + c + d > n) return 0; el...
12
#include <bits/stdc++.h> const int MAXN = 3e5 + 15; using namespace std; long long modexp(long long a, long long p, long long mod) { if (p == 0) return 1; long long ans = modexp(a, p / 2, mod); ans = (ans * ans) % mod; if (p % 2) return (a * ans) % mod; else return ans; } pair<long long, long long> A[...
10
#include <bits/stdc++.h> using namespace std; const long long N = 1000005; const long long logN = 19; const long long M = 1000000007; const long long dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const long long dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; long long Y[N], num, den, inv[N]; long long n, k; long long power(long long a, l...
18
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0, cnt = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; sum = sum + a[i]; } for (int i = 0; i < n; i++) { if ((sum - a[i]) % 2 == 0) { cnt++; } } cout << cnt; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0; cin >> n; while (n--) { int before, after; string str; cin >> str; cin >> before >> after; if (before >= 2400 && after > before) { ans++; } } if (ans == 0) cout << "NO" << endl; else cout << "YES...
0
#include <bits/stdc++.h> using namespace std; int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); int n; string s; cin >> n >> s; int b = 0, g = 0, r = 0; for (int i = 0; i < int(n); i++) { if (s[i] == 'B') b++; if (s[i] == 'G') g++; if (s[i] == 'R') r++; } if (b == 0 && g == 1)...
5
#include <bits/stdc++.h> using namespace std; const int Nmax = 1e6 + 5; map<int, int> mp; int x[Nmax], y[Nmax], c[Nmax]; long long curr; vector<pair<int, int>> start[Nmax]; int where[Nmax]; int n, l, best; class SegTree { long long a[Nmax << 2]; long long lazy[Nmax << 2]; int pos[Nmax << 2]; inline void cobor(i...
16
#include <bits/stdc++.h> using namespace std; void process(queue<long long int> &q, vector<vector<long long int> > &v, long long int idx, vector<long long int> &taken, vector<long long int> &mark) { for (long long int i = 0; i < v[idx].size(); i++) { if (!taken[v[idx][i]]) { taken[...
9
#include<bits/stdc++.h> using namespace std; #define ar array #define ll long long #define FOR(n) for(int i = 0; i < n; ++ i) #define FOR1(n) for(int ii = 0; ii < n; ++ ii) const int MAX_N = 1e5 + 1; const ll MOD = 1e9 + 7; const ll INF = 1e9; int main() { int t; cin>>t; FOR(t) { int num; ci...
6
#include <bits/stdc++.h> using namespace std; const int maxN = 500 * 1000 + 321; const int mod = 1000 * 1000 * 1000 + 7; int a[60]; int dp[maxN]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, d; cin >> n >> d; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = 1; sort(a, a + n); int sum = 0; ...
14
#include <bits/stdc++.h> using namespace std; vector<int> L, R, res; vector<pair<pair<int, int>, int> > v, final; bool mark[10000007]; int ans[10000007]; int main() { int n, x, y; cin >> n; priority_queue<pair<pair<int, int>, int> > pq; for (int i = 0; i < n; i++) { cin >> x; L.push_back(x); cin >> ...
11
#include <bits/stdc++.h> using namespace std; const long long N = 4e14 + 5; struct node { int size; node *childL, *childR; node() { size = 0; childL = childR = this; } node(int s, node* l, node* r) { size = s; childL = l; childR = r; } }; struct segment_multiset { node *nil, *root; s...
10
#include <bits/stdc++.h> using namespace std; const long long mod1 = static_cast<long long>(1073741824); const long long mod2 = static_cast<long long>(1000000007); const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; const long double ldOne = 1.0; long long gcd(long long a, long long b) { if (!b) ...
5
#include <bits/stdc++.h> using namespace std; int main() { string a, b; getline(cin, a); getline(cin, b); int cnt = 0; for (int j = 0; j < b.size(); j++) { for (int i = 0; i < a.size(); i++) { if (a[i] == b[j] && a[i] != ' ') { a[i] = '.'; cnt++; break; } } } in...
3
#include <bits/stdc++.h> using namespace std; int main(void) { long long n, k; cin >> n >> k; long long m = k * (k + 1) / 2; if (k >= 150000 || m > n) { printf("-1"); return 0; } long long sn = sqrt(n), ans = 0; for (long long i = 1; i <= sn; ++i) if (n % i == 0) { if (n / i >= m) ans = ...
11
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) { return b; } return gcd(b % a, a); } long long int power(long long int x, long long int y) { long long int res = 1; while (y > 0) { if (y % 2 == 1) { res = (res * x); } x = (x...
9
#include <bits/stdc++.h> using namespace std; inline long long Readint() { long long ret = 0; int f = 1; char ch; do { ch = getchar(); if (ch == '-') f *= -1; } while (ch >= 0 && (ch < '0' || ch > '9')); while ('0' <= ch && ch <= '9') { ret = ret * 10 + ch - '0'; ch = getchar(); } return...
17
#include <bits/stdc++.h> using namespace std; const int MAX = 100000 + 5; const int INF = (int)1e9; class tri { public: int first, second, z; int ind; tri(int first, int second, int z, int i) { this->first = first, this->second = second, this->z = z, this->ind = i; } }; inline bool cmp(tri a, tri b) { re...
19
#include <bits/stdc++.h> using namespace std; int dp[205][205][205], zagrada[205][205][205]; char s[205], t[205]; int n, m; int resi(int l, int d, int zbir) { if (dp[l][d][zbir] + 1) return dp[l][d][zbir]; if (zbir == 0) { dp[l][d][zbir] = 1 + resi((s[l] == ')' ? l - 1 : l), (t[d] ...
14
#include <bits/stdc++.h> using namespace std; int Max(int a[], int n) { int max = a[0]; for (int i = 0; i < n; i++) if (max < a[i]) max = a[i]; return max; } int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < v.size(); i++) cin >> v[i]; int I; I = *max_element(v.begin(), v.end());...
0
#include <bits/stdc++.h> using namespace std; long long pow(long long x, long long y) { long long res = 1; x = x % 1000000007; if (x == 0) return 0; while (y > 0) { if ((y & 1) == 1) res = (res * x) % 1000000007; y >>= 1; x = (x * x) % 1000000007; } return res; } long long count(long long v, lon...
13
#include <bits/stdc++.h> using namespace std; const long long MAX = 1 << 18, N = 1e6 + 10, MOD = 998244353; long long n; long long silnia[N]; long long odsilnia[N]; long long pot3[N], pot1[N]; long long qpow(long long a, long long b) { if (b == 0) return 1; else if (b % 2 == 1) return (a * qpow(a, b - 1)) %...
17
#include<bits/stdc++.h> #define forn(i,n) for(int i=0;i<(int)(n);i++) #define form(i,n) for(int i=1;i<=(int)(n);i++) using namespace std; typedef vector<int> vi; #define ll long long void solve() { int n,m; cin>>n; int a[n]; forn(i,n) { cin>>a[i]; } cin>>m; int b[m]; forn(i,m) { cin>>b[i]; } int l=0,x=...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, maxl = 110; bool mark[maxl][maxn]; int dis[maxn][maxl]; vector<int> v[maxn]; vector<int> adj[maxn]; void bfs(int u) { queue<int> q; for (auto x : v[u]) q.push(x), mark[u][x] = 1, dis[x][u] = 0; while (!q.empty()) { int z = q.front(); ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x = 0, c = 0, c2 = 0; char search[101][101], find_max = '0'; cin >> n >> m; for (int i = 0; i < n; i++) for (int i2 = 0; i2 < m; i2++) cin >> search[i][i2]; while (x < m) { for (int i = 0; i < n; i++) find_max = max(search[i][x], fin...
1
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int inf = 50000000; const int maxn = 300010; int rnk[maxn], parent[maxn], diameter[maxn], seen[maxn], dist[maxn], n; vector<int> adj[maxn], vis; int find(int x) { if (parent[x] == x) return x; return parent[x] = find(parent[x]); } void ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int t; int seg[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; cin >> t; while (t--) { int n; cin >> n; if (n % 2 == 0) { int k = n / 2; for (int i = 0; i < k; ++i) { ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = (int)5e6 + 100; const int M = (int)(1 << 22) - 1; const int mod = (int)1e9 + 7; const int P = mod; inline int getint() { char _c = getchar(); int _x = 0, _s = 1; while (_c <= 32) _c = getchar(); if (_c == '-') _s = -1, _c = getchar(); while ('0' <...
14
#include <bits/stdc++.h> using namespace std; void puzzle() { double a, b, c; cin >> a >> b >> c; if (c > a) { cout << 1 << " "; } else { cout << -1 << " "; } if ((a * b > c)) { cout << (int)b << " "; } else { cout << -1 << " "; } cout << "\n"; } int main() { ios_base::sync_with_stdi...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<long long int> arr; for (int i = 0; i < n; i++) { long long int x; cin >> x; arr.insert(x); } for (int i = 0; i < 32; i++) { for (auto x : arr) { if (arr.find(x - (long long int)pow(2, i)) != arr.end() && ...
10
#include <bits/stdc++.h> using namespace std; bool home = 1; signed realMain(); signed main() { home = 0; if (home) { freopen("input", "r", stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } realMain(); } const long long N = 14; const long long INF = (long long)1e18; long long n, m; vector<lo...
20
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n; cin >> n; string x; cin >> x; int cnt = 0; for (i = 0; i < n - 1; i += 2) { if (x[i] == 'a' && x[i + 1] != 'b') { cnt++; x[i + 1] = 'b'; } else if (x[i] == 'b' && x[i + 1] != 'a') { cnt++; x[i + 1] = 'a';...
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } long long Max(long long a, long long b) { return a > b ? a : b; } long long Min(long long a, long long b) { return a < b ? ...
4
#include <bits/stdc++.h> using namespace std; vector<int> Ans[200010]; int p, cnt, n = 1; int main() { for (char ch = getchar(); isdigit(ch); ch = getchar(), n++) if (ch == '1') { if (!p) { printf("-1\n"); return 0; } Ans[p--].push_back(n); } else if (p == cnt) Ans[p = ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 3e6 + 123; const int INF = 1e9 + 9; const int maxval = 3e6; bool is_prime(int x) { for (int i = 2; i * i <= x; ++i) if (x % i == 0) return 0; return 1; } bool is_cm[maxn]; void Eratosthenes() { is_cm[1] = 1; for (int i = int(2); i <= int(maxval)...
8
#include <bits/stdc++.h> using namespace std; int T, n, m; int main() { scanf("%d", &T); while (T-- > 0) { scanf("%d%d", &n, &m); int fr = 1, to = 2; for (int i = 1; i <= 2 * n + m; ++i) { printf("%d %d\n", fr, to); if (to == n) to = ++fr; ++to; } } return 0; }
7
#include <bits/stdc++.h> using namespace std; struct trio { int first; int second; int third; }; struct long_trio { long long first; long long second; long long third; }; const int MOD = 1000000007; const long long INF = 1e18 + 2; const int LIT = 505; const int BIG = 200001; string months[12] = {"January", ...
15
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n, k, a[N], res; long long s[N]; int main() { ios::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + 1 + n); for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + a[i]; int l = 0, r = 1e9; whi...
12
#include <bits/stdc++.h> using namespace std; long long signed pow_(long long signed a, long long signed e, long long signed m = 1000000007) { long long signed r = 1; while (e) { if (e & 1) r = r * a % m; a = a * a % m; e >>= 1; } return r; } long long inv(long long signed a) {...
7
#include <bits/stdc++.h> using namespace std; long long a, b, x, y; bool check(long long mid) { long long xx = mid - mid / x; long long yy = mid - mid / y; long long zz = mid / (x * y); if (xx < a || yy < b) return false; if (mid - zz >= a + b) return true; return false; } int main() { scanf("%I64d%I64d%I...
10
#include <bits/stdc++.h> using namespace std; char s[200010]; int tmp[200010], len[200010], fa[200010], ch[200010][26], sz[200010], last, node, id[200010]; void init() { last = node = 1; memset(ch, 0, sizeof(ch)); memset(sz, 0, sizeof(sz)); memset(tmp, 0, sizeof(tmp)); memset(fa, 0, sizeof(fa)); } void in...
15
#include <bits/stdc++.h> using namespace std; vector<long long> gp[1001]; long long k1, k2, n, flag; set<long long> x, y; long long ans; long long dfs(long long st, long long par) { if (flag == 1) return 0; if (x.count(st) == 1) { flag = 1; cout << "A " << st << endl << flush; long long val; cin >> ...
11
#include <bits/stdc++.h> using namespace std; pair<int, int> tmp[200010]; struct Edge { int from, to, weight, id; }; struct P { int first, second, id; }; struct cmp { bool operator()(P a, P b) { return a.first > b.first; } }; int n, m, s; vector<int> G[200010]; Edge edges[200010 << 1]; priority_queue<P, vector<P>...
19
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const int MAXN = 200100; pair<int, int> V[MAXN]; int t[6 * MAXN], cnt = 0; int order[MAXN]; bool redundant[MAXN]; int main() { cin.sync_with_stdio(0); cin.tie(nullptr); fill(redundant, redundant + MAXN, true); for (int i = 0; i < MA...
12
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; const int N = (int)1e6 + 7; const int MOD = (int)1e9 + 7; const int INF = (int)2e7; const long long BIG = 1e18; int prime[N]; int a, b, k; int cnt_pr(int l, int r) { return prime[r] - prime[l - 1]; } bool valid(int l) { ...
8
#include <bits/stdc++.h> using namespace std; int n, i, j, a, b[200010], ans; int main() { cin >> n; ans = 1; b[0] = 1; for (i = 1; i <= n; i++) { cin >> a; if (b[a] != 0) { b[a] = 0; b[i] = 1; continue; } ans++; b[i] = 1; } cout << ans << endl; return 0; }
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; bool linha[N], coluna[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; long long tot = 1LL * n * n; int totLinha = 0, totColuna = 0; for (int i = 0; i < (int)m; i++) { int foo, bar; cin >> foo >> bar...
4
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; const int M = 1000000007; const double PI = atan(1) * 4; const int oo = 1000000000; int n, ct, b, p0 = -1, p1 = -1; string s; int cttt; int que() { assert(++cttt <= 15); printf("? %s\n", s.c_str()); fflush(stdout); int x; scanf("%d", &x)...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; vector<int> val(n); for (auto &i : val) cin >> i; int a, b; long long res = 0; for (int i = 0; i < m; ++i) { cin >> a >> b; long long t = 0; for (int j = a - 1; j < b; ++j) t += ...
4
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; const int mod=1e9+7; int T; int n,l,r; int frac[N],inv[N]; void init(){ frac[0]=frac[1]=inv[0]=inv[1]=1; for(int i=2;i<N;i++)frac[i]=1ll*frac[i-1]*i%mod,inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod; for(int i=2;i<N;i++)inv[i]=1ll*inv[i]*in...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, l, k, m; cin >> n >> l; cin >> k >> m; vector<int> vec1(n); vector<int> vec2(l); for (int i = 0; i < n; i++) cin >> vec1[i]; for (int i = 0; i < l; i++) cin >> vec2[i]; int max = vec1[k - 1]; int s = 0; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long int> d; for (long long int i = 1; (i * i) <= n; i++) { if (n % i) continue; d.push_back(i); if (i != n / i) d.push_back(n / i); } sort(d.rbegin(), d.rend()); for (int j : d) { long long int sum = 1...
6
#include <bits/stdc++.h> using namespace std; void solve() { int n = 0, m = 1, a = 0, b = 0, k = 0, x = 0, p = 0, q = 0, r = 0, y = 0, c = 0, z = 0, g = 0, h = 0, i = 0; cin >> n; vector<int> st(n), gh(n); for (int i = 0; i < n; i++) cin >> st[i]; for (int i = 0; i < n; i++) cin >> gh[i]; sort(gh.begi...
5
#include <bits/stdc++.h> using namespace std; template <class T> inline T Tmin(const T &lch, const T &rch) { if (lch < rch) return lch; return rch; } template <class T> inline T Tmax(const T &lch, const T &rch) { if (lch < rch) return rch; return lch; } const int Inf = 0x3f3f3f3f; const int Mod = 998244353; con...
20
#include <bits/stdc++.h> const long long MXN = 1e5 + 3; const long long MNN = 1e3 + 1; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long long OO = 1e9 + 500; using namespace std; string s; long long even, odd, d1[MXN]; long long l, r; int main() { ios_base::sync_with_stdio(0), cout.tie(0), cin.tie...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, k; while (scanf("%d %d", &n, &k) != EOF) { if (n == 1) { if (k == 1) puts("a"); else puts("-1"); } else if (k == 1 || k > n) puts("-1"); else { int m = n - (k - 2); for (int i = 0; i < m / 2; ...
5
#include <bits/stdc++.h> using namespace std; char str1[100005], str2[100005]; int len1, len2; int sbc1[100005], sbc2[100005]; int sua1[100005], sua2[100005]; int Q; int main() { scanf("%s%s", str1 + 1, str2 + 1); len1 = strlen(str1 + 1), len2 = strlen(str2 + 1); for (int i = 1; i <= (len1); ++i) sbc1[i] = sb...
17
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5, Mod = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n, m; cin >> n >> m; long long x = n * (n + 1); x /= 2; map<long long, long long> mp; long long r = 0; string s = ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1001, Q = 100005; struct FNode { bitset<N> *bs[N]; int sum; }; int n, m, q; FNode *place(FNode *f, int i, int j) { i--; FNode *new_f = new FNode(); *new_f = *f; new_f->bs[i] = new bitset<N>(); *new_f->bs[i] = *f->bs[i]; bitset<N> *t = new_f->bs...
14
#include <bits/stdc++.h> using namespace std; template <class T> void splitstr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } static void redirec...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 101; string home, b, c[maxn]; int ans1, ans2; int main() { int n; scanf("%d", &n); cin >> home; for (int i = 1; i <= n; i++) { cin >> b; c[i] = b.substr(0, home.length()); } for (int i = 1; i <= n; i++) { if (c[i].compare(0, home.len...
1
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> v; int t, n; long long s; bool ok(int x) { vector<pair<int, int>> b, c; int cnt = 0; long long aux = 0; for (const auto& [l, r] : v) if (r < x) cnt++, aux += l; else if (x < l) aux += l; else c.emplace_back(l, r);...
11
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3f; long long dx[] = {0, 1, 1, 1, 0, -1, -1, -1}; long long dy[] = {1, 1, 0, -1, -1, -1, 0, 1}; long long func(map<long long, long long> &m) { long long ans = 0; long long val = 0; for (pair<long long, long long> p : m) { ans ...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, a, x, b, y; cin >> n >> a >> x >> b >> y; while (a != x && b != y) { if (a == b) { cout << "YES"; return 0; } if (a + 1 <= n) { a++; } else { a = 1; } ...
1
#include <bits/stdc++.h> using namespace std; const long long N = 150010; long long n, m, c, x[N], a, b, p; double val[N]; struct node { double l, r, m, s; } nd[N << 2]; void build(long long x, long long l, long long r) { if (l == r) { nd[x].l = nd[x].r = nd[x].m = nd[x].s = val[l]; return; } long long ...
14
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, r; cin >> n >> r; if (n > r) cout << (r * (r + 1)) / 2 << endl; else cout << ((n * (n - 1)) / 2 + 1) << endl; } return 0; }
4
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int INF = 1e9 + 7; const int N = 1e5 + 10; long long n, m, t, k, len, sum; int a[N]; char s[N], str[N]; bool vis[N], f; string arr; struct node { int id, v; } p[N]; struct nod1 { int v, x, y; } b[N]; bool cmp(node a, node b) { if (a.v !=...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-all-loops") #pragma GCC target("sse4.2") using namespace std; ifstream in; ofstream out; const long long kk = 1000; const long long ml = kk * kk; const long long mod = ml * kk + 7; const long long inf = ml * ml * ml + 7; long long n; vector<long long> v; bool ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int MOD = 1e9 + 7; int X[maxn], a[maxn], val[maxn]; int main() { int N, H; int prex = 0, prey = 0; cin >> N >> H; H--; int x, y; for (int i = 1; i <= N; i++) { cin >> x >> y; val[i] = y - x; X[i] = x; a[i] = x - pr...
9
#include <bits/stdc++.h> const long long int M = 1e9 + 7; using namespace std; int main() { int t, n, m, ck, i = 0, j, rice; char ptn[65], mt[200][200], ans[200][200]; for (j = '0'; j <= '9'; j++) ptn[i++] = j; for (j = 'a'; j <= 'z'; j++) ptn[i++] = j; for (j = 'A'; j <= 'Z'; j++) ptn[i++] = j; ptn[i] = '\...
9
#include <bits/stdc++.h> using namespace std; bool non_coprime(int b, int s) { int mod = 1, gcd; while (mod) { gcd = s; mod = b % s; b = s; s = mod; } return (gcd > 1); } int main() { long k, p, i = 0; vector<long> v; int m, n; cin >> k; for (m = sqrt(k); m > 1; m--) { for (n = 1 +...
4
#include <bits/stdc++.h> using namespace std; const long long mx = 1e18; int n; vector<long long> v; long long a[25]; int main() { long long hgf = 1; a[1] = 1; for (int i = 2; i <= 17; ++i) { hgf *= 10; a[i] = hgf; } long long k = 90; long long sum = 9; v.push_back(0); v.push_back(9); for (int...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; const int MOD = 998244353; template <class T1, class T2> istream& operator>>(istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; } template <class T> ...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 500005; int n, m, l, r, mx, a[maxn]; int dp[maxn][22]; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> l >> r; a[l] = max(a[l], r); mx = max(mx, r); } for...
14
#include <bits/stdc++.h> int read() { int res = 0, c; do c = getchar(); while (c < '0' || c > '9'); while ('0' <= c && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } return res; } const int size = 1 << 17; std::complex<double> root[size], invR[size]; int tot; void init(int n) { tot = n; ...
24
#include <bits/stdc++.h> using namespace std; void fw_update(vector<int> &f, vector<int> &d, int pos, int v, int x) { int diff = min(v + d[pos], x) - min(d[pos], x); for (int i = pos; i < f.size(); i += i & (-i)) { f[i] += diff; } d[pos] += v; } int fw_sum(vector<int> &f, int pos) { int res = 0; for (in...
9
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0); template <class T> void show(T a) { for (auto x : a) cout << x << " "; cout << endl; } const string DIGITS = "0123456789"; const int LOG = 21; const int N = 1 << LOG; complex<double> w[N]; int rev[N]; inline void init_fft() { double an...
18
#include <bits/stdc++.h> using namespace std; long long vis[2000005]; long long cnt; vector<long long> v[2000005]; vector<long long> v1; void dfs(long long node) { v1.push_back(node); cnt++; vis[node] = 1; for (long long i = 0; i < v[node].size(); i++) { if (vis[v[node][i]] == 0) dfs(v[node][i]); } } int ...
6
#include <bits/stdc++.h> using namespace std; struct abc { bool lr; int coor, index, coor2; }; bool comp(abc a, abc b) { if (a.coor != b.coor) return a.coor < b.coor; if (a.lr != b.lr) return a.lr < b.lr; if (a.coor2 != b.coor2) return a.coor2 > b.coor2; return a.index < b.index; } signed main() { int n, ...
10
#include <bits/stdc++.h> using namespace std; map<vector<int>, int> s; int main() { int n; cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; int a[n]; int cnt[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; cnt[i] = __builtin_popcount(a[i]); } for (int i = 0; i < (1 << 15); ++i...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, i; int a[150]; while (~scanf("%d", &n)) { int sum = 0; int t = 0; for (i = 1; i <= n; i++) { scanf("%d", &a[i]); sum += a[i]; } for (i = 1; i <= n; i++) { if ((sum - a[i]) % 2 == 0) t++; } printf("%d\n"...
1
#include <bits/stdc++.h> using namespace std; static inline void canhazfast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T extgcd(T a, T b, T &x, T &y) { T x0 = 1, y0 = 0, x1 = 0,...
18
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e9 + 9; const int N = 1e5 + 10; int n; struct Node { long long x, y; Node(long long X = 0, long long Y = 0) { x = X, y = Y; } } p[N]; long long miny[2][N], maxy[2][N]; bool cmpx(Node A, Node B) { return A.x < B.x; } ...
21
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const double PI = 3.1415926535; inline int sgn(double x) { return (x > eps) - (x < -eps); } struct Point { double x, y; Point() : x(0), y(0) {} Point(double _x, double _y) : x(_x), y(_y) {} void set(double _x, double _y) { this->x = _x; ...
20