solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int n, i, j, k, m, s, r; bool f; char str[50000010]; int A[50000010], ll[2], rr[2], rr2[2], I[2], P[100][2], power[2], mod[] = {40009, 40013}; int fun(char c) { if (islower(c)) return c - 'a' + 1; if (isupper(c)) return c - 'A' + 27; return c - '0' + 53; } int mai...
14
#include <bits/stdc++.h> using namespace std; bitset<1000003> visited; bitset<1000003> ada; vector<int> vec[1000003]; long long edge[1000003]; void dfs(int u) { visited[u] = 1; for (int v : vec[u]) if (!visited[v]) dfs(v); } int main() { long long loop = 0; int n; long long m; scanf("%d %lld", &n, &m); ...
13
#include <bits/stdc++.h> using namespace std; const int M = 23e4 + 5; int sum[M], n, fen[M]; int main() { scanf("%d", &n); int t = 2; while (t--) { memset(fen, 0, sizeof fen); for (int i = 0; i < n; i++) { int p; scanf("%d", &p); int k = p, u = p, ans = 0; for (; p > 0; p -= p & -p...
12
#include <bits/stdc++.h> using namespace std; long long dp[100000][3][2]; int n; int adj[100000][2]; long long solve(int p, int d, int b) { long long& res = dp[p][d][b]; if (res != -1) return res; res = 0; if (d == 2) { long long dirback = 0, dirnoback = 0, esqback = 0, esqnoback = 0, t; t = adj[p][1] -...
12
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:64777216") void Solve() { int ti, td, tr, te; cin >> ti >> td >> tr >> te; string a, b; cin >> a >> b; a = " " + a; b = " " + b; vector<vector<int> > d(a.size(), vector<int>(b.size(), 0)); vector<vector<int> > lastA(a.size(), ...
18
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); mt19937_64 rnd64( chrono::high_resolution_clock::now().time_since_epoch().count()); long long power(long long a, long long m, long long mod) { long long ans = 1; while (m) { if (m % 2)...
19
#include <bits/stdc++.h> using namespace std; int r, c, n, k; bool has[11][11]; int main() { cin >> r >> c >> n >> k; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; has[x][y] = 1; } int ans = 0; for (int u = 1; u <= r; u++) { for (int d = u; d <= r; d++) { for (int l = 1; l <= c...
22
#include <bits/stdc++.h> inline long long Read() { char c = getchar(); long long n = 0; while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') n = (n << 1) + (n << 3) + (c ^ 48), c = getchar(); return n; } long long n, q; int main() { n = Read(), q = Read(); for (int i = 1; i <= q; i++...
9
#include <bits/stdc++.h> using namespace std; void customrun() {} void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } bool isprime(long long n) { for (long long i = 2; (long long)i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } long long fib(in...
7
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n1, n2, a, b; cin >> n1 >> n2 >> a >> b; if (n1 > n2) cout << "First" << "\n"; else cout << "Second" << "\n"; r...
0
#include <bits/stdc++.h> using namespace std; long long a[200000 + 1], sum[200000 + 1], num[200000 << 1 | 1]; int main() { int n, m, pos; cin >> n >> m; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] == m) pos = i; } memset(num, 0, sizeof(num)); num[200000]++; sum[0] = 0; long long ...
10
#include <bits/stdc++.h> using namespace std; long long a[100005], b[100005], cartel[100005], x, y, k, n, tata[100005], i; vector<long long> v[100005]; long long ExpLog(long long b, long long e) { long long sol = 1; for (long long i = 1; i <= e; i <<= 1) { if (i & e) sol = (sol * b) % 1000000007; b = (b * b...
12
#include <bits/stdc++.h> using namespace std; const int N = 200043; const int INF = int(1e9) + 43; int n; int dp[N]; int p[N]; pair<int, int> a[N]; int t[N]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { a[i].second = i; scanf("%d", &a[i].first); } sort(a, a + n); for (int i = 1; i <= n;...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; int n; int a[30001]; int le; scanf("%d", &t); for (int ty = 0; ty < t; ty++) { le = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (i > 0 && a[i] < a[i - 1]) { le += (a[i - 1] - a[i]);...
10
#include <bits/stdc++.h> using namespace std; int main() { int x[27]; int y[27]; char z[25]; cin >> z; int i, sum = 0, flag = 0; for (i = 1; i < strlen(z); i++) { if (z[i] = z[i - 1]) sum++; else { flag = flag + sum; sum = 0; } } cout << (strlen(z) + 1) * 26 - strlen(z) << ...
1
#include <bits/stdc++.h> using namespace std; const int max_n = 1011, mod = 1000000007, inf = 1011111111; const long double lg = log2(3); bool cmp(int a2, int a3, int b2, int b3) { if ((a2 <= b2) == (a3 <= b3)) { return a2 <= b2 && a3 <= b3; } int o2 = min(a2, b2), o3 = min(a3, b3); a2 -= o2; b2 -= o2; ...
15
#include <bits/stdc++.h> using namespace std; int main() { int i, o1 = 0, o2 = 0; string s1; cin >> s1; for (i = 0; i < s1.size(); i++) o1 += (s1[i] == '1'); string s2; cin >> s2; for (i = 0; i < s2.size(); i++) o2 += (s2[i] == '1'); o1 += o1 % 2; if (o1 >= o2) cout << "YES"; else cout << "N...
9
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; int perm[MAX_N]; int vis[MAX_N]; vector<vector<int>> cycles; void dfs(int u) { if (vis[u]) return; vis[u] = 1; cycles.back().push_back(u); dfs(perm[u]); } int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i...
13
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { while (b != 0) { long long int t = b; b = a % b; a = t; } return a; } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } bool isprime(long long int n) { if (n == 1) re...
3
#include <bits/stdc++.h> using namespace std; long long mod; long long gcd(long long a, long long b) { return a % b == 0 ? b : gcd(b, a % b); } long long pow(long long a, long long b) { long long an = 1; long long base = a % mod; while (b > 0) { if (b & 1 != 0) { an = (an * base) % mod; } base...
1
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int N = 4 * n; int x = N - n; x = x / 4; for (int i = 0; i < x; i++) { cout << 9; } for (int i = 0; i < n - x; i++) { cout << 8; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); co...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 5; long long w[maxn][maxn], d[maxn]; bool v[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) { for (int j = 1; i + j < n; ++j) cin >> w[i][i + j], w[i + j][i] = w[i][i ...
19
#include <bits/stdc++.h> using namespace std; const long long MOD = 1E9 + 7; bool open(char ch) { return ch == '(' || ch == '<' || ch == '[' || ch == '{'; } bool match(char ch1, char ch2) { return ((ch1 == '{' && ch2 == '}') || (ch1 == '[' && ch2 == ']') || (ch1 == '<' && ch2 == '>') || (ch1 == '(' && ch2 =...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 200000; int n, q; int a[maxn + 1]; int lastUpdate[maxn + 1]; int l[maxn + 1], r[maxn + 1]; int mini[maxn + 1]; void update1(int t, int p, int x) { a[p] = x; lastUpdate[p] = t; } void update2(int t, int x) { mini[t] = x; } int main() { ios_base::sync_w...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> dppos(n), dpneg(n); vector<bool> ispos(n); for (int i = 0; i < n; i++) { int x; cin >> x; ispos[i] = (x > 0); } if (ispos[0]) { dppos[0] = 1; dpneg[0] = 0; } else { dppos[0] = 0; dpneg[0] ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x, y, z, m, r, s; cin >> x >> y >> z >> m >> r >> s; x = min(y, n - z - r); z = min(m, n - x - r); cout << x << " " << z << " " << n - x - z << endl; }
3
#include <bits/stdc++.h> using namespace std; struct matrix { int g[2][2]; }; matrix tree[300000]; matrix tmp, result; struct query { long long x; int y, z; inline bool operator<(const query t) const { if (x != t.x) return x < t.x; else return y < t.y; } }; query p[200000]; int g[100000]; ...
19
#include <bits/stdc++.h> using namespace std; template <class T> void splitstr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } static void redirec...
23
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 1000; char tmp[maxn]; long long ans[maxn]; int n, qq, sz, m, Time, dp[maxn], sum[maxn], ed[maxn]; int L[maxn], R[maxn], lft[maxn], rght[maxn], bel[maxn], ql[maxn], qr[maxn], qk[maxn]; vector<int> pos[maxn], ask[maxn], edge[maxn]; int root, tot,...
22
#include <bits/stdc++.h> using namespace std; int calc(int m) { int res = 0; while (m) { res += (m % 10); m /= 10; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> res; for (int i = (((0) > (n - 81)) ? (0) : (n - 81)); i <= n; i++) { ...
4
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; const long long INF = 1e18; const int Mod = 1e9 + 7; const int maxn = 1e6 + 10; long long n, x; int a[maxn]; long long d[maxn], s[maxn], sum[maxn]; void init() { for (int i = 1; i < maxn; i...
11
#include<bits/stdc++.h> using namespace std; void remchar(string &s,char c){ string t; for(auto &nx : s){ if(nx==c){continue;} t.push_back(nx); } s.swap(t); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t>0){ t--; vector<vector<int>> mem(26); ...
12
#include <bits/stdc++.h> #pragma GCC optimize("-O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; const long long MOD = 998244353; long long n, m, k, q, l, r, i, j, x, y, ans, a[200001]; long long tt[200001]; struct dsu { long long d[200001]; void make_set(long long h) { d...
10
#include <bits/stdc++.h> using namespace std; int main() { long long int t = 1, n, k, p, lop, s, no; while (t--) { scanf("%lld %lld", &n, &k); s = k - 1; p = 2; p = p + (s * 3); p++; if (n > k) { p = p + k; lop = n - k - 1; if (lop == 0) p = p + 2; else if (lo...
2
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive...
25
#include <bits/stdc++.h> using namespace std; string s, ss; int a, b, num; bool k = true; int main() { cin >> s; cin >> ss; num = ss.length(); for (int i = 0; i < s.length(); i++) { if (s[i] == '|') { k = false; continue; } if (k) a++; else b++; } if (abs(a - b) <= nu...
3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 1e6 + 100; const int mod = 1e9 + 7; int n, m, t; struct node { int l, r; long long mx, lz; } N[maxn << 2]; void up(int root) { N[root].mx = max(N[root << 1].mx, N[root << 1 | 1].mx); } void pd(int root) { if (!N[root].lz) r...
12
#include <bits/stdc++.h> const int MAXN = 5e5 + 10; using namespace std; inline long long in() { long long x = 0, flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getch...
25
#include <bits/stdc++.h> using namespace std; int solve() { long long int n, m, k; string str; long long int tmp = 0, sum = 0, cnt = 0; int flag = 0; cin >> n; vector<long long int> a(n); for (long long int i = 0; i < n; i++) cin >> a[i]; long long int prev = 1; long long int cur = 0; for (long long...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; int tempos[20]; int bb(int num, int minute) { int sup = num; int inf = 0; while (inf < sup) { int mid = inf + (sup - inf) / 2; if (tempos[mid + 1] <= minute) inf = mid + 1; e...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ; int t; cin >> t; for (int i = 0; i < int(t); i++) { int n, k; cin >> n >> k; string s; cin >> s; bool posib = true; for (int j = 0; j < int(k); j++) { char seen = '?'; ...
7
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) long long sms[100002]; int main() { int l; string cmd; while (cin >> l) { int n; int sc = 1; long long acum = 0; sms[0] = 1; for (int i = int(0); i < int(l); i++) { cin >> cmd; if (cmd[0] == 'a') { ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, s; cin >> n >> s; vector<int> g(n + 1); for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; ++g[a]; ++g[b]; } int l = 0; for (int i = 1; i <= n; ++i) { if (g[i] == 1) {...
9
#include <bits/stdc++.h> int main() { int n, m; scanf("%d%d", &n, &m); if (n > m) { int t = n; n = m; m = t; } if (n == 1) { printf("%d\n", m - m / 3 - (m % 3 == 0 ? 0 : 1)); } else if (n == 2) { printf("%d\n", m * n - 1 - m / 2); } else if (n == 3) { printf("%d\n", 2 * m + (m - 1)...
13
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T&& x) { cout << x << "\n"; } template <typename T, typename... S> void print(T&& x, S&&... y) { cout << x << ' '; print(y...); } const long long Mod = 1000000007, Mod2 = 998244353; const long long MOD = Mod2; const long long maxn = 30...
18
#include <bits/stdc++.h> using namespace std; double a, b, c, d, ans1, ans2; int main() { cin >> a >> b >> c >> d; ans1 = max(3 * a / 10.00, a - a * c / 250.00); ans2 = max(3 * b / 10.00, b - b * d / 250.00); if (ans1 < ans2) puts("Vasya"); else if (ans1 == ans2) puts("Tie"); else puts("Misha");...
1
#include <bits/stdc++.h> using namespace std; int a[100000], n, i, ans, bonus; int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) if (a[i] == i) ans++; for (i = 0; i < n; i++) { if (i != a[i] && i != a[a[i]] && bonus < 2) bonus = 1; if (i != a[i] && i == a[a[i]]) bon...
3
#include <bits/stdc++.h> using namespace std; long long d, m, t; int main() { scanf("%lld", &t); while (t--) { scanf("%lld %lld", &d, &m); long long ret = 1; bool brk = false; for (int bit = 0; bit <= 29; bit++) { long long lower = 1 << bit; long long upper = (1 << (bit + 1)) - 1; ...
9
#include <bits/stdc++.h> using namespace std; int s, m; string a, b; int main() { scanf("%d %d", &m, &s); a = b = "1"; for (int i = 1; i <= m - 1; ++i) a += "0", b += "0"; int s1 = s; if (s == 0 && m == 1) { puts("0 0"); return 0; } if (s == 0 || s > m * 9) { puts("-1 -1"); return 0; } ...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long maxn = 5e5 + 100; const long long inf = 1e15; long long n, m, k, t, h; struct vertex { long long mx = -inf; ; long long mn = inf; bool good = 1; bool operator==(vertex other) { return mx == other.mx && mn == other.mn ...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; vector<int> G[maxn]; vector<int> leaves; int fa[maxn]; int dep[maxn]; void dfs(int u) { bool leaf = true; for (auto v : G[u]) { if (dep[v] == 0) { leaf = false; fa[v] = u; dep[v] = dep[u] + 1; dfs(v); } } if ...
19
#include <bits/stdc++.h> using namespace std; void Get_Val(int &Ret) { Ret = 0; char ch; while (ch = getchar(), ch > '9' || ch < '0') ; do { (Ret *= 10) += ch - '0'; } while (ch = getchar(), ch >= '0' && ch <= '9'); } const int Max_N(50050); int N, Q, A[Max_N]; int Head[Max_N], Total, To[Max_N << 1], ...
24
#include <bits/stdc++.h> using namespace std; const int MAXN = 210; struct node { int v, next, use; } edge[MAXN << 2]; bool bridge[MAXN]; int low[MAXN], dfn[MAXN], vis[MAXN]; int head[MAXN], pre[MAXN], ip, sol, Count, u[MAXN], v[MAXN], n, m, p[MAXN], i, viss[MAXN], s, ans = -1, j, t[MAXN]; void init(void) { mem...
20
#include <bits/stdc++.h> using namespace std; int d, s; queue<pair<int, int> > q; pair<pair<int, int>, bool> sol[505][5005]; void solve(int cf, int sum) { if (sum == s) return; solve(sol[cf][sum].first.first, sum + sol[cf][sum].first.second); cout << sol[cf][sum].first.second; } int main() { cin >> d >> s; fo...
14
#include <bits/stdc++.h> using namespace std; int sgn(int x) { return x > 0 ? 1 : (x < 0 ? -1 : 0); } double pi = 3.14159265358979323846; int64_t mod = 1000000007; vector<int> prime(100001, -1); void solve() { int64_t n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int x = 0, y = 0; ...
6
#include <bits/stdc++.h> long long gcd(long long a, long long b) { while (a % b != 0) { long long temp = b; b = a % b; a = temp; } return b; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } long long solve(const std::vector<long long> &nums) { std::vector<long long> gcds(nums....
8
#include <bits/stdc++.h> using namespace std; int id[300]; int main() { int n; cin >> n; vector<int> f(26); for (int i = 0; i < n; i++) { string s; cin >> s; f[s[0] - 'a']++; } int ans = 0; for (int t : f) { int m = t / 2; ans += m * (m - 1) / 2; m = t - m; ans += m * (m - 1) /...
1
#include<iostream> #include<string> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<algorithm> #include<cstring> using namespace std; int n; vector<pair<int, int>> v; bool comp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { int t; int i; int...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; const int inf = 0x3f3f3f3f; struct node { int x, y; }; int fx[4][2] = {1, 0, 0, -1, -1, 0, 0, 1}; char fxans[4] = {'U', 'R', 'D', 'L'}; int n; node G[maxn][maxn]; char ans[maxn][maxn]; bool vis[maxn][maxn]; void dfs(int x, int y, int px, int py) ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<pair<int, int> > v; for (int i = 0; i < n; i++) { int l, r; scanf("%d %d", &l, &r); v.push_back({l, 1}); v.push_back({r + 1, -1}); } sort(v.begin(), v.end()); int cnt = 0; for (int i = 0; i < v.size...
7
#include <bits/stdc++.h> using namespace std; const unsigned long long p = 179; vector<unsigned long long> powers; vector<vector<pair<int, string> > > G; unsigned long long patt = 0; int sz, counter = 0; void form(string s) { sz = int(s.size()); powers.resize(500000); powers[0] = 1; for (int i = 1; i < 500000; ...
12
#include <bits/stdc++.h> using namespace std; char a[1100000], b[1100000]; int cnt[10][10]; int main() { int la, lb, i, j, k; long long ans = 0; scanf("%s%s", &a, &b); la = strlen(a); lb = strlen(b); for (i = 0; i < la; i++) { if (a[i] == 'R') a[i] = 0; if (a[i] == 'G') a[i] = 1; if (a[i] == 'B'...
17
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 12, lg = 18; int n; int a[N]; pair<int, int> mxmn[N][lg + 2]; void getSPT() { for (int i = 0; i < n; i++) mxmn[i][0] = {a[i], a[i]}; for (int k = 1; k < lg; k++) { for (int j = 0; j < n; j++) { mxmn[j][k].first = max(mxmn[min(n - 1, j + (1 ...
18
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long b[1000012], t, n, m, k, ccnt, pos = 0, sum = 0, minn2 = INT_MAX, sum2, cnt = 0, cnt1 = 0, cnt2 = 0, x, y, cnt3 = 0, cnt4 = 0, cnt5 = 0, cnt6 = 0, cnt7 = 0, a[1000005], a2[1000005], ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 101000; const int INF = 99999999; int n, m; int x[maxn], y[maxn], a[maxn][2], dis[maxn], now, ans; int abs(int a) { if (a < 0) return -a; return a; } int main() { for (int i = 0; i < maxn; i++) dis[i] = -1; int tmp; cin >> n >> m >> tmp >> tmp; ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int flag = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (flag == 0) { cout << 'W'; flag = 1; } else { cout << 'B'; flag = 0; } } if (n % 2 == 0) { ...
3
#include <bits/stdc++.h> using namespace std; int n, k; int a[500]; int ans = 0; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (i == n - 1) { break; } if (a[i] + a[i + 1] < k) { if (a[i] < a[i + 1]) { while (a[i] + a...
2
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; bool cmp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) { if (a.first != b.first) return a.first < b.first; if (a.second.first != b.second.first) return a.second.first < b.second.first; return a.second.second < b.second.second; ...
9
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, k; char x; int main() { cin >> n >> m; long long a[n + 1][m + 1]; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cin >> x; if (x == '.') a[i][j] = 1; if (x == 'S') a[i][j] = 0; } } for (i = 1; i <= n; i++) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; int f, s; cin >> n; string arr[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 11; string s; int x[N], y[N], z[N]; int main() { cin >> s; int n = s.length(); for (int i = 1; i <= n; i++) { if (s[i - 1] == 'x') x[i]++; else if (s[i - 1] == 'y') y[i]++; else z[i]++; x[i] += x[i - 1]; ...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 3e18 + 5; vector<int> tab[6][6]; using cd = complex<double>; const double PI = acos(-1); void fft(vector<cd>& a, bool invert) { int n = a.size(); for (int i = 1, j = 0; i < n; i++) { int bit = n >> 1; for (; j & bit...
14
#include<iostream> #include<cstdio> #include<cstring> using namespace std; #define ll long long int main(){ int t; scanf("%d",&t); while(t--){ ll n; scanf("%lld",&n); ll i=0; while(i*(i+1)/2<n)i++; ll ans=0; ll tp=i*(i+1)/2-n; if(tp==0){ ans=i; } else if(tp==1){ ans=i+1; } else { ans=...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 4e3 + 10; int n, m, k; int a[maxn]; inline void solve() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); k = min(m - 1, k); int ans = 0; for (int i = 0; i <= k; i++) { int tmp = 1e9; for (int j = 0; j <= m - k...
8
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 2e5 + 10; int a[MAXN], b[MAXN]; int main() { int n, m, k; cin >> n >> m >> k; vector<pair<int, int>> v; for (int i = 1; i <= n; i++) scanf("%d", &a[i]), v.push_back({a[i], i}); sort(v.begin(), v.end(), greater<pair<int,...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long f[100005], ans, n, m; signed main() { cin >> n >> m; f[1] = f[2] = 1; for (long long i = 3; i <= max(n + 1, m + 1); i++) f[i] = (f[i - 1] + f[i - 2]) % mod; ans = 2 * ((f[n + 1] + f[m + 1] - 1) % mod) % mod; cout << ans...
9
#include <bits/stdc++.h> using namespace std; const char nl = '\n'; const long long int MAX = INT_MAX; const long long int MIN = INT_MIN; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } void solve() { long long int n, m, i, j, k, c; cin >> n >> m; long long int...
2
#include <bits/stdc++.h> using namespace std; int i, j, n; bool k, l; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { cin >> i >> j >> n; while (n != 0) { n = n - gcd(i, n); if (n == 0) { k = true; break; } n = n - gcd(j, n); if (n ...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string a; cin >> a; int b[123] = {0}; int l = a.size(); int c = 0; for (int i = 0; i < l; i++) { if (a[i] >= 'A' && a[i] <= 'Z') { if (b[a[i] + 'a' - 'A'] == 0) c++; else b[a[i] + 'a' - 'A']--; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int counter = 0, res = 0; for (int i = 0; i < n; i++) { int x; cin >> x; if (x == -1) { if (counter > 0) counter--; else res++; } else counter += x; } cout << res << '\n'; return 0...
0
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; map<int, pair<int, int> > amo; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (amo.count(a)) { amo[a].first++; amo[a].second++; } else { amo[a] = make_pair(1, 1); ...
7
#include <bits/stdc++.h> using namespace std; using Int = long long; constexpr static int mod = 1e9 + 7; constexpr static int inf = (1 << 30) - 1; constexpr static Int infll = (1LL << 61) - 1; int Competitive_Programming = (ios_base::sync_with_stdio(false), cin.tie(nullptr), cout << fixed << setprecision(15), ...
8
#include <bits/stdc++.h> using namespace std; void read(int &x) { x = 0; char ch = getchar(); bool f = 0; while (ch > '9' || ch < '0') { if (ch == '-') f = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - 48; ch = getchar(); } if (f) x = -x; } void rea...
11
#include <bits/stdc++.h> using namespace std; template <typename C> auto test(C* x) -> decltype(cerr << *x, 0LL); template <typename C> char test(...); template <typename C> struct itr { C begin, end; }; template <typename C> itr<C> get_range(C b, C e) { return itr<C>{b, e}; } struct debug { template <typename T>...
13
#include <bits/stdc++.h> using namespace std; int findX(int A, int B) { int j = 0, x = 0; while (A || B) { if ((A & 1) && (B & 1)) { x += (1 << j); } A >>= 1; B >>= 1; j += 1; } return x; } int main() { int T; cin >> T; while (T--) { int A, B; cin >> A >> B; int X = f...
0
#include <bits/stdc++.h> using namespace std; string numtostr(long long n) { ostringstream str1; str1 << n; return str1.str(); } long long strtonum(string s) { long long x; stringstream str1(s); str1 >> x; return x; } int n, i; long double m, s; bool c = true; int main(void) { ios_base::sync_with_stdio(...
7
#include <bits/stdc++.h> using namespace std; unsigned long long hh = 1000037; int mod = 1000000009; unsigned long long pot[200001], pot2[200001]; unsigned long long t1[200001][2]; unsigned long long t2[200001][2]; unsigned long long h1[200001], h2[200001]; unsigned long long h3[200001], h4[200001]; int main() { int ...
13
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int n = (a + b) / 3; if (min(a, b) >= n) { cout << n; } else { cout << min(a, b); } return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (a[n - 3] + a[n - 2] <= a[n - 1]) { cout << "NO"; ret...
3
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define precise cout<<fixed<<setprecision(10); #define forr(i,m,n) for(ll i=m;i<n;i++) #define testcase int t;cin>>t;while(t--) #define all(v) v.begin(),v.end() #define rev(v) v.r...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int las = -1; for (int i = 1; i <= n; i++) { int now = -1; for (int j = 1; j <= m; j++) { char c = getchar(); while (!(c >= '0' && c <= '9')) c = getchar(); if (now != -1 && now != c - '0') { co...
0
#include <bits/stdc++.h> using namespace std; void optimise() { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long int mod = 1e6 + 3; void normalize(long long int &a) { a = (a + mod) % mod; } long long int modmul(long long int a, long long int b) { a = a % mod; b = b % mod; normalize(a); normalize...
12
#include <bits/stdc++.h> using namespace std; long long n, m, b, a[2000005], ans = 1152921504606846976ll; pair<long long, pair<long long, long long> > p[105]; int main() { scanf("%I64d%I64d%I64d", &n, &m, &b); for (int i = 1; i <= n; i++) { int o; scanf("%I64d%I64d%d", &p[i].second.first, &p[i].first, &o); ...
11
#include <bits/stdc++.h> using namespace std; vector<char> chars = {'A', 'C', 'G', 'T'}; vector<string> inp; int n, m; pair<int, vector<string>> solve(vector<string> s) { pair<int, vector<string>> ans; ans.first = (1 << 30); for (char aa : chars) { for (char bb : chars) { char a = aa, b = bb; if (...
13
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; char a[N], b[N], c[N]; int aaa[200], bbb[200], ccc[200]; int maxaa, maxbb, maxcc; int n; int main() { scanf("%d", &n); scanf("%s %s %s", &a, &b, &c); int len = strlen(a); for (int i = 0; i < len; i++) { aaa[a[i]]++; maxaa = max(max...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10, INF = 1e9 - 10; int dis[maxn], a[maxn], b[maxn]; bool mark[maxn]; vector<int> edges[maxn]; void dfs(int u) { mark[u] = 1; for (int i : edges[u]) { if (!mark[i]) { dis[i] = dis[u] + 1; dfs(i); } } } int main() { int t; ...
11
#include <bits/stdc++.h> char s[111]; int n, i; long long r, f[111][2]; void solve(int st) { for (i = st; i <= n + 1; i++) { f[i][s[i] - 'A'] += f[i - 1][1]; if (s[i] == 'A' || s[i - 1] == 'B') f[i][s[i] - 'A'] += f[i - 1][0]; if (i <= n && s[i] == 'B' && s[i + 1] == 'A') f[i + 1][1] += f[i - 1][0] ...
13
#include <bits/stdc++.h> using namespace std; vector<int> R; int DFS(vector<int> a, int dep) { if (a.size() <= 2) return a.size(); int i, x, y, ans; vector<int> b, c; for (i = 0; i < a.size(); i++) { if ((1 << dep) & a[i]) b.push_back(a[i]); else c.push_back(a[i]); } x = DFS(b, dep - 1),...
13
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = 0; c = getchar(); } while (c >= '0' && c <= '9') s = (s << 1) + (s << 3) + (c ^ 48), c = getchar(); return f ? s : -s; } const int M = 2e5 + 10; ...
14
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e8; const long long int inf = 1e9 + 5; const long long int inf64 = 1e18 + 5; long long int times(string A, string B) { long long int n = A.length(); long long int with = 0; for (long long int i = 0; i < n - 6; i++) { long long int t = i;...
7