func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; ; long long ans = 0; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int fa[100010]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } bool merge(int x, int y) { int f1 = find(x), f2 = find(y); if (f1 == f2) return false; fa[f2] = f1; return true; } int main() { int n, k; scanf( %d %d , &n, ...
#include <bits/stdc++.h> using namespace std; inline void open(const char *s) {} inline int rd() { static int x, f; x = 0; f = 1; char ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) f = -1; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - ...
#include <bits/stdc++.h> using namespace std; struct edge { int to, cost; edge(int to = 0, int cost = 0) : to(to), cost(cost) {} }; vector<edge> vec[100005]; long long int F[100005], G[100005]; int nd[100005]; int n; long long int mpow(long long int m, long long int t) { if (t == 0) return 1...
#include <bits/stdc++.h> using namespace std; int xa, xb, xc, da, db, dc, ta, tb, tc, ans; bool f[42 + 5][42 + 5][42 + 5][8][8][8]; void calc(int a, int b, int c, int aa, int bb, int cc) { if (a < 0 || b < 0 || c < 0) return; if (a == b || a == c || b == c || f[a][b][c][aa][bb][cc]) return; int x = ...
#include <bits/stdc++.h> using namespace std; const long long INF = LLONG_MAX - 1e10; const long long maxn = 1e6 + 5; const long long mo_num = 1e9 + 7; long long n, m, a[maxn], b[maxn], ans; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (long long i = 1; i <= 4; i++)...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int x; scanf( %d , &x); bool found = 0; for (int n = 1; n <= 200000; n++) { int lo = 1, hi = n; bool done = 0; while (lo <= hi) { int m = lo + hi >> ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; int n, h, l, r, dp[2222][2222], a[2222]; int main() { ios_base::sync_with_stdio(false); cin >> n >> h >> l >> r; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < h; i++) for (int j = 0; j <= n; j++) dp[j][i]...
#include <bits/stdc++.h> using namespace std; const int max_n = 1e3 + 5; const int max_p = 1e3 + 5; const int max_k = 50 + 5; bool a[max_n], b[max_n]; int dp[2][max_p][max_k][max_k]; inline void check_max(int &x, int y) { x = max(x, y); } int main() { int n, p, k; scanf( %d%d%d , &n, &p, &k); ...
#include <bits/stdc++.h> using namespace std; long long calc(long long n, long long k) { long long a = 1, b = 1, c; for (long long i = 1; i <= k; i++) a = a * (n - i + 1), b = b * i; if (k == 4) c = 9; else if (k == 3) c = 2; else if (k == 2) c = 1; else c = 0; re...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; char zf = 1; char ch = getchar(); while (ch != - && !isdigit(ch)) ch = getchar(); if (ch == - ) zf = -1, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x * zf; ...
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &str, vector<T> &a) { for (auto &i : a) { str << i << ; } return str; } template <class T> istream &operator>>(istream &str, vector<T> &a) { for (auto &i : a) { str >> i; } ret...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( -ffloat-store ) #pragma GCC optimize( -fno-defer-pop ) long long int power(long long int a, long long int b, long long int m) { if (b == 0) return 1; if (b == 1) ret...
#include <bits/stdc++.h> using namespace std; const int nn = 115; const double PI = 2 * acos(0); int main() { int n; double r; double ans; cin >> n >> r; double x = (PI * (180 - (360.0 / n)) / 2.0) / 180.0; double L = 0, R = 1e5; while (L <= R) { double mid = (L + R) / 2.0; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, i, o = 0; cin >> n; long long int a[n]; for (i = 0; i < n; ++i) { cin >> a[i]; if (a[i] & 1) o++; } cout << min(o, n - o); }
#include <bits/stdc++.h> using namespace std; int count(string &s) { int p = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 1 ) p++; } return p; } int main() { string a, b; cin >> a >> b; int x, y; x = count(a); y = count(b); if (x >= y || (x + 1 == y && x %...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); bool sign = false; for (int i = 0; i < n; i++) { if (s[i] == a && !sign) continue; if (s[i] == a && sign) break; s[i]--; sign = true; } if (!sign) s[n - 1] = z ...
#include <bits/stdc++.h> using namespace std; int q, n, a[200000 + 5], cnt[200000 + 5]; int main() { scanf( %d , &q); for (; q--;) { memset(cnt, 0, sizeof(cnt)); int sum1 = 0, sum2 = 0, tot = 0, m = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(T x) { return x * x; } template <class T> inline T parse(const string &s) { T x; stringstream ss(s); ss >> x; return x; } const double EPS = 1e-12; const int INF = 1000 * 1000 * 1000; const long long LI...
#include <bits/stdc++.h> const int N = 1e2 + 9; using namespace std; int n, m; int mp[N][N]; int main() { scanf( %d%d , &n, &m); puts( YES ); memset(mp, 0, sizeof mp); if (m <= n - 2) { int mid = (n + 1) / 2; if (m & 1) { mp[2][mid] = 1; } for (int i = 1; i <= m...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MOD = 1e9 + 7; const long long maxn = 2e5 + 7; const long long maxm = 2e5 + 7; int n; bool isPrime(int a) { for (int i = 2; i <= sqrt(a); i++) { if (a % i == 0) { return 0; } } return 1...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using ld = long double; const int MN = 5e5 + 5, MM = 1e6 + 3; vector<int> bs; struct Lady { int a, b, c; } ladies[MN]; int bit[MN]; int n; void update(int i, int v) { ...
#include <bits/stdc++.h> using namespace std; vector<pair<double, double> > a; pair<double, double> cur; double r; void findmax(pair<double, double> p) { double y = sqrt(2 * r * 2 * r - abs(p.first - cur.first) * abs(p.first - cur.first)); y += p.second; cur.second = max(cur.second, y); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int b[100]; for (int i = 0; i < 100; i++) b[i] = 0; int x; for (int i = 0; i < n; i++) { cin >> x; b[x - 1] += 1; } x = b[0]; for (int i = 0; i < 100; i++) { if (b[i] > x) { ...
#include <bits/stdc++.h> using namespace std; struct node { int point, w; } p[30][30]; int n, m; int s[30][30], w[30][30], Min[30], f[3000000]; int Get() { char c = getchar(); while (!isalpha(c)) c = getchar(); return c; } void init(int x, int y) { int t1 = 0, t2 = 0, mx = 0; for...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int ctra = 0; int ctrb = 0; for (int i = 0; i < n; i++) { if (s[i] == A ) { ctra++; } else { ctrb++; } } if (ctra > ctrb) { cout << Anton ; ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, x, y, z; cin >> a >> b >> c; cin >> x >> y >> z; a -= x; b -= y; c -= z; if (a >= 0) a /= 2; if (b >= 0) b /= 2; if (c >= 0) c /= 2; if (a + b + c >= 0) cout << Yes << endl; else cout <<...
#include <bits/stdc++.h> using namespace std; int n, tot, Trie[2000000 + 5][2], Num[2000000 + 5]; long long x; char s[9], ch[20]; int main() { for (scanf( %d , &n); n; n--) { scanf( %s , s); if (s[0] == ? ) { scanf( %s , ch); int len = strlen(ch), u = 0, ans; for (int ...
#include <bits/stdc++.h> using namespace std; int p[300100], l[300100]; vector<int> e[300100]; int f(int x) { while (x != p[x]) { x = p[x] = p[p[x]]; } return x; } pair<int, int> L(int x, int p) { int lon = 0, h1 = 0, h2 = 0, S = e[x].size(); pair<int, int> R; for (int i = 0; i...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; const int MAX = 3e5 + 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, 0}; const int dc[] = {0, 1, 0, -1, ...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; map<string, int> m; int ans = 0; vector<string> a, b; for (int i = 0; i < n; i++) { string s; cin >> s; if (m[s] != 0) ans++;...
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define endl n #define boostIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); ll gcd(...
#include <bits/stdc++.h> using namespace std; const int N = 100; int n, k[N]; double p[N], p_log[N], p_log_1[N]; priority_queue<pair<double, int>> s; inline double P(int i, int k) { double x = pow(p[i], k); if (x > 1e-6) return log(1 - x); x = -x; return x - x * x / 2 + x * x * x / 3; } ...
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch; while (!isdigit(ch = getchar())) (ch == - ) && (f = -f); for (x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48)) ; return x * f; } const long long N = 2e5...
#include <bits/stdc++.h> using namespace std; int n; struct node { int x, index; } a[1010]; bool cmp(node x, node y) { if (x.x != y.x) return x.x > y.x; else return x.index > y.index; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i].x);...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { long long int n, a, b, x, y; cin >> n; x = 1 + (n - 1) / 3; long long int sum = 0, k = 1; while (sum < x) { sum += k; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native ) using namespace std; namespace _c { const double pi = acos(-1.0); namespace min { const int i8 = -128; const int i1...
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; const int INF = 1 << 30; int n, m, D; int a[MAX]; vector<int> v[MAX]; int down[MAX]; inline void Down(int x, int fa) { int res = -1; for (int i = 0; i < v[x].size(); i++) { int next = v[x][i]; if (next == fa) conti...
#include <bits/stdc++.h> using namespace std; int a, b, c, d; double Max(double x, double y, double d) { double temp = (x - d) * (y + d); temp = max((x - d) * (y - d), temp); temp = max((x + d) * (y - d), temp); temp = max((x + d) * (y + d), temp); return temp; } double Min(double x, doubl...
#include <bits/stdc++.h> using namespace std; const int p = 1000000007; long long quick_mod(long long a, long long b) { long long ans = 1; a %= p; while (b) { if (b & 1) { ans = ans * a % p; b--; } b >>= 1; a = a * a % p; } return ans; } long long C(...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int cnt = 0, rem = m; int arr[10000]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { if (rem >= arr[i]) rem -= arr[i]; else { cnt++; rem = m; ...
#include <bits/stdc++.h> using namespace std; long long a[200500]; long long res[200500]; long long n; bool check(long long x) { for (long long i = 0; i < n; i++) { res[i] = 0; } for (long long i = n - 1; i >= 2; i--) { long long f = (a[i] + res[i]) - x; if (f < 0) { retu...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5; int l = 0; int r = 0; int res = 0; int f[maxn + 11][55]; int a[maxn + 11]; int cnt[maxn + 11]; void add(int x) { if (!cnt[a[x]]) res++; cnt[a[x]]++; } void del(int x) { cnt[a[x]]--; if (!cnt[a[x]]) res--; } int...
#include <bits/stdc++.h> using namespace std; int main() { int a[100][3]; int n = 0; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } int s = 1; int m = 0; int f = 0; int cou = 0; int back = 0; for (int k = 0; k...
#include <bits/stdc++.h> using namespace std; long long int power(long long int first, long long int n) { if (n == 0) return 1; else if (n % 2 == 0) { long long int second = power(first, n / 2); return second * second; } else return first * power(first, n - 1); } int strTOint...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, m, m1, arr[9] = {0}, num = 0, num1 = 0; cin >> n >> m, m1 = m; if (n == 1 && m == 0) cout << 0 0 ; else if (9 * n < m || m == 0) cout << -1 -1 ; else { num1...
#include <bits/stdc++.h> using namespace std; using namespace rel_ops; using ll = int64_t; using Pii = pair<int, int>; using ull = uint64_t; using Vi = vector<int>; void run(); int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); run(); return 0; } ...
#include <bits/stdc++.h> using namespace std; int piles[105]; int main() { int n; cin >> n; vector<int> A(n); for (int i = 0; i < n; ++i) cin >> A[i]; sort(A.begin(), A.end()); for (int i = 0; i < n; ++i) { bool flag = false; for (int j = 0; j <= A[i]; ++j) if (piles[j]...
#include <bits/stdc++.h> using namespace std; const int N = 10005; long long int p[N], s[N], n, c; long long int dp[2][N]; int main() { cin >> n >> c; for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++) cin >> s[i]; dp[0][0] = p[0]; dp[0][1] = s[0]; int row = 1; fo...
#include <bits/stdc++.h> std::set<int> s; std::vector<bool> wh; bool push(int n) { for (int it = 1; it < 32; ++it) { if (!wh[n >> it]) { s.erase(n); wh[n] = false; s.insert(n >> it); wh[n >> it] = true; return true; } } return false; } void solut...
#include <bits/stdc++.h> using namespace std; char buf[1000000]; vector<vector<int> > g; vector<bool> used; vector<long long> border, space, w, h; vector<int> tp; void dfs(int v) { used[v] = true; for (int i = (0); i < (int((g[v]).size())); ++i) if (!used[g[v][i]]) dfs(g[v][i]); if (tp[v...
#include <bits/stdc++.h> using namespace std; int Array[10005]; int main() { int N, m, i, j, l, r, x, Count; scanf( %d%d , &N, &m); for (i = 1; i <= N; i++) scanf( %d , Array + i); for (i = 1; i <= m; i++) { Count = 0; scanf( %d%d%d , &l, &r, &x); for (j = l; j <= r; j++) { ...
#include <bits/stdc++.h> using namespace std; const int M = 105; const int MOD = 1e6 + 3; struct matrix { int val[M][M]; int n; matrix(int nn, int x = 0) { n = nn; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j) val[i][j] = 0; e...
#include <bits/stdc++.h> using namespace std; struct re { int x, y; }; int n, K, f[2001][2001]; char mp[2001][2001]; vector<re> A, B, zy[4001]; string Ans; void upd(int &x, int y) { if (y <= K) { if (x == -1) x = y; if (y < x) x = y; } } int main() { scanf( %d%d , &n, &K)...
#include <bits/stdc++.h> using namespace std; const int mxn = 1e5 + 100; int a[mxn], b[mxn], c[mxn]; set<int> mp; void add(int x) { if (c[x] == 0) mp.insert(b[x]); else if (c[x] == 1) mp.erase(b[x]); c[x]++; } void remove(int x) { if (c[x] == 2) mp.insert(b[x]); else ...
#include <bits/stdc++.h> using namespace std; int main() { int t; long long n; cin >> t; while (t--) { cin >> n; if (n % 2) { if ((n / 2) & 1) { cout << n + 1 << endl; } else { cout << 2 * n + 1 << endl; } } else { cout << 4 * n +...
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long f = 1, x = 0; while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 1) + (x << 3) + (c ^ 0 ); c = getchar(); }...
#include <bits/stdc++.h> using namespace std; const long long inf = (1LL << 60) - 1; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; void solve() { long long n, x, y, k, c = 0; cin >> n >> x >> y; for (long long i = 0; i < n; i++) { cin >> k; if (k <= x) c++; } if (x > y) ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); int arr[4]; for (int i = 0; i < 4; i++) cin >> arr[i]; int a, b; cin >> a >> b; sort(arr, arr + 4); if (arr[0] > b) cout << b - a + 1 << endl; els...
#include <bits/stdc++.h> using namespace std; int main() { int ans = -1; int n, dol, cent, s, i; cin >> n >> s; for (i = 0; i < n; i++) { cin >> dol >> cent; if (s > dol && cent != 0 && 100 - cent > ans) ans = 100 - cent; if (s >= dol && cent == 0 && ans == -1) ans = 0; } c...
#include <bits/stdc++.h> using namespace std; int tree[270000 * 4]; int t; char opt; void insert(long long x) { if (x == 0) { ++tree[2]; return; } int num = x % 10; x /= 10; num = (num % 2 == 0 ? 0 : 1); int root = (num == 0 ? 2 : 3); ++tree[root]; while (x) { ...
#include <bits/stdc++.h> using namespace std; long long ans, tot, n; long long a[105]; void update(long long d) { long long sum = 0; for (int i = 1; i <= n; i++) sum += (a[i] - 1) / d + 1; if (sum * d <= tot) ans = max(ans, d); } int main() { long long k; scanf( %lld %lld , &n, &k); ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1108864220 ) using namespace std; const int MOD = 1000000007; const int INF = 1000000000; const double EPS = 1e-9; const int HASH_POW = 29; const long double PI = acos(-1.0); mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().c...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 2100; int a[N][N], b[N][N], d[N][N]; int c[N], n, tag = -1, res[N]; void print() { cout << -1; exit(0); } int cnt = 0; void solve(int id, int T) { if (T) { for (int i = 1; i <= n; i++) { i...
#include <bits/stdc++.h> using namespace std; int main() { int cambio; cin >> cambio; vector<int> hansel; int madera = 0; int piedra = 0; int ladrillo; for (int i = 0; cambio > i; i++) { int gretel; cin >> gretel; piedra = piedra + gretel; hansel.push_back(gretel)...
#include <bits/stdc++.h> using namespace std; inline int mod(int a, int k) { return (a % k + k) % k; } int main() { int n, k, v; cin >> n >> k >> v; vector<int> a(1 + n, 0); int ss = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; ss += a[i]; } if (ss < v) { cout << N...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long l = 1, u = n, mid; while (l <= u) { mid = (l + u) / 2; long long sum = (mid * (mid + 1)) / 2; sum = sum - (n - mid); if (sum == k) { cout << n - mid << endl; br...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; long long x = 0; vector<long long> v; map<long long, long long> mp; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int m = (n << 1) - 1; vector<int> a(m); int first = -1; for (int i = 0; i < m; ++i) { scanf( %d , &a[i]); --a[i]; if (!~first && ~a[i]) { first = i; } } if (!~first) { ...
#include <bits/stdc++.h> using namespace std; int answer(); int main() { long long t; t = 1; while (t--) { answer(); } return 0; } int answer() { string k; cin >> k; int sup[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; if (k.size() > 1) { cout << sup[k[0] - 0 ] * sup[...
#include <bits/stdc++.h> int main() { double n, m; scanf( %lf %lf , &m, &n); double ans = 0; for (int i = 1; i <= m; i++) { ans += pow(i / m, n); } ans = m - ans + 1; printf( %.10lf , ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 20; const long long MOD = 2305843009255636993, RT = 5; struct CD { double r, i; CD(double r = 0, double i = 0) : r(r), i(i) {} double real() const { return r; } void operator/=(const int c) { r /= c, i /= c; } }; CD operator...
#include <bits/stdc++.h> using namespace std; long long int pow(long long int x, long long int y, long long int m) { long long int res = 1; x = x % m; while (y > 0) { if (y & 1) res = ((res % m) * (x % m)) % m; y = y >> 1; x = ((x % m) * (x % m)) % m; } return res % m; } te...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long powmod(long long a, long long l, long long md) { long long res = 1; while (l) { if (l & 1) res = res * a % md; l /= 2; a = a * a % md; } return res; } long long binpow(long long a, long long l) {...
#include <bits/stdc++.h> using namespace std; using namespace chrono; const int N = 1205; const int INF = 0x3f3f3f3f; template <class T> bool read(T& x) { char c; while (!isdigit(c = getchar()) && c != - && c != EOF) ; if (c == EOF) return false; T flag = 1; if (c == - ) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 500001; int a[maxn][2]; int cur, n; int r[maxn][2], tot; void dosth() { int i; a[1][cur ^ 1] = a[1][cur]; a[n][cur ^ 1] = a[n][cur]; for (i = 2; i < n; ++i) a[i][cur ^ 1] = a[i - 1][cur] + a[i][cur] + a[i + 1][cur] > 1 ? 1 ...
#include <bits/stdc++.h> using namespace std; int num[100005]; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %1d , num + i); for (int i = 1; i <= n && k; i++) { if (num[i] == 4 && num[i + 1] == 7) { if (i % 2 == 0 && num[i - 1] == 4) { if...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 1; for (int i = 6; i <= n; i++) { if (n % i == 0) { int k1 = 0, k0 = 0; int f = 0; int x = i; while (x > 1 and f == 0) { int x2 = x % 2; if (x2 == 1 and k0 ...
#include <bits/stdc++.h> using namespace std; int n, m, k, ans[2005]; char a[2010][2010]; void load() { scanf( %d%d%d n , &n, &m, &k); for (int i = 0; i < n; i++) { scanf( %s , a[i]); } } void solve() { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][...
#include <bits/stdc++.h> using namespace std; int main() { int m; cin >> m; int c[m]; int sum1 = 0; for (int i = 0; i < m; i++) { cin >> c[i]; sum1 += c[i]; } int x, y; cin >> x >> y; int flag = 0; int k = 1; int sum2 = 0; if (sum2 >= x && sum2 <= y && sum...
#include <bits/stdc++.h> using namespace std; int n, x, y; char a[100005]; int main(void) { scanf( %d%d%d , &n, &x, &y); for (int i = 1; i <= n; i++) { cin >> a[i]; } if (a[x] == a[y]) puts( 0 ); else puts( 1 ); }
#include <bits/stdc++.h> using namespace std; int kk[(100010)]; map<int, int> possible; int main() { int t, m, k, tj, rj, pre(0); bool first(false), already(false); scanf( %d , &t); for (int i = 0; i < t; ++i) { first = false; already = false; pre = 0; possible.clear(); ...
#include <bits/stdc++.h> using namespace std; long long int B = 257; char s[1000100]; char t[1000100]; int n; int m; unsigned long long int hash1[1000100]; unsigned long long int hash2[1000100]; struct resp { unsigned long long int count; unsigned long long int indices[1000100]; } indice; ...
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ...
#include <bits/stdc++.h> using namespace std; using namespace std; vector<bool> Prime(20000000 + 1, 1); vector<bool> Pal(20000000 + 1, 1); void gen1() { long long int n = 2000000; Prime[1] = 0; for (long long int i = 2; i <= 20000000; i++) { if (Prime[i]) { for (long long int j = i +...
#include <bits/stdc++.h> using namespace std; bitset<6> a, b; int main() { int n; cin >> n; a = bitset<6>(n); b.set(5, a[5]); b.set(4, a[0]); b.set(3, a[2]); b.set(2, a[3]); b.set(1, a[1]); b.set(0, a[4]); cout << b.to_ulong(); }
#include <bits/stdc++.h> using namespace std; int main() { long long n, c[100000], b[100000], a[100000], s1 = 0, s2 = 0, s3 = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; s1 += a[i]; } for (int i = 0; i < n - 1; i++) { cin >> b[i]; s2 += b[i]; } for (in...
#include <bits/stdc++.h> using namespace std; bool a[30][30]; void fun(int x, int y) { a[x][y] = a[y][x] = true; } int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { memset(a, false, sizeof a); int n, p; cin >> n >> p; if (n % 2 == 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n < k * 1ll * (k + 1) / 2) { cout << NO << endl; return 0; } int nn = n - k * (k + 1) / 2; vector<int> a(k); for (int i = 0; i < k; ++i) { a[i] = i + 1 + (nn / k) + (i >= k - nn % ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, mod = 1e9 + 7; long long a[N], x, n, sum; long long fastpower(long long b, long long p) { if (p == 0) return 1; long long halfpower = fastpower(b, p / 2) % mod; halfpower *= halfpower; halfpower %= mod; if (p % 2) halfpower...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1 1 << endl << 1 ; return 0; } cout << 5 * (n - 1) << << 2 << endl << 1 5 ; }
#include <bits/stdc++.h> int const maxn = 255; int const mod = 1e9 + 7; long long a[maxn]; long long c[maxn][maxn]; long long pow(long long a, long long b, long long p) { long long r = 1; while (b) { if (b & 1) r = (r * a) % p; a = (a * a) % p; b >>= 1; } return r; } int ...
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long res = 1; a = a % 1000000007; while (b > 0) { if (b & 1) { res = (res * a) % 1000000007; b--; } a = (a * a) % 1000000007; b >>= 1; } return res; } long l...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000 * 1000 * 1000 + 7; const long long int INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; const long long int MOD2 = 998244353; const long double PI = 3.141592653589793; long long int gcd(long long int a, long long int b) { ...
#include <bits/stdc++.h> using namespace std; long long a, b; int ans[60]; void dfs(int dep) { long long cur = ans[dep - 1]; long long x = cur << 1; long long y = cur * 10 + 1; if (x == b || y == b) { puts( YES ); cout << dep + 1 << endl; for (int i = 0; i < dep; i++) cout << a...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, x, y, z, r = 0; scanf( %d%d%d%d%d%d , &a, &b, &c, &x, &y, &z); if (a > x) { r += (a - x) / 2; a -= r * 2; } if (b > y) { r += (b - y) / 2; b -= (b - y) / 2 * 2; } if (c > z) { r += (c - ...
#include <bits/stdc++.h> int a[6] = {0, 2, 3, 1, 2, 1}; int main() { int n; scanf( %d , &n); printf( %d n , a[n]); return 0; }
#include <bits/stdc++.h> #pragma comment(linker, /stack:20000000 ) #pragma warning(disable : 4146) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int inf = 1e9; const long long lnf = 1e18; const long long h1 = 23901...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (x > y) { cout << n << endl; return 0; } int cnt = 0; for (int i = 0; i < n; i++) { if (a[i] <= x)...
#include <bits/stdc++.h> const int N = 100005; using namespace std; long long n, a, b, k; char s[N]; long long mod = 1e9 + 9; long long pow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % mod; b >>= 1; a = a * a % mod; } return ans; }...