func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long a, b, res = 1; int main() { cin >> a >> b; if (b - (a + 1) > 20) { cout << 0; return 0; } for (long long i = a + 1; i <= b; i++) res = (res * (i % 10)) % 10; cout << res; }
#include <bits/stdc++.h> using namespace std; void Solve() { long long int n, q; cin >> n >> q; long long int a[n + 1], cnt[n + 1]; for (auto i = 1; i < n + 1; i++) cin >> a[i], cnt[i] = 0; while (q--) { long long int l, r; cin >> l >> r; cnt[l]++; if (r != n) cnt[r + 1]-...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long rand_seed() { long long a = rng(); return a; } int t; int n; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
#include <bits/stdc++.h> using namespace std; int a[100], b[45], c[100]; int main() { int x; cin >> x; int p = 0, ans = 0, q = 0, f = 0; while (x) { c[p++] = x % 2; if (x % 2 == 0) f = 1; x = x / 2; } int pp = 0; for (int h = p - 1; h >= 0; h--) { a[pp++] = c[h]...
#include <bits/stdc++.h> using namespace std; long long f[300005][2], g[300005]; vector<int> vec[300005]; long long powi(long long a, long long b) { long long p; if (!b) return 1; p = powi(a, b / 2); p = (p * p) % 998244353; if (b % 2) p = (p * a) % 998244353; return p; } long long m...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) const int maxn = 1e6 + 50; int seg[4 * maxn], ans[maxn], last_pos[maxn], next_pos[maxn]; int n, m; vector<int> v, get_val, partial_xor; vector<pair<pair<int, int>, int> > ques; void upda...
#include <bits/stdc++.h> using namespace std; long long pow(long long b, long long e, long long m) { long long t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; } template <class T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template <...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; template <typename T> bool mycomp(T x, T y) { return (x == y); } bool paircomp(const pair<long long int, long long int> &x, const pair<...
#include <bits/stdc++.h> using namespace std; template <typename T> using vc = vector<T>; using pii = pair<long long, long long>; void xmax(long long& a, long long b) { a = max(a, b); } void xmin(long long& a, long long b) { a = min(a, b); } void print(vc<long long>& a, string second) { cerr << second...
#include <bits/stdc++.h> using namespace std; inline void sfr(int *a) { char c = 0; while (c < 33) c = fgetc(stdin); *a = 0; while (c > 33) { *a = *a * 10 + c - 0 ; c = fgetc(stdin); } } inline void sfp(int a) { char c[1000]; sprintf(c, %d , a); puts(c); } int m...
#include <bits/stdc++.h> using namespace std; int n, dir[200005]; long long cnt, le; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &dir[i]); if (dir[i] == 0) le++; } for (int i = 0; i < n; i++) { if (dir[i] == 1) cnt += le; else l...
#include <bits/stdc++.h> using namespace std; const long long int maxn = 2e5 + 6; const long long int inf = 2e18 + 1; long long int a[maxn]; int main() { long long int n, k; cin >> n >> k; long long int next[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; } next[n - 1] =...
#include <bits/stdc++.h> using namespace std; long long T, W, B, H, P; long long fpb(long long A, long long B) { if (A == 0) { return B; } return fpb(B % A, A); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> T >> W >> B; H = W / fpb(W, B); ...
#include <bits/stdc++.h> using namespace std; struct type { int a, b; } b[17]; int p[17]; int a[17]; int ans[101]; bitset<2001> f[65536]; int n, K, L, i, j, k, l, sum, len, s, tot; bool cmp(type a, type b) { return a.b > b.b; } int main() { p[1] = 1; for (i = 2; i <= 16; i++) p[i] = p[i ...
#include <bits/stdc++.h> const int N = 209, MOD = 1000000007; long long f[N][N], area[N][N]; struct point { long long x, y; point(const long long _x = 0, const long long _y = 0) : x(_x), y(_y) {} } p[N]; int n; inline int sign(long long x) { return x < 0 ? -1 : x > 0; } inline long long cpr(const ...
#include <bits/stdc++.h> int main(void) { int n; scanf( %d , &n); while (1) { if (n % 2 == 1) { int atk = n - 1; n = n - atk; } else if (n % 2 == 0) { printf( Mahmoud n ); break; } if (n % 2 == 1) { printf( Ehab n ); break; } el...
#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 power(long long first, unsigned long long second, unsigned long long m) { if (second == 0) return 1; long long p = power(first, second...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353, INF = 1e9; const long long N = 2e5 + 1; const double ep = 1e-10; const double pi = 3.141592653589793238; void floyd() { long long n; cin >> n; string a, b; cin >> a >> b; long long a1 = 0, a2 = 0, k = 0, ans =...
#include <bits/stdc++.h> using namespace std; struct node { int l, r; } h[(200000 + 5)]; int ql, qr; namespace Seg_tree { int hn, hv[(15000000 + 5)], ch[(15000000 + 5)][2]; void Modify(int &o, int L, int R, int p) { if (!o) o = ++hn; if (L == R) { ++hv[o]; return; } if (p <...
#include <bits/stdc++.h> using namespace std; const int MX = 200200, MSK = (1 << 20) - 1; int T, n, m, i, x, y, z, pos, cnt, le, ri, h, fi[MX], lst[MX], s[MX], t[MX], ch[MX], a[18][MX], npw[MX], L[MX], R[MX], A[MX]; priority_queue<long long, vector<long long>, greater<long long>> q; long long seg[MX * 8...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> namespace std { long long abs(long long x) { return x < 0 ? -x : x; } } // namespace std using namespace std; void dprintf(char* format, ...) { fprintf(stderr, DEBUG: ); va_list argp; va_start(argp, format); vfprintf(stderr, format, argp); va_end(argp); fpri...
#include <bits/stdc++.h> using namespace std; int arr[200000 + 10]; int arr2[200000 + 10]; int main() { int n, num1 = 0, num2 = 0, tem1, l1 = 0, l2 = 0, num = 0; long long ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> tem1; if (tem1 == 0) { ans += num; } else ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; char T; string a[100]; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < a[i].size(); j++) { if (i % 2 == 0) { if (j % 2 ==...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, l, c, d, p, nl, np, a, b, f, mina; cin >> n >> k >> l >> c >> d >> p >> nl >> np; a = (l * k) / nl; b = (c * d); f = p / np; if (a < b) mina = a; else mina = b; if (mina > f) mina = f; cout << (mina ...
#include <bits/stdc++.h> using namespace std; long long a[10]; int n; int cnt[10], sump; vector<long long> tree; int rec(int cur, int trees, int treessum) { if (cur > n) return treessum + (trees > 1) + n - sump; int ans = (int)1e9; for (int i = 0; i < tree.size(); ++i) if (tree[i] % a[cur]...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:10000000000 ) #pragma GCC optimize( O3 ) using namespace std; const int MOD = 1000000007; const int INF = 1000000007LL; const long long INF2 = 1LL << 62LL; const long double EPS = 1e-9; const int SIZE = 200010; mt19937 rng(time(0)); uniform_in...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; int A[n][m], row[n], col[m]; char c; memset(row, 0, sizeof(row)); memset(col, 0, sizeof(col)); for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int N = 100007; int n, m, q[N], a[N], mn = 100000007, k, l; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> m; for (int i = 0; i < m; i++) { cin >> q[i]; mn = min(mn, q[i]); } cin >> n; for...
#include <bits/stdc++.h> int D[61]; int main() { int i, j, k, cnt; for (i = 0; i <= 60; i++) { cnt = 0; for (j = 1, k = i; k > 0; j++, k -= j) cnt++; D[i] = cnt; } int n, x, p = 0; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &x); p ^= D[x]; } ...
#include <bits/stdc++.h> using namespace std; bool win(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return false; if (!win(b % a, a)) return true; long long df = b - b % a; if (a % 2) return df % 2 == 0; else return df / a % (a + 1) % 2 == 0; } void solve() ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n; int hasil[101] = {0}; for (int i = 1; i <= n; i++) { cin >> a; if (a / 2 != 1) { while (a % 2 != 0) { a++; hasil[i]++; } } else { a++; hasil[i]++; ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n; char s[N]; struct SuffixAutomaton { struct node { int ch[26], par; int len; } t[N << 1]; int root, tail, cnt; inline int newnode(int len) { t[++cnt].len = len; return cnt; } inline void ...
#include <bits/stdc++.h> const long long Inf = 1e18; const long double eps = 1e-7; long long LINF = (long long)2e18; using namespace std; long long mod = 1e9 + 7; long long mod5 = 1e9 + 9; long long mod3 = 998244353; long long mod4 = 1000003; long long mod2 = 1e9 + 123; const int MAXN = 4000001; c...
#include <bits/stdc++.h> using namespace std; long long read() { long long ans = 0; char last = , ch = getchar(); while (ch < 0 || ch > 9 ) last = ch, ch = getchar(); while (ch >= 0 && ch <= 9 ) ans = ans * 10 + ch - 0 , ch = getchar(); if (last == - ) ans = -ans; return ans; } ...
#include <bits/stdc++.h> int main() { int x, y, n; int k, i, t; scanf( %d , &t); for (i = 0; i < t; i++) { scanf( %d %d %d , &x, &y, &n); if (n - n % x + y <= n) { k = n - n % x + y; } else { k = n - n % x - (x - y); } printf( %d n , k); } return 0...
#include <bits/stdc++.h> using namespace std; bool check(string s) { for (int i = 0; i < s.size() - 1; i++) { if (s[i] == s[i + 1]) return false; } return true; } void solve() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == ? && i != 0 && i != s.size(...
#include <bits/stdc++.h> using namespace std; int n, m; int a[555][555]; char ans[555]; void die() { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i != j) { if (abs(ans[i] - ans[j]) <= 1 && !a[i][j]) { cout << No n ; exit(0); } ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; typedef int ll; const ll MAX = 1e3; const ll mod = 1e4; const ll inf = 1e9; struct FlowEdge { int v, u; int cap, flow = 0; FlowEdge(int v, int u, int cap) : v(v), u(u), cap(cap) {} ...
#pragma GCC optimize( Ofast ) #include<bits/stdc++.h> #define int long long using namespace std; void fileio(const string &s) { freopen((s+ .in ).c_str(), r ,stdin); freopen((s+ .out ).c_str(), w ,stdout); } const int INF=4e18; inline int read() { int x=0; bool flag=1; char c=getchar();...
#include <bits/stdc++.h> using namespace std; int x[1000001][2]; int main() { int i, j, k, l, test, m, n; int a[4100]; scanf( %d , &n); int c[4100]; for (i = 0; i < n; i++) { scanf( %d , &a[i]); c[i] = a[i]; } sort(c, c + n); int b[4100]; int d[4100]; b[0] = c[0...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; long long n, a[100007], x, ans, t, res, tmp; vector<long long> v, cur; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (long int i = 0; i < n; i++) { cin >> x; if (x) v....
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector<int> a; for (int i = 1; i <= n; i++) if (n % i == 0) a.push_back(i); for (int i = 1; i < a.size(); i++) { for (int j = 0; j < a[i] / 2; j++) swap(s[j], s[a[i] - j - 1]); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int key; vector<int> v; for (int i = 0; i < n; ++i) { cin >> key; v.push_back(key); } int max = v[0]; int min = v[0]; int amz = 0; for (int i = 1; i < n; ++i) { if (v[i] > max) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; vector<int> p(n), result; for (int& j : p) { cin >> j; } vector<int> maximu...
#include <bits/stdc++.h> using namespace std; int mat[105][105]; int nodes[105]; int n, m; int cycles = 0; void cycle_det(int cur, int parent); int main() { cin >> n >> m; memset(mat, 0, sizeof mat); memset(nodes, 0, sizeof nodes); for (int i = 0; i < m; i++) { int _1, _2; cin ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int MAXN = 1e6 + 7; const double EPS = 1e-8; long long power(long long a, long long k) { if (!k) { return 1; } long long b = power(a, k / 2); b = b * b % INF; if (k % 2) { return a * b % INF; ...
#include <bits/stdc++.h> using namespace std; long double pi = 3.141592653589793238; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t; cin >> t; while (t--) { string x; cin >> x; long long n = x.length(); if (n == 0) { cout << 0 <<...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 10; long long n, k; char s[MAXN]; int num[33]; int main() { while (cin >> s) { cin >> k; int len = strlen(s); if (len < k) { cout << impossible << endl; } else { memset(num, 0, sizeof num); ...
#include<bits/stdc++.h> #define mamun() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl n #define tab t #define ll long long #define lli long long int #define pb push_back #define fin(file) freopen(file...
#include <bits/stdc++.h> using namespace std; int n; string ans, word; vector<int> get_pi(string s) { int j = 0, k = -1; vector<int> q; q.clear(); q.push_back(-1); while (j < s.size()) { if (k == -1 || s[j] == s[k]) { q.push_back(++k); ++j; } else { k = q[...
#include <bits/stdc++.h> using namespace std; int dcount(long long i) { int c = 0; while (i > 0) { i = i / 10; c++; } return c; } int main() { long long n, cnt = 0; cin >> n; int num = dcount(n); for (long long int i = 0; i < num; i++) { cnt += n > (pow(10, i + ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a = 1, b = 2; while (n--) { int c; cin >> c; if (c == a) { b = 6 - (a + b); } else if (c == b) { a = 6 - (a + b); } else { ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; long long a[N]; struct tr { int l, r, maxi; } t[N * 4]; int sign(long long x) { if (x > 0) return 1; if (x < 0) return -1; return 0; } inline void cal(int cur, int l, int r) { int m = (l + r) / 2; int dcur = cur...
#include <bits/stdc++.h> using namespace std; vector<long long> v; map<long long, int> mp, mpp; long long ans[200005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { long long l, r; cin >> l >> r; if (!mpp[l]) { v.push_back(l); mpp[l] = 1; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, i, sum = 0, x, y; cin >> n >> t; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n - 1; i++) { if ((a[i] >= 0 && a[i + 1] >= 0) || (a[i] <= 0 && a[i + 1] <= 0)) { x = abs(a[i] - a[i + 1]) / t; ...
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline void normal(long long int &a) { a %= 1000000007; (a < 0) && (a += 1000000007); } inline long long int modMul(long long int a, long long int b) { a %= 1000000007, b %= 1000000007; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int dp[550][550], A[550], B[550], path[550][550], n, m; bool print(int x) { if (!x) return false; if (print(path[n][x])) printf( %d , B[x]); else printf( %d , B[x]); return true; } int main() { int i, j, ...
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } debug; template <typename T1, typename T2> inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << ( <...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int MOD = INF + 7; int memo[3000 + 1][100 + 1][100]; int N; vector<int> a, b; int solve(int len, int w, int nouse) { if (len == 0) return 1; if (len < 0) return 0; if (memo[len][w][nouse] != -1) return memo[len][w]...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; void solve() { long long n; cin >> n; string s; cin >> s; vector<long long> v(n); for (long long i = 0; i <= n - 1; i++) cin >> v[i]; long long ans = mod; for (long long i = 0; i <= n - 2; i++) { if ...
#include <bits/stdc++.h> using namespace std; int A[100000]; int main() { int n; cin >> n; int sh = 0; for (int i = 0; i < n - 1; i++) { int a; cin >> a; A[i] = A[i] + a; int k = n - i - 1; int l = 1; while (l <= k) { if (l * 2 > k) { break; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long mod = 1e9 + 7; const long long N = 1e5 + 10; struct node { int ind, type, row, color; node(int a, int b, int c, int d) { ind = a; type = b; row = c; color = d; } }; bool comp(node ...
//I ll always miss you like a darling. #include <bits/stdc++.h> using namespace std; #define LL long long #define LD long double #define ull unsigned long long #define x first #define y second #define pb push_back #define pf push_front #define mp make_pair #define Pair pair<int,int> #define p...
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, num, mi = 1000000, ma = 0, ans = 1; cin >> n >> p; vector<long long> v, res; for (long long i = 0; i < n; i++) { cin >> num; v.push_back(num); mi = min(mi, num); ma = max(ma, num); } sort(v.beg...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int a, b; cin >> a >> b; long long int r1 = 45; long long int s1 = 10; long long int r2 = 20; long lo...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if ((n - 2) % 3 != 0) cout << 1 << 1 << n - 2; else cout << 1 << 2 << n - 3; }
#include <bits/stdc++.h> using namespace std; int getint() { unsigned int c; int x = 0; while (((c = getchar()) - 0 ) >= 10) { if (c == - ) return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - 0 ); } while (((c = getchar()) - 0 ) < 10); return x...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int dx4[] = {-1, 0, 1, 0}; const int dy4[] = {0, 1, 0, -1}; const int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1}; const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1}; inline long long Int() { long long num = 0; char c = getchar_u...
#include <bits/stdc++.h> using namespace std; const int N = 333; long long n, ans[N], a[N][N], pos[N]; long long absv(long long val) { if (val < 0) val *= -1; return val; } int main() { std::ios::sync_with_stdio(false); cin >> n; for (int i = 0; i <= n; i++) { for (int j = 0; j < n...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a[3] = {0}; int n, t; cin >> n; while (n--) { cin >> t; a[t]++; } int res = min(a[1], a[2]); a[1] -= a[2]; if (a[1] <= 0) a[1] = 0; res += ...
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } const int LEN = 300; const int MAX = (100000 + LEN - 1) / LEN; int n; int m; int was[100000], x[100000], y[100000]; int l[MAX], r[MAX], w[MAX]; vector<pair<pair<int, int>, int> > v; vector<...
#include <bits/stdc++.h> using namespace std; template <typename item> item abs(item i) { if (i < 0) i = -i; return i; } char *s; int n; int pos; int main() { cin >> n; cin >> pos; s = new char[n + 2]; cin >> s + 1; int cnt = 0; if (n == 1) { cout << 0; return...
#include <bits/stdc++.h> using namespace std; const int maxn = 5000; const double INF = 1e18; const double ep = 1e-8; struct Edge { int from, to; long long cap, flow; int id; Edge() {} Edge(int u, int v, long long c, long long f, int id_) : from(u), to(v), cap(c), flow(f), id(id_) ...
#include <bits/stdc++.h> using namespace std; const long long MOD = (1e9) + 7; const long double EPS = 0.0000001; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; string t; cin >> t; int szs = s.size(); int szt = t.size(); int cur = 0; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int num = 0; char c = getchar(); if (c == - ) return -read(); while (c >= 0 && c <= 9 ) { num = (num << 3) + (num << 1) + c - 0 ; c = getchar(); } return num; } inline long long READ() { long long num ...
#include <bits/stdc++.h> using namespace std; int slope[150 + 1]; int main(void) { int w, h; scanf( %d%d , &w, &h); for (int i = 0; i < 2; i++) { int ww, hh; scanf( %d%d , &ww, &hh); slope[hh] = ww; } while (h > 0) { w += h; if (slope[h] > 0) w = max(0, w - slope[...
#include <bits/stdc++.h> using namespace std; int n, t, s, ma; int main() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> t; s += t; ma = max(ma, t); } cout << max(ma, (2 * s + n) / n); return 0; }
#include <bits/stdc++.h> using namespace std; long long sign(long long x) { return x < 0 ? -1 : 1; } pair<long long, long long> part(long long from, long long to, long long s, long long dir) { pair<long long, long long> res{dir, abs(to - from)}; if (to != from && sign(to ...
#include <bits/stdc++.h> using namespace std; long long int f1(long int x, long int a) { if ((x < 0 && x > (-1 * ((double)a) / 2)) || (x > 0 && x < ((double)a) / 2) || x == 0) return 1; else return 0; } long long int f2(long long int x, long long int a) { if ((x < 0 && x > (-1 * ...
#include <bits/stdc++.h> using namespace std; long long a, x = 1e18; int main() { cin >> a; cout << a - x % a * 9 % a * 9 % a << << a - x % a * 9 % a * 9 % a + x - 1; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; const double PI = acos(-1.0); const long long INF = 0x3f3f3f3f3f3f3f3f; int a[maxn], val[maxn]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:268435456 ) using namespace std; const double PI = 3.1415926535897932384626433832795; template <class T> T min(T &a, T &b) { return (a < b) ? a : b; } template <class T> T max(T &a, T &b) { return (a > b) ? a : b; } template <class T> ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const double pi = acos(-1.0); const long long int inf = 0x3f3f3f3f3f3f3f3f; const long long int mod = 998244353; bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); } void fast() { ios::sync_with_stdio(0); cin.tie(0); co...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 3, K = 11, M = N * 4; const long long MOD = 998244353, oo = 1e9, OO = 1e18, mod = MOD; const double pi = acos(-1), eps = 1e-17; long long di[] = {0, 0, 1, -1}; long long dj[] = {1, -1, 0, 0}; long long pos[N]; int32_t main() { i...
#include <bits/stdc++.h> using namespace std; int m, n; int R[1005]; map<int, int> cnt; long long bell[1005][1005]; void geneBell() { bell[0][0] = 1; for (int i = 1; i < m + 2; i++) { bell[i][0] = bell[i - 1][i - 1]; for (int j = 1; j <= i; j++) { bell[i][j] = (bell[i][j - 1] + b...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, a, b; cin >> n >> a >> b; if (a + b > n - 1 || a == n - 1 && n > 1) cout << -1 << endl; else { if (n == 1) cout << 1 << endl; else ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; cout << max(a + b, c + d) << endl; } }
#include <bits/stdc++.h> using std ::max; using std ::min; const int maxx = 300000 + 25; int n, m, x, y, z, k, num; int cnt, ans, tot; int front, back, kr; int cur[maxx]; std ::priority_queue<int, std ::vector<int>, std ::greater<int> > quq; class Node { public: int x; int y; int id; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int k = 0; k < t; k++) { int x, y, d = 0; cin >> x >> y; if (x >= y || x > 3) { cout << YES << endl; d = 1; } if (d == 0) { if (x == 1) { cout << NO << end...
#include <bits/stdc++.h> using namespace std; int main() { int mx = 0, i, n, m, d, h, ld, lh; cin >> n >> m; for (i = 0; i < m; i++) { cin >> d >> h; if (i == 0) { ld = d; lh = h; mx = lh + ld - 1; continue; } if (abs(h - lh) > d - ld) { co...
#include <bits/stdc++.h> using namespace std; string bad; int k, ans = 0; struct node { node *edges[26]; node() { for (int i = 0; i < 26; i++) edges[i] = NULL; } }; void insert(node *trie, string s) { for (int i = 0; i < s.size(); i++) { if (trie->edges[s[i] - a ] == NULL) trie-...
#include <bits/stdc++.h> using namespace std; int l, ans; string s; char t[1000005]; int cal(string s) { int l = s.size(), p = 0, q = 0, cnt1 = 0, flag = 0; char ch; for (int i = 0; i < l; i++) { ch = (q & 1) ? R : L ; if (s[i] == X ) { q++; } else { if (s[i] ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename V> ostream &operator<<(ostream &out, const pair<T, V> x) { out << { << x.first << : << x.second << } ; return out; } template <typename T> ostream &operator<<(ostream &out, const set<T> x) { for (auto &it : x) { ...
#include <bits/stdc++.h> using namespace std; int dpo[2010][15], dpe[2010][15], a[2010], b[2010]; long long combe[15], combo[15]; long long f[2010], c[2010]; long long nck(long long n, long long k) { if (n < k) return 0; long long ret = (f[n] * c[k]) % 998244353; return (ret * c[n - k]) % 99824435...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n; int res = 0; int r[10]; int v[10]; int main() { int t; cin >> t; while (t--) { long long x = 1; int n; cin >> n; for (int i = 3; i <= n * 2; i++) { x = x * i % mod; } cout ...
#include <bits/stdc++.h> using namespace std; int n, k; int a[105]; map<int, bool> q; int main() { while (~scanf( %d %d , &n, &k)) { q.clear(); for (int i = 0; i < k; i++) scanf( %d , &a[i]); int t = 1; int t2 = n; for (int i = 0; i < k; i++) { int t3 = (a[i] %= t2); ...
#include <bits/stdc++.h> using namespace std; bool comp(int x, int y) { return x > y; } int main() { int t = 1; cin >> t; int n; while (t--) { cin >> n; if (n == 1 || n == 2) { cout << 1 << n ; continue; } if (n & 1) cout << n / 2 + 1 << n ; ...
#include <bits/stdc++.h> using namespace std; int main() { int num; cin >> num; for (int i = 1; i <= 2 * sqrt(num); i++) { int x = (i * (i + 1)) / 2; int tmp = num - x; int st = 1, en = 2 * sqrt(num); while (st <= en) { int mid = st + (en - st) / 2; int y = (mid *...
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma GCC optimize(3) template <typename T> T min(T x, T y) { return x < y ? x : y; } template <typename T> T max(T x, T y) { return x > y ? x : y; }; const int INF = 1000000000; const int MAXN = 100005; const int B = 500; int N,...