solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; if (a.length() != b.length()) { cout << "No"; return 0; } for (int i = 0; i < a.length(); i++) { if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u') { if (b[i] == 'a' || b[...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x[200000], s = 0, a = 0; cin >> n; for (i = 0; i < n; i++) { cin >> x[i]; s = s + x[i]; } for (i = 0; i < n; i++) { a = a + x[i]; if (a >= s / 2 && s % 2 == 0) break; else if (s % 2 != 0 && a >= s / 2 + 1) bre...
5
#include <bits/stdc++.h> using namespace std; const int sz = 4e5; long long a[sz], n; long long curinv[32], flipinv[32]; void foo(vector<int> v, int b) { if (b < 0 || v.empty()) return; vector<int> zvec, ovec; int z = 0, o = 0; for (int k : v) { if ((k >> b) & 1) { o++; flipinv[b] += z; ov...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 100006; int n; vector<int> e[maxn]; int c[maxn]; bool check(int x, int p, int o) { if (p != 0 && c[x] != c[p]) return false; for (auto i : e[x]) if (i != p && i != o) if (!check(i, x, o)) return false; return true; } bool check_point(int o) ...
8
#include <bits/stdc++.h> using namespace std; const int Maxm = 500005; int m, k, n, s; int a[Maxm]; int lft[Maxm], tot; bool mark[Maxm]; vector<int> res; void Add(int x) { if (lft[x] == 1) tot--; lft[x]--; } void Rem(int x) { if (lft[x] == 0) tot++; lft[x]++; } int main() { scanf("%d %d %d %d", &m, &k, &n, &s...
11
#include <bits/stdc++.h> using namespace std; int main() { int test, cas = 0; int n; cin >> n; int ar[n + 5]; for (long long i = 1; i <= n; i++) { cin >> ar[i]; }; bool ck = 0; for (long long i = 1; i <= n; i++) { if (ar[i] % 2 == 0) { cout << ar[i] / 2 << endl; } else if (ck == 0) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long n, m; cin >> n >> m; long long total = 0; for (long long i = 1; i <= n; i++) { long long k = (m + i % 5) / 5; total += k; } cout << total; }
3
#include <bits/stdc++.h> int main() { int i, j = 1, k = 1, n, m, a[1000] = {0}, b[1000] = {0}, c, d, e, f; scanf("%d %d", &n, &m); for (i = 1; i <= m; i++) { if (i % 2 != 0) { a[k] = i; k++; } else { b[j] = i; j++; } } c = n + 1; d = n + 1; k = 1; j = 1; for (i = 1;...
2
#include <bits/stdc++.h> using namespace std; inline int read() { register int s = 0, t = 0; register char ch = getchar(); while (ch > '9' || ch < '0') t |= ch == '-', ch = getchar(); while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return t ? -s : s; } int c[11], d[11],...
24
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int main() { int n; cin >> n; string s; for (int i = 0; i < n; ++i) { if (i % 4 < 2) { s += 'a'; } else { s += 'b'; } } cout << s << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int l[n], r[n]; int L = 0, R = 0; for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; L += l[i], R += r[i]; } int ans = abs(L - R); int col = 0; for (int i = 0; i < n; i...
3
#include <bits/stdc++.h> using namespace std; map<string, int> MP; int go(int t, string s) { if (MP.find(s) != MP.end()) { return MP[s]; } if (s.size() == 2) { return MP[s] = (s[0] - '0') * 2 + (s[1] - '0'); } bool lose = true; bool vis[4] = {0}; for (int i = (0); i < (int)(s.size()); i++) { s...
11
#include <bits/stdc++.h> using namespace std; struct data { int siz; int old; int par; }; vector<data> t; void remake(int v) { t[v] = {1, 0, v}; } void make(int v) { t.push_back({1, 0, v}); } int fin(int v) { if (v == t[v].par) return v; else { t[v].par = fin(t[v].par); return t[v].par; } } void...
13
#include <bits/stdc++.h> using namespace std; int C[1001][1001]; int MOD = (int)1e9 + 7; int COMBO(int n, int r) { if (n < 0 || r < 0) return 0; if (n < r) return 0; if (C[n][r] != -1) return C[n][r]; return C[n][r] = (COMBO(n - 1, r - 1) + COMBO(n - 1, r)) % MOD; } int main() { ios_base::sync_with_stdio(fals...
12
#include <bits/stdc++.h> using namespace std; string s, t; int sc[100005]; int bc[100005]; int ca[100005], cb[100005]; ; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> s >> t; int cnt = 0; for (int i = 0; i < s.size(); i++) { sc[i + 1] = sc[i]; if (s[i] == 'A') cnt++; else ...
17
#include <bits/stdc++.h> using namespace std; const int N = 500009; const int mod = 1000000007; long long int n, m, x, y; vector<long long int> v[N]; vector<bool> vis; bool is; void pre() { vis.assign(N, 0); } void dfs(long long int ver, long long int par) { vis[ver] = 1; for (auto &it : v[ver]) { if (it == par...
8
#include <bits/stdc++.h> using namespace std; struct Pt { double x, y; double Dist(Pt p) { return sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y)); } double Len() const { return sqrt(x * x + y * y); } void Norm() { double l = Len(); if (!l) return; x /= l; y /= l; } void Mul(double ...
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const long long md = 1e9 + 7; int main() { iostream::sync_with_stdio(0); cin.tie(0), cout.tie(0); vector<int> cn(5, 0); string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (s.substr(i, min((int)s.length() ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[101], b[101], s = 0, c[101], l = 0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = i + 1; } for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { int t = a[i]; ...
2
#include <bits/stdc++.h> const long long mod = 1e9 + 7; using namespace std; int main() { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; long long d1[n], d2[n], d3[n], d4[n], d5[n], d6[n]; memset(d1, 0, sizeof(d1)); memset(d2, 0, sizeof(d2)); memset(d3, 0, size...
5
#include <bits/stdc++.h> using namespace std; int main() { float hh, mm, h, d, c, n; cin >> hh >> mm; cin >> h >> d >> c >> n; float xmin = 0; if (hh < 20) { xmin = 60 - mm + (20 - hh - 1) * 60; } float xh = xmin * d + h; float xnr = ceil((xh / n)); float nr = ceil((h / n)); float xval = c - c *...
3
#include <bits/stdc++.h> using namespace std; int ans = -1; int mi = 2 * 1e9; void rec(string s, int level) { int l = s.size(); if (l == 0) return; if (s[0] != '0') { int tonum = stoi(s); double square = sqrt(tonum); int square_int = (int)square; if (square_int == square) { if (level < mi) {...
6
#include <bits/stdc++.h> using namespace std; const int N = 31; const int OFFSET = 150; const int MOD = 1e9 + 7; int n, t[N]; bool f[N][310][310][3][3], g[310][310]; int ans; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> t[i]; for (int i = 1; i <= t[1...
11
#include <bits/stdc++.h> using namespace std; vector<long long int> bit(400005, 0), pre(400005, 0); map<long long int, long long int> mp; void upd(int x) { while (x < 400005) { bit[x]++; x += x & -x; } } int get(int x) { int ans = 0; while (x > 0) { ans += bit[x]; x -= x & -x; } return ans; ...
10
#include <bits/stdc++.h> int main() { int n, i; scanf("%d", &n); if (n <= 2) { printf("1 \n1"); } else if (n == 3) { printf("2 \n1 3"); } else if (n == 4) { printf("4 \n3 1 4 2"); } else { printf("%d\n", n); for (i = 1; i <= n; i = i + 2) { printf("%d\t", i); } for (i = 2; ...
3
#include <bits/stdc++.h> using namespace std; const int NN = 555; const int mod = 1e9 + 7; int a[NN][NN]; int dp[NN][NN][2]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cin >> a[i][j]; } for (int i = 1; i <= n; i++) dp[i][i][0] = 1; for (int len = 1; len <= ...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; int a = 0, b = 0; cin >> n; int arr[10]; for (int i = 0; i < 10; i++) arr[i] = 0; for (int i = 0; i < n; i++) { cin >> a >> b; if (a * b == 2) arr[0]++, arr[1]++, arr[2]++; if (a * b == 3) arr[0]++, arr[6]++, arr[9]++; if (a *...
5
#include <bits/stdc++.h> using namespace std; const long long MN = 200; long long d[MN], h[MN]; void solve() { long long n, k; cin >> n >> k; for (long long i = 0; i < n; ++i) cin >> d[i] >> h[i]; long long imax1 = 0, imax2 = 0; for (long long i = 0; i < n; ++i) { if (d[i] > d[imax1]) imax1 = i; if (d...
8
#include <bits/stdc++.h> using namespace std; class seg_max_index { public: int n, size; vector<long long> arr; vector<int> hai; long long inf; seg_max_index(int size) : n(size / 2), inf(-(1LL << 60)) { arr.resize(n); hai.resize(n * 2); fill(arr.begin(), arr.end(), inf); this->size = size; ...
15
#include <bits/stdc++.h> using namespace std; __inline bool nextInt(int &val) { char ch; int sgn = 1; while ((ch = getchar()) != EOF) { if (ch == '-') sgn = -1; if (ch >= '0' && ch <= '9') break; } if (ch == EOF) return false; val = (int)(ch - '0'); while (true) { ch = getchar(); if (ch >=...
13
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x; } const int maxn = 1e5 + 5; struct tree { int c[2], siz; } t[maxn * 40]; struct edge { int ...
21
#include <bits/stdc++.h> using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar(); if (_tc == '-') _tc = getchar(), _tmp = -1; while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();...
20
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:36777216") using namespace std; string __file__() { string res = "<stdin>"; int r = int((res).size()) - 1; while (res[r] != '.') --r; int l = r - 1; while (res[l] != '\\') --l; ++l; return res.substr(l, r - l); } void Exec(string a, string b, string...
19
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long n) { long long s = 1; while (n) { if (n & 1) s = s * a % 1000000007; a = a * a % 1000000007; n >>= 1; } return s; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long c, i, j, k, l, m, t, x, y,...
11
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, c[N], pc[N]; long long res[N]; vector<int> E[N]; map<int, int> S[N]; map<int, long long> cnt[N]; void dfs(int cur, int pre) { S[cur].insert(make_pair(c[cur], 1)); cnt[cur].insert(make_pair(1, c[cur])); for (int j = (0); j <= (E[cur].size()...
15
#include <bits/stdc++.h> using namespace std; int w[2 * 100010], n, a[100010]; struct point { int x, y; point() {} point(int a, int b) { x = a, y = b; } void sc() { scanf("%d%d", &x, &y); } void pr() { printf("%d %d\n", x, y); } bool eq(point b) { return x == b.x && y == b.y; } point add() { return point(...
9
#include <bits/stdc++.h> using namespace std; bool check(long long int *a, long long int n, long long int l, long long int x) { for (int i = 0; i < n; i++) if (binary_search(a, a + n, a[i] - x) | binary_search(a, a + n, a[i] + x)) return true; return false; } void func(long long int *a, long lo...
9
#include <bits/stdc++.h> using namespace std; pair<int, int> a[2005]; pair<int, int> b[2005]; int maxv[1000005]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { scanf("%d", &a[i].first); scanf("%d", &a[i].second); } for (int i = 0; i < m; i++) { scanf("%d", &b[i].first); sc...
12
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2; cout << l1 << ' ' << ((l1 != r2) ? r2 : l2) << endl; } }
0
#include <bits/stdc++.h> using namespace std; vector<pair<char, int> > as, bs; int N; vector<pair<int, int> > solve(int initmoveb, int initmovea) { vector<pair<int, int> > ans; vector<pair<char, int> > na, nb; int bcnt = 0, acnt = 0; for (int i = 0; i < initmoveb; ++i) { na.push_back(bs[i]); bcnt += bs[...
20
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O2") #pragma GCC optimization("unrolled-loops") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long base = 1e9 + 7; const long long oo = 6e3 + 1; const long long gh = 1e3 + 3; const long l...
14
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int N = 1005; long long f[N][N], F[N][N], binom[N][N], fac[N]; void prepro() { f[0][0] = 1; for (int n = (1); n <= (1001); ++n) for (int k = (1); k <= (50); ++k) { for (int i = k; i <= n; i += k) f[n][k] = (f[n -...
15
#include <bits/stdc++.h> using namespace std; int n, m, now, i, j, k, cnt; int l[105], r[105], d[205]; double ans[105], f[105][105]; double len, ll, rr, p1, p2, p3; void calc(int L, int R) { int i, j, k; cnt = 1; for (i = 0; i <= n; ++i) for (j = 0; j <= n; ++j) f[i][j] = 0; f[0][0] = 1; for (i = 1; i <= ...
22
#include <bits/stdc++.h> using namespace std; int p[311111]; int x[311111]; long long s[311111]; int n; int k; long long mn; int ind; long long now = 0; bool comp(int i, int j) { return x[i] < x[j]; } long long labs(long long a) { if (a < 0) a = -a; } int main() { int i, j; cin >> n; for (i = 1; i <= n; ++i) { ...
12
#include <bits/stdc++.h> using namespace std; int a, b, c, n; int main() { int tmp = 0; for (; cin >> a;) n += a * tmp++; cout << n << endl; return 0; }
12
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int m, n, a[maxn]; long long s[maxn], p[maxn]; pair<long long, long long> Q[maxn]; double K[maxn]; double getk(pair<long long, long long> A) { return 1.0 * A.second / A.first; } double getk(pair<long long, long long> A, pair<long long, long long> B)...
24
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, c; string s, t; bool ff; while (cin >> s) { c = -1; for (i = 0; i < s.size(); i++) { if (s[i] == '<') { ff = true; for (j = i + 1; j < s.size(); j++) { if (s[j] == '>') break; if (s[j] == '/...
2
#include <bits/stdc++.h> using namespace std; bool iscons(char ch) { if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == '-' || ch == '?') { return false; } return true; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int n = s.length(); ...
7
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); long long tc = 1; while (tc--) { long long k, d; cin >> k >> d; if (d == 0) if (k > 1) { cout << "No solution"; continue; } cout << d; for (long long i = 0; i < ...
3
#include <bits/stdc++.h> using namespace std; char str[100005]; int flag[100005]; void print(int len) { for (int i = 0; i < len / 2; i++) { printf("4"); } for (int j = len / 2; j < len; j++) { printf("7"); } printf("\n"); } int main() { scanf("%s", str); int len = strlen(str); memset(flag, 0, si...
10
#include <bits/stdc++.h> using namespace std; int n; int dp[100003]; int ans[100003]; int mark[100003]; void f(int X) { ans[X] = -1; for (int i = 2; (i * (i + 1)) / 2 <= X; i++) if ((X - (i * (i + 1)) / 2) % i == 0) { int bas = (X - (i * (i + 1)) / 2) / i + 1; int st = dp[bas + i - 1] ^ dp[bas - 1];...
12
#include <bits/stdc++.h> using namespace std; const int X = 30; long long L, R, memo[X][4][2]; int T, len; string s; long long dfs(int cur, int M, int f) { if (M > 3) return 0; if (cur == len) return 1; if (memo[cur][M][f] != -1) return memo[cur][M][f]; int v; if (f) v = s[cur] - '0'; else v = 9; ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int maxSum = 0; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) maxSum++; if (maxSum > k) { int y = 0; for (int i = 0; i < n; i++) { cout << "0 " << y++ << endl; } } else { cout << "no...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; struct TR { int sum, l0, r0, nmin; }; int n, q, a[maxn], maxa; set<int> pos[maxn]; int nmax[4 * maxn]; void nmax_xg(int k, int l, int r, int x, int z) { if (l == r) { nmax[k] += z; return; } int t = k << 1, mid = (l + r) >> 1; if ...
24
#include <bits/stdc++.h> using namespace std; int main() { long long l, r, i; while (~scanf("%I64d%I64d", &l, &r)) { if ((r - l + 1) % 2 == 0) { printf("YES\n"); for (i = l; i <= r; i += 2) printf("%I64d %I64d\n", i, i + 1); } else printf("NO\n"); } return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { char s[25]; char t[25]; scanf("%s", s); scanf("%s", t); int len = strlen(s); int res = 0; for (int i = 0; i < len; i += 2) { if (s[i] == '[') { if (t[i] == '(') { res++; } else if (t[i] == '8') { res--; } ...
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a; cin >> b; string s; cin >> s; vector<int> v(a); for (int i = 0; i < a; i++) { v[i] = int(s[i]) - '0'; } if (a == 1 && b == 1) { cout << 0; return 0; } if (v[0] != 1 && b != 0) { v[0] = 1; b--; } ...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; const ll MAX_N = 1e5 + 1; ll MOD = 1e9 + 7; const ll INF = 1e9; template <typename T> void print(T &&t) { cout << t << "\n"; } te...
5
#include <bits/stdc++.h> #define mod (int)(1e9+7) using namespace std; int n, t, q, x, i, j; long long sum = 1; int b[110], c[110], sp[110], f[10204], mp[1200000], sc[110], s[10204]; int main() { cin >> n; for (i = 1; i <= n; i ++ ) cin >> c[i], sum = 1ll * sum * (c[i] + 1) % mod, sc[i] = sc[i - 1] + c[i]; for (in...
21
#include <bits/stdc++.h> const int maxn = 200005; using namespace std; int l[maxn + 5], r[maxn + 5]; int main() { int id, lnum = 0, rnum = 0, num = 0, q; char c; scanf("%d", &q); memset(l, -1, sizeof(l)); memset(r, -1, sizeof(r)); for (int i = 0; i < q; i++) { getchar(); num++; scanf("%c %d", &c...
6
#include <bits/stdc++.h> using namespace std; class Edge { public: int to, next; long long cost; Edge(int t, int n, long long c) : to(t), next(n), cost(c) {} Edge() : to(-1), next(-1), cost(0) {} }; void add_edge(int u, int v, long long w); void add_edge_DAG(int u, int v, long long w); long long get_limit(long...
13
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 7; const int N = 1e8 + 7; const int INF = 1000000000000000001; const int MOD = 1000000009; const double eps = 1e-2; long long po(long long x, long long y) { if (y == 0) { return 1; } long long sq = po(x, y / 2); sq *= sq; sq = sq; if (y...
3
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int, pair<int, int> > > > ad; vector<vector<int> > fre(40); int v[12] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; int sz[12] = {6, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2}; long long int pro(long long int a, long long int b, long long int M) { if (b == 0 ||...
20
#include <bits/stdc++.h> int cuberoot(int x) { int fr = 0, la = 1001, mid, p; while (la - fr > 0) { mid = (fr + la) / 2; p = mid * mid * mid; if (p == x) return mid; else if (p > x) la = mid; else fr = mid + 1; } if (fr * fr * fr == x) return fr; else return -1; }...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; int main() { int t; cin >> t; while (t--) { ll n, x, y; cin >> n >> x >> y; ll sum = x + y; if (x > y) swap(x, y); ll mx = min(n, x + y - 1); ll mn = max(1LL, min(n, x + y - n + 1)); cou...
9
#include <bits/stdc++.h> using namespace std; mt19937 rnd(time(0)); const int N = 1e4 + 7; int MOD; bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) { return false; } } return (x != 1); } int dp[N]; vector<pair<int, int> > e[N]; void add(int x) { for (int i = N - x; i >= 0; i...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 101111; struct node { int u, v, w; }; vector<node> out; int n, m, dis[maxn], val[maxn], pre[maxn], cant[maxn]; bool vis[maxn]; vector<pair<int, int> > G[maxn], tmp; map<pair<int, int>, int> mp; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) ...
13
#include <bits/stdc++.h> using namespace std; vector<int> adj[105]; int n, k; struct State { int node, disUp, disDown; bool operator<(const State &other) const { if (node != other.node) return node < other.node; if (disUp != other.disUp) return disUp < other.disUp; return disDown < other.disDown; }; }...
17
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 1; int dp[N][N]; int acc[N]; int ht[N]; int nxt[N][N]; int n; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; ++i) { cin >> acc[i + 1]; acc[i + 1] += acc[i]; } for (int i = 0; i < n; ...
13
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000; bool used[1100]; string S, St; int n; map<char, int> M; vector<int> prime(int n) { vector<int> Ans; vector<bool> p; p.assign(n + 1, true); p[1] = false; for (int i = 2; i <= n; ++i) { if (p[i]) for (int j = i + i; j <=...
5
#include <bits/stdc++.h> using namespace std; int a[100010], b[100010]; int main() { int n, sum, k; while (~scanf("%d%d", &n, &k)) { sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); for (int i = 0; i < n && k; i++) { for (int j = n - 1 - i; j >= 0 && k; j-...
8
#include <bits/stdc++.h> using namespace std; long long int ans(int num) { long long int sum = 0; for (int i = 0; i <= 5; i++) { if ((num >> i) % 2 == 0) { sum++; } } return sum; } long long int power(long long int sum) { long long int ans = 1, res = 3; while (sum) { if (sum % 2) ans *= re...
7
#include <bits/stdc++.h> using namespace std; int n; vector<int> note; vector<pair<int, int> > maxNote; vector<pair<int, int> > minNote; bool Work() { maxNote.resize(n); minNote.resize(n); maxNote[0] = make_pair(1, 1); minNote[0] = make_pair(1, 1); if (note[0] > 1) return false; for (int i = 1; i < n; ++i) ...
17
#include <bits/stdc++.h> using namespace std; const long long Maxn = 1e6 + 10; const long long Mod = 1e9 + 7; const long long Max = 1e3 + 1; const long long Inf = 1e9 + 1; char s[Max] = {0}, t[Maxn] = {0}; int main() { cin >> s >> t; int end = -1, start = -1, p = 0; int sl = strlen(s); int tl = strlen(t); for...
6
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(nam...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, plus, minus, A, B, C, D, E; string x, name; cin >> n; int array[n]; int sum, largest = -100000; for (int i = 0; i < n; i++) { cin >> x >> plus >> minus >> A >> B >> C >> D >> E; sum = (plus * 100) - (minus * 50) + A + B + C + D + E; ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long r, g, b, ans, minn, maxn; scanf("%I64d%I64d", &r, &g); scanf("%I64d", &b); minn = 2e9 + 5; maxn = max(r, g); maxn = max(maxn, b); int flag = 0; if (r == maxn) { if (maxn >= 2 * (g + b)) { flag = 1; ans = g + b; } ...
10
#include <bits/stdc++.h> using namespace std; const int N = 100 + 10; int main() { int n; cin >> n; vector<string> dict(n); for (int i = 0; i < n; i++) cin >> dict[i]; string s; bool mark[N] = {0}; cin >> s; for (int i = 0; i < (int)(s).size(); i++) { for (int j = 0; j < (int)(dict).size(); j++) { ...
8
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const long long mod = 998244353; const double eps = 1e-6; const double PI = acos(-1); const double R = 0.57721566490153286060651209; inline long long read() { long long res = 0; bool zf = 0; char c; while (((c = getchar()) < '0' || ...
13
#include <bits/stdc++.h> using namespace std; const int Mod = 777777777; const long long Mod2 = (long long)Mod * Mod; int n, k; inline int add(int a, int b) { a += b; if (a >= Mod) return a - Mod; return a; } inline int mul(int a, int b) { return (int)(((long long)a * b) % Mod); } int choose[1005][1005]; const in...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> v, color; bool flag = false; for (int i = 0; i < n; i++) { int x; cin >> x; x--; v.push_back(x); } int sum = 0; for (int i = 0; i < m; i++) { int x; cin >> x; sum += x; color.p...
7
#include <bits/stdc++.h> using namespace std; int main() { int x; scanf("%d", &x); if (x == 3) { printf("5"); } else { for (int k = 0;; ++k) { int v = 2 * k * k + 2 * k + 1; if (v >= x) { printf("%d", 2 * k + 1); break; } } } return 0; }
9
#include <bits/stdc++.h> int main() { int n, t; std::cin >> n >> t; int arr[n - 1]; int i = 0; for (; i < n - 1; ++i) std::cin >> arr[i]; i = 1; while (i < t) { i += arr[i - 1]; } std::cout << (i == t ? "YES" : "NO") << std::endl; }
2
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &output, const vector<T> &v) { if (v.empty()) return output; for (int i = 0; i < v.size() - 1; i++) output << v[i] << " "; output << v.back(); return output; } template <typename T> istream &operator>>(istream &input...
12
#include <bits/stdc++.h> using namespace std; int n, a[1000], mas[1000], st, fin; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int cur = 0; for (int i = 0; i < n / 2 + n % 2; i++) { mas[cur] = a[i]; cur += 2; } cur = 1; for (int i = n / 2 + n % 2;...
2
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, a, b, c; int main() { std::cin.sync_with_stdio(false); std::cin.tie(0); cin >> n >> m >> k >> a >> b >> c; if (a >= n && a + b >= n + m && a + b + c >= n + m + k) { cout << "YES"; } else { cout << "NO"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); long long gcd(long long a, long long b) { while (b) { a %= b; a ^= b, b ^= a, a ^= b; } return a; } int main() { long long a, b; scanf("%I64d%I64d", &a, &b); if (gcd(a, b) > 1) puts("Impossible"); else { while (a &...
16
#include <bits/stdc++.h> int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int n; int a[100005]; int a1[100005]; int i; int cou = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); a1[i] = a[i]; } qsort(a1, n, sizeof(int), cmp); for (i = 0; i...
5
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define oo 1000000010 const int N = 300010; int n , arr[N]; vector< int > g[N]; int main(){ scanf("%d",&n); for(int i = 0 ;i < n;i++){ scanf("%d",&arr[i]); } for(int i = n - 1;i >= 0;i--){ g[arr[i]].push_back(i); } int last1 = -1, last2...
13
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:16777216") #pragma warning(disable : 4786) int cnt[1000002]; int getValue(char a[]) { int ret = 0; for (int i = 0; a[i]; i++) { ret = ret * 2 + (a[i] - 48); } return ret; } int getPattern(char a[]) { char bin[100]; long long l...
6
#include <bits/stdc++.h> using namespace std; int n, k; int arr[505][505]; int main() { scanf("%i%i", &n, &k); arr[1][1] = 1; int curr = 1; int sum = 0; if (k == 1) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { arr[i][j] = curr; curr++; if (j == k) { ...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long pow_q(long long n, long long q) { long long tmp = 1; while (q > 0) { if (q & 1) { tmp *= n; tmp %= mod; } n *= n; n %= mod; q >>= 1; } return tmp; } int main() { long long n; scanf("%lld", ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int MOD = 1e9 + 7; int n, ans, ret; int tot[N], p10[N], p2[N], t4[N], t7[N], t47[N]; int a[N]; void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } void dfs(int x, int y, int o) { if (x == n + 1) return; if (!o) { int bt = n -...
20
#include <bits/stdc++.h> using namespace std; long long n, k, ans = 1e18; signed main() { scanf("%lld%lld", &n, &k); for (long long i = 1; i <= n; i++) { if (n % i == 0) { long long j = n / i; long long x = k * i + j; if ((x % k) * (x / k) == n) ans = min(ans, x); } } printf("%d\n", an...
3
#include <bits/stdc++.h> using namespace std; long long int n, m, ara[10010], low[10010][1010], g, r, ind, rem, vrem, res; deque<pair<long long int, long long int> > q; int main() { cin >> n >> m; for (int i = 0; i < m; i++) cin >> ara[i]; sort(ara, ara + m); cin >> g >> r; for (int i = 0; i <= m; i++) { ...
16
#include <bits/stdc++.h> using namespace std; int main() { long long int m; cin >> m; long long int arr[m]; for (int j = 0; j < m; j++) { cin >> arr[j]; } sort(arr, arr + m); long long int ans = 0; for (int j = 0, h = m - 1; h > j; h--, j++) { ans += ((arr[j] + arr[h]) * (arr[j] + arr[h])); } ...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll MOD = 998244353; int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); re...
7
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(0); int n, i, j, k, cnt; long double p[] = {500, 1000, 1500, 2000, 2500}; long double m[10], w[10], s, u, sum = 0; for (i = 0; i <= 4; i++) cin >> m[i]; for (i = 0; i <= 4; i++) cin >> w[i]; cin >> s >> u; for (i =...
2
#include <bits/stdc++.h> using namespace std; long long n, px, py; double dist(long long px, long long py, long long x1, long long y1, long long x2, long long y2) { double d2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); if (d2 == 0.0) return ((x1 - px) * (x1 - px) + (y1 - py) * (y1 - py)); double ...
11
#include <bits/stdc++.h> using namespace std; const long long maxn = 5000 * 1000 + 5, base = 737, mod = 1000 * 1000 * 1000 + 7; long long dp[maxn]; bool p[maxn]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; long long x = 0, y = 0, b = 1; f...
14