func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) #pragma GCC optimize( unroll-loops ) using namespace std; const int MAX = 47 + 5; const long long MAX2 = 11; const long long MOD = 1000000007; const long long MOD2 = 1000005329; const long long INF = 2e18; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1,...
#include <bits/stdc++.h> using namespace std; int n, m, x; int main() { scanf( %d%d , &n, &m); x = n; for (int i = 0; i < m; i++) { int l, r; scanf( %d%d , &l, &r); x = min(x, r - l + 1); } printf( %d n , x); for (int i = 0; i < n; i++) printf( %d , i % x); printf( ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> g(n), v(m), b(m); for (auto &i : g) cin >> i; for (auto &i : v) cin >> i; for (auto &i : b) cin >> i; int res = 0; ve...
#include <bits/stdc++.h> using namespace std; inline int in() { int x, y; y = scanf( %d , &x); return x; } const int N = 2 * 100 * 1000 + 5; int a[N], ans[N]; vector<pair<int, int>> v; int seg[4 * N]; void add(int p, int s = 0, int e = N, int x = 1) { seg[x]++; if (e - s == 1) return...
#include <bits/stdc++.h> using namespace std; const int MAX = 100000 + 10; const int Alpha = 27; string str; int sum[Alpha], need[Alpha]; int get(char a) { if (a == 9 ) a = 6 ; if (a == 5 ) a = 2 ; return a - 0 ; } int main() { int i; cin >> str; for ((i) = (0); (i) != ((int...
#include <bits/stdc++.h> using namespace std; string s; long long a[101], b[101]; int main() { long long i, j, k, l, n, c, m, x, y, lft, rgt, p, q; cin >> n; for (i = 0; i < 2 * n; i++) { cin >> a[i]; } sort(a, a + 2 * n); c = 0; p = 0; long long mnm = 1267357834; for (...
#include <bits/stdc++.h> using namespace std; bool arr[1001][1001]; struct node { int ct; int lastind; }; struct node1 { int ct; int lastind; }; node row[1001]; node1 col[1001]; int main() { vector<int> a; int n, i, x, y, j, temp; scanf( %d , &n); for (i = 0; i < n - 1;...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 2e5 + 5; int a[maxn], lst[maxn]; bool used[maxn]; int occ[maxn]; int main() { ios::sync_with_stdio(false); int n; cin >> n; int ans = n; for (int i = 1; i <= n; i++) { cin >> a[i]; lst[a[i]...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10, maxm = 2e6 + 10; const long long INF = 0x3f3f3f3f, mod = 1e9 + 7; int casn, n, m, k; namespace graph { vector<int> g[maxn]; int all, sz[maxn], root, maxt; bool vis[maxn]; int dfs_root(int now, int fa) { int cnt = 1; for (...
#include <bits/stdc++.h> using namespace std; long long read() { long long s = 0, w = 1; char c; while (c = getchar(), c > 9 || c < 0 ) if (c == - ) w = -1; while (c >= 0 && c <= 9 ) s = s * 10 + c - 0 , c = getchar(); return s * w; } void write(long long x) { if (x < 0) pu...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int main() { int t; scanf( %d , &t); ; while (t--) { int n; scanf( %d , &n); ; if (n % 2 == 0) { n = n / 2; while (n--) { cout << 1; } cout << n ; } else {...
#include <bits/stdc++.h> using namespace std; int dp[1 << 6][1 << 6][41][41]; int h, w; const int dy[] = {-1, 0, 0, 1, 0}; const int dx[] = {0, -1, 1, 0, 0}; int dfs(const int up, const int down, const int cx, const int cy) { if (cy == h) { int cnt = 0; for (int i = 0; i < w; i++) if...
#include <bits/stdc++.h> using namespace std; int main() { int max; int a[3]; for (int i = 0; i < 3; i++) { cin >> a[i]; sort(a, a + 3); max = 1 + a[2] - (a[0] + a[1]); } if (max > 0) cout << max; else cout << 0 ; }
#include <bits/stdc++.h> using namespace std; int gi() { int x = 0, w = 1; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) w = 0, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = (x << 3) + (x << 1) + ch - 0 , ch = getchar(); return w ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<pair<int, int> > v; while (n--) { int x, y; cin >> x >> y; v.push_back(make_pair(-x, y)); } sort(v.begin(), v.end()); int ind = k - 1; int res = 1; while (ind - 1 >= 0 && ...
#include <bits/stdc++.h> using namespace std; int main() { int T, b, w, tmp; scanf( %d , &T); while (T--) { scanf( %d %d , &b, &w); if (b >= w) tmp = 2; else tmp = 3, swap(b, w); if (b > 3 * w + 1) printf( NO n ); else { printf( YES n ); ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } ...
#include <bits/stdc++.h> using namespace std; int T; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> T; for (int i = 0; i < T; i++) { int n, oneCnt = 0, zeroCnt = 0; cin >> n; string str; for (int j = 0; j < n; j++) { char ch; cin >> ch; ...
#include <bits/stdc++.h> using namespace std; long long dx[] = {1, -1, 0, 0}; long long dy[] = {0, 0, 1, -1}; const int sz = 2e6 + 5, mod = 998244353; long long t, n, m, k; const int MAXN = 2e5 + 7; const long long lim = 1e18; const long long inf = 1e15; vector<long long> Prime; vector<bool> sie(sz,...
#include <bits/stdc++.h> using namespace std; long long int i, j, p, d, n, m, total, k, ok, a, b, c, op, maxi, rasp, m1, m2, p1, p2, rez, modu = 1000000007, mini, mij, ls, ld; pair<long long int, long long int> v[300500]; priority_queue<pair<long long int, long long int> > nxt; priority_queue<long long ...
#include <bits/stdc++.h> using namespace std; long long bipow(long long a) { if (a == 0) return 1; long long aea = bipow(a / 2) % 998244353; if (a % 2 == 0) return (aea * aea) % 998244353; else return ((aea * aea) % 998244353 * 2) % 998244353; } int main() { ios_base::sync_with_s...
#include <bits/stdc++.h> using namespace std; struct numer { int rost; int num_of; numer() : rost(0), num_of(0) {} numer(int _rost, int _num_of) : rost(_rost), num_of(_num_of) {} }; int maxim(int a, int b) { return a > b ? a : b; } int comp(const void *a, const void *b) { int *A = (int *)a...
#include <bits/stdc++.h> using namespace std; const int N = 6e5; const long long mo = 1e9 + 7; const long long inf = 1e9; const long long Inf = 1e18; int lz[N], a[N], ls[N], rs[N], mi[N], mx[N]; bool ok[N]; char s[N]; void f(int x, int l, int r, int y, int z, int L, int R) { if (l == L && r == R &...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int tree[maxn * 4], add[maxn * 4]; void push(int v, int tl, int tr) { if (add[v] != 0) { tree[v] += add[v]; if (tl != tr) { int vv = v + v; add[vv] += add[v]; add[vv + 1] += add[v]; tree[v] =...
#include <bits/stdc++.h> using namespace std; template <class T> void chmax(T& a, const T& b) { a = max(a, b); } template <class T> void chmin(T& a, const T& b) { a = min(a, b); } using ll = long long; using P = pair<int, int>; using VI = vector<int>; using VVI = vector<VI>; using VL = v...
#include <bits/stdc++.h> using namespace std; vector<long long> t1, t2; long long a, b, n, k, q, day, val, p, t; void update1(long long i, long long l, long long r, long long qi, long long qx) { if (l + 1 == r) { t1[i] += qx; t1[i] = min(t1[i], a); return; } long lon...
#include <bits/stdc++.h> using namespace std; void read_file(bool outToFile = true) {} int n, K; int cnt50, cnt100; const int MAXN = 51 + 9; int memo[MAXN][MAXN][2]; int memoo[MAXN][MAXN][2]; int vis[MAXN][MAXN][2]; int C[MAXN][MAXN]; inline void add(int &x, int v) { x += v; if (x >= (100000...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 1; i <= n; i++) cin >> a[i]; int c = 0, t = 0; for (int i = 1; i <= n; i++) { if (a[i] < 0) { c++; } else { t++; } } if (t == n || n == 1) { cout...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a; b = a; long long int x = 0, y = 0, z = 0; long long int i; for (i = 0; i < a.size(); i++) { if (a[i] == a ) { x++; } if (a[i] == b ) { y++; } if (a[i] == c ) { ...
#include <bits/stdc++.h> using namespace std; int a[1001][1001]; vector<pair<pair<int, int>, char> > start; int row[1001][1001], col[1001][1001]; pair<char, int> dir[100001]; vector<char> ans; void init() { for (int i = 0; i < 1001; i++) { for (int j = 0; j < 1001; j++) a[i][j] = -1; } } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %d%d , &n, &k); vector<char> s(n + 1), t(n + 1); scanf( %s , &s[0]); scanf( %s , &t[0]); long long ans = 0; long long cnt_a = 0; long long cnt_b = 0; bool found_diff = false; bool big_num = false; ...
#include <bits/stdc++.h> using namespace std; int n; int a[101]; int dp[101][1 << 17]; int M[61]; vector<int> prime; bool isprime(int num) { int i; for (i = 2; i < num; ++i) { if (num % i == 0) return 0; } return 1; } void pre() { int i, j; for (i = 2; i < 60; ++i) { ...
#include <bits/stdc++.h> using namespace std; double dp[2][600 + 10]; int main(void) { int N, K, i, j; double ans = 0.0; cin >> N >> K; dp[0][1] = 1.0; for ((i) = 0; (i) < (int)(N); (i)++) { int cur = i % 2, next = (i + 1) % 2; for ((j) = 0; (j) < (int)(600); (j)++) ans += ...
#include <bits/stdc++.h> using namespace std; bool ask(long long l, long long r) { printf( %lld %lld n , l, r); fflush(stdout); char x[4]; scanf( %s , x); return x[0] == Y ; } long long n, k; int main() { cin >> n >> k; long long l = 1, r = n; srand(time(0)); while (1) { ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { ...
#include <bits/stdc++.h> using namespace std; bool used[15]; int main() { int n, m, a[15], b[15]; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j = 1; j <= m; j++) cin >> b[j]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i] == b[j] && u...
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, long long>> v[63]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; long long sum = 0; for (int i = 0; i < n; i++) { int val; long long mask; cin >> val >> mask; sum += val; ...
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b); long long int gcd(long long int a, long long int b); int prime(int n); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { ...
#include<bits/stdc++.h> using namespace std; template<typename AA>inline void CMax(AA &u,AA v){if(v>u)u=v;} template<typename AA>inline void CMin(AA &u,AA v){if(v<u)u=v;} #define Put(a) cout<<(a)<<endl #define For(a,b,c) for(int a=(b);a<=(c);++a) #define Fov(a,b,c) for(int a=(b);a>=(c);--a) #define Foe(a,...
#include <bits/stdc++.h> using namespace std; const int N = 1005; long long a[N][N], dp[N][N][4]; int n, m; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int i = 1; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; const long long mm = 2; long long n, m0[mm][mm], m1[mm][mm] = {{0, 1}, {2, 1}}, mz[mm][mm], tmp[mm][mm], pwk, dv = 1e9 + 7; void cop(long long x[mm][mm], long long y[mm][mm]) { long long i, j; for (i = 0; i < mm; i++) { for (...
/** * Author: lukasdeimos */ #include<bits/stdc++.h> #define endl n #define ff first #define ss second using ll = long long; using namespace std; void solve() { int n,k; cin >> n >> k; cout << (n-k+k/2) << endl; for(int i = k+1; i <= n; i++) cout << i << ; for(i...
#include <bits/stdc++.h> using namespace std; long long nCr(int n, int r) { if (r > n - r) r = n - r; long long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int n, MOD; pair<int, int> s[MAXN]; int main() { scanf( %d , &n); int m = 0; for (int i = 1; i <= n; i++) { int a, b; scanf( %d , &a); s[++m] = make_pair(a, i); } for (int i = 1; i <= n; i++) { i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == * ) { for (int j = 1; j < n; j++) { int t = i; int k = 0; while (k < 6 && t < n && s[t] == * ) { t =...
#include <bits/stdc++.h> using namespace std; int aaa = 0; int n, pown = 1, a[250005], indx, indy, p[250005], lvl[250005], timer, in[250005], out[250005], pw[4 * 250005], st, en, lc, oo, c[6], ans, q, typ; vector<int> v[250005], gg; pair<int, pair<int, int> > tt[2 * 250005], l[2 * 250005][19...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } struct key { string name; int t, p, g; }; int main() { int n, s, mt = 0, mg = 0, mp = 0; string x; cin >> n; vector<key> vec(n); for (int i = 0; i < n; i++) { cin >> s...
#include <bits/stdc++.h> using namespace std; vector<int> a, Q; vector<vector<int>> Q2; int n; void help(int x) { int p1, p2, p3, s1, s2, s3, s4; vector<int> A, B, C, D; p3 = find(a.begin(), a.end(), x) - a.begin(); p1 = find(a.begin(), a.end(), x + 1) - a.begin() - 1; p2 = p3; while (...
#include <bits/stdc++.h> using namespace std; int dx[] = {-2, -1, 1, 2, -2, -1, 1, 2}; int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <...
#include <bits/stdc++.h> using namespace std; char str[25][25]; int cost[25][25]; const int maxc = 1 << 20; int dp[maxc]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) scanf( %s , str + i); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) scanf( %d ...
#include <bits/stdc++.h> using namespace std; const int N = 2505; int n, a[N][N]; struct node { int x, y, v; node() {} node(int _x, int _y, int _v) : x(_x), y(_y), v(_v) {} bool operator<(const node k) const { return v < k.v; } }; vector<node> p; bitset<N> r[N], c[N], t; int main() { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; cin >> n; vector<long long int> v(n); for (long long int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); long long int i = 0, j = 0, ans = ...
#include <bits/stdc++.h> using namespace std; template <class T> void inc(T& a, const T& b) { if (a < b) a = b; } template <class T> void dec(T& a, const T& b) { if (a > b) a = b; } const int N = 100010; int n; int a[N]; struct node { int lf, len; bool operator<(const node& rhs) co...
#include <bits/stdc++.h> using namespace std; bool debug; const int inf = 1e9 + 5; const int nax = 3005; vector<int> w[nax]; int d[nax][nax]; int main(int argc, char *argv[]) { debug = argc > 1; int n, m; scanf( %d%d , &n, &m); for (int _ = 0; _ <= (m)-1; ++_) { int a, b; scanf...
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } int main() { fast(); double n; cin >> n; vector<double> v(n); for (int i = 0; i < n; i++) cin >> v[i]; double sum = 0; for (int i = 0; i < n; i++) su...
#include <bits/stdc++.h> using namespace std; const long long N = 100005; long long T, ans, res; long long Ans[N], p[N], a, b, c; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigi...
#include <bits/stdc++.h> using namespace std; int t, pos, ans; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> s; ans = pos = 0; s += R ; for (int i = 0; i < s.size(); i++) { if (s[i] == R ) { ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template <typename T> inline void Add(T &x, T y) { x += y; if (x >= mod) x -= mod; } template <typename T> inline void Mul(T &x, T y) { (x *= y) %= mod; } inline int read() { int x = 0; char ch = getchar()...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; char s[33]; int num[33]; char mp[3][14]; int main() { while (scanf( %s , s + 1) != EOF) { memset(num, 0, sizeof(num)); int id; for (int i = 1; i <= 27; i++) { num[s[i] - A ]++; if (num[s[i] - A ] =...
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265359; template <typename T> T abs(T x) { return x > 0 ? x : -x; } template <typename T> T sqr(T x) { return x * x; } long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } const int maxn = 2e5 + ...
#include <bits/stdc++.h> using namespace std; int a[1100], b[1100]; int main() { int i, j, n, k, x; cin >> n >> k >> x; int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; a[arr[i]]++; } for (j = 0; j < k; j++) { int sum = 0; for (i = 0; i < 1100; i++) { if...
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long int, long long int> v1, pair<long long int, long long int> v2) { if (v1.first == v2.first) { return v1.second > v2.second; } return v1.first > v2.first; } int main() { long long int n, i, j, k, flag; str...
#include <bits/stdc++.h> using namespace std; int n, m, k, a[100001][11], x[100001], cnt[11], u, v; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]); for (int i = 1; i <= k && scanf( %d%d , &u, &v); i++) x[u]++, cnt[v]++; ...
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { string s; cin >> s; vector<string> v(10); for (int i = 0; i < 10; i++) { cin >> v[i]; } string res = ; for (int i = 0; i <= 70; i += 10) { string find = s.substr(i, 10); for (int j = 0; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 555; long long saveori[maxn]; long long savepos[maxn]; long long tree[maxn << 2]; void update(long long nowid, long long l, long long r, long long pos, long long v) { if (l == r) { tree[nowid] = v; return; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long int a, b, c; cin >> a >> b >> c; if (min(a, b) != max(a, b)) cout << (2 * min(a, b) + 1 + 2 * c); else cout << (a + b + 2 * c); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
#include <bits/stdc++.h> using namespace std; int sc1() { int x; scanf( %d , &x); return x; } long long sc2() { long long x; scanf( %lld , &x); return x; } int bs; int n, q; int arr[100007]; int cnt[100007]; int ans = 0; int answer[100007]; struct A { int l, r, id; ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); const double PI = 2 * acos(0.0); const string DIGITS = 0123456789 ; const string ALPH = abcdefghijklmnopqrstuvwxyz ;...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; vector<vector<int> > graph, trees, chains; vector<int> head, sub, mxs, mp, idx; int dfs(int ind = 0) { sub[ind] = 1; mxs[ind] = 0; for (auto u : graph[ind]) { sub[ind] += dfs(u); mxs[ind] = max(mxs[ind], su...
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; if ((int)str.size() == 1) { cout << 1 << endl; return 0; } str += 8 ; int cnt = 1, ans = 0; for (int i = 1; i < (int)str.size(); i++) { if (str[i] == str[i - 1]) cnt++; els...
#include <bits/stdc++.h> int ar[100000]; using namespace std; int main() { int n; cin >> n; int c = 0, ans = 0; int r; for (int i = 0; i < 2 * n; i++) { cin >> r; if (ar[r]) { ar[r] = 0; c--; } else { c++; ar[r] = 1; } if (ans < c) ...
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[600000], *p1, *p2; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 600000, stdin), p1 == p2) ? EOF : *p1++; } long long rd() { long long x = 0; char ch = nc(); while (ch < 0 |...
#include <bits/stdc++.h> using namespace std; template <typename T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( % PRId64, &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); }...
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 20; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; if (k % 2 == n % 2 && (k * k) <= n) cout << YES << endl; e...
#include <bits/stdc++.h> using namespace std; long long a, b; long long f(long long a, long long b) { if (b == 0) return 0; return a / b + f(b, a % b); } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> a >> b; cout << f(a, b) << endl; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 50; signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; long long ans = 0; sort(a.begin(), a.end());...
#include <bits/stdc++.h> const int maxn = 1000010; const int P = 1000000007; int k, w; int f[maxn], g[maxn]; int pow(int x, int y) { int e = 1; while (y) { if (y & 1) e = (long long)e * x % P; x = (long long)x * x % P; y >>= 1; } return e; } int main() { int i, d, t, ...
#include <bits/stdc++.h> using namespace std; void bruteforce() {} long long power(long long x, long long y) { long long res = 1; x = x % 1000000007; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; y = y >> 1; x = (x * x) % 1000000007; } ret...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, l, k; cin >> t; while (t--) { cin >> n >> k >> l; int s = 0, f = 2 * k - 1, dep, flg = 1; for (i = 1; i <= n; i++) { cin >> dep; if (!flg) continue; if (l < dep) { cout << NO << ...
#include <bits/stdc++.h> int main() { int n, i, cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0, cnt5 = 0, cnt6 = 0; char x[10]; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %s , x); if (x[0] == p ) { cnt1++; } else if (x[0] == g ) { cnt2++; } else if (x[0] == b ...
#include <bits/stdc++.h> using namespace std; using pii = pair<long long, long long>; using vi = vector<long long>; using vvi = vector<vi>; const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL; const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}, DY[9] = {-1, 0,...
#include <bits/stdc++.h> using namespace std; void getmax(int &a, const int b) { if (b > a) a = b; } struct Segment { int l, r; Segment() {} Segment(const int _l, const int _r) : l(_l), r(_r) {} bool operator<(const Segment &s) const { return l != s.l ? l < s.l : r > s.r; } }; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 55; int n, m; int f[N][N], g[N][N], h[N][N], F[N][N], inv[N]; inline long long qpow(long long a, long long b) { long long res = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) res = res * a % mod; return...
#include <bits/stdc++.h> using namespace std; int main() { long n, i, a; unsigned long long s1 = 0, s2 = 0, s3 = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a; s1 += (unsigned long long)a; } for (i = 0; i < n - 1; i++) { cin >> a; s2 += (unsigned long long)a; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10, maxk = 52; const int MOD = (int)1e9 + 7; inline void add(long long &a, long long b) { a = (a + b) % MOD; } long long fac[maxn]; struct P { int to, w; }; vector<P> v[maxn], v2[maxn]; bool vis[maxn]; int n, fa[maxn], in[ma...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long a[N], b[N]; void add(int l, int r, int val) { if (l > r) return; b[l] += val; b[r + 1] -= val; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; struct node { int next, to; } e[maxn * 2]; int head[maxn * 2]; int a[maxn]; set<int> G[maxn]; int ans[maxn]; int cnt; int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } void init() { memset...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; int powmod(long long a, int b, int c) { long long r = 1 % c; while (b) { if (b & 0x1) r = r * a % c; a = a * a % c; b >>= 1; } return r; } int phi(int n) { int ret = n, i; for (i = 2; i * i <= n; +...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (!(n & 1)) cout << -1 << endl; else { for (int i = 0; i < n; i++) cout << i << ; cout << endl; for (int i = 0; i < n; i++) cout << i << ; cout << endl; for (int i = 0; i < n; i++)...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const double EPS = 1e-8; const int mod = 1e9 + 7; const int N = 1e6 + 10; const long long INF = 1e18; long long power(long long x, long long y) { long long t = 1; while (y > 0) { if (y % 2) y -= 1, t = t * x % m...
#include <bits/stdc++.h> using namespace std; const double bili = acos(-1.0) / 4; const double pi = acos(-1.0); bool IN() { char ch = getchar(); while (ch < 0 || ch > 9 ) ch = getchar(); return bool(ch - 0 ); } int n, ptot, yuan; bool a[2005][2005], vis[2005][2005]; int sum[2005][2005]; ...
#include <bits/stdc++.h> using namespace std; int arr[100009]; int dp[100009]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; int ans = 1; dp[0] = 1; for (int i = 0; i < n; i++) { dp[i] = 1; if (arr[i] >= arr[i - 1]) dp[i] = dp[i - 1] + 1; ans ...
#include <bits/stdc++.h> using namespace std; int T; double pi = acos(-1.0); vector<long long> v; long long factorial(long long x) { long long total = 1; for (int i = 2; i <= x; i++) total *= i; return total; } bool isprime(long long x) { vector<bool> prime(x + 1, 1); prime[0] = prime[...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( -O2 ) const int lim = 2e5 + 5; long long n, k, x, y, t, ans, p[lim]; map<long long, long long> f; long long inv(long long x) { return (~x) & ((1LL << k) - 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int matrix[n][n], sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> matrix[i][j]; } } int j = 0; for (int i = 0; i < n; i++) { sum += matrix[i][i]; } fo...
#include <bits/stdc++.h> using namespace std; char a[3][3]; int main() { int p = 1; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { if (a[0][0] != a[2][2] || a[0][1] != a[2][1] || a[0][2] != a[2][0] |...
#include <bits/stdc++.h> using namespace std; int dp[123000]; int n, m; long long d, k, a, b, t; void input() {} void solve() { long long ans = 0; if (d <= k) { ans = (long long)a * (long long)d; printf( %lld n , ans); return; } d -= k; ans += (long long)a * (long long)...
#include <bits/stdc++.h> #define LL long long #define PII pair<int, int> #define PLL pair<LL, LL> #define all_of(v) (v).begin(), (v).end() #define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define fi first #define se second const int MAXN = 401; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string a, b, c; cin >> a >> b >> c; int i = 0, flag = 0; for (; i < a.size(); i++) { if ((a[i] == c[i] || b[i] == c[i]) || (a[i] == c[i] && b[i] == c[i])) { flag = 0; ...
#include <bits/stdc++.h> using namespace std; int n; long long A[100000 + 8], mark[20 + 8]; long long result = 0; long long getC(int n, int k) { if (n < k) return 0; if (n == k) return 1; long long result = 1; for (long long i = max(k, n - k) + 1; i <= n; i++) result *= i; return result / ...