func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } void solve() { int n; cin >> n; vector<int> a(2 * n); for (int i = 0; i < 2 * n; i++) { cin >> a[i]; } int din = 0; for ...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); const double EPS = 1E-6; const int INF = 2 * (1e+9) + 1; const int MAXN = 3 * 100000001; const int MOD = (1e+9) + 7; int n, m; map<int, int> m1, m2; map<int, int> u, cnt; int main() { cin >> n; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; vector<vector<pair<string, int>>> adl; vector<int> dist(2000, inf); map<pair<string, int>, int> nums; map<string, pair<int, int>> mins; void bfs(string& poly, int version) { vector<string> order; order.push_back(poly); mins...
#include <bits/stdc++.h> using namespace std; using nagai = long long; const int N = 100; int matr[N][N]; const int K = 12; int de[N][K]; const int oo = 0x3f3f3f3f; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(false); cin.tie(0...
#include <bits/stdc++.h> const int mod = 1000000007, maxn = 200005, maxk = 105; int n, m; int a[maxn], fac[maxn], nfac[maxn], inv[maxn], sum[maxn][maxk]; inline int C(int a, int b) { return 1ll * fac[a] * nfac[b] % mod * nfac[a - b] % mod; } int main() { fac[0] = fac[1] = nfac[0] = nfac[1] = inv[1] ...
#include <bits/stdc++.h> using namespace std; const long long N = 500010; long long n, sx, sy, x, y, res[6]; int main() { scanf( %lld , &n); scanf( %lld%lld , &sx, &sy); for (int i = 0; i < n; i++) { scanf( %lld%lld , &x, &y); if (x < sx) res[1]++; if (y < sy) res[2]++; if (x...
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return (a > b ? a = b, true : false); } template <class T> bool uax(T &a, T b) { return (a < b ? a = b, true : false); } int const X = 8; int const L = 26; int const N = 41; long long const INF = 3e18 + ...
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 2; int n, m; void solve() { string n, m; cin >> n >> m; sort((n).begin(), (n).end()); if (n[0] == 0 && n.size() > 1) swap(n[0], n[1]); if (n == m) cout << OK << endl; else cout << WRONG_ANSWER << endl; ...
#include <bits/stdc++.h> using namespace std; map<int, long long> ans, re, now; int n, h[200005], tot, mp[200005], siz[200005], mz[200005], rem[200005], cnt; bool vis[200005]; struct DX { int v, p; } dx[400005]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } void add(int u, int v) { dx[...
#include <bits/stdc++.h> using namespace std; int main() { int m; cin >> m; for (int i = 1; i <= m; i++) { if ((i * (i + 1)) / 2 == m) { cout << YES << endl; return 0; } if ((i * (i + 1)) / 2 > m) { cout << NO << endl; return 0; } } ret...
#include <bits/stdc++.h> using namespace std; const int MAXN = 150000 + 50; int n, m, h, vec[MAXN], sec[MAXN], ans, need[4 * MAXN], ex[4 * MAXN]; void plant(int v, int b, int e) { need[v] = e - b; if (e - b == 1) return; int mid = (b + e) / 2; plant(v << 1, b, mid); plant(v << 1 ^ 1, mid, e)...
#include <bits/stdc++.h> using namespace std; int n, k; char s[200]; char p[200]; char ans[200]; bool used[200][30]; bool brute(int pos) { if (pos == n) { puts(ans); exit(0); } if (ans[pos] != 0) { if (pos >= strlen(s) - 1) { if (p[pos - strlen(s) + 1] == 0 ) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (k > n) { cout << -1 ; return 0; } if (n == 1) { cout << a ; return 0; } if (n > 1 && k == 1) { cout << -1 ; return 0; } string str; char c1 = a , c2...
#include <bits/stdc++.h> using namespace std; int n, m, dfsCont, dfs_num[2005], dfs_low[2005], numComp; vector<vector<int> > lista; string ans[2005]; vector<int> pila, comp; map<string, int> names; bool vis[2005]; void tarjan(int u) { dfs_low[u] = dfs_num[u] = dfsCont++; vis[u] = 1; pila.pus...
#include <bits/stdc++.h> using namespace std; template <typename X> void MA(X &a, X b) { a = max(a, b); } template <typename X> void MI(X &a, X b) { a = min(a, b); } int DEBUG = 0, MULTI = 0, GCJ = 0; struct solver_t; solver_t *solver; struct solver_t { vector<int> A; vector<vector...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long INFLL = 1e18 + 1; const int MAX = 100001; const long long MOD = 1000000007; const int SZ = 300100; const double PI = 3.14159265358979323846264338327; long long inq(long long k, long long q, long long mod) { if (q == 0...
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; vector<string> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int ans = 1 << 30; for (int k = 2; k < 100; k++) { int nn = (n + k - 1) / k * k; int nm = (m + k - 1) / k * k; v...
#include<bits/stdc++.h> #define int long long using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin>>t; while(t--) {int n,k; cin>>n>>k; int ok=1; int poss=0; for(int i=0;i<n-1;i++) {ok=ok*2; if(ok>=k){poss=1;break;}...
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; int ans = 0; int csize[100005]; int dfs(int u, int fa) { csize[u] = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (v == fa) continue; dfs(v, u); csize[u] += csize[v]; if (csize[v] % 2 ==...
#include <bits/stdc++.h> using namespace std; int n, m, s[105][105]; int main() { int i, j, x, y; scanf( %d , &n); for (i = 3; i <= 102; i++) { m = (i * (i - 1) * (i - 2)) / 6; if (m > n) break; } i--; memset(s, 0, sizeof(s)); for (y = 1; y <= i; y++) for (x = 1; x <=...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 11; const long long MOD = 1e18; long long a[N], b[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long x, y, l, r; cin >> x >> y >> l >> r; vector<long long> v; long long k = 1, kk = 1; ...
#include <bits/stdc++.h> int main(void) { int b_cost, money, b_number; scanf( %d %d %d , &b_cost, &money, &b_number); int total_cost; int loan = 0; total_cost = b_cost; for (int i = 2; i <= b_number; i++) { total_cost += i * b_cost; } if (money < total_cost) { loan = total_...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const long long mod = 1e9 + 7; struct node { int s, e, next; } edge[maxn]; int head[maxn], len; void add(int s, int e) { edge[len].e = e; edge[len].next = head[s]; head[s] = len++; } void init() { memset(head,...
#include <bits/stdc++.h> using namespace std; int main() { int n, d, h, i; cin >> n >> d >> h; if (h == 1) { if (d == 1 && n == 2) { cout << 1 << << 2 << n ; } else if (d == 2) { for (i = 1; i < n; i++) cout << 1 << << i + 1 << n ; } else { cout << ...
#include <bits/stdc++.h> using namespace std; long long a[200100], sum[200100], qs[200100]; bool bad(pair<long long, long long> &a, pair<long long, long long> &b, pair<long long, long long> second) { return (a.second - second.second) * (b.first - a.first) > (a.second - b.second) * (secon...
#include <bits/stdc++.h> using namespace std; int m, n, nums[1010][35], P[1010] = {0}, nCr[1010][1010], basis[1010][35], sz = 0, pivots[1010]; char buf[1010]; int main() { int mask = 0x1F, shift = 5; scanf( %d%d , &m, &n); for (int i = 0; i < n; i++) { scanf( %s , b...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, t = 0, c = 0; cin >> a >> b; t += a; while (b <= a) { c = a % b; a /= b; t += a; a += c; } cout << t << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const long long INFLL = 1000000000000000000LL; const int MAXN = 200009; int m, x; vector<int> weights; stack<int> order; void print() { if (order.empty()) return; int x = order.top(); order.pop(); print(); cout...
#include <bits/stdc++.h> int N, head[51], next[99], from[99], to[99], len[99], E, root, M, q[51], fa[51], count_e[99], f[51][99][51], vi[51][99]; void BFS() { int H = 0, T = 1, u; q[1] = root; while (H < T) for (int e = head[u = q[++H]]; e; e = next[e]) if (to[e] != fa[u]) fa[q[++T] ...
#include <bits/stdc++.h> const int mxn = 100000 + 10; using namespace std; string s; string soln; int main() { cin >> s; int n = s.size(); for (int i = 0; i < n; i++) if (s[i] == . ) printf( 0 ); else { if (s[i + 1] == - ) printf( 2 ); else ...
//CLOCKS_PER_SEC using namespace std; #include<bits/stdc++.h> #define sqr(x) 1ll*(x)*(x) //#define sort stable_sort #define ll long long #define mk make_pair #define pb push_back #define in insert #define mtr(x,y,z) mk(mk(x,y),z) #define fi first #define se second #define lch(x) ((x)<<1) #defi...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); int main() { long long n; cin >> n; unsigned long long p = 1; unsigned long long sq = (unsigned long long)(sqrt(n + 0.0) + eps + 1); bool was = fa...
#include <bits/stdc++.h> using namespace std; int main() { long long t1, n, zero, one, cnt, cnt1, i, j; string s; cin >> t1; while (t1--) { cin >> n; cnt = 0, zero = 0, one = 0; for (i = 0; i < n; i++) { cin >> s; for (j = 0; j < s.length(); j++) { if (s[j...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; long long a[n], b[n]; for (long long i = 0; i < n; i++) { cin >> a[i] >> b[i]; } for (long long i = 0; i < n; i++) { if (a[i...
#include <bits/stdc++.h> using namespace std; long long int Mmax(long long int a, long long int b) { if (a > b) return a; return b; } long long int Mmin(long long int a, long long int b) { if (a < b) return a; return b; } long long int nod(long long int a, long long int b) { while (a && ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s1, s2; cin >> s1 >> s2; int flag = 0; if (n % 2 != 0) flag = 1; int mid; if (flag) mid = (n + 1) / 2; else mid = n / 2; int cnt = 0; for (int i = 0; i < n / 2; i++) { int...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int a[205]; cin >> n >> k; for (int i = 0; i < 2 * n + 1; i++) { cin >> a[i]; } for (int i = 2 * n - 1; k != 0; i--) { if (a[i] > a[i + 1] + 1 && a[i] > a[i - 1] + 1) { a[i]--; k--; } }...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int isprime[1010]; int mp[256]; int main() { isprime[0] = isprime[1] = 1; for (int i = 2; i <= 1000; i++) if (!isprime[i]) for (int j = i * 2; j <= 1000; j += i) isprime[j] = 1; char s[1100], str[1010]; sca...
#include <bits/stdc++.h> using namespace std; template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } inline int read() { int s = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != - ) ch ...
#include <bits/stdc++.h> using namespace std; const int N = 35000, K = 50; struct seg_node { seg_node *lc, *rc; int l, r, f, m; seg_node(seg_node *lc, seg_node *rc, int l, int r) : lc(lc), rc(rc), l(l), r(r), f(), m() {} static seg_node *build(int l, int r) { if (l == r - 1) return n...
#include <bits/stdc++.h> using namespace std; int n; int a[222222]; set<int> s; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { s.insert(i); } for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); if (a[i] != 0) { s.erase(a[i]); } } int idx = n...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long ans = 0; int t = n; for (int i = 2; i * i <= t; ++i) { while (n % i == 0) { ans += n; n /= i; } } ans += n == 1 ? 1 : n + 1; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int freq[101]; int main() { int n, x, max = 0, count = 0; cin >> n; string s; if (n == 1) { cin >> s; sort(s.begin(), s.end()); for (int i = 0; i < s.length(); i++) { if (s[i] == s[i + 1]) count++; } cout << count ...
#include <bits/stdc++.h> using namespace std; const int AND = 0; const int OR = 1; const int NAND = 2; const int NOR = 3; const int N = 111; int n, m, k; string s; int a[N][3]; int b[N][3]; vector<int> g[N]; bool st[N]; int ord[N]; int ordSz; int col[N]; int C; bool used[N]; bool old...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const signed long long int LINF = LLONG_MAX; const double EPS = 1e-9; const int MOD = 1000000007; const int MAXN = 100001; const int ALPH = 26; const int DALPH = 52; string s; vector<int> z; vector<pair<int, int> > ans; vecto...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> xx(n); vector<int> yy(n); vector<int> diff(n); for (int i = 0; i < n; i++) { string s; cin >> s; xx[i] = count(s....
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; const int INF = 1000000000; int n, m, numV; int head[MAXN], e_cnt, s, t; bool volunt[MAXN]; struct Edg { int v, next; } edg[MAXN * 4]; inline void add(int a, int b) { edg[e_cnt].v = b; edg[e_cnt].next = head[a]; hea...
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int> > edges; vector<int> conn[201]; bool v1[201], v2[201]; int mx = 0; void setEdge(int a, int b, int v) { for (int s = 0; s < conn[a].size(); s++) { if (conn[a][s] == b || conn[a][s] == -1) conn[a][s] = (v == 1 ? b : -1); ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector< ll > vl; typedef vector< vector< ll > > vvl; #define ff first #define ss second #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define pb push_back #define all(c) c.begin(), c.end()...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(); cin.tie(); cout.tie(); int n; cin >> n; int weight[n]; for (int i = 0; i < n; ++i) cin >> weight[i]; int p; cin >> p; vector<pair<pair<int, int>, int> > data; for (int i = 0; i < p; ++...
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include<time.h> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <stdio.h> #include <deque> #include ...
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 5; int a[maxn], dp[maxn]; int n, k; bool ok_hack(int x) { memset(dp, 0, sizeof(dp)); int last = 0; for (int i = k; i <= n; i++) { if (a[i] - a[dp[i - k] + 1] <= x) last = i; dp[i] = last; } return dp[n] == ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,abm,mmx,tune=native ) using namespace std; const int64_t INF = (int64_t)(2e18); const int maxn = 500 * 1000 + 100; chrono::time_point<chrono::steady_clock> cl; double curre...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<ll, ll>; int main() { char rep[256], a[256], b[256], d[256]; while (scanf( %[0-9].%[0-9]e%[0-9] n , a, d, b) == 3) { auto len = strlen(d); if (b[0] == 0 ) { if (len == 1 and d[0] == 0 ) pr...
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; map<long long, long long> m...
#include <bits/stdc++.h> using namespace std; struct node { int x, h, id; } a[100005]; int n, i, j, f[100005], ans[100005]; bool cmp(node x, node y) { if (x.x != y.x) return x.x < y.x; else return x.h < y.h; } int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { s...
#include <bits/stdc++.h> using namespace std; int main() { map<char, int> ma; char a; int b; cin >> b; for (int i = 0; i < b; i++) { cin >> a; ma[a]++; } for (auto i : ma) for (int j = 0; j < i.second; j++) cout << i.first; }
#include <bits/stdc++.h> using namespace std; double x; int N, M, ar[5005], res; int dn[5005]; int main() { scanf( %d %d , &N, &M); for (int i = 0; i < N; i++) { scanf( %d %lf , &ar[i], &x); ar[i]--; } for (int i = 0; i < N; i++) { for (int j = ar[i]; j >= 0; j--) { d...
#include <bits/stdc++.h> const int MN = 1e3 + 10; const int K = 20; int N, M, T, id[MN], t[MN], ctr, m[1 << K]; bool conn[MN][MN]; char s[10]; std::vector<int> a[MN], on[K + 1]; struct Mod { public: char c; int a, b; void out() const { printf( %c %d %d n , c, a, b); } }; std::vector<Mod...
#include <bits/stdc++.h> using namespace std; long long n; long long b[500010], a[500010]; void solve() { cin >> n; for (int i = 0; i < n; i++) cin >> b[i]; long long sum = 0, flag = 1; for (int i = 0; i < n; i++) sum += b[i]; if (sum % (n * (n + 1) / 2)) flag = 0; sum /= n * (n + 1) / 2...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5; const int INF = 1e9; int n; int ct[MAXN][2]; vector<int> ok(int d) { vector<int> bad(2, -1); int loX = 0, hiX = INF; int loY = 0, hiY = INF; int loD = -INF, hiD = INF; for (int i = 0; i < n; i++) { int x = ct[i][0]...
#include <bits/stdc++.h> using namespace std; const int N = 205, M = N * N; using ll = long long; int n, a[N][N]; struct Edge { int v, nxt; ll w, cw; } e[M << 2]; int head[M], ptr; void add_edge(int uu, int vv) { e[ptr] = {vv, head[uu], 1, 0}; head[uu] = ptr++; e[ptr] = {uu, head[vv]...
#include <bits/stdc++.h> using namespace std; int main() { string A, B; int ma = 0; cin >> A >> B; for (char &ch : A) ma = max(ma, ch - 0 ); for (char &ch : B) ma = max(ma, ch - 0 ); ma++; int a = 0, b = 0; for (char &ch : A) { a = a * ma + ch - 0 ; } for (char &ch :...
#include <bits/stdc++.h> using namespace std; int n, m, ar[11][100005]; int rev[11][100005]; long long mx(int start) { int val = ar[0][start]; for (int tmp = 0; tmp < n; ++tmp) { for (int row = 1; row < m; ++row) { int col = rev[row][val]; if (col + tmp >= n) { return tmp...
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 5, mod = 998244353; vector<int> num; long long A[N]; int a[N]; long long sumup = 0, sumdown = 0; long long qpow(long long a, long long b) { long long c = 1; while (b) { if (b & 1) c = (a * c) % mod; b >>= 1; a = (a...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } x *= f; } const int N = ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int n, m, q; long long add[510], a[510][510], dp[510][510], gox[510][510], goy[510][510]; vector<pair<int, int> > vx[510][510], vy[510][510]; int main() { scanf( %d%d%d , &n, &m, &q); for (int i = 0; i < q; i++) { int x,...
#include <bits/stdc++.h> int main() { int h, w, bh, bw, th, tw; long long ar, ba; bh = bw = ba = 0; scanf( %d %d , &h, &w); int tmp; for (int i = 30; i >= 0; i--) { tmp = (1 << i); if (tmp <= w) { long long x = (long long)tmp * 8; long long y = (long long)tmp * 125;...
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2; int main() { scanf( %d%d%d%d%d%d , &r1, &r2, &c1, &c2, &d1, &d2); for (int i = 1; i <= 9; ++i) for (int j = 1; j <= 9; ++j) for (int ii = 1; ii <= 9; ++ii) for (int jj = 1; jj <= 9; ++jj) { if (i ...
#include <bits/stdc++.h> using namespace std; double a[100010], ans1, ans2; int n, n1, n2; bool cmp(double a, double b) { return a > b; } int main() { scanf( %d%d%d , &n, &n1, &n2); if (n1 > n2) swap(n1, n2); for (int i = 1; i <= n; i++) scanf( %lf , &a[i]); sort(a + 1, a + n + 1, cmp); fo...
#include <bits/stdc++.h> using namespace std; map<long long, long long> bismarck, dp; long long n; void factorization(long long x) { for (long long i = 2; i * i <= x; i++) { if (x % i == 0) { long long c = 0; while (x % i == 0) { c++; x /= i; } dp[i]...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long res = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { res = res * 10 + c - 48; c = getchar(); } retur...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int A, B; cin >> A >> B; string a, b; cin >> a >> b; int p = 0, m = a.size(); for (int i = 0; i + a.size() <= b.size(); i++) { int k = 0; for (int j = 0; j < a.size(); j++) { if (a[j] != b[...
#include <bits/stdc++.h> using namespace std; long long a, b, n, m, k, l; int main() { ios_base::sync_with_stdio(false); cin.tie(); cin >> n >> m >> k >> l; if ((n / m) * m < k + l) { cout << -1 n ; return 0; } cout << (k + l) / m + ((k + l) % m != 0) << endl; return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int temp, sum = 0; int size, counter = 0; cin >> size; for (int i = 0; i < size; i++) cin >> temp, sum += temp; if (sum % size == 0) cout << size << endl; else cout << size - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, Execution time: %.3lf s. n , (double)clock() / CLOCKS_PER_SEC); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 * 1000; int n, m; int ar1[maxn]; int ar2[maxn]; void read(); int main() { read(); int i, j; int s1, s2; int file; i = j = s1 = s2 = file = 0; while (i < n) { if (s1 == 0) s1 += ar1[i++]; else { ...
#include <bits/stdc++.h> using namespace std; long long qpow(long long a, long long k) { long long b = 1LL; while (k) { if (k % 2 == 1) b = (b * a) % 1000000007; a = (a * a) % 1000000007; k = k / 2; } return b; } int main() { char s[105] = {0}; scanf( %s , s); int l...
#include <bits/stdc++.h> using namespace std; int n, x, y, u, v, to[600005], nxt[600005], p[300005], sz[300005]; void dfs(int x, int lst) { sz[x] = 1; for (int i = p[x]; i != -1; i = nxt[i]) if (to[i] != lst) { dfs(to[i], x); sz[x] += sz[to[i]]; } } int main() { scanf( ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int maxn = 100; const int MAXN = 2750131; long long T, n, m, i, j; long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); } long long g[200005]; int main() { ios::sync_with_stdio(false); long lo...
#include <bits/stdc++.h> int x1, x2, x3, y11, y2, y3, length; int main() { scanf( %d %d %d %d %d %d , &x1, &y11, &x2, &y2, &x3, &y3); length = (int)(sqrt(x1 * y11 + x2 * y2 + x3 * y3) + 0.01); if (x1 * y11 + x2 * y2 + x3 * y3 != length * length) { printf( -1 n ); return 0; } if (x1 <...
#include <bits/stdc++.h> using namespace std; const int N = 2e3; bool possible, check[N << 2], mark[N << 2]; vector<int> topol, from[N << 2], to[N << 2]; int n, m, c, d[N], com[N << 2], row[N], col[N], a[N][N], b[N][N]; void dfs_scc(int u, int c) { com[u] = c; mark[u] = true; for (auto v : to[u]...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); int index1 = 0; int index2 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) index1 = i + 1; else if (a[i] == n) index2 = i + 1; } int ans = ma...
#include <bits/stdc++.h> using namespace std; double eps(1e-10); int sign(const double& x) { return (x > eps) - (x + eps < 0); } bool equal(const double& x, const double& y) { return x + eps > y && y + eps > x; } struct Point { double x, y, z; Point() {} Point(const double& x, const double& ...
#include <bits/stdc++.h> using namespace std; struct Node { int idx, sum; int left, right; } tree[3000000]; int cnt; long long sumVal; char ch[10]; void addNode(int cur, int def, int h, int val) { if (tree[cur].idx == def) { tree[cur].sum += val; return; } tree[cur].sum += ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; char a[65]; void pre() { int j = 1; for (j = 1; j <= 10; j++) a[j - 1] = (char)(j - 1 + 48); for (int i = 0; i < 26; i++) a[j++] = (char)(i + 97); for (int i = 0; i < 26; i++) a[j++] = (char)(i + 65); a[10] = Z ; } int...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 4; const int M = 1e9 + 7; vector<pair<int, int> > g[N]; const int inf = 1e9 + 10; vector<int> dist(N, inf); void dijkstra(int source) { dist[source] = 0; set<pair<int, int> > s; s.insert({0, source}); while (!s.empty()) { ...
#include <bits/stdc++.h> using namespace std; long long int to_reach(long long int number, long long int moves, long long int target) { if (target == 0) { return (number / moves); } else { long long int res = (target - number) / moves; return res; } } int m...
#include <bits/stdc++.h> #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( O3 ) #pragma GCC target( avx ) const long long MOD = 1000000007; const long double PI = 3.1415926535898; const l...
#include<iostream> using namespace std; int main() { int t; cin>>t; while(t--){ int a,b; cin>>a>>b; if(a==0&&b==0) cout<< 0 n ; else if(a==0&&b!=0) cout<<2*b-1<<endl; else if(a!=0&&b==0) cout<<2*a-1<<endl...
#include <bits/stdc++.h> using namespace std; bool comp(const vector<int> &l, const vector<int> &r) { if (l[0] % 2 && r[0] % 2) { return l[1] < r[1]; } if ((l[0] % 2) && (r[0] % 2 == 0)) return true; if ((l[0] % 2 == 0) && (r[0] % 2)) return false; else return true; } int m...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const int N = 105; const int M = 5005; long long dp[N][M]; int x[N]; int y[N]; long long c[M][N]; int sum[N]; int rSum[N]; int h[N]; int main() { int n, i, j, k, l; long long ans = 0; scanf( %d , ...
#include <bits/stdc++.h> using namespace std; long long dp[1005][1005], sum[1005][1005], c[2 * 1005][2 * 1005]; long long res[55][1005], p[55]; int main() { dp[0][0] = 1; for (int i = 0; i < 1005; i++) sum[0][i] = 1; for (int i = 1; i <= 51; i++) { for (int j = 1005 - 1; j >= 1; j--) { ...
#include <bits/stdc++.h> using namespace std; int *s; int fenzhi(int left, int right, int d) { int mins = 0x3f3f3f3f; ; for (int i = left; i <= right; i++) mins = min(mins, s[i] - d); int ans = 0; for (int i = left; i <= right; i++) if (s[i] > mins + d) { int j = i; while...
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; for (int i = 0; i < a.length(); i++) { if (isupper(a[i])) a[i] = tolower(a[i]); } string s = ; for (int i = 0; i < a.length(); i++) { if (a[i] == a || a[i] == o || a[i] == u || a[i] == e || ...
#include <bits/stdc++.h> using namespace std; int a[112], dp[312][312], mnix[312]; int **func(int **mat1, int **mat2, int mx) { int **ans; ans = new int *[mx + 2]; for (int i = 1; i <= mx; i++) { ans[i] = new int[mx + 2]; for (int j = 1; j <= mx; j++) { ans[i][j] = 0; for (...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> v(n + 1); long long s = 0; for (long long i = 1; i <= n; i++) { cin >> v[i]; s += v[i] - i, v[i] = i; } for (long long i = 1; i <= n; i++) v[i] += s / n; for (long long i...
#include <bits/stdc++.h> using namespace std; vector<long long> q; long long i, j, n, k, m = 1000000007, ww = 1, a[20005], b[20005], c[20005], w[20005]; bool flag; bool otv(int n, bool sign) { long long t = n; for (long long j = 0; j < q.size(); j++) { if (t % q[j] == 0) ...
#include <bits/stdc++.h> using namespace std; struct circle { long double x, y, r; }; struct mod { long double theta, op; }; struct node { long double x, y, theta; }; int n, d, i, j, tot, S, ans, gg; circle c[20005]; mod l[2000005]; node A, B; long double D, k, t, L, R, dis1, dis2, d...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a; for (int i = (0); i < (n); i++) { int t; cin >> t; a.push_back(t); } vector<int> b; for (int i = (0); i < (n); i...