func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int i, c = 0, j, x = 0, n; cin >> n; string s; vector<string> ar; for (i = 0; i < n; i++) { cin >> s; ar.push_back(s); } for (i = 0; i < ar[0].length(); i++) { for (j = 0; j < n - 1; j++) { if (ar[j][i] ...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)((1e5) + 100); int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else...
#include <bits/stdc++.h> using namespace std; map<pair<int, long long>, int> dp; int n, s[1000010]; int calc(pair<int, long long> u) { if (dp.count(u) > 0) return dp[u]; if (u.first == 0) return dp[u] = 0; vector<bool> g(61); for (int i = 1; i <= u.first; ++i) { if (u.second & (1ll << i)) ...
#include <bits/stdc++.h> using namespace std; int r[8192]; vector<int> g[8192]; int ans[8192] = { 0, }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; ans[0] = 1; for (int i = 0; i < 8192; i++) { g[i].push_back(0); } f...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int h = 0; int start = 0; map<int, int> m; set<int> hash; for (int i = 0; i < s.size(); ++i) { int index = i; if (s[i] == > ) { for (int i = 0; i < 2 * h; ++i) { cout << ; ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; while (scanf( %d%d%d%d , &a, &b, &c, &d) != EOF) { if (d > 2 * c || d >= b || c > 2 * d) { printf( -1 n ); } else { printf( %d n%d n%d n , 2 * a, 2 * b, max(c, d)); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int T; cin >> T; while (T--) { long long int x, y, z; cin >> x >> y >> z; long long int ans = 0; if (x == y || x == z || y == z) { ...
#include <bits/stdc++.h> using namespace std; const long long oo = 1e18; struct Data { long long v; int x, y; Data() {} Data(long long tv, int tx, int ty) { v = tv; x = tx; y = ty; } }; int a[2010], b[2010]; Data mp1[4000010], mp2[4000010]; long long gabs(long long x)...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; long long a[N], dp[N]; long long n, k; long long check(long long m) { for (int i = 0; i < n; i++) { dp[i] = i - 1; for (int j = 0; j < i; j++) { if (abs(a[i] - a[j]) <= 1ll * (i - j) * m) { dp[i] = min(dp[i]...
#include <bits/stdc++.h> using namespace std; const int c = 100002, k = 6; long long s[7], n, ans = 1e9, mini = 1e9, t[c]; priority_queue<pair<int, pair<int, int> > > q; void pb(int a, int b) { q.push({t[a] - s[b], {a, b}}); mini = min(mini, t[a] - s[b]); } int main() { ios_base::sync_with_std...
#include <bits/stdc++.h> using namespace std; int a[100006]; int main() { int n; while (scanf( %d , &n) != EOF) { if (n == 1) puts( 1 ); else if (n == 2) puts( -1 ); else { int delta = n; for (int i = 1; i <= n && delta > 0; i++) { if (i == 1) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char a[53][53] = {5}; int ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { char x; cin >> x; if (x == a || x == f || x == c || x == e ) a[i][j] = x; } ...
#include <bits/stdc++.h> using namespace std; const int maxN = (int)5e3 + 3; vector<int> g[maxN], p[maxN]; int u, v, cur_h[maxN], cnt, n; bool used[maxN], dp[maxN], ans[maxN]; void dfs(int v, int* cur_h) { used[v] = true; cur_h[v] = 1; for (int i = 0; i < (int)g[v].size(); ++i) { int to = ...
#include <bits/stdc++.h> using namespace std; const int mo = 998244353; const int M = (1 << 23) | 5; const int N = 50; int n, m, fa[N], e[N][N]; int sz[N], id[N]; int GG[M], cnt[M]; char s[N][N]; int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); } int main() { scanf( %d , &n); for...
#include <bits/stdc++.h> using namespace std; int stmp; const int MAXB = 100000; const int INF = 1000000001; int vis[MAXB + 1]; vector<int> arr; int k, n, maxb, t, _t; int z; inline int lis() { vector<int> L(z, INF); for (int s = 0; s < (t); ++s) { for (int i = 0; i < ((int)(arr).size())...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long w, h, k, arr[4], brr[1000000], ans; cin >> w >> h; for (int i = 0; i < 4; i++) { cin >> k; for (int j = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-8; const double PI = acos(-1); int n, k, b, c, t[N]; pair<int, int> a[N]; long long ans = INF; long long cnt = 0...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], i; double ans = 0.0f; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (n % 2 == 0) { for (i = 0; i < n; i = i + 2) { ans = ans + ((a[i + 1] * a[i + 1]) - (a[i] * a[i])); } ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int ans = min(a, min(b / 2, c / 4)); cout << ans + (2 * ans) + (4 * ans) << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1 << 17; int MAX[maxn << 1], lazy[maxn << 1], e[maxn]; void push_up(int now) { MAX[now] = max(MAX[now << 1], MAX[now << 1 | 1]); } void push_down(int now) { lazy[now << 1] += lazy[now]; lazy[now << 1 | 1] += lazy[now]; MAX[now << 1] +=...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c = 0, n, t, i, j, flag = 0, sum, f; string s, s1, s2; cin >> t; while (t--) { cin >> n; c = 0, sum = 0, flag = 0, f = 0; int ara[n], ara1[n]; for (i = 0; i < n; i++) { cin >> ara[i]; } f...
#include <bits/stdc++.h> using namespace std; int main() { int s, k; cin >> k >> s; while (s >= 1) { for (int i = 1; i <= k; i++) { if (s >= i) { s = s - i; } else { cout << s << endl; return 0; } } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; inline int Read() { char c = getchar(); int num = 0; while ( 0 > c || c > 9 ) c = getchar(); while ( 0 <= c && c <= 9 ) num = num * 10 + c - 0 , c = getchar(); return (num); } inline void Add(int &a, int b) { a = max(a, b); } int ans, n, m...
#include <bits/stdc++.h> char gb[65536], pb[65536], *gp = gb + 65536, *pp = pb, a[2][2005], s[2005]; int _5[65], n = 0, m = 0, f[2][2005][2005]; long long seed[2005]; inline void add(int &x, int y) { x += y; if (x >= 1e9 + 7) x -= 1e9 + 7; } inline int gline(char *b) { char c = getchar(); in...
#include <bits/stdc++.h> using namespace std; int m, n; int main() { cin >> n >> m; if (n == 1) { cout << 1; return 0; } if (m <= n - m) { cout << m + 1; return 0; } cout << m - 1; }
#include <bits/stdc++.h> using namespace std; int const nMax = 40000; map<pair<int, int>, int> Q; int main() { int n; int ans = 0; scanf( %d , &n); pair<int, int> a; for (int i = 0; i < n; i++) { scanf( %d%d , &a.first, &a.second); if (Q.find(a) == Q.end()) { Q[a] = 1; ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; bool pd(complex<double> a, complex<double> b, complex<double> c, complex<double> d) { return imag((b - a) * conj(d - a)) * imag((b - a) * conj(c - a)) < -eps; } bool aa(complex<double> a, complex<double> b, complex<double> c)...
#include <bits/stdc++.h> using namespace std; int n, r[500005]; int f[24][500005]; int Min[500005 * 8], key[500005]; void insert(int now, int l, int r, int pos, int val) { if (pos > r || pos < l) return; if (l == r) { Min[now] = l; key[l] = val; return; } int mid = (l + r) >>...
#include <bits/stdc++.h> using namespace std; int n, m; int a[500050]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int m = n; int res = 0; for (int i = n / 2; i >= 1; i--) { if (a[i] * 2 <= a[m]) { m--; res++; } ...
#include <bits/stdc++.h> using namespace std; int n; string s; int dp[510][510]; bool has[510][510][30]; int dfs(int l, int r) { if (l >= r) return 0; int &ans = dp[l][r]; if (ans != 0) return ans; if (!has[l + 1][r][s[l] - a ]) return ans = dfs(l + 1, r); ans = dfs(l + 1, r); for (...
#include <bits/stdc++.h> using namespace std; bool pal(string s) { string b = s; reverse(b.begin(), b.end()); return b == s; } int main() { string s; cin >> s; for (int i = 0; i <= s.size(); ++i) { for (char a = a ; a <= z ; ++a) { string b = s.substr(0, i) + a + s.substr...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e3 + 10; long double dp[MAXN][MAXN]; long long p[MAXN]; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); long long n, m; cin >> n >> m; long double res = 0; for (long...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int inf = 1001001001; const long long PRED = 2500000000; int n, a[111111], used[111111], ans, k; vector<int> v[111111], b[111111]; int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); i...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0; vector<pair<long long, long long> > v; cin >> n; for (int i = 0; i < n; i++) { long long a, b; cin >> a >> b; v.push_back(make_pair(a + b, a - b)); } sort(v.begin(), v.end()); long long last = -1...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, arr[N]; long long k; int main() { cin >> n >> k; long long x = 1ll * n * (n + 1) / 2; if (k < x) return cout << -1, 0; long long rem = k - x; set<int> all; for (int i = 1; i <= n; ++i) all.insert(i); long l...
#include <bits/stdc++.h> using namespace std; const long long N = 100005; vector<long long> male[3]; vector<long long> fe[3]; string ms[3] = { lios , etr , initis }; string fs[3] = { liala , etra , inites }; string s; long long n = 0; long long m = 0, f = 0; void check() { long long flag = 0...
#include <bits/stdc++.h> using namespace std; long long q, n, c[30], r, a[100001]; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == ) ) { c[1]--; if (c[1] < 0) c[2] += 2; } else c[1]++; ...
#include <bits/stdc++.h> using namespace std; const int K = 50; long long p[K], Rem[K], V, As, Aa, Ac, Topc; int q[K], k; long long IN() { int c, f; long long x; while (!isdigit(c = getchar()) && c != - ) ; c == - ? (f = 1, x = 0) : (f = 0, x = c - 0 ); while (isdigit(c = getchar...
#include <bits/stdc++.h> using namespace std; string l, r; long long f[16][16][1 << 16]; long long g[16][16], h[16][16][16]; void init() { int m16 = (1 << 16) - 1; for (int j = 0; j < 16; ++j) f[1][j][j] = 1; for (int i = 1; i < 15; ++i) { for (int j = 0; j < 16; ++j) { for (int k = ...
#include <bits/stdc++.h> using namespace std; void file() { freopen( input.txt , r , stdin); freopen( output.txt , w , stdout); } void fast() { ios::sync_with_stdio(0); cin.tie(0); } int main() { int n; cin >> n; int x[n], y[n], ind[n + 5]; for (int i = 0; i < n; i++) cin >...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10, INF = 1e9 + 10, mod = 1e9 + 7; const double eps = 1e-9; void chmax(int &a, int b) { a = (a > b ? a : b); } void chmin(int &a, int b) { a = (a < b ? a : b); } int sqr(int x) { return x * x; } int add(int x, int y) { if (x + y < 0)...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long double PI = 4 * atan((long double)1); const long long INF = 1e18; const long long NINF = -1e18; long long get_hash(string s) { long long N = 1000001; long long base[N], A = 11, MD = 1110111110111; base[0] = 1...
#include <bits/stdc++.h> class big_integer { public: big_integer(int32_t v) { if (v >= base) { data_.push_back(v % base); data_.push_back(v / base); } else { data_.push_back(v); } } void inc() { int32_t carry = 1; size_t ptr = 0; while (carry ...
#include <bits/stdc++.h> int main() { signed int n, i, j; scanf( %d , &n); signed int arr[n][3]; for (i = 0; i < n; i++) { scanf( %d %d %d , &arr[i][0], &arr[i][1], &arr[i][2]); } for (i = 0; i < n; i++) { int u; u = arr[i][1] < arr[i][2] ? arr[i][1] : arr[i][2]; int to...
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; char ch; int FL = 0, LL = 0, FR = 0, LR = 0, CL = 0, CR = 0; for (int i = 1; i <= n; i++) { cin >> ch; if (ch != . ) { if (ch == ...
#include <bits/stdc++.h> using namespace std; const int mxn = 2e5 + 5; void solve() { long long n, k; cin >> n >> k; long long arr[n]; for (long long int i = 0; i < n; i++) cin >> arr[i]; long long a; cin >> a; long long c[n]; for (long long int i = 0; i < n; i++) cin >> c[i]; ...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; const long long M = 1e9 + 7; long long power(long long a, long long b) { long long result = 1; while (b > 0) { if (b % 2 == 1) { result *= a; } a *= a; b /= 2; } return result; } long l...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const double pi = acos(-1); const long long inf = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; const int MAX = 2e5 + 10; const long long mod = 1e9 + 7; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int...
#include <bits/stdc++.h> using namespace std; int l[200010], r[200010]; int main() { string s, t; cin >> s >> t; int n = s.size(), k = t.size(); if (s[0] == t[0]) l[0] = 1; if (s[n - 1] == t[k - 1]) r[n - 1] = 1; for (int i = 1; i < n; i++) { if (l[i - 1] < k && s[i] == t[l[i - 1]]) ...
#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 gcf(int A, int B) { if (A < B) return gcf(B, A); else if (B == 0) return A; else return gcf(B, A % B); } int main() { int n, m; cin >> m >> n; bool A[m], B[n]; memset(A, 0, sizeof(A)); memset(B, 0, sizeof(B)); ...
#include <bits/stdc++.h> using namespace std; long long m; long long a[100005], b[100005], c[100005], ans[100005]; bool prime[100005]; vector<long long> pvec; long long modpow(long long a, long long n) { if (n == 0) return 1; if (n % 2) { return ((a % 998244353) * (modpow(a, n - 1) % 998244353...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int mini, c; const int MAXN = 2e3 + 3; long long dp[2][MAXN][MAXN]; long long go(int lft, int cur, bool f) { if (lft == 0 and !f) return 1; if (dp[f][lft][cur] != -1) return dp[f][lft][cur]; long long ret = 0; if (f) { ...
#include <bits/stdc++.h> using namespace std; int main() { int l, r, a; cin >> l >> r >> a; int mini = min(l, r); int maxi = max(l, r); int diff = maxi - mini; mini += (diff <= a) ? diff : a; a -= (diff <= a) ? diff : a; if (a & 1) a--; cout << 2 * min(mini, maxi) + a; }
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; vector<long long int> vec(n); for (long long int i = 0; i < n; i++) { cin >> vec[i]; } long long int left = 0, right = 1e10; long long int ans = 0; while (left <= right) { long long in...
#include <bits/stdc++.h> using namespace std; string smallest(string s) { if (s.length() % 2 == 1) return s; string s1 = smallest(s.substr(0, s.length() / 2)); string s2 = smallest(s.substr(s.length() / 2)); if (s1 < s2) return s1 + s2; else return s2 + s1; } bool solve(string s1...
#include <bits/stdc++.h> using namespace std; const int n = 2; struct Matrix { long long matrix[5][5]; }; Matrix unit; int m; long long cnt[1000005], MOD; void initUnit() { memset(unit.matrix, 0, sizeof(unit.matrix)); int i; for (i = 1; i <= n; i++) unit.matrix[i][i] = 1; } Matrix ma...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string ans; int maxScore = -99999999; for (int i = 0; i < n; i++) { string name; int pp, mm; cin >> name; cin >> pp >> mm; int score = pp * 100 - mm * 50; for (int j = 0; j < 5; j++) {...
#include <bits/stdc++.h> using namespace std; long long n, m, ans, spe, a[100100], b[100100], c[100100], fa[100100 << 1]; char str[2]; map<pair<long long, long long>, bool> mm; long long ff(long long u) { return u == fa[u] ? u : fa[u] = ff(fa[u]); } inline long long po(long long u, long long v) { long l...
#include <bits/stdc++.h> using namespace std; int main() { int pre = 0; char ch; while (scanf( %c , &ch) != EOF) { int x = ch, b[9]; if (x < 32 || x > 126) break; for (int j = 1; j <= 8; ++j) { b[j] = x % 2; x /= 2; } x = 0; for (int j = 1; j <= 8; ++j...
#include <bits/stdc++.h> using namespace std; int id[200005], sz[200005]; vector<pair<int, int> > edges; int n, m, s1, s2, l1, l2; bool bad(int x) { return x == s1 || x == s2; } bool cmp(pair<int, int> p1, pair<int, int> p2) { bool b1 = bad(p1.first) || bad(p1.second); bool b2 = bad(p2.first) || bad...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 500 + 20; int tav(long long n, long long k) { long long res = 1; while (k > 0) { if (k & 1) { res *= n; } n *= n; k /= 2; } return res; } vector<int> adj[MAX_N]; int dis[MAX_N][MAX_N], cnt[MAX_N][...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) { int n; cin >> n; if (n == 2) { cout << 2 n1 2 n ; continue; } vector<pair<int, int>> ans; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; void solve() { long long int n; cin >> n; vector<long long int> a(n); for (long long int i = 0; i < n; i++) { cin >> a[i]; } long long int mx = *max_element((a).begin(), (a).end()); long long int sum = ac...
#include <bits/stdc++.h> using namespace std; inline int nxt() { int x; scanf( %d , &x); return x; } int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long n; cin >> n; vector<long long> ps; for (long long i = 2; i * i <= n; ++i) { if (n...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; int p; cin >> n >> k >> p; long long ndiv2 = n / 2; long long ndiv2minus1 = n / 2 - 1; long long nminusk = n - k; for (int i = 0; i < p; i++) { long long x; scanf( %I64d , &x); printf( %c , ((((x...
#include <bits/stdc++.h> using namespace std; typedef vector<vector<long long> > vvl; long long x, y, z, j, i, t, n, k, input, ans, flag, maxi, mini, a, b; int main() { cin >> n >> x; ans = 0; for (long long i = 1; i <= n; i++) { if (x % i == 0 && x / i <= n) ans++; } cout << ans << ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, r; cin >> n >> m >> r; int s[n], b[m]; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < m; i++) cin >> b[i]; sort(s, s + n); sort(b, b + m); int x = r / s[0]; int remind = r % s[0]; int y = x * b...
#include <bits/stdc++.h> const int N = 2e5 + 5; int n, i, j, x, sz[N], c[N], t, s; int main() { scanf( %d , &n); for (i = 1; i < n; i <<= 1, t++) ; for (i = 1; i <= n; i++) { scanf( %d , &x); c[i] += x; for (j = x + 1; j; j -= j & (-j)) c[i] -= sz[j]; for (j = x + 1; j <=...
#include <bits/stdc++.h> using namespace std; class Solution { public: long long solve(vector<int>& A) { int n = A.size(); int F = 0; for (int i = 0; i < n; ++i) { if (A[i] == -1) { F = i; break; } } if (F == n - 1) { return 0; }...
#include <bits/stdc++.h> using namespace std; int n, m, top, tot, ans[100005], in[200005], rtx; int col; struct column { vector<int> a; int id; friend bool operator<(column X, column Y) { return X.a[col] < Y.a[col]; } } empty; vector<column> b; vector<int> to[200005]; void toposort() { q...
#include <bits/stdc++.h> using namespace std; long long int a, b, c, d; int main() { cin >> a >> b >> c >> d; if (a + 8 * c >= b) cout << 0 ; else if (c > d) { int num = b - a - 8 * c, den = 12 * (c - d); cout << (num + den - 1) / den; } else cout << -1 ; return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int T; scanf( %d n , &T); for (int t = 0; t < T; t++) { string s; getline(cin, s); bool p = false; int prevZero = -1; for (int i = 0; i < s.size(); i++) { char c = s[i]; if (c == 0 ) { if ...
#include <bits/stdc++.h> using namespace std; int p1[10][13], p2[10][13]; bool fl = false; int c1[10], c2[10]; int len, n, m; int sum = 0, ans; int main() { memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); memset(p1, -1, sizeof(p1)); memset(p2, -1, sizeof(p2)); scanf( %d%d , &n, &...
#include <bits/stdc++.h> using namespace std; using ll = long long; int a[8][128]; int main() { cin.tie(0); cin.sync_with_stdio(0); int n, k; cin >> n >> k; for (int i = 1; i <= 4; ++i) for (int j = 1; j <= n; ++j) cin >> a[i][j]; vector<tuple<int, int, int>> ans; if (k == 2 * ...
#include <bits/stdc++.h> using namespace std; const int M = 6e5 + 10, P = 490019; const double PI = acos(-1.0); int a[M << 1], b[M << 1], c[M << 1], pw[M], inv[M], C[M << 1], oo, n, m, cc, r[M << 1], N, l; struct cp { double x, y; cp(double _x = 0, double _y = 0) : x(_x), y(_y) {} } p[M << 1],...
#include <bits/stdc++.h> using namespace std; const int maxn = 2097152; const double pi = acos(-1); using cplx = complex<double>; const cplx I(0, 1); cplx omega[maxn + 1]; int a[maxn], cnt[maxn]; void prefft() { for (int i = 0; i <= maxn; ++i) omega[i] = exp(2 * pi * i / maxn * I); } void bin(ve...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int N = 2e5 + 10; const int M = 300; int a[N]; int b[N]; int typ[N]; int flag[N]; int root[N]; int tmp[N]; int q[N]; int qn; int find_root(int u) { if (u == root[u]) { return u; } root[u] = find_r...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, t; ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; while (t--) { int b, k; cin >> n >> b >> k; int arr[n]; for (i = 0; i < n; i++) cin >> arr[i]; int flag = 1; for...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const double PI = acos(-1.); const double eps = 1e-9; char s[1000005]; char t[1000005]; int fs[11]; int ft[11]; int fx[11]; char y[1000005]; int main() { int i, j, k, _T; while (~scanf( %s%s , s, t)) { if...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5, nax = 1e6 + 5; char rodz[25]; int id[25]; int res[2 * nax]; int cob(int a) { if (a) return (a % 2 ? 1 : 0) + cob(a / 2); return 0; } int pro() { int n; cin >> n; vector<int> w; for (int _ = 1, _n = (n); _ <= _...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); long long x; char c; long long pr = -1, pb = -1; long long lr = -1, lb = -1, lp = -1; long long ans = 0; long long mr = -1, mb = -1; for (int i = 0; i < n; i++) { scanf( %lld %c , &x, &c); ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int maxn = 500005; const long long int mm = 1e+18; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int a[n], p[m]; for (int i = 0; i < n; i++) cin >> a[i...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; ...
#include <bits/stdc++.h> using namespace std; pair<int, int> pp[10]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i, j, k, l, m, n, even1 = 0, odd1 = 0, count = 0, t, even2 = 0, odd2 = 0, even = 0, odd = 0; cin >> t; int a[t]; for (i = 0; i < ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int arr[n], brr[m], check[n], indexer = 0; for (int i = 0; i < n; i++) cin >> arr[i], check[i] = -2; for (int i = 0; i < m; i++) { cin >> brr[i]; for (int j = 0; j < n; j++) if (brr[i] == arr[...
#include <bits/stdc++.h> using namespace std; int main() { string name = 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 ; string test; int ...
#include <bits/stdc++.h> using namespace std; struct __TS { ~__TS() { cerr << Time elapsed: << clock() * 1.0 / CLOCKS_PER_SEC << endl; } } __ts; const int mod = 1e9 + 7; const int maxn = 1239; long long tp[maxn]; int main() { tp[0] = 1; for (int i = (int)(1); i < (int)(maxn); i++)...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, maxn = 1000001; long long t[maxn]; void init() { for (int i = 0; i <= 1000000; i++) t[i] = (long long)i * i * i; } int main() { init(); int n, a, b; scanf( %d , &n); while (n--) { scanf( %d%d , &a, &b); ...
#include <bits/stdc++.h> using namespace std; int cc[100002]; pair<int, int> in[100002]; vector<pair<int, int> > adj[100002]; int pos = 1; int l[100002], r[100002], label[100002]; long long d[100002]; void dfs(int node, int par, long long depth = 0) { l[node] = pos; d[node] = depth; int ch, ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int pre[N], n, m; int f(int x) { return pre[x] == x ? x : pre[x] = f(pre[x]); } set<int> s[N]; map<int, vector<int> > v[N]; void join(int x, int y) { x = f(x); y = f(y); if (x == y) return; if (s[x].size() < s[y].size())...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long n; cin >> n; long long i; if (n == 1) cout << 1; else { long long sum = 1; for (i = 1;; i++) { sum += (1ll << i); if (sum >=...
#include <bits/stdc++.h> using namespace std; constexpr long long R = 1e3 + 69, INF = 2e9 + 6969, mod = 998244353; long long n, a[R], dp[R], fact[R], rev[R]; long long choose(long long N, long long K) { long long cur = (fact[N] * rev[K]) % mod; cur = (cur * rev[N - K]) % mod; return cur; } long ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, h, a, b, k; cin >> n >> h >> a >> b >> k; for (long long int i = 0; i < k; i++) { long long int t1, f1, t2, f2; cin >> t1 >> f1 >> t2 >> f2; long long int ans; if (t1 == t2) { cout << abs(f1 - f2)...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; constexpr auto MOD = 1000000007LL; constexpr auto LINF = (1LL << 60); constexpr auto INF = 2147483647LL; constexpr auto PI = 3.1415926535897932384626433; co...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010, mod = 1e9 + 7; int i, j, k, n, m, y, e; long long ans = 1, a[maxn]; int main() { a[0] = 1; a[1] = 1; cin >> n; for (i = 2; i <= n; i++) a[i] = (a[i - 2] * (i - 1) + a[i - 1]) % mod; for (i = 1; i <= n; i++) { int...
#include <bits/stdc++.h> using namespace std; int quick_pow(int a, int b, int MOD) { a %= MOD; int res = 1; while (b) { if (b & 1) res = (res * a) % MOD; b /= 2; a = (a * a) % MOD; } return res; } const int maxn = 200000 + 10; const int MOD = 1e9 + 7; const int INF = 1e...
#include <bits/stdc++.h> using namespace std; const double pai = acos(-1); const double eps = 1e-8; const long long mod = 1e9 + 7; const int MXN = 1e6 + 5; vector<int> v[MXN]; int c[MXN]; int suf[MXN]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int le; scanf( ...
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll int n,q; string s; cin>>n>>q; ll int cum[n+2]; cin>>s; cum[0]=s[0]- a +1; for(int i=1;i<n;i++) { cum[i]=cum[i-1]+s[i]- a +1; } for(ll int i=0;i<q;i++) { ll...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; void __never(int a) { printf( nOPS %d , a); } const int INF = 1000000000; bool was[6][26][6][11][16][21]; int dp[6][26][6][11][16][21]; struct Edge { int a, l, h; }; int n; Edge graf[7][7]; int mask[7]; ...