solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long n, m; long long fel[100009]; struct stp { long long t, l, c; }; map<long long, stp> mp; stp stps[100009]; long long clt = 0; int main() { cin >> m; long long lin = 100005; for (long long i = 0; i < (m); i++) { cin >> stps[i].t >> stps[i].l; if (stp...
8
#include <bits/stdc++.h> const long long INF = 1e18; using namespace std; long long POWER(long long base, long long expo) { long long num = 1; long long i = expo; while (i) { num = num * base; i--; } return num; } int main() { long long t = 1; while (t--) { long long a, b, c, sum = 0; cin ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x; long long bit[32]; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &k); for (int j = 0; j < 32; ++j) bit[j] = 0; for (int j = 0; j < k; ++j) { scanf("%d", &x); int r = 0; while (x >>= 1) { r+...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; void sIO(); int n, m, x, y, a[111111]; vector<vector<int> > g, gr; bool w1[111111], w2[111111], w[111111]; void dfs1(int v) { w1[v] = true; w[v] = true; int kk = (int)g[v].size(), tto; for (int i = 0; i < kk; ++i) { tto...
9
#include <bits/stdc++.h> using namespace std; const int MaxN = 300005; int n, m; int color[MaxN]; vector<int> g[MaxN]; int main() { cin.sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } bool change = true; wh...
14
#include <bits/stdc++.h> using namespace std; int getButtonPressedCount(int n, int m) { int num = m; int buttonPressedCount = 0; while (num > 0) { if (num == n) { return buttonPressedCount; } else if (num < n) { num++; buttonPressedCount++; } else if (num % 2 == 0) { num /= 2; ...
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAX = 110; int n, m, x[MAX], y[MAX]; char a[MAX][MAX]; int main() { ios_base::sync_with_stdio(0); cin >> n >> m; for (int i = 0, _n = (n); i < _n; ++i) cin >> a[i]; for (int i = 0, _n = (n); i < _n; ++i) { for (int j = 0, _n = ...
0
#include <bits/stdc++.h> using namespace std; int N, K; char buf[200010]; int t[30], a[30][30]; long long score[(1 << 22)]; int sz, last[30]; void func(void) { int i, j, k; sz = 0; for (i = N - 1; i >= 0; i--) { int x = buf[i] - 'A'; int mid = 0; for ((j) = 0; (j) < (int)(sz); (j)++) { int y = l...
19
#include <bits/stdc++.h> using namespace std; map<int, int> occ; vector<int> f(const int m) { vector<int> res; for (auto &&p : occ) for (int rep = p.second / m; rep > 0; --rep) res.push_back(p.first); return res; } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, k; cin >> n >> k;...
8
#include <bits/stdc++.h> using namespace std; void flip(vector<vector<int>> &a, vector<pair<int, int>> &z, int i, int j) { z.push_back({i, j}); a[i][j] ^= 1; } void fix(vector<vector<int>> &a, vector<pair<int, int>> &z, int i, int j) { int n = a.size(), m = a[0].size(); if (i == n - 1) { i--; } if (j ==...
7
#include <bits/stdc++.h> using namespace std; const int p[6] = {2, 3, 5, 7, 11, 13}; int k, a[10]; vector<int> v[70], ans; set<int> ss; void dfs(int x, int idx, int z) { if (idx == 5) return; if (k <= 60 && idx == 4) return; dfs(x, idx + 1, z); x *= p[idx]; while (x <= k * k * 2) { v[z | (1 << idx)].push_...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; struct data { int ok, open, close; data() {} data(int _ok, int _open, int _close) { ok = _ok, open = _open, close = _close; } data operator+(const data &temp) const { data ret; ret = data(ok + min(open, temp.close) + temp.ok, ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int INF = (1e+9) + 7; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int a, b; cin >> a >> b; if (a == 1 && b == 1) { cout << "YES\n" << 1; return 0; } if (a == 3 && b == 3) { cout << "YES\n" << "8 2 ...
14
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; long result = 0; while (n.size() > 1) { int digits = 0; for (int i = 0; i < n.size(); i++) { digits += n[i] - '0'; } n = to_string(digits); result++; if (digits < 9) break; } cout << result << endl; ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = n; i > (n / 2); i--) cout << a...
0
#include <bits/stdc++.h> using namespace std; int main() { int y1, m1, d1, y2, m2, d2; char c; cin >> y1 >> c >> m1 >> c >> d1 >> y2 >> c >> m2 >> c >> d2; if (y1 > y2 || (y1 == y2 && m1 > m2) || (y1 == y2 && m1 == m2 && d1 > d2)) { swap(y1, y2); swap(m1, m2); swap(d1, d2); } int days = 0; for...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; int cnt[13]; string s1, s2; string res; int n1 = 0; int n2 = 0; cin >> n; cin >> s1; cin >> s2; cnt[00] = cnt[01] = cnt[10] = cnt[11] = 0; for (int i = 0; i < s1.size(); ++i) { ++cnt[(s1[i] - '0') * 10 + (s2[i] - '0')]; } fo...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n); int sq = 0; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = LONG_MAX; int t = sqrtl(a[i]); if (t * t == a[i]) { sq++; } else { for (int j = t - 1; j <= t + 1; j++) b[i] = min(b...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f; int fa[maxn]; void dfs(int u) { if (u == 1) { printf("1 "); return; } dfs(fa[u]); printf("%d ", u); } int main() { int n; cin >> n; for (int i = 2; i <= n; ++i) scanf("%d", &fa[i]); dfs(n); ...
1
#include <bits/stdc++.h> using namespace std; int a, b, c, d, e, f, g, h, i, j, k; int dcmp(double x) { if (fabs(x) < (1e-8)) return 0; if (x > 0) return 1; return -1; } double sqr(double x) { return x * x; } struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} friend Point ope...
22
#include <bits/stdc++.h> using namespace std; char c[10][10]; bool visit[70][10][10]; bool check(int x, int y, int move) { if (x < 0 || y < 0 || x >= 8 || y >= 8) return false; if (visit[move][x][y]) return false; if (x >= move) if (c[x - move][y] == 'S') return false; if (x + 1 >= move) if (c[x - move ...
7
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7LL; const int MAX = 2009; int main() { long long sum, xor_, and_, ans = 1; cin >> sum >> xor_; long long doubleAnd = sum - xor_; if (doubleAnd % 2 == 1 || sum < xor_) { cout << 0 << endl; return 0; } and_ = doubleAnd / 2; l...
9
#include <bits/stdc++.h> using namespace std; int n, x, y, z, num; const int MAXN = 100005; const int mod = 1e9 + 7; int b[MAXN]; int nxt[2 * MAXN], cost[2 * MAXN], a[2 * MAXN]; int fa[MAXN][25]; int be[MAXN], en[MAXN]; int sum, m, dep[MAXN]; int len; int dist[MAXN], sumx[MAXN]; int ans, ans1, ans2; int sum1[MAXN], sum...
19
/* This is code of SuperJ6 for Codeforces. Don't copy my code during f*kin' contests. 2.71828182845904523536 */ #include <iostream> #include <cstdio> #include <algorithm> #include <set> #include <map> #include <stack> using namespace std; #define endl '\n' #define ll long long #define pi pair<ll, ll> #define f first ...
21
#include <bits/stdc++.h> using namespace std; string s1[4] = {"", "soil", "rte", "sitini"}; string s2[4] = {"", "alail", "arte", "setini"}; vector<string> p; int isFeminime() { int i; for (i = 0; i < p.size() && p[i].find(s2[1]) == 0; i++) ; if (i == p.size() || p[i].find(s2[2]) != 0) return 0; for (++i; i ...
8
#include <bits/stdc++.h> using namespace std; struct TT { int id; double x, v; bool operator<(const TT &b) const { return (fabs(x * b.v) < fabs(b.x * v)); } } s[100005]; int a[100005], b[100005], c[100005], n; double w; void update(int v, int data) { while (v <= n) { c[v] += data; v += v & -v; } } int...
17
#include <bits/stdc++.h> using namespace std; inline void wait(double seconds) { double endtime = clock() + (seconds * CLOCKS_PER_SEC); while (clock() < endtime) { ; } } template <class T> inline T fastIn() { register char c = 0; register T a = 0; bool neg = false; while (c < 33) c = getchar(); whil...
8
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, n, m, z, c, t; long long b[266] = {0}; map<long long, long long> a[256]; string s; for (i = 97; i < 123; i++) { cin >> b[i]; } cin >> s; n = s.size(); c = 0, z = 0; for (i = 0; i < n; i++) { z = z + a[s[i]][c]; ...
10
#include <bits/stdc++.h> using namespace std; long long deg[1000010]; int main() { int n, m, x, y; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) scanf("%d%d", &x, &y), deg[x]++, deg[y]++; long long sum = 0; for (int i = 1; i <= n; i++) sum += (deg[i] * (deg[i] - 1LL)) + (n - deg[i] - 1) * (n - deg[i]...
11
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const long double eps = 1e-9; const long double pi = fabs(atan2(0.0, -1.0)); int *ass; void ML() { for (;;) { ass = new int[2500000]; for (int i = 0; i < 2500000; i++) ass[i] = rand(); } } enum { INT, DBL, STR, TTT } tps; struct pr...
10
#include <bits/stdc++.h> using namespace std; int expo(int x, int y) { int res = 1; while (y) { if (y % 2) res = (res * x % 1000000007) % 1000000007; x = (x * x) % 1000000007; y /= 2; } return res; } bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 ...
10
#include <bits/stdc++.h> using namespace std; int n; int cnt = 0; int a[100001]; const long long Mod = 1e9 + 7; long long power(long long x, int n) { if (!n) return 1; if (n % 2 == 0) return power(x * x % Mod, n / 2); return x * power(x * x % Mod, n / 2) % Mod; } int main() { cin >> n; cnt = 0; for (int i =...
13
#include <bits/stdc++.h> using namespace std; vector<char> s[111111]; char c[111111], cc[222222]; int l[111111], rk[222222], h[222222], f[111111], ql[222222], qr[222222], q[222222]; long long ans[111111]; pair<int, int> sa[222222]; pair<pair<int, int>, int> a[222222]; int T[222222], T2[222222]; void build(int x, in...
20
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, INF = 1e9; deque<int> q[N]; int a[N], b[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } int sum = 0, trash = 0; for (int i = 0; i < m; ...
7
#include <bits/stdc++.h> using namespace std; int Q, N, M, K, L; long long A[3][100001]; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; long long dp[3][100001]; bool visit[3][100001]; struct Go { long long x, y, v; }; void adv(int x, int y, int ox, long long v, int adved, vector<Go>& r) { visit[y][x] = 1; ...
15
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7, N = 55; int d[N], f[N][N], g[N][N], ft[N], c1[N], c[N][N]; void upd(int &x, int y) { x = (x + y) % mod; } int ksm(int x, int y) { int tmp = x, ans = 1; while (y) { if (y & 1) ans = (long long)ans * tmp % mod; tmp = (long long)tmp * ...
18
#include <bits/stdc++.h> using namespace std; int n, m, q, r, c, ans = -1; set<int> st; bool ch[400012]; vector<int> ad[400012]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m >> q; for (int i = 0; i < q; i++) { cin >> r >> c; r--; c--; c += n; ad[r].push_back(c);...
11
#include <bits/stdc++.h> using namespace std; int a[200005]; int n; map<long long, int> dp; map<long long, vector<int> > v; int f(int idx) { int val = a[idx] - 1; while (v[val].size() && v[val].back() >= idx) { v[val].pop_back(); } if (v[val].size() == 0) { return -1; } return v[val].back(); } int m...
9
#include <iostream> #include <set> #include <iterator> using namespace std; typedef long long ll; int main() { int t; cin >> t; while (t--) { ll n, w; cin >> n >> w; multiset<int> s; // multiset<int>::iterator j; for (int i = 0; i < n; i++) { int x; cin >> x; s.insert(x); } /* cout << endl;...
5
#include <bits/stdc++.h> using namespace std; long long a[1000000]; vector<long long> v; signed main() { long long n; cin >> n; for (long long i = 1; i <= n; ++i) { cin >> a[i]; if (a[i]) { v.push_back(i); } } if (!v.size()) return 0 * printf("0\n"); long long ans = 1; for (long long i =...
5
#include <bits/stdc++.h> using namespace std; vector<int> q[100000 + 1000]; int ans = 0, b[1000001]; void dfs(int x, int y) { b[y]++; for (int j = 0; j < q[x].size(); j++) { int m = q[x][j]; dfs(m, y + 1); } return; } int main() { int n; cin >> n; for (int j = 2; j <= n; j++) { int x; cin ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, i, ans = 0; cin >> n >> x; long long C[n]; for (i = 0; i < n; i++) cin >> C[i]; sort(C, C + n); for (i = 0; i < n; i++) { ans = ans + (x * C[i]); if (x - 1 >= 1) x--; } cout << ans << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; int n, m, t, c; string A[1000000]; int X1, X2, Y1, Y2; set<pair<int, int> > B; int dx[] = {0, 0, -1, 1, 1, -1, 1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; bool ok(int x, int y) { return (x >= 0 && y >= 0 && x < n && y < m); } void dfs(int x, int y) { B.insert(make_pai...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; bool uses[N][N]; int a[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } vector<pair<int, int> > cur = {{1, n + 1}}; for (int i = 1; i <= n; ++i) { ...
18
#include <bits/stdc++.h> using namespace std; const int MAXN = 5001; int a[MAXN], cnt[MAXN], ans[MAXN]; int main() { int n, i, j; scanf("%d", &n); for (i = 0; i <= n - 1; i++) { scanf("%d", &a[i]); a[i]--; } int len; for (i = 0; i <= n - 1; i++) { int prevDom = a[i]; memset(cnt, 0, sizeof(cn...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, k, prime[200], i, j, count, flag, z; for (i = 2, z = 0; i < 1001; i++) { flag = 1; for (j = 2; j < i; j++) { if (i % j == 0) flag = 0; ; } if (flag) prime[z++] = i; } cin >> n >> k; count = 0; for (i = 200; i >= 0;...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, cnt = 0, ans[N]; pair<int, int> p[N]; pair<pair<int, int>, int> c[N]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> c[i].first.first >> c[i].first.second; c[i].second = i; } cin >> m; for (int i = 0; i < m; i+...
9
#include <bits/stdc++.h> int main() { int n, k, m, i, j; while (scanf("%d%d", &n, &k) != EOF) { m = (n * (n * (n + k - 2) + 1 + k)) / 2; printf("%d\n", m); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (j < k) printf("%d ", (k - 1) * (i - 1) + j); else ...
5
#include <bits/stdc++.h> using namespace std; bool markP[100007]; vector<int> prime; inline void sieve() { int i, j; for (i = 2; i * i <= 100007; ++i) if (!markP[i]) for (j = i << 1; j < 100007; j += i) if (!markP[j]) markP[j] = 1; prime.push_back(2); for (i = 3; i < 100007; i += 2) if (!m...
5
#include <bits/stdc++.h> using namespace std; int a[200000]; int c[200000]; vector<int> e[200000]; int p[200000]; int b[200000]; int pp; bool vv; int dfs(int k) { int re = 0; for (int i = 0; i < int(e[k].size()); i++) re += dfs(e[k][i]); if (a[k] > re) vv = false; b[k] = re + 1; return (re + 1); } vector<pair...
10
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:64000000") const int infi = 1e9 + 7; const long long infl = 1e18 + 7; int cnt[3][30]; int tmp[30]; string s[3]; int main() { cin.sync_with_stdio(false); cin.tie(0); for (int i = 0; i < (3); ++i) { cin >> s[i]; for (int j = 0; j ...
10
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& x) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == '-') fu = 1, c = getchar(); for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0'; if (fu) x = -x; }; template <class T> inline void rea...
16
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e2 + 7, MOD = 1e9 + 7, INF = 1e18 + 7, N = 5000 + 7; int n; long double a[maxN], carry, help = 1, res, ans, q; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for (int i = n; i >= 1; i--) { int x =...
10
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void minimize(X &x, const Y &y) { if (x > y) x = y; } template <class X, class Y> void maximize(X &x, const Y &y) { if (x < y) x = y; } template <class T> T Abs(const T &x) { return (x < 0 ? -x : x); } const string NO = "NO"; void answerNO(...
12
#include <bits/stdc++.h> using namespace std; string un; int cntr = 1; int main() { cin >> un; sort(un.begin(), un.end()); for (int i = 1; i < un.length(); i++) { if (un[i] != un[i - 1]) cntr++; } if (cntr % 2 == 0) { cout << "CHAT WITH HER!\n"; } else { cout << "IGNORE HIM!\n"; } }
0
#include <bits/stdc++.h> using namespace std; const int MAX = 1 << 9; int k; bool ans[MAX][MAX]; void f(int n) { if (n == 1) { ans[0][0] = 1; return; } int m = n / 2; f(m); for (int i = 0; i < m; i++) for (int j = 0; j < m; j++) { int x = ans[i][j]; ans[i + m][j] = x; ans[i][j + ...
10
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void wr...
20
#include <bits/stdc++.h> using namespace std; const int N = 303030; int n, m; int pre[N], dis[N], deg[N], par[N], sz[N]; vector<int> g[N]; void bfs(int st, int o) { vector<int> q; q.push_back(st); memset(dis, 0x3f, sizeof(dis)); dis[st] = 0; for (int i = (0); i < ((int)q.size()); i++) { int u = q[i]; ...
18
#include <bits/stdc++.h> using namespace std; int main() { int a, b, k; cin >> a >> b; int count = 0; while (a < b) { k = a * 6; if (b % k == 0 && k <= b) { count += 2; a = k; } else break; } while (a < b) { k = a * 3; if (b % k == 0 && k <= b) { count += 1; ...
2
#include <bits/stdc++.h> using namespace std; struct point { double x, y; } A, B, C; double CCW(point A, point B, point C) { return (double)(B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y); } void Read() { scanf("%lf %lf", &A.x, &A.y); scanf("%lf %lf", &B.x, &B.y); scanf("%lf %lf", &C.x, &C.y); } void So...
5
#include <bits/stdc++.h> using namespace std; int n, m, k, v, t; char mas[5][12]; string s[5]; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= 11; i++) { for (int j = 1; j <= 4; j++) { if (n == 0) break; if (i != 1 && j == 3) { j++; } mas[j][i] = 'O'; ...
3
#include <bits/stdc++.h> using namespace std; int n; int x1[200000], x2[200000], yy1[200000], yy2[200000]; int x12 = INT_MIN, x22 = INT_MAX, yy12 = INT_MIN, yy22 = INT_MAX; int x13 = INT_MIN, x23 = INT_MAX, yy13 = INT_MIN, yy23 = INT_MAX; bool check(int a, int b) { int cnt = 0; for (int i = 0; i < n; i++) { if ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int s = 0; for (int i = 3; i <= n; i++) { s += (i * (i - 1)); } cout << s; return 0; }
4
#include <bits/stdc++.h> using namespace std; using LL = long long; multiset<int> s[30]; LL sum[30]; int main() { ios::sync_with_stdio(false); cin.tie(0); int times; cin >> times; int cnt = 0; while (times--) { string st; int a; cin >> st >> a; if (st == "+") { ++cnt; for (int i ...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; int n, x, d, c = 30; long long a[maxn], b[maxn], e[maxn], one[maxn]; long long ans[maxn]; int nxt() { x = (long long)(x * (long long)37 + 10007) % mod; return x; } void init() { for (int i = 0; i < n; i++) a[i] = (lon...
15
#include <bits/stdc++.h> using namespace std; class Init { public: Init() noexcept try { ios_base::sync_with_stdio(false); cin.tie(nullptr); } catch (...) { cerr << "Init constructor threw an exception" << endl; terminate(); } } __init __attribute__((unused)); using ll = long long; using ld = lon...
0
#include <bits/stdc++.h> using namespace std; int main() { int t, l, a, b, c, d, num, i, flag, an, ans; char str[100]; long long min_ = -1000000002, max_ = 1000000002; scanf("%d", &t); scanf("\n"); while (t--) { a = b = c = d = num = 0, flag = 0, ans = an = 0; gets(str); l = strlen(str); if ...
6
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5 + 10; char s[N]; int n, m, k; int main() { scanf("%d", &n); scanf("%s", s); if (n == 1) { puts("NO"); return 0; } for (int i = 0; i < (n - 1); i++) if (s[i] != s[i + 1]) { puts("YES"); printf("%...
2
#include <bits/stdc++.h> using namespace std; const int N = 20; int n; string s; long long f[N][N], pw[N] = {1}; void update(long long& x, long long d) { x = max(x, d); } string ans; void dfs(int i, int j) { if (i == 0) ans += string(j, 'M'); else if (j == 0) ans += string(i, 'H'); else { if (f[i][j] ...
16
#include <bits/stdc++.h> using namespace std; int n, x; string s; vector<int> v; int main() { scanf("%I64d", &n); for (int i = 1; i <= n; i++) { cin >> s; if (s != "sum") cin >> x; if (s == "add") v.insert(lower_bound(v.begin(), v.end(), x), x); if (s == "del") v.erase(lower_bound(v.begin(), v.end()...
15
/* Snippets :- 1. Binomial (nCr) - nCr Modulo 2. (x^y)mod m - power 3. gcd & lcm - gcd 4. Djisktra - Djikstra 5. Priority Queue - priority 6. Disjoint Set Union - dsu 7. Compare Sort [sort pair with customisation] - compare */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(...
0
#include <bits/stdc++.h> using namespace std; const int NMax = 1010; long long INF = 1000000007LL; long long dp[NMax][NMax], C[NMax * 2][NMax]; void INIT() { C[0][0] = 1; for (int i = 1; i <= 2000; i++) { C[i][0] = 1; for (int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % INF; } ...
15
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; template <typename first, typename second> ostream& operator<<(ostream& os, const pair<first, second>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template...
12
#include <bits/stdc++.h> using namespace std; int arr[200005], n, F[200005], B[200005]; signed main() { ios_base::sync_with_stdio(false); int t, i, j, l, w, h, lo, up; cin >> t; while (t--) { cin >> n; for (i = 1; i <= n; i++) { cin >> arr[i]; F[arr[i]]++; } for (i = 1; i <= n; i++) ...
6
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 123; const long long INF = (long long)1e18 + 123; const int inf = (int)1e9 + 123; const int MOD = (int)1e9 + 7; void megaRandom() { unsigned int FOR; asm("rdtsc" : "=A"(FOR)); srand(FOR); } set<int> emp_f, emp_s; string name[N]; int type[N]; i...
14
#include <bits/stdc++.h> using namespace std; const int maxN = 2005; const int dx[10] = {0, 0, 0, 1, -1, 1, 1, -1, -1}; const int dy[10] = {0, 1, -1, 0, 0, -1, 1, -1, 1}; int n, area, sx, sy; bool p[maxN][maxN], vis[maxN][maxN]; void init() { scanf("%d", &n); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n;...
11
#include <bits/stdc++.h> int main() { int i, n, t, a, d = 86400, l = 0, c = 0; scanf("%d%d", &n, &t); for (i = 0; i < n; i++) { scanf("%d", &a); l = l + d - a; c++; if (l >= t) break; } printf("%d\n", c); return 0; }
0
#include <bits/stdc++.h> namespace IOStream { const int MAXR = 10000000; char _READ_[MAXR], _PRINT_[MAXR]; int _READ_POS_, _PRINT_POS_, _READ_LEN_; inline char readc() { if (!_READ_POS_) _READ_LEN_ = fread(_READ_, 1, MAXR, stdin); char c = _READ_[_READ_POS_++]; if (_READ_POS_ == MAXR) _READ_POS_ = 0; if (_READ_...
18
#include <bits/stdc++.h> using namespace std; int main() { int n, m, val; cin >> n; int maxa = 0, maxb = 0; for (int i = 0; i < n; i++) { cin >> val; if (val > maxa) maxa = val; } cin >> m; for (int i = 0; i < m; i++) { cin >> val; if (val > maxb) maxb = val; } cout << maxa << " " << m...
0
#include <bits/stdc++.h> using namespace std; inline long long myInt() { char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); int flag = 1; if (c == '-') flag = -1, c = getchar(); long long x = 0; while (isdigit(c)) { x = (x * 10) + (c - '0'); c = getchar(); } if (-1 == flag) retur...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; char ch = 'a'; string s; for (int i = 1; i <= n; i++) { s += ch; if (int(ch - 96) >= k) ch = 'a'; else ch = char(int(ch - 95) + 96); } cout << s << endl; }
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(0.0) * 2.0; const double eps = 1e-12; const int step[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; template <class T> inline T abs1(T a) { return a < 0 ? -a : a; } template <class T> inline T max1(T a, T b, T c = -1234567, T d = -1234567) { T ans = ...
10
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; struct Edge { int from, to, nxt, w; }; Edge e[maxn * 2]; int head[maxn], cnte; int brig[maxn * 2]; int n, m, k; int kn[maxn]; int c[maxn], ww[maxn]; void addEdge(int u, int v, int w) { e[cnte].from = u; e[cnte].to = v; e[cnte].w = w; e[c...
20
#include <bits/stdc++.h> using namespace std; const int N = 100010; int h[N]; int n, k; int Max(int a, int b) { return a > b ? a : b; } int Min(int a, int b) { return a < b ? a : b; } int erfen(int shu, int s, int e) { if (s == e - 1 || s == e) return s; int mid = (s + e) / 2; if (shu == h[mid]) return mid; if ...
8
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int x, y, k = 0; vector<long long int> v[n + 50]; long long int ans[n + 50]; for (long long int i = 1; i <= n; i++) ans[i] = -111; for (long long int i =...
7
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; struct node { int x, k; } a[100010]; int n; int main() { while (~scanf("%d", &n)) { for (int i = 1; i <= n; i++) scanf("%d %d", &a[i].x, &a[i].k); if (n == 1) { if (a[n].x == 0) printf("YES\n"); else printf...
6
#include <bits/stdc++.h> using namespace std; int a[1000000 + 5]; int f[1000000 + 5][2][2]; pair<int, int> g[1000000 + 5][2][2]; void print(int n, int i, int j) { if (n == 0) return; print(n - 1, g[n][i][j].first, g[n][i][j].second); if (j == 0) printf("%d ", a[n]); else printf("%d ", -a[n]); } int main...
20
#include <bits/stdc++.h> using namespace std; long long C[110][110]; long long dp[110][10010]; long long a[110]; long long power(long long x, long long n) { if (n == 0) return 1; long long y = power(x, n / 2); y = y * y % 1000000007ll; if (n % 2 == 1) y = y * x % 1000000007ll; return y; } int main(void) { i...
11
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int gcd(int a, int b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a - b, b); return gcd(a, b - a); } bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); printf("%d\n", (6 * n - 1) * k); for (int i = 0; i < n; i++) { printf("%d %d %d %d\n", (6 * i + 1) * k, (6 * i + 2) * k, (6 * i + 3) * k, (6 * i + 5) * k); } }
11
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); 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, m...
11
#include <bits/stdc++.h> using namespace std; int n, r, i, a[100010], j; double b[100010]; int main() { scanf("%d%d", &n, &r); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); b[i] = r; for (j = 1; j < i; j++) if (abs(a[i] - a[j]) <= 2 * r) b[i] = max(b[i], b[j] + sqrt(4 * r * r ...
7
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a; bool can(int mid) { int prev = 0; for (auto &i : a) { int cur = -1; if (i + mid >= m) { int l1 = 0, r1 = i + mid - m; int l2 = i, r2 = m - 1; if (prev > r2) return 0; if (prev <= r1) cur = prev; else...
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:60777216") using namespace std; int main() { int a, b, n; cin >> a >> b >> n; for (int x = -1000; x <= 1000; ++x) { long long curr_a = a; long long curr_b = b, tmp = 1; bool breaked = false; for (int i = 0; i < n; ++i) { tmp *= x; ...
6
#include <bits/stdc++.h> using namespace std; int visit[2000010], prime[10000], tot_prime, mu[2000010]; int mi[2000010], ans[2000010], ANS; int calc(int a, int k) { int ans = 1; while (k) { if (k % 2) ans = (long long)ans * a % 1000000007; a = (long long)a * a % 1000000007; k /= 2; } return ans; } i...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int x = n; int y = n + 1; int z = n * (n + 1); if (n == 1) puts("-1"); else printf("%d %d %d", x, y, z); }
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vs = vector<string>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios_base::sync_wit...
19
#include <bits/stdc++.h> using namespace std; template <class T> string toStr(const T &x) { stringstream s; s << x; return s.str(); } template <class T> int toInt(const T &x) { stringstream s; s << x; int r; s >> r; return r; } int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dy[8] = {-1, 0, 1, 1, 1, 0, -1,...
3
#include <bits/stdc++.h> using namespace std; const int N = 200002; int get(char c) { if (c >= 'a' && c <= 'z') return c - 'a'; if (c >= 'A' && c <= 'Z') return c - 'A' + 26; return c - '0' + 52; } struct node { vector<int> v; int cnt; node() { v = vector<int>(62, 0); cnt = 0; } }; node tree[3 * N...
13