func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> const int INF = 2147483647; const int MOD = 1000000007; const long long INF64 = 9223372036854775807; const long double EPS = 1e-7; using namespace std; vector<int> a; int getDist(int fr, int to) { int l = fr, r = to, mid = (a[to] + a[fr]) / 2; while (l < r - 1) { int...
#include <bits/stdc++.h> using namespace std; const long long base = 17LL; const long long MOD = 998244353LL; const int MAXN = 1e5 + 10; struct Node { long long v; long long tagv; long long len; } st[MAXN << 2]; long long a[MAXN]; inline long long fp(long long x, long long y) { long long...
#include <bits/stdc++.h> using namespace std; bool deb = false; int i; const int N = 100011; int g[N]; int ans1[N], ans2[N]; int main() { int i, j, n, k; scanf( %d , &n), scanf( %d , &k); int a, b, c, d; scanf( %d , &a), scanf( %d , &b), scanf( %d , &c), scanf( %d , &d); if (k < n + 1 ...
#include <bits/stdc++.h> using namespace std; string s; long cmpduong(string s1, string s2) { long len1 = s1.size(); long len2 = s2.size(); if (len1 < len2) return 2; if (len1 == len2) { if (s1 > s2) return 1; else return 2; } if (len1 > len2) return 1; } lo...
#include <bits/stdc++.h> using namespace std; long long sum[400006] = {0}; long long Min[400006] = {0}; long long Max[400006] = {0}; void solve() { long long n; cin >> n; long long k; cin >> k; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; for (long long i ...
#include <bits/stdc++.h> using namespace std; int N, M; int ans[100010]; int a[100010], b[100010]; int c[100010], d[100010], cnt[100010]; set<pair<int, int> > s; int x[100010 * 4], nx; vector<int> A[100010 * 4], B[100010 * 4]; bool solve() { for (int i = 0; i < N; i++) { x[nx++] = a[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, n1 = 0, n2 = 0, ar = 0, curr = 0, current; cin >> n; vector<int> a(n); for (i = 0; i < n; i++) cin >> a[i]; current = a[0]; for (i = 0; i < n; i++) { if (curr == 0 && a[i] == current) n1++; else if...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; vector<int> d(n); for (int(i) = 0; (i) < (n); (i)++) { cin >> d[i]; } sort((d).begin(), (d).end()); if (d[b] != d[b - 1]) { cout << d[b] - d[b - 1] << endl; } else { cout << ...
#include <bits/stdc++.h> using namespace std; const int N = 205000; const int SQRTN = 320; const int LOGN = 20; const long double PI = acos(-1); vector<string> w, a, b; string s1, s2; bool check(string& s) { if (s.size() == 0) return 0; if (s[0] == 0 ) return s.size() == 1; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e5 + 5; int n, I; int a[MAXN], num[MAXN]; int read() { int s = 1, x = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) s = -1; ch = getchar(); } while (isdigit(ch)) { x = 10 * x + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, x, y, x1, y1; cin >> n >> a >> b; if (max(n - a, n - b) < max(a - 1, b - 1)) cout << black n ; else cout << white n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int a[MAXN], deg[MAXN]; set<pair<int, int> > s; int main() { int n, sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> deg[i] >> a[i]; if (deg[i]) s.insert(make_pair(deg[i], i)); sum += deg[i]; } ...
#include <bits/stdc++.h> using namespace std; int cnt[6], ans[100001]; pair<int, int> arr[100001]; bool given[100001]; string tshirt[6] = { S , M , L , XL , XXL , XXXL }; int match(string s) { for (int i = 0; i < 6; i++) { if (tshirt[i] == s) return i; } } void convert(int ind, string...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000; const int D[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; set<pair<int, int> > s; set<pair<pair<int, int>, int> > vis; char dir[10]; int sx, sy, h, w, d, tar; inline void update(int& a, int b) { if (b < a) a = b; } int main(...
#include <bits/stdc++.h> using namespace std; int num[100009]; int main() { int n; while (cin >> n) { for (int i = 0; i < n; ++i) cin >> num[i]; long long sum = n; long long count = 1; for (int i = 1; i < n; ++i) { if (num[i] == num[i - 1]) count++; else {...
#include <bits/stdc++.h> using namespace std; const int MX = 11; int n, l; int main() { scanf( %d , &n); while (n) { int a = n % 10; int b = n % 100; int c = n % 1000; if (a == 1) n /= 10; else if (b == 14) n /= 10; else if (c == 144) n /= 100;...
#include <bits/stdc++.h> using namespace std; map<int, int> MP1, MP2; map<int, int>::iterator it; const int N = 300100; const long long INF = 3000 * 1000 * 1000LL; vector<int> v; int a[N]; long long ps[N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, l, r; lon...
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <cstring> #include <list> #include <casser...
#include <bits/stdc++.h> using namespace std; int main() { string s; int cnt = 0, cnt1 = 0; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == - ) cnt++; else cnt1++; } if (cnt1 == 0) { cout << YES ; return 0; } if (cnt % cnt1 == 0)...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, rt; int p[20][N], sz[N]; bool vis[N]; int dep[N], yr[N]; int cur = 1, pos[N], chainhd[N], chain[N], rpos[N]; int L[100 * N], R[100 * N], t[100 * N], root[N], nxt = 1, num; int query[N], a[N], b[N], k[N], y[N]; vector<int>...
#include <bits/stdc++.h> using namespace std; inline void init() {} string lines[1001]; int main() { string s; int n = 0; int mx = 0; while (getline(cin, lines[n])) { mx = std::max<int>(mx, lines[n].length()); n++; } cout << string(mx + 2, * ) << endl; int sw = 0; fo...
#include <bits/stdc++.h> struct M { int p, b; }; struct F { const int p, i; int r; int c; F(int p, int t, int i) : p(p), i(i), r(p + t), c(0) {} int t() { return r - p; } }; void solve(std::vector<F> &fs, std::vector<M> &ms) { std::multimap<int, int> ms_landed; std::map<int, F ...
#include <bits/stdc++.h> using namespace std; long long edgestory; long long last; struct UnionFind { vector<int> f; vector<bool> special; void init(int n) { f.clear(); f.insert(f.begin(), n, -1); special.clear(); special.insert(special.begin(), n, false); edgestory = 0...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; long long a[200005], b[200005], t[200005]; long long c(long long l, long long r, long long* a) { if (l == r - 1) return 0; long long ans = 0, m = (l + r + 1) / 2, k = l, ct = 0; ans += c(l, m, a) + c(m, r, a); for (long...
#include <bits/stdc++.h> using namespace std; using ll = long long; ll mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t, n, m, i, j, k; cin >> n >> k; vector<ll> v; i = 0; if (n % 2 == 1) { v.push_back(1); n -= 1; ...
#include <bits/stdc++.h> using namespace std; signed main() { long long V; cin >> V; while (V--) { double a[250]; for (long long i = 0; i < 250; i++) cin >> a[i]; double exp = 0; for (long long i = 0; i < 250; i++) exp += a[i]; exp /= 250; double var = 0; for (l...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> G[100000]; int a[100000]; int b[100000]; int c[100000]; void dfs(int v) { b[v]++; c[v] = 1; for (int i = 0; i < (int)(G[v].size()); i++) { int w = G[v][i]; if (++b[w] == a[w]) dfs(w); } } int main() { c...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long sum = 0; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846264338327950288419716939937510; const double E = 2.7182818284590452353602874713526624977572470936999596; const double eps = 0.000000001; const int MOD = 998244353; inline int max(int u, int v) { return u > v ? u : v; } i...
#include <bits/stdc++.h> using namespace std; const greater<int> gt; int A[100000]; int main() { cout << fixed << setprecision(11); long long n, k, m; cin >> n >> k >> m; for (int i = 0; i < n; ++i) cin >> A[i]; sort(A, A + n, gt); double mx = 0, rx = 0; for (int i = 0; i < n; ++i) {...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; int n, deg[N], a[N]; bool ed[N][N]; void change(int u) { for (int v = 0; v < n; v++) { deg[u] -= ed[u][v], deg[u] += ed[u][v] ^= true; deg[v] -= ed[v][u], deg[v] += ed[v][u] ^= true; } } bool check() { copy(deg, d...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long mod = 1e9 + 7; vector<long long> v; long long n, s; bool check(long long x) { long long sum = 0; for (long long i = 0; i < n; i++) { sum += (v[i] - x); } return sum >= s; } int main() { ios_bas...
#include <bits/stdc++.h> using namespace std; const int maxn = 1 << 20; const int inf = 2e9; int n, q; int h[maxn], v[maxn]; pair<pair<int, int>, int> b[maxn]; vector<int> hull[maxn]; long double inter(int id1, int id2) { if (v[id1] == v[id2]) return -1; return (long double)(h[id1] - h[id2]) / (...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, num; cin >> n >> k; num = (n) * (n - 1) / 2; if (num <= k) cout << no solution << endl; else for (int i = 1; i <= n; i++) cout << 1 << << i << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1000000009; const int MOD = 1000000007; double probMayor(pair<int, int> x, int bid) { if (bid < x.first) { return 1.0; } if (bid > x.second) { return 0.0; } return double(x.second - bid) / (x.second - x.first + 1); }...
#include <bits/stdc++.h> using namespace std; const int N = 305, MOD = 1e4 + 7; char s[N]; int n, m, ndc, f[N][N][N]; int getf(int cnt, int l, int r) { if (cnt < 0) return 0; if (~f[cnt][l][r]) return f[cnt][l][r]; if (l == 1 && r == m) return f[cnt][l][r] = !cnt; int ret = 0; if (l > 1 &&...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; char ch; string str; cin >> str; int n1 = 0, n2 = 0; int ct = 0; for (int i = 0; i < n; i++) { if (str[i] == ( ) { if (n2 > 0) { ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; double E = 2.71828182846; double PI = 3.1415926535897932384626433832795; double EPS = 1e-9; const int ROOT = 444; const int MAXN = 300100; const int ROOTN = 555; int n; int gcd(int a, int b) { while (b) { ...
#include <bits/stdc++.h> using namespace std; inline int read() { int X = 0, w = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) w = -1; c = getchar(); } while (c >= 0 && c <= 9 ) X = X * 10 + c - 0 , c = getchar(); return X * w; } const int N = 100 + 10...
#include <bits/stdc++.h> using namespace std; const int MX = 200005; int ans, cnt0, cnt1, lth, pos1[MX], pos0[MX], pre[MX], nxt[MX]; char s[MX]; bool vis[MX]; int main() { scanf( %s , s + 1); lth = strlen(s + 1); for (int i = 1; i <= lth; i++) { if (s[i] == 0 ) pos0[++cnt0] = i; ...
#include <bits/stdc++.h> using namespace std; const long long int N = 2e5 + 5; void solve() { long long int n, m; cin >> n >> m; vector<long long int> v(m); for (auto &it : v) cin >> it; ; vector<long long int> suf(m); long long int s = 0; for (long long int i = m - 1; i >= 0; i--)...
#include<fstream> #include<iostream> #include<sstream> #include<iomanip> #include<string> #include<vector> #include<list> #include<set> #include<map> #include<queue> #include<algorithm> #include<functional> #include<numeric> #include<bitset> #include<cassert> #include<array> #include st...
#include <bits/stdc++.h> using namespace std; unsigned long long modExponentiate(unsigned long long a, unsigned long long b) { if (b == 0) return 1; unsigned long long ans = a; unsigned long long t = 1; while (b > 1) { if (b % 2 == 0) { ans = (ans * ans) % (1000000007); a = (a ...
#include <bits/stdc++.h> int main() { int steps, count, i, n; char str[500]; char pc; scanf( %s , str); steps = count = 0; n = strlen(str); if (n == 0) { printf( 0 n ); return 0; } pc = str[0]; count = 1; for (i = 1; i < n; i++) { if (count == 5) { ...
#include <bits/stdc++.h> using namespace std; const long long INF = 2e9; const long long MOD = 1e9 + 7; mt19937 azino(777); int ask(int a, int b, int c) { cout << ? << a << << b << << c << endl; int x; cin >> x; return x; } void answer(vector<int>& ans) { cout << ! << ans...
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y, z, t1, t2, t3; cin >> x >> y >> z >> t1 >> t2 >> t3; long long int lift = abs(x - z) * t2 + 3 * t3 + abs(x - y) * t2, walk = abs(x - y) * t1; if (lift <= walk) cout << YES ; else cout <<...
#include <bits/stdc++.h> using namespace std; int T; char s[2000]; int main() { scanf( %d , &T); while (T--) { scanf( %s , s + 1); int l = strlen(s + 1); if (s[l] == o && s[l - 1] == p ) printf( FILIPINO n ); else if (s[l] == u && s[l - 1] == s && s[l - 2] == e &...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int a[n][m]; int f = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; if ((i == 0 || i == n - 1) && (...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int a[maxn], b[maxn]; int n, m; int main() { while (~scanf( %d%d , &n, &m)) { for (int i = 0; i < n; i++) scanf( %d , a + i); for (int i = 0; i < m; i++) scanf( %d , b + i); int dis, ans = 0; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; const int mod = 1e9 + 7; inline int cal(int x, int y) { int l = 0, r = 1e9; while (l < r) { int mid = l + r + 1 >> 1; if (3ll * mid + y <= x) l = mid; else r = mid - 1; } if (y > x) return 0;...
#include <bits/stdc++.h> using namespace std; int n; const double Exp = 1e-9; int sgn(double x) { if (fabs(x) < Exp) return 0; return x > 0 ? 1 : -1; } struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} friend Point operator+(const Point &a, const Point &b) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, h; cin >> s; h = s; sort(h.begin(), h.end()); if (s != h) { cout << NO ; return 0; } int a = 0, b = 0, c = 0; for (int i = 0; i < s.siz...
#include <bits/stdc++.h> using namespace std; const int MAX_INT = 1000 * 1000 * 1000; int n, m; vector<int> ver; vector<int> hor; int main() { cin >> n >> m; ver.reserve(n + 1); ver.resize(n); for (int i = 0; i < n; ++i) cin >> ver.at(i), ver.at(i) += 1; ver.push_back(MAX_INT + 1); s...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; string a(s); int n; cin >> n; for (int i = 0; i < int(s.size()); ++i) { if (isupper(s[i])) { s[i] -= A ; s[i] += a ; } if (...
#include <bits/stdc++.h> using namespace std; void timer() { return; } const int mod = 1e9 + 7; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; string ds = RLDU ; const int mx = 5e4 + 10; long long sum[mx]; void solve() { int n, t; cin >> n >> t; for (int i = (1); i < (n + 1); ++i) { ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } enum dir { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT }; i...
#include <bits/stdc++.h> using namespace std; int n, m; long long a[200000], b[200000]; bool ok(long long x) { int p(1); long long q(0); for (int i = 1; i <= (m); ++i) if (b[i] > q) { while (p <= n && a[p] + x < b[i]) ++p; if (a[p] - x > b[i] || p > n) return false; if ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int x; cin >> x; vector<long long> result; for (long long i = 1; i <= x; i++) { long long n; cin >> n; vector<long long> v(n); for (long long h = 0; h ...
#include <bits/stdc++.h> using namespace std; void solve(int test_number); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.setf(ios::fixed); cout.precision(9); cerr.setf(ios::fixed); cerr.precision(3); int n = 1; for (int i = 0; i < n; i++) { solve(i); ...
#include <bits/stdc++.h> long long int n, m; long long int pow(long long int k) { long long int a = 1, t = 3; for (; k; k /= 2) { if (k & 1) a = (a * t) % m; t = t * t % m; } return a; } void suru() { scanf( %I64d %I64d , &n, &m); } void truli() {} void sutru() { printf( %I64d n ...
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; template <typename T> inline T read() { T sum = 0, fl = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == - ) fl = -1; for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; int n = s.length(); int r = 0; vector<int> fin(3, -1); fin[0] = 0; vector<int> z(n + 1); for (int i = 1; i <= n; i++) { r = (r + s[i - 1] - 0 ) % 3; z[i] = z[i - 1]; if (fin[r] != -1) ...
#include <bits/stdc++.h> using namespace std; inline char nc() { return getchar(); static char buf[100000], *l = buf, *r = buf; return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r) ? EOF : *l++; } template <class T> void read(T &x) { x = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[100005]; for (int i = 0; i < n; i++) { cin >> a[i]; } int Count = 1; if (n == 1) { cout << 1 << endl; } else { for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) { ...
#include <bits/stdc++.h> const int maxn = 1005; int p[maxn], d[maxn], l[maxn][2], nl, ti; int main() { int n, h, r, c; scanf( %d%d%d , &n, &h, &r); for (int i = 0; i != n; ++i) scanf( %d%d , p + i, d + i); c = h; while (true) { c += r; if (c > h) c = h; if (c <= 0) break; ...
#include <bits/stdc++.h> using namespace std; int main() { string p, z; cin >> p; cin >> z; for (int i = 0; i < p.length(); i++) { if (p[i] >= A && p[i] <= Z ) p[i] = tolower(p[i]); } for (int i = 0; i < z.length(); i++) { if (z[i] >= A && z[i] <= Z ) z[i] = tolower(z[i]); ...
#include <bits/stdc++.h> using namespace std; struct Edge { int src, dst; int weight; Edge(int src, int dst, int weight) : src(src), dst(dst), weight(weight) {} }; bool operator<(const Edge &e, const Edge &f) { return e.weight != f.weight ? e.weight > f.weight : e.src != f.src ? e...
#include <bits/stdc++.h> using namespace std; namespace IO { void setIn(string s) { freopen(s.c_str(), r , stdin); } void setOut(string s) { freopen(s.c_str(), w , stdout); } void setIO(string s = ) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); ...
#include <bits/stdc++.h> using namespace std; int b[1000005], a[40]; int main() { int n, m, d; cin >> n >> m; for (int(i) = (0); (i) < (n); (i)++) { scanf( %d , &d); int j = 0; while (d) a[j++] += d & 1, d /= 2; } for (int(i) = (0); (i) < (m); (i)++) scanf( %d , &b[i]); s...
#include <bits/stdc++.h> using namespace std; const long long MAX_N = 10 * 100 + 19; const long long inf = 2e9 + 19; long long n; int32_t main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; cout << 1ll * ((n + 1) / 2) * (n / 2) << endl; for (long long i = 1; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, n, m, ans = 0; cin >> n >> m >> k; ans = n + m + k; cout << min(ans / 3, ans - max(n, max(m, k))); }
#include <bits/stdc++.h> using namespace std; const int MAXSIZE = 2001; const long long BASE = 1000000007; int n, m; long long dp[MAXSIZE + 1][MAXSIZE + 1]; long long sum[MAXSIZE + 1][MAXSIZE + 1]; int main() { scanf( %d%d , &n, &m); for (int l = 1; l < m; l++) dp[1][l] = 1; for (int i = 2; i ...
#include <bits/stdc++.h> using namespace std; constexpr int inf = 1e9 + 5; void umin(int& a, int b) { a = min(a, b); } void umax(int& a, int b) { a = max(a, b); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<array<int, 2>> a(n); for (auto& ai : a) { ...
#include <bits/stdc++.h> using std::vector; bool judge(int x) { for (int i = 0; i < 31; i++) { if (x == (1 << i) - 1) return true; } return false; } int get_hzero(int x) { int res = 0, pre = 0; for (int i = 0; i < 31; i++) { if (x & (1 << i)) res = pre; else ...
#include <bits/stdc++.h> inline int in() { int x = 0; char c = getchar(); bool f = false; while (c < 0 || c > 9 ) f |= c == - , c = getchar(); while (c >= 0 && c <= 9 ) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? -x : x; } const int N = 105; int t[N], f[N *...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; const int mod = 1e9 + 7; int prime[N], pp, pri[N], ans = 1, p[N], n, cnt[N], mx[N]; bool iscomp[N]; void primetable() { for (int i = 2; i < N; i++) { if (!iscomp[i]) prime[pp++] = i, pri[i] = i; for (int j = 0; j < pp && 1...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; const int MAXT = 1e10 + 1000; int N; long long T; const double EPS = 1e-12; const double CHTLB = -1; const double CHTUB = 1e20; double V, t; double pow(double b, long long p) { assert(p >= 0); if (p == 0) return 1; ...
#include <bits/stdc++.h> using namespace std; int ans; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) { int k = i ^ j; if (k >= j && k <= n && i + j > k && i + k > j && j + k > i) ans++; } cout << ans; }
#include <bits/stdc++.h> using namespace std; struct node { int va, num; bool operator<(const node &o) const { return va < o.va; } } a[100005]; int n, m, nub, lastnode, nextnode, now; int mark[400005], mm; int ans[400005], co; vector<int> save[400005]; void dfs(int h) { mark[h] = 1; for ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; if (n == 1 && t == 10) { cout << -1 << endl; return 0; } if (t == 10) { for (int i = 1; i < n; i++) cout << 1; cout << 0 << endl; return 0; } if (n == 1) { cout << t <<...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { string s; int ans = 0; cin >> s; int curRow = 0, curCol = 0; map<pair<pair<int, int>, pair<int, int>>, bool> mp; for (int i ...
#include <bits/stdc++.h> using namespace std; int main() { int temp = 0, n; cin >> n; int arr[n]; bool b[n]; for (int j = 0; j < n; j++) { cin >> arr[j]; b[j] = false; } for (int i = n - 1; i >= 0; i--) { if (temp > 0) b[i] = true; temp--; temp = max(temp, a...
#include <bits/stdc++.h> using namespace std; int a[101], b[101], g[101][101]; int main() { int i, j, n, k; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]); for (i = 1; i <= n; i++) scanf( %d , &b[i]); memset(g, 0, sizeof(g)); for (i = 1; i <= n; i++) { if (i + b[i] <= n...
#include <bits/stdc++.h> using namespace std; int err; int bitc(long long r) { return r == 0 ? 0 : (bitc(r >> 1) + (r & 1)); } long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; } string cts(char c) { string s = ; s += c; return s; } char buf[1000000]; string getLine()...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-7; const long long int m = 1000000007; void solve() { int n, m, r, c; cin >> n >> m; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < s.length(); j++) { if (s[j] == B ) { ...
#include <bits/stdc++.h> using namespace std; int A[2][2]; int main() { int d, i, n; cin >> n; int k = n; int cd = 0, ud = 0, c_i = 0, u_i = 0; while (k--) { cin >> i >> d; if (i == 0) c_i++; else u_i++; if (d == 0) cd++; else ud++;...
#include <bits/stdc++.h> using namespace std; vector<int> v; vector<int> primes; bool flag[100005]; bool flag2[100005]; void sieve(int n) { for (int i = 2; i <= n; i++) { if (!flag2[i]) { primes.push_back(i); for (int j = 2 * i; j <= n; j += i) { flag2[j] = true; ...
#include <bits/stdc++.h> using namespace std; int const INF = numeric_limits<int>::max(); int const N = 1e5 + 5; string a[N]; int main() { ios::sync_with_stdio(false); vector<pair<int, int>> v; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; int m; cin >> m; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) { string s; cin >> s; long long int a, b; cin >> a >> b; long long int n = s.length(); vector<long long int> v1(n...
#include <bits/stdc++.h> using namespace std; const int MAX_SIZE = 200010; pair<int, int> arr[MAX_SIZE], backup[MAX_SIZE]; long long prefix[MAX_SIZE]; int N; void sortX(int l, int r) { if (l >= r) return; int mi = (l + r) / 2; sortX(l, mi); sortX(mi + 1, r); int i = l, j = mi + 1, k = l;...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, x, y; bool B[1005]; cin >> n >> m; for (i = 0; i < n; i++) B[i] = true; for (i = 0; i < m; i++) { cin >> x >> y; B[x - 1] = false; B[y - 1] = false; } for (i = 0; i < n; i++) if (B[i]) brea...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; mt19937 rnd( std::chrono::high_resolution_clock::now().time_since_epoch().count()); void ProdamGaraje() { vector<long long> a[2000]; long long m, n; cin >> n >> m; for (long long i = 0; i < n; ++i) { a[i].push_...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000000, inv2 = (MOD + 1) / 2; long double eps = 1e-6; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; long double pi = acos(-1.0L); struct node { int x, y, z, op, id; } a[1000000 + 10], c[1000000 + 10]; bool cmp(node a, ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, vector<pair<int, int> > > mp; int res[200], mini = INT_MAX; for (int i = 0; i < n; i++) { pair<int, int> p; scanf( %d%d , &p.first, &p.second); mp[p.first].push_back({p.second, i}); } i...
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535897932384626433832795; double eps = 1e-14; char ch[1 << 20]; inline string gs() { scanf( %s , ch); return string(ch); } inline int gi() { int x; scanf( %d , &x); return x; } void error() { int ttt = 0; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const double EPS = 1e-9; const int INF = 1 << 29; int const NN = 1e6 + 6; string s; string t[NN]; pair<pair<int, int>, int> p[NN]; int tot = 0; int mxI[NN]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; int main() { int q, n, k; string s; cin >> q; while (q--) { cin >> n >> k >> s; string rgb = RGB ; int cnt = 0, ans = k; for (int i = 0; i <= n - k; i++) { for (int j = 0; j < 3; j++) { cnt = 0; for (i...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; cout << a + b << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, k, x, ans, a, b; int main() { scanf( %d%d , &n, &k); while (n--) { scanf( %d%d , &a, &b); x += b - a + 1; } x = (k - (x % k)) % k; printf( %d , x); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int v; cin >> v; if (v == 2) { cout << 2 << endl; return 0; } cout << 1 << endl; return 0; }