func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int number_of_usb; int file_size; int usb_required = 0; int summing = 0; int temp; int main() { cin >> number_of_usb; cin >> file_size; int usb_sizes[number_of_usb]; for (int i = 0; i < number_of_usb; i++) { cin >> usb_sizes[i]; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int MOD = 1e4 + 7; int n, m, q; int main() { scanf( %d , &q); while (q--) { int a, b; scanf( %d%d , &a, &b); int delt = abs(a - b); int ans = delt / 10 + (delt % 10 != 0); printf( %d n , ans); ...
#include <bits/stdc++.h> using namespace std; int N, tmp; bool flag = false; int main() { scanf( %d , &N); for (int i = 0; i < N; i++) { scanf( %d , &tmp); if (tmp == 1) flag = true; } if (flag) printf( %d , -1); else printf( %d , 1); return 0; }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int p = 27; string s; long long int hashnum(int lw, int up) { if ((up - lw) % 2 == 0) return (((hashnum(lw, (lw + up) / 2) * p) % mod + 1) * ((hashnum((lw + up) / 2, up) * p) % mod + 1))...
#include <bits/stdc++.h> using namespace std; struct point { int x, y; } a[200005]; bool cmp(struct point A, struct point B) { if (A.x != B.x) return A.x < B.x; return A.y < B.y; } int m; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { scanf( %d , &a[i].x); ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 2; int tree[N * 32][2], cnt[N * 32]; long long int curr = 1, n, ans; vector<long long int> arr(N); void clean() { for (long long int i = 0; i <= N * 32 - 1; i++) tree[i][0] = tree[i][1] = -1; } void add(long long int x) { long lon...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l, max1 = 0, n, p, sum = 0; string a, b, c; cin >> n; int x[26] = {0}; cin >> a; if (n > 26) cout << -1 << endl; else { for (i = 0; i < n; i++) { p = a[i] - a ; x[p]++; } fo...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int MAX = 30; long long x, num; long long a[40]; bool check(long long x) { for (int i = 1; i < MAX; ++i) { if (a[i] == x) return 1; } return 0; } vector<int> ans; int main() { long long x = 1; for (in...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:67108864 ) using namespace std; vector<int> g[200000]; bool def[200000], del[200000]; int all[200000], good[200000], _good[200000]; int n, m, k; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 0; i < k; i++) { int t; scanf...
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323846; const long long mod = 1e9 + 7; const long long N = 5e5; const long long INF = 1e9 + 1; long long n, m, ans; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); ci...
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(0); long long int n; cin >> n; cout << 1 << ; n--; for (int i = 1; i <= 2; i++) { if ((n - i) % 3 != 0) { cout << i << << n - i; break; } } }
#include <bits/stdc++.h> using namespace std; int n, sum, prv[100010], val[100010], a[100010]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); for (int i = n - 1; i >= 0; i--) { if (i == n - 1) val[i] = 1, sum = a[i]; else { if (sum <= a[i]) { ...
#include <bits/stdc++.h> using namespace std; int next(int a) { return a < 2 ? 1 : (next(a - 2) + (a - 1) / 2); } int main() { long int N; cin >> N; long int ret = 1; cout << (N + 1) / 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, f = 0, ans = 0; cin >> n; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) { if (a[i + 1] < a[i]) ans += (a[i] - a[i + 1]);...
#include <bits/stdc++.h> using namespace std; int main() { long n, h, x, m1 = 0, m2 = 0; cin >> n >> h; for (int i = 1; i <= n; i++) { cin >> x; if (x > h) { m1 += 2; } else { m2++; } } cout << m1 + m2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 4, inf = 1e9 + 7; vector<int> vec[N]; vector<pair<int, int> > qry[N]; int col[N], cnt[N], frq[N]; int vis[N], siz[N], Res[N]; void dfs(int u, int p) { siz[u] = 1; for (auto v : vec[u]) { if (v == p) continue; dfs(v, u); ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1000 * 1000 * 1000; struct rib { long long b, u, c, f; size_t back; }; void add_rib(vector<vector<rib> >& g, long long a, long long b, long long u, long long c) { rib r1 = {b, u, c, 0, g[b].size()}; rib r2 = {a,...
#include <bits/stdc++.h> using namespace std; int main() { int s, n, x, y; cin >> s >> n; vector<pair<int, int> > v; pair<int, int> p; for (int i = 0; i < n; i++) { cin >> x >> y; p = make_pair(x, y); v.push_back(p); } sort(v.begin(), v.end()); for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 10, maxm = 10000 + 10; long long n, m, drt = 1, x = 1, y = 1, ans = 0, dis = 0, o = 0; char mat[maxn][maxm]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { mat[i][0] = # ; mat[i][m + 1] = # ; for (int ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 12, INF = 1e9 + 7; int a[N]; int main() { int n, m, i, j, k; scanf( %d , &(n)); ; vector<int> dp; dp.push_back(-100001); for (i = 0; i < (n); ++i) { dp.push_back(100001); scanf( %d , &(a[i])); ; } ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int SIZE = 1e5 + 10; int t[SIZE * 3], thing[SIZE * 3]; int main() { int a, b, c, d, start, len, n; scanf( %d%d%d%d%d%d%d , &n, &a, &b, &c, &d, &start, &len); for (int i = 0; i < n; i++) scanf( %d%d , &t[i], &thing[i]);...
#include <bits/stdc++.h> using namespace std; string s; int n, x, y; void upd(pair<int, int> &pos, char mv, int d) { switch (mv) { case U : pos.second += d; break; case D : pos.second -= d; break; case L : pos.first -= d; break; case...
#include <bits/stdc++.h> using namespace std; const long long int mod = 998244353; const long long int INF = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; long long int i, j, k, a, b, flag = 0, m, n, q, sum, x, y, temp = 1, l, r, g, ...
#include <bits/stdc++.h> using namespace std; int main() { string str; while (cin >> str) { int len = str.size(); int times = 0; int c = 0, p = 0; char tmp; for (int i = int(0); i <= int(len - 1); i++) { c = 0, p = 0; tmp = str[i]; if (tmp == C ) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long ans = LONG_LONG_MAX; for (int i = 1; i * i <= n; i++) { ans = min(ans, ((i - 1) + ((n + i - 1) / i) - 1)); } cout << ans << n ; ...
#include <bits/stdc++.h> int* array; int f(int index) { if (array[index] == -1) { array[index] = index; return index; } if (array[index] == index) return index; int r = f(array[index]); array[index] = r; return r; } int main() { int n, m; scanf( %d %d , &n, &m); i...
#include <bits/stdc++.h> using namespace std; const int MM = 2e5 + 34; template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << ( ; os << v.first << , << v.second << ) ; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<...
#include <bits/stdc++.h> using namespace std; long long n, dp[200000]; vector<long long> bit(200000, 0); void update(long long x, long long val) { while (x <= n) { bit[x] ^= val; x += x & -x; } } long long query(long long x) { long long ans = 0; while (x) { ans ^= bit[x]; ...
#include <bits/stdc++.h> using namespace std; const int mxnn = 300000 + 10, inf = 0x3f3f3f3f; int n, q, a, cnt; int head[mxnn], son[mxnn], ans[mxnn], fa[mxnn]; struct node { int u, v, next; } e[mxnn << 1]; void adde(int u, int v) { e[++cnt].u = u; e[cnt].v = v; e[cnt].next = head[u]; h...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int> > v(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> v[i][j]; } } vector<vector<int> > res(n, vector<int>(m)); for (int j = 0; ...
#include <bits/stdc++.h> using namespace std; void move(char b[], int n, int i) { for (int j = i; j < n - 1; ++j) { b[j] = b[j + 1]; } } int main() { int a[10]; char b[101]; char d[101]; int c; int n, q, nd, nn; cin >> n >> q; for (int i = 0; i < n; ++i) { cin >> ...
#include <bits/stdc++.h> using namespace std; const int N = 51; const int mod = (int)1e9 + 7; long long dp0[N][N]; long long dp1[N][N]; long long C[N][N]; inline long long modpow(long long x, long long p) { long long res = 1; while (p) { if (p & 1) res = res * x % mod; x = x * x % mod;...
#include <bits/stdc++.h> using namespace std; int main() { long long int n = 0, temp1 = 0, temp2 = 0; cin >> n; std::vector<long long int> v1; std::vector<long long int> v2; long long int hash1[100001], hash2[100001]; for (long long int i = 0; i < 100001; ++i) { hash1[i] = 0; has...
#include <bits/stdc++.h> using namespace std; long long row[1000], col[1000]; char ch[1000][1000]; list<int> ax, ay; int main() { int i, j, x, y; long long res = 0; cin >> x >> y; memset((row), (-1), sizeof((row))); memset((col), (-1), sizeof((col))); for (i = 0; i < x; i++) { fo...
#include <bits/stdc++.h> using namespace std; int n, L, a; void read() { int x = 0, y = 0, lx = 0, ly = 0, ans = 0; scanf( %d %d %d , &n, &L, &a); for (int i = 0; i < n; i++) { scanf( %d %d , &x, &y); ans += (x - (lx + ly)) / a; lx = x; ly = y; } ans += (L - (x + y)) / ...
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b, long long MOD) { long long res = 1; a %= MOD; for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res; } const int N = 1e5 + 5; double pos[N]; double getExpe(in...
#include <bits/stdc++.h> using namespace std; int const N = 200000; long long const inf = 1e18; int w[N + 1], h[N + 1]; long long dp[N + 1][2]; vector<int> tr[N + 1]; void up(long long &x, long long y) { if (y < x) x = y; } void fn(int v, vector<long long> const &ch, long long s, int in, int out, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n; long long sol(long long* data) { long long ans = 0, fang = 0, sum = 0; for (int i = 1; i <= n; i++) { ans += data[i] * data[i] * (i - 1); ans -= sum * data[i] * 2; ans += fang; fang += data[i] * data[i]...
#include <bits/stdc++.h> using namespace std; struct point { int x, y; point() {} point(int a, int b) { x = a, y = b; } }; template <class T> T sqr(T a) { return a * a; } template <class T> T power(T n, T p) { T res = 1; for (int i = 0; i < p; i++) res *= n; return res; } ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e4; vector<string> pri; string s; int X, n; bool check(string cur) { for (int i = 0; i < cur.size(); i++) { int sum = 0; for (int j = i; j < cur.size(); j++) { sum += cur[j] - 0 ; if (sum < X && X % sum == 0) ret...
#include <bits/stdc++.h> using namespace std; int BIN[30], P[1000005], vis[1000005]; int _bin(int n) { int i, now; for (i = 0; BIN[i] <= n; i++) now = BIN[i]; return BIN[i]; } int main() { int i, j, n, k, now, t; long long ans = 0; for (i = 1, BIN[0] = 1; i < 30; i++) BIN[i] = BIN[i - ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long maxn = 2e5 + 5; long long rowdp[101][101]; vector<long long> a[101]; void f(long long id) { vector<long long> dp(101, 0); for (long long i = 0; i < a[id].size(); ++i) { if (i == 0) dp[i] = a[id...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; int main() { int n, size = 1, arr[200005], arr1[200005]; long long sum = 0; memset(arr, 0, sizeof(arr)); memset(arr1, 0, sizeof(arr1)); cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; if (a...
#include <bits/stdc++.h> using namespace std; int cp(int a, int b) { return a > b; } int main() { int a[55], i, j, k, l, coun, flag; int n; scanf( %d%d , &n, &k); for (i = 1; i <= n; i++) { scanf( %d , &a[i]); } sort(a + 1, a + n + 1, cp); if (k <= n) { for (i = 1; i <= k; ...
#include <bits/stdc++.h> using namespace std; struct point { int x, y; }; int F[500][500]; int x, y; void Init() { F[0 + 200][0 + 200] = 0; F[1 + 200][0 + 200] = 0; F[1 + 200][1 + 200] = 1; F[-1 + 200][1 + 200] = 2; F[-1 + 200][-1 + 200] = 3; for (int i = 2; i <= 110; i++) ...
#include <bits/stdc++.h> using namespace std; const int INF = 100000005; const int p = 31; const int mod = (1 << 8) - 1; char s[200005]; const int siz = 5; struct node { public: int c[5][5]; void out() { for (int i = 0; i < siz; i++) { for (int j = 0; j < siz; j++) { pri...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( -ffloat-store ) #pragma GCC optimize( -fno-defer-pop ) long long int power(long long int a, long long int b, long long int m) { if (b == 0) return 1; if (b == 1) ret...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, c = 0, j = 0, index[3], sum = 0, avg; cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } avg = sum / n; if (avg * n != sum) cout << Unrecoverable configurati...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k, a, b; cin >> n >> k >> a >> b; if (k == 1) { cout << (n - 1) * a << endl; return 0; } long long ans = 0; while (n != 1) { if (n >= k) { ...
#include <bits/stdc++.h> using namespace std; int dcmp(double a, double b) { return fabs(a - b) <= 0.0000000001 ? 0 : (a > b) ? 1 : -1; } int main() { int x1, y1, x2, y2, r1, r2, R1, R2; cin >> x1 >> y1 >> r1 >> R1 >> x2 >> y2 >> r2 >> R2; double dis = sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x...
#include <bits/stdc++.h> using namespace std; int main() { int x[100005], y[100005]; int i, n, d = 0, k = 0, cnt = 0; cin >> n; cin >> x[0] >> y[0]; d = x[0]; k = y[0]; for (i = 1; i <= n; i++) { cin >> x[i] >> y[i]; if (y[i] > y[i - 1]) { k = y[i]; } } ...
#include <bits/stdc++.h> template <class T> inline void chkmax(T &x, const T &y) { if (x < y) x = y; } template <class T> inline void chkmin(T &x, const T &y) { if (x > y) x = y; } template <class T> inline void read(T &x) { char c; int f = 1; x = 0; while (((c = getchar()) < 0 ...
#include <bits/stdc++.h> #pragma GCC optimize(3, inline,Ofast ) using namespace std; int siz[1505], ans[1505], X, Y, n; bool vis[1505]; vector<int> fir[1505]; struct P { int x, y, d; bool operator<(const P& o) const { if (x - X >= 0 && o.x - X <= 0) return 1; if (x - X <= 0 && o.x - X >...
#include <bits/stdc++.h> using ll = long long; const ll LINF = 1e13; using namespace std; namespace ProconLib { template <typename cost_t = long long, bool hasNegativeCost = false, cost_t INF = LINF> class Flow { public: struct Edge { int to; cost_t cap, rev; cost_t cost...
#include <bits/stdc++.h> using namespace std; const int b[2] = {1, -1}; int n, m, f[105][55][205][2], ans; char a[200]; int main() { scanf( %s , a); scanf( %d , &n); f[0][0][0][0] = 1; m = strlen(a); for (int i = (0); i <= (m - 1); i++) for (int j = (0); j <= (n); j++) for (i...
#include <bits/stdc++.h> int main() { char s[100]; scanf( %s , s); int ans = 0; for (int i = 0; s[i]; ++i) { if (isalpha(s[i])) { if (s[i] <= Z ) ans += s[i] - A + 1; else ans -= s[i] - a + 1; } } printf( %d n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { double x, y; cin >> x >> y; double ans = (x * x + y * y) / (x * 2); ans -= x; printf( %.12lf , ans); return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> _edge; set<int> se, to_del; int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int t, n, m, i, j, k, x, y, z, a, b, c; cin >> t; while (t--) { cin >> n >> m; n *= 3; se.clear(); _edge.c...
#include <bits/stdc++.h> using namespace std; bool compare(const int &a, const int &b) { return a < b; } int main() { int n; cin >> n; int i = 0; double aux = 0; while (n >= aux) { aux = (1.0 / 6.0) * (i) * (i + 1) * (i + 2); i++; } cout << i - 2 << endl; return 0; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); multiset<int> b; int c[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { int z; cin >> z; b.insert(z); } for (int i = 0; i < n; i...
#include <bits/stdc++.h> using namespace std; const long long max_n = 2e5 + 100; long long n; vector<pair<long long, long long> > adj[max_n]; long long S[max_n]; vector<long long> G[max_n]; struct Edge { long long x, y, w, idx; Edge() {} Edge(long long x, long long y, long long w, long long id...
#include <bits/stdc++.h> using namespace std; bool func(pair<long long,long long> &fi,pair<long long,long long>&se){ return fi.first<se.first; } int main() { int t=1; cin>>t; while(t--){ long long a,b,n; cin>>a>>b>>n; pair<long long,long long>arr[n]; ...
#include <bits/stdc++.h> using namespace std; int main() { stack<char> Stack; string s; cin >> s; for (int i = 0; i < s.size(); i++) { char ch = s[i]; if (!Stack.empty() && ch == Stack.top()) Stack.pop(); else Stack.push(ch); } if (Stack.empty()) print...
#include <bits/stdc++.h> using namespace std; int number[1003][1003][2]; int n, m, sum; int part = -1; int parts[1000003]; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; string s[1003]; bool isvalid(int x, int y) { if (x >= 0 && x < n && y >= 0 && y < m) return 1; return 0; } int find...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > score; map<pair<int, int>, int> freq; bool compare(const pair<int, int> a, const pair<int, int> b) { if (a.first == b.first) return a.second < b.second; return a.first > b.first; } void solve() { int n, k; cin >> n >> k; ...
#include <bits/stdc++.h> using namespace std; int t[200005]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); string s, ans; int test, n; cin >> test; while (test--) { cin >> s; n = s.length(); for (int i = 1; i <= n; ++i) t[i] = t[i - 1] + s[i - 1] - 0 ; ans = ...
#include <bits/stdc++.h> using namespace std; struct info { int red, yel, chk; } v[1000]; struct info1 { int red, yel, chk; } v1[1000]; int main() { string home, away; cin >> home >> away; int in, n, i, j, time, number; char formation, card; cin >> n; while (n--) { cin ...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; int a[101010]; int dp[1010101]; int main() { int n; while (~scanf( %d , &n)) { for (int i = 0; i < n; i++) scanf( %d , &a[i]); sort(a, a + n); n = unique(a, a + n) - a; int b, c; scanf( %d%d ...
#include <bits/stdc++.h> using namespace std; struct node { int l, m, r; }; node t[3000005]; int arr[300005], n, m; long long a[300005]; int sign(long long x) { if (x > 0) return 1; if (x < 0) return -1; return 0; } void cal(int x, int l, int r) { int m = (l + r) / 2; t[x].m = ...
#include <bits/stdc++.h> using namespace std; int N, cnt[100010], beg_cnt[100010]; double ans = 0, dp[100010][110], buf[110]; int main() { scanf( %d , &N); for (int i = 0; i < N; ++i) { scanf( %d , &cnt[i]), dp[i][cnt[i]] = 1; beg_cnt[i] = cnt[i]; if (cnt[i] == 0) ++ans; } int ...
#include <bits/stdc++.h> using namespace std; const int maxx = 2e5 + 10; long long arr[maxx + 5]; int main() { long long n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { long long x; cin >> x; arr[i] = x + arr[i - 1]; } long long lag = 0, best = 0, x, y, ans; for (in...
#include <bits/stdc++.h> using namespace std; const int N = 400010; char ss[N], s[N]; int fail[N], trie[N][30]; struct node { int v, next; } e[N]; int n, opt, m, dfsclock, id, siz[N], tree[N], fa[N], dfsxu[N], ans[N], head[N], cnt, tot; void add(int u, int v) { e[++cnt].v = v; e[cnt].n...
#include <bits/stdc++.h> using namespace std; const long long mod1 = 1000000007; const long long mod2 = 998244353; mt19937 rng( (unsigned int)chrono::steady_clock::now().time_since_epoch().count()); long long power(long long a, long long b) { long long result = 1; while (b > 0) { if (b % 2...
#include <bits/stdc++.h> using namespace std; int T, sum = 0; string a, b; int main() { cin >> T; while (T--) { int temp = 0, flag = 0; cin >> a; cin >> b; int k = 0; int LA = a.size(); int LB = b.size(); for (int i = 0; i <= LA; i++) { if (flag == 0 && ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i, u, v, w = 0, l = 0; scanf( %d%d , &n, &k); for (i = 1; i <= k; ++i) scanf( %d%d , &u, &v), w = (w + u * 1ll * v) % n, l += v; if (l < n) puts( 1 ); else if (l > n) puts( -1 ); else if ((1ll + n) * n / 2...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 10; char a[maxn], b[maxn], t[maxn]; int main() { int n; char c[1]; scanf( %d , &n); gets(c); scanf( %s , a + 1); int d = 0; while (d <= n) { d++; if (n % d == 0) { for (int i = 1; i <= d; i++) { ...
#include <bits/stdc++.h> using namespace std; const long long N = (long long)(5e5) + 322; const long long INF = (long long)(1e9); const long long mod = (long long)(1e9) + 7; const double eps = 1e-9; int xp, yp, xv, yv, distp, distv; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); c...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; long long arr[36] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64...
#include <bits/stdc++.h> using namespace std; void pb_200() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { long long int x; cin >> x; while (x--) { long long int n; cin >> n; long long int *arr = new long long int[n]; ; for (long...
#include <bits/stdc++.h> int a[1005][1005]; int n; void solve(int x) { for (int flag = 0; flag < n; flag++) { if (a[x][flag] == 0) { for (int flag1 = flag; flag1 < n; flag1++) { a[x][flag1] = a[x][flag1 + 1]; } break; } } } int main() { while (scanf( %...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf( %d , &n) != EOF) { int m = n * 2 - 1; printf( %d 2 n , m); printf( 1 2 n ); } }
#include <bits/stdc++.h> using namespace std; long long fact[(long long)(1e6 + 10)], mod_inv[(long long)(1e6 + 10)]; long long _pow(long long a, long long n) { if (n == 0) return 1; if (n % 2 == 1) return (a * _pow(a, n - 1)) % (long long)(1e9 + 7); long long x = _pow(a, n / 2) % (long long)(1e9 + 7);...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while (T--) { int n, m, k; cin >> n >> m >> k; vector<vector<int>> G(n + 1); vector<int> deg(n + 1); for (int i = 1; i <= m; i++) { int x, y;...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 100100; int n; int deg[N]; int main() { scanf( %d , &n); for (int i = 1; i < n; i++) { int v, u; scanf( %d%d , &v, &u); v--; u--; deg[v]++; ...
#include <bits/stdc++.h> using namespace std; int cal(long long n) { int sum = 0; string s = to_string(n); for (int i = 0; i < s.size(); i++) { sum = sum + (s[i] - 0 ); } return sum; } int main() { long long n; cin >> n; if (n < 9) { cout << n << endl; return 0...
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &a, T b) { return (a < b) ? a = b, 1 : 0; } template <typename T> bool chkmin(T &a, T b) { return (a > b) ? a = b, 1 : 0; } inline int read() { int x = 0, fh = 1; char ch = getchar(); for (; !isdigit(ch...
#include <bits/stdc++.h> using namespace std; int tree[4000009][3]; int a[1000009]; void init(int node, int b, int e) { if (b == e) { tree[node][a[b]] = 1; tree[node][1 - a[b]] = 0; tree[node][2] = 0; return; } int mid = (b + e) / 2; int left = node * 2; int right = n...
#include <bits/stdc++.h> using namespace std; long long int n, tmp; long long int k, c = 0; list<int> game; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> tmp; game.push_back(tmp); } while (*game.begin() != n) { if (*game.begin() > *(++game.begin())) { ...
#include <bits/stdc++.h> using namespace std; char s[200003]; long long k; struct pos { char c; int nom; }; pos a[100003]; pos b[100003]; pos c[100003]; void mergesort(pos *a, pos *b, int n) { int i, i1, i0, iRight, iEnd, width, j; for (width = 1; width < n; width *= 2) for (i = ...
#include <bits/stdc++.h> using namespace std; int n; int a[200001]; int b[200001]; int main() { cin >> n; int tong = 0; int i; for (i = 1; i <= n; i++) cin >> a[i], tong += a[i]; int k = 1; i = 1; bool ok = true; while (i <= n) { if (tong % n == 0 && a[i] == tong / n) { ...
#include <bits/stdc++.h> using namespace std; struct SEG { int segment_length; char chars; }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; string s; cin >> s; SEG cur; vector<SEG> st; cur.segment_length = 0; cur.chars = - ; for (char x...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, s, min, max, l, r; cin >> n; s = pow(n, 2); long long int v[s + 1]; for (long long int i = 0; i < s; i++) { v[i] = i + 1; } for (long long int i = 0; i < n; i++) { l = i; r = n - 1; if (n ...
#include <bits/stdc++.h> using namespace std; void solve() { string n; int s; cin >> n >> s; int sum = 0; vector<int> digit; for (int i = 0; i < (int)n.size(); i++) { digit.push_back(n[i] - 0 ); sum += digit[i]; } if (sum <= s) { cout << 0 << n ; return; ...
#include <bits/stdc++.h> using namespace std; using LL = long long; using LD = long double; void err() { cerr << 033[39;0m << endl; } template <typename T, typename... A> void err(T a, A... x) { cerr << a << ; err(x...); } const int N = 1e6 + 10; struct Node { map<int, Node*> link; ...
#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; int main() { int tc, i, j, k, cs = 1, m, n, ans; { scanf( %d%d , &m, &n); if (n > m) swap(m, n); if (n == 1) ans = m; else if (n == 2) { ans = (m / 4) * 4; if (m % 4 == 1) ans += 2; else if (m % 4...
#include <bits/stdc++.h> using namespace std; int n; long long dp[210][210]; struct point { long long x, y; void read() { scanf( %I64d%I64d , &x, &y); } } P[210]; long long cross(point a, point b, point c) { return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); } int main() { lon...
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b) { long long res = 1; a %= 1000000007; for (; b; b >>= 1) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; } return res; } long long gcd(long long x, long long y) { while (...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int q = 0; q < t; q++) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int moves = 0; int max_size = 0; int alice = 0, bob = 0; while (a.size() !...