solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int n, m, k; long long gm[101][101][100]; int nxt[101][101][100]; long long ds[101][101][100]; struct subj { int c, n; long long a, b; }; vector<subj> s; bool operator<(const subj& x, const subj& y) { return x.c < y.c; } long long getmax(int x, long long d, int left) { ...
6
#include <bits/stdc++.h> using namespace std; const int pts[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}; int n, m, r; int sum[1000], a[1000], b[1000]; string name[1000]; int g[1000][50]; map<string, int> all; inline int get(string s) { if (all.count(s)) return all[s]; a[r] = r; b[r] = r; all[s] = r; name[r] = s...
3
#include <bits/stdc++.h> using namespace std; char change(char w); bool hop(int g, int h, char w, int u, int v, char D); queue<pair<pair<int, int>, int> > qu; int d[1010][1010][4], n, m, X1, Y1, X2, Y2; char ch[1010][1010]; int p[4] = {1, -1, 0, 0}; int q[4] = {0, 0, 1, -1}; int main() { ios::sync_with_stdio(0); ci...
6
#include <bits/stdc++.h> using namespace std; const long long MAX_LL = 1LL << 60; const int MAXN = 200020; struct tnode { long long x, p; } a[MAXN]; int q[MAXN]; bool cmp(tnode a, tnode b) { return a.x < b.x; } int main() { int m; long long d, n; scanf("%I64d%I64d%d", &d, &n, &m); for (int i = 1; i <= m; i++)...
7
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); double a, b, c, s, x, y, z, sum; cin >> s >> a >> b >> c; sum = a + b + c; if (sum == 0) { x = y = 0; z = s; } else { x = a / sum * s; y = b / sum * s; z = c / sum * s; ...
5
#include <bits/stdc++.h> using namespace std; int a[2005], b[2005], sum, k, n; bool ok(int d) { for (int i = 1; i <= n; i++) b[i] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j < i; j++) { if (abs(a[i] - a[j]) <= (long long)(i - j) * d) b[i] = max(b[i], b[j] + 1); } } sum = 0; for...
6
#include <bits/stdc++.h> using namespace std; int n, d, m; long long a[100001], c[100001]; bool cmp(const long long &x, const long long &y) { return x > y; } int main() { scanf("%d%d%d", &n, &d, &m); ++d; int l = 0, r = 0; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (x <= m) a[++...
5
#include <bits/stdc++.h> using namespace std; template <class T> inline T modinv(T a, T n) { T i = n, v = 0, d = 1; while (a > 0) { T t = i / a, x = a; a = i % x; i = x; x = d; d = v - t * x; v = x; } return (v + n) % n; } long long modpow(long long n, long long k, long long mod) { lon...
3
#include <bits/stdc++.h> using namespace std; void copyfile(int a, int b, vector<pair<int, int> > &hd, int &freeguy, vector<pair<int, int> > &result) { hd[b] = hd[a]; hd[a] = make_pair(-1, -1); result.push_back(make_pair(a, b)); freeguy = a; } int main() { int n, m; scanf("%d %d", &n, &m); v...
5
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); } long long lcm(long long x, long long y) { return ((x / gcd(x, y) * y)); } int arr[1001][1001]; int solve(int i, int j, int n, int m) { if (i == n) return j; int x = a...
3
#include <bits/stdc++.h> using namespace std; vector<long long> adj[200001]; vector<long long> adj1[64]; long long n; long long parent[200001]; long long helper() { long long ans = INT_MAX; for (long long i = 1; i <= n; i++) { vector<long long> dist(n + 2, (long long)(1e9)); vector<long long> par(n + 1, -1)...
5
#include <bits/stdc++.h> using namespace std; long long modpow(long long base, long long exp, long long modulus) { base %= modulus; long long result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result; } int main() { ...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; vector<pair<int, int> > vec[1001]; int dist[1001][1001]; int vis[1001]; int n, m, k; vector<pair<int, int> > des; struct compare { bool operator()(const pair<int, int> &a, const pair<int, int> &b) const { return (a.first > b.first); } }; void di...
6
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 998244353; int lim = 1000000; int main(){ std::ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; vector<ll> nd(n+1,0); for(int i=1;i<=n;++i){ for(int j=2*i;j<=n;j+=i){ ++nd[j]; } } vector<ll> r...
4
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { int n, m, k; scanf("%d%d%d", &n, &m, &k); int Rows[n], Col[m], X[k]; for (int i = 0; i < n; i++) Rows[i] = -1; for (int j = 0; j < m; j++) Col[j] = -1; for (int i = 0; i < k; i++) { X[i] = 0; int t, rc; scanf("%d%d%d...
2
#include <bits/stdc++.h> using namespace std; const int N = 1005; const int INF = 0x3f3f3f3f; int n; long long k; long long pri[N], pn; int cnt[N], ts[N]; long long a[N]; pair<int, long long> dp[N][1 << 13]; int path[N][1 << 13][2]; int s[N]; int ans[N], an; void print(int n, int s) { if (n == 0) return; print(n - ...
9
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; map<long long, long long> mp, st, en; long long n; int main() { cin >> n; long long x, y, xx; vector<pair<long long, long long>> vect; for (long long i = 0; i < n; i++) { int a, b; cin >> a >> b; vect.push_back({a, b}); ...
3
#include <bits/stdc++.h> using namespace std; vector<int> e[30]; int vis[30]; vector<int> ord; bool dfs(int v) { if (vis[v] == 2) return true; if (vis[v] == 1) return false; vis[v] = 1; for (int u : e[v]) { if (!dfs(u)) return false; } vis[v] = 2; ord.push_back(v); return true; } int main() { int ...
4
#include <bits/stdc++.h> using namespace std; const int N = 100005; double a[N], b[N]; char s[N]; int n, m; int main() { scanf("%d%s", &n, &s); m = n; for (int i = 0; i < n; i++) a[i] = s[i] - '0'; for (int i = 2; i <= n; i++) if (m % i == 0) { while (i >= 2 && m % i == 0) m /= i; for (int j = 0...
11
#include <bits/stdc++.h> using namespace std; //int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; //int dirs[8][2]={{-1,0},{0,-1},{0,1},{1,0},{1,1},{-1,-1},{-1,1},{1,-1}}; long long modd=1e9+7; vector<int> dsu; vector<int> height; vector<bool> has_loop; int find_leader(int u) { if(dsu[u]==u) return u; return dsu...
6
#include <bits/stdc++.h> using namespace std; const int N = 5e5, mod = 998244353; int f[N][2], pw[N], w[N], tmp1[N], tmp2[N], n, k; void make(int n) { f[0][1] = 1; for (int i = 1; i <= n; i++) { f[i][0] = 1ll * f[i - 1][1] * (k - 1) % mod; f[i][1] = (f[i - 1][0] + 1ll * (k - 2) * f[i - 1][1]) % mod; } p...
7
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point(double _x, double _y) : x(_x), y(_y) {} Point() {} } P[1000]; int x[1000], y[1000], z[1000]; int n, m; Point chg(int a, int b, int c, int d, int e, int f) { if (a == 0 && b == 0) return Point(d, e); if (b == 0 && c == 0) return Po...
8
#include <bits/stdc++.h> using namespace std; int n, m, mark[4][155], ok; char s[4][155]; void dfs(int x, int y) { if (ok) return; if (y >= n) { ok = 1; return; } if (mark[x][y] || s[x][y + 1] != '.') return; mark[x][y] = 1; if (s[x][y + 2] == '.' && s[x][y + 3] == '.') dfs(x, y + 3); if (x - 1 >=...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,inline,unroll-loops,fast-math") using namespace std; class Node { public: Node *s[2]; Node *p; Node *q; Node(void) { s[0] = s[1] = p = q = NULL; return; } bool Relation(void) { return this == p->s[1]; } }; int n; Node a[100020]; vector<pair<int, ...
11
#include <bits/stdc++.h> using namespace std; vector<long long> ans; int main() { long long p, k; cin >> p >> k; k = -k; while (p) { long long md = p % k; p /= k; if (md < 0) { md += abs(k); p++; } ans.push_back(md); } printf("%d\n", (int)ans.size()); for (int i = 0; i < an...
6
#include <bits/stdc++.h> using namespace std; double a, b, l; double eps = 1e-8; double func(double x) { return (x * a + sqrt(l * l - x * x) * b - sqrt(l * l - x * x) * x) / l; } double tsearch(double l, double r) { if (r - l < eps) return (l + r) / 2; double a = (2 * l + r) / 3; double b = (l + 2 * r) / 3; i...
8
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > A, B; vector<int> R, T; map<pair<int, int>, int> ID, P; int f(int first, int second) { return (first + second); } void build(int ver, int p, int q) { int med = (p + q) / 2, left = 2 * ver + 1, rigth = 2 * ver + 2; if (p == q) { T[ver] = 1; ...
5
#include <bits/stdc++.h> using namespace std; long long n, m, ans, mid, mn, mx, T, sum, h1, h2, e[1234567], b[1234567], c[1234567], d[1 << 20], k, i, j, l, r, h, a[1234567], w, x, y, z, res, par[1234567], cnt, sz[1234567]; bool used[1234567]; vector<long long> v[1234567], vec1; string s1, s; vector<pair<long lo...
5
#include <bits/stdc++.h> using namespace std; int n, a[100005] = {0}, ans; int main() { int i, j, k, h; scanf("%d", &n); ans = 1, h = 1; scanf("%d", &j); a[j] = 1; for (i = 2; i <= n; i++) { scanf("%d", &k); if (k == j) h++; else if (k == j + 1) h = min(i - a[k - 2], h + 1); else...
3
#include <bits/stdc++.h> using namespace std; const int N = 300005, INF = 99999999; const long long P = 1e9 + 7; template <typename T> inline void read(T& first, char s = getchar()) { for (first = 0; s > '9' || s < '0';) s = getchar(); while (s <= '9' && s >= '0') first = first * 10 + s - '0', s = getchar(); } temp...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; vector<int> edge[maxn], root; int n, ans = 0, a; void dfs(int node, int par, int depth) { depth++; ans = max(depth, ans); for (int v : edge[node]) { if (v == par) { continue; } dfs(v, node, depth); } } int main() { cin >> n...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long target = n + k + 1; long long sqrtar = sqrt(2 * target); cout << n - sqrtar + 1; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int MAXN = 1e6 + 3; const double EPS = (1e-7); int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } long long gcd(long long a, long long b) { if (b == 0) return a; else return gc...
2
#include <bits/stdc++.h> int main() { int t, j; scanf("%d", &t); for (j = 1; j <= t; j++) { int n, d = 0, i; char a[100000], b[100000], c[100000]; scanf("%s %s %s", a, b, c); n = strlen(a); for (i = 0; i < n; i++) { if (a[i] == c[i] || b[i] == c[i]) d++; if (a[i] == b[i] && b[i] !=...
0
#include <bits/stdc++.h> using namespace std; bool isPowerOfTwo(long long n) { return (ceil(log2(n)) == floor(log2(n))); } long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res *= a; a = a * a; b >>= 1; } return res; } bool sortbysec(const pair<int, int> &a, ...
0
#include <bits/stdc++.h> using namespace std; bool appeared[10000000] = {false}; void print_s1(int s1) { cout << setfill('0') << setw(9) << s1 << endl; } int main(void) { int a, b, mod; cin >> a >> b >> mod; int suffix = 1000000000; int m = suffix % mod; int curr_m = 0; bool p1_win = false; int s1 = a; ...
5
#include <bits/stdc++.h> int gao(int n, int k, int t) { int m = 2 * (n - 1); int x = t / m * m; int y = t % m; if (k >= 1 + y) { x += k - 1; } else if (k <= n - (y - (n - 1))) { x += (n - 1) + (n - k); } else { x += m + k - 1; } return x; } int main() { int n, m, a, b, c; scanf("%d%d", &...
2
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long b) { long long exp = 1000000007; a %= exp; long long res = 1; while (b > 0) { if (b & 1) res = ((res) * (a)) % exp; a = ((a) * (a)) % exp; b >>= 1; } return res; } bool isprime(long long x) { for (long long d...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); } bool sorta(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } bool sortd(co...
1
#include <bits/stdc++.h> using namespace std; int n, sum; int main() { cin >> n; while (n != 0) { if (n % 8 == 1) sum++; n /= 8; } cout << sum; return 0; }
6
#include <bits/stdc++.h> using namespace std; int sig(double x) { return (x > 1e-8) - (x < -1e-8); } struct P { double x, y; P(double a = 0, double b = 0) : x(a), y(b) {} P operator+(const P &a) const { return P(x + a.x, y + a.y); } P operator-(const P &a) const { return P(x - a.x, y - a.y); } double operator...
8
#include <bits/stdc++.h> using namespace std; struct Edge { int next, val; }; int edge[200010][2]; vector<Edge> V[200010]; int dp[200010][2]; int ans; void dfs1(int u, int pre, int r) { dp[u][0] = 0; for (int i = 0; i < V[u].size(); i++) { int son = V[u][i].next; if (son == pre || son == r) continue; ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; struct node { int d[60]; node operator+(const node& t) const { node tmp; for (int i = 0; i < 60; i++) tmp.d[i] = this->d[i] + t.d[(i + (this->d[i])) % 60]; return tmp; } } a[maxn * 4]; void up(int k, int l, int r, int p, in...
8
#include <bits/stdc++.h> using namespace std; int main() { vector<int> V(1000001, 1); for (int i = 1; i < 1000000; ++i) for (int j = 2; i * j < 1000001; ++j) ++V[i * j]; long long res = 0; int a, b, c; cin >> a >> b >> c; for (int i = 1; i <= a; ++i) for (int j = 1; j <= b; ++j) for (int k = 1...
9
#include <bits/stdc++.h> using namespace std; long long n, k; long long icount = 0; int main(void) { cin >> n >> k; if (k >= n / 2) { cout << (n - 1) * n / 2 << endl; return 0; } for (int i = 0; i < k; i++) { icount += (n - i * 2 - 1) * 2; icount--; } cout << icount << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; string second; cin >> n >> k; cin >> second; int len = second.length(); int a[len]; int present[26]; for (int i = 0; i < 26; ++i) { present[i] = 0; } for (int i = 0; i < len;...
3
#include <bits/stdc++.h> using namespace std; long long powermodm(long long x, long long n, long long M) { long long result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return result; } long long power(long long _a, long long _b) { long long _r = 1;...
4
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const int INF = ~0U >> 2; const int MAXN = 1e6 + 10; int main() { int a, b; while (~scanf("%d%d", &a, &b)) { bool flag = false; int x2, x3, y2, y3, sx; if (a > b) { int tx = a; a = b; b = tx; } double a1 = (...
4
#include<iostream> #include<vector> #include<algorithm> using namespace std; bool find(long int A, long int B, int n, vector<long int> a, vector<long int> b) { int64_t damage = 0; for(int i = 0; i < n; i++) { damage += int64_t(b[i] + A - 1) / A * a[i]; } for(int i = 0; i < n; i++) { i...
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n, m; int test = 0; n = s.length(); m = s.find("1"); if (m == -1) cout << "no"; else { for (int i = m; i < n; i++) { if (s[i] == '0') test++; } if (test >= 6) cout << "yes"; else cout...
1
#include <bits/stdc++.h> using namespace std; long long convertToNum(string s) { long long val = 0; for (int i = 0; i < (s.size()); i++) val = val * 10 + s[i] - '0'; return val; } char bu[50]; string convertToString(int a) { sprintf(bu, "%d", a); return string(bu); } long long GCD(long long x, long long y) { ...
6
#include <bits/stdc++.h> using namespace std; multiset<int> s; multiset<int>::iterator it; int a[100001], ans, b[100001]; int main() { int n, x; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &x); a[x] = i; } for (int i = 1; i <= n; i++) { scanf("%d", &b[i]); s.insert(i - a[b[i]])...
6
#include <bits/stdc++.h> using namespace std; const int MaxN = 2e5, MaxM = 4e5; int n, all; int pre[MaxM + 5], last[MaxN + 5], other[MaxM + 5]; bool vis[MaxN + 5]; int ans[MaxM + 5], num[MaxM + 5], used[MaxN + 5]; int seq[MaxM + 5]; vector<int> v[MaxN + 5]; void Build(int x, int y, int d) { pre[++all] = last[x]; la...
5
#include <bits/stdc++.h> int main() { char st[100]; int len = 0, i, j, temp = 0; scanf("%s", st); len = strlen(st); for (i = 0; i < len; i += 2) { for (j = 0; j < len - 1; j += 2) { if (st[j] > st[j + 2]) { temp = st[j]; st[j] = st[j + 2]; st[j + 2] = temp; } } } ...
0
#include <bits/stdc++.h> using namespace std; int N, A, B, X, Ans = 0, C = 0; int main() { cin >> N >> A >> B; for (int i = 1; i <= N; i++) { cin >> X; if (X == 1) { if (A > 0) A--; else if (B > 0) C++, B--; else if (C > 0) C--; else Ans++; } else ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; bool hasCW = false, hasCCW = false; for (int i = 0; i < n; i++) { if (s[i] == '<') { hasCCW = true; } if (s[i] == '>') { hasCW = ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int INF = 1e9; int main() { long long n, k, ans = 0; cin >> n >> k; bool t = 0; ans += n * 2 / k + (t = (n * 2 % k)); ans += n * 5 / k + (t = (n * 5 % k)); ans += n * 8 / k + (t = (n * 8 % k)); cout << ans; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); map<string, int> points, goals, missed, cnt; string s; while (getline(cin, s)) { stringstream ss(s); string team1, team2, ngoals; ss >> team1 >> team2 >> ngoals; int goal1 = ngoals[0] - '0'; int goal2 = ...
5
#include <bits/stdc++.h> int n, b[500005], c[500005]; std::vector<int> e[500005]; int t[500005 << 2]; inline void build(int p, int L, int R) { if (L == R) { t[p] = c[L]; return; } int mid = (L + R) >> 1; build(p << 1, L, mid); build(p << 1 | 1, mid + 1, R); t[p] = std::max(t[p << 1], t[p << 1 | 1]);...
11
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("-ffloat-store") using namespace std; clock_t time_p = clock(); void aryanc403() { time_...
8
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); int f = 1; for (int i = 1; i < n; i++) { int val = abs(arr[i] ...
0
#include <bits/stdc++.h> using namespace std; int q_pow(int x, int n) { int ret = 1; for (; n; n >>= 1, x = (long long)x * x % 998244353) if (n & 1) ret = (long long)ret * x % 998244353; return ret; } int A[100005 << 2], B[100005 << 2], tmp[100005], tx[100005], ty[100005], Q, n, m; void NTT(int *a, int le...
11
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; const int N = 100 + 17; const int S = 1000 + 17; const lon...
8
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (abs(b) < abs(a)) return gcd(b, a); if (abs(b) % abs(a) == 0) return a; else return gcd(abs(a), abs(b) % abs(a)); } int main() { int n, m; cin >> n >> m; vector<int> v1(n + 1), v2(m + 1); for (int i = 0; i <= n; i++) cin >> v...
3
#include <bits/stdc++.h> using namespace std; string q(string s) { cout << "?" << " " << s << "\n"; string t; cin >> t; return t; } int main() { string s1, s2, s3, t1, t2, t3, t; cin >> t; int n = t.size(); for (int i = int(0); i <= int(n - 1); i++) { s1 += char('a' + i % 26); s2 += char(...
7
#include <bits/stdc++.h> using namespace std; int ans[1005]; bool vis[1005]; int main() { for (int i = 0; i < 1001; i++) ans[i] = 2e9; int n; scanf("%d", &n); int len = 1; for (int i = 1; i <= 10; i++) { vector<int> vec1, vec2; for (int j = 0; j < n; j++) { if (j % (len * 2) < len) vec1....
5
#include <bits/stdc++.h> struct Answer { int a, b; }; int main() { int n, q; scanf("%d%d", &n, &q); std::deque<int> deq; for (int i = 0; i < n; i++) { int ai; scanf("%d", &ai); deq.push_back(ai); } Answer answers[n]; for (int i = 0; i < n; i++) { answers[i].a = deq[0]; answers[i].b =...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (k <= n || n <= 4) return cout << -1, 0; for (int i = 0; i < 2; i++) { cout << a << " " << c << " "; for (int j = 1; j <= n; j++) { if (j != a && j != b && j != c && j != d) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { int i, j, t; cin >> t; while (t > 0) { t--; int k = 0; long long a, b; cin >> a >> b; if (b > a) swap(a, b); if (a % b != 0) cout << "-1" << endl; else { long long p = a / b; while (p % 8 == 0) { k++; ...
1
#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; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") string ask(Int p, Int q) { cout <<...
6
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(T x) { return x * x; } template <class T> inline bool isSquare(T x) { T y = sqrt(x + 0.5); return (y * y) == x; } template <class T1, class T2> inline T1 gcd(T1 a, T2 b) { return b ? gcd(b, a % b) : a; } template <class T1, class T2> ...
7
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 15; const long long int inf = 1e18; vector<string> a(100); long long int n, m; vector<vector<long long int> > vis(100, vector<long long int>(100)); vector<long long int> dx = {0, -1, 1, 0}; vector<long long int> dy = {1, 0, 0, -1}; void dfs(long long int...
3
#include <bits/stdc++.h> using namespace std; int mark[100000 + 5], ara[100000 + 5]; int main() { int i, j, k, n, l, gcd, mx = 0; cin >> n; for (i = 1; i <= n; i++) { scanf("%d", &l); ara[l]++; } if (ara[1] > 0) mx = 1; for (i = 2; i <= 100000; i++) { if (!mark[i]) { gcd = ara[i]; fo...
3
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = ' '; while (!isdigit(ch)) { ch = getchar(); if (ch == '-') f = -1; } while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return x * f; } long long n, m, k, a[500005], c[500005], d[...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0; cin >> n; vector<string> arr[2]; for (int i = 0; i < n; i++) { string name, colour; cin >> name >> colour; arr[0].push_back(name); arr[1].push_back(colour); c++; for (int j = i - 1; j >= 0; j--) { if (arr[0][j...
0
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> construct(int st, vector<int> d) { if (d.empty()) return vector<pair<int, int>>(); vector<pair<int, int>> res; for (int i = 0; i < d[0]; i++) { for (int j = st + i + 1; j <= st + d.back(); j++) { res.push_back({st + i, j}); } } ...
8
#include <bits/stdc++.h> int main() { long long n, x, y; scanf("%I64d", &n); scanf("%I64d %I64d", &x, &y); if (((((x) > (y)) ? (x) : (y)) - 1) > (n - (((x) < (y)) ? (x) : (y)))) { printf("Black\n"); } else { printf("White\n"); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 228; const int INF = (int)1e9 + 228; int dp[75][75][75][75]; int a[75][75]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j...
6
#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 int read() { int x = 0; char ch = getchar(); bool positive = 1; for ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 210; int n; int p[MAXN], q[MAXN], d[MAXN]; bool bt[MAXN]; vector<int> pt[MAXN], et[MAXN]; bool Check(int k) { for (int i = 0; i < pt[k].size(); i++) if (!bt[pt[k][i]]) return false; return true; } int Calc(int st) { memset(bt, false, sizeof(bt)); ...
4
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 5; int A[M]; char B[M]; int main() { int n; scanf("%d", &n); for (int j = 0; j < n; j++) scanf("%d", &A[j]); scanf("%s", B); int cnt = 0; for (int j = 0; j < n; j++) if (B[j] == '1') cnt += A[j]; int ans = cnt, sum = 0, sum1 = 0; for ...
4
#include <bits/stdc++.h> using namespace std; int q; map<long long, map<long long, long long>> mp; int main() { cin >> q; while (q--) { int ch; cin >> ch; if (ch == 1) { long long u, v, w; cin >> u >> v >> w; set<long long> st; long long cx = u; while (cx) { st.inse...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 10; const int mod = 1e9 + 7; int n, m, s[maxn]; bool cow[maxn][maxn]; long long cnt0[maxn], cnt1[maxn], psum[maxn][maxn]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { scanf("%d", &s[i]); } for (int i = 0; i < m; i++) { int...
8
#include <iostream> #include <bits/stdc++.h> using namespace std; #define ll long long #define vint vector<ll> #define pint pair<ll,ll> #define vpint vector<pint> #define ppint pair<pint,ll> #define pb push_back #define all(v) v.begin(),v.end() #define ios cin.sync_with_stdio(false),cin.tie(NULL) #define f_(i,m,n) for...
0
#include <bits/stdc++.h> const int maxn = 100005; const char f0[] = "What are you doing at the end of the world? Are you busy? Will you save " "us?"; const char fi1[] = "What are you doing while sending \""; const char fi2[] = "\"? Are you busy? Will you send \""; const char fi3[] = "\"?"; const int f0len = str...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int maxm = 1e6 + 10; const int inf = 0x3f3f3f3f; const long long mod = 998244353; const int maxblock = sqrt(maxn) + 10; const double eps = 1e-7; const long long INF = 1e16; long long n, m, l, r; long long qpow(long long a, long long b, long ...
6
#include <bits/stdc++.h> using namespace std; int main() { int a, c; cin >> a >> c; vector<int> va, vc; while (a) { va.push_back(a % 3); a /= 3; } while (c) { vc.push_back(c % 3); c /= 3; } if (va.size() < vc.size()) { int len = vc.size() - va.size(); for (int i = 0; i < len; i++...
1
#include <bits/stdc++.h> using namespace std; const int N = 200001; long long a[N + 1], tree[4 * N], lazy[4 * N]; void build(int idx, int l, int r) { if (l == r) tree[idx] = a[l]; else { int m = (l + r) / 2; build(2 * idx, l, m); build(2 * idx + 1, m + 1, r); tree[idx] = min(tree[2 * idx], tree[...
7
#include <bits/stdc++.h> using namespace std; int n; int q; int s; struct st { int a; int b; long long int cost; }; vector<st> v[100002 * 4][2]; int node[100002]; inline void init(int b, int l, int r) { v[b][1].push_back({b, 0, 0}); if (l + 1 == r) { node[l] = b; return; } init(b * 2 + 1, l, (l + ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, cnt = 0, m, a, b, start = -1, stop = -1; cin >> n; int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } for (i = 0; i < n - 1; i++) { if (arr[i] > arr[i + 1]) { start = i; cnt++; while (i < n - 1 && arr[i]...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, t, c = 0, q = -1; cin >> n >> k; vector<long long int> a, b; map<long long int, int> d; for (int i = 0; i < n; i++) { cin >> t; a.push_back(t); } sort(a.begin(), a.end()); for (long long int i = 0; i < n; i++) { i...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, k; bool vis[2][maxn]; char wall[2][maxn]; bool dfs(int d, int p, int lev) { if (p >= n) return true; int j = p + k, i = d ^ 1; if (j >= n || (!vis[i][j] && wall[i][j] == '-' && lev + 1 < j)) { if (j < n) vis[i][j] = true; if (df...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long k; cin >> k; bool d = 1; int z = 0; while (k != 0) { if (k % 10 != 4 && k % 10 != 7) { int h = 2; } else { z++; } k = k / 10; } if (z == 0) { d = 0; } ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; int k[n]; for (int i = 0; i < n; i++) cin >> k[i]; int time[n]; for (int i = 0; i < n; i++) { time[i] = 15 * k[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j <...
0
#include <bits/stdc++.h> using namespace std; vector<long long int> v[200005]; vector<long long int> v1[200005]; long long int d[200005]; long long int s, t; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, a, b, k; cin >> n >> m; for (long long int i = 0; i < m; i++) { ci...
4
#include <bits/stdc++.h> using namespace std; void test(vector<int> a, vector<int> b, int n) { int flag = 0; int diff = 0; int i = 0; for (i = 0; i < n; i++) { if (a[i] == b[i]) { if (!flag) { continue; } else { break; } } if (a[i] != b[i]) { if (!flag) { ...
1
#include <bits/stdc++.h> using namespace std; int n, p[300000], q[300000]; vector<pair<int, int> > v; void deb() { for (int i = 0; i < n; i++) cout << p[i] + 1 << " "; cout << endl; } void sw(int i, int j) { int t; v.push_back(pair<int, int>(i, j)); t = p[i]; p[i] = p[j]; p[j] = t; q[p[i]] = i; q[p[j]...
4
#include <bits/stdc++.h> using namespace std; int a[10000]; int main() { ios_base::sync_with_stdio(0); long long n, q; cin >> n >> q; while (q--) { long long x; cin >> x; if (x % 2) cout << (x + 1) / 2 << endl; else { long long mv = n - x / 2; long long id = x; while (mv)...
4
#include <bits/stdc++.h> #ifdef ALGO #include "el_psy_congroo.hpp" #else #define DUMP(...) 1145141919810 #define CHECK(...) (__VA_ARGS__) #endif template<int MOD> struct Integral { int v_ = 0; template<typename T> Integral(T v) : v_(norm(v)) { // Implicit conversion is allowed. static_assert(std::is_integral...
7
#include <bits/stdc++.h> using namespace std; const int N = 200005; int t[N], n, a[N], p[N]; int v[N * 4], S[N * 4]; long long SS[N * 4]; void change(int x) { for (; x <= n; x += x & (-x)) ++t[x]; } int ask(int x) { int s = 0; for (; x; x -= x & (-x)) s += t[x]; return s; } void build(int k, int l, int r) { S...
7