solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcoun...
9
#include <bits/stdc++.h> using namespace std; long long a, b, total = 0, temp; int main() { scanf("%I64d %I64d", &a, &b); while (a != 0 && b != 0) { total += a / b; a %= b; temp = a; a = b; b = temp; } printf("%I64d\n", total); return 0; }
4
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <class T> inline T ison(T n...
5
#include <bits/stdc++.h> using namespace std; vector<long long int> v[1003]; long long int has[1003]; void balance(long long int a, long long int b) { has[a] -= 1; has[b] -= 1; for (long long int i = 0; i < v[a].size(); i++) if (has[v[a][i]] != 0) has[v[a][i]] -= 1; for (long long int i = 0; i < v[b].size()...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000007; int a[200001]; int b[200001]; int main() { long long n, x, ans = 1; cin >> n; for (int i = 2; i < n; i++) { x = i; while (x % 2 == 0) { b[2]++; x /= 2; } for (int j = 3; j <= sqrt(x); j += 2) while (x % j ...
5
#include <bits/stdc++.h> using namespace std; char s[505]; int graph[505][505]; int n, m, a, b; int flag; void dfs(int i, char k) { s[i] = k; for (int j = 1; j <= n; j++) { if (i != j && s[j] != 'b') if (graph[i][j] == 0) { if (s[j] == 'd') { k == 'a' ? dfs(j, 'c') : dfs(j, 'a'); ...
5
#include <bits/stdc++.h> int n, a, s; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); if (a < 0) s += a * -1; else s += a; } printf("%d", s); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1050; int n, tot = 0, m = 0; int siz[N], p[N], h[N], ex[N], ey[N]; vector<int> RT, U; namespace GRD { int f[N][N]; void init() { int i, j, k, u, v; memset(f, 0x3f, sizeof(f)); for (i = 1; i <= n; i++) f[i][i] = 0; for (i = 1; i < n; i++) { scanf("%...
11
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> using namespace std; #define endl '\n' #define ll long long #define pi pair<int, int> #define f first #define s second const int mxn = 100003, k = 4; int n; string s; vector<pi> v; vector<int> ans; int dp[mxn]; int main(){ ios::sync_with_st...
9
#include <bits/stdc++.h> using namespace std; int y, z[101], n, a[101][101], x, b[101]; int main() { cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { cin >> a[i][j]; if (a[i][j] == 1) { b[i] = 1; } if (a[i][j] == 2) { b[j] = 1; } if (a[i...
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T& x) { int f = 0, c = getchar(); x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); if (f) x = -x; } template <typename T, typename... Args> inline void read(T& x,...
7
#include <bits/stdc++.h> using namespace std; const int maxN = 22, MOD = 1e9 + 7; const long long INF = LLONG_MAX >> 1; int dp[1 << maxN], au[1 << maxN], adj[maxN], n; void prt(int m) { int ct = 0; for (int i = 0; i < n; i++) if (1 << i & m) ct++; cout << ct << '\n'; while (m) cout << au[m] + 1 << ' ', m ^=...
8
#include <bits/stdc++.h> using namespace std; long long n, ans, ra, rb, rc, P[20][70], p[20]; int k, d[20]; void attB(int i, long long a, long long b, long long bc) { if (b * b > bc) return; if (i == k) { long long c = bc / b; if (a * b + b * c + c * a < ans) { ans = a * b + b * c + c * a; ra = ...
10
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 3e5 + 5; char s[maxn]; int st[maxn], ed[maxn]; int rk[maxn], tp[maxn], tax[maxn]; int height[maxn], sa[maxn], f[maxn][21], bin[maxn]; int mn[maxn][21], mx[maxn][21]; int M; void qsort(int n) { for (int i = 0; i <= M; i++) tax[i]...
7
#include <bits/stdc++.h> using namespace std; unsigned long long n, p[1000005], ans, l, h[1000005], db[1000005], f; char s[1000005]; void hhash(unsigned long long x) { for (unsigned long long i = 1; i < l; i++) { if (i + x - 1 >= l - 1) return; unsigned long long sum = h[x - 1]; if (h[i + x - 1] - h[i - 1...
4
/*______________________________________________Bismillahir Rahmanir Rahim____________________________________________ | | TTTTTTTTTTTTTTTTTTTTTTTRRRRRRRRRRRRRRRRR 888888888 ...
4
#include <bits/stdc++.h> using namespace std; string s[500000 + 10]; void calc(string& a, string& b) { if (a <= b) { return; } int i; for (i = 0; i < min(a.length(), b.length()); i++) { if (a[i] > b[i]) break; } a.resize(i); } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> s...
5
#include<iostream> using namespace std; const int N = 405; char a[N][N]; int main(){ int t;cin >> t; while(t --){ int n;cin >> n; int fl = 0; int x,y,xx,yy; for(int i = 0;i < n;i ++){ for(int j = 0;j < n;j ++){ cin >> a[i][j]; if(!fl ...
0
#include <bits/stdc++.h> using namespace std; const int NN = 2e5 + 100; long long n, dp[NN + 100]; long long mod = 998244353; int main() { cin >> n; dp[0] = 1; for (int i = 1; i <= NN; i++) { dp[i] = 10 * dp[i - 1] % mod; } for (int i = 1; i < n; i++) { long long res = 180 * dp[n - i - 1] % mod; r...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; void err(istringstream &ss) { cout << "\n"; } template <typename T, typename... Args> void err(istringstream &ss, const T &a, const Args &...args) { string token; getline(ss, token, ','); cout << token << " = " << ...
2
#include <bits/stdc++.h> using namespace std; template <class c> c gcd(c a, c b) { if (b == 0) return a; gcd(b, a % b); } template <class a> bool prime(a n) { for (a i = 2; i <= sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } bool bigger(pair<int, int> picachu, pair<int, int> qicachu) { return (...
3
#include <bits/stdc++.h> using namespace std; int cnt[3] = {0}, prime[400005]; vector<int> p; void preComp() { for (int i = 0; i < 400005; i++) { prime[i] = 1; } prime[0] = 0; prime[1] = 0; for (int i = 2; i <= 400000; ++i) { if (prime[i]) { for (int j = 2 * i; j <= 400000; j += i) { pri...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5; const int S = 450; const uint8_t M = 101; int n, m, l, r; uint8_t a[N], x, y; int st[S], en[S], bk[N]; list<int> b[S][M]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%hhu", a + i); int i = 0, j = 0, k = 0; while (i < n) { ...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e2 + 10; long long n, arr[MAXN], aarr[MAXN], al[MAXN], l[MAXN], dp[MAXN][MAXN], dp2[MAXN][MAXN], save[MAXN][MAXN], maper, p[MAXN]; set<int> s; map<int, long long> mp, mp2, mp3; bool cmp(int i, int j) { return aarr[i] < aarr[j]; } int main() { ios::sy...
11
#include <bits/stdc++.h> using namespace std; const long long MOD = 1E9 + 7; const long long N = 2E5 + 6; const long long inf = 1E15; int main() { ios::sync_with_stdio(false); cin.tie(NULL); if (fopen("inp.txt", "r")) { freopen("inp.txt", "r", stdin); freopen("outp.txt", "w", stdout); } long long n, i...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int a[maxn]; int main() { int n; while (cin >> n) { int ans = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i]) ans++; } for (int i = 1; i <= n; i++) { if (a[i] == 1) { if (i == 1) continue; ...
0
#include <bits/stdc++.h> using namespace std; int getint() { int _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(); return _x * _tmp...
7
#include <bits/stdc++.h> using namespace std; const int N = 1000005; const int mo = 998244353; int n, fac[N], inv[N], C[N * 2]; int main() { scanf("%d", &n); fac[0] = inv[0] = inv[1] = 1; for (int i = (int)(2); i <= (int)(n); i++) inv[i] = 1ll * inv[mo % i] * (mo - mo / i) % mo; for (int i = (int)(1); i <= ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long n, c = 0; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == '-' && c > 0) { c--; } else if (s[i] == '+') { c++; } } cout << c; }
0
#include <bits/stdc++.h> using namespace std; void getData(int *dataArray, int count) { for (int i = 0; i < count; i++) { scanf("%d", &dataArray[i]); } } double inline max(double x, double y) { return x - y > 1e-6 ? x : y; } int main() { int n; scanf("%d", &n); int *x = new int[n]; getData(x, n); int ...
2
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; vector<string> v; int i = 0; while (i < s.size()) { if (s[i] == '0') { i++; continue; } int j; j = i; while (s[j++] == '1' && j <= s.size()) ; v.push_back(s.substr(i, j - i - 1)); i =...
0
#include <bits/stdc++.h> using namespace std; void RI(int& x) { x = 0; char c = getchar(); while (!(c >= '0' && c <= '9' || c == '-')) c = getchar(); bool flag = 1; if (c == '-') { flag = 0; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } if (!fla...
6
#include <bits/stdc++.h> using namespace std; long long n, m; long long ans[51]; bool used[51]; int main() { scanf("%I64d%I64d", &n, &m); long long i = 1, last = 1, cnt = n - 2; for (; i <= n && last <= n;) { if ((1LL << cnt) >= m) { cnt = max(cnt - 1, 0LL); ans[i] = last++; i++; conti...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, a, p, price = 101, money = 0; cin >> n; while (n--) { cin >> a >> p; if (price > p) { price = p; } money += a * price; } cout << money; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[2 * n]; for (long long int i = (0); i < (2 * n); i++) cin >> a[i]; long long int b[2 *...
5
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b, long long int m = 1000000007) { if (b == 0) return 1; if (b == 1) return a; long long int c = power(a, b / 2, m); if (b % 2 == 0) return ((c % m) * (c % m)) % m; return ((((c % m) * (c % m))...
0
#include <bits/stdc++.h> using namespace std; long long arr[200010]; priority_queue<pair<long long, long long> > pq, pq1; vector<long long> v; int main() { long long total; cin >> total; for (long long i = 1; i <= total; i++) { scanf("%lld", &arr[i]); pq1.push(make_pair(-arr[i], i)); } char p; for (...
2
#include <bits/stdc++.h> using namespace std; int n, q, t, nc = 0, root; int in[200005]; int out[200005]; int sm[400005]; bool lazy[400005]; int lc[400005]; int rc[400005]; int src[200005]; vector<int> v[200005]; char s[5]; int build(int l, int r) { int id = ++nc; if (l == r) { sm[id] = src[l]; lazy[id] = f...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int arr[maxn]; int main() { int b, k; scanf("%d%d", &b, &k); for (int i = k - 1; i >= 0; i--) { scanf("%d", &arr[i]); } long long ans = 0; for (int i = k - 1; i >= 0; i--) { if (i) ans += arr[i] * b; else ans += ...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, tex, n = 3, d = 0; cin >> a >> b >> c; d = a + b + c; if (2 * a + 2 * b < d) d = 2 * a + 2 * b; if (a * 2 + 2 * c < d) d = a * 2 + 2 * c; if (b * 2 + 2 * c < d) d = b * 2 + 2 * c; ; cout << d << endl; }
0
#include <bits/stdc++.h> int n; int pzs(int k) { for (int i = 2; i * i <= k; i++) { if (k % i == 0) { return 0; break; } } return 1; } int main() { scanf("%d", &n); if (pzs(n)) { printf("1\n%d\n", n); return 0; } printf("3\n3 "); n -= 3; for (int i = 3;; i += 2) { if (p...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, a, d; double t[100005]; cin >> n >> a >> d; memset(t, 0, sizeof(t)); for (int i = 1; i <= n; i++) { int tt, v; double s; cin >> tt >> v; double ttt = (double)v / a; s = 0.5 * a * ttt * ttt; if (s <= d) { t[i] = tt ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m > n) cout << -1 << endl; else { if (m == n) cout << m << endl; else { int p = n / 2 + n % 2; while (p % m != 0 && p <= n) { p++; } cout << p << endl; } } return 0; ...
1
#include <bits/stdc++.h> using namespace std; const long long mxn = 1e5 + 7; int main() { long long n; set<long long> qwe; while (cin >> n) { qwe.insert(n); } cout << 4 - qwe.size(); }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; char s[maxn]; int main() { scanf("%s", s); int n = strlen(s); int m = (n + 1) / 2; int ans = 0; for (int i = 0; i < m; i++) { if (s[i] != s[n - i - 1]) ans++; } if (n & 1) { if (ans <= 1) printf("YES\n"); else ...
1
#include <bits/stdc++.h> using std::set; using std::string; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); string s; std::cin >> s; int h = -1, e = -1, i1 = -1, i2 = -1, d = -1; for (size_t i = 0; i < s.size(); ++i) { if (s[i] == 'h' && h < 0) { h = i; } if (s[i...
0
#include <bits/stdc++.h> using namespace std; inline void init() { ios::sync_with_stdio(false); cin.tie(0); } int dx[4] = {0, 0, -1, 1}; int dy[4] = {-1, 1, 0, 0}; const int N = 2001; const int INF = 0x3f3f3f3f; int g[N][N]; bool vis[N][N]; int lft[N][N]; void test() { int n, m; cin >> n >> m; int r, c; cin...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; vector<pair<int, int> > v; cin >> s; int n = (int)s.length(), last = 0; for (int i = 0; i < n; i++) { if (i == n - 1 || s[i] != s[i + 1]) { if (s[i] == '1') { ...
5
#include <bits/stdc++.h> using namespace std; const int N = 4444; const int M = N * 10; int s[N], c[M]; char str[N]; int main() { long long a; while (cin >> a >> str) { int n = strlen(str); s[0] = 0; for (int i = 0; i < n; i++) s[i + 1] = str[i] - '0'; for (int i = 1; i <= n; i++) s[i] += s[i - 1]; ...
4
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265359; const long long int mini = 1e18; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long n, m, i, j, l, k = 0, p = 0, s = 0, t = 1, x, y, z, r, c; long long a[15]; long long b[15] = {0}; cin >> n >> ...
1
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return res; } signed main() { std ::ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); ;...
4
#include <bits/stdc++.h> using namespace std; using lint = long long; using ulint = unsigned long long; const int N = 500 + 1; const int K = 10 + 1; int h[K]; int dp[N * K]; int n, k; int solve(int p, int c) { if (p == 0 || c == 0) { return 0; } fill(begin(dp), end(dp), 0); while (p--) { for (int i = 0;...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for (int it = 0; it < t; ++it) { int n; cin >> n; vector<int> v(n, 0); for (auto& x : v) cin >> x; vector<int> kek(n, 0); if (n % 2 == 1) { for (int i = 0; i <= n...
2
#include <bits/stdc++.h> using namespace std; inline void read(long long &x) { x = 0; long long f = 1; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s ^ 48); s = getchar(); } x *= f; } inl...
5
#include <bits/stdc++.h> using namespace std; struct node { int l, r; mutable long long val; node(int L = -1, int R = -1, long long Val = 0) { l = L, r = R, val = Val; } bool operator<(const node &d) const { return l < d.l; } }; set<node> s; int n, m, inp; int seed, vmax; vector<pair<long long, int> > v; int rn...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x1, y1, x2, y2; scanf(" %d %d %d %d", &x1, &y1, &x2, &y2); if (x1 != x2) printf("%d %d\n", x1, x2); else if (y1 != y2) printf("%d %d\n", y1, y2); else printf("...
0
#include <bits/stdc++.h> using namespace std; int main() { bool b = false; int a1[5000], a2[5000], a3[5000], b1 = 0, b2 = 0, b3 = 0; int n; cin >> n; int a[n], t1 = 0, t2 = 0, t3 = 0, m; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == 1) { t1++; a1[b1] = i; b1++; } else...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; template <typename T> inline T read() { T ans = 0, flag = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') flag = -1; c = getchar(); } while (isdigit(c)) { ans = ans * 10 + c - 48; c = getchar(); } return an...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const double eps = 1e-12; double x, y; double k; int cal1(int mid) { double temp = (y - x) / (-2 * mid); if (temp + eps >= y) return 1; else return 0; } int cal2(int mid) { double temp = (y + x) / (2 * mid); if (temp + eps >= y) ...
4
#include <bits/stdc++.h> using namespace std; const int inft = 1000000009; const int MAXN = 1000006; const double eps = 1e-15; inline bool iszero(double first) { return first <= eps && first >= -eps; } int sgn(double first) { return iszero(first) ? 0 : (first < 0 ? -1 : 1); } struct pt { int first, second; int nr; ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; char str[maxn]; int dp[maxn]; int main() { while (scanf("%s", &str) == 1) { int len = strlen(str); int ans = 0; int sum = 0; stack<int> s; memset(dp, 0, sizeof(dp)); for (int i = 0; i < len; ++i) { if (str[i] == '(')...
5
#include <bits/stdc++.h> const int N = 300000; int n; char s[N + 1]; int main() { scanf("%d%s", &n, s); int p = -1; for (int i = 0; i < n - 1; ++i) if (s[i] > s[i + 1]) p = i; if (p != -1) { printf("YES\n"); printf("%d %d\n", p + 1, p + 2); } else printf("NO\n"); return 0; }
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int add(int a, int b) { long long x = a + b; if (x >= 998244353) x -= 998244353; if (x < 0) x += 998244353; return x; } long long mul(long long a, long long b) { return (a * b) % 998244353; } long long pw(long long a, long long b) { long...
8
#include <bits/stdc++.h> using namespace std; int b, d; string a, c; int dp[111]; int main() { cin >> b >> d >> a >> c; for (int i = (0); i < (c.size()); i++) { int k = 0; for (int j = (0); j < (a.size()); j++) if (c[(i + k) % c.size()] == a[j]) k++; dp[i] = k; } long long int ans = 0; for (...
6
#include <bits/stdc++.h> using namespace std; int a[110]; int main() { int n, m, l, r, i, j; int k = 0; while (~scanf("%d %d", &n, &m)) { memset(a, 0, sizeof(a)); for (i = 1; i <= m; i++) a[i] = i; for (i = 1; i <= n; i++) { scanf("%d %d", &l, &r); for (j = l; j <= r; j++) a[j] = 0; } ...
0
#include <bits/stdc++.h> const int N = 100100; std::mt19937 rd(time(0)); int ls[N], rs[N], sz[N], p[N], rt, n, tot; long long v[N], ad[N], tg[N]; int nd(long long a) { return p[++tot] = rd(), sz[tot] = 1, v[tot] = a, tot; } void up(int x) { sz[x] = sz[ls[x]] + sz[rs[x]] + 1; } void pt1(int x, long long t) { if (x) v[...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); map<char, int> mp; int t = 1; for (char i = 'a'; i <= 'z'; i++) { mp[i] = t; t++; } int n, k; cin >> n >> k; string s; cin >> s; sort(s.begin(), s.end()); s...
0
#include <bits/stdc++.h> using ll = long long; using namespace std; unsigned long long int leftRotate(unsigned long long int n, unsigned long long int d) { return (n << d) | (n >> (16 - d)); } unsigned long long int rightRotate(unsigned long long int n, ...
2
#include <bits/stdc++.h> using namespace std; template <class T> void readi(T &x) { T input = 0; bool negative = false; char c = ' '; while (c < '-') { c = getchar(); } if (c == '-') { negative = true; c = getchar(); } while (c >= '0') { input = input * 10 + (c - '0'); c = getchar();...
6
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf("%d", &x); return x; } bool Check(int N, int pos) { return (bool)(N & (1 << pos)); } int Set(int N, int pos) { return N = N | (1 << pos); } int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1}; int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; int hr[...
0
#include <bits/stdc++.h> using namespace std; long long n, g, b; void Process() { cin >> n >> g >> b; long long good = (n + 1) / 2; long long bad = n - good; long long cycle = good / g; if (good % g == 0) --cycle; good -= cycle * g; bad -= cycle * b; if (bad <= 0) { cout << cycle * (g + b) + good <<...
3
#include <bits/stdc++.h> using namespace std; int main() { char srt[110]; int count = 1, i, l, max = 0; gets(srt); l = strlen(srt); for (i = 0; i < l; i++) { if (srt[i] == 'A' || srt[i] == 'E' || srt[i] == 'I' || srt[i] == 'U' || srt[i] == 'O' || srt[i] == 'Y') { if (count > max) { m...
1
#include <bits/stdc++.h> using namespace std; const int MN = 1000111; const int BASE = 1000000007; int f[2][MN], g[2][MN]; int main() { int n = 1000000; f[0][1] = g[0][1] = 0; f[1][1] = g[1][1] = 1; for (int i = (2), _b = (n); i <= _b; i++) for (int last = 0, _a = (2); last < _a; last++) { if ((i & 1)...
4
#include <bits/stdc++.h> using namespace std; struct SuffixAutomaton { int len[2 * 1000100], link[2 * 1000100], cnt[2 * 1000100]; int nxt[2 * 1000100][26], sz, last, root; int newnode() { int x = ++sz; len[x] = 0; link[x] = -1; cnt[x] = 1; for (int c = 0; c < 26; c++) nxt[x][c] = 0; return...
9
#include <bits/stdc++.h> using namespace std; const long long m1 = 799999969; const long long k1 = 599999929; struct h { long long v; int l; }; long long pot[300011]; long long minv[300011]; long long modpot(long long x, long long p, long long mod) { if (p == 0) return 1; if (p % 2 == 1) return (x * modpot(x, p...
11
#include <bits/stdc++.h> using namespace std; int mo = 1e9 + 7, x[101000], n, L[101000], R[101000], f[101000], two[101000], ten[101000], tot[101000], l[101000], r[101000], size[101000], w[101000]; char ch[101000]; int solve() { int ans = 0; size[n + 1] = 1; int totnum = 0; for (int i = n; i; i--) if (x[...
10
#include <bits/stdc++.h> const long long K = 1e6 + 100; const long long MOD = 1e9 + 7; long long n, k; long long pre[K]; long long suf[K]; long long fac[K]; long long inv[K]; long long pow(long long x, long long k) { if (x == 0) return 0; long long res = 1; while (k) { if (k & 1) res *= x, res %= MOD; x *...
9
#include <bits/stdc++.h> using namespace std; int a[300]; int main() { int n, i, ans; while (scanf("%d", &n) != EOF) { ans = 0; int f = 0; for (i = 0; i < 2 * n - 1; i++) { scanf("%d", &a[i]); if (a[i] < 0) { f++; } } sort(a, a + 2 * n - 1); a[2 * n - 1] = 1; if...
5
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFLL = 1e18; const int MOD = 998244353; const int MAXN = 2e5 + 5; long long dp[MAXN][11]; int n; vector<int> g[MAXN]; int dfs(int v, int d, int p) { if (dp[v][d] != -1) return dp[v][d]; int r = INF; if (d == 0) { r = 0;...
6
#include <bits/stdc++.h> using namespace std; inline void read(register int *n) { register char c; *n = 0; do { c = getchar(); } while (c < '0' || c > '9'); do { *n = c - '0' + *n * 10; c = getchar(); } while (c >= '0' && c <= '9'); } vector<int> kperm(vector<int> V, long long k) { k--; vect...
5
#include <bits/stdc++.h> using namespace std; char memo[503][503][503]; int c[503], n; char DP(int pos, int c1, int c2) { if (pos == n) return c1 == 0 && c2 == 0; char &ret = memo[pos][c1][c2]; if (ret != -1) return ret; char ans = DP(pos + 1, c1, c2); if (c[pos] <= c1) ans = max(ans, DP(pos + 1, c1 - c[pos],...
5
#include <bits/stdc++.h> using namespace std; int main() { int a[200010], n; scanf("%d", &n); stack<int> s; for (int i = 1; i <= n; i++) { cin >> a[i]; if (!s.empty() && abs(s.top() - a[i]) % 2 == 0) s.pop(); else s.push(a[i]); } if (s.size() <= 1) cout << "YES" << endl; else ...
7
#include <bits/stdc++.h> using namespace std; long long int MOD = 1e9 + 7; long long int INF = 1e18; long long int power(long long int base, long long int exp) { long long int res = 1; while (exp > 0) { if (exp % 2 == 1) res = (res * base); base = (base * base); exp /= 2; } return res; } long long i...
6
#include <bits/stdc++.h> using namespace std; const int maxN = (int)1e6 + 10; int a, b; int f[maxN]; int ans[maxN]; int to[maxN]; vector<int> v; int n; int main() { ios_base::sync_with_stdio(false); cin >> n; v.resize(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); v.erase(unique(v.be...
7
#include <bits/stdc++.h> using namespace std; const int N = (2e5 + 10); char s[2][N]; struct node { int l, r; int val[4]; } t[N * 4]; void pushup2(node &u, node &l, node &r) { u.val[0] = min({u.val[0], l.val[0] + r.val[0], l.val[1] + r.val[2]}); u.val[1] = min({u.val[1], l.val[0] + r.val[1], l.val[1] + r.val[3]...
7
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } struct point { double first, second; point(double first = 0, double second = 0) : first(first), se...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 17; int a[MAXN], m, lazy[MAXN << 2], seg[MAXN << 2]; void relax(int v) { seg[v << 1] += lazy[v]; seg[v << 1 | 1] += lazy[v]; lazy[v << 1] += lazy[v]; lazy[v << 1 | 1] += lazy[v]; lazy[v] = 0; } void add(int lp, int rp, int val, int v ...
7
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 12; const long long INF = 1e18, mod = 1e9 + 7; int n, h[N], in[N], out[N], was[N]; long long t[N], ans, dp1[N], dp2[N]; vector<int> g[N]; void dfs(int v, int pr) { was[v] = 1; vector<long long> dif; long long sum = 0; for (int to : g[v]) { if...
10
#include <bits/stdc++.h> const int mod = 1e9 + 7; using namespace std; long long POW(long long bs, long long ex) { long long res = 1; while (ex) { if (ex % 2) res = (res * bs) % mod; bs = (bs * bs) % mod; ex /= 2LL; } return res % mod; } long long GS(long long r, long long n) { if (r == 1) return ...
4
#include <bits/stdc++.h> using namespace std; template <typename T> T nextInt() { T x = 0, p = 1; char ch; do { ch = getchar(); } while (ch <= ' '); if (ch == '-') { p = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + (ch - '0'); ch = getchar(); } return x * p; ...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; int n, m; vector<vector<int> > A, sol; inline int num(int i, int j) { return i * m + j + 1; } void load() { scanf("%d%d", &n, &m); } void transpose(vector<vector<int> > &X) { vector<vector<int> > B; for (int i = 0; i < m; i++) { vector<int> ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, m, a[maxn], b[maxn]; bool pan(long long x) { for (int i = 1; i <= n; i++) b[i] = a[i]; int pos = n; for (int i = 1; i <= m; i++) { long long t = x; while (!b[pos] && pos) pos--; if (!pos) return true; t -= pos; if (t...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long sum = 0, cur = 0, x; cin >> x; int* y = new int[x]; for (int i = 0; i < x; i++) { cin >> y[i]; sum += y[i]; } for (int i = 0; i < x; i++) { cur += y[i]; ...
2
#include <bits/stdc++.h> using namespace std; int n, m, h; int bb[109][109][109]; int a[109], b[109], c[109][109]; int main() { scanf("%d%d%d", &n, &m, &h); for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= h; k++) { bb[i][j][k] = 1; } } } for (int i ...
2
#include <bits/stdc++.h> using namespace std; int n; int lista[507]; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> lista[i]; } bool flag = false; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { for (int k = 0; k < n; ++k) { int t[3] = {lista[i], lista[j], lista[...
0
#include <bits/stdc++.h> using namespace std; int g[65]{0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10}; const int MAXN = 1000007; int s[MAXN]; map<p...
6
#include <bits/stdc++.h> using namespace std; void solve() { return; } int main() { int q; cin >> q; for (int i = 0; i < q; i++) { long long n, k; cin >> n; int a[2 * n]; map<int, int> pos; for (int i = 0; i < 2 * n; i++) { cin >> a[i]; pos[a[i]] = i; } long long val, prev ...
5
#include <bits/stdc++.h> using namespace std; int main() { string s, p = ""; int n, k; cin >> n >> k >> s; for (int i = 0; i < k; i++) { char c; cin >> c; p += c; } long long ans = 0; int len = 0; for (int i = 0; s[i]; i++) { if (strchr(p.c_str(), s[i])) { len++; } else { ...
2
#include <bits/stdc++.h> using namespace std; long long n, m; vector<vector<long long>> g; vector<vector<pair<long long, long long>>> dp; pair<long long, long long> add(pair<long long, long long> a, pair<long long, long long> b) { return {a.first + b.first, a.second + b.second}; } vecto...
8
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n'; const ll nmax = 1000000007; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); ll t; cin >> t; while(t--){ ll n, a, b; cin >> n >> a >> b; string s; cin >...
1