solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const long long N = 3e4; void solve() { long long x, y, z; cin >> x >> y >> z; long long ans = INT_MAX; long long aa = x, bb = y, cc = z; for (long long a = 1; a <= N; ++a) { for (long long b = a; b <= N; b += a) { for (long long c = b; c <= N; c += b) {...
12
#include <bits/stdc++.h> using namespace std; const double pi = (2 * acos(0)); struct point { long double x, y; }; double area(int x1, int y1, int x2, int y2, int x3, int y3) { double a = (x2 * y3) - (x3 * y2) - (x1 * y3) + (x3 * y1) + (x1 * y2) - (x2 * y1); a /= 2; return fabs(a); } long double anyarea(p...
6
#include <bits/stdc++.h> using namespace std; int n, k, a, b; string s; bool check(int &x, int &y, int a, int b) { if (abs(x - y) <= 1) return true; int prea = -1, preb = -1; if (x < y) { while (a > 1) { int cur = a; if (a % 2) a = max(prea, a / 2 + 1); else a = max(prea, a /...
7
#include <bits/stdc++.h> void solve() { int n, a; long long s = 0, x = 0; std::cin >> n; for (int i = 0; i < n; i++) { std::cin >> a; s += a; x ^= a; } std::cout << 2 << std::endl << x << ' ' << s + x << std::endl; } int main() { int t; std::cin >> t; while (t--) solve(); return 0; }
6
#include <bits/stdc++.h> using namespace std; int n; int a[5555]; int dp[5005][5005], res[5005][5005]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { if (!k) dp[i][i] = res[i][i] = a[i]; else if (i +...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; long long n, m; int mi, mx, head[maxn], cnt = 0; int via[maxn]; int d[maxn]; struct node { int v, next; } t[maxn]; queue<int> q; bool check[maxn]; void spfa(int t1, int mode) { q.push(t1); d[t1] = 0; check[t1] = 1; while (!q.empty()) { ...
9
#include <bits/stdc++.h> using namespace std; long long N, Q; long long p[200005]; long long h[200005]; vector<long long> ady[200005]; long long niv[200005]; long long papa[200005][17 + 2]; long long lca(long long a, long long b) { if (niv[a] < niv[b]) swap(a, b); for (long long i = 17; i >= 0; i--) if (niv[pap...
14
#include <bits/stdc++.h> template <class t> inline void read(t &s) { s = 0; register long long f = 1; register char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); ; s *= f; } template <class t, cla...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 1600005; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }...
19
#include <bits/stdc++.h> using namespace std; map<string, int> mp; map<int, string> mp2; set<string> s; set<string>::iterator it; vector<string> arr, arrc; vector<pair<int, int> > sorted; int main() { int n; cin >> n; int cnt = 0; vector<string> v[50]; int mx = -1; for (int i = 0; i < n; i++) { string s...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> fib; cin >> n; if (n == 3) { cout << "1 1 1"; return 0; } else if (n == 0) { cout << "0 0 0"; return 0; } else if (n == 1) { cout << "1 0 0"; return 0; } else if (n == 2) { cout << "1 1 0"; return...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; void solve() { long long t, k; cin >> t >> k; long long dp[(long long)1e5 + 7]; dp[0] = 1; for (long long i = 1; i < k; i++) dp[i] = 1; for (long long i = k; i < (long long)1e5 + 7; i++) { dp[i] = (dp[i - 1] + dp[i - k]) % mod;...
9
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int maxn = 5000; int dp[maxn + 5][maxn / 2 + 5][2]; int h[maxn + 5]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); int m = (n + 1) / 2; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++)...
11
#include <bits/stdc++.h> using namespace std; template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } inline int read() { char ch = getchar(); int x = 0, q = 0; while (ch < '0' || ch > '9') q = ch == '-' ? 1 : q, ch = getcha...
20
#include <bits/stdc++.h> const long long N = 1e6 + 5; using namespace std; void out(long long l1, long long r1, long long l2, long long r2, bool check) { if (check) swap(l1, l2), swap(r1, r2); cout << r1 - l1 + 1 << endl; for (long long i = l1; i <= r1; i++) cout << i << " "; cout << endl; cout << r2 - l2 + 1...
22
#include <bits/stdc++.h> using namespace std; map<string, int> mp; bitset<1003> bs[5005][2]; int res[1003][2]; int main() { int n, m; cin >> n >> m; mp["?"] = 0; bs[0][1].set(); string x, tmp, y, op, z; getchar(); for (int i = 0; i < n; ++i) { cin >> x >> tmp >> y; mp[x] = i + 1; if (y[0] == '...
10
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } int n; int ans; int main() { long long a, b; cin >> a >> b; vector<i...
12
#include <bits/stdc++.h> int main() { unsigned int a, b, c; scanf("%u%u%u", &a, &b, &c); if (((a % 3 + b % 3 + c % 3 == 4 && (a == 0 || b == 0 || c == 0)) || a % 3 + b % 3 + c % 3 == 3) && (a % 3) * (b % 3) * (c % 3) == 0) { printf("%u\n", (a + b + c) / 3 - 1); } else printf("%u\n", (a + b ...
8
#include <bits/stdc++.h> using namespace std; const long long MAX = 100005; const long long mod = 1.0e9 + 7; long long ceil(long long a, long long b) { if (a % b == 0) { return a / b; } else { return a / b + 1; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); l...
9
#include <bits/stdc++.h> using namespace std; using std::string; string s; map<int, int> m[1001]; int mark[1001]; int main() { int n; cin >> n; for (int(i) = 0; (i) < (n); ++(i)) { cin >> s; for (int(j) = 0; (j) < (s.size()); ++(j)) { m[i][s[j] - 'a'] = 1; } } int cnt = 0; for (int(i) = 0;...
1
#include <bits/stdc++.h> using namespace std; vector<long long int> adj[100001]; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } long long int power(long long int x, long long int y, long long int p) { long long int ans = 1; x = x % p; while (y > 0) { if (y & 1) ans = (ans * x) % p; ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; t = 1; while (t--) { long long n; cin >> n; long long d = 0; string s = ""; for (long long i = 0; i < n; i++) { long long a, b; cin >> ...
7
#include <bits/stdc++.h> using namespace std; long long MAX = 1000000000000000000LL; long long ret = MAX + 1; int primes[60]; bool isPrime[10000 + 1]; int n; void sieve() { memset(isPrime, 1, 10000); isPrime[0] = isPrime[1] = false; for (int i = 2; i * i <= 10000; i++) if (isPrime[i]) for (int j = i * i...
12
#include <bits/stdc++.h> using namespace std; template <class T> using vc = vector<T>; template <class T> using vvc = vc<vc<T>>; template <class T> void mkuni(vector<T> &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } long long rand_int(long long l, long long r) { static mt19937_64 ...
22
#include <bits/stdc++.h> const int maxn = 2000000; int k, b, n, t; int result; int a[maxn + 1], bb[maxn + 1], atop, bbtop; bool xiaodeng() { int i; if (bbtop < atop) return false; if (bbtop > atop) return true; for (i = atop; i >= 1; --i) { if (a[i] > bb[i]) return false; if (bb[i] > a[i]) return true; ...
9
#include <bits/stdc++.h> using namespace std; vector<int> a1, a2; vector<int> p1, p2; vector<int> b, us; int n; int sum(int m, int k, int &p) { if (k >= n) { p = n; return b[m]; } int t[3]; t[1] = max(b[m], b[k]) + a1[k + 1]; t[2] = max(b[m], b[k + 1]) + a2[k]; t[0] = sum(m, k + 2, p) + max(b[k], b[...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const int maxm = 55; const int inf = 2147483647; const int p = 1000000007; const double eps = 1e-9; const long long INF = 9223372036854775807ll; int win(long long s, long long e) { if (e % 2ll == 1) { if (s % 2ll == 1) return 0; else...
19
#include <bits/stdc++.h> char str1[100005], str2[100005]; int main() { int i, len, ftos, stof; scanf("%s %s", str1, str2); len = strlen(str1); stof = ftos = 0; for (i = 0; i < len; i++) { if (str1[i] != str2[i]) { if (str1[i] == '4') ftos++; else stof++; } } if (stof > ...
4
#include <bits/stdc++.h> using namespace std; map<int, int> X; map<int, int> Y; map<pair<int, int>, int> M; int main() { long long ans = 0; int n; cin >> n; for (int x, y; n--;) { cin >> x >> y; ans += X[x]++; ans += Y[y]++; ans -= M[{x, y}]++; } cout << ans; }
6
#include <bits/stdc++.h> using namespace std; struct edge { long long u, v, w; }; const long long MX = 2e5 + 9; unordered_map<long long, long long> mp; vector<pair<long long, long long> > adj[MX], adj1[MX]; pair<long long, long long> par[MX]; long long dis[MX], mrk[MX], done[MX]; edge edg[MX]; void dij() { set<pair...
15
#include <bits/stdc++.h> using namespace std; string FILE_NAME = "testcase.455A"; string NAME; string itos(int n) { stringstream ss; ss << n; return ss.str(); } const int MAX_N = (int)1e5 + 5; int a[MAX_N]; int cnt[MAX_N]; long long dp[MAX_N]; int main() { memset(cnt, 0, sizeof(cnt)); memset(dp, 0LL, sizeof(d...
7
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { int t; cin >> t; while (t--) { v.clear(); int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == '1') { v.push_back(i + 1); v.push_back(n - i); } } sort(v.b...
2
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; void Debug(char *s) { if (!1) return; cout << s << endl; } void Debug(int val) { if (!1) return; cout << val << endl; } void Debug(double val) { if (!1) return; cout << val << endl; } void Debug(string s) { if (!1) return; cout << s <...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 50000; const int MAXV = 6 * MAXN; const int MAXE = 20 * MAXN; struct Graph { struct edge { int to; edge *nxt; } edges[MAXE + 5], *adj[MAXV + 5], *ecnt; Graph() { ecnt = edges; } void addedge(int u, int v) { edge *p = (++ecnt); p->to ...
23
/* This Qstn is a dp qstn like u can figure it out but it has O(n^2) time In order to pass u need to do it in O(nlogn) So let me write the thought process for the O(n^2) naive dp nd then how to go for O(nlogn) So if u are trying to build the answer for 0 to n-1 then it's obvious that the first one will face right nd...
22
#include <bits/stdc++.h> using namespace std; int main() { int n, c; cin >> n >> c; long long ps[n]; for (int i = 0; i < n; ++i) cin >> ps[i]; long long ts[n]; for (int i = 0; i < n; ++i) cin >> ts[i]; long long cnta = 0; long long ta = 0; for (int i = 0; i < n; ++i) { ta += ts[i]; cnta += max...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; const int MAX = 2e5 + 10; int a[MAX]; int r[MAX]; ll BO = 4e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = ...
13
#include <bits/stdc++.h> using namespace std; int main() { char a[8][8]; int A = 1e6, B = 1e6; for (int i = 0; i < 8; i++) cin >> a[i]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (a[j][i] == 'W') A = min(A, j); else if (a[j][i] == 'B') break; } } for (...
4
#include <bits/stdc++.h> using namespace std; const int N = int(1e6) + 5; const int inf = (int)1e9 + 7; struct fenwick { long long t[N]; void clr() { fill(t, t + N, 0); } void inc(int v, long long x) { for (; v < N; v += v & -v) { t[v] += x; } } long long get(int v) { long long ans = 0; ...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, i, x, y, m, z, g = 1, r, j; cin >> n; pair<long long, long long> a[n + 1]; set<long long> st; long long end[n + 1]; for (i = 1; i <= n; i++) { cin >> a[i].first;...
12
#include <bits/stdc++.h> const int Max = 2e5 + 100; using namespace std; char str[Max]; int vis[Max]; int main() { int n; cin >> n >> str; for (int a = 0; a < n - 1; a++) { int tmp = (str[a] - 'A') * 26 + str[a + 1] - 'A'; vis[tmp]++; } int maxs = 0, id = 0; for (int a = 0; a < Max; a++) { if (v...
1
#include <bits/stdc++.h> int main() { int n, a, b, arr1[1001], arr2[10001], i, j, t = 0, k = 0; scanf("%d%d%d", &n, &a, &b); for (i = 0; i < a; i++) { scanf("%d", &arr1[i]); } for (i = 0; i < b; i++) { scanf("%d", &arr2[i]); } for (i = 0; i < a; i++) { for (j = 0; j < a; j++) { if (arr1[...
0
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c; cin >> a >> b >> c; map<string, int> all; int win[4]; all["rock"] = 1; all["paper"] = 2; all["scissors"] = 3; win[1] = 3; win[2] = 1; win[3] = 2; if (win[all[a]] == all[b] && win[all[a]] == all[c]) cout << "F" << endl; ...
1
#include <bits/stdc++.h> int main() { int ar[200], n, i, j, d; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &ar[i]); } if (n == 1) { if (ar[0] == 15) printf("DOWN\n"); else if (ar[0] == 0) printf("UP\n"); else printf("-1\n"); } else if (ar[n - 1] > ar[n - 2]) { ...
3
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } int v[1001]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, m; cin >> n >> m; int c ...
5
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = acos(-1); template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x; } const int MAXN = 30; ...
7
#include <bits/stdc++.h> using namespace std; int g[100001]; int usd[1010]; int main() { int n; scanf("%d", &n); int win_move = -1; for (int i = 2; i <= n; i++) { int k = 2; int m = i; set<int> grundy; memset(usd, 0, sizeof usd); while (1) { int minus = ((k - 1) * (k)) / 2; if (m...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 4005, MAXM = 20 * 1000 + 5; struct Stack { int dp[MAXN][MAXN], cc[MAXN], hh[MAXN], n; void push(int c, int h) { for (int i = 0; i < MAXN; i++) { dp[n][i] = (n ? dp[n - 1][i] : 0); if (i >= c && dp[n][i] < (n ? dp[n - 1][i - c] : 0) + h) ...
19
#include <bits/stdc++.h> using namespace std; const long long siz = 2e5 + 10; const long long SIZ = 1e6 + 10; const long long mod = 1e9 + 7; const long long maxx = 2e9; const long long MAXX = 1e18; const string file = "3"; long long x[siz]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long...
10
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; } return i; } templat...
20
#include <bits/stdc++.h> using namespace std; const int Maxn = 200005; int n, m, Q, sign, tot; int h[Maxn], dep[Maxn], p[Maxn][20], L[Maxn], R[Maxn], upper[Maxn][20]; int fa[Maxn], ans[Maxn], cnt[Maxn], tr[Maxn]; void add(int x, int val) { for (int i = x; i <= n; i += i & -i) tr[i] += val; } int ask(int x) { int re...
20
#include <bits/stdc++.h> const long long Infll = 0x3f3f3f3f3f3f3f3f; const int MN = 100005; int N, Q, fl[MN], deg[MN]; long long wgh[MN], inc[MN]; std::multiset<long long> st0[MN], stmn, stmx; inline long long MinVal(int i) { return st0[i].empty() ? Infll : wgh[i] / deg[i] + *st0[i].begin(); } inline long long MaxVal...
21
#include <bits/stdc++.h> using namespace std; int main() { int n, num[105]; cin >> n; for (int i = 0; i < n; i++) scanf("%d", &num[i]); int ma, lim = *(min(&num[0], num + n)); for (int i = 1; i <= lim; i++) { int can = 1; for (int k = 0; k < n; k++) if (num[k] % i != 0) can = 0; if (can == 1...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(15); long long n; cin >> n; vector<int> a; vector<int> b; long long sa(0), sb(0); int last(0); for (int i = 0; i < n; ++i) { int v; cin >> v; if (v > 0) { a.push_back(...
6
#include <bits/stdc++.h> using namespace std; const int N = 300000 + 10; struct Edge { int v; long long w0, w1; }; int n, sz[N], conquered[N], mx[N]; long long bridge[N]; vector<int> comp[N], compPath[N]; vector<Edge> g[N]; void dfs_miao(int id, int u, int p) { comp[id].push_back(u); sz[u] = 1; mx[u] = 0; f...
19
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; const long long N = 1e3 + 10; const long long IM = 1e15 + 37; const long long PI = 3.14159265; void PV(vector<long long> v) { for (long long i = 0; i < v.size(); i++) cout << v[i] << " "; cout << "\n"; } void PA(long long v[], long long n, long lo...
6
#include <bits/stdc++.h> using namespace std; const long double E = 2.71828182845904523536; const long double pi = acos(-1); const double eps = 1e-9; const long long mod = 1e9 + 7; const long long inf = 1LL << 30; const int N = 111; vector<pair<int, pair<int, int>>> ans; int n = 4, m, k; int a[11][N]; bool _1 = 1; bool...
13
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unrolled-loops") using namespace std; const long long m = 1e9 + 7; int test = 1; void nathan_on_osu() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int n, k; string s; vector<string> v; int co...
12
#include <bits/stdc++.h> using namespace std; vector<vector<int>> vb(200050); int main(int argc, const char* argv[]) { int n, k, tem; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &tem); int cnt = 0; vb[tem].push_back(0); while (tem > 0) { cnt++; tem /= 2; vb[t...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int ans[N]; void solve(int n) { if (n == 0) return; for (int j = 20; j >= 0; j--) { if ((1 << j) > n) continue; int cen = (1 << j); int ada = n - cen + 1; for (int i = 0; i < ada; i++) { swap(ans[cen + i], ans[cen - i - 1]); ...
17
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const long long mod = (long long)1e9 + 7; const double eps = (double)1e-9; const double pi = acos(-1.0); const int dx[] = {0, 0, 1, 0, -1}; const int dy[] = {0, 1, 0, -1, 0}; const int N = (int)2e6 + 123; int n, m, na, ans[N], d[N], len[N], X[N], Y...
18
#include <bits/stdc++.h> using namespace std; const int M = 105; int cntt[M]; int32_t main() { ios_base::sync_with_stdio(false); ; int n, q; cin >> n >> q; vector<int> ans; for (int i = 1; i <= q; i++) { int mom, k, t; cin >> mom >> k >> t; vector<int> serve; for (int j = 1; j <= n; j++) ...
5
#include <bits/stdc++.h> using namespace std; int n, m, vis[100100]; bool x[100100]; vector<int> ans, g[100100]; void dfs(int v) { vis[v]++, ans.push_back(v); for (int i = 0; i < g[v].size(); i++) if (!vis[g[v][i]]) { dfs(g[v][i]); if ((vis[g[v][i]] ^ x[g[v][i]]) & 1) vis[v]++, ans.push_back...
14
#include <bits/stdc++.h> using namespace std; inline int add(int x, int y) { x += y; return x >= 1000000007 ? x - 1000000007 : x; } inline void Inc(int &x, int y) { ((x += y) < 1000000007) || (x -= 1000000007); } inline void Dec(int &x, int y) { ((x -= y) < 0) && (x += 1000000007); } inline int Pow(int n, int x) { ...
25
#include <bits/stdc++.h> using namespace std; int a[101010]; int ccr[202020]; int v[101010]; const int N = 1 << 18; int st[2 * N]; int lol[N]; int getmax(int aa, int bb) { aa += N; bb += N; int m = 0; while (aa <= bb) { if (aa % 2) m = max(m, st[aa++]); if (!(bb % 2)) m = max(m, st[bb--]); aa /= 2; ...
22
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; inline void read(int &x) { x = 0; int f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } x *= ...
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long n, k, x; cin >> n >> k >> x; vector<long long> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } vector<vector<long long>> dp(n, vector<long long>(x, -1)); for (int i = 0; i < k; i++) { dp[i][0...
11
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double EPS = 1e-8; int main(void) { int x, y, z; cin >> x >> y >> z; int a = x + z; int b = y + z; bool up = b < x, down = a < y; if (up && !down && a != y) { printf("+\n"); } else if (!up && down && b != x) { cout << ...
0
#include <bits/stdc++.h> using namespace std; void fastInOut() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); } int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, -1, 1}; int main() { fastInOut(); int n, a, b; cin >> n; long long fin = 0; map<int, int> x, y; map<pair...
6
#include <bits/stdc++.h> using namespace std; bool compare(const pair<int, int> &i, const pair<int, int> &j) { if (i.second > j.second) return true; else return false; } const long long mod = 1e9 + 7; double fact(long long n) { if (n == 1 or n == 0) return 1; else return n * fact(n - 1); } int m...
5
#include <bits/stdc++.h> void out(int n, int k) { printf("%d", n); while (k--) printf("0"); puts(""); } int a[200]; char s[110000]; int main() { scanf("%s", s); int numw = 0, i, j, cnt = 0; for (i = 0; s[i]; i++) { if (s[i] == '?') numw++; else if (s[i] >= 'A' && s[i] <= 'Z') a[s[i]]++; ...
3
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) cin >> v[i]; int alice = 1, bob = n - 1, turn = 1; int alice_sum = v[0], bob_sum = 0; int last_bob = 0, last_alice = v[0]; int turn_count = 1; vector<bool> ate(n, false); ate[0...
5
#include <bits/stdc++.h> using namespace std; const int MAX_N = 25; const int MAX_A = 50000; int n, a[2][MAX_N]; int f[MAX_N * 2][MAX_N * MAX_A]; vector<int> p, row0, row1; void readInput() { cin >> n; p.resize(2 * n); for (int i = 0; i < 2; ++i) { for (int j = 0; j < n; ++j) { cin >> p[i * n + j]; ...
23
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INTMAX = numeric_limits<int>::max(); const long long LLMAX = numeric_limits<long long>::max(); void writeln() { cout << "\n"; } template <class T> inline void print(T&& a); template <class T> inline void priws(T&& a); template <class T>...
5
#include <bits/stdc++.h> using namespace std; struct s { long long id, v; } a[300005]; bool cmp(s aa, s bb) { return aa.v > bb.v; } int main() { long long n, x1, x2; scanf("%I64d %I64d %I64d", &n, &x1, &x2); for (long long i = 1; i <= n; ++i) { a[i].id = i; scanf("%I64d", &a[i].v); } sort(a + 1, a +...
9
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, m, C, ans, T; int a[N][N], b[N][N]; int dfn[N], low[N], vis[N]; int S[N], G[N], f[N], be[N]; void tarjan(int x, int fa) { dfn[x] = low[x] = ++T; vis[x] = 1; S[++*S] = x; for (int i = 1; i <= n; i++) if (a[x][i] && i != fa) { if (...
19
#include <bits/stdc++.h> using namespace std; int maxx(int*); int arr[4]; int main() { int n, i, k, count1 = 0, max, maxi, a, g, c, t, counta, countb, countc, countd; counta = countb = countc = countd = 0; string str; cin >> n >> str; if (n % 4 != 0) { cout << "===" << '\n'; return 0; ...
1
#include <bits/stdc++.h> using namespace std; int a[222222], n, m, k; map<int, int> mp[100005]; int len[100005]; bool judge(int x) { int ans = 0x3fffffff; for (int i = 1; i <= m; i++) { for (int j = 1; j + x - 1 <= len[i]; j++) { ans = min(ans, mp[i][j + x - 1] - mp[i][j] + 1 - x); } } return ans ...
10
#include <bits/stdc++.h> const int MOD = 1e9 + 7; const int maxn = 1e6 + 10; int binPow(int a, int n) { int res = 1; while (n) { if (n & 1) res = (1LL * res * a) % MOD; a = (1LL * a * a) % MOD; n >>= 1; } return res; } using namespace std; vector<long long int> primefactors(long long int num) { ve...
8
#include <bits/stdc++.h> using std::abs; using std::cin; using std::cout; using std::max; using std::min; int n, m, i, j, a, b; bool nomod(int x, int y) { if (x % a == 0 && y % b == 0) return false; return true; } int ans = 1 << 30; int main() { cin >> n >> m >> i >> j >> a >> b; if ((i == 1 || i == n) && (j ==...
12
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; cout << "x= " << x << endl; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } cout << "res" << res << endl; retu...
6
#include <bits/stdc++.h> using namespace std; long long n; long long a[200004]; int in[1000004], out[1000004]; int main() { memset(in, 0, sizeof(in)); memset(out, 0, sizeof(out)); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int cnt = 0, d = 0, day = 1; vector<int> ans; for (int i = 0; i < n; i++) {...
6
#include <bits/stdc++.h> using namespace std; template <class A> void read(vector<A>& v); template <class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d = stod(t); } void read(long double& d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H& h, ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, INF = 0x3f3f3f3f; int a[maxn]; vector<int> u, v; vector<pair<int, int> > ans; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { scanf("%d", a + i); if (a[i] >= 2) { if (int(u.size())) a[u.back()]--, a[i]--; u.p...
10
#include <iostream> #include "cmath" #include "numeric" #include "algorithm" #include "set" #include "vector" using namespace std; int main() { int quantity; cin >> quantity; for (int i = 0; i < quantity; i++){ unsigned long long result; cin >> result; unsigned long long base ...
5
#include <bits/stdc++.h> using namespace std; long long a[2000007]; vector<long long> v; bool sortinrev(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.first > b.first); } void seive() { for (long long i = 0; i <= 2000000; i++) a[i] = 1; a[0] = a[1] = 0; for ...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; long long cnt, p[1005], a[14]; long long ct(long long x) { if (!x) return 0; return ct(x / 2) + (x & 1); } long long q[14][1005], l[14], ans[1005]; signed main() { long long n; scanf("%lld", &n); for (long long i = (1 << 5) - 1; i < 1...
20
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k; cin >> n >> k; string s; cin >> s; bool ok = true; for (long long int i = k; i < n; i++) { if (s.at(i) != s.at(i % k)) { if (s.at(i) < s.at(i % k)) { ok = true; } else { ok = false; } ...
9
#include <bits/stdc++.h> using namespace std; long long n, ctd, sbt[100069], eu[100069], z = 0, sq[100069]; vector<long long> al[100069]; bitset<100069> vtd; void bd(long long x) { long long i, sz = al[x].size(), l; vtd[x] = 1; sbt[x] = 1; for (i = 0; i < sz; i++) { l = al[x][i]; if (!vtd[l]) { bd...
13
#include <bits/stdc++.h> using namespace std; #define ll long long const double PI=acos(-1.0); ll a[100005],b[100005],c[100005]; ll dp[100005]; int main() { int t; cin>>t; while(t--) { int n; cin>>n; ll ans=0; for(int i=1;i<=n;i++) { cin>>c[i]; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, A[200009], B[200009], mapa[200009]; cin >> n; for (int i = 1; i < n + 1; ++i) cin >> A[i]; for (int i = 1; i < n + 1; ++i) cin >> B[i]; for (int i = 1; i < n + 1; ++i) mapa[A[i]] = i; int ind = 1; bool mark[200009]; memset(mark, 0, sizeof...
7
#include <bits/stdc++.h> using namespace std; int dp[200001][3]; using namespace std; set<pair<pair<int, int>, int>> s[1001][1001]; int main() { int n, m; cin >> n; int x, y; for (int i = 0; i < n; i++) { scanf("%d%d", &x, &y); s[(x - 1) / 1000][(y - 1) / 1000].insert(make_pair(make_pair(x, y), i)); }...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n; vector<int> p[maxn]; int cnt[maxn]; long long calc(long long x, long long y) { long long res = 1; int z = 998244353 - 2; while (z) { if (z % 2 == 1) (res *= y) %= 998244353; z /= 2; (y *= y) %= 998244353; } return x * ...
9
#include <bits/stdc++.h> using namespace std; const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; const int N = 1e6 + 10; const double pi = acos(-1); const int INF = 0x3f3f3f3f; int a[N], b[N]; int n, m, K; int main() { ios::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } int ans...
13
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("avx,avx2,fma") using namespace std; long long power(long long a, long long b) { long long res = 1; a = a % 1000000007; while (b > 0) { if (b &...
12
#include <bits/stdc++.h> using namespace std; int const N = 500000; vector<int> x[N + 1]; int y[N + 1]; vector<pair<int, int> > go[N + 1]; int main() { int n; scanf("%d", &n); if (n & 1) { printf("Second\n"); fflush(stdout); int m = n << 1; for (int i = 1; i < (int)(m + 1); ++i) { int t; ...
20
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, d, e, f; while (cin >> a >> b >> c >> d >> e >> f) { if (d == 0) cout << "Hermione" << endl; else if (b == 0 && c != 0) cout << "Hermione" << endl; else if (c == 0) cout << "Ron" << endl; else if (a == 0 && ...
10
#include <bits/stdc++.h> const int maxn = 1E5 + 77; const int cL = 26; int m_abs(int v) { return v > 0 ? v : -v; } int LP[cL][maxn], RP[cL][maxn]; unsigned char LV[2][cL][maxn], LVC[2][cL][maxn][cL], SV[cL][maxn]; bool sgv[cL + 3]; int calc(int l, int r) { int ret = 0; memset(sgv, 0, sizeof(sgv)); for (int c = 0;...
24
#include <bits/stdc++.h> using namespace std; const int N = 405; vector<int> e[N]; int n, k, father[N]; int dp[N][N], path[N][N][N], id[N][N]; void dfs(int u, int pre) { father[u] = pre; dp[u][1] = 0; for (int i = 0; i < e[u].size(); i++) { int v = e[u][i]; if (v == pre) continue; dfs(v, u); for (...
14
#include <bits/stdc++.h> using namespace std; struct team { int pointsBefore; int delta; int index; int postOrder; }; struct score { int points; int index; }; int n; team* teams; score before(const team& a) { score s; s.points = a.pointsBefore; s.index = a.index; return s; } score after(const team& ...
14