func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int abs(int x) { return x >= 0 ? x : -x; } int main() { int n; cin >> n; while (n--) { vector<int> x; vector<int> y; char tmp; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { cin >> tmp; if (t...
#include <bits/stdc++.h> using namespace std; string s; int n, i, j, k, mx = 0, sum = 0, vis[5005], letter[26], check[26][5005][26], ok; double ans = 0; int main() { cin >> s; n = s.length(); s = s + s; for (i = 0; i < n; i++) { letter[s[i] - a ]++; for (j = i; j < i + n; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> sms; int time1, amount1; for (int i = 0; i < n; i++) { cin >> time1 >> amount1; sms.push_back(make_pair(time1, amount1)); } int time = 0; int amount = 0; int maxamount =...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, t, cc, flag[maxn], a[maxn]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; if (n == 1) { cout << + << endl; return 0; } for (int i = 1; i <= n; i++) flag[i] = 1; flag[n] = -1; ...
#include <bits/stdc++.h> using namespace std; double revs, a, b, c, d, C, totdist; const double pi = atan(1) * 4; int n, r, v, s, f; double distcovered(double t) { return max(r * (t + sin(t)), r * (t - sin(t))); } int main() { cout << fixed << setprecision(8); cin >> n >> r >> v; for (int c = 0;...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e15; const int MOD = 1e9 + 7; const double EPS = 1e-7; const double PI = acos(-1.0); const int N = 3e5 + 5; long long n, a[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); cin >> n; for (int ...
#include <bits/stdc++.h> using namespace std; void make(vector<pair<int, int> > &a, long long int b) { int last = 0; int n = a.size(); for (int i = 0; i < a.size() - 1; i++) { if (b >= pow(2, n - 2 - i)) { a[i].first = n - last; last++; b = b - pow(2, n - 2 - i); } el...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 1000005; int n, k; int st1[MAX][20]; int st2[MAX][20]; int v[MAX]; int c[MAX]; int ans[MAX]; double factor[MAX]; int log(int x) { int ct = 0; int k = 1; while (k <= x) { k *= 2; ct++; ...
#include <bits/stdc++.h> using namespace std; void fast_in_out() { std::ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); } int main() { fast_in_out(); int n, x, y, c = 0; cin >> n; for (int(i) = 0; (i) < (n); ++(i)) { cin >> x >> y; if (y >= x + 2) c++; ...
#include <bits/stdc++.h> using namespace std; int main() { long long int w, h; cin >> w >> h; long long int cnt = 0; for (int i = 2; i <= w; i += 2) { for (int j = 2; j <= h; j += 2) { cnt += ((w - i + 1) * (h - j + 1)); } } cout << cnt; return 0; }
#include <bits/stdc++.h> const int mxn = 1e5 * 4 + 10, mod = 1e9 + 7; using namespace std; long long phi(long long n); long long gcd(long long a, long long b); long long lcm(long long a, long long b); long long n, m, t = 0, l, k, a, tmp, d; int mn = 1e9, mx = -1; int main() { cin >> n >> t >> k >> d...
#include <bits/stdc++.h> using namespace std; int x[10007], y[10007]; int n, w, v, u; int main() { cin >> n >> w >> v >> u; double maxer = -1; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } double lim = u * 1.0 / v; bool flag1 = false; bool flag2 = false; for (int i =...
#include <bits/stdc++.h> using namespace std; int a[200002], ans[200002]; int main() { int n, i, k = 0, sum = 0; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a[i]); sum += a[i]; } for (i = 0; i < n; i++) { if (((sum - a[i]) / (n - 1) == a[i]) && ((sum - a[i]) % (n ...
#include <bits/stdc++.h> using namespace std; long long int cnt[22]; int main() { int n; cin >> n; int a; for (int i = 0; i < n; i++) { cin >> a; cnt[a + 10]++; } long long int ans = cnt[10] * (cnt[10] - 1) / 2; for (int i = 1; i <= 10; i++) ans += cnt[-i + 10] * cnt[i + 10...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10, size = 1 << 20, mod = 998244353; template <class o> void qr(o &x) { char c = getchar(); x = 0; int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - 0 ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { int a; cin >> a; string s; cin >> s; set<char> st; for (int i = 0; i < s.size(); i++) { st.insert(s[i]); } if (st.size() == 1) { cout << -1 << << ...
#include <bits/stdc++.h> using namespace std; int main() { long long int MOD = 998244353; long long int n; cin >> n; pair<long long int, long long int> arr[n]; for (long long int i = 0; i < n; ++i) cin >> arr[i].first >> arr[i].second; long long int fact[n + 1]; fact[0] = 1; for (lon...
#include <bits/stdc++.h> using namespace std; void solve() { long long h, w; cin >> h >> w; long long pow2max = 1; while (2 * pow2max <= h && 2 * pow2max <= w) pow2max *= 2; long long hmax = min(h, (long long)(1.25 * pow2max)); long long wmax = min(w, (long long)(1.25 * pow2max)); if (hm...
#include <bits/stdc++.h> int main() { long i, n, d = 0; scanf( %ld , &n); for (i = 1; i <= n / 2; i++) { if (n % i == 0) d++; } printf( %d , d); return 0; }
#include <bits/stdc++.h> using namespace std; long long Ax, Ay, Bx, By, Cx, Cy; bool solvable(long long A, long long B) { return (Cx * A + Cy * B) % (Cx * Cx + Cy * Cy) == 0 && (-Cy * A + Cx * B) % (Cx * Cx + Cy * Cy) == 0; } bool possible() { cin >> Ax >> Ay >> Bx >> By >> Cx >> Cy; if...
#include <bits/stdc++.h> using namespace std; bool a[1000][1000]; int main() { ios::sync_with_stdio(false); int n, m, ans = 0; cin >> n >> m; bool tmp = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; char s[6][8], t[10]; int n; bool match(char* a, char* b) { for (int i = 0; i < 7; i++) if (b[i] != . && a[i] != b[i]) return 0; return 1; } int main() { sprintf(s[0], jolteon ); sprintf(s[1], flareon ); sprintf(s[2], umbreon ); ...
#include <bits/stdc++.h> using namespace std; string s, v; int ans, p, t; char c; char tr[1000]; int mypow(int k) { int c = 1; for (int i = 1; i <= k; i++) { c *= 2; } return c; } int main() { gets(tr); s = (string)tr; p = 0; for (int i = 0; i < s.length(); i++) { ...
#include <bits/stdc++.h> using namespace std; struct ruchy { bool kol[55]; bool wiersze[55]; }; int dl, szer, ilosc_ruchow; int kolumny[55]; int wiersze[55]; ruchy gra[2510]; char palnsza[54][54]; bool dasie = 1; void wypisgry() { for (int k = 0; k < ilosc_ruchow; k++) { cout << r...
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int dx2[] = {1, -1, 0, 0, -1, 1, -1, 1}; int dy2[] = {0, 0, 1, -1, 1, -1, -1, 1}; int read() { int x; scanf( %d , &x); return x; } int ans[100005]; int a[100005]; int used[1000001]; int ma...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, c; cin >> n >> m >> c; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> b(n); for (int i = 0; i < m; i++) cin >> b[i]; int cur = 0; for (int i = 0; i < a.size(); i++) { if (i >= 0 && i < ...
#include <bits/stdc++.h> using namespace std; const long long Mo = 1e9 + 7; int cnt[1 << 6], sz; void add(long long &x, long long y) { x += y; x %= Mo; } void gao(int n, int C, int R, vector<vector<long long>> &Ma) { int loop = 1 << R; for (int i = 0; i < sz; i++) { int c = i / loop, r...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1000000 ) using namespace std; int c, v, c1, v1, *a[262144], *s[262144]; void l(int w, int e, int t) { w <<= 1; if ((c <= e) && (e + t - 1 <= v)) { c1 += a[w][v1]; v1 = s[w][v1]; } else if (min(v, e + t - 1) - max(c, e) >= 0) ...
#include <bits/stdc++.h> using namespace std; vector<int> cities[100000], T[100000]; bool visited[100000]; int tin[100000], low[100000], tv[100000]; int up[100000][20]; map<pair<int, int>, int> b; int c = 0, n, l, m, k; void dfs1(int v, int p = -1) { visited[v] = true; tin[v] = low[v] = c++; ...
#include <bits/stdc++.h> using namespace std; long long sum[500001], ans; long long solve(long long a, long long b, long long c, long long hh) { if (a < b + c) return 0ll; long long now = min(a - b - c, hh); return (now + 1) * (now + 2) / 2; } int main() { long long a, b, c, l, i; scanf( %...
#include <bits/stdc++.h> using namespace std; const int maxn = 10005; long long n, m, a[maxn], b[maxn]; int k; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long exgcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1, y = ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 17; long long n, a[MAXN], ans; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { int t = log2(n - i); a[...
#include <bits/stdc++.h> using namespace std; int n, a[101]; void scan() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); sort(a, a + n); } void out() { int ans = 0, k = 0, c; while (1) { c = 0; for (int i = 0; i < n; i++) { if (a[i] != -1) { ...
#include <bits/stdc++.h> using namespace std; long long n; vector<pair<long long, long long> > serv; bool check(long long x1, long long x2) { long long pos = 0; bool found = false; for (long long i = n - 1; i >= 0; --i) { if (serv[i].first * (n - i) >= x2) { found = true; pos =...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 9, base = 27; int cnt_list, pos[20200], pa[20100], len[20100], fs[20100], pc[20100], ls[20100], cnt_ls, tmp[20100], cnt, n, num_q; struct pp { int id; char ch; }; vector<pp> adj[20201]; pp now; void dfs(int id, int pr) { ...
#include <bits/stdc++.h> using namespace std; const int N = 50 + 7; int ned[N][N]; string s[N]; void paint(const vector<pair<int, int> > &v) { set<pair<int, int> > s; queue<pair<int, int> > que; map<pair<int, int>, int> cnt; for (auto e : v) { que.push(e); s.insert(e); } co...
#include <bits/stdc++.h> using namespace std; long long x, y, p, q; bool check(long long t) { return ((p * t >= x) && ((q * t - p * t) >= (y - x))); } int main() { int t; scanf( %d , &t); while (t--) { scanf( %I64d%I64d%I64d%I64d , &x, &y, &p, &q); long long l = 0, r = 1e9, mid; ...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; inline int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } inline int sub(int a, int b) { a -= b; if (a < 0) a += mod; return a; } inline int mul(int a, int b) { return (a * 1ll * b) % mod; } ...
#include <bits/stdc++.h> using namespace std; vector<int> x[200]; int y[200], n, i, j, k, a, b, c, s, A, B; int main() { scanf( %d , &n); n *= 2; for (i = 1; i <= n; i++) scanf( %d , &k), x[k].push_back(i); for (i = 10; i <= 99; i++) if (x[i].size() == 1) { if (a > b) y[x...
#include <bits/stdc++.h> #include <chrono> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<long, long>; using vi = vector<int>; using vl = vector<long long>; using vb ...
#include <bits/stdc++.h> using namespace std; #define endl n typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef tuple<int, int, int> tiii; typedef tuple<ll, ll, ll> tlll; const int INF = 100000000; const ll INFINITE = 4500000000000000000; int main(void) { in...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); int main() { int n; double R, r; double st; while (scanf( %d %lf , &n, &R) != EOF) { st = pi / (1.0 * n); r = sin(st) * R / (1 - sin(st)); printf( %.7lf n , r); } return 0; }
#include <bits/stdc++.h> using namespace std; int a[2000090]; int d[2000009][11]; int main() { ios::sync_with_stdio(0); for (int i = 1; i < 10; i++) a[i] = i; for (int i = 1; i < 2000009; i++) { int l = 1; int g = i; while (g != 0) { if (g % 10 != 0) l *= (g % 10); ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; if (m == 0) { cout << n << << n << endl; return 0; } long long min = 0; if (m * 2ll <= n) { min = n - m * 2; } long long e = 1; long long g = 2; long long max = 0; ...
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; typedef long long ll; const ll Mod = 1000000007; int t; int n; ll x[500500]; ll sum_bit[70]; int main(){ ios::sync_with_stdio(false); cin >> t; while(t--){ cin >> n; rep(i, n) cin >> x[i]; ...
#include <bits/stdc++.h> using namespace std; struct ant { int id; int novo_id; long long int p; int dir; }; struct rotate_edges { int id_ini; int id_fim; }; int compara_p(ant a, ant b) { return a.p < b.p || (a.p == b.p && a.dir < b.dir); } int compara_p_reverso(ant a, ant b)...
#include <bits/stdc++.h> int max(int a, int b) { return a > b ? a : b; } int a[510][510], num[510], n, m, Q, ans, x, y; void work(int pos) { num[pos] = 0; int f = 0; for (int i = 1; i <= m; i++) if (a[pos][i]) f++; else num[pos] = max(num[pos], f), f = 0; num[pos] = max...
#include <bits/stdc++.h> int main() { int n, start; char str[60]; scanf( %s , str); n = strlen(str); n = n % 2 ? n / 2 : n / 2 - 1; printf( %c , str[n]); for (int i = 1; i <= n; i++) printf( %c%c , str[n + i], str[n - i]); if (strlen(str) % 2 == 0 && strlen(str) > 1) printf( %c ,...
#include <bits/stdc++.h> using namespace std; int main() { int n, cntx = 0, cntX = 0, c = 0; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == x ) cntx++; else cntX++; } int i = 0; if (cntx > cntX) { while (cntx != cntX) { ...
#include <bits/stdc++.h> const double EPS = 1e-9; const int INT_INF = 1 << 31 - 1; const long long I64_INF = 1ll << 63 - 1ll; const double PI = acos(-1.0); using namespace std; vector<int> r; string second; void ReadTable(int id, int& FinalId); string GetTag(int id) { string res = ; id++; ...
#include <bits/stdc++.h> using namespace std; int n, T, cnt, top; char s[5100][5100]; struct poi { int x, y; poi() {} poi(int x, int y) : x(x), y(y) {} void trs() { swap(x, y); x--; y = n - y; } friend bool operator<(const poi &r1, const poi &r2) { if (r1.x == r2....
#pragma GCC optimize(3, Ofast , inline ) #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <set> #include <map> #include <vector> #include <stack> #include <queue> using namespace std; typedef long long ll; typedef pair<int, int> pii; ...
#include <bits/stdc++.h> using namespace std; long long n, x, a, s; vector<pair<int, long long> > v, u; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x >> a; if (x < 0) v.push_back(make_pair(-x, a)); else u.push_back(make_pair(x, a)); s += a; } ...
#include <bits/stdc++.h> using namespace std; int a[101][101]; void rec(int x, int y) { if (x - 1 > 0 && a[x][y] > a[x - 1][y]) { a[x - 1][y] = a[x][y] - 1; rec(x - 1, y); } if (a[x][y] > a[x + 1][y]) { a[x + 1][y] = a[x][y] - 1; rec(x + 1, y); } if (y - 1 > 0 && a[x][y...
#include <bits/stdc++.h> using namespace std; string i_str(int n) { char buff[10]; sprintf(buff, %d , n); return string(buff); } int main() { int a, b; cin >> a >> b; if (a < b) { cout << b; return 0; } string sa, sb, t, r = , si = ; sb = i_str(b); for (i...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const long long mod = 1e9 + 7; long long powr(long long a, long long b) { long long x = 1 % mod; a %= mod; while (b) { if (b & 1) x = (x * a) % mod; a = (a * a) % mod; b >>= 1; } return x; } long l...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t, n; string s; cin >> t; while (t--) { cin >> n >> s; vector<int> szs; char prev = s.front(); int sz = 0; for (char c : s) { if (c != prev) { s...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 3e5 + 10; template <typename value_t> class fenwick { public: fenwick(int n) { memset(c, 0, sizeof c); this->n = n; } void add(int i, value_t x) { while (i <= n) { c[i] += x; ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, n, t, r = 0; cin >> a >> b >> c >> n; for (int i = 0; i < n; i++) { cin >> t; if (t > b && t < c) r++; } cout << r << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using ld = long double; using pii = pair<int, int>; ll val(ll solve, ll whole) { if (2 * solve > whole) return 500; if (4 * solve > whole) return 1000; if (8 * solve > whole) return 1500; if (16 * sol...
#include <bits/stdc++.h> using namespace std; int main() { int i, j; string s; cin >> s; if ((int)s[0] >= 97 && (int)s[0] <= 122) { s[0] = (char)((int)s[0] - 32); } for (i = 0; i < s.size(); i++) { cout << s[i]; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 101000; int a[maxn], x, y, z, cnt, curr, ans, n, m; vector<int> v; int bs(int x) { int l = 0, r = m; while (l < r - 1) { int mid2 = (l + r) / 2; if (v[mid2] < x) { l = mid2; } else { r = mid2; } ...
#include <bits/stdc++.h> long long int mod = 1000000007; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k; cin >> n >> k; long long int p = k / n; if (k % n != 0) { p += 1; } cout << p; return 0; }...
#include <bits/stdc++.h> using namespace std; long long n, z = 1, x, c, zx; map<string, long long> m; string a[1001], s; int main() { while (getline(cin, s)) { a[n++] = s; zx = max(zx, (long long)s.size()); } for (int i = -2; i < zx; i++) cout << * ; cout << n ; for (int i =...
#include <bits/stdc++.h> using namespace std; int main() { int samples, len, temp, sz; cin >> samples >> len; deque<int> q; set<int> s; sz = s.size(); for (; samples--;) { cin >> temp; s.insert(temp); if (s.size() > sz) { q.push_front(temp); if (q.size() > l...
#include <bits/stdc++.h> using namespace std; struct inter { int l, r, id; inter() { l = r = id = -1; } inter(int _l, int _r, int _id) { l = _l, r = _r, id = _id; } bool operator<(const inter &r) const { return l < r.l; } }; int N, L, R; int A[100005], C[100005]; int B[100005]; map<int, in...
#include <bits/stdc++.h> using namespace std; int n, m, c; int a[1005]; bool check() { bool good = a[0] > 0; for (int i = 1; i < n; i++) good &= (a[i] > 0) && (a[i] >= a[i - 1]); return good; } int main() { cin >> n >> m >> c; for (int i = 0; i < n; i++) a[i] = 0; while (m--) { ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1 << 19; long long n, k; long long ans[maxn], mx[maxn], mn[maxn]; bool occ[maxn]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (long long i = 0; i < (long long)(1 << k); ++i) mx[i] = -1e...
#include <bits/stdc++.h> using namespace std; int n, k; int d[2005]; vector<int> E[2005]; bool h[2005]; const int INF = 1e9 + 7; void add(int u, int v) { E[u].push_back(v); } void bfs() { queue<int> q; d[0] = 0; q.push(0); while (q.size()) { int t = q.front(); q.pop(); ...
#include <bits/stdc++.h> using namespace std; int ncr(int n, int r) { int ret = 1; for (int i = 1; i <= n - r; i++) { ret = (ret * (n - r + i)) / i; } return ret; } int main() { int n; cin >> n; int x; long long pos = 0; long long neg = 0; long long prod = 1; fo...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int a[maxn]; struct node { int l, r, Max, Min, pa, pi; } T[maxn << 2]; void pushup(int o) { T[o].Min = min(T[o << 1].Min, T[o << 1 | 1].Min); T[o].Max = max(T[o << 1].Max, T[o << 1 | 1].Max); if (T[o].Min == T[o << 1].Min...
#include <bits/stdc++.h> typedef struct pair { int x, y; } pair; int const N = 1e4 + 5; int n = 8; pair sMatrix[N], sac[N]; char matrix[N][N], mariaMove[10][10][100]; pair anna, maria; int i, j, k, s, m, h, t; int kontrol(int x, int y) { int i, j; for (i = 0; i < s; i++) { if (sMatri...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; clock_t timeStart, timeFinish; void timeBegin() { timeStart = clock(); } void timeEnd() { timeFinish = clock(); } void timeDuration() { double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC); cout << Time take...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int INF = 1e9 + 7; const int N = 2e5 + 7; const int M = 1e6 + 7; long long a[N], b[N]; long long dp[N][2]; signed main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >>...
#include <bits/stdc++.h> using namespace std; const int N = 1005; const int INF = 0x3f3f3f3f; int n, w[N], h[N]; int maxx; int sum, sum1, ans = INF; inline void fuck(int id, int tot) { sum1 = sum; priority_queue<int> q; int tall; if (tot == 1) tall = w[id], sum1 = sum1 - w[id] + h[id...
#include <bits/stdc++.h> using namespace std; int main() { int t, s, q, ans = 0; cin >> t >> s >> q; int downloaded = s; while (downloaded < t) { downloaded += s * (q - 1); s = downloaded; ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 5; struct Node { long long ls, rs, val, key, cnt, tag, add; }; Node t[maxn]; long long pol; void newnode(long long vv) { t[++pol].val = vv; t[pol].cnt = 0; t[pol].key = rand(); t[pol].ls = t[pol].rs = 0; t[p...
#include <bits/stdc++.h> using namespace std; long long mas[1010]; unordered_map<long long, int> sootv; long long num[100100]; long long gcd(long long a, long long b) { if (!a) return b; return gcd(b % a, a); } int main() { int n; long long k; cin >> n >> k; for (int i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; const int N = 100000; int aa[N]; map<int, int> mp; set<int> s; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> aa[i]; for (int i = 0; i < n; i++) { mp[aa[i]]++; if (mp[aa[i]] == 1) s.insert(aa[i]); ...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; class DSU { public: vector<int> parent; vector<int> sizes; int noOfComponenents; DSU(int N) { parent.resize(N); sizes.resize(N); noOfComponenents = N; for (int i = 0; i < N; ++i) { parent[i] = i...
#include <bits/stdc++.h> using namespace std; long long C(long long n, long long m) { long long res = 1; for (long long i = n; i > n - m; i--) res *= i; for (long long i = m; i >= 1; i--) res /= i; return res; } int main() { ios::sync_with_stdio(0), cin.tie(0); long long n, k, res = 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int M = 205; long long n, m, k, cnt, ans; long long g[N], h[N], dp[N][M]; struct redpocket { long long s, t, d, w; bool operator<(const redpocket &x) const { if (w == x.w) return d < x.d; return w < x.w; } ...
#include <bits/stdc++.h> using namespace std; void PT(long long a); void PT1(long long a); const long long M = 2010, mod = 1e9 + 7; long long n, m, x, y, a, b, dp[M][M], mp[M][M], mp1[M][M]; vector<string> v; void bfs(long long r, long long c, long long l, long long ri) { queue<pair<long long, long lo...
#include <bits/stdc++.h> using namespace std; int main() { long int i, j, d, m, n, a[100000]; while (cin >> n) { for (i = 1; i <= n; i++) { cin >> a[i]; } i = 1; j = n; int A = a[i], B = a[j]; int ca = 0, cb = 0; while (1) { if (A > B) { B ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<long long> sc(n); for (typeof(n) i = (0); i < (n); i++) cin >> sc[i]; int m; cin >> m; for (typeof(m) i = (0); i < (m); i++) { long long w, h; cin >> w >> h; ...
#include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored -Wformat template <typename T> void printContainer(T& a) { auto it = a.begin(); cout << { << *(it++); for (; it != a.end(); ++it) cout << , << (*it); cout << } n ; } map<long long, int> A1, A2; int sol; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 17; int l1[N], r1[N], a[N], use[N]; map<int, bool> mt; void dfs(int v, int l, int r) { if (a[v] > l && a[v] < r) mt[a[v]] = 1; if (l1[v] != -1) dfs(l1[v], l, min(r, a[v])); if (r1[v] != -1) dfs(r1[v], max(l, a[v]), r); } int mai...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n; int ar[100005]; int main() { scanf( %d , &n); if (n == 2) { printf( 2 1 ); return 0; } for (int i = 1; i <= n; i++) ar[i] = i; for (int i = 1; i <= n; i++) { for (int j = i + i; j <= n; j...
#include <bits/stdc++.h> using namespace std; struct pt { long long x, y; int id; pt() {} pt(long long a, long long b, int c = -1) : x(a), y(b), id(c) {} }; pt operator+(pt a, pt b) { return pt(a.x + b.x, a.y + b.y); } pt operator-(pt a, pt b) { return pt(a.x - b.x, a.y - b.y); } long long d...
#include <bits/stdc++.h> using namespace std; const int N = 200005, mod = 1e9 + 7; int n, head[N], nxt[N << 1], to[N << 1], num = 0, dfn[N], DFN = 0, a[N], dep[N]; inline void link(int x, int y) { nxt[++num] = head[x]; to[num] = y; head[x] = num; } namespace tr { int fa[N], top[N], sz[N], son[...
#include <bits/stdc++.h> using namespace std; const double error = 1e-15; const double pi = 2 * acos(0); const int maxn = (int)1e5 + 10; const int mod = (int)1e9; int dx[] = {0, -1, 0, +1, -1, -1, +1, +1}; int dy[] = {-1, 0, +1, 0, -1, +1, +1, -1}; long A[205][200], B[200]; vector<int> v; int main()...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1 << endl; } else if (n % 2 == 0) { cout << n / 2 << endl; } else if (n % 2 != 0) { cout << n / 2 + 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 300010; map<pair<pair<int, int>, int>, vector<int> > ans; map<pair<pair<int, int>, int>, vector<pair<int, int> > > l; map<pair<pair<int, int>, int>, vector<pair<int, int> > >::iterator it; int n, m; struct Point { int x, y; Point(int _x =...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; int n, k; long long f[100009], g[100009]; vector<int> p; string s1, s2; int main() { cin >> s1 >> s2 >> k; int i; n = s1.size(); p.clear(); for (i = 1; i <= n; ++i) { if (s1 == s2) p.push_back(i - 1);...
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; cout << min(n, m) + 1 << endl; for (int i = 0; i <= min(n, m); i++) cout << i << << min(n, m) - i << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long A[100005]; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { long long n; long long i; cin >> n; for (i = 0; i < n; i++) cin >> A[i]; sort(A, A + n); long long g, s, num; s = num = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 2, M = 1e6 + 2; int n, m, X[N << 1], Y[N << 1], C[N][N]; void Merge(vector<pair<int, pair<int, int> > > &v) { sort(v.begin(), v.end()); int q = 0; for (int i = 1; i < (int)(v.size()); i++) { if (v[i].first != v[q].first || v[i]....
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long MOD2 = 998244353; double eps = 1e-12; using namespace std; template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << ( << p.first << , << p.second << ) ; } ...
#include <iostream> using namespace std; int main() { int n,q, l,r; cin>>n>>q; string s; cin>>s; int arr[n]; arr[0]=s[0]- a +1; for(int i=1;i<n;i++){ arr[i]=arr[i-1]+s[i]- a +1; } while(q--){ cin>>l>>r; cout<<(arr[r-1]-((...
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false), cin.tie(nullptr); int tests; cin >> tests; while (tests--) { int n, k; string s; cin >> n >> k >> s; const int need = n / k; vector<vector<int>> counts(k, vector<int>(26, 0)); f...