func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 5005; int n, m, ans[N]; pair<int, int> p[N]; vector<pair<int, int> > g[N]; void dfs(int v, int pr = -1) { for (auto it : g[v]) { int to = it.first; if (to != pr) { p[to] = make_pair(v, it.second); dfs(to, v); }...
#include <bits/stdc++.h> using namespace std; const int N = 1001; char s[N]; bool check(char a, char b) { if (a == b) return true; if (a > b) swap(a, b); if (b - a > 2) return false; if (b - a == 2) return true; if (b - a == 1) return false; } bool solve() { int n; scanf( %d%s , ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int main() { int num, dig; scanf( %d%d , &num, &dig); vector<int> a, b; for (int i = 0; i < num / dig; i++) { int z; scanf( %d , &z); a.push_back(z); } for (int i = 0; i < num / dig; i++) { in...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast , unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const long long inf = numeric_limits<long long>::max() / 2; const long double eps = 1e-9; co...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, MAXN = 4e5 + 10; int dp[MAXN], dp2[MAXN]; int *cur = dp2, *prv = dp; int main() { int r, g; cin >> r >> g; int b = r + g; int n; for (n = 1; n * (n + 1) / 2 <= b; n++) ; n--; cur[0] = 1; for (int i = 1...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; int num; int sa[N], fir[N], sec[N], t[N]; int height[N], L[N], R[N], st[N]; char c[N]; inline long long SA(int len, char s[]) { num = 300; for (int i = 1; i <= num; i++) t[i] = 0; for (int i = 1; i <= len; i++) ++t[fir[i] =...
#include <bits/stdc++.h> using namespace std; int main() { map<int, int> m; string s; int n, a; cin >> n >> s; for (int i = 1; i < 10; ++i) { cin >> a; m[i] = a; } for (int i = 0; i < n; ++i) { if (s[i] - 0 < m[s[i] - 0 ]) { while (s[i] - 0 <= m[s[i] - 0 ]...
#include <bits/stdc++.h> using namespace std; const int maxn = 15000; int d[maxn]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < m; i++) { int maxx = -1, maxi = 0; int x; for (int j = 1; j <= n; j++) { scanf( %d , &x); if (x > maxx) { m...
#pragma GCC optimize(4) #include<bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<=b;++i) #define REP(u) for(int i=p[u];i!=-1;i=e[i].nxt) #define ll long long #define rd (rand()<<16^rand()) #define PII pair<int,int> #define pb push_back #define sz(x) (int)(x.size()) #define gc (_p1==_p2&&(_p2=(_p1=_buf...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; int n, x; while (t--) { cin >> n >> x; if (n == 1 || n == 2) cout << 1 << endl; else { if ((n - 2) % x == 0) cout << (n - 2) /...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int rand(int x, int y) { ++y; return (rng() % (y - x)) + x; } int n, k, A[300006], dp[35006][56]; vector<pair<int, int> > v; struct node { int second, e, m; int v = 0; ...
#include <bits/stdc++.h> namespace io { const char endl = n ; template <typename T> inline void chkmin(T &a, T b) { a > b ? a = b : 0; } template <typename T> inline void chkmax(T &a, T b) { a < b ? a = b : 0; } struct Stream { template <class T> Stream operator>>(T &x) { x = 0...
#include <bits/stdc++.h> using namespace std; const int INF = 100005; const long long LL_INF = (long long)2e18 + 5; inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } const long long mod = 1000000007; bool isprime(long long n) { for (long long i = 2; i * i <= n; ++i) { if (n % i =...
#include <bits/stdc++.h> using namespace std; string p; bool cap = false, l = false, dig = false; char digits[10] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 }; int main() { cin >> p; int s = p.length(); if (s < 5) { cout << Too weak ; return 0; } for (int i = 0; i < s;...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int n1, n2, n3; cin >> n1 >> n2 >> n3; vector<int> v[n + 1]; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; v[a].push_back(b); v[b]...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) using namespace std; inline int read() { int x = 0, neg = 1; char op = getchar(); while (!isdigit(op)) { if (op == - ) neg = -1; op = getchar(); } while (isdigit(op)) { x = 10 * x + op - 0 ; op...
#include <bits/stdc++.h> using namespace std; typedef pair<long long, long long> pii; typedef vector<long long> vi; typedef vector<pii> vpii; typedef vector<vi> vvi; double prob[20][20]; double dp[(1 << 19)]; double pmove(long long prev_mask, long long j, long long n) { long long k = __builtin_popco...
#include <bits/stdc++.h> using namespace std; const int oo = 1e9; int n, q; int a[400005]; struct rmq { int tree[1050000], lim; void init(int n) { memset(tree, 0, sizeof(tree)); for (lim = 1; lim <= n; lim <<= 1) ; } void add(int x, int v) { x += lim; tree[x] = ...
#include <bits/stdc++.h> using namespace std; const int n0 = 1 << 17; const long long inf = 1e18; int n, a[n0], q; long long d[n0], gaps; struct Node { int l = 0, r = 0; long long val[3]; Node() { val[0] = val[1] = val[2] = -inf; } void init(int pos) { l = r = pos; if (l < 2 || l...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const int mod = 1000000007; const int MAXN = 1010; int n, m, t, x, y, xx, yy, ans, v, u, q, a, b, c, cnt; string A[MAXN]; int dist[MAXN][MAXN]; int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; const int maxt = 1000000, maxn = maxt + 7; int h[7][7]; char s[5][maxn]; void output(int n) { for (int i = 1; i <= 4; i++) { for (int j = 1; j <= n; j++) printf( %c , s[i][j]); puts( ); } } bool DoIt_2(int I, int n, int tot) { for (int...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; map<pair<int, long long>, bool> vis; map<pair<int, long long>, int> memo; int grundy(int x, long long mask) { for (int i = 61; i > x; i--) { if ((mask >> i) & 1) mask ^= (1ll << i); } if (vis[{x, mask}]) return memo[{x, ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int div[] = {1, 2, 3, 4, 6, 12}; while (t--) { string s; cin >> s; vector<pair<int, int> > dimen; int n, m; int i, j, k; for (k = 0; k < 6; k++) { n = div[k]; m = 12 / n; ...
#include <bits/stdc++.h> using namespace std; string gen[100]; string merge(string s1, string s2) { int e = s1.size() - 1; for (int i = 0; i < s2.size(); i++) { if (s1[0] == s2[i]) { int k = s2.size() - i; if (k <= s1.size()) { s1.erase(0, k); return s2 + s1; ...
#include <bits/stdc++.h> using namespace std; map<long long, long long> frequency(vector<long long> v) { map<long long, long long> m; for (long long i = 0; i < v.size(); i++) { if (m.find(v[i]) != m.end()) m[v[i]]++; else { m.insert({v[i], 1}); } } return m; } v...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, m, x, s = 0; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> x; s += x; } if (s == m) cout << YES ; else cout << NO ; cout << ...
#include <bits/stdc++.h> using namespace std; const long long bl_size = 320; int n, m; long long k; long long res; long long a[100005]; unordered_map<long long, long long> cnt; struct Query { int l, r, id; bool operator<(Query other) const { if (l / bl_size != other.l / bl_size) re...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e5 + 10; const int LG = 20; int power(int a, int b) { int res = 1; while (b > 0) { if (b & 1) { res = 1LL * res * a % mod; } a = 1LL * a * a % mod; b >>= 1; } return res; } ...
#include <bits/stdc++.h> const int MAXN = 1e5 * 5; const int INF = 1e9 + 7; using namespace std; long long f[501][501]; long long a[501][501]; int n, p[501]; long long ans[501]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) for (int j = 1;...
#include <bits/stdc++.h> using namespace std; const int mn = 100010; long long x[mn], y[mn]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %lld %lld , &x[i], &y[i]); if (n <= 4) { printf( YES n ); return 0; } bool flag = 0; for (int i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> divs[N]; vector<int> mult[N]; int mu[N], a[N], n; int cnt[N]; long long res = 0; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); mu[1] = 1; for (int i = 1; i < N; i++) { divs[i].p...
#include <bits/stdc++.h> const double PI = acos(-1.0); int main() { double n, r; scanf( %lf%lf , &n, &r); double p1 = PI / n, p2 = PI / (2 * n), p3 = PI - p1 - p2; double l3 = r, l2 = l3 / sin(p3) * sin(p2); double s = l3 * l2 * sin(p1); printf( %.15f n , n * s); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int tas[101], cal[101]; int dp1[10001], dp2[10001]; int w1[101][3], w2[101][3]; while ((cin >> n >> k)) { int s = 0, t = 0; int sum1 = 0, sum2 = 0, sum = 0; for (int i = 1; i <= n; ++i) cin >> tas[i]; fo...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, m, k, t, mx; cin >> t; while (t--) { cin >> n >> m >> k; mx = min(n / k, m); cout << (m >= mx ? mx - ceil((long double)(m - mx) / (k - 1)) : m...
#include <bits/stdc++.h> using namespace std; string s = FESTIVAL ; long long dp[1010][10]; int a[1010]; int main(void) { int i, j, k; dp[0][0] = 1; for ((i) = 0; (i) < (int)(1000); (i)++) for ((j) = 0; (j) < (int)(8); (j)++) for ((k) = 0; (k) < (int)(8); (k)++) if (j <= k...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long 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 MAX...
#include <bits/stdc++.h> using namespace std; const long long inf(101010101010101010LL); int n; struct uf { int par[1005]; uf() { for (int i(0); i < (n); i++) par[i] = i; } int ff(int x) { return par[x] == x ? x : par[x] = ff(par[x]); } void uu(int x, int y) { x = ff(x), y = ff(y...
#include <bits/stdc++.h> using namespace std; class SegmentTree { private: vector<long long> tree; vector<long long> lazy; vector<long long> num; long long build(long long ind, long long l, long long r) { if (l == r) { tree[ind] = num[l]; return tree[ind]; } tree...
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> t[500050]; bitset<2020> P[2020], B[2020]; void solve() { scanf( %d%d , &n, &m); for (int i = 0; i < m; i++) { int x, y; scanf( %d%d , &x, &y); t[i] = pair<int, int>(x, y); P[x][y] = 1; } for (int i =...
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int N = 100003; int ld[N]; int a[N]; void sieve() { for (int i = 2; i * i < N; ++i) if (ld[i] == 0) for (int j = i * i; j < N; j += i) if (ld[j] == 0) ld[j] = i; for (int i = 2; i < N; ++i) if...
#include <bits/stdc++.h> using namespace std; int n; string s; struct str { int len; bool vis; string pre, suf; void push_front(char ch) { if (!len) vis = 0; else if (ch ^ pre[0]) vis = ch < pre[0]; pre = ch + pre; if (len < 2) suf = ch + suf; ...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long int n, k; string s, s1; void hi() { for (int i = k; i < s.length(); i++) { s[i] = s[i - k]; } } int main() { cout.precision(10); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n ...
#include <bits/stdc++.h> using namespace std; const int N = 1E5 + 10; const int inf = 1 << 30; long long read() { long long a = 0; char b = 1, c; do if ((c = getchar()) == 45) b = -1; while (c < 48 || c > 57); do a = (a << 3) + (a << 1) + (c & 15); while ((c = getchar()) > 47 && c ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t = 0, k; cin >> n >> k; if (n > k) n = k; long long unsigned int sum = 1; while (n != 1) { sum *= n; n--; } cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; while (~scanf( %d %d %d , &a, &b, &c)) { int ans = a + b + c; ans = max(ans, a * b * c); ans = max((a + b) * c, ans); ans = max(a * (b + c), ans); printf( %d n , ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int gi() { int res = 0, w = 1; char ch = getchar(); while (ch != - && !isdigit(ch)) ch = getchar(); if (ch == - ) w = -1, ch = getchar(); while (isdigit(ch)) res = res * 10 + ch - 0 , ch = getchar(); return res * w; } const int MAX_N = 1e...
#include <bits/stdc++.h> using namespace std; long long bef[1000100], af[1000100]; long long calc(long long n) { return (n * (n + 1)) / 2; } int main() { int k; string s; cin >> k >> s; memset(bef, 0, sizeof bef); memset(af, 0, sizeof af); long long last(1000010), cur(1), i(0); vecto...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b = 0, c = 0, n, t; cin >> t; for (int o = 1; o <= t; o++) { b = 0; c = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a; if (a != 1) { c = 1; } else { if (c ==...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > G[500005]; int sz[500005]; vector<int> *vec[500005]; int cnt[(1 << 23) + 5]; int lazy[500005]; int len[500005]; int res[500005]; void get_ready(int u, int par, int mask, int hh) { sz[u] = 1; len[u] = hh; lazy[u] = mask; ...
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; cout << (n + 1) / 2; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { long long int n, i, j, k, t; scanf( %lld , &n); long long int prev = 0, ans = 0, count = 0, diff = 0, sum = 0, powe = 0; long long int a[n]; for (i = 0; i < n; i++) scanf( %lld , &a[i]); sort(a, a + n); if (n == 1) { cou...
#include <bits/stdc++.h> using namespace std; long long sum[500000 + 10]; int data[500000 + 10]; int main() { int n, l, r, ql, qr; scanf( %d%d%d%d%d , &n, &l, &r, &ql, &qr); for (int i = 1; i <= n; ++i) { scanf( %d , &data[i]); sum[i] += (sum[i - 1] + data[i] * r); } long long an...
#include <bits/stdc++.h> using namespace std; vector<int> v; int n, x; char s[3]; int main() { cin >> n; while (n--) { cin >> s; if (s[0] == a ) { cin >> x; v.insert(lower_bound(v.begin(), v.end(), x), x); } if (s[0] == d ) { cin >> x; v.erase(...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 1; const long long M = 1e5 + 1; vector<int> len; vector<int> dist[N]; vector<long long> pre[N]; long long n, m; void mer(long long v, long long l, long long addl, long long r, long long addr) { dist[v].push_back(0); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0; int d; for (int i = 0; i < n; i++) { cin >> d; sum += d; } int count = 5; for (int i = 1; i <= 5; i++) { if ((sum + i) % (n + 1) == 1) { count--; } } cout ...
#include <bits/stdc++.h> using namespace std; long long arr1[1000001]; template <typename T> T myMax(T x, T y) { return (x > y) ? x : y; } template <typename T> T myMin(T x, T y) { return (x < y) ? x : y; } template <typename T> T sum(T x, T y) { return (x + y); } template <typename ...
#include <bits/stdc++.h> using namespace std; long long ini; struct TrieNode { long long value; TrieNode *arr[2]; }; TrieNode *newNode() { TrieNode *temp = new TrieNode; temp->value = 0; temp->arr[0] = temp->arr[1] = NULL; return temp; } void insert(TrieNode *root, long long pre_xo...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long number; cin >> number; if (number == 2) { cout << 0 << endl; } else if (number == 1) { cout << 0 << endl; } else { if (number % 2 == 0) { co...
#include <bits/stdc++.h> using namespace std; int n, u[6], v[6], x; int main() { scanf( %d , &n); for (int i = (1); i <= (n); i++) { scanf( %d , &x); u[x]++; } for (int i = (1); i <= (n); i++) { scanf( %d , &x); v[x]++; } int dif = 0; for (int i = (1); i <= (5);...
#include <bits/stdc++.h> long long int min(long long int x, long long int y) { return (x < y) ? x : y; } long long int max(long long int x, long long int y) { return (x > y) ? x : y; } long long int fastexpo(long long int base, long long int power) { long long int res = 1; while (power) { if (power ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, x, y, c1 = 0, c2 = 0, m; cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; if (x > 0) c1++; else c2++; } m = min(c1, c2); if (m <= 1) cout << YES << endl; else cout <<...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const long long UNDEF = -1; const long long INF = 1e18; template <typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; } template <typename T> inline bool chkmin(T &aa, T bb) { return aa ...
#include <bits/stdc++.h> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template <class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; char buf[200001]; int main() { int q; cin >> q; whil...
#include <bits/stdc++.h> using namespace std; int main() { int k, r; cin >> k >> r; int count = 1; int aux = k; while (true) { if ((k % 10 == 0) || (abs(k - r) % 10 == 0)) { break; } else { k += aux; count++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long n, d; cin >> n >> d; vector<long long> delta(n); vector<long long> rs(n); for (int i = 0; i < n; ++i) cin >> delta[i]; rs[0] = delta[0]; for (int i = 1; i < n; ++i) rs...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - 0 + c, c = getchar(); x *= f; } const int N = 1...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int arr[t]; for (int i = 0; i < t; i++) { int y; cin >> y; y = y + i; arr[i] = y; } sort(arr, arr + t); for (int i = 0; i < t; i++) { arr[i] -= i; } int check = 1; for (i...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; const int N = 1e5 + 15, M = 105, T = 1e7 + 5; long long maxi[N], l[N], r[N]; pair<long long, long long> f[N]; pair<long long, int> bsd(pair<long long, int> a, pair<long long, int> b) { if (a.first > b.f...
#include <bits/stdc++.h> using namespace std; const int N = 300005, T = 100000; int n, m, a[N], l[N], r[N]; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= m; i++) cin >> a[i]; if (n == 1) { cout << 0 << endl; return 0; } for (int i = m; i > 0; -...
#include <bits/stdc++.h> using namespace std; int n, i, j, k, e, x, l[7], r[7]; double p, c, res, f[7][7][3]; int main() { scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d%d , &l[i], &r[i]); for (i = 1; i <= 10000; i++) { memset(f, 0, sizeof(f)); f[0][0][0] = 1; for (j = 0; j < n...
#include <bits/stdc++.h> int gcd(int x, int y) { if (y == 0) return x; else return gcd(y, x % y); } int main() { int n, a; scanf( %d , &n); for (int i = 1; i <= n / 2; i++) { if (gcd(i, n - i) == 1) a = i; } printf( %d %d , a, n - a); }
#include <bits/stdc++.h> int main() { char str[5010]; memset(str, 0, sizeof(str)); scanf( %s , str); int n; n = strlen(str); int res = 0; for (int i = 0; i < n; i++) { int l = 0, sum = 0; for (int j = i; j < n; j++) { if (str[j] == ( ) l++; else if (s...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int r1, r2, c1, c2; cin >> r1 >> c1 >> r2 >> c2; if (r1 == r2 || c1 == c2) { cout << 1 << ; } else { cout << 2 << ; } if ((r1 + c1) % 2 !=...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (d > 2 * c || 2 * d < c || d >= b) { printf( -1 n ); return 0; } int tmp = max(c, d); cout << max(d * 2 + 2, a) << endl; cout << max(d * 2 + 1, b) << endl; cout << tmp <...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 20; unsigned long long bit[N][20], ans, s; int main() { int n, k, a; cin >> n >> k; for (int x = 1; x < N; x += x & (-x)) bit[x][0]++; for (int i = 0; i < n; i++) { cin >> a; for (int j = k + 1; j > 0; j--) { s...
#include <bits/stdc++.h> using namespace std; const int dr[] = {-1, 0, 1, 0}; const int dc[] = {0, 1, 0, -1}; string FILE_NAME = testcase.C ; string NAME; string itos(int n) { stringstream ss; ss << n; return ss.str(); } int main() { int n, k; cin >> n >> k; if (k >= n * (n - 1)...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e4; bitset<maxn * 25> f[50][25]; int n; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; vector<int> a(n * 2); for (int i = 1; i <= n * 2; i++) cin >> a[i - 1]; sort(a.begin(), a.end()); vector...
#include <bits/stdc++.h> using namespace std; int a[100100], b[100100]; int n, x; multiset<int> st; multiset<int>::iterator it; int main() { scanf( %d%d , &n, &x); for (int i = 0; i < n; i++) scanf( %d , a + i); for (int i = 0; i < n; i++) { int w; scanf( %d , &w); st.insert(w)...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 9; long long n, a, b, val[MAX], incc[MAX], decc[MAX]; vector<int> g[MAX]; void dfs(int v, int p) { for (auto u : g[v]) if (u != p) dfs(u, v), decc[v] = max(decc[v], decc[u]), incc[v] = max(incc[v], incc[u]...
#include <bits/stdc++.h> using namespace std; int n; long long ans, p; int main() { scanf( %d , &n); p = 2; for (int i = 1; i <= n; i++) { cout << (long long)i * (i + 1) * (i + 1) - p / i << endl; p = (long long)i * (i + 1); } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2) { int w = max(y1, y2) - min(y1, y2); cout << x1 + w << << y1 << << x2 + w << << y2 << endl; } else if (y1 == y2) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t = 0; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> s; if (s[0] >= 0 && s[0] <= 9 ) { if (s.size() == 1 || (s.size() == 2 && s < 18 )) t++; } else if (s == ABSINTH || s == CHAMPAGNE || s =...
#include <bits/stdc++.h> #pragma GCC optimize( O3,inline,unroll-loops ) using namespace std; int f[4020][4020][2][2]; inline int Mod(int x) { return x + ((x >> 31) & 1000000007); } inline void Modadd(int &x, int y) { x = Mod(x + y - 1000000007); return; } int Modular(string &a, int b) { string...
#include <bits/stdc++.h> using namespace std; double cooy1, cooy2, cooyw, cooxb, cooyb, r; double s1, s2; int main() { ios_base::sync_with_stdio(false); cin >> cooy1 >> cooy2 >> cooyw >> cooxb >> cooyb >> r; cooy1 += r; cooy2 -= r; cooyw -= r; s1 = 2 * cooyw - cooy1; s2 = 2 * cooyw -...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long power(long long a, long long b) { a = a % mod; long long ans = 1; while (b > 0) { if (b % 2 == 1) { ans = (ans * a) % mod; } b = b / 2; a = (a * a) % mod; } return ans; } ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 10; long long ans; long long n, k; long long s[maxn]; long long l[maxn]; long long r[maxn]; long long seg[4 * maxn]; long long lazy[4 * maxn]; vector<long long> bois[maxn]; void in(); void solve(); long long doaz(long l...
#include <bits/stdc++.h> using namespace std; void dbg() { std::cout << # n ; } template <typename T, typename... Args> void dbg(T a, Args... args) { std::cout << a << ; dbg(args...); } const long long maxn = 2e5 + 10; const long long MAX = 1000; const long long inf = 0x3f3f3f3f; const l...
#include <bits/stdc++.h> using namespace std; int main() { int arr[101], n, imin = 0, imax = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; if (arr[i] == 1) imin = i; else if (arr[i] == n) imax = i; } int a; if (imax < imin) swap(imax, imin); ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cout << fixed; setprecision(15); double x, y; cin >> n >> x >> y; long long p1 = 0, p2 = 0, ans = 0; set<double> s; for (long long i = 0; i < n; i++) { double a, b; cin >> a >> b; if (a == x) ...
#include <bits/stdc++.h> using namespace std; int par[200010]; bool isLeaf[200010]; vector<int> adj[200010]; long long f[200010], dp[200010], s[200010], ans = 0, n; void duyet(int u) { s[u] = 1; f[u] = 0; for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i]; if (par[u] != v) {...
#include <bits/stdc++.h> using namespace std; constexpr long long maxn = 2e5 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7; long long n, m, du[maxn], vis[maxn], f[maxn]; long long res, ans = 1; vector<long long> e[maxn]; map<pair<long long, long long>, long long> mp; inline long long ksm(long long a, long long b) ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); long long int n, s, p, q; char d; map<long long int, long long int> p1, p2; cin >> n >> s; for (long long int i = 1; i <= n; i++) { cin >> d >> p >> q; if (d == B ) p1[p] += q; else...
#include <bits/stdc++.h> using namespace std; char s[1005][1005]; int sum[1005][1005]; int mn = 1000000007, area = 0; int X, Y, n, m; int extend(int x, int y, int dx, int dy) { int mx = 0; if (x + dx <= n && y + dy - 1 <= m && sum[x + dx][y + dy - 1] - sum[x + dx][y - 1] - sum[x][y + dy - 1]...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; set<int> s; multiset<int> m; auto add = [&](int x) { auto it = s.insert(x).first; if (next(it) != s.end() && it != s.begin()) m.erase(m.find(*next(...
// author: sharad12arse #include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define gcd __gcd #define INF LONG_LONG_MAX void solve(){ int n; cin>>n; ll a1=0,a2=0,x=0; vector<ll> arr(n); for(int i=0;i<n;i++){ cin>>arr[i]; x^=arr[i];...
#include <bits/stdc++.h> using namespace std; const int MX = 200005; const int MD = 998244353; void add(int& a, int b) { a += b; if (a >= MD) a -= MD; } void sub(int& a, int b) { a -= b; if (a < 0) a += MD; } int mod_mult(long long a, long long b) { return (a * b) % MD; } int h[MX]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { long long s, a, b, c; cin >> s >> a >> b >> c; s /= c; s += (s / a) * b; cout << s << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int M = 2; struct Node { int parent, rela; void set(int p, int r) { parent = p; rela = r; } } node[maxn]; int Find(int x) { int tmp_p; if (node[x].parent != x) { tmp_p = node[x].parent; ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e6 + 6; const long long MOD = 1e9 + 7; bool comparator(long long i, long long j) { return (i < j); } struct setCompare { bool operator()(const int64_t& lhs, const int64_t& rhs) const {} }; long long power(long long x, long long i) {...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long MX = 1e9; const long long INF = 1e9; void solve() { string s; cin >> s; int n = s.length(), mx[n + 1], c = 0; for (int i = 0; i < s.length(); ++i) { if (s[i] == 1 ) ++c; else if (c) ...