func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int list[n]; int i; for (i = 0; i < n; i++) cin >> list[i]; int total = accumulate(list, list + n, 0); n++; int count = 0; for (i = 1; i <= 5; i++) { if ((total + i) % n != 1) { count++; ...
#include <bits/stdc++.h> using namespace std; struct node { long long l; long long r; long long s; node* ln; node* rn; void change(long long n, long long k) { if (l == r) s += k; else { if (n <= (l + r) / 2) { if (ln == 0) { ln = new node; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int x, y, k; cin >> x >> y >> k; long long int tot = y * k + k; if (x >= tot) { cout << 1 + k << endl; continue; } else if (x == 2) { cout << tot - 1 ...
#include <bits/stdc++.h> using namespace std; int n, k, c[1001], i, x, a, b; int main() { cin >> n >> k; for (int x, i = 1; i <= n; ++i) { cin >> x; c[x]++; } for (i = 1; i <= k; ++i) { a = a + c[i] / 2 * 2; b = b + c[i] % 2; } cout << a + (b + 1) / 2; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6; const int maxv = 4e5; const long long INF = 3e14 + 333; struct Node { int u, v, c; void in() { scanf( %d%d%d , &u, &v, &c); } } wo[maxn]; vector<int> G[maxv], st[maxv], ed[maxv]; int n, m; int dfn = 0; int d[maxv][2]; int ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int pa = a, pb = b, pc = c, pd = d; a = pa; b = pb; c = pc; d = pd; vector<int> ans; if (a > 0) { ans.push_back(0); a--; while (a + b + c + d != 0) { if (...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-12; int main() { int n; double r, v, T; scanf( %d%lf%lf , &n, &r, &v); T = 2 * acos(-1) * r / v; for (int i = 0; i < n; i++) { double s, f, tim, tot = 0; scanf( %lf%lf , &s, &f); tim = (f - s) / v; tot ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; int ans = n; if (k >= n) { cout << 1; } else { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { if (i <= k) { ans = min(ans, n / i); } if (n /...
#include <bits/stdc++.h> using namespace std; int n; char c[1010]; int main() { scanf( %d , &n); scanf( %s , c + 1); c[0] = 0 , c[n + 1] = 0 ; if (n == 1) { if (c[1] == 0 ) return 0 * puts( No ); return 0 * puts( Yes ); } for (int i = 1; i < n; i++) { if (c[i] == 1 ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n, x; cin >> n >> x; int arr[n]; int o, e; o = e = 0; int i = 0; for (int j = 0; j < 10; j+...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, mx = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (a > mx) mx = a; } if (mx - 25 > 0) cout << mx - 25 << endl; else cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, dp[25][1100000], ans = 1e9; char num[25][100005]; int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) scanf( %s , num[i] + 1); for (int i = 1; i <= m; ++i) { int t = 0; for (int j = 1; j <= n; ++j) t = t * 2 + num[j][i] - 0 ; ...
#include <bits/stdc++.h> using namespace std; int main() { long long c, w, v, a, l, pages, days = 1; cin >> c >> v >> w >> a >> l; pages = v; while (pages < c) { v += a; if (v > w) v = w; pages = pages - l + v; days++; } cout << days; }
#include <bits/stdc++.h> using namespace std; int n, k, x, y; struct node { int L, R, e; long long int Lsum, Rsum, Ls, Rs; int mid() { return (L + R) / 2; } } a[200005 * 4]; void BuildTree(int r, int L, int R) { a[r].L = L; a[r].R = R; a[r].e = 0; a[r].Lsum = 0; a[r].Rsum = 0; ...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; const long long BIG = 1446803456761533460LL; const int Big = 336860180; const long long int INF = LONG_LONG_MAX; const long long int adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const long long int adj8[8][2] = {{0, 1}...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int* x = new int[2 * n]; int odd = 0; int even = n; int len = n - 1; for (int len = n - 1, i = 1; len > 0; len--, i++) if (i % 2 == 1) { x[odd] = i; x[odd + len] = i; odd++; ...
#include <bits/stdc++.h> using namespace std; bool issorted(long long int *arr, int n) { int flag = 0; for (int i = 1; i < n; i++) { if (arr[i - 1] > arr[i]) { flag = 1; break; } } if (flag == 0) return true; flag = 0; for (int i = n - 2; i >= 0; i--) { if (...
#include <bits/stdc++.h> using namespace std; int MDA[10000010]; int MDB[10000010]; int main() { long long a, b, m; int i; cin >> a >> b >> m; for (i = 0; i < (min(m, a + 1)); i++) { MDA[i] = (i * 1000000000) % m; } for (i = 0; i < (min(m, b + 1)); i++) { MDB[(i) % m] = 1; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { int n, k; cin >> n >> k; if (k / n > 2) cout << 0 n ; else cout << n - (k % n) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int num[maxn]; map<int, int> mp; int sum[maxn]; int main() { int n, i, j, k; cin >> n; for (i = 1; i <= n; i++) cin >> num[i], sum[i] = sum[i - 1] + num[i]; int s = 0; long long ans = 0; for (i = 1; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; int a[100001], n, num, siz = 0, sq; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; vector<int> kill(n, 1); stack<int> s; s.push(0); kill[0] = 1000000000; for (int i = 1; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int t, n, m, sum; int fa[1000010], sz[1000010]; vector<int> vec[1000010]; int find(int x) { if (x == fa[x]) return x; else return fa[x] = find(fa[x]); } int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using std ::vector; template <typename Tp> Tp Max(const Tp &a, const Tp &b) { return a > b ? a : b; } template <typename Tp> Tp Min(const Tp &a, const Tp &b) { return a < b ? a : b; } template <typename Tp> Tp Abs(const Tp &a) { return a > 0 ? a : -a; } templat...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MAXN = (int)3e5 + 3; const int infint = (int)1e9 + 3; const long long inf = (long long)2e18; struct node { int minf, tedf, mimm, tmimm, mipm, tmipm, min, max, lazymax, lazymin; node() { minf = infint, tedf = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; const int s = 1000000; int n; int b[maxn]; int p[maxn]; int c[maxn]; vector<int> ans; int main() { scanf( %d , &n); int t; for (int i = 0; i < n; ++i) { scanf( %d , &t); b[t] = 1; p[i] = t; } ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MOD = 1e9 + 7; const int N = 0; string s; long long solve(string s) { int n = s.length(); long long ans = 1988; for (auto i = (n - 1); i >= (4); i--) { long long mul = 1, add = 0; for (auto j = (i); j < (n);...
#include <bits/stdc++.h> using namespace std; string name[105], body[105]; int n; string s; int d[105]; map<string, int> macro_id; int add(string& s, int& ptr); void go(int k); int un(string& s, int& ptr) { if (s[ptr] == ( ) { ptr++; int r = add(s, ptr); if (r & 2) r ^= 2; ...
#include <bits/stdc++.h> using namespace std; const int NMAX = 200005; int n; char str[NMAX]; int in, allin; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cin >> n; cin >> str; for (int i = 0; i < n; ++i) if (str[i] == A ) ++allin; else if (str[i] ==...
#include <bits/stdc++.h> int a, b, n; long long ans; int chk[10000010]; int np, pri[10000010]; int lis[10000010], mon[10000010]; void go(int now, int poi) { lis[now] = 1; for (int i = poi; i < np; ++i) { long long t = (long long)now * pri[i]; if (t > n) break; go(t, i + 1); } ...
#include <bits/stdc++.h> using namespace std; const int N = 3009; int box[N], kk; struct node { int t, next; } e[N << 1]; int n; void add(int s, int t) { e[kk].t = t, e[kk].next = box[s]; box[s] = kk++; } int tot; void pre_dfs(int r, int fa) { for (int i = box[r]; i + 1; i = e[i].nex...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; int a[maxn], n, x; int main() { int k; cin >> k; while (k--) { cin >> n >> x; int sum = 0; bool f = 1, f1 = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; if (a[i] != ...
#include<bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count()); #define ii for(int i=1;i<=n;++i) #define ji for(int j=1;j<=n;++j) #define jj for(int j=1;j<=m;++j) #define ij for(int i=1;i<=m;++i) #d...
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int c1, c2; char str[maxn]; int main() { scanf( %s , str); int len = int(strlen(str)); for (int i = 0; i < len; i++) { int t = str[i] - 0 ; if (t == 0) { if (!c1) { puts( 1 1 ); } else ...
#include <bits/stdc++.h> using namespace std; long long labs(long long a) { return a < 0 ? (-a) : a; } long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } const int MAXN = 1005; const int UNDEF = -1; const int IMPOS = INT_MAX ...
#include <bits/stdc++.h> using namespace std; long long a[503400], b[477574], c[534567], d, e, i, j, r, m, y, k, l, n, s, z, x, t, tt; string p[3456], q, qq; map<long long, long long> zz; int main() { cin >> n >> m; for (i = 1; i <= n; i++) cin >> p[i]; cin >> x; q = p[x]; a[x] = 1; ...
#include <iostream> #include <algorithm> #include <vector> using namespace std; typedef vector<int> vi; int n,a[300010],res[300010],gtm[300010]; vi L,R,rm; void solve() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; L.assign(n,0); R.assign(n,0); rm.assign(n + 1, 0); L[0] = 0; for...
#include <bits/stdc++.h> using namespace std; bool need[8000010], rem[8000010]; int n, k, b[8000010], sum[8000010], minl = (int)1e9, out; vector<int> ans; int main() { scanf( %d%d , &k, &n); for (int i = 1; i <= k; i++) scanf( %d , &sum[i]), sum[i] += sum[i - 1]; for (int i = 1; i <= n; i++) scanf...
#include <bits/stdc++.h> using namespace std; int k, t = 0, tt = 0, j = -1; int kk; int main() { cin >> k >> kk; if (k == 5) { cout << >...v << endl; cout << v.<.. << endl; cout << ..^.. << endl; cout << >.... << endl; cout << ..^.< << endl; cout << 1 << ...
#include <bits/stdc++.h> using namespace std; signed long long int a, b; long long int a1, b1, y, s; int main() { cin >> a >> b >> s; if (a >= 0) a1 = a; else a1 = 0 - a; if (b >= 0) b1 = b; else b1 = 0 - b; y = a1 + b1; if (y - s == 0 || (y - s) % 2 == 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int S; cin >> S; string str; cin >> str; for (int i = 0; i < S; i++) cout << str[S - 1]; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; long long gcd(long long a, long long b) { long long r; while (b) { r = a %...
#include <bits/stdc++.h> using namespace std; long long int pow1(long long int a, long long int b, long long int m = 1000000007) { if (b == 0) return 1ll; else if (b == 1) return a; else { long long int x = pow1(a, b / 2, m); x *= x; x %= m; if (b...
#include <bits/stdc++.h> using namespace std; int t; int a[4][100100]; vector<int> beg[4], en[4]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { bool out = 1; int n, noob; cin >> n >> noob; for (int i = 1; i <= 3; i++) { for (int ...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans[1500], t, i, j, v[1100]; memset(v, 0, sizeof(v)); for (i = 2; i * i <= 1100; i++) { if (v[i] == 0) { for (j = i + i; j <= 1100; j += i) v[j] = 1; } } while (scanf( %d , &n) != EOF) { if (n == 1) ...
#include <bits/stdc++.h> using namespace std; const long long int M = 1000000007; long long int mod(long long int x) { return (x % M + M) % M; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, t, c, ans = 0, g = 0, cnt = 0; cin >> n >> t >> c; ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const long double eps = 1e-11; const long double pi = acos(-1); const long lon...
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, i, j, k, d; cin >> n >> m; vector<int> arr(101, 0); for (i = 0; i < m; i++) { int no; cin >> no; arr[no]++; } for (d = m; d >= 1...
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 5002; constexpr int mod = 1e9 + 7; string x, y; int n, m; int cache[N][N]; int dp(int a, int b) { if (b == m) return 0; int &rv = cache[a][b]; if (~rv) return rv; rv = dp(a, b + 1); if (x[a] == y[b]...
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x7fffffffffffffff; const double eps = 1e-10; unsigned int seed = 19260817; const unsigned int _RAND_MAX_ = 4294967295u; __inline__ __attribute__((always_inline)) unsigned int Rand() { return seed = seed * 99824...
#include <bits/stdc++.h> using namespace std; struct $ { $() { ios_base::sync_with_stdio(false); cin.tie(NULL); } } $; const int Maxn = 202005; class BIT { int *tree, sz; public: BIT() { sz = 202005; tree = new int[sz + 1]; } BIT(int N) { sz = N; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 65; const int MAXB = 10; const int MAXS = (1 << 10) + 7; int q; int b; long long l, r; in...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 7; const int mod = 1e9 + 7; map<int, int> mp; int n, x, ma, ans; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &x); mp[x]++; } for (auto p : mp) { int x = p.first, y = p.second; ...
#include<iostream> #include<cstdio> #include<fstream> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<bitset> #include<cmath> #include<cstring> #include<cstdlib> using namespace std; typedef long long LL; typedef double DB; const int N = 222222; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long N = 200005; int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1}; int dy[] = {0, -1, 0, 1, 1, -1, 1, -1}; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>=...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e7 + 10; int n, fac[MAX_N], pri[MAX_N], pri_n, fac_cnt[MAX_N], phi[MAX_N]; long long ans; void init() { scanf( %d , &n); for (int i = 2; i <= n; i++) { if (!fac[i]) { phi[i] = (fac[i] = pri[++pri_n] = i) - 1; fac_cn...
#include <bits/stdc++.h> using namespace std; struct ASDF { ASDF& operator,(int& a) { scanf( %d , &a); return *this; } ASDF& operator,(long int& a) { scanf( %ld , &a); return *this; } ASDF& operator,(long long int& a) { scanf( %lld , &a); return *this; } ...
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long read() { long long s = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { s = s * 10 + ch - 0 ; ch = getchar(...
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> inline bool smin(S &l, T r) { return r < l ? l = r, 1 : 0; } template <typename S, typename T> inline bool smax(S &l, T r) { return l < r ? l = r, 1 : 0; } constexpr int MOD = 1e9 + 7; template <typename S> inlin...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long a, b, k; cin >> a >> b >> k; if (k % 2 == 0) cout << a * (k / 2) - b * (k / 2) << n ; else ...
#include <bits/stdc++.h> using namespace std; long long int cnt[7]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, i, a, x; bool test = true; vector<pair<long long int, pair<long long int, long long int>>> v; cin >> n; for (i = 0; i <...
/*#pragma GCC target ( avx2 ) #pragma GCC optimization ( O3 ) #pragma GCC optimization ( unroll-loops ) */ #include<bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} v...
#include <bits/stdc++.h> using namespace std; long long int n, m; long long int power(long long int a, long long int b) { if (b == 0) return 1; long long int sr = power(a, b >> 1); long long int r = sr * sr; if (b & 1) r = a * r; return r; } void solve() { long long int z = power(2, 0)...
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 5; long long n, m; vector<vector<long long> > g(N, vector<long long>()); vector<long long> d(N, 0), last(N, -1); vector<long long> path; long long k = 0; vector<bool> in_path(N, 0); vector<pair<long long, long long> > pairs; lon...
#include <bits/stdc++.h> using namespace std; int read() { char ch = getchar(); int f = 0, x = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) x = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { f = (f << 1) + (f << 3) + ch - 0 ; ch = getchar(); } return ...
#include <bits/stdc++.h> using namespace std; bool check(string cards, int a, int b) { bool isValid = false; for (int j = 0; j < b && !isValid; j++) { int shift = 0; isValid = true; for (int i = 0; i < a; i++, shift += b) { if (cards[shift + j] != X ) { isValid = false; ...
#include <bits/stdc++.h> using namespace std; const int oo = 1e9 + 9; const long long inf = 1e18 + 18; const int max6 = 1e6 + 6; const int modx = 1e9 + 123; const int mody = 997; const int base = 137; int t[max6]; int n, k; bool ok(int l, int r) { int cnt = 0; for (int i = l; i <= r; ++i) cn...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &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; ...
#include <bits/stdc++.h> using namespace std; map<int, int> m; int main() { int a, t, n, i, j, k, l, mn = INT_MAX, mx = 0; cin >> n >> k; int cnt = 0; int ans = 0; for (int i = 0; i < n; i++) { cin >> a; mn = min(mn, a); m[a]++; } int p = mn; while (p < k) { ...
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238; const double EPS = 1e-6; void solve() { long long r, g, b, w; cin >> r >> g >> b >> w; long long total = r + g + b + w; long long odd = 0; odd = r % 2 + g % 2 + b % 2 + w % 2; long long col = r && ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t,n,k; string x= abc ; cin>>t; while(t--) { cin>>n>>k; string s,h; for(int i=0;i<n-k;i++) { s+=x[i%3]; } char c=x[(n-k)%3]; while(k--) { s+=c; } cout...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s = ; for (int i = 0;; i++) { bool flag = 1; for (int j = i * k; j < (i + 1) * k; j++) { s += ( a + j - i * k); if (j =...
#include <bits/stdc++.h> using namespace std; void start() {} void sober() { long long int n, x = 0, a = 0, b = 0, y = 0, sum = 0, k = 0, m = 0; cin >> n >> a >> b; string s; cin >> s; a--, b--; if (s[a] == s[b]) cout << 0 n ; else cout << 1 n ; } signed main() { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int a[maxn]; unordered_map<int, int> b, c; unordered_map<int, int>::iterator it, it2; vector<int> ans; int main() { ios_base::sync_with_stdio(0); int n, m, p; cin >> n >> m >> p; int x; for (int i = 0; i < n; ++i) c...
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; char s[200]; vector<int> __v; __v.assign(1000000, 127); cin >> s; int n; cin >> n; set<int> n_del[ z - a + 1]; set<int>::iterator pos_n_del[ z - a + 1]; for (int i = 0; i < n; i++) { c...
#include <bits/stdc++.h> using namespace std; const int dx[4] = {0, 1, -1, 0}, dy[4] = {-1, 0, 0, 1}; int n, m; char g[60][60]; bool col[60][60][2][4]; bool tmp[60][60][2][4]; bool inrange(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } void solve(int x, int y, int turn, int dir) { int ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef string ss ; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef vector<int> vi; typedef vector<ll> vl; #define mp make_pair #define pb push_back void solve(){ ll n,k=0,...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 17; int N, Q; int main() { ios_base::sync_with_stdio(false); cin >> Q; while (Q--) { cin >> N; long long mx; cin >> mx; long long diff = 0; while (--N) { long long x; cin >> x; ...
#include <bits/stdc++.h> using namespace std; int n, p; string msg, s[100001], h = <3 ; int sub(int &i, string &w) { int k = 0; for (; k < w.length() && i < msg.length(); i++) { if (w[k] == msg[i]) { ++k; } } return k == w.length(); } int main() { ios_base::sync_with...
#include <bits/stdc++.h> using namespace std; const int OO = 1e9; const double EPS = 1e-9; const int MX = 1e6 + 5; int p = 1299709, n, m, u, v; vector<vector<int>> adj(MX); unsigned long long pPw[MX], M = 1000000009, Hash[MX]; int main() { ios::sync_with_stdio(false); cout.precision(10); cin...
#include <bits/stdc++.h> using namespace std; int a[200], ans[200]; int v[1000001]; int main() { int T, n; cin >> T; while (T--) { memset(v, 0, sizeof v); scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + n + 1); for (int i = 1; i <= n; i...
#include <bits/stdc++.h> using namespace std; template <class T> istream& operator>>(istream& is, vector<T>& v) { for (T& x : v) is >> x; return is; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { if (!v.empty()) { os << v.front(); for (int i = 1; i < v.si...
#include bits/stdc++.h using namespace std; string alpha[26] = { 1 0 0 1 0 , 1 1 0 2 0 , 2 0 0 1 1 , 2 1 0 1 2 , 1 1 0 1 1 , 2 1 0 2 1 , 2 2 0 2 2 , 1 2 0 2 1 , 1 1 0 1 1 , 1 2 0 1 2 , 1 0 1 2 0 , 1 1 1 3 0 , 2 0 1 2 1 , 2 1 1 2 2 , 1 1 1 2 1 , ...
#include <bits/stdc++.h> using namespace std; char c[503][503]; vector<pair<int, int> > v[503][503]; int main() { int n, m, k; cin >> n >> m >> k; int s = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> c[i][j]; if (c[i][j] == . ) s++; } }...
#include <bits/stdc++.h> using namespace std; const int N = 32, M = 2e5 + 10; int q[N], qz[M]; bool insert(int x) { for (int i = N - 1; i >= 0; --i) { if ((x >> i) & 1) { if (!q[i]) { q[i] = x; return true; } else x ^= q[i]; } } return false;...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, a[N], b[N], c[N]; multiset<int> S; multiset<int>::iterator it; int main() { std::ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) cin >> a[i], c[a[i]] = i; for (int i = 0; i < n; i++) cin >> b[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); long long n, i, j; cin >> n; vector<long long> v(n / 2); for (i = 0; i < v.size(); i++) { cin >> v[i]; } sort(v.begin(), v.end()); long long mn = LLONG_MAX; j = 1; ...
#include <bits/stdc++.h> using namespace std; const unsigned long long hash1 = 201326611; const double eps = 1e-8; const long long INF = 0x3f3f3f3f3f3f3f3f; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const int N = 255; const int M = 12; const int dif = 26; const double PI = acos(-1.0...
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int getChar() { static char buf[1 << 16]; static int pos = 0, size = 0; if (pos == size...
#include <bits/stdc++.h> using namespace std; long long n, m, s, e, v, q; vector<long long> vs, ve; int32_t main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n >> m >> s >> e >> v; vs.resize(s), ve.resize(e); for (auto& u : vs) { cin >> u; } for (auto& u : ve) { cin >> u; ...
#include <bits/stdc++.h> using namespace std; long long w[1000000], w1[100000]; long long t[1000000]; pair<long long, long long> ans; long long a, b, c, n, m, q, k, x, c1, b1; long long poww(long long x, long long y) { if (x == 0) return 0; if (x == 1) return 1; if (y == 0) return 1; if (y =...
#include <bits/stdc++.h> using namespace std; int main() { string s = ROYGBIV ; long long int n, i; cin >> n; for (i = 0; i < n - 3; i++) { cout << s[i % 4]; } cout << BIV ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int sum = 100; bool res = false; for (int i = 0; i < n; i++) { int temp1, temp2; cin >> temp1 >> temp2; if (temp1 < s) { res = true; if (temp2 != 0 && temp2 < sum) sum = temp2; ...
#include <bits/stdc++.h> using namespace std; const int dx[8] = {0, -1, 0, 1, 1, -1, -1, 1}; const int dy[8] = {-1, 0, 1, 0, -1, -1, 1, 1}; const long long mod = 1000000007; const int base = 311; const int N = 6e5 + 5; map<long long, vector<pair<int, int>>> e; int n, m; long long a[N]; vector<int> d...
#include <bits/stdc++.h> using namespace std; int n; long long ans, X, Y, s[200010], w[30], t, A[131072], B[131072]; inline long long gcd(long long a, long long b) { for (long long c; b; a = b, b = c) c = a % b; return a; } int main() { scanf( %d%lld%lld , &n, &X, &Y); for (int i = 1; i <= n...
#include <bits/stdc++.h> using namespace std; double x[1005], y[1005], z[1005], r[1005]; long long int n, m; int main() { double res = (1ll << (long long int)(60)), ax, ay, az, vx, vy, vz, R; cin >> ax >> ay >> az >> vx >> vy >> vz >> R >> n; for (long long int i = 0; i < ((long long int)(n)); i++) ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 20; vector<int> a[N]; vector<int> Q; int t, x, p, k; int solve(int n, int p) { int ret = 0; Q.clear(); Q.push_back(-1); vector<int>& f = a[p]; for (int i = 0; i < (int)f.size(); ++i) { int top = Q.size(); for (...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; } inline int read() { int x(0), sgn(1); char ch(getchar()); for (; !is...
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0); void solve(void) { string str; cin >> str; int one = 0, zero = 0; for (int i = 0; i < str.length(); i++) { if (str[i] == 1 ) { one++; while (i < str.length() && str[i] == 1 ) i++; i--; ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline string tostring(const T &x) { ostringstream os; os << x; return os.str(); } inline int toint(const string &s) { istringstream is(s); int x; is >> x; return x; } inline int todecimal(string s) { int a...
#include <bits/stdc++.h> #pragma GCC optimize( inline,Ofast , 3) #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline ) #pragma GCC optimize( -fgcse ) #pragma GCC optimize( -fgcse-lm ) #pragma GCC optimize( -fipa-sra ) #pragma GCC optimize( -ftree-...