func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; int N; long long A[MAXN + 10], B[MAXN + 10], S; vector<long long> prime; int main() { long long i, j; scanf( %d , &N); for (i = 1; i <= N; i++) scanf( %d , &A[i]), S += A[i]; for (i = 2; i * i <= S; i++) { if (S % i ==...
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; struct Segment { int l, r; int id; bool operator<(const Segment &o) const { return l < o.l; } } a[maxn]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { scanf( %d %d , &a[i].l, &a[i].r); ...
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int inf = 1e9 + 7; void solve() { long long int n, m; cin >> n >> m; vector<vector<long long int> > v(n, vector<long long int>(m)); long long int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++)...
#include <bits/stdc++.h> using namespace std; const int N = 300005; const int mod = 998244353; int n; long long a[N], b[N], c[N], k, ans = 2e15; inline long long qpow(long long a, long long b, long long m) { long long ans = 1ll; for (; b; b >>= 1, a = a * a % m) if (b & 1) ans = ans * a % m; ...
#include <bits/stdc++.h> using namespace std; struct node { int a, b; node(int a = 0, int b = 1e9) : a(a), b(b) {} int get(int x) { return a * x + b; } }; struct Eins { vector<node> st; int n; Eins(int n) : n(n) { st.resize(n << 2 | 1); } void modify(int id, int l, int r, node v) { ...
#include <bits/stdc++.h> using namespace std; char buf[(1 << 22)], *p1 = buf, *p2 = buf; inline int read() { char c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 22, stdin), p1 == p2) ? EOF : *p1++); int x = 0, f = 1; while (c< 0 | c> 9 ) { if (c == - ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010, maxs = 200010; const int inf = 2000000000; int n, m, ecnt; pair<int, int> edges[maxs]; bool dat[maxn]; int c[maxn]; int pos[maxn], last[maxn], nowt; vector<pair<int, int> > ga[maxn]; vector<int> weight[maxn]; void insertunit(in...
#include <bits/stdc++.h> int main() { int n, i; int a[100000]; double sum = 0; int sum1 = 0, sum2 = 0; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a[i]); sum += a[i]; } sum = sum / n; for (i = 0; i < n; i++) { if (sum - a[i] > 0) sum1 += fabs(s...
#include <bits/stdc++.h> using namespace std; const int maxn = 3007; const int w = 31; int n, m, q, d[maxn][maxn >> 4], o[maxn][maxn >> 4], sm[maxn]; set<pair<int, int> > s; set<pair<int, int> > valid; vector<int> val[maxn]; int gd(int n) { int ans = 0; while (n) { ans += n & 1; n >>...
#include <bits/stdc++.h> using namespace std; long long dx[8] = {-1, 1, 0, 0, 1, -1, 1, -1}; long long dy[8] = {0, 0, -1, 1, 1, -1, -1, 1}; void solve() { long long n, m; cin >> n >> m; char a[n][m]; for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) cin >> a[i][j]; ...
#include <bits/stdc++.h> using namespace std; map<int, int> moebius(int n) { map<int, int> res; vector<int> primes; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { primes.push_back(i); while (n % i == 0) n /= i; } } if (n != 1) primes.push_back(n); int m = pr...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; scanf( %d%d%d , &n, &a, &b); printf( %d n , ((a - 1) + b + 100 * n) % n + 1); return 0; }
#include <bits/stdc++.h> using namespace std; string grid[60]; int main() { cin.tie(0); ios::sync_with_stdio(0); int t; cin >> t; int r, c; while (t--) { cin >> r >> c; for (int i = 0; i < r; i++) cin >> grid[i]; bool quina = false, borda = false, meio = false, all = true...
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::string; using std::vector; void print(std::list<int> &a) { for (std::list<int>::iterator it = a.begin(); it != a.end(); ++it) { cout << *it << ; } cout << endl; } void print(vector<int> &a) { f...
#include <bits/stdc++.h> using namespace std; int main() { int s, x1, x2, t1, t2, p, d; cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d; int cnt = 0, initial_position = p; while (initial_position != x1) { if (initial_position == s) d = -1; if (initial_position == 0) d = 1; initial_posit...
#include <bits/stdc++.h> using namespace std; bool even(long long int x) { return (x % 2 == 0); } bool odd(long long int x) { return (x % 2 != 0); } vector<int> sieve(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { ...
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int main() { int r, g, h, t; cin >> r >> g; t = r + g; h = sqrt(t * 2); if ((h * (h + 1)) / 2 > t) { h--; } int dp[2][r + 1]; for (int j = 0; j <= r; j++) { dp[0][j] = 0; dp[1][j] = 0; } dp[0...
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mmp; int n, m, L[1000010], R[1000010], V[1000010], Head[1000010], Next[1000010], Go[1000010], Val[1000010], Cnt = 0, tmp[1000010], Dep[1000010], fa[200010], Fa[200010][20], Len[200010][20]; int Ans[1000...
#include <bits/stdc++.h> using namespace std; long long read() { long long f = 1, x = 0; char s = getchar(); while (s < 0 || s > 9 ) { if (s == - ) f = -f; s = getchar(); } while (s >= 0 && s <= 9 ) { x = x * 10 + (s - 0 ); s = getchar(); } return f * x; ...
#include <bits/stdc++.h> using namespace std; const int MaxN = 123456, Mod = 1000000000; long long a[MaxN], f[MaxN]; int main(void) { int i, j, n, m; f[0] = f[1] = 1; for (i = 2; i < MaxN; i++) f[i] = (f[i - 1] + f[i - 2]) % Mod; while (scanf( %d %d , &n, &m) != EOF) { int i, t, l, r; ...
#include <bits/stdc++.h> using namespace std; int n, m, x, y; long int v[1001]; long int ans; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { scanf( %ld , &v[i]); } for (int i = 0; i < m; i++) { scanf( %d%d , &x, &y); if (v[x] > v[y]) ans += v[y]; els...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; cout << n / 2520 << endl; }
// O(q*log(q)) with pretty big constant factor #include<bits/stdc++.h> using namespace std; struct query { vector<int> nodes; }; // for a given path // active will find intersections not at it s lca // cnts with find intersections at it s lca const int maxn = 3e5 + 1; int n, m; vector<int>...
#include <bits/stdc++.h> using namespace std; string itos(int x) { stringstream ss; ss << x; return ss.str(); } int n, k, a[400010], nxt[400010], pt[400010], res; struct Comp { bool operator()(int l, int r) const { return pt[l] > pt[r]; } }; set<int, Comp> s1; int main() { ios_base::...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> p(n); vector<int> a(n), b(n); for (int i = 0; i < n; ++i) cin >> p[i]; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; ++i) cin >> arr[i]; vector<bool> used(n, false); int count = 0; int marked = 0; while (marked < n) { int min = 101; for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; long long S; cin >> n >> k >> S; int a[30]; for (int i = 0; i < n; i++) cin >> a[i]; long long fac[50]; fac[0] = 1; for (int i = 1; i < 50; i++) { fac[i] = i * fac[i - 1]; if (fac[i] > 10000000000000000l...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; int B[100000 + 5]; int S[100000 + 5]; int main() { int k, n; cin >> n >> k; for (int i = 0; i < n; i++) { char c; int a, b; cin >> c >> a >> b; if (c == B ) { B[a] += b; } else { ...
#include <bits/stdc++.h> using namespace std; int n, f[2][200]; int main() { f[0][0] = f[1][1] = 1; int t = 1; cin >> n; for (int i = 2; i <= n; ++i) { t = i & 1; for (int j = 1; j <= i; ++j) f[t][j] = (f[t][j] + f[t ^ 1][j - 1]) & 1; } printf( %d n , n); for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int N, M; int A[5002], B[5002]; int D[5002], E[5002], F[5002]; int result; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int getDif(int x) { int resnow = 0; for (int i = 1; i <= M; ++i) ...
#include <bits/stdc++.h> int mn(int a, int b) { return a < b ? a : b; } int main() { int a, b; scanf( %d%d , &a, &b); int x = mn(a, b); int ans = 1; for (int i = 2; i <= x; i++) { ans *= i; } printf( %d n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int ara[3]; int a, b, c, sum, d, sum1; int m; for (int wq = 0; wq < t; wq++) { cin >> ara[0] >> ara[1] >> ara[2]; sort(ara, ara + 3); m = ara[2]; sum = ara[0] + ara[1] + ara[2]; sum1 = a...
#include <bits/stdc++.h> using namespace std; int n, m, s, d; vector<int> a; map<int, int> p, q; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m >> s >> d; a.resize(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.begin(), a.end()); i...
#include <bits/stdc++.h> using namespace std; mt19937 rng(1234); const long long mod = 1e9 + 7; long long n, m, k, r, c; long long ax, ay, bx, by; long long modpow(long long u, long long v) { long long res = 1, t = u; while (v) { if (v & 1) res = res * t % mod; t = t * t % mod, v >>= 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n, m; int pre[maxn]; void init(int n) { for (int i = 0; i <= n + 1; i++) pre[i] = i; } int finds(int x) { if (x == pre[x]) return x; else return pre[x] = finds(pre[x]); } int main() { while (cin >> ...
#include <bits/stdc++.h> using namespace std; const int maxN = 30, maxRow = maxN * maxN; int n, m, a, b, d[maxN], g[maxN][maxN]; double A[maxRow][maxRow], p[maxN][maxN]; int main() { scanf( %d%d%d%d , &n, &m, &a, &b); --a, --b; for (int i = 0; i < m; ++i) { int x, y; scanf( %d%d , &x, ...
#include <bits/stdc++.h> void build_comp(int v, int comp_num, std::vector<int> &cur_comp, std::vector<int> &rev_comps, const std::vector<std::vector<int>> &g) { cur_comp.push_back(v); rev_comps[v] = comp_num; for (int to : g[v]) { if (rev_comps[to] == -1) { ...
#include <bits/stdc++.h> long long int a[100005], c[100005], s[100005]; using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; c[a[i]]++; } s[0] = 0; s[1] = c[1]; for (int i = 2; i <= 100000; i++) { s[i] = max(s[i - 1], (s[i - 2...
#include <bits/stdc++.h> using namespace std; int n, k1, k2, u[1001], q[1001], start, x, y; vector<int> vec[1001]; int a, b; int f(int v, int pr) { if (u[v] == 1) { return v; } int yy = 0; for (int i = 0; i < vec[v].size(); i++) { if (vec[v][i] != pr) { yy = max(yy, f(vec[v...
#include <bits/stdc++.h> using namespace std; template <typename T> bool chmax(T& a, const T& b) { return a < b ? (a = b, true) : false; } template <typename T> bool chmin(T& a, const T& b) { return b < a ? (a = b, true) : false; } int N; vector<int> A; list<int> edges[100001]; long long d...
#include <bits/stdc++.h> int main() { int n, i; while (scanf( %d , &n) != EOF) { if (n == 1) printf( %d n , n); else { printf( %d , n); for (i = 1; i < n; i++) { if (i != n - 1) printf( %d , i); else printf( %d n , i); }...
#include <bits/stdc++.h> using namespace std; const int Maxn = 100 * 1000 + 5; int n; vector<int> arr[Maxn]; int main() { scanf( %d , &n); int x, k; for (int i = 0; i < n; i++) { scanf( %d%d , &x, &k); arr[k - 1].push_back(x); } for (int i = 0; i < Maxn; i++) { int num = ...
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int _; for (cin >> _; _--;) { int n; cin >> n; int a[n + 1]; int cnt = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (a[i] != i)cnt++; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1123; const int MAXK = 312345; struct S2DSum { long long x[MAXN][MAXN]; void integrate(int n, int m) { for (int j = 0; j < m; j++) { for (int i = 1; i < n; i++) { x[i][j] += x[i - 1][j]; } } for (i...
#include <bits/stdc++.h> using namespace std; struct node { int x, y, msk; string s; node(int x1, int x2, int x3, string x4) { x = x1, y = x2, msk = x3, s = x4; } bool operator<(const node &b) const { if (s.size() != b.s.size()) return s.size() > b.s.size(); return s > b.s; } }; ...
#include <bits/stdc++.h> using namespace std; struct rest { int s, f; }; rest lis[1000500]; bool cmp(rest &a, rest &b) { return a.f < b.f; } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { scanf( %d %d , &lis[i].s, &lis[i].f); } sort(lis + 1, lis + n + 1, cmp); ...
#include <bits/stdc++.h> char s[2000000], t[2000000]; int n, i, YY = 0, YN = 0, NY = 0, NN = 0, Yaro = 0, Andrew = 0; int main() { scanf( %d n , &n); for (i = 0; i < 2 * n; i++) scanf( %c , &s[i]); scanf( n ); for (i = 0; i < 2 * n; i++) scanf( %c , &t[i]); for (i = 0; i < 2 * n; i++) { ...
#include <bits/stdc++.h> using namespace std; clock_t T; constexpr auto EPS = 1e-7; const int mod = (int)1e9 + 7; const double pi = acos(-1); int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; long long gcd(long long a, long long b) { return (a) ? gcd(b % a, a) : b; } long...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( avx,avx2,fma ) using namespace std; using ll = long long; using ld = long double; const ld eps = (ld)1e-11; const long long INF = 4e18; long long n, q; vector<long long> a, b; vector<arr...
#include <bits/stdc++.h> using namespace std; int mod(int a, int b) { if (a > b) return a - b; else return b - a; } int main() { int n, m, i, j, l = 0; cin >> n >> m; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 41; int n, m, q, cs; char a[N][N]; int s[N][N]; int dp[N][N][N][N]; int main() { memset(dp, 0, sizeof(int) * N * N * N * N); cin >> n >> m >> q; for (int i = 0; i < n; ++i) { cin.ignore(); for (int j = 0; j < m; ++j) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; for (long long int ij = 0; ij < n; ++ij) { long long int a, b; cin >> a >> b; long long int p = llabs(a - b), s = 0, i = 0, d = 0; while (s < p || d == 0) { ++i; s += i; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, k, q, l, r; int b[N], sum[N]; int main() { scanf( %d%d%d , &n, &k, &q); for (int i = 1; i <= n; ++i) { scanf( %d%d , &l, &r); b[l]++; b[r + 1]--; } int tot = 0; for (int i = 1; i <= 200000; ++i) ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, a, b; cin >> n >> m >> a >> b; long long cost = 0; if (m > n) m = n; if (m * a <= b) cost = n * a; else { cost = (n / m) * b; n = n % m; if (n > 0) { if ((n)*a <= b) cost += n...
#include <bits/stdc++.h> using namespace std; long long inf = 1e9 + 7; long long mod = 1e9 + 7; using namespace std; bool comp(pair<pair<long long, long long>, long long> a, pair<pair<long long, long long>, long long> b) { if (a.first.first != b.first.first) return a.first.first < b.first.firs...
#include <bits/stdc++.h> using namespace std; template <class T> bool ckmax(T& x, T y) { return x < y ? x = y, 1 : 0; } template <class T> bool ckmin(T& x, T y) { return x > y ? x = y, 1 : 0; } inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 20; long long a[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, sum = 0, mx = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; mx = max(mx, a[i]); sum += a[i]; }...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long 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 << 1) + (x << 3) + (ch ^ 48); ch = getchar(...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) { return + s + ; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } template ...
#include <bits/stdc++.h> using namespace std; int const maxn = 1e5 + 5; int ans[maxn], used[maxn]; inline int oks(vector<int> a) { for (int i = 0; i < (int)a.size(); ++i) if (a[i] == i + 1 || (a[i] & (i + 1)) == 0) return 0; return 1; } int main() { ios_base::sync_with_stdio(0); cin.ti...
#include <bits/stdc++.h> using namespace std; int main() { int n; float sum = 0; cin >> n; int k[n], count = 0; float a[n]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) sum += a[i]; for (int i = 1; i <= n; i++) { if ((sum - a[i]) / (n - 1) == a[i]) { ...
#include <bits/stdc++.h> using namespace std; long long psum[505][505]; int pw[1000000]; int dp[505][505]; int main() { int n, k; scanf( %d%d , &n, &k); if (!k) { printf( 1 n ); return 0; } pw[0] = 1; for (int i = 1; i < 1000000; ++i) pw[i] = (pw[i - 1] * 2) % 1000000007; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; vector<int> hung(const vector<vector<int> > &A) { int n = A.size(); int m = A[0].size(); vector<vector<long long> > a(n + 1); a[0] = vector<long long>(m + 1); for (int i = 0; i < n; ++i) { a[i + 1].push_back(100LL ...
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<vector> #include<cassert> using namespace std; int n,m,k,vx[100],vy[100];long long sum[100];bool mp[100][100],used[100],tmp[100],clsa[100],clsb[100];int match[100];vector<pair<int,int> >ansseq,curseq; bool dfs(int v){for(int...
#include <bits/stdc++.h> using namespace std; int main() { int meow, k = 0; string s[4]; for (int i = 0; i < 4; i++) cin >> s[i]; for (int i = 0; i < 4; i++) { int n1 = 0, n2 = 0; for (int j = 0; j < 4; j++) { if (j == i) continue; n1 += (((s[i].size() - 2) * 2) <= (s[j]....
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n; k = (20.0 + pow(1.0 + 3 * n, 0.5)) / 3.0; while (k--) { if (3 * k * k - 2 * k <= n) break; } n -= 3 * k * k - 2 * k; if (n - k <= 0) { cout << k - 2 * n << << 2 * k << endl; return ...
#include <bits/stdc++.h> using namespace std; int main() { long long temp = 0; string s; cin >> s; for (int i = 0; i < s.length(); i++) { temp = temp * 16; if (s[i] == > ) temp += 8; else if (s[i] == < ) temp += 9; else if (s[i] == + ) temp += 10; ...
#pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #include bits/stdc++.h using namespace std; #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(n) (n).begin(), (n).end() #define SZ(n) ((int)(n).size()) #define MOD 1000000007 const int N = 2000...
#include <bits/stdc++.h> using namespace std; template <typename T> constexpr string_view gtype() { string_view s = __PRETTY_FUNCTION__; return string_view(s.data() + 45, s.find( ; , 45) - 45); } const int MAXN = 10000; int arr[MAXN]; int best[MAXN]; int cur[MAXN]; int n; const long long MOD...
#include <bits/stdc++.h> using namespace std; int less_than(vector<int>& a, vector<int>& b) { for (int i = 0; i < 3; ++i) if (a[i] >= b[i]) return false; return true; } int main(int argc, char* argv[]) { int n; cin >> n; vector<vector<int> > v(n, vector<int>(5)); for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; const int N = 213700; vector<int> g[N]; int t[N]; int n; vector<int> divisiors[N]; vector<int> genDivisiors(int a) { vector<int> v; for (int i = 1; i * i <= a; i++) { if (a % i == 0) { v.push_back(i); if (i * i != (a)) v.push_back...
#include <bits/stdc++.h> using namespace std; int n, k, d, mod = 1000000007; long long dp[105][2]; long long go(int nw, bool gotit) { if (nw == 0 && gotit) return 1; if (nw <= 0) return 0; if (dp[nw][gotit] != -1) return dp[nw][gotit]; long long ret = 0; for (int i = 1; i <= k; i++) { ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int N = 100010; char s[N]; int n, k; int main() { ios::sync_with_stdio(false); cin.tie(); cout.tie(0); int T = 1; cin >> T; while (T--) { cin >> n >> k; cin >> s + 1; priority_queue<int, vec...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30); ; int c = 0, z, n; string a, b, s, t; cin >> a >> b; int x = a.size(); int y = b.size(); if (x > y) { a.swap(b); z = x; x = y...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long c[1000001] = {0}; long long d[1000001] = {0}; long long f[1000001] = {0}; long long p; int binpow(long long b, int n) { long long ans = 1; while (n) { if (n & 1) ans = ans * 1ll * b % mod; b = b * 1ll *...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9 + 10; const int MOD = 1e9 + 7; const int N = 1e6 + 10; int n, k, m; string x, y, z; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin >> x >> y; n = x.length(); int ans = 1; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; pair<int, int> add(pair<int, int> p1, pair<int, int> p2, int odd, int even) { return make_pair(p1.first + p2.first - odd, p1.second + p2.second - even); } pair<int, int> dfs(vector<int>* adj, int* visited, int* store, int u, int parent, int ...
#include <bits/stdc++.h> int main() { int t, j; scanf( %d , &t); for (j = 1; j <= t; j++) { int n, d = 0, i; char a[100000], b[100000], c[100000]; scanf( %s %s %s , a, b, c); n = strlen(a); for (i = 0; i < n; i++) { if (a[i] == c[i] || b[i] == c[i]) d++; if (a...
#include <bits/stdc++.h> template <typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First& first, Rest&... rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } template <typename T> void MACRO_VEC_ROW_Init(int n, T& t) ...
#include <bits/stdc++.h> using namespace std; template <class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template <class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return ...
#define y1 askjdkasldjlkasd #include <bits/stdc++.h> #undef y1 using namespace std; #define pb push_back #define mp make_pair #define fi(a, b) for(int i=a; i<=b; i++) #define fj(a, b) for(int j=a; j<=b; j++) #define fo(a, b) for(int o=a; o<=b; o++) #define fdi(a, b) for(int i=a; i>=b; i--) #de...
#include <bits/stdc++.h> using namespace std; int main() { string temp; cin >> temp; string a[4]; a[0] = temp[0]; a[1] = temp[1]; cin >> temp; a[3] = temp[0]; a[2] = temp[1]; cin >> temp; string b[4]; b[0] = temp[0]; b[1] = temp[1]; cin >> temp; b[3] = temp[0]...
#include <bits/stdc++.h> using namespace std; class p1328D { public: void solve() { int q; cin >> q; while (q--) { int n; cin >> n; vector<int> t(n); for (int i = 0; i < n; i++) cin >> t[i]; int sum = 1; for (int i = 1; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238; const double E = 2.718281828459045235; const int MOD = 1000000007; const long long INF = 1000000000; int main() { ios_base::sync_with_stdio(0); string s; cin >> s; cout << s; reverse((s).begin(), (s).en...
#include <bits/stdc++.h> using namespace std; int n; int query(int x1, int y1, int x2, int y2) { if (x1 > x2 || y1 > y2) return 0; printf( ? %d %d %d %d n , x1, y1, x2, y2); fflush(stdout); int ans; scanf( %d , &ans); return ans; } int get_right(int x1, int y1, int x2, int y2) { in...
#include <bits/stdc++.h> using namespace std; int nodistinct(string s, string a) { int counter = 0; for (int i = 0; i < a.size(); i++) { for (int j = 0; j < s.size(); j++) { if (a[i] == s[j]) { counter++; break; } } } return counter; } int main() {...
#include <bits/stdc++.h> using namespace std; long long n, m, k, lp, i, j, mp; long long CNM[120][12000]; long long dp[120][10]; long long ans[120][12000]; long long xar(long long now) { if (now == 0) return 1; if (now == 1) return CNM[n][i]; long long ans = xar(now % 2); long long res = xar...
#include <bits/stdc++.h> using namespace std; namespace MCMF { const int N = 1e6; const long long inf = 1e18; struct node { int to, next, v, cap; } edge[N]; int st[2000], cnt, S, T, n; int d[N], from[2000]; int can_flow[2000]; long long dis[2000]; bool bz[N]; void init(int s, int t, int nn) ...
#include <bits/stdc++.h> using namespace std; struct si { long long x, s; }; long long t[2][6] = {0}, k[200] = {0}, p[6][7] = {0}, sp = 0; vector<si> s; bool cmp(si a, si b) { return a.x < b.x; } int main() { long long n, q, p, x, y, a, m; si S; cin >> n; m = n; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; long long sum[55]; long long two[55]; const int maxn = 200000 + 10; struct node { long long l; long long r; } jiedian[maxn]; int cmp(node a, node b) { return a.l < b.l || (a.l == b.l && a.r < b.r); } int main() { two[0] = 1; sum[1] = 1; f...
#include <bits/stdc++.h> using namespace std; int main() { int n, s, len; scanf( %d%d%d , &n, &s, &len); vector<int> a(n); for (int &t : a) scanf( %d , &t); if (len > n) { puts( -1 ); return 0; } multiset<int> ms; vector<int> dp(n + 1, 1 << 20); for (int r = 0; r < le...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long ext_gcd(long long a, long long b, long long& x, long long& y) { long long t, ret; if (!b) { x = 1, y = 0; return a; } ret = ext_gcd(b, a % b, x, y); t =...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int a, b, c, d; cin >> a >> b >> c >> d; if (a <= c && b <= d) cout << Polycarp ; else if (a + b <= c + d - min(c, d)) cout << Polycarp ; else cout << Vasil...
#include <bits/stdc++.h> const int N = 2010; const int M = 200010; struct Edge { int u, v, idx; char tp; } edge[M]; struct ROAD { int v, idx; void push(int _v, int _idx) { v = _v; idx = _idx; } }; std::vector<ROAD> road[N]; struct PREVEVE { int u, idx; void push(i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000006; const long long mod = 1000000000 + 7; long long x, y; long long fact[MAXN + 25], inv_fact[MAXN + 25]; long long fast_pow(long long base, long long exp) { if (exp == 0) return 1; if (exp == 1) return base; long long ret = fas...
#include <bits/stdc++.h> using namespace std; long long n, h[100005], num = 0, lt = 0, rt, dp[100005], dp1[100005], cur; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; for (long long i = 1; i <= n; i++) { long long temp = dp[lt] + (i - lt); if (h[i] - cur <= 0 || temp <= ...
#include <bits/stdc++.h> using namespace std; long long int BinSea(vector<long long int>& a, long long int low, long long int high, long long int n) { long long int ct = high; long long int ans = high; while (low <= high) { long long int mid = low + ((high - low) / 2); ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long INF = 1e18; const int N = 100010; struct E { int to, nxt; } e[N << 3]; vector<int> a[N]; int n, m, head[N], cnt, f[N], ans[N], t, g[N]; int Write[20]; int read() { int d = 0, f = 1; char c = getchar(); ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int dp[2][20005]; inline void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } int main() { int n; scanf( %d , &n); int ans = 0, now = 0; for (int _i = 1; _i <= n; ++_i) { memset(dp[now], 0, sizeof dp[...
#include <bits/stdc++.h> using namespace std; complex<long long int> convex[1000006]; long long int cross(complex<long long int> a, complex<long long int> b) { return a.real() * b.imag() - b.real() * a.imag(); } int main() { long long int n; scanf( %lld , &n); long long int sum = 0; vector...