func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int M = 100000 + 10; struct Node { int l, r, q; }; struct Tree { int l, r; int ans; int lazy; }; Tree tree[M * 3]; Node d[M]; int mex[M]; int n, m; void get_same(int s) { if (tree[s].l == tree[s].r) return; if (tree[s].laz...
#include <bits/stdc++.h> using namespace std; int main() { int t; char arr[105]; cin >> t; gets(arr); for (int i = 0; i < t; i++) { int flg1 = 0; int flg2 = 0; gets(arr); int len = strlen(arr); if (arr[0] == m && arr[1] == i && arr[2] == a && arr[3] == o && ...
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<stack> #include<ctime> #include<map> #define ll long long #define MAXN 20105 #define uns unsigned #define INF 0x3f3f3f3f #define MOD 1000000007ll #define lowb...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, arr[25], ans = 0, c[3]; bool r1 = 1; cin >> n >> a >> b; c[0] = a, c[1] = b; for (int i = 0; i < n; i++) { cin >> arr[i]; } int mid = n / 2; if (2 * mid < n) mid++; for (int i = 0; i < mid; i++) { ...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 10; const long long M = 1e9 + 7; int n, x, y, z; int last[N], to[2 * N], w[2 * N], num, nxt[2 * N]; long long a[N]; long long ans; void Add(int u, int v, int c) { nxt[++num] = last[u]; to[num] = v; w[num] = c; last[u...
#include <bits/stdc++.h> using namespace std; long long int a, b, c, t, d, e, f; long long int max(long long int x, long long int y) { if (x > y) return x; else return y; } int main() { scanf( %I64d%I64d%I64d , &a, &b, &c); t = max(a, max(b, c)); d = max(t - 1, b); e = max(...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << << a.second;...
#include <bits/stdc++.h> using namespace std; long long srw[1000], scol[1000]; long long rows[1000001], cols[1000001]; int main() { int x, n, m, k, p, y, i, j; scanf( %d%d%d%d , &n, &m, &k, &p); for (i = 0; i < n; i++) for (j = 0; j < m; j++) { scanf( %d , &x); srw[i] += x; ...
#include <bits/stdc++.h> using namespace std; int n, m, i, j, T, ti; long long MX = 4294967295; long long temp; long long loop(int n) { long long ret = 0; string str; int rn; cin >> str; m--; while (str != end ) { if (str == add ) { ret++; } else if (str == for )...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { t = 0; char ch = getchar(); int f = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } do { (t *= 10) += ch - 0 ; ch = getchar(); } while ( 0 <= ch &&...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &k) { k = 0; int flag = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) flag = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { k = k * 10 + c - 0 ; c = getchar...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int a = 1; int b = N; for (int i = 2; N / i >= i; i++) if (N % i == 0) a = i, b = N / i; cout << a << << b << n ; }
#include <bits/stdc++.h> using namespace std; const long double PI = 3.1415926535897923846; const long long int MOD = 1000000007; const long long int N = 998244353; long long int power(long long int x, long long int n) { long long int res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; ...
#include <bits/stdc++.h> using namespace std; int main() { int p[3500]; int n; cin >> n; bool b = 1; int j = 1; for (int i = 1; i <= n; i++) { cin >> p[i]; } sort(p + 1, p + n + 1); for (int i = 1; i <= n; i++) { if (p[i] != j) { cout << j; return 0; ...
#ifndef ONPC #define _FORTIFY_SOURCE 0 #pragma GCC optimize( Ofast ) #pragma GCC optimize( no-stack-protector ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native ) #pragma GCC optimize( fast-math ) #endif #include <bits/stdc++.h> ...
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; if (str[0] > 96) { str[0] -= 32; } cout << str << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long int dx[] = {0, 1, 0, -1, -1, 1, -1, 1}; long long int dy[] = {-1, 0, 1, 0, -1, 1, 1, -1}; const long long int MAXN = 2e5 + 5; const long long int N = 2e5 + 5; long long int n, m; void LCSubsequence(string s1, string s2) { long long int n1 = s1.si...
#include <bits/stdc++.h> using namespace std; int n, ans = 0x3f3f3f3f; int a[100005], cnt; int b[100005], gc; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); for (int i = 1; i <= 9; ++i) { cnt = 0; if (i == 1) b[1] = a[1] - 1, b[2] = a[2] - 1; if (i...
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 ) #pragma GCC target( avx,avx2,fma ) using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int a, k, nc = 0, isz = 0; vector<unordered_set<int>...
#include <bits/stdc++.h> using namespace std; string s; int main() { int n, i, j, k, l, m; cin >> n; cin >> s; int cnt, ans; char c, c1, c2, c3; ans = 0; for (i = 0; i < n - 1; i++) { cnt = 0; if (s[i] == s[i + 1] && i < n - 1) { c = s[i]; while (s[i] == c) ...
#include <bits/stdc++.h> using namespace std; string s; int x[100009], y[100009], z[100009], m, l, r; int main() { cin >> s; cin >> m; for (int i = 1; i <= s.size(); i++) { x[i] = x[i - 1]; y[i] = y[i - 1]; z[i] = z[i - 1]; if (s[i - 1] == x ) x[i]++; if (s[i - 1] == ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[110]; for (int i = 0; i < n; i++) { cin >> a[i]; } int i, one, two, j, ans = 0; for (i = 0; i < k; i++) { for (one = 0, two = 0, j = i; j < n; j += k) { if (a[j] == 1) ...
#include <bits/stdc++.h> using namespace std; int n, a, b; int main() { cin >> n >> a >> b; int t = 1; int r = 0; if (a > b) { a ^= b ^= a ^= b; } while (t < n) { t <<= 1; ++r; } t >>= 1; if (a <= t && b > t) { cout << Final! << endl; return 0; ...
#include <bits/stdc++.h> using namespace std; const long long mo = 1e9 + 7; const int maxi = 1e6 + 6; long long a[maxi], x[maxi], b[maxi]; int n; long long t; int sum[maxi]; int los[maxi]; int ll[maxi]; int main() { cin >> n >> t; for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); for (i...
#include <bits/stdc++.h> using namespace std; typedef vector<vector<int>> graph; ifstream in( buffcraft.in , ios::in); ofstream out( buffcraft.out , ios::out); int pl, pr, vl, vr, k; vector<int> p; void dfs(long long x) { if (x < 1000000000) { p.push_back(x); dfs(x * 10 + 4); dfs(x *...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 256; int n, a[MAXN], k, ans; list<int> L; set<int> s, S; multiset<int> M; int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (i >= k) s.insert(a[i]); } if (s.size() > 1) { cout <<...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using v...
#include <bits/stdc++.h> using namespace std; long long ret = 0; long long La, Ra, Ta; long long Lb, Rb, Tb; long long GCD = 0; pair<long long, long long> gcd(long long a, long long b) { if (b == 0) { GCD = a; return {1, 0}; } pair<long long, long long> nxt = gcd(b, a % b); long ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; while (cin >> a >> b >> c) { if (b >= c) { b = c - 1; } else { c = b + 1; } if (a >= b) { a = b - 1; cout << a + b + c << endl; } else { b = a + 1; c = a + 2;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n, m, ans, l; int mark[MAXN], comp[MAXN], scc[MAXN], cyc[MAXN]; vector<int> edge[MAXN], adj[MAXN], radj[MAXN]; deque<int> dq; void dfs(int source) { mark[source]++; ans++, comp[source] = l; for (auto &u : edge[source]...
#include <bits/stdc++.h> using namespace std; long long int MAX3(long long int x, long long int y, long long int z) { long long int t = max(x, y); return max(t, z); } long long int power(long long int x, long long int n) { long long int i, ans = 1; for (i = 1; i <= (n); i += 1) { ans = ans...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int> > a(n, vector<int>(n)); int sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf( %d , &a[i][j]); if (i == j) sum += a[i][j]; } } sum &= 1; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<vector<int>> g; vector<int> deg; ll ans; int n, m; void add_edge(int x, int y) { if (x > y) { int t = x; x = y; y = t; } g[x].push_back(y); deg[x]++; deg[y]++; } void init() { scanf( %d...
#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 deb { template <class c> ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; inline bool checkBit(long long n, int i) { return n & (1LL << i); } inline long long setBit(long long n, int i) { return n | (1LL ...
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e3 + 20; long long inf = (long long)1e15; long long mod = (long long)1e9 + 7; long long n, cntr[MAX], cntc[MAX], l[MAX][MAX], used[MAX]; void swpr(long long ind1, long long ind2) { swap(cntr[ind1], cntr[ind2]); for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; size_t pos1 = s.find( AB ), pos2 = s.find( BA ); string tmp = s; s.erase(0, pos1 + 2); tmp.erase(0, pos2 + 2); bool check = false; if (pos1 == string:...
#include <bits/stdc++.h> using namespace std; string mask(int a) { string ans; int x = a; while (x) { if (x % 10 == 4 || x % 10 == 7) ans.insert(ans.begin(), x % 10 + 0 ); x /= 10; } return ans; } int main() { string b; int a; cin >> a >> b; a++; while (mask(...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f, mn1, mn2, res, ans1, ans2; cin >> a >> b >> c >> d >> e >> f; res = d; mn2 = min(b, min(c, d)); d = abs(mn2 - d); mn1 = min(a, d); ans1 = (mn2 * f) + (mn1 * e); mn1 = min(a, res); res = abs(mn1 - res...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int node[4][11][11][maxn]; int h[110]; char s[maxn], e[11]; int lowbit(int x) { return x & (-x); } void add(int ty, int pos, int x, int d) { for (; x < maxn; x += lowbit(x)) { for (int k = 1; k <= 10; k++) { node[ty...
#include <bits/stdc++.h> using namespace std; long long p[1000100], h[1000100], g[1000100], ans; int main() { int m, n, x, y; cin >> n >> m; for (int i = 0; i <= n; i++) p[i] = (i ? p[i - 1] * 9 : 1); while (m--) { scanf( %d%d , &x, &y); h[x] += p[y]; h[y] += p[x]; } for ...
#include <bits/stdc++.h> using namespace std; void die(string S) { puts(S.c_str()); exit(0); } int number[333][333]; int cnt[100100]; vector<int> V[100100]; int grid[333][333]; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<int> v; ...
#include <bits/stdc++.h> using namespace std; const int maxN = 10 + 5; char a[maxN][maxN][maxN]; int mark[maxN][maxN][maxN]; int k, n, m; int dx[] = {-1, 1, 0, 0, 0, 0}; int dy[] = {0, 0, -1, 1, 0, 0}; int dz[] = {0, 0, 0, 0, -1, 1}; int cnt; void dfs(int x, int y, int z) { mark[x][y][z] = 1; ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; int n = s.size(); int cz = 0; int co = 0; int ct = 0; for (int i = 0; i < n; i++) { co += (s[i] == 1 ); ct += (s[i] == 2 ); ...
#include <bits/stdc++.h> using namespace std; const int mx = (int)2e5 + 5; int n, c[mx], ans[mx]; char a[mx], b[mx]; void solve() { int cnt = 0, temp = 0; for (int i = n - 1; i >= 0; i--) { c[cnt++] = (a[i] + b[i] - 2 * a + temp) % 26; temp = (a[i] + b[i] - 2 * a + temp) / 26; } ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; int c = 0; cin >> a >> b; while (a > 0 && b > 0) { if (a > b) { a -= 2; b -= 1; } else { a -= 1; b -= 2; } if (a > -1 && b > -1) c++; } cout << c; }
#include <bits/stdc++.h> using namespace std; const int mod = 998244353, MAX = 100003, INF = 1 << 30; long long rui(long long a, long long b) { if (b == 1) return a % mod; else if (b == 0) return 1; else if (b % 2 == 0) return (rui(a, b / 2) * rui(a, b / 2)) % mod; else ret...
#include <bits/stdc++.h> using namespace std; int lenA, lenB; int A[1000004]; int B[1000004]; int idxB[1000004]; int lenP = 0, idxP = 0; long long P[1000004 * 2]; int main() { scanf( %d %d , &lenA, &lenB); for (int i = 0, _n = (lenA); i < _n; ++i) scanf( %d , A + i); memset(idxB, -1, sizeof(...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long d = (k / (n - 1)), r = (k % (n - 1)); if (r != 0) { cout <...
#include <bits/stdc++.h> int n, m; int main() { long long ans; int b, c, A, B, C, l; scanf( %d%d , &n, &m); n++; m++; ans = 0; for (c = m; c <= n - m; c++) { C = 2 * (n * n - n * c + c * c); for (b = n - m; b >= m; b--) { A = 2 * n - b - c; B = b * (n + c); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; struct node { int c, f, l, i; } a[maxn], b[maxn]; bool cmp1(node a, node b) { return a.f < b.f; } bool cmp2(node a, node b) { return a.c > b.c; } int main() { int n, d, s; scanf( %d%d%d , &n, &d, &s); int nn = n; in...
#include <bits/stdc++.h> using namespace std; bool flag; int vis[(1 << 17)]; int n, m, k; vector<pair<int, int> > vt[(1 << 17)]; void dfs(int u) { for (int i = 0; i < vt[u].size(); i++) { int v = vt[u][i].first; int c = vt[u][i].second; if (vis[v] == -1) { if (c == 1) ...
#include <bits/stdc++.h> using namespace std; int n, m, w[210], d[210][30010], f[30010], x[210][30010], u[30010], p; vector<int> a[30010], b[30010]; inline void GG() { printf( -1 n ); exit(0); } inline void line(int i, int j) { a[i].push_back(j); a[j].push_back(i); } inline void dfs(int ...
#include <bits/stdc++.h> using namespace std; int n; int main() { pair<long long, long long> s, e; long long t; cin >> t; cin >> s.first >> s.second >> e.first >> e.second; map<char, int> mp; string str; cin >> str; for (int i = 0; i < t; ++i) { mp[str[i]]++; } char d...
#include <bits/stdc++.h> using namespace std; class graph { int v; list<int>* adj; public: graph(int x) { this->v = x; adj = new list<int>[v]; } void add_edge(int a, int b) { adj[a].push_back(b); adj[b].push_back(a); } void count_colors(int a, int& n, int co...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int M = 1e9 + 7; int n; double v, v2, a[N], b[N]; double x, y; int id = 1; int main() { ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> v >> v2; for (int i = 0; i < n; ++i) { cin >> b[i]; ...
#include <bits/stdc++.h> using namespace std; const long long int maxn = 1e5 + 6; const long long int MOD = 1e9 + 7; vector<int> prim(1000005, 1); int fact[maxn]; long long int binomialCoeff(long long int n, long long int k) { long long int res = 1; if (k > n - k) k = n - k; for (long long int i...
#include <bits/stdc++.h> using namespace std; struct edge { int v, w; }; long long MOD = 1000000007; long long _MOD = 1000000009; double EPS = 1e-10; long long extgcd(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = (a >= 0) ? 1 : -1; y = 0; return abs(a)...
#include <bits/stdc++.h> using namespace std; const int INF = ((long long)1E9 + 7); template <class C> void mini(C& a, C b) { a = min(a, b); } template <class C> void maxi(C& a, C b) { a = max(a, b); } const int LG = 20; struct node { int par; vector<int> inc; bool monk; int ...
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(long long N, int pos) { return (bool)(N & (1LL << pos)); } int k, n; int ase[30]; string arr[2505]; vector<int> pos; vector<int> adj...
#include <bits/stdc++.h> using namespace std; int n, m, dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0}, mp[100005], b; int cheak(int x, int y) { if (abs(x - y) == m || abs(x - y) == 1) return 1; else return 0; } void dfs(int x) { if (x == n * m) { b = 1; cout << YES << endl; ...
#include <bits/stdc++.h> using namespace std; struct coordinate { float x; float y; }; float check1(coordinate c1, coordinate c2, coordinate c3, coordinate c4, coordinate x1) { float ans1 = (x1.y - c1.y) + (x1.x - c1.x); float ans2 = (x1.y - c3.y) + (x1.x - c3.x); if (ans1 == ...
#include <bits/stdc++.h> using namespace std; long long mul_mod(long long a, long long b, long long MOD) { return a * b; } struct myhash { long long chash[401000][2]; long long mult[401000][2]; long long b1, M1, b2, M2; myhash(long long b1 = 1000000021, long long M1 = 1200000000000000013LL, ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; long long mpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % mod; x = x * x % mod; n /= 2; } return res; } long long s2(long long n) { n %= mod; return n ...
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { if (a > b) return true; else return false; } struct pack { long long t, T, x, cost; }; int main() { long long ans = 0, n, m; cin >> n >> m; vector<pack> data; for (int i = 0; i < (n); ++i) { ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long infl = 0x3f3f3f3f3f3f3f3fLL; template <class T> void rd(T &a) { char ch = getchar(); bool ng = 0; a = 0; for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) ng = 1; for (; ch >= 0 && c...
#include <bits/stdc++.h> #define PI atan(1.0)*4 #define rp(i,s,t) for (register int i = (s); i <= (t); i++) #define RP(i,t,s) for (register int i = (t); i >= (s); i--) #define sc(x) scanf( %d ,&x) #define scl(x) scanf( %lld ,&x) #define ll long long #define ull unsigned long long #define mst(a,b) memset...
#include <bits/stdc++.h> const int N = 2e5 + 3; int n, m, l[N + N + N], r[N + N + N], k; char a[N + N + N], b[N]; int main() { int p, q; scanf( %d%d%s , &n, &m, a + 1); for (int i = 1; i <= n; i++) a[i + n] = a[i + n + n] = a[i]; for (int i = 1; i <= n; i++) b[i] = a[i]; for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, k, x, d[200001] = {}, last_d = 1, last = 0, a; long long sum = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> t; if (1 == t) { cin >> a >> x; sum += a * x; if (last_d == 0) { last +=...
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> n >> d; int t[n], sum = 0, rest = (n - 1) * 10; for (int i = 0; i < n; i++) { cin >> t[i]; sum = sum + t[i]; } if ((rest + sum) > d) { cout << -1 ; return 0; } else { int bal = d - ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:100000000 ) using namespace std; const int N = 200; char s[N][N]; int main() { int C; cin >> C; int n = 3; while (n * (n - 1) * (n - 2) / 6 <= C) ++n; int m = --n; C -= n * (n - 1) * (n - 2) / 6; vector<int> add; while (C...
#include <bits/stdc++.h> using namespace std; const int64_t INF = 0x7FFFFFFF; const int MAX = 1; unordered_map<int, int> maps; unordered_map<int, int> cnt; int main(int argc, char* args[]) { int n; scanf( %d , &n); for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) { int x; scanf( %d...
#include <bits/stdc++.h> using namespace std; bool lucky(char a) { if (a == 4 || a == 7 ) return true; else return false; } int main() { long long int a, b, c, d; vector<bool> res; cin >> a >> b >> c >> d; if (abs(c - d) > 1 || min(a, b) < max(c, d)) { puts( -1 ); ...
#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf; inline int qread() { register char c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++); register int x = 0, f = 1; while (c < 0 || c > 9 )...
#include <bits/stdc++.h> using namespace std; int s[3000005], ps[3000005][5]; int n, ans; vector<int> temp; int po(int a, int b) { if (b == 0) return 1; return a * po(a, b - 1); } void prep() { int ptr1 = 1, ptr2 = 1, maxi = 0; ps[1][0] = 1; for (int i = (2); i <= (3000000); i++) { ...
#include <bits/stdc++.h> using namespace std; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; ...
#include <bits/stdc++.h> using namespace std; const long long int maxn = 2e5 + 5; long long int sz[maxn], dp[maxn], ans[maxn]; vector<long long int> g[maxn]; long long int n; long long int dp1(long long int node, long long int parent) { sz[node] = 1; for (auto& itr : g[node]) if (itr != parent...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[16] = {0}; int index = 0; for (int i = 1; i <= n; i++) { string s = to_string(i); bool lucky = true; for (int j = 0; j < (s.length()); j++) { if (s[j] != 4 && s[j] != 7 ) { lu...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; set<long long> ss; for (int i = 1; i <= 1e6; i++) { long long need = i * 2; long long cards = (i * (i + 1)) / 2; l...
#include <bits/stdc++.h> using namespace std; struct edge { int v, nxt, c; } e[1505 * 1505 * 2]; int p[1505], eid; void init() { memset(p, -1, sizeof p); eid = 0; } void insert(int u, int v, int c) { e[eid].v = v; e[eid].c = c; e[eid].nxt = p[u]; p[u] = eid++; } void add(in...
#include <bits/stdc++.h> const int MAXN = 1e5 + 5; enum { GRASS = G , WATER = W , LAVA = L }; enum { G = 5, W = 3, L = 1 }; long long a[MAXN]; char s[MAXN]; int n; bool water; long long grass, stamina, t; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %lld , &a[i]...
#include <bits/stdc++.h> using namespace std; int n; vector<vector<int>> g; vector<int> w; vector<int> dp; void dfs(int node, int p) { dp[node] = w[node]; for (int u : g[node]) { if (u != p) { dfs(u, node); dp[node] += dp[u]; } } } int main() { cin >> n; i...
#include <bits/stdc++.h> using namespace std; int n; int a[300010]; long long ans = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } sort(a + 1, a + 1 + n); for (int i = 1; i <= n / 2; ++i) { long long sum...
#include <bits/stdc++.h> using namespace std; vector<int> a; vector<int> b; int n; void get_input() { cin >> n; } void solve() { for (int i = 0; i < n; i++) { int kom; cin >> kom; a.push_back(kom); b.push_back(kom); } sort(b.begin(), b.begin() + n); int cnt = 0; f...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; const double pi = 3.14159265358979323846264338327950288419716939937...
#include <bits/stdc++.h> const int mod = 1000000007; struct uinon_set { int father[100003], n, value[100003]; int ans; void init() { ans = 0; for (int i = 1; i <= n; i++) { father[i] = i; value[i] = 0; } return; } int getfather(int i) { if (father[i]...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 5e5 + 5; bool vis[MAXN]; long long sp[MAXN]; long long f[MAXN]; bool is[MAXN]; long long ar[MAXN]; long long POWER[25]; long long F[25]; void sieve() { for (long long i = 0; i < MAXN; i++) vis[i] = false, sp[i] = 2; for (lo...
#include <bits/stdc++.h> using namespace std; int main() { int x, y; string s, t; cin >> x >> y >> s >> t; int arr[y - x + 1]; int mx = -1, res; for (int i = 0; i < y - x + 1; i++) { int k = i; arr[i] = 0; for (int j = 0; j < x; j++, k++) { if (t[k] == s[j]) arr[i] ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, m; cin >> n >> k; m = n * (n - 1) / 2; if ((double)k > ((double)n - 1) / 2) { cout << -1; return 0; } else { cout << k * n << endl; for (int i = 1; i <= n; ++i) { for (int j = 0; j < k; ++j) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long inf = 0x3f3f3f3f3f3f3f3f; const int maxn = 1005; int main() { int N; cin >> N; cout << 2 * N - 1 << << 2 << endl; cout << 1 << << 2 << endl; return 0; }
#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--) { int n; cin >> n; vector<pair<pair<int, int>, int> > a(2 * n - 1); for (int i = 0; i < 2 * n - 1; i++) { cin >> a[i].firs...
#include <bits/stdc++.h> using namespace std; template <typename T1> void print_list(const T1& a) { cerr << a << endl; } template <typename T1, typename T2> void print_list(const T1& a, const T2& b) { cerr << a << << b << endl; } template <typename T1, typename T2, typename T3> void print_...
#include <bits/stdc++.h> using namespace std; long long n, k; char s[1005], ans[1005]; map<long long, bool> dp[1005]; map<long long, char> pre[1005]; inline long long read() { long long q = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = 0; ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) { ans = (ans * a) % 1000000007; } a = (a * a) % 1000000007; b = b / 2; } return ans; } int main() { cin.tie(0); ios::sync_w...
#include <bits/stdc++.h> using namespace std; list<int> l[100005]; list<int> son[100005]; int n, dad[100005], x, y, val[100005], res; void f(int a) { for (list<int>::iterator it = l[a].begin(); it != l[a].end(); it++) if ((*it) != dad[a]) { dad[*it] = a; f(*it); son[a].push_b...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); if (fopen( input.txt , r )) { freopen( input.txt , r , stdin); freopen( output.txt , w , stdout); } int n, a, b; cin >> n; bool visit[1000005] = {false}; int ans = -1...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int tt; cin >> tt; while (tt--) { int n; int diff = 0; cin >> n; ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } int main() { int n, p, k, ai; cin >> n >> k >> p; vector<int> ods; ...
#include <bits/stdc++.h> using namespace std; int fa[101000][20], h[101000], lev[101000], ans[101000]; int dp[101000]; struct EDGE { int to, nxt; } box[2 * 101000]; int top, K; void add(int u, int v) { box[top].to = v; box[top].nxt = h[u]; h[u] = top++; } void DFS(int u, int pre, int t...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long extgcd(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return a; } long long x1, y1; long ...