solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { long long b1, q, l, m; cin >> b1 >> q >> l >> m; long long bad = 0; set<long long> prev; for (long long i = 0; i < m; ++i) { long long a; cin >> a; long long cop = a; prev.insert(cop); } long long ans = 0; int i = 0; vector<lon...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int a; while (cin >> a) { if (a == 20) cout << 15; else if (a <= 10 || a >= 22) cout << 0; else if ((a >= 11 && a <= 21)) cout << 4; else cout << 10; cout << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; long long dp[20][20]; int p[20][20]; long long e10[19]; const int H = 1, M = 2; int main() { { if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL...
16
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } const int maxn = 200200; const int mod = 1000000007; int n, k, a, b, q; pair<int, int> t[maxn << 2]; pair<int, int> combine(pair<int, in...
9
#include <bits/stdc++.h> using namespace std; const long long mo = 1000000007; template <typename _T> _T Fabs(_T x) { return x < 0 ? -x : x; } template <typename _T> void read(_T &x) { _T f = 1; x = 0; char s = getchar(); while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while ('...
16
#include <bits/stdc++.h> using namespace std; int a[1010], n, k; int main() { while (cin >> n >> k) { for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { int j; for (j = 1; j <= n; j++) if (!a[j]) break; cout << j << ' '; for (int q = 1; q <= j - k; q++) a[...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, p[N], bulb[N]; int main() { memset(bulb, -1, sizeof(bulb)); ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n; for (int i = (2); i <= (n); ++i) cin >> p[i], bulb[p[i]] = 0; for (int i = (1); i <= (n); ++i)...
8
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long LINF = 2e18; void inv(bool e); template <typename T> void die(T& a); bool brute, alter; int cnt_tests = 1; int n; vector<int> arr; void inp() { cin >> n; int x; for (int i = 0; i < n; i++) { cin >> x; arr.push_back(x); } ...
9
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int p; cin >> p; while (p--) { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; if (a == 1 && b == 0 && c == 0 && d == 1 && e ==...
18
#include <bits/stdc++.h> using namespace std; bool check(string w, vector<string> s, long long int m) { for (long long int i = 0; i < s.size(); i++) { long long int dif = 0; for (long long int j = 0; j < m; j++) if (s[i][j] != w[j]) dif++; if (dif > 1) return false; } return true; } void solve()...
9
#include <bits/stdc++.h> using namespace std; vector<long long> G[100010], ter; long long n, root, c[100010], par[100010], dt[100010][2], ans; void dfs(int v, int pv) { dt[v][0] = 1; dt[v][1] = 0; for (int w : G[v]) if (w != pv) { dfs(w, v); dt[v][1] *= dt[w][0]; dt[v][1] += dt[v][0] * dt[w]...
12
#include <bits/stdc++.h> using namespace std; char ln[200000], b[20][20]; int dg[20]; int main() { gets(ln); int n, i, j, k, l, r = 0, st, t, q = 0; scanf("%d ", &n); for (i = 0; i < n; i++) gets(b[i]); for (i = 0; i < n; i++) { dg[i] = 20; for (j = 0; j < n; j++) { for (k = 0; b[i][k]; k++) { ...
10
#include <bits/stdc++.h> using namespace std; inline int read() { int sum = 0; char c = getchar(); bool f = 0; while (c < '0' || c > '9') { if (c == '-') f = 1; c = getchar(); } while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); } if (f) return -sum; return sum; } ...
17
#include <bits/stdc++.h> using namespace std; int dp[10500], s[120], a[120]; int main() { int n, m, nn; cin >> n >> m; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) { cin >> nn; a[0] = 0; for (int j = 1; j <= nn; j++) { cin >> a[j]; a[j] += a[j - 1]; } memset(s, 0, sizeo...
11
#include <bits/stdc++.h> const long long MaxN = 1e6 + 50; const long long MaxM = 1050; const long long p = 1e9 + 7; template <class t> inline void read(t &s) { s = 0; register long long f = 1; register char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)...
15
#include <bits/stdc++.h> using namespace std; long long fun(int n, int m) { long long s = 1; for (int i = 1; i <= m; i++) { s *= n; s %= 1000000007; } return s; } int main() { int n, k; long long s; cin >> n >> k; s = fun(n - k, n - k) * fun(k, k - 1); s = s % 1000000007; cout << s << endl; ...
7
#include<bits/stdc++.h> using namespace std; int t, n; long long b[200005]; long long sum; int main() { ios::sync_with_stdio(0); cin >> t; while(t--) { cin >> n; for(int i = 1; i <= n + 2; i++) cin >> b[i]; sort(b + 1, b + n + 1 + 2); sum = 0LL; for(int i = 1; i <= n; i++) sum += b[i]; long long ...
4
#include <bits/stdc++.h> using namespace std; int break_point() { char c; while ((c = getchar()) != '\n') ; return 0; } template <typename T> void read_integer(T &r) { bool sign = 0; r = 0; char c; while (1) { c = getchar(); if (c == '-') { sign = 1; break; } if (c != ' ' &...
7
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> ostream& operator<<(ostream& o, const pair<T, U>& x) { o << "(" << x.first << ", " << x.second << ")"; return o; } template <typename T> ostream& operator<<(ostream& o, const vector<T>& x) { o << "["; int b = 0; for (auto& a : x) ...
14
#include <bits/stdc++.h> using namespace std; char str[150], ch[150]; int main() { int n, q; scanf("%d%d", &n, &q); scanf("%s", str + 1); while (q--) { int l, r; scanf("%d%d", &l, &r); memset(ch, '\0', sizeof(ch)); for (int i = 1; i <= r - l + 1; i++) ch[i] = str[i + l - 1]; int dir = 1, s[1...
7
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); long long tt; cin >> tt; vector<long long> three; long long count = 1; while (count <= 2000000000000000000) { three.push_back(count); count *= 3; } while (tt--) { long long n; cin >> ...
5
#include <bits/stdc++.h> using namespace std; int n, k, d, t, i, j, sz; set<int> s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> t; while (t--) { cin >> n >> k >> d; int a[n]; int mn = n + 1; for (i = 0; i < n; ++i) cin >> a[i]; for (i = 0; i + d - 1...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n, p[maxn]; bool vis[maxn]; int main() { scanf("%d", &n); for (int i = 1; i < n + 1; i++) scanf("%d", p + i); int max1 = 0, max2 = 0; long long ans = 0; for (int i = 1; i < n + 1; i++) if (!vis[i]) { int len = 0; i...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k, flag = 1; cin >> n >> k; if (k % 3 == 0) { n %= (k + 1); if (n != k && n % 3 == 0) flag = 0; } else { if (n % 3 == 0) flag = 0; } cout << (flag ? "Alice\n" : "Bob\n"); } ...
9
#include <bits/stdc++.h> using namespace std; int a[1000111]; int main() { int n, w; scanf("%d", &n); memset(a, 0, sizeof a); for (int i = 0; i < (int)(n); i++) { scanf("%d", &w); a[w]++; } int ans = 0; for (int i = 0; i < (int)(1000100); i++) { a[i + 1] += a[i] / 2; ans += a[i] & 1; } ...
7
#include <bits/stdc++.h> using namespace std; int h[100005]; int n, a, r, m; long long costMv(long long x, long long y) { return x * m + y * (a + r); } long long cost(int target) { long long dp = 0; long long dm = 0; for (int(i) = 0; (i) < (n); (i)++) { if (h[i] > target) { dp += h[i] - target; } ...
13
#include <bits/stdc++.h> using namespace std; const int N = 100050, M = 40; long long a[N], x[N], y[N]; long long num; struct trie { trie *next[2]; trie() { next[0] = next[1] = 0; } void insert(int i = M) { if (i == -1) return; bool ind = num & (1LL << i); if (next[ind] == 0) next[ind] = new trie(); ...
14
#include <bits/stdc++.h> using namespace std; struct A { int all; int start; } all[200005]; int ans[200005]; bool F(A a, A b) { return a.all < b.all; } priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > how; int main() { int N, M, K, i, j, now = 1; pair<int, in...
8
#include <bits/stdc++.h> const int N = 200500; using namespace std; int n, tdx, tdy, vtmn, vtmx; int sm[N][3]; string s; bool cx[5]; void out() { exit(0); } bool check(int k) { int xn, yn, xt, yt; for (int x = 1; x <= n + 1 - k; x++) { xn = sm[n][0] - sm[x + k - 1][0] + sm[x - 1][0]; yn = sm[n][1] - sm[x + ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[m + 1], b[m + 1], i; for (i = 0; i < m; i++) cin >> a[i] >> b[i]; string s; for (i = 0; i < n; i++) { if (i % 2 == 0) s += '1'; else s += '0'; } cout << s << endl; }
5
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int count = 0; int i; while (n) { i = n % 10; n /= 10; count++; } if (count == 1) count = 1; else if (count == 2) count = 3; el...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 400005; const long long MOD = 1000000007; const long long INF = (long long)1e9 + 5; struct ACA { static const int MAXL = 400005, SIGMA = 26; int n, link[MAXL], next[MAXL][SIGMA]; int trie[MAXL][SIGMA], tag[MAXL], nocc[MAXL]; int new_node(int p) { ...
19
#include <bits/stdc++.h> using namespace std; int n, k, t, tmp, ans1, ans2; int cnt, a[110]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &k); t = k >> 1; for (int i = 1; i <= t; i++) { scanf("%d", &tmp); ans1 += tmp; } if (k & 1) { scanf("%d", &tmp)...
12
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); const long long INF = 0x3f3f3f3f3f3f3f3f; const int inf = 0x3f3f3f3f; const int N = 2e5 + 5; int n; int a[N]; int b[N]; int c[N]; vector<int> e[N]; int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; vector<int> d[N]; v...
12
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; int n, m; vector<int> G[MAX]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b); G[a].push_back(b); G[b].push_back(a); } if (m == n - 1) { int flag = 0; for (int i = 1;...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; void solve() { string s; cin >> s; int n; cin >> n; vector<int> v(n); string res(n, 'a'); for (int i = 0; i < (n); ++i) { cin >> v[i]; } vector<int> alpha(26, 0); for (auto c : s) { alpha[c - 'a']++; } int j ...
10
#include <bits/stdc++.h> using namespace std; long long int c(long long int x) { if (x < 10) return x; long long int y = x, a = x % 10; while (y / 10) y /= 10; x = x / 10 + 9; if (a < y) return x - 1; return x; } int main() { long long int a, b; cin >> a >> b; cout << c(b) - c(a - 1); }
7
#include <bits/stdc++.h> using namespace std; vector<int> edge[5010]; int size[5010], dp[5010], ans[5010], n; void solve(int cur, int pre) { size[cur] = 1; for (vector<int>::iterator iter = edge[cur].begin(); iter != edge[cur].end(); iter++) if (*iter != pre) solve(*iter, cur), size[cur] += size[*iter]; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 300010; vector<pair<int, char> > gr[N]; vector<int> nivel[N]; pair<int, int> pai[N]; int dist[N]; int solve(vector<int> at, int root) { if ((int)at.size() <= 1) return root ? (int)at.size() : 0; int res = 0; for (char c = 'a'; c <= 'z'; c++) { vector...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int i, j = 0, k, a = 0, b = 0, n, m, x; vector<int> vec, vec1; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> x; vec.push_back(x); vec1.push_back(x); } sort(vec.begin(), vec.end()); ...
3
#include <bits/stdc++.h> using namespace std; int n, k, ans, aux, maximum; int kit[150]; set<int> kitchen; set<int>::iterator it; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &aux); kit[aux]++; kitchen.insert(aux); maximum = max(maximum, kit[aux]); } maximum = ce...
1
#include <bits/stdc++.h> using namespace std; const int oo = 1 << 29, N = 1e5 + 10; const long double PI = acos(0.0) * 2; int btns, lights, x, tmp; bool vis[N]; int main() { cin >> btns >> lights; for (int i = 0; i < btns; ++i) { cin >> x; for (int j = 0; j < x; ++j) { cin >> tmp; vis[tmp - 1] =...
0
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; const long long INF = 1011111111; const long long LLINF = 1000111000111000111LL; const long double EPS = 1e-10; const long double PI = 3.14159265358979323; using namespace std; long long powm(long long base, long long exp, long long mod = MOD) { long long ans = ...
16
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, i, j, cnt = 0; cin >> n >> m; char x; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> x; if ((i == n - 1 && x == 'D') || (j == m - 1 && x == 'R')) cnt++; } } cout << cnt << endl; } int main() { in...
0
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 5e5 + 5, M = 1e6 + 5; int n, q, sz, a[N], mn[2100000], nm[2100000], la[2100000]; void upd(int x) { if (la[x] != 0) { la[2 * x + 1] += la[x]; la[2 * x + 2] += la[x]; if (mn[2 * x...
25
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; while (cin >> n >> m) { string s; cin >> s; char minn = s[0], maxx = s[0]; for (int i = 1; i < n; i++) { minn = min(minn, s[i]); maxx = max(maxx, s[i]); } if (n < m)...
7
#include <bits/stdc++.h> int main() { int w = 0, k = 0, n = 0, i = 0, s = 0; while (w < 1 || k < 1 || k > 1000 || w > 1000 || n < 0 || n > 1000000000) { scanf("%d", &k); scanf("%d", &n); scanf("%d", &w); } for (i = 1; i < (w + 1); i++) s += i * k; if (n > s) printf("%d", 0); else printf(...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, test, i, j, ara[200003 + 2], mark[200003 + 2]; cin >> test; while (test--) { cin >> n; memset(mark, 0, sizeof(mark)); for (int i = 1; i <= n; i++) cin >> ara[i]; int mx = 0; for (int i = 1; i <= n; i++) { int x = ara[i]...
2
#include <bits/stdc++.h> using namespace std; const long long BIG = 100000000100000; long long a[100001]; long long b[100001]; long long n, m; long long max(long long a, long long b) { if (a > b) return a; else return b; } long long ypa(long long k) { for (long long i = 1; i <= n; i++) b[i] = a[i]; long...
14
#include <bits/stdc++.h> using namespace std; void sign(pair<long long, long long> &a) { if (a.second < 0) { a.first *= -1; a.second *= -1; } } bool smaller(pair<long long, long long> a, pair<long long, long long> b) { sign(a); sign(b); return a.first * b.second < b.first * a.second; } void intersect(...
15
#include <bits/stdc++.h> using namespace std; const double INF = 1000000000; const long long INFLL = 1000000000000000005ll; const long long MOD = 1000000007; enum { F1, F2, F3, Q1, Q2, Q3 }; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> E; int K, N1, N2, N3, T1, T2, T3, W1, W2, W3;...
11
#include <bits/stdc++.h> using namespace std; vector<vector<char> > vec; vector<vector<bool> > visited; queue<pair<int, int> > q; vector<pair<int, int> > temp; vector<vector<pair<int, int> > > perm; pair<int, int> p; int a, b, c, f, s, counter; bool edge; int dirx[4] = {0, 0, -1, 1}; int diry[4] = {1, -1, 0, 0}; bool c...
8
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 500; const long long mod = 1e9 + 7; const long long cmod = 998244353; const long long inf = 1LL << 61; const int M = 1e6 + 500; const long long int ths = 1LL << 40; const int NN = 5e3 + 6; void solve() { long long int n, k; cin >> n >> k; long long...
12
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int t[4 * N]; int mod[4 * N]; void update(int v, int x) { t[v] += x; mod[v] += x; } void push(int v) { if (mod[v]) { update(2 * v + 1, mod[v]); update(2 * v + 2, mod[v]); mod[v] = 0; } } void modify(int ql, int qr, int x, int l, in...
14
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n, U; char s[20]; struct table { int f, tp; string s; table(void) {} table(int _f, int t, string a) : f(_f), tp(t), s(a) {} inline bool operator<(const table &b) const { if (s.size() == b.s.size()) return s < b.s; return s.size() < ...
16
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m; cin >> n >> m; vector<string> in(n); for (int i = 0; i < n; i++) { cin >> in[i]; } vector<vector<bool> > grid(n, vector<bool>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { grid[i][j] = (in[i][j] == 'B...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10, modd = 1e9 + 7, inf = 0x3f3f3f3f, INF = 0x7fffffff, hmod1 = 0x48E2DCE7, hmod2 = 0x60000005; const int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}; const double eps = 1e-8; template <class T> inline void scand(T &x) { char c; x = 0...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve(int n, int x1, int x2, const vector<pair<ll, int>> &c, bool sw = false) { vector<pair<int, int>> min_s1; for (int i = 0; i < n; ++i) { int y = c[i].first; int min_req = i + (x1 + y - 1) / y; min_s1.emplace_back(i, ...
9
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { string s; cin >> s; int ans = 1; for (int i = 0; i <= 9; i++) { for (int j = 0; j <= 9; j++) { bool f = 0; int sum = 0; for (int k = 0; k < s.size(); k++) { if (s[k] - ...
7
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const int maxn = 2010; const int maxnode = 200010; long long ans, w[maxn], f[maxnode]; struct Point { long long w, rw; int r, c; bool operator<(const Point& tp) const { if (r != tp.r) return r < tp.r; else return c < tp...
14
#include <bits/stdc++.h> using namespace std; int n, m, s, num[100100], ck, ans; pair<int, int> a, b; struct Kuai { int cnt[100100], num[400 << 1], size; inline void add(int u, int v) { int i; cnt[v]++, size++; for (i = size; i > u; i--) num[i] = num[i - 1]; num[u] = v; } inline void del(int u) ...
19
#include <bits/stdc++.h> using namespace std; int n, m, x, y, E[333333][5], g[333333], d[333333]; void dfs(int x) { int cnt = 0; for (int i = (1); i <= (d[x]); i++) if (g[x] == g[E[x][i]]) ++cnt; if (cnt >= 2) { g[x] ^= 1; for (int i = (1); i <= (d[x]); i++) if (g[x] == g[E[x][i]]) dfs(E[x][i]);...
14
#include <bits/stdc++.h> using namespace std; void fun() {} long long int md = 1e9 + 7; long long int __gcd(long long int a, long long int b) { if (b == 0) return a; return __gcd(b, a % b); } long long int poww(long long int a, long long int b, long long int md) { if (b < 0) return 0; if (a == 0) return 0; lo...
12
#include <bits/stdc++.h> using namespace std; const int maxx = 800010; const double pi = acos(-1.0); const double eps = 1e-15; long long t, n, m, k, a, b, q, a1, a2, a3; long long ans = 0, total = 0, sum = 0, cnt = 0; long long d[maxx], bj[maxx]; struct node { long long l; long long r; long long valx; long long...
9
#include <bits/stdc++.h> const int MAX_N = (int)2e5 + 123; const double eps = 1e-6; const int mod = (int)1e9 + 7; const int inf = (int)1e9 + 123; using namespace std; int n; int a[MAX_N], b[MAX_N]; int maxi[20][MAX_N], mini[20][MAX_N], lg[MAX_N]; void calc_max() { for (int i = 1; i <= n; i++) maxi[0][i] = a[i]; for...
13
#include <bits/stdc++.h> using namespace std; long long a[1000001]; map<long long, long long> fr; int main() { long long n, i, ok = -1, nr = 0, act; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; fr[a[i]]++; if (fr[a[i]] >= 2) { nr++; ok = a[i]; } } if (nr >= 2 || ok == 0 || (ok...
10
#include <bits/stdc++.h> using namespace std; int N; queue<int> D; queue<int> R; int main() { cin >> N; char c; for (int i = 0; i < N; ++i) { cin >> c; (c == 'D' ? D : R).push(i); } while (D.size() > 0 && R.size() > 0) { if (D.front() < R.front()) { R.pop(); D.push(D.front() + N); ...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using vc = vector<t>; template ...
25
#include <bits/stdc++.h> using namespace std; const int N = 5000007; struct node { int l, r; int s; }; int a[N]; int sets[107]; node seg[N]; queue<int> garbage; int tt; int new_node() { int u; if (garbage.size()) u = garbage.front(), garbage.pop(); else u = ++tt; seg[u].l = seg[u].r = seg[u].s = 0; ...
17
#include <bits/stdc++.h> using namespace std; int a[15][15]; int main() { ios::sync_with_stdio(0); memset(a, 0, sizeof(a)); int r, c, n, k; cin >> r >> c >> n >> k; int ann = 0; for (int j = 0; j < n; j++) { int x, y; cin >> x >> y; x--; y--; a[x][y] = 1; } for (int i = 0; i < r; i++...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int res = 1; int op = 0; int op2 = 1; bool mul = false; int val = -1; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { res *= i; int count = 0; while (n % i == 0) { count++; n /= i; ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int q; cin >> q; for (long long int t = 0; t < q; ++t) { long long int n; cin >> n; long long int a[n]; set<long long int> s; map<long long int, long long int> m; for (long long int i = 0; i < n; ++i) { cin >> a[i];...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, ans = 0; cin >> n; vector<int> a(n + 1, 0); for (int i = 1; i < n + 1; i++) cin >> a[i]; for (int i = ...
13
#include <bits/stdc++.h> using namespace std; int N; int main(void) { scanf("%d", &N); printf("%d\n", 6 * N * (N - 1) + 1); return 0; }
5
#include <bits/stdc++.h> using namespace std; int arr[200005]; int happy[200005]; inline long max(long x, long y) { return x > y ? x : y; } int main() { long N, W, K; while (scanf("%ld %ld %ld", &N, &W, &K) != EOF) { long result = 0, RESULT = 0; set<pair<int, int> > S_, S; for (int i = 1; i <= N; ++i) s...
14
#include <bits/stdc++.h> using namespace std; inline int read() { int x(0), w(1); char c = getchar(); while (c ^ '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') w = -1, c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar(); return x * w; } int n, d, h, cur; i...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; vector<int> adj[MAXN << 1], door[MAXN]; stack<int> scc; int cur[MAXN], low[MAXN << 1], num[MAXN << 1], compID[MAXN << 1], vis[MAXN << 1]; int n, m, cnt = 0, idx = 0; template <class T, class U> void minimize(T &x, U y) { if (x > y) x = y; } t...
12
#include <bits/stdc++.h> using namespace std; int main() { char A[100005], B[100005]; int n; cin >> A; cin >> B; n = strlen(A); int c4 = 0, c7 = 0; for (int i = 0; i < n; i++) { if (A[i] != B[i]) { if (A[i] == '4') c4++; else c7++; } } int a = (c4 > c7) ? c4 : c7; ...
4
#include <bits/stdc++.h> using namespace std; long long int combine(int n, int r) { long long int sum = 1; for (int i = 1; i <= r; i++) { sum *= n - i + 1; sum /= i; } return sum; } int main() { int x, y, c; cin >> x >> y >> c; long long int sum = 0; for (int i = 4; i < c; i++) { sum += comb...
6
#include <bits/stdc++.h> using namespace std; ifstream in("in.in"); ofstream out("out.out"); string s; int solve() { cin >> s; int st = 0; int num = 0; for (int i = 0; i < s.length(); i++) { if ((st == 1) && (s[i] == 'a')) st = 2; if ((s[i] != 'a') && (st == 0)) st = 1; if (st == 1) s[i]--; } if...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int d[maxn], t[maxn], n, k, maxk, root, mx[maxn], mn[maxn], sz[maxn]; bool flag[maxn]; vector<int> v[maxn]; queue<int> q; void dfs(int dep, int u, int f = 0) { sz[u] = 1; if (v[u].size() > 1) mn[u] = 1e9; for (int i = 0; i < v[u].size(); i++...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[101]; for (int i = 0; i < n; i++) { cin >> arr[i]; } if (n % 2 != 0 && arr[0] % 2 != 0) { if (arr[n - 1] % 2 != 0) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const double PI = acos(-1.0); const double epsilon = PI / 180.0; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod;...
15
#include <bits/stdc++.h> using namespace std; const int S = 450; int n, m, ans, a[100005], cnt[100005 / S + 3][100005 * 2], tag[100005 / S + 3], bel[100005]; int dep[100005], fa[100005], top[100005], son[100005], siz[100005], dfn[100005], tim; bool col[100005]; int fir[100005], nxt[100005]; void line(int x, int...
21
#include <bits/stdc++.h> using namespace std; void Fast_IO() { ios::sync_with_stdio(0); cin.tie(0); } class sparseTable { public: long long n, k = 25; vector<vector<long long> > st; long long init() { return -1000000000; } long long compute(long long a, long long b) { return max(a, b); } sparseTable(vect...
14
#include <bits/stdc++.h> using namespace std; int N, M, K; char a[1005][1005]; long long cnt[26][1005][1005]; long long cst[1005][1005]; pair<int, pair<pair<int, int>, pair<int, int> > > qry[300005]; long long scst[1005][1005]; long long sless[1005][1005], cless[1005][1005], ssless[1005][1005], scless[1005][1005]; ...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x; long long w = 0, b = 0; for (int i = 0; i < n; ++i) { cin >> x; if (x % 2 == 0) { w += x / 2; b += x / 2; } else if (i % 2) { w += x / 2; b += x / 2 + 1; } else { w += x / 2 + 1; ...
12
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while ((c < '0' || c > '9') && (c != '-')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } const int N = 1...
15
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long dp[2000001]; bool is_prime[2000001]; void seive(long long N) { for (long long i = 0; i < N; i++) is_prime[i] = true; is_prime[0] = is_prime[1] = false; for (long long i = 2; i * i <= N; i++) { if (is_prime[i] == true) { ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long exgcd(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return a; } long long ans = exgcd(b, a % b, x, y); lon...
7
#include <bits/stdc++.h> using namespace std; int n, m, k, s; const int maxk = 10, maxm = 2005; int val[maxk][maxk]; int dp[2][maxm], ip[maxm][maxm], ptr; void solve1(int first, int second) { for (int i = 0; i < maxm; i++) dp[0][i] = dp[1][i] = 3e6; ptr = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j <=...
14
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int b, p, f, h, c; cin >> b >> p >> f >> h >> c; int t2 = min(b / 2, f); int ans = t2 * c + min((b - t2 * 2) / 2, p) * h; int t1 = min(b / 2, p); b -= t1 * 2; ans = max(ans, t1 * h + min(b / 2, f)...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, k, r; cin >> n >> k; if (n == k) cout << n; else cout << 2; cout << "\n"; ; return 0; }
2
#include <bits/stdc++.h> using namespace std; vector<long long> a; vector<pair<long long, long long>> v; long long b; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; for (long long i = 0; i < n; i++) { cin >> b; a.push_back(b); } long long m = a[0]; ...
4
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed; cout << setprecision(20); long long int t = 1; cin >> t; while (t--) { long long int n, g, b, ans = 0; cin >> n >> g >> b; long long int h...
6
#include <bits/stdc++.h> const int N = (int)1e5 + 228; using namespace std; int a1[N], a2[N], sz; long long n, p[N], ans, nn; void rec2(int pos, long long x, long long y) { if (pos == sz + 1) { long long z = nn / x / y; if ((x + y + z) % 2 == 0 && x > 1 && y > 1 && z > 1 && x + y - z > 0 && y + z - x ...
16
#include <bits/stdc++.h> using namespace std; int main() { long long int N; cin >> N; vector<long long int> Numbers(N); map<long long int, long long int> Count; for (long long int i = 0; i < N; i++) { cin >> Numbers[i]; Count[Numbers[i]]++; } long long int Max = 0; for (auto i : Numbers) Max = m...
5
#include <bits/stdc++.h> using namespace std; int l, r; vector<long long int> tt; void generate() { long long int x = 2; int idx; tt.push_back(1); while (x <= 2000000000ll) { tt.push_back(x); x *= 2; } idx = tt.size(); x = 3; while (x <= 2000000000ll) { tt.push_back(x); x *= 3; } int...
5
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) const int W = 12, N = 6e5; int countOfA[1 << W], numOfP[N]; char s[W + 1]; map<char, int> st = {{'A', 0}, {'O', 0}, {'X', 0}, {'a', 2}, {'o', 1}, {'x', 1}}, add = {{'A', 1}, {'O', -1}, {'X', 2}, ...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0, l = 0; cin >> n; int q = 1; while ((sum + ((q * (q + 1)) / 2)) <= n) { sum += ((q * (q + 1)) / 2); q++; l++; } cout << l << endl; }
0