func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int G[16][110]; bool B[110][2]; int main() { memset(G, -1, sizeof(G)); for (int i = 0; i < 16; i++) { G[i][0] = 0; } for (int j = 1; j <= 105; j++) { for (int i = 0; i < 16; i++) { if ((i & 5) == 5 || (i & 10) == 10) { c...
#include <bits/stdc++.h> using namespace std; long long int maxSubArraySum(long long int a[], long long int size) { long long int max_so_far = INT_MIN, max_ending_here = 0; for (long long int i = 0; i < size; i++) { max_ending_here = max_ending_here + a[i]; if (max_so_far < max_ending_here) max_...
#include <bits/stdc++.h> using namespace std; const int N = 200010; long long a[N], f[N]; int main() { long long o, t, n = 1; long long s = 0; scanf( %I64d , &o); while (o--) { scanf( %I64d , &t); if (t == 2) { n++; scanf( %I64d , &a[n]); f[n] = 0; s +...
#include <bits/stdc++.h> using namespace std; long long n, d[500][500], dist[500][500]; long long t, a, c, b; int main() { cin >> n; for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= n; j++) { cin >> d[i][j]; dist[i][j] = d[i][j]; } } long long tong; ...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; const int MAX = 2e5 + 5; const long long MAX2 = 11; const int MOD = 1000000000 + 7; const long long INF = 20000; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1}; const double pi = acos(-...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (a % b != 0) { long long aux = a % b; a = b; b = aux; } return b; } int main() { ios::sync_with_stdio(0); cin.tie(); int n; cin >> n; for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); double exp, ans, pi; exp = ans = 0.0; for (int i = 0; i < n; i++) { scanf( %lf , &pi); exp = exp * pi + pi; ans = ans + 2 * exp - pi; } printf( %.12lf n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(T x) { return x * x; } const double EPS = 1e-10; const int INF = 0x3fffffff; const long long LINF = INF * 1ll * INF; const double PI = acos(-1.0); using namespace std; int sign(double x) { return x > 0 ? 1 : -1; } in...
#include <bits/stdc++.h> using namespace std; int main() { int k, rt, i, j; char a[] = { a , e , i , o , u }; cin >> k; rt = (int)sqrt(k); for (; k % rt != 0; rt--) ; if (rt > 4) { for (i = 0; i != k / rt; i++) { for (j = 0; j != rt; j++) { cout << a[(i + j)...
#include <bits/stdc++.h> using namespace std; const int N = 505; int dp[N][N]; int a[N]; int calc(int l, int r) { if (dp[l][r] != -1) return dp[l][r]; if (l > r) { return dp[l][r] = 1; } if (l == r) { return dp[l][r] = 1; } dp[l][r] = N; if (a[l] == a[r]) { dp[l][...
#include <bits/stdc++.h> const long long int M = 2000000005; using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int t; t = 1; while (t--) { long long int n, i, c, j; string s; cin >> s; n = s.size(); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; long long an1 = 1, an2 = 1; for (int i = 0; i < n; ++i) { an1 = (an1 * 7) % 1000000007; } for (int i = 0; i < 3 * n; ++i) { an2 = (an2 * ...
#include <bits/stdc++.h> int p, prime[100005], count[100005][20]; void Prime() { int i, j; for (i = 2, p = 0; i < 100005; i++) { for (j = 2; j <= sqrt(i); j++) if (i % j == 0) break; if (j > sqrt(i)) prime[p++] = i; } } void Count() { int i, j; memset(count, 0, sizeof(cou...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; err(++it, args...); } long long powMod(long long x, long long y) { long lon...
#include <bits/stdc++.h> using namespace std; struct node { int x, id; friend bool operator<(node a, node b) { if (a.x == b.x) return a.id < b.id; return a.x < b.x; } } a[200005]; priority_queue<node> Q; struct edge { int s, e; } ans[2000005]; int id; int main() { int n, ...
#include <bits/stdc++.h> using namespace std; const int N = 1E5 + 1; long long int n, m, rk, ans; set<pair<long long int, long long int> > dep[N], dpt; vector<pair<long long int, pair<long long int, long long int> > > query; pair<long long int, long long int> arrival[N]; long long int setarrival() { f...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a, b; cin >> a >> b; int pa = 0; while (pa + 1 < a.size() && a[pa + 1] < b[0]) pa++; for (int i = 0; i <= pa; i++) cout << a[i]; cout << b[0]; }
#include <bits/stdc++.h> using namespace std; void SieveOfErat() { bool prime[1000001]; memset(prime, true, sizeof(prime)); for (long long p = 2; p * p <= 1000000; p++) { if (prime[p] == true) { for (long long i = p * 2; i <= 1000000; i += p) prime[i] = false; } } } long long...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, dx, dy, ans = 0, a, b; map<long long, int> num; double k; scanf( %lld%lld%lld%lld , &n, &m, &dx, &dy); long long x, y; for (int i = 0; i < m; i++) { scanf( %lld%lld , &x, &y); k = ((dy * x - dx * y) % n + ...
#include <bits/stdc++.h> int get() { int x = 0; char s = getchar(); while (s < 0 || s > 9 ) s = getchar(); while (s >= 0 && s <= 9 ) x = (x << 3) + (x << 1) + (s ^ 48), s = getchar(); return x; } const int M = 1e5 + 5; int n, m, head[M], cntedge, ans, s, a[M << 2]; bool c[M], v...
#include <bits/stdc++.h> using namespace std; const int N = 1 << 17; const int LOG = 17; int n, m, q, tick; int id[N], st[N], nd[N], ch[N], dep[N], lca[LOG][N]; vector<int> v[N]; void dfs(int p, int x) { dep[x] = dep[p] + 1; lca[0][x] = p; for (int i = 1; i < LOG; i++) lca[i][x] = lca[i - 1][l...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; scanf( %d %d %d %d , &a, &b, &c, &d); int M, M1, M2, V, V1, V2; M1 = (3 * a) / 10; M2 = (a - (a / 250) * c); if (M1 > M2) { M = M1; } else { M = M2; } V1 = (3 * b) / 10; V2 = (b - (b / 250)...
#include <bits/stdc++.h> using namespace std; const long long LINF = 1e18; const long long MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const int MAXN = 200050; int a[MAXN], cnt[105]; unordered_map<int, int> mp; void solve(int T) { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { s...
#include <bits/stdc++.h> using namespace std; long long int mod1 = 1000000007; long long int mod2 = 67280421310721; long long int mod3 = 998244353; long long int INF = 1e18; long long int binpow1(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b & 1) res = res * ...
#include <bits/stdc++.h> using namespace std; int freq[3]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { freq[s[i] - 0 ]++; } for (int i = n - 1; i >= 0; i--) { if (freq[0] <= n / ...
#include <bits/stdc++.h> using namespace std; long long n, m, ps[69][69]; bitset<69> a[69]; long long sm(long long y1, long long x1, long long y2, long long x2) { return max(ps[y2][x2] - ps[y1 - 1][x2] - ps[y2][x1 - 1] + ps[y1 - 1][x1 - 1], 0ll); } int main() { long long t, rr, i, j; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const int N = (int)1e6 + 7; int n, k; int a[N], bit[N]; map<int, int> cnt[11]; long long dp[N][11]; void Init() { for (int i = (1); i < (11); ++i) cn...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; c *= 2; int d = a / c; if (d > 1) d -= 1; int e = b / c; if (e > 1) e -= 1; int res = d * e; if (!res % 2) cout << Second n ; else cout << First n ; }
#include <bits/stdc++.h> using namespace std; const int maxn = 55; const int M = 1000000007; int n, p, c[maxn]; long long ans = 0, pw[maxn], od[maxn], ev[maxn], f[maxn][maxn][maxn][maxn]; void init() { f[0][0][0][0] = 1; pw[0] = 1; for (int i = 1; i < maxn; i++) pw[i] = pw[i - 1] * 2 % M; ev...
#include <bits/stdc++.h> using ll = long long; int n, q; namespace BIT { int seg[100005]; inline void modify(int pos, int val) { for (; pos <= n; pos += pos & -pos) seg[pos] += val; } inline int query(int pos) { int res = 0; for (; pos; pos -= pos & -pos) res += seg[pos]; return res; } ...
#include <bits/stdc++.h> using namespace std; struct Query { int id, left, right, time, blockLeft, blockRight; Query() : id(-1), left(-1), right(-1), time(-1), blockLeft(-1), blockRight(-1) {} Query(int id, int left, int right, int time, int blockLeft, int blockRight) : id(id), ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int arr[n]; int count = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { int x = 5 - arr[i]; if (x >= k) { count++; } } cout << count...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const int MAXN = -1; const int MOD = 1; int main() { int n; while (cin >> n) { string s; cin >> s; vector<int> d(n); for (int i = 0; i < n; i++) cin >> d[i]; int cur = 0; vector...
#include <bits/stdc++.h> const long long inf = 1000000000ll; const long long inf64 = inf * inf; const long long base = inf + 7; const long long MOD = inf + 9; const double pi = acos(-1.0); using namespace std; bool solve() { int n, q; scanf( %d %d , &n, &q); vector<long long> a(2 * n + 1); ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 1e18; vector<long long> factorial; void fill_factorial(long long n) { factorial.resize(n + 1); factorial[0] = 1; for (long long i = 1; i <= n; i++) factorial[i] = (factorial[i - 1] * i) % mod; ...
#include <bits/stdc++.h> using namespace std; int main() { char s[1100000]; scanf( %s , s); int l = strlen(s); int ans = 0; int m = 0; int p = 0; while (s[p] == F ) p++; for (int i = p; i < l; i++) { if (s[i] == M ) { m++; } if (s[i] == F ) { ans ...
#include <bits/stdc++.h> long long int dx[] = {-2, -2, -1, 1, 2, 2, 1, -1}; long long int dy[] = {-1, 1, 2, 2, 1, -1, -2, -2}; using namespace std; bool comp(long long int x, long long int y) { return abs(x) > abs(y); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int te...
#include <bits/stdc++.h> using namespace std; int Gcd(int x, int y) { while (x > 0 && y > 0) { if (x > y) { x = x % y; } else { y = y % x; } } return x + y; } int Sign(int x) { return (x > 0) ? 1 : -1; } int Abs(int x) { return (x > 0) ? x : -x; } void ReduceFra...
#include <bits/stdc++.h> using namespace std; long long add(long long a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; return a; } long long mul(long long a, long long b) { return ((a % 1000000007) * (b % 1000000007)) % 1000000007; } long long binary_expo(long long base, long ...
#include <bits/stdc++.h> using namespace std; int ans, n, m, f1[1000005], vis[1000005], vis1[1000005], num, g1[1000005], k; long long f[1000005], g[1000005]; struct he { int d, s, t, c; } a[1000005]; bool cmp(he a, he b) { return a.d < b.d; } int main() { scanf( %d%d%d , &n, &m, &k); for (int ...
#include <bits/stdc++.h> using namespace std; int n, k; bool check(int x) { int s[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int t; while (x > 0) { t = x % 10; if (t <= k) s[t]++; x /= 10; } for (int i = 0; i <= k; i++) { if (s[i] == 0) return false; } return true; }...
#include <bits/stdc++.h> using namespace std; int n, m, k, x[100005], pn, st; pair<int, pair<int, int> > p[100005]; priority_queue<pair<int, pair<int, int> > > q, qq; int main() { scanf( %d%d , &n, &m); for (int a = (1); a <= (n); a++) for (int b = (1); b <= (m); b++) p[pn++] = make_pair...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int n, sa[N], sb[N], a1[N], b1[N], suma, sumb, q[N]; struct nd { int w, id; } a[N], b[N]; bool cmp(nd a, nd b) { return a.w > b.w; } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , &a[i].w), a[i]....
#include <bits/stdc++.h> using namespace std; const int N = 5; const int M = 1e7 + 1; const long long INF = 1LL << 61; long long a[N], t[N], cost[N]; inline long long bs(long long bytes, long long maxt) { long long res = -1; if (t[0] <= t[2]) { if ((t[0] * bytes) <= maxt) { res = 0; ...
#include <bits/stdc++.h> using namespace std; double round(double x) { return ((long long)(x * 1e8 + 0.5)) / 1e8; } double x[5], y[5], r[5]; set<pair<double, double> > c[5]; set<pair<double, double> > u; void intersection(int i, int j) { double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[...
#include <bits/stdc++.h> const int INF = 1000000; using namespace std; int main() { int a, b, m; vector<int> r(1); scanf( %d %d %d %d , &a, &b, &m, &r[0]); for (int i = 1; i < 2 * m + 2; i++) { r.push_back((a * r[i - 1] + b) % m); } vector<int> ans(2 * m + 2, INF); int res = 1; ...
#include <bits/stdc++.h> const int N = 120000; using namespace std; vector<string> fig; int n, m; vector<vector<string> > figs; int ans; vector<pair<pair<int, int>, int> > avec; int board[200][200]; bool bad(int a, int b) { return (a < 0 || a >= n || b < 0 || b >= m || board[a][b] == 1); } vec...
#include <bits/stdc++.h> using namespace std; const long long LLINF = 9223372036854775807LL; const int INF = 2147483647; const int MOD = 1000000007; const double eps = 1e-7; const double PI = acos(-1.0); int dr[] = {1, 0, -1, 0, -1, 1, 1, -1}; int dc[] = {0, -1, 0, 1, 1, 1, -1, -1}; int m; pair<int,...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const int INF = 1e12; const int maxnnn = 2e8 + 30; const long long zero = 0; long long gcd(long long a, long long b) { if (a < b) swap(a, b); if (a % b == 0) return b; else gcd(b, a...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; long long int x = 0; vector<long long int> sum = {}; vector<long long int> val = {}; for (int i = 0; i < (int)q; i++) { int op; cin >> op; if (op == 1) { cin >> x; sum.push_back(((su...
#include <bits/stdc++.h> using namespace std; template <typename T> T inverse(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u; } template <typename T> class Modular { pub...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; const long long INF = numeric_limits<long long>::max(); enum { EVEN, ODD }; int A[MAXN]; long long dp[2][MAXN]; int main() { int N; cin >> N; for (int i = 1; i <= N; ++i) cin >> A[i]; dp[ODD][1] = dp[EVEN][1] = dp[...
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX, df = 8e5 + 7; int i, j, k = 1, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, le[df], rig[df], c[df][26], ma[df << 1], head[df], pos[df << 1], tot, ans[df], fail[df], cnt, yet[df][26]; struct node { int sum, id; }...
#include <bits/stdc++.h> using namespace std; const int size_c = 26; const int Maxn = 500010 << 1; string s[100020]; int w[100020]; int n; struct Suffix_Automaton { int ch[Maxn][size_c]; int f[Maxn]; int ml[Maxn]; int sz, head, tail; long long val[Maxn]; int cnt[Maxn], id[Maxn]; ...
#include <bits/stdc++.h> using namespace std; void time() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { time(); int a, s, d, f; cin >> a >> s >> d >> f; if (a == s || s > a) { cout << Second << endl; } else { cout << First << endl; }...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { string s; cin >> s; int n = s.length(); vector<int> dist(n); for (int i = 0; i < n; i++) if (s[i] == 0 ) dist[i] = (i ? dist[i - 1] : 0) + 1; vector<int> dp(n + 2), nxt(n + 2, n); auto get = [...
#include <bits/stdc++.h> using std::cin; using std::string; string x; int a, b, c; int main() { cin >> x; switch (x[0]) { case r : a = 0; break; case s : a = 2; break; case p : a = 5; break; } cin >> x; switch (x[0]) { ...
#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; long long int p = sqrt(n); for (int i = 5; i <= p; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false; retu...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, p, s; cin >> n; int a[5][5]; for (i = 1; i <= 4; i++) { for (j = 1; j <= 4; j++) { cin >> a[i][j]; } } s = 0; for (i = 1; i <= 4; i++) { k = min(a[i][1], a[i][2]); p = min(a[i][3], ...
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; struct Cup { uint cap; uint ix; uint cur; }; int main() { uint n; uint total; cin >> n >> total; vector<Cup> cups(n); for (uint i = 0, wi; i < n; ++i) { cin >> wi; cups[i] = {wi, i, 0}; } ...
#include <bits/stdc++.h> using namespace std; int n, m, A[405][405], B[405][405], a[405][405]; char s[405][405]; void Solve() { cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> (s[i] + 1); for (int j = 1; j <= m; ++j) { a[i][j] = s[i][j] - 0 ; } } for (int j = 1; j...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; int n[2], k[2]; string s[] = { First , Second }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n[0] >> n[1] >> k[0] >> k[1]; int cur = 0; while (1) { if (n[cur] == 0) break;...
#include <bits/stdc++.h> inline int getint() { register char ch; while (!isdigit(ch = getchar())) ; register int x = ch ^ 0 ; while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ 0 ); return x; } const int N = 101, K = 41, mod = 1e9 + 7; int k, f[N][K], tmp[K]; std::fo...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> p(n + 1); for (long long i = 1; i < n + 1; i++) { long long x; cin >> x; p[x] = i; } multiset<pair<long long, long long> > k; vector<long long> ct(n + 1, 1); for (l...
#include <bits/stdc++.h> int d, n, m; int deq[200100]; int qs, qe; struct stt { int x, p; bool operator<(const stt& r) const { return x < r.x; } }; stt a[200100]; int main() { int i, j; long long int ans; scanf( %d%d%d , &d, &n, &m); for (i = 0; i < m; i++) { scanf( %d%d , &a...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool size = false, small = false, cap = false, digit = false; if (s.size() >= 5) { size = true; for (int i = 0; i < s.size(); i++) { if (s[i] == ! || s[i] == _ || s[i] == ; || s[i] == , || ...
#include <bits/stdc++.h> using namespace std; string q; string d; int b; void f(string s, int p) { char a = 0; int c = 0; if (s.size() <= p) return; for (int i = p; i < s.size(); i++) { if (s[i] > a) { a = s[i]; b = i; c = 1; } else if (s[i] == a) { ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } return x * f; } const int mod = 998...
#include <bits/stdc++.h> using namespace std; int n, m; vector<vector<int> > G; double dfs(int u, int p = -1) { double res = 0; int cnt = 0; for (int i = 0; i < G[u].size(); ++i) { int v = G[u][i]; if (v == p) continue; cnt++; res += dfs(v, u); } return (cnt ? res / c...
#include <bits/stdc++.h> using namespace std; int n; int x[1000005], y[1000005]; int s[1000005], _sum[1000006], _sumx[1000006], _sumy[1000006], *sum = _sum + 1, *sumx = _sumx + 1, *sumy = _sumy + 1; long long _tot[1000006], *tot = _tot + 1; const int MOD = 1e9 + 7; inline int area(int x, int y, int ...
#include <bits/stdc++.h> using namespace std; struct node { int l, c; } a[100005]; int b, c, d, e, f[205], g, h, i, j, k, l, m, n, s[100005]; inline bool cmp(node a, node b) { return a.l < b.l; } int main() { scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i].l); for (i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; int gcd(int u, int v) { return (v != 0) ? gcd(v, u % v) : u; } struct disjoint_sets { int parent[100000 + 10]; int ccOfParent[100000 + 10]; int cc; disjoint_sets(int V) { cc = V; for (int i = 1; i <= V; i++) parent[i] = i, ccOfParent[i] = 1...
#include <bits/stdc++.h> using namespace std; int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; } long long n; long long x[1010]; long long y[1010]; int main() { cin >> n; for (int i = 0; i < n / 3; i++) { printf( %d %d n , 0, i * 2 + 1); } for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2010; struct Point { long long x, y; int id; Point(int _x = 0, int _y = 0, int _id = 0) : x(_x), y(_y), id(_id) {} void read(int i) { id = i; scanf( %lld%lld , &x, &y); } } ps[maxn]; Point operator-(Point a, Point b...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a, b, f = 0; long long min = 500, max = 0; string s = ; long long suma = 0, sumb = 0; for (int i = 0; i < n; i++) { cin >> a >> b; if (abs((suma + a) - sumb) <= 500) { s += ...
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); int main() { int n, m, cnt, i, j; while (~scanf( %d%d , &n, &m)) { if ((n % 2 == 0 && m * 2 <= n * n) || (n % 2 && m * 2 <= n * n + 1)) { printf( YES n ); cnt = 0; for (i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int C = 26; void add(int &x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x) { while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int pw(int a, int b) { ...
#include <bits/stdc++.h> using namespace std; using llong = long long; inline char Flip(char x) { return (x == 0 ) ? 1 : 0 ; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; vector<int> ans; while (t--) { int n; cin >> n; n *= 2;...
#include <bits/stdc++.h> using namespace std; int n, m, u, v, flag, num, vis[100100]; vector<int> edge[100100]; queue<int> sk[100100]; struct G { int a, b, c; } ans[100100]; void dfs(int u, int father) { vis[u] = true; for (int i = 0; i < edge[u].size(); ++i) { int v = edge[u][i]; ...
#include <bits/stdc++.h> int main() { int n, k, i, start; bool b; while (scanf( %d%d , &n, &k) != EOF) { if (n < k || k == 1 && n > 1) { printf( -1 n ); continue; } start = k; for (i = b = 0; i < n; i++) { if (b && n - i == k - 2) { start = 2; ...
#include<bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; const int maxn=1e6+100; const int M=1000000007; typedef array<int,41> A; struct hasher { size_t operator()(const A& p) const { size_t result = 0; for (int i=1;i<=40;i++) result = result * 1926...
#include <bits/stdc++.h> using namespace std; const int NN = 1000100; int link[NN], fail[NN], len[NN], dif[NN], nxt[NN][26]; int ed, sz, cur; char s[NN], S[NN], T[NN]; int tp[NN], dp[NN], pre[NN], pr[NN]; void clear(int u, int L = 0) { len[u] = L; } void init() { sz = 2; ed = 1; cur = 0; ...
#include <bits/stdc++.h> using namespace std; struct Fenwick { vector<long long> BIT; long long N; Fenwick(long long n) { N = n + 2; BIT.resize(N + 10); } void reset() { for (long long i = 0; i <= N; i++) { BIT[i] = 0; } } void add(long long r, long long v...
#include <bits/stdc++.h> using namespace std; const long long LINF = 1e18; const long long INF = 1e9; const long long MOD = 1000000007; const long long MAX = 100005; #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( -ffloat-store ) #p...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, vector<int> > map1; for (int i = 1; i <= n; i++) { int a; cin >> a; map1[i].push_back(a); map1[a].push_back(i); } int counter = 0; map<int, bool> check; for (int i = 1; i <= n...
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 10; const long long inf = 1e18; const long long mod = 1e9 + 7; long long n, q; long long a[maxn]; long long cost(long long g) { long long ans = 0; for (long long i = 1; i <= n; i++) { if (a[i] < g) ans += g - ...
#include <bits/stdc++.h> using namespace std; long long h, n; int main() { cin >> h >> n; long long ans = 0; long long l = 1, r = (1LL << h); int dir = 0; for (int i = h - 1; i >= 0; i--) { ans++; long long mid = (l + r) / 2; if (dir == 0) { if (mid < n) { a...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int two = 0, one = 0; int x[n + 1000]; for (int i = 0; i < n; ++i) cin >> x[i]; for (int i = 0; i < n; ++i) { if (x[i] == 2) ++two; else ++one; } if (two == 0) { for (int i =...
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } const int maxn = 3 * (int)1e5 + 5; int n; int a[maxn]; int p[maxn]; int main() { srand(time(NULL)); ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string colors = ROYGBIV ; string remainder = GBIVGB ; string answer = ; for (int i = 0; i < n / 7; ++i) { answer += colors; } for (int i = 0; i < n % 7; ++i) { answer += remainder[i]; } ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, N = 1e5 + 5; int n, m, sta[N], tp, tot, siz[N], low[N], dfn[N], be[N], bl, dep[N], f[N][22], w[N]; vector<int> e[N], vec[N]; int read() { int x = 0, f = 1; char s; while ((s = getchar()) > 9 || s < 0 ) if (s == ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 7; const long long INF = 1e18 + 5; const long long maxn = 5e5 + 5; long long n = 100000000000, a[1555555], d[555555], mx = -1000000001; long long u[1511111], b[1100005], sum, cnt, t[555555]; long long bi(long long x, long long y) { ...
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862; void gn(int &x) { int sg = 1; char c; while (((c = getchar()) < 0 || c > 9 ) && c != - ) ; if (c == - ) sg = -1, x = 0; ...
#include <bits/stdc++.h> using namespace std; int pct(int x) { return __builtin_popcount(x); } int pct(long long x) { return __builtin_popcountll(x); } int bt(int x) { return 31 - __builtin_clz(x); } int bt(long long x) { return 63 - __builtin_clzll(x); } int cdiv(int a, int b) { return a / b + !(a < 0 || a...
#include <bits/stdc++.h> using namespace std; struct number { long long sum, a, b; bool operator<(const number& in) const { return sum < in.sum; } bool operator>(const number& in) const { return sum > in.sum; } }; vector<number> v; const long long MN = 2000 + 1; long long a[MN], b[MN]; long lo...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const int xx[4] = {1, -1, 0, 0}; const int yy[4] = {0, 0, 1, -1}; int inline nextin() { int t; if (scanf( %d , &t) != 1) exit(0); return t; } int inline in() { int x = 0...
#include <bits/stdc++.h> int main() { long long int a, i, j, k = 1; scanf( %lld , &a); for (i = 1; i <= a; i++) { k = k * 2; } k = 2 * (k - 1); printf( %lld n , k); return 0; }
#include <bits/stdc++.h> using namespace std; int a[500500], b[500500]; int main() { int n, q; int p1 = 1; int p2 = 1; scanf( %d%d , &n, &q); for (int i = 1; i <= n; i++) { if (i % 2) a[i / 2 + 1] = i; else b[i / 2] = i; } int tt = 0; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; namespace number_theory { long long gcd(long long x, long long y) { if (x == 0) return y; if (y == 0) return x; return gcd(y, x % y); } bool isprime(long long n) { if (n <= 1) return false; if (n <= 3) return true; ...
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) int main(int argc, char **argv) { ifstream from; const int nmin = 2, nmax = 300, kmin = 1, kmax = 300; int n, rt, rt1, rt2, i, j, j0, j1, k; int err = 0; char ch; cin >> n; vector<vector<int>> d(n); for (...