func_code_string
stringlengths
59
71.4k
// Codeforces Round #720 (Div. 2) // Problem link: https://codeforces.com/problemset/problem/1521/B // Problem tags: constructive algorithms math *1300 // CODE #include <iostream> #include <vector> #include <limits.h> using namespace std; int main() { int t; ...
#include <bits/stdc++.h> using namespace std; const int MX = (int)1e5 + 5; int test; vector<int> con[MX]; int dp[MX], sz[MX], prv[MX]; void dfs(int u) { sz[u] = 1; for (int v : con[u]) { dp[v] = dp[u] + 1; dfs(v); sz[u] += sz[v]; } } int fst[MX], st[MX], en[MX], pn; void ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, i, s, a1, b1, m; cin >> t; while (t--) { cin >> n >> m; if (n < m) { cout << 0 n ; continue; } if (n == m) cout << n % 10 << n ; else { long long int a[10] = {}...
#include <bits/stdc++.h> using namespace std; int getInt(); int getNegInt(); int T, N; int get_nearest(int p, int a, vector<vector<int> >& path, unordered_set<int>& me) { if (me.find(a) != me.end()) return a; for (auto b : path[a]) { if (b == p) continue; int tar = get_ne...
#include <bits/stdc++.h> using namespace std; vector<long long> a; bool valido; vector<vector<long long>> adj; long long d; void dfs(long long u, long long p = 0) { if (!valido) return; for (long long v : adj[u]) if (v != p) dfs(v, u); if (a[u] % d == 0) { a[p]++; } else { ...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { int n; cin >> n; vector<int> nums; for (long long i = 0; i < n; i++) { int num; cin >> num; nums.push_back(num); } sort(nums.begin(), nums.end()); ...
#include <bits/stdc++.h> using namespace std; struct node { int l, r; node() { l = r = -1; } } p[30]; int vis[30], sum[1000005]; int main() { int n, k; cin >> n >> k; string s; cin >> s; for (int i = 0; i < s.length(); i++) { int id = s[i] - A ; if (!vis[id]) { ...
#include <bits/stdc++.h> using namespace std; int n, q; int arr[1000010], lazy[1000010 << 2]; string str; struct data { int n4, n7, n47, n74; data() { n4 = n7 = n47 = n74 = 0; } } tree[1000010 << 2]; void build(int node, int l, int r) { if (l == r) { tree[node].n4 = (arr[l] == 4); ...
#include <bits/stdc++.h> using namespace std; struct FenwickTree { int N; vector<int> A; FenwickTree(int N) : N(N), A(N) {} int rsq(int b) { int sum = 0; for (; b; b -= (b & (-b))) sum += A[b]; return sum; } int rsq(int a, int b) { return rsq(b) - (a == 1000000000 ? 0 : rsq...
#include <bits/stdc++.h> using namespace std; int main() { int t, s, q; cin >> t >> s >> q; int ans = 0; while (s < t) { s = s * q; ans++; } cout << ans; return 0; }
#include <bits/stdc++.h> inline int read() { static char ch; while (ch = getchar(), ch < 0 || ch > 9 ) ; int res = ch - 48; while (ch = getchar(), ch >= 0 && ch <= 9 ) res = res * 10 + ch - 48; return res; } inline unsigned int Rand() { static unsigned int x = 998666131; re...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, A = 1e5 + 2; bool v[20][20]; long long dp[20][1 << 20]; int n, m, start = 0; long long solve(int node, int mask) { if (~dp[node][mask]) return dp[node][mask]; long long ret = 0; if (v[node][start] && __builtin_popcount(mask) ...
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, m, q, t, r, c, x; int R[N], C[N], ans[N][N]; pair<int, pair<int, int> > arr[N][N], temp[N]; int main() { cin >> n >> m >> q; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { arr[i][j].second.first = i; ...
#include <bits/stdc++.h> using namespace std; const int N = 330, INF = 1000010000; int n, m, u, x, y, z, I, ans; int r[N], l[N], X[N], W[N], a[N], b[N], f[N], g[N][N], h[N][N]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d%d , &X[i], &W[i]); b[++m] = X[i], b[++m] =...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 1e5 + 10; vector<int> v[N]; void init() { int tot = 0; for (int i = 1; i < N; i++) { for (int j = i; j < N; j += i) { v[j].push_back(i); } tot = max(tot, (int)v[i].size()); } } ...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int n, a[MAX], bk[3]; int ans[MAX]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], bk[a[i]]++; sort(a + 1, a + n + 1, greater<int>()); int cur = 0, top = 0, tar; for (int i = 1; i <= n; i++) { cu...
#include <bits/stdc++.h> using namespace std; template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << ( << p.first << , << p.second << ) ; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << { ; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; int n, m; char mat[100][100]; char c; vector<int> us; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> mat[i]; for (int i = 0; i < n; i++) { us.clear(); for (int j = 0; j < m; j++) { if (mat[i][j] == # ) us.push_bac...
#include <bits/stdc++.h> using namespace std; priority_queue<long long int> dif; vector<long long int> vec; long long int a[1000000], b[1000000]; int main() { long long int x, d, contador = 0, i; long long int pot, exp; cin >> x >> d; while (x > 0) { x++; pot = 1; exp = 0; ...
#include <bits/stdc++.h> using namespace std; const long long pw10[] = {1, 10, 100, 1000, 10000, 100000}; long long K, F[7], Q, dp[7][2000000]; signed main() { cin >> K; for (long long i = 1; i <= 6; ++i) cin >> F[i]; memset(dp, -0x3f, sizeof(dp)); dp[0][0] = 0; for (long long i = 1; i <= 6;...
#include <bits/stdc++.h> using namespace std; const long long maxn = 500000 + 5; long long a[maxn], tmp[maxn]; multiset<long long> save; vector<pair<long long, long long> > b; int main() { long long total = 0; long long n; scanf( %lld , &n); for (long long i = 0; i < n; i++) scanf( %lld , a ...
#include <bits/stdc++.h> using namespace std; long long int b[101]; int main() { long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; b[a[i]]++; } long long int ans = 0; for (int i = 1; i < 101; i++) { if (b[i] >= ans) { an...
#include <stdio.h> #include <vector> #include <algorithm> #include <set> #define pii pair<int,int> #define ll long long using namespace std; vector<int> edge[200001]; vector<pii > pt[200001]; int depth[200001]; ll d[200001]; int a[200001],v[200001]; void dfs(int x) { for (auto nxt : edge[x]) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, res1, res2; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; res1 = a[0] ^ a[1]; vector<int> st; for (int i = 0; i < n; i++) { while (!st.empty() && st.back() < a[i]) st.pop_back(); st.push_...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse2 ) using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __...
#include <bits/stdc++.h> using namespace std; void solve() { int N, K; cin >> N >> K; set<int> s; for (int i = 0; i < N; i++) { int a; cin >> a; s.insert(a); } if (s.size() > K) { cout << -1 << endl; return; } cout << N * K << endl; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int a[100005]; int l[1000], r[1000]; vector<int> v[100000]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= m; i++) { int s, t; scanf( %d%...
#include <bits/stdc++.h> using namespace std; long long power(long long b, long long e, long long m) { long long p = 1; while (e > 0) { if (e & 1) p = (p * b) % m; e = e >> 1; b = (b * b) % m; } return p; } long long cnt[16] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 0}; ...
#include <bits/stdc++.h> using namespace std; int sum[705][705], a[500100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q, t, x, y; memset(sum, 0, sizeof(sum)); cin >> q; while (q--) { cin >> t >> x >> y; if (t == 1) { a[x] += y; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 300001; int dp[82][82][82][82], n, k, m, u, v, c; vector<pair<int, int> > g[83]; int calc(int idx, int l, int r, int rem) { if (rem == 0) return 0; if (l > r) return 1e9; int &ret = dp[idx][l][r][rem]; if (r...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<pair<string, int>> v(n); for (int i = 0; i < n; i++) { string s; cin >> s; v[i].first = s; v[i].second = i + 1; } for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; long long FastExp(long long a, long long b, long long c) { if (b == 1) return a; long long ans = FastExp(a, b / 2, c); if (b % 2 == 0) return ans % c * ans % c; if (b % 2 != 0) return ans % c * ans % c * a % c; } int main() { int n; cin >> n;...
#include <bits/stdc++.h> using namespace std; int main() { int mas[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int m, n; bool ans = false; cin >> n >> m; for (int i = 0; i < 15; i++) { if (mas[i] == n) { if (mas[i + 1] == m) { ans = true; bre...
#include <bits/stdc++.h> using namespace std::chrono; using namespace std; const int mod = 1e9 + 7; string s; int op[501], cl[501]; int sop[501], scl[501]; int n; void f() { memset(op, 0, sizeof(op)); memset(cl, 0, sizeof(cl)); if (s[0] == ( ) op[0]++; else cl[0]++; mems...
#include <bits/stdc++.h> using namespace std; int n; int a[100100]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); set<int> s; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) s.insert(a[i] - a[i - 1]); if (s.size() == 1) cout << a[n - 1] + ...
#include <bits/stdc++.h> using namespace std; vector<int> g[500000]; bool visited[500000]; int n; unordered_map<int, int> m, p; vector<pair<int, int> > v; void check(int u) { visited[u] = true; for (auto v : g[u]) { if (!visited[v]) check(v); } } int main() { cin >> n; set<in...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; struct ppi { long long max; int id; int w; } pp1; struct pi { int le; int ri; int max; int id; } pp[maxn << 2]; void build(int tot, int le, int ri) { pp[tot].le = le; pp[tot].ri = ri; pp[tot].max...
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n, k; cin >> n >> k; int j = 1000; for (int i = 0; i < n; i++) { cin >> a[i]; if (k % a[i] == 0) { j = min(k / a[i], j); } } cout << j; }
#include <bits/stdc++.h> using namespace std; const int MAX = 100010, TOUR = 1 << 17; struct tour { int val, broj, prop; tour(int val, int broj, int prop) : val(val), broj(broj), prop(prop) {} tour() {} } t[2 * TOUR]; struct event { int t, l, r, val; event(int t, int l, int r, int val) : t...
#include <bits/stdc++.h> using namespace std; constexpr long long mod = 1000000007; const long long INF = mod * mod; const long double eps = 1e-12; const long double pi = acosl(-1.0); long long mod_pow(long long x, long long n, long long m = mod) { long long res = 1; while (n) { if (n & 1) res...
#include <bits/stdc++.h> using namespace std; const int N = 1000000 + 10; int n, m, k; int a[N], b[N]; char s[N], t[N]; int p[22]; int mn[1 << 20], mx[1 << 20]; int getint(char *str) { char news[22]; for (int i = 1; i <= k; i++) { news[p[i]] = str[i]; } int ans = 0; for (int i ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } ...
#include <bits/stdc++.h> using namespace std; int t, n, a[110]; int main() { scanf( %d , &t); while (t--) { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); for (int i = 0; i < n; i++) a[i] %= 2; int sum = 0; for (int i = 0; i < n; i++) sum += a[i]; if (...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8, pi = acos(-1); const int SZ = 100050, INF = 0x7FFFFFFF; vector<int> mp[SZ]; int res, pos; int in[SZ]; void dfs(int u, int par) { int cur = 0; for (int i = 0; i < mp[u].size(); ++i) { int to = mp[u][i]; if (to != par...
#include <bits/stdc++.h> using namespace std; int len, rt, n, m; vector<int> g[210]; int a[210], b[210]; void dfs(int cur, int pre, int dep) { int i; if (dep > len) { len = dep; rt = cur; } for (i = 0; i < g[cur].size(); i++) { int u = g[cur][i]; if (u == pre) continue;...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int n; int fa[1000005], huan[1000005], zihuan[1000005], siz[1000005]; int find(int now) { return fa[now] == now ? now : fa[now] = find(fa[now]); } int main() { scanf( %d , &n); for (int i = 1; i <= 2 * n; i++) { fa[i]...
#include <bits/stdc++.h> using namespace std; template <class T> inline void amin(T &x, const T &y) { if (y < x) x = y; } template <class T> inline void amax(T &x, const T &y) { if (x < y) x = y; } template <class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp = 0...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int q = 0; q < t; ++q) { int n, k; cin >> n >> k; vector<int> x(n); for (int i = 0; i < n; ++i) { cin >> x[i]; } vector<int> p(n, 0); for (int i = 1; i < n - 1; ++i) { ...
#include <bits/stdc++.h> using namespace std; bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); } void solve() { long long n, m; cin >> n >> m; if (n == 1 || m == 1) { cout << YES << n ; return; } if (n != m) { cout << NO << n ; return; } if...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); string s; cin >> s; vector<string> a, b; string t = ; bool if_num = true, if_first = true; for (int i = 0; i < (int)s.size(); i++) { if (s[i] == , or s[i] == ; ) { if (if_num a...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a, b; int count = 0; for (int a = 0; a <= n + m; a++) for (int b = 0; b <= n + m; b++) { if (a * a + b == n && b * b + a == m) count++; } cout << count; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const int MAX = 505; int n, grid[MAX][MAX]; char s[5]; bool valid(int x, int y) { if (x < 1) return false; if (y < 1) return false; if (x > n) return false; if (y > n) return false; return true; } bool di...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int Log[N], bin[21], ls[N], rs[N], root, a[N], n, i, j; set<int> s[N]; pair<int, int> mx[N][20]; long long ans; void merge(int x, int y) { if (s[x].size() < s[y].size()) swap(s[x], s[y]); for (auto& z : s[y]) s[x].insert(z); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 510; long long sum[maxn]; int main() { long long n, k; int t; cin >> t; while (t--) { cin >> n >> k; if (n >= 32) { cout << YES << << n - 1 << endl; } else { memset(sum, 0, sizeof(...
#include <bits/stdc++.h> using namespace std; void solve(); int main() { solve(); } void solve() { int t; cin >> t; while (t--) { string s; cin >> s; priority_queue<int> q; int k = s.length(); int cur = (s[0] == 1 ) ? 1 : 0; for (int i = 1; i < k; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { float a1, b1, c1, a2, b2, c2; cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; if (!b1 && !b2) { if (!a1 && !a2 && c1 && c2) { cout << 0 << endl; return 0; } if ((!a1 && c1) || (!a1 && c2)) { cout << 0 << endl; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s, curr[1000]; long long int size = 0, j; cin >> j; while (j--) { cin >> s; if (s.compare( pwd ) == 0) { for (long long int i = 0; i < size; ++i) { cout <...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const int M = N * 30; int tree[M][2]; vector<int> val[M]; int main() { int n; scanf( %d , &n); vector<int> a(n + 1); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); int idx = 0; auto insert = [&](int n, int id) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>;...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long qpow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a; b >>= 1; a = a * a; } return res; } int a[500005]; int main() { int n, k; cin >> n >> k; fo...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast , unroll-loops ) using namespace std; const int inf = numeric_limits<int>::max() / 2; const long double eps = 1e-9; const long double pi = acos(-1); const int MAXN = (3e8 + 10) / 3; int n; unsigned int a, b, c, d; bitset<MAXN> primes; unsigned in...
#include <bits/stdc++.h> using namespace std; const int Max = 2e5 + 10; vector<int> A; int ok[Max]; int len; int seg[Max * 4]; int lazy[Max * 4]; void build(int tl = 0, int tr = len + 1, int idx = 1) { if (tr - tl == 1) { seg[idx] = len - tl; return; } int mid = (tl + tr) / 2; ...
#include <bits/stdc++.h> using namespace std; const int N = 120000 + 10; const double PI = acos(-1); pair<double, double> operator+(pair<double, double> a, pair<double, double> b) { return make_pair(a.first + b.first, a.second + b.second); } pair<double, double> operator-(pair<double, double> a, pair<do...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i <= n - 1; i++) cin >> arr[i]; vector<pair<int, int> > G[n]; int cnt = 0; for (int i = 0; i <= n - 1; i++) { for (int j = i + 1; j <= n - 1; j++) { if (arr[i] > arr[j]) ...
#include <bits/stdc++.h> using namespace std; int arr[300022]; int main() { int q; scanf( %d , &q); while (q--) { int n, i; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &arr[i]); map<int, int> mf, ml; map<int, int>::iterator it; for (i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; namespace mainns { template <typename T> void relaxMax(T& relaxWhat, const T& relaxBy) { relaxWhat = max(relaxWhat, relaxBy); } template <typename T> void relaxMin(T& relaxWhat, const T& relaxBy) { relaxWhat = min(relaxWhat, relaxBy); } namespace {...
#include <bits/stdc++.h> using namespace std; bool allCharactersSame(string s) { int n = s.length(); for (int i = 1; i < n; i++) if (s[i] != s[0]) return false; return true; } signed main() { int n; const int letters = 26; cin >> n; for (int i = 0; i < n; i++) { string st...
#include <bits/stdc++.h> using namespace std; const int N = 200010; int hp[N], dmg[N], p[N]; bool cmp(int a, int b) { return hp[a] - dmg[a] > hp[b] - dmg[b]; } bool vis[N]; int main() { int n, a, b; scanf( %d%d%d , &n, &a, &b); for (int i = 1; i <= n; i++) { scanf( %d%d , &hp[i], &dmg[i]);...
#include <bits/stdc++.h> using namespace std; const long long Maxn = 10000; const long double pi = acos(-1); const long long mod = 1000000007; template <class T> ostream &operator<<(ostream &out, vector<T> &A) { for (auto x : A) out << x << ; return out; } template <class T> ostream &operat...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 + 5; int N, P[MAXN]; long long D[MAXN]; vector<pair<long long, int>> v, f[2]; int main() { scanf( %d , &N); P[1] = 1, P[2] = 2; for (int i = 3, x; i <= N; ++i) { printf( 2 1 %d %d n , P[2], i); fflush(stdout); ...
#include <bits/stdc++.h> using namespace std; int i, j, m, n, u, v; long long a[15], mod, lose[14][16389], f[16389], g[16389][15]; long long sz[16389], inv[16389]; long long getinv(long long a, long long p) { if (a == 1) return 1; long long k = a - getinv(p % a, a); return (k * p + 1) / a; } l...
#include <bits/stdc++.h> const long double eps = 1e-9; const long long mod = 1e9 + 7, ll_max = (long long)1e18; const int MX = 2e5 + 10, int_max = 0x3f3f3f3f; using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long n, k; long long arr[MX]; int solve() { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long x[300001]; long long p[300001] = {1}; int main() { std::ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> x[i]; p[i + 1] = p[i] * 2 % MOD; } sor...
#include <bits/stdc++.h> using namespace std; vector<long long int> v, v1, v2; multiset<long long int> mss; multiset<long long int>::iterator it; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int a, b, c, d, i, j, z = 0, k, w = 1, q = 0, cnt = 0, x = 0, p = 0; ...
#include <bits/stdc++.h> using namespace std; bool cmp(int x, int y) { return x > y; } const int maxn = 3e5 + 100; vector<int> v[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (int i = 2; i < maxn; i++) for (int j = i; j < maxn; j += i) v[j].push_back(i); ...
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c...
#include <bits/stdc++.h> using namespace std; int main() { long long a, c; cin >> a >> c; vector<long long> aa; while (a) { aa.push_back(a % 3); a /= 3; } vector<long long> cc; while (c) { cc.push_back(c % 3); c /= 3; } long long i = 0, j = 0; vector<l...
#include <bits/stdc++.h> using namespace std; int sett(int n, int pos) { return n = n | (1 << pos); } int reset(int n, int pos) { return n = n & ~(1 << pos); } bool check(int n, int pos) { return (bool)(n & (1 << pos)); } template <typename T> T bigmod(T x, T p) { if (p == 0) return 1; if (p & 1) { ...
#include <bits/stdc++.h> using namespace std; map<int, vector<int> > mx; map<int, vector<int> > my; int pow(int x) { long long i = 2; long long r = 1; while (x) { if (x & 1) r = (r * i) % 1000000007; i = (i * i) % 1000000007; x = x >> 1; } return r; } int main() { i...
#include <bits/stdc++.h> using namespace std; long long Pow(long long a, long long b) { long long ans = 1LL, base = a % 1000000007; while (b != 0) { if (b & 1LL != 0) ans = ans * base % 1000000007; base = base * base % 1000000007; b >>= 1LL; } return ans; } long long A, B, n, x...
#include <bits/stdc++.h> using namespace std; void solve() { int n, d, m; cin >> n >> m >> d; int c[m], sum = 0; for (int i = 0; i < m; i++) { cin >> c[i]; sum += c[i]; } d--; if (sum + (m + 1) * d >= n) { cout << YES << endl; int k = (d > 0 ? (n - sum) / d : 0)...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e6 + 7; const int ALPHA = 40; const long long INF = 1e16 + 7; const int MOD = 1e9 + 7; const int LOG = 22; const int BASE[2] = {313, 239}; long long n, d; bool ns[MAXN], seen[MAXN]; vector<long long> group[MAXN], plast[MAXN]; void sol...
#include <bits/stdc++.h> using namespace std; const int maxn = 3000 + 50; vector<int> edge[maxn]; int sub[maxn][maxn], fa[maxn][maxn]; long long n, ans, dp[maxn][maxn]; void dfs(int root, int k, int dad) { sub[root][k]++; fa[root][k] = dad; for (auto t : edge[k]) { if (t != dad) { ...
#include <bits/stdc++.h> using namespace std; int main() { int i, n; long long a, sum, ans; priority_queue<long long, vector<long long>, greater<long long> > Q; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %lld , &a); Q.push(a); } if (n % 2 == 0) Q.push(0); ans = 0; ...
#include <cstdlib> #include <cstdarg> #include <cassert> #include <cctype> // tolower #include <ctime> #include <cmath> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <stdexcept> #include <map> #include <set> #include <list> #include <queue> #in...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, pg, pt; scanf( %d %d , &n, &k); char a[105]; scanf( %s , a); for (int i = 0; i < n; i++) { if (a[i] == G ) pg = i; if (a[i] == T ) pt = i; } int x = abs(pg - pt); if (x % k == 0) { int fg = 0, st...
#include <bits/stdc++.h> using namespace std; int n, m, k, trap[510]; int e[510][510]; long double t[510][510]; const long double EPS = 1e-9; void mult(long double a[110][110], long double b[110][110], long double c[110][110]) { long double r[110][110] = {}; for (int i = 0; i < (int)(110...
#include <bits/stdc++.h> using namespace std; int n; int a[303 + 303][303]; int d[303 + 303][303][303]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) scanf( %d , &a[i + j][j]); for (int diag = 0; diag < n + n - 1; ++diag) for (int i = 0; i < n; +...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double EPS = 1e-9; long long dis(pair<long long, long long> a, pair<long long, long long> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } signed main() { ...
#include <bits/stdc++.h> using namespace std; int main() { int a[101] = {}, b = 0, c, d, x, y, i, max = -1, f = 0; cin >> x >> y; for (i = 1; i <= x; i++) { cin >> c; a[c]++; } for (i = 1; i <= 100; i++) { if (a[i] > max) max = a[i]; if (a[i] != 0) f++; } if (max ...
#define _CRT_SECURE_NO_DEPRECATE #define _USE_MATH_DEFINES #include <array> #include <iostream> #include <fstream> #include <cstdio> #include <cstdlib> #include <cassert> #include <climits> #include <ctime> #include <numeric> #include <vector> #include <algorithm> #include <bitset> #include ...
#include <bits/stdc++.h> using namespace std; void solve_problem() { int n; cin >> n; set<int> s; for (int i = 1; i * i <= n; ++i) { s.insert(i * i); } for (int i = 1; i * i * i <= n; ++i) { s.insert(i * i * i); } cout << s.size() << n ; } int32_t main() { ios_b...
#include <bits/stdc++.h> using namespace std; const int N = 105; int t, a[N], b[N], n, m; int st[N], cnta[N], cntb[N]; unordered_map<int, int> num; int main() { cin >> t; while (t--) { memset(st, 0, sizeof(st)); scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &a[i])...
#include <bits/stdc++.h> using namespace std; const int N = 300005, inf = 0x3f3f3f3f; int n, a[N], tag[N << 2], mn[N << 2], mn_cnt[N << 2]; void upd(int u, int v) { mn[u] += v, tag[u] += v; } void pushdown(int u) { if (tag[u]) { upd(u << 1, tag[u]); upd(u << 1 | 1, tag[u]); tag[u] = 0; ...
#include <bits/stdc++.h> using namespace std; string s; int main() { ios_base::sync_with_stdio(0); cin >> s; vector<int> a; vector<int> b; int n = s.size(); for (int i = 0; i < n; i++) { if (s[i] == l ) a.push_back(i + 1); if (s[i] == r ) b.push_back(i + 1); } for (in...
#include <bits/stdc++.h> using namespace std; inline int read() { int l = 0, f = 1; char a = getchar(); for (; a < 0 || a > 9 ; a = getchar()) if (a == - ) f = -1; for (; a >= 0 && a <= 9 ; a = getchar()) l = l * 10 + a - 48; return l * f; } const int N = 300005; int n, ans = ...
#include <bits/stdc++.h> using namespace std; const long long oo = 1000000007; vector<long long> G; bool v[1000010]; long long a[1000010]; long long f[1000010]; long long p, k, i, j, ans; void dfs(long long o, long long st) { v[o] = 1; if (!v[(o * k) % p]) { dfs((o * k) % p, st + 1); }...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int start = 1; while (1) { if (m >= start) m -= start; else break; start++; if (start == (n + 1)) start = 1; if (m == 0) break; } cout << m; return 0; }
#include <bits/stdc++.h> using namespace std; int c[55]; bool dp[11111 * 55]; int a[11111 * 55]; int main() { ios_base::sync_with_stdio(false); int n, d; cin >> n >> d; for (int _n(n), i(0); i < _n; i++) cin >> c[i]; memset((dp), (0), sizeof(dp)); dp[0] = true; for (int _n(n), i(0)...
#include <bits/stdc++.h> using namespace std; const long long int N = 500005; long long int a[N], l[N], r[N]; long long int vl[N], vr[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); stack<long long int> s1, s2; long long int nu; cin >> nu; long long int pos ...