func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x = 0, y = 0; char s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == 0 ) y++; else x++; } if (x == y) { cout << 2 << endl << s[0] << ; for (int i...
#include <bits/stdc++.h> using namespace std; long long n, k; long long a[100010]; signed main() { scanf( %lld%lld , &n, &k); long long cnt = 1; long long l = 1; long long ans = 0; for (long long i = 1; i <= n; i++) { scanf( %lld , &a[i]); cnt = cnt * a[i] % k; if (!cnt) { ...
#include <bits/stdc++.h> using namespace std; const int N = 200001; int n; vector<pair<int, int> > a[N * 2]; vector<int> odd; int used[N * 2], cur[N * 2]; char res[N]; void dfs(int u) { while (cur[u] < a[u].size()) { int v = a[u][cur[u]].first; int pos = a[u][cur[u]].second; if (us...
#include <bits/stdc++.h> using namespace std; const long long linf = 1e18 + 5; const int mod = (int)1e9 + 7; const int logN = 17; const int inf = 1e9; const int N = 2e5 + 5; int n, a[N], s; vector<pair<long long, long long> > T[N << 2], g[N << 2]; pair<long long, long long> line[N]; long long pre[N]...
#include <bits/stdc++.h> using namespace std; int n; char a[22][22], b[22][22], c[22][22]; bool chk() { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (a[i][j] != b[i][j]) return false; return true; } void flip() { for (int i = 0; i < n; i++) for (int j = 0; j < n...
#include <bits/stdc++.h> using namespace std; inline int getc() { char ch = getchar(); while (ch != 0 && ch != 1 ) { ch = getchar(); } return ch - 0 ; } int main() { int n; scanf( %d , &n); int cnt1 = 0, cnt2 = 0; for (int i = 0; i < n; ++i) { if (getc() == i % 2)...
#include <bits/stdc++.h> using namespace std; template <typename T> struct Segtree { int n; T e; vector<T> dat; typedef function<T(T a, T b)> Func; Func f; Segtree() {} Segtree(int n_input, Func f_input, T e_input) { initialize(n_input, f_input, e_input); } void initializ...
#include <bits/stdc++.h> using namespace std; int dp[2][1 << 16]; char art[7][1008]; int n; int c[5]; vector<int> modi[1008]; void upd(int &x, int y) { x = min(x, y); } int main() { scanf( %d , &n); for (int i = 1; i <= 4; i++) scanf( %d , &c[i]); for (int i = 1; i <= 4; i++) scanf( %s , art...
#include <bits/stdc++.h> using namespace std; const int N = 106; long long d, A[N], f[N]; bool vs[N]; int X[N], Y[N], n; queue<int> q; inline long long dis(int a, int b) { return abs(X[a] - X[b]) + abs(Y[a] - Y[b]); } bool judge(long long init) { memset(f, -1, sizeof f); while (!q.empty())...
#include <bits/stdc++.h> using namespace std; void RI() {} template <typename... T> void RI(int &head, T &...tail) { scanf( %d , &head); RI(tail...); } struct Maxflow { struct E { int to, cap, rev, rcap, ucap; E() {} E(int _to, int _cap, int _rev) : to(_to), cap(_cap)...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, t, x; string s = ; cin >> t; for (i = 0; i < t; i++) { s += o ; } int ara[t + 5]; ara[0] = 1; ara[1] = 1; s[0] = O ; s[1] = O ; for (i = 2; i <= t; i++) { ara[i] = ara[i - 1] + ara[i ...
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const int maxn = 1e6 + 50; const int Mod = 1e9 + 7; using namespace std; int n, m, sx, sy, dx, dy; int get(int sx, int sy, int ex, int ey) { int cx = abs(sx - ex), cy = abs(sy - ey); if (cx == 0 && cy == 0) return 0; if (cx % dx != 0 || cy % d...
#include <bits/stdc++.h> using namespace std; char op[] = { R , G , B , Y , W , 1 , 2 , 3 , 4 , 5 }; string s[555]; int main() { int n, i, j, k; ios_base::sync_with_stdio(0), cin.tie(0); cin >> n; for (i = 1; i <= n; i++) { cin >> s[i]; } map<char, bool> mp; int mn = 1...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<pair<long long, long long>> v(n); for (int i = 0; i < n; i++) cin >> v[i].second >> v[i].first; sort(v.rbegin(), v.rend()); long long ans = 0, sum = 0; priority_queue<long long, vector<long long>, ...
#include <bits/stdc++.h> using namespace std; const int N = 2e2; int i, a[N], n; int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); cout << a[n - 1] << ; for (i = 1; i < n - 1; i++) cout << a[i] << ; cout << a[0]; return 0; }
#include <bits/stdc++.h> using namespace std; int TEST, CASE = 1; int n, m, a, b, c, k, x, y, z, len, total = 0; string s, temp, ans; vector<string> v; bool cmp(string &a, string &b) { if (a.size() < b.size()) return true; else return false; } int main(void) { cin >> n; for (...
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf( %d , A + i); } unordered_map<int, int> dp; int N, S[(4000)]; int dyn(int a, int b, int K, bool x) { if (b - a + 1 < K) return 0; if (b - a + 1 == K) return (S[b] - (a ? S[a - 1] : 0)); if...
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N |= (1LL << pos); } int Reset(int N, int pos) { return N &= ~(1LL << pos); } bool Check(int N, int pos) { return N & (1LL << pos); } int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {1, -1, 0, 0, 1, -1, -1, 1}; inline void cn(long...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); double a, b, c[100005], mx; int n; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %lf %lf , &a, &b); c[i] = (atan2(b, a) * 180) / pi; } sort(c, c + n); for (int i = 0; i < n - 1; i++) ...
#include <bits/stdc++.h> using namespace std; int n, ans = 1e9; pair<int, int> p[1005]; void solve(int height) { int width = 0, remain = n / 2; vector<int> priority; for (int i = 1; i <= n; i++) if (p[i].second > height) if (p[i].first > height) return; else if (remai...
#include <bits/stdc++.h> using namespace std; struct node { int x, num; } s[100009]; int mark[100009]; int cmp(node a, node b) { return a.x < b.x; } int main() { int n, m; while (scanf( %d %d , &n, &m) == 2) { int l, h; scanf( %d %d , &l, &h); for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const long long N = 2000 * 100 + 1000; vector<long long> adj[N]; long long a[N], h[N], t[N]; bool mark[N]; long long f(long long p) { mark[p] = true; long long ans = h[p] * a[p]; t[p] = a[p]; for (auto q : adj[p]) if (mark[q] == false) { ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 1 ) continue; if (s[i] == 4 && s[i - 1] == 1 ) continue; if (s[i] == 4 && i > 1 && s[i - 1] == 4 && s[i - 2] == 1 ) continue; return cout << N...
#include <bits/stdc++.h> using namespace std; const int N = 5010; int n, m, s; vector<int> e[N]; int low[N], dfn[N], idx; bool vis[N]; stack<int> st; bool in_stack[N]; int color[N], color_tot; int indeg[N]; int ans; void AddEdge(int u, int v) { e[u].push_back(v); } void Dfs(int u) { low[u]...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, a; cin >> n >> m >> a; long long v = n / a; long long t = m / a; if (n % a != 0) v++; if (m % a != 0) t++; cout << v * t; }
#include <bits/stdc++.h> using namespace std; struct Edge { int v; char c; } edge[220]; vector<Edge> ans; vector<int> Chain[10]; int N; bool flag[110]; void dfs(int x) { for (int i = 0; i < Chain[x].size(); i++) { int v = edge[Chain[x][i]].v, id = Chain[x][i] >> 1; if (!flag[id])...
#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; } const int N = 1e3 + 9; double dp[N][...
#include <bits/stdc++.h> using namespace std; long long spf[3000001]; long long fac[3000001]; void sieve() { spf[1] = 1; for (long long i = 2; i < 3000001; i++) spf[i] = i; for (long long i = 4; i < 3000001; i += 2) spf[i] = 2; for (long long i = 3; i * i < 3000001; i++) { if (spf[i] == i)...
#include <bits/stdc++.h> using namespace std; long long int pow_mod(long long int a, long long int b) { long long int res = 1; while (b != 0) { if (b & 1) { res = (res * a) % 1000000007; } a = (a * a) % 1000000007; b /= 2; } return res; } long long int inv(long lo...
#include <bits/stdc++.h> using namespace std; const unsigned long long INF = ~0ll; unsigned long long prime[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int n; unsigned long long ans; void dfs(int deepth, unsigned long long v, unsigned long long n...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, a, b; cin >> n >> a >> b; if (2 * a < b) { long long ans = n * a; cout << ans << endl; } else { long long cou = n % 2; long long ans = (n / 2) * ...
#include <bits/stdc++.h> using namespace std; const long long p = 1000000007LL; long long power(long long x, long long n) { long long ret = 1LL; while (n > 0LL) { if (n & 1LL) ret = ret * x % p; x = x * x % p; n >>= 1LL; } return ret; } long long n, m; long long dp; int m...
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull; template <typename T> bool umax(T& a, const T& b) { return b <= a ? false : (a = b, true); } template <typename T> bool umin(T& a, const T& b) { return b >= a ? false...
#include <bits/stdc++.h> using namespace std; void solve() { int n, t; cin >> n >> t; for (int i = 1; i <= n; i++) { int val; cin >> val; t -= (86400 - val); if (t <= 0) { cout << i << n ; return; } } } int main() { solve(); return 0; } ...
#include <bits/stdc++.h> using namespace std; void desperate_optimization(int precision) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(precision); } const int N = 2e5; long long arrA[N + 5], arrB[N + 5]; ...
#include <bits/stdc++.h> using namespace std; long long maxm = -1e18; long long minm = 1e18; long long mod = 1e9 + 7; long long mod1 = 1e9 + 9; const long double Pi = 3.141592653; long long int fact(long long int n) { if (n == 0) { return 1; } else if (n == 1) { return 1; } lon...
#include <bits/stdc++.h> using namespace std; const int M = 4e3 + 44; const int F = 4000; int n; int s[M]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &s[i]); printf( %d n , n + 1); int tmp, tmp1, tmp2, sum = 0; for (int i = n; i >= 1; i--) { tmp = (F + i...
#include <bits/stdc++.h> using namespace std; static const int maxn = 2e5 + 5; struct Node { bool ok; int val; int pos, rpos; Node(bool ok = 0, int val = 0, int pos = 0, int rpos = 0) : ok(ok), val(val), pos(pos), rpos(rpos) {} bool operator<(const Node &other) const { if (ok and...
#include <bits/stdc++.h> using namespace std; long long rdtsc() { long long tmp; asm( rdtsc : =A (tmp)); return tmp; } inline int myrand() { return abs((rand() << 15) ^ rand()); } inline int rnd(int x) { return myrand() % x; } const int INF = (int)1e9 + 1; const long double EPS = 1e-9; voi...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000,100000000 ) using namespace std; const long long inf = 1e9 + 7; const long long mod = 1e9 + 7; const double eps = 1e-9; const double PI = 2 * acos(0.0); const double E = 2.71828; int main(void) { long long n; cin >> n; double...
#include <bits/stdc++.h> using namespace std; string norm(string s) { string res = s; for (int i = 0; i < 2; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { res = min(s, res); swap(s[0], s[1]); swap(s[1], s[2]); swap(s[2], s[3]); ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; vector<vector<int> > dp(201); for (int i = 1; i <= n; i++) { dp[a[i]].push_back(i); ...
#include <bits/stdc++.h> using namespace std; int n, m; int s, t, ds, dt; struct edge { int u, v; } E[400005]; vector<int> vecr[200005]; int pre[200005]; int find(int x) { if (x != pre[x]) pre[x] = find(pre[x]); return pre[x]; } void Union(int x, int y) { pre[find(x)] = find(y); } int ...
#include <bits/stdc++.h> using namespace std; double power(float x, int y) { float temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else { if (y > 0) return x * temp * temp; else return (temp * temp) / x; } } bool i...
#include <bits/stdc++.h> using namespace std; int64_t calc(int64_t l, int64_t r, int64_t ln) { if (ln < 2) return 1; int64_t mx = max(l, r); int64_t mn = min(l, r); int64_t ans = (int64_t)pow(201, (ln - 2)); cout << ans << endl; ans += (int64_t)pow((201 - mx + 1), (ln - 1)); cout << ans ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-6; int main() { { ; }; int n; scanf( %d , &n); vector<pair<int, int> > V(n); int totalW = 0; for (int i = 0; i < n; i++) { scanf( %d %d , &V[i].first, &V[i].second); totalW += V[...
#include <bits/stdc++.h> int findMaximalK(int n); using namespace std; int main() { int n, b, p, x, y; cin >> n >> b >> p; y = n * p; x = 0; int remaining = n; while (remaining > 1) { int doingMatch = pow(2, findMaximalK(remaining)); x += doingMatch * b + doingMatch / 2; ...
#include <bits/stdc++.h> using namespace std; using LL = long long; const int M = 1e7 + 5; const int N = 3e5 + 5; struct node { vector<int> h, c; node() { h.clear(); c.clear(); } void read(int n) { int ans; for (int i = 0; i < n; i++) { scanf( %d , &ans); ...
#include <bits/stdc++.h> long long Max(const long long x, const long long y) { if (x > y) return x; return y; } const long long mo = 1e9 + 7, M = 1005; char s[M]; long long k, a[M], len, dp[M][M][2]; long long dfs(const long long pos, const long long dis, const bool pd, const bool li...
#include <bits/stdc++.h> template <class Class> void Print(Class instance) { std::cout << instance << std::endl; } void Print() { std::cout << std::endl; } int main() { std::ios_base::sync_with_stdio(false); size_t n; std::cin >> n; std::vector<int> time(n + 1); std::vector<int> paid(n...
#include <bits/stdc++.h> using namespace std; multiset<int> s1; struct node { char s; int a1; } p1[int(1e6 + 50)]; char s[50]; int main() { int n, a; while (~scanf( %d , &n)) { int cnt = 0; s1.clear(); for (int i = 0; i < n; i++) { scanf( %s , s); if (s[0] !...
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vll = vector<long long>; using vvll = vector<vll>; using vpii = vector<pair<int, int> >; using vpll = vector<pair<long long, long long> >; using vld = vector<long double>; using vb = vector<bool>; const int inf = (int)1e9 + 7;...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> yarr(51, 0); vector<int> xarr(51, 0); int q = 4 * n + 1; vector<pair<int, int>> trav; for (int i = 0; i < q; i++) { int x, y; cin >> x >> y; trav.push_back(make_pair(x, y)); xa...
#include <bits/stdc++.h> using namespace std; long long s[10], m[10]; const long long md = 1e9 + 7; string str; int n; vector<int> v[100010]; int main() { for (int i = 0; i <= 9; i++) { m[i] = 10; s[i] = i; } cin >> str; scanf( %d , &n); for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; 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)); } const int MAXN = 600010; set<int> g[MAXN]; int n, t, m, k; int visited[MAXN]...
#include <bits/stdc++.h> using namespace std; int n, m; int a, b, c; vector<pair<int, int> > v[200005], e[200005]; int p[200005]; int fin(int x) { if (p[x] != x) p[x] = fin(p[x]); return p[x]; } void onion(int x, int y) { if (fin(x) == fin(y)) return; p[fin(y)] = fin(x); } priority_q...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3010; const int INF = 0x3f3f3f3f; int d[MAXN], e[MAXN]; int main() { memset(d, INF, sizeof d); memset(e, INF, sizeof e); int n; cin >> n; string s; cin >> s; int at = INF; for (int i = 0; i < n; i++) { if (s[i...
#include <bits/stdc++.h> using namespace std; inline void Rd(int &res) { char c; res = 0; while (c = getchar(), c < 0 ) ; do { res = (res << 1) + (res << 3) + (c ^ 48); } while (c = getchar(), c >= 0 ); } const int S = 200; long long n, s, ans; int work(long long x) { i...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, i, fuck = 0; scanf( %lld , &a); scanf( %lld , &b); scanf( %lld , &c); for (i = a; i >= 1; i--) { if ((2 * i) <= b && (4 * i) <= c) { fuck = 1; break; } } if (fuck == 0) printf(...
#include <bits/stdc++.h> using namespace std; unsigned long long pw[1020304], iv[1020304]; unsigned long long h[1020304], f[1020304]; int check(int l, int r) { unsigned long long p1 = (h[r] + 1000000007 - h[l - 1] * pw[r - l + 1] % 1000000007) % 10000...
#include <bits/stdc++.h> using namespace std; const int N = 150000; const int L = 19; vector<int> edges[N]; long long x[N], y[N]; int anc[N][L], tin[N], tout[N], s[N], moment; void dfs(int x, int last) { tin[x] = ++moment; anc[x][0] = last; for (int i = 1; i < L; i++) anc[x][i] = anc[anc[x][i ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) using namespace std; const double inf = 1e121; const double eps = 1e-10; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long randint(long long l, long long r) { long long out = rng...
#include <bits/stdc++.h> using namespace std; int n, tot, d[105]; int read() { int _ = 0, ___ = 1; char __ = getchar(); while (__ > 9 || __ < 0 ) { if (__ == - ) ___ = -1; __ = getchar(); } while (__ >= 0 && __ <= 9 ) { _ = _ * 10 + __ - 0 ; __ = getchar(); ...
#include <bits/stdc++.h> using namespace std; int prime(int n) { if (n == 1) { return 0; } for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return 0; } } return 1; } int main() { int n; cin >> n; int cnt = n; while (!prime(cnt)) { cnt++; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long double PI = acosl(-1); const long long inf = 3e18; const int nmax = 1e5 + 5; const int MAXLG = log2(nmax) + 1; vector<int> g[nmax]; long long val[nmax], chein[nmax], path[nmax]; long long dfs(int u, int p = 0) { chei...
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, k; cin >> n >> k; vector<long long> v; set<long long> s; map<long long, long long> m; for (long long i = 0; i < n; i++) { cin >> x; if (m[x] == 0) { m[x]++; v.insert(v.begin(), x); } ...
#include <bits/stdc++.h> using namespace std; int md = 1e9 + 7; int __gcd(int a, int b) { if (b == 0) return a; return __gcd(b, a % b); } int poww(int a, int b) { int res = 1; while (b) { if (b & 1) { res *= a; res %= md; } a *= a; a %= md; b >>= 1...
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long const int MAX_N = 1e5 + 1; const int m = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; int main() { int t=1; cin>>t; int n; while(t--) { cin>>n; int A[n]; for(int i=0;i<n;i+...
#include <bits/stdc++.h> using namespace std; long long dp[2000010], v[2000010]; int main() { for (int i = 3; i <= 2000000; i++) { dp[i] = (dp[i - 1] + 2 * dp[i - 2] + 4 * (!v[i - 1] && !v[i - 2])) % 1000000007; v[i] = !v[i - 1] && !v[i - 2]; } int t; scanf( %d , &t); whi...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e3; int r, c, n, k, tot, bound[maxn + 2], vis[maxn + 2], suc[maxn + 2], pre[maxn + 2], rest[maxn + 2]; bool exist[maxn + 2][maxn + 2]; long long ans; struct vertex { int x, y; } a[maxn + 1]; vector<int> t[maxn + 1]; int main() {...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, a, b; string s = ; cin >> n >> a >> b; s += a ; for (int i = 1; i < b; i++) { s += s[i - 1] + 1; } string s2 = s; for (int i = 0; i < n / b - 1; i++...
#include <bits/stdc++.h> using namespace std; set<int> cn[10000]; int nx[10000]; string xm[10000]; int main() { int m; cin >> m; ; map<string, int> mx; int n = 0; for (int i = (0); i < m; i++) { string a, b; cin >> a >> b; if (!mx.count(a)) mx[a] = n, xm[n++] = a; ...
#include <bits/stdc++.h> enum { WHITE, GREY, BLACK }; using namespace std; long long int inf = 1e18; template <class T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T last_bit(T n) { ret...
#include <bits/stdc++.h> using namespace std; int n, m, k, ans, s, e, in[100020], pre[100020], vis[100020], ff[100020]; long long len[100020]; struct node { int v, f; long long w; }; vector<node> adj[100020]; bool operator<(const node &x, const node &y) { if (x.w > y.w) return true; return...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; cin >> n; long long int mc[6]; mc[0] = mc[5] = 0; for (long long int i = 0, k = 0; i < n; i++) { cin >> k; mc[k] += 1; } if (mc[0...
#include <bits/stdc++.h> using namespace std; const int MOD = 32768, N = 109; char ch; string s[N], t; int ans, v, f[MOD + 9], num, p, pos; int ex(); int gt() { int ret = 0; if (t[pos] == n ) return pos++, v; if (t[pos] == f ) return pos += 2, ret = f[ex()], pos++, ret; while (t[pos] >= ...
#include <bits/stdc++.h> using namespace std; int n, m, l; vector<vector<int>> adj; int timer; vector<int> tin, tout; vector<vector<int>> up; vector<int> dist; vector<int> down; void dfs(int v, int p) { dist[v] = dist[p] + 1; down[v] = 1; tin[v] = ++timer; up[v][0] = p; for (int i ...
#include <bits/stdc++.h> using namespace std; int fp(int abc, int parent[]) { if (parent[abc] == abc) return abc; int def = fp(parent[abc], parent); parent[abc] = def; return def; } void cycledmerge(vector<int> hub[], int n, int parent[]) { stack<int> urutan; for (int i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; int n, resmax = -round(1e9), resmin = round(1e9); int main() { cin >> n; for (int i = 1; i <= 7; i++) { int j = i, dem1 = 0; for (int dem = 1; dem <= n; dem++) { if ((j % 7 == 0) || (j % 7 == 6)) dem1++; j++; if (j > 7) j = ...
#include <bits/stdc++.h> using namespace std; int main() { string st; cin >> st; for (int i = 0; i < st.length(); i++) { if (st[i] == H || st[i] == Q || st[i] == 9 ) { cout << YES << endl; return 0; } } cout << NO << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int solve() { int n; cin >> n; if (n == 1) return cout << -1 << endl, 0; string s = ; for (int i = 0; i < n - 1; i++) s += 3 ; cout << 2 + s << endl; return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(...
#include <bits/stdc++.h> using namespace std; int gi() { int res = 0, w = 1; char ch = getchar(); while (ch != - && !isdigit(ch)) ch = getchar(); if (ch == - ) w = -1, ch = getchar(); while (isdigit(ch)) res = res * 10 + ch - 0 , ch = getchar(); return res * w; } const int Mod = 1e9 ...
#include <bits/stdc++.h> using namespace std; map<int, int> cnt, b; vector<int> ans; int a[200010], x; int n, m, p; int main() { cin >> n >> m >> p; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) { cin >> x; b[x]++; } for (int i = 0; i < p; i++) { ...
#include <bits/stdc++.h> using namespace std; int k[5] = {100, 20, 10, 5, 1}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; while (cin >> n) { long long ans = 0; for (int i = 0; i < 5; i++) { ans += n / k[i]; n %= k[i]; } cout << ans << n ;...
#include <bits/stdc++.h> #pragma optimize( Ofast ) using namespace std; using ll = long long int; using ull = unsigned long long int; using dd = double; using ldd = long double; using si = short int; using pii = pair<int, int>; using pll = pair<ll, ll>; int _size = 1 << 20; vector<ll> tree(_size <...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; cin >> TESTS; while (TESTS--) { long long n, x, y, d; cin >> n >> x >> y >> d; if (abs(y - x) % d == 0) { cout << abs(y - x) / d << ...
#include <bits/stdc++.h> using namespace std; long long nch(long long n) { long long ans = 0, tmp = 1, k = 1; while (n) { ans += min(n, tmp * 9) * k; n -= min(n, tmp * 9); tmp *= 10; k++; } return ans; } char get(long long n, long long d) { string s; stringstream ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 7; vector<int> g[N]; int used[N]; int pos[N]; vector<vector<int>> cycles; vector<int> st; void dfs(int u, int p = -1) { st.push_back(u); pos[st.back()] = (int)st.size() - 1; used[u] = 1; for (auto v : g[u]) { if (!us...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200015; const int MOD = 1000000007; int a[MAXN]; bool F(int len, int num) { bool flag; int pres; for (int i = 0; i <= num - 1; i++) { flag = true; pres = i; for (int j = 0; j <= len - 1; j++) { if (a[pres] == ...
#include <bits/stdc++.h> using namespace std; int main() { int n; int s; cin >> n; s = n; int k = 2; while (k <= n) { if (n % k == 0) { s += n / k; n = n / k; } else k++; } cout << s; return 0; }
#include <bits/stdc++.h> using namespace std; int signum(long long a) { return (a == 0 ? 0 : (a > 0 ? 1 : -1)); } int dir(pair<long long, long long>& a, pair<long long, long long>& b, pair<long long, long long>& c) { return signum((b.first - a.first) * (c.second - a.second) - (b.se...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, y = 0; cin >> a >> b; while (a <= b) { a *= 3; b *= 2; y++; } cout << y; return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const long long Inf = 1e10; const int P = 1e9 + 7; const int N = 100005; const int M = 1000005; inline long long IN() { long long x = 0; int ch = 0, f = 0; for (ch = getchar(); ch != -1 && (ch < 48 || ch > 57); ch = getchar()) ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 500010; const int Maxk = 110; const int Maxp = 110; const int inf = 2147483647; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } int main() { int t; cin >> t; while (t--) { long long x, y; cin >> x >> y; if (gcd(x, y) == 1) { cout << FINITE <<...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int cycl[N], set_val[N], cycl_size[N]; int main() { int h, m, n; cin >> h >> m >> n; vector<int> strt; bool vis[h]; memset(vis, false, sizeof vis); int kk = 0; set<int> dmm[h + 1]; for (long long i = 0; i < m; i+...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int a[n], p[n], s[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int blocks = 0; p[0] = a[0]; for (int i = 1; i < n; i++) { p[i] = max(p[i - 1], a[i]); } s[n - 1] = a[n - 1]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, i, j; cin >> n >> m >> k; int a[n][m]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> a[i][j]; } } int x; for (i = 0; i < k; i++) { cin >> x; x--; int v = 0; wh...
#include <bits/stdc++.h> using namespace std; int main() { int n, i = 0; cin >> n; long long a; vector<long long> vc; while (n--) { cin >> a; vc.push_back(a); } sort(vc.begin(), vc.end()); i = vc.size(); long long ans = vc[i - 1]; for (int j = i - 2; j >= 0; j--) ...
#include <bits/stdc++.h> using namespace std; int q, n; long long s, cur; char str[100100]; int main() { scanf( %lld%d , &s, &q); while (q--) { scanf( %lld , &cur); scanf( %s , str); n = strlen(str); for (int i = 0; i < n; i++) { long long t = 1; while (cur % (t...