func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; inline int read() { int 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 * 10 + (ch - 0 ); ch = getchar(); } return...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; while (t--) { int n, a[100005]; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; int MIN = INT_MAX, MAX = -100; f...
#include <bits/stdc++.h> using namespace std; double sqr(double x) { return x * x; } double distsqr(double x, double y, double a, double b) { return sqr((x - a)) + sqr((y - b)); } double cosine_angle(double a, double b, double c) { return (double)(sqr(a) + sqr(b) - sqr(c)) / ((double)2.0 * a * b); }...
#include <bits/stdc++.h> template <typename T> extern inline void SWAP(T &a, T &b) { T t = a; a = b, b = t; } const int MAXN = 500005; const int MAXBIT = 20; const int MEMBIT = MAXBIT + 5; int bas[MEMBIT], pos[MEMBIT], n, rt, a[MAXN], q; struct quest { int lt, rt, id; bool operator<(cons...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> s(n); for (int i = 0; i < n; ++i) cin >> s[i]; int answer = 0; for (int col = 0; col < (int)s[0].size(); ++col) { bool is_sorted = true; for (int i = 0; i < n - 1; ++i) { if...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n + 1, 0); vector<vector<int> > g(n + 1); int i, j, k; for (i = 1; i <= n; i++) { cin >> j >> k; v[i] = k; if (j != -1) { g[j].push_back(i); } } vector<int> ans; ...
#include <bits/stdc++.h> using namespace std; int n, t; int main() { cin >> n >> t; if (n == 1 && t == 10) { cout << -1; return 0; } if (t == 2) { for (int i = 0; i < n - 1; i++) { cout << 9; } cout << 2; return 0; } if (t == 3) { for (int ...
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323846; long long MOD = 1e9 + 7; const char nl = n ; const long long inf = 1e15; long long power(long long x, long long y) { long long z = 1; while (y > 0) { if (y % 2) z = z * x; x = x * x; y /=...
#include <bits/stdc++.h> using namespace std; int n, s, K, r[55], f[55][2555]; char col[55]; pair<int, int> p[55]; inline void Umn(int &x, int y) { x = min(x, y); } int main() { scanf( %d%d%d , &n, &s, &K); for (int i = 1; i <= n; ++i) scanf( %d , &r[i]); scanf( %s , col + 1), col[0] = & ; ...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(51); long long ask(long long a, long long b, long long c) { cout << ? << a << << b << << c << endl; long long p; cin >> p; return p; } signed main() { long long t; cin >> t; while (t--) { long long n, bad = ...
#include <bits/stdc++.h> long long int p = 1e9 + 7; long long int power(long long int x, long long int y) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { long long int n, k; ...
#include <bits/stdc++.h> using namespace std; struct event { int t, l, r, v; }; void solve() { int n, q; cin >> n >> q; vector<event> e(q); vector<int64_t> a(n, INT_MAX), upd(n, 0); for (int i = 0; i < q; ++i) { cin >> e[i].t; cin >> e[i].l; cin >> e[i].r; cin >> ...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int main() { int n; cin >> n; string a, b; cin >> a >> b; int x[n], y[n]; for (int i = 0; i < n; i++) { x[i] = a[i] - 0 ; y[i] = b[i] - 0 ; } sort(x, x + n); sort(y, y + n); int px = 0, py = ...
#include <bits/stdc++.h> using namespace std; int t, n, num[10], tu[500], fir[10], flag[10]; char ss[1000005]; struct node { int v[5]; }; vector<node> p[100005]; map<long long, bool> ma[100005]; int main() { tu[ G ] = 1; tu[ H ] = 2; tu[ R ] = 3; tu[ S ] = 4; scanf( %d , &n); ...
#include <bits/stdc++.h> using namespace std; const int maxN = 1000100; const int Num = 999999; const int Mod = 1e9 + 7; int n; int Sm1[maxN], Sm2[maxN], Sm3[maxN]; void Plus(int &x, int y); void Minus(int &x, int y); int QPow(int x, int cnt); int main() { scanf( %d , &n); for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; int n, s, x1, x2, v1, v2, w, d, ans; int main() { cin >> s >> x1 >> x2 >> v1 >> v2 >> w >> d; ans = abs(x1 - x2) * v2; if (d == 1) { if (w < x2) { if (x1 < x2) { if (x1 >= w) ans = min(ans, (x2 - w) * v1); else...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[111]; long long int dp[105][105][3010]; int n, l; long long int cal(int pre, int ind, int rem) { if (rem == 0) return 1; if (rem < 0) return 0; long long int &ret = dp[pre][ind][rem]; if (ret != -1) return ret; ret++; for (...
#include <bits/stdc++.h> using namespace std; int N, K; char s[1100000]; int cnt[1100000][3], tot[1100000]; int pb[1100000], pw[1100000]; bool can(int p, int f) { if (p < K) return false; if (f) { if (p - pb[p - 1] - 1 < K) return false; if (p > K && s[p - K - 1] == W ) return false; ...
#include <bits/stdc++.h> using namespace std; char grid[10][10]; bool colW[10], colB[10]; int main() { int Case = 1; int l, p, q; char dump[2]; while (gets(grid[1])) { for (int i = 2; i <= 8; i++) { gets(grid[i]); } memset(colB, false, sizeof(colB)); memset(colW, ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 5 + 1e5; int main() { int a, b, c, m, ans = 0; ios::sync_with_stdio(0); cin.tie(); cin >> a >> b; c = a - b; if (c < 0) cout << 0; else if (c == 0) cout << infinity ; else { ...
#include <bits/stdc++.h> using namespace std; int num(string s) { if (s == 00 ) return 0; if (s == 10 ) return 2; if (s == 11 ) return 3; return 1; } void solve(int x) { vector<int> v[4], vv[4]; int n; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { string s; ...
#include <bits/stdc++.h> using namespace std; int k; struct node { int ma[10]; int mi[10]; int cnt = 1; bool operator==(const node &a) const { bool f0 = false, f1 = false; for (int i = 0; i < k; ++i) { if (ma[i] > a.mi[i]) f0 = true; if (mi[i] < a.ma[i]) f1 = true; ...
#include <bits/stdc++.h> using namespace std; const int Max = 510; int arr[Max][Max]; int ps[Max][Max]; bool check(int i, int j); int calcPs(int minX, int minY, int maxX, int maxY); int main() { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) { string s; cin >> s; ...
#include <bits/stdc++.h> using namespace std; char s[1000005]; int main() { int n, k; while (scanf( %d%d , &n, &k) != EOF) { if (k > n || (n > 1 && k == 1)) { printf( -1 n ); break; } else { if ((n - k) % 2) { for (int i = 1; i <= n - k + 1; i++) { ...
#include <bits/stdc++.h> using namespace std; template <class T> string toStr(const T &x) { stringstream s; s << x; return s.str(); } template <class T> int toInt(const T &x) { stringstream s; s << x; int r; s >> r; return r; } const double pi = acos(-1); const double P...
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == - ) nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, i, n, x, j; cin >> t; while (t--) { cin >> n; vector<int> a, b; for (i = 0; i < n; i++) { cin >> x; a.push_back(x); } for (i =...
#include <bits/stdc++.h> struct XD { double x, y, z; void input() { scanf( %lf%lf%lf , &x, &y, &z); } XD operator+(const XD& b) const { XD a; a.x = x + b.x; a.y = y + b.y; a.z = z + b.z; return a; } }; XD a, v; double r; inline double MIN(double a, double b) { ret...
#include <bits/stdc++.h> bool compare(int a, int b) { return a < b; } void swapped(char s1, char s2) { char temp = s1; s1 = s2; s2 = temp; } long long int modd(long long int n, long long int k) { return (k + (n % k)) % k; } bool i(long long first) { return first && (!(first & (first - 1))); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, mn, mx; cin >> n >> m >> mn >> mx; set<int> temp; for (int i = 0; i < m; ++i) { int x; cin >> x; temp.insert(x); } if (*temp.begin() < mn or *temp.rbegin()...
#include <bits/stdc++.h> using namespace std; int x, s, t; int main(void) { cin >> t >> s >> x; int a = (x - t) / s; if (t == x) { cout << YES << endl; } else if (a <= 0) { cout << NO << endl; } else if (t + a * s == x || t + a * s + 1 == x) { cout << YES << endl; }...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const int oo = 0x3f3f3f3f; inline long long read() { char ch = getchar(); int x = 0, f = 1; while (ch > 9 || ch < 0 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x...
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int INF((1 << 30) - 1); const int MAXN(30); string a[MAXN]; int type[200] = {0}; int main() { int n, m, x; scanf( %d%d%d , &n, &m, &x); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = A ; i <= Z ; i++) t...
#include <bits/stdc++.h> int dp[51 * 10001]; int main(void) { int n, d, a, sum, i, j; while (scanf( %d%d , &n, &d) != EOF) { sum = 0; memset(dp, 0, sizeof(dp)); dp[0] = 1; for (i = 0; i < n; i++) { scanf( %d , &a); sum += a; for (j = sum; j >= a; j--) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 150000; struct node { long long l, r, sm, mx; } tr[4 * maxn]; inline node comb(node ll, node rr) { node ret; ret.l = max(ll.l, ll.sm + rr.l); ret.r = max(rr.r, rr.sm + ll.r); ret.sm = ll.sm + rr.sm; ret.mx = max(max(ll.mx, ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); long long chess[5][2004][2004]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int N, r1, r2, c1, c2; cin >> N; for (int i = 1; i < N + 1; i += 1) for (int j = 1; j < N + 1; j += 1) cin ...
#include <bits/stdc++.h> //#define int long long #define pii pair<short, int> #define x1 x1228 #define y1 y1228 #define left left228 #define right right228 #define data data228 #define pb push_back #define eb emplace_back #define mp make_pair ...
#include <bits/stdc++.h> using namespace std; long long int a[300009]; vector<pair<pair<long long int, long long int>, pair<long long int, long long int>>> v; long long int ans = 1; vector<int> vec; bool check(int idx, long long int mid) { long long int dist, i, j, x, fuel = mid, cnt...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int node[(ll)(1e5 + 7)], in[(ll)(1e5 + 7)], out[(ll)(1e5 + 7)], ti = 1, hie[(ll)(1e5 + 7)]; int dp[(ll)(1e5 + 7)][17]; vector<int> gr[(ll)(1e5 + 7)], hi[(ll)(1e5 + 7)]; void dfs(int node, int h) { hi[h].p...
#include <bits/stdc++.h> using namespace std; int x[110000]; char str[110000]; long long tail[110000], a[110000], b[110000], c[110000], sum[110000], cm1[110000], cm2[110000]; int n, m; const long long MOD = 1000000007L; long long mod_reset(long long x) { return (x % MOD + MOD) % MOD; } void extgcd...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const double PI = 3.141592653589793238463; const int MAXN = 100005; long long n, s; long long temp = 0; long long arr[MAXN]; bool ok(long long mid) { long long tArray[n]; for (long long i = 0; i < n; i++) { tArray...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e3; int ans[MAXN]; char s[MAXN]; void solve() { int n; cin >> n; int k, num; int s12, s13, s23; cout << ? << 1 << << 2 << endl; scanf( %d , &s12); cout <<...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int r, g, b; cin >> r >> g >> b; int a[3] = {r, g, b}; int i = 0; while (a[0] > 0 || a[1] > 0 || a[2] > 0) { if (a[i % 3] > 0) a[i % 3] -= 2; i++; } cout << 30 ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 1; int MOD = 1e9 + 7; const int INF = 1e9; const long long LINF = 1e18; void solve() { int n; cin >> n; string s; cin >> s; vector<int> a; int ans = 0; bool ok = true; bool all_s = true; vector<int> pre...
#include <bits/stdc++.h> long long ans, fac[101000], fac_inv[101000], sum, nn; int n, k, len; char s[101000]; inline long long C(int x, int y) { if (x < y || x < 0 || y < 0) return 0; if (y == 0) return 1; return fac[x] * fac_inv[y] % 1000000007 * fac_inv[x - y] % 1000000007; } inline long long ...
#include <bits/stdc++.h> using namespace std; map<char, int> mp; map<char, int> mp1; map<char, int> mp2; long long frq[100002] = {}; bool lol = true; int main() { bool u = false; long long x, y, p; scanf( %lld%lld , &x, &y); long long num = y, sum = 0; if (x == 1 && y == 10) { pr...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; int n; cin >> n >> a >> b; int T[n], pom[n]; for (int i = 0; i < n; ++i) T[i] = -1; for (int i = 0; i < n; ++i) { bool ud = false; for (int j = 0; j < n; ++j) { if (T[j] == -1 && a[j] == b[i]) { ...
#include <bits/stdc++.h> template <class T> std::vector<T> ReadVector(size_t size) { std::vector<T> vector(size); for (auto& element : vector) { std::cin >> element; } return vector; } int64_t divisor(int64_t x) { for (int64_t d = 2; d * d <= x; ++d) { while (x % d == 0) { ...
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = RDLU ; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? YES : NO ); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { assert(y >=...
#include <bits/stdc++.h> using namespace std; char a[130000]; struct gg { int x, y, z; } b[130000]; int cmp(gg p, gg q) { return p.z < q.z; } void solve() { int n, m; cin >> n >> m; cin >> a; int l = 0; int p = 0, q = 0, o = 0; for (int i = 0; i < n; i++) if (a[i] == W ) {...
#include <bits/stdc++.h> struct point { int x, l; } pp[1000000 * 2]; int qq[1000000 * 2], sk; int pcompare(const void *a, const void *b) { struct point *pa = (struct point *)a; struct point *pb = (struct point *)b; return pa->x != pb->x ? pa->x - pb->x : pb->l - pa->l; } void sort(struct poi...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); long long f[110][110]; long long n, k; char s[110]; long long ch2i[225]; long long ich2i[110][225]; int main() { cin >> n >> k; scanf( %s , s); for (int i = a ; i < z + 1; i++) { ch2i[i] = -1; } for ...
#include <bits/stdc++.h> using namespace std; long long a, b, sol; int main() { sol = 1; scanf( %lld%lld , &a, &b); sol *= ((1LL) << __builtin_popcountll(b)); if (((a - b) & 1) || (((a - b) >> 1) & b)) { puts( 0 ); return 0; } if (a == b) sol -= 2; if (!(a & 1) && !b) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 110, MAXK = 22, mod = 1000000007; struct edge { int adj, next; } e[MAXN << 1]; int n, k, f[MAXN][MAXK << 1]; int tot, head[MAXN], temp[MAXK << 1]; inline void AddEdge(int u, int v) { tot++; e[tot].adj = v, e[tot].next = head[u]; ...
#include <bits/stdc++.h> using namespace std; const int N = int(500 * 1000 + 7); int n, k; vector<pair<int, int> > adj[N]; long long dp[N][2]; void dfs(int v, int p = -1) { vector<long long> x; long long curr = 0; for (auto it : adj[v]) { int to = it.first; int w = it.second; i...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const long long ooo = 9223372036854775807ll; const int _cnt = 1000 * 1000 + 7; const int _p = 1000 * 1000 * 1000 + 7; const int N = 200005; const double PI = acos(-1.0); const double eps = 1e-9; int o(int x) { return x % _p; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, c; long long t, a; scanf( %d%lld%d , &n, &t, &c); int ans = 0, tmp = 0; for (int i = 0; i < n; i++) { scanf( %lld , &a); if (a > t) { tmp = 0; } else { tmp++; if (tmp >= c) { ans...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, p, q, mx = 0, sm = -1, smc = 0, cnt = 0, n; scanf( %d , &n); int arr[n + 5]; int a[100050]; memset(a, 0, sizeof(a)); for (i = 0; i < n; i++) { scanf( %d , &p); a[p]++; arr[i] = p; } sort(arr, ar...
#include <bits/stdc++.h> using namespace std; long long mas[200100], k, s = 0, d; long long n, p = 1, del = 0, a, b, c; unsigned long long inf = (unsigned long long)1000000000 * 1000000000 * (long long)10; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) scanf( %I64d , &mas[i]); for ...
#include <bits/stdc++.h> using namespace std; int t, n, a[1000], k; int main() { cin >> t; while(t--) { cin >> n >> k; if(k <= (n - 1)/2) { int spt = 0, spt1 = k + 1; for(int i = 1; i <= 2*k + 1; i++) { i...
#include <bits/stdc++.h> using namespace std; struct node { char ch; int val; int idx; node(char ch = a , int val = -1, int idx = 0) : ch(ch), val(val), idx(idx) {} }; void swap(node& a, node& b) { node temp(a.ch, a.val, a.idx); a = b; b = temp; } void disp(vector<node>& arr) { ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; int t[m], l[m], r[m]; int a[n + 1]; fill_n(a, n + 1, -1); a[0] = 1e5; for (int i = 0; i < m; i++) { cin >> t[i] >> l[i] >> r[i]; ...
#include <bits/stdc++.h> const int MAX = 1e3 + 11; using namespace std; char A[MAX]; int W[33]; int main() { scanf( %s , (A)); int(K); scanf( %d , &K); for (int i = 0; i < (26); ++i) scanf( %d , &(W[i])); int mx = 0, N = int(strlen(A)); int v = *max_element(W, W + 26); for (int i =...
#include <bits/stdc++.h> using namespace std; int i, j, n; int a[1005]; string s; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cin >> n; n--; cin >> s; for (i = 0; i <= n; i++) a[i] = 1; for (i = 0; i < n; i++) { if (s[i] == = ) a[i + 1] = a[i]; if (s[i] == R ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); template <class T> void R(T &x) { cin >> x; } void R(int &x) { scanf( %d , &x); } void R(long long &x) { scanf( %lld , &x); } void R(double &x) { scanf( %lf , &x); } void R(char &x) { scanf( %c , &x); } void R(char *x) ...
#include <bits/stdc++.h> using namespace std; int a[111][111][11], n, q, c, x, y, rx, ry, t, v; int main() { cin >> n >> q >> c; for (int i = 1; i <= n; i++) { cin >> x >> y >> t; a[x][y][t]++; } for (int l = 0; l <= c; l++) { for (int i = 1; i <= 100; i++) for (int j = 1...
#include<set> #include<map> #include<stack> #include<cmath> #include<queue> #include<cstdio> #include<vector> #include<climits> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define LL long long using namespace std; LL read(){ bool f=0;LL x=0;char c=getchar();...
#include <bits/stdc++.h> using namespace std; int n, ans, Max, an, x; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &x); if (Max < x) { Max = x; ans = 0; an = 0; } if (x == Max) an++; else an = 0; ans = ...
#include <bits/stdc++.h> int main() { unsigned short n; unsigned short ac1; unsigned short i; unsigned short w; unsigned short ac2; unsigned short gw; if (scanf( %hu , &n) != 1) return -1; if (n < 1 || n > 100) return -1; ac1 = 0; for (i = 0; i < n; i++) { if (scanf( %hu ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int maxN = 1005; long long x[maxN], y[maxN]; long long det(int i, int j, int k) { return (x[j] - x[i]) * (y[k] - y[i]) - (x[k] - x[i]) * (y[j] - y[i]); } long long askArea(int i, int j, int k) { cout << 1 << << i <<...
#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; constexpr int maxn = 2e5 + 10, N = 260, M = 5e6 + 10; constexpr int MAX_INF = 0x3f3f3f3f; int mp[maxn]; int main() { int T; cin >> T; while (T--) { int n, m; scanf( %d%d , &n, &m); int root = 0; memset(mp, 0, sizeof(mp)); ...
#include <bits/stdc++.h> using namespace std; int n, hp = 0, row[100], col[100]; char cake[101][101]; int main() { for (int i = 0; i < 100; ++i) { row[i] = 0, col[i] = 0; } cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> cake[i][j]; if (ca...
#include <bits/stdc++.h> using namespace std; int n, a[100001], b[100001]; void solve(int first) { vector<int> ans(1, first); for (int i = 1; i < n; i++) { int pre = ans.back(); for (int j = 0; j <= 3; j++) { if ((pre & j) == b[i] && (pre | j) == a[i]) { ans.push_back(j); ...
#include <bits/stdc++.h> using namespace std; int n, m; int a[111]; int b[111]; int main() { cin >> n >> m; int s = 0; for (int i = 0; i < n; i++) { cin >> a[i]; s ^= a[i]; } int tmp = 0; for (int i = 0; i < m; i++) { cin >> b[i]; tmp ^= b[i]; } if (tmp ...
#include <bits/stdc++.h> using namespace std; int main() { int n, temp; cin >> n; string s; cin >> s; temp = n; for (int i = n - 2; i >= 0; i--) { if (s.substr(i, 2) == 10 || s.substr(i, 2) == 01 ) { temp -= 2; s.erase(i, 2); i++; } } cout << te...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; map<int, bool> a; for (int i = 0, j; i < n; i++) { cin >> j; a[j] = 1; } int k = 0; vector<int> l; for (int i = 1; m - i >= 0; i++) if (!a[i]) { l.push_back(i); m -= ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, q, t = 1; int lson[N * 2], rson[N * 2], vm[2][N * 2], ovl[N * 2]; set<pair<int, int> > sm[2][N * 2]; map<int, int> op[N * 2]; void build(int pos, int x, int y) { vm[1][pos] = m + 1; if (x == y) return; int mid = (x ...
#include <bits/stdc++.h> using namespace std; void solve() { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2 && y1 == y2) { cout << 10 ; return; } if (x1 == x2) { cout << 2 * (abs(y2 - y1) + 1) + 4; return; } if (y1 == y2) { cout << 2 * (abs(x...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int N = 1 << 7, M = 1 << 14; i...
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int M = 400005; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 0 ; ch = getch...
#include <bits/stdc++.h> using namespace std; template <typename T, typename TT> ostream& operator<<(ostream& s, pair<T, TT> t) { return s << ( << t.first << , << t.second << ) ; } template <typename T> ostream& operator<<(ostream& s, vector<T> t) { for (int(i) = 0; (i) < (sz(t)); ++(i)) s << t...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string name, a; vector<pair<int, string> > s; vector<pair<int, string> > v(n); for (int i = 0; i < (int)n; i++) cin >> v[i].second >> v[i].first; sort(v.begin(), v.end()); int h = 1e9; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, k; cin >> n >> k; long long int ans = 0; if (n < k) { cout << n << endl; continue; } while (n != 0) { if (n % k == 0) { n = n /...
#include <bits/stdc++.h> using namespace std; const int N = 111; const double INF = 1e200; double dp[N][10 * N]; struct problem { int a, p; bool operator<(const problem &o) const { return a > o.a; } } p[N]; int n; double C, T; double solve(double x) { x /= 0.9; auto t = (sqrt(C * x) - ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[101], ans = 0; cin >> n; bool flag = false; for (int i = 1; i <= n; i += 1) { cin >> a[i]; if (a[i] == 100) flag = true; ans += a[i]; } if (ans % 200 == 100) cout << NO << endl; else { if ...
#include <bits/stdc++.h> using namespace std; const int N = 10 * 100 * 1000 + 10; vector<int> vec[N]; int bit[N]; int n, c; void addbit(int i, int p) { for (i++; i <= c; i += (i & -i)) bit[i] += p; } int get(int i) { int x = 0; for (i++; i > 0; i -= (i & -i)) x += bit[i]; return x; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; scanf( %i , &n); int a = n / 3, b = n - a; for (i = 1; i <= b; i++) printf( 1 %i n , i); for (i = 1; i <= a; i++) printf( 4 %i n , i * 2); return 0; }
#include <bits/stdc++.h> using namespace std; int n; string s, ret; bool dfs(int idx, int four, int seven, bool flag) { if (idx == n) return true; if (flag) { for (int i = 0; i < four; i++) ret[idx + i] = 4 ; for (int i = four; i < four + seven; i++) ret[idx + i] = 7 ; return true; ...
#include <bits/stdc++.h> using namespace std; inline void Routine() { srand(time(NULL)); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } template <class T, class U> istream &operator>>(istream &in, pair<T, U> &p) { in >> p.fi >> p.se; return in; } template <class...
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; using namespace std::chrono; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; string s; cin >> s; long long int a[26]; for (int i = 0; i < 26; i++) cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; vector<string> s; vector<pair<int, int> > v; int gf = 0; int x[9] = {-1, -1, -1, 0, 1, 1, 1, 0, 0}; int y[9] = {-1, 0, 1, 1, 1, 0, -1, -1, 0}; void dfs(int a, int b, int le) { if (gf) return; if (le == 8 || (a == 0 && b == 7)) { gf = 1; ret...
#include <bits/stdc++.h> using namespace std; struct Wall { int l, r, t; void init(int _l, int _r, int _t) { l = _l, r = _r, t = _t; } void input() { scanf( %d%d%d , &l, &r, &t); } static bool by_l(const Wall &a, const Wall &b) { return a.l < b.l; } bool operator<(const Wall &a) const { return t...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int a[200001]; int i; for (i = 0; i < n; i++) { scanf( %d , &a[i]); } long long buy = a[n - 1]; int pre = a[n - 1]; for (i = n - 2; i >= 0; i--) { if (a[i] >= pre - 1) { if (pre - 1 == 0) br...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); set<string> s; s.insert( don t even ); s.insert( worse ); s.insert( terrible ); s.insert( no way ); s.insert( go die in a hole ); s.insert( are you serious ); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int max = a[0]; int pos = 0; for (int i = 0; i < n; i++) { if (max < a[i]) { max = a[i]; pos = i; } } bool k = ...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> sum; vector<vector<bool>> used; int n, m; int g = 0; int k = 0; vector<pair<int, int>> p = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; void dfs(int first, int second, const int &r1, const int &r2, const int &l1, const int &l2) { if...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; int sum = 0, odd = 0, even = 0; for (int i = 0; i < n; i++) { int x; cin >> x; if (x % 2 == 0) { even++; } else { ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1E9; const long long LINF = (long long)1E18; int INP, AM; char BUF[(1 << 10) + 1], *inp = BUF; template <typename T> T gcd(T a, T b) { return (b == 0) ? abs(a) : gcd(b, a % b); } template <typename T> inline T lcm(T a, T b) { ...
#include <bits/stdc++.h> #include <iomanip> // std::setprecision #define ll long long const long modulo=1000000007; using namespace std; int ctoi(char c) {return c- 0 ;} int compare(pair <int,pair<int,int>> one, pair <int,pair<int,int>> two){ if(one.first<two.first) return 1;...