func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int a[MAXN]; bool mark[MAXN]; void add(int v, int u) { while (mark[u] == false) { cout << v << << u << endl; mark[u] = true; v = a[v]; u = a[u]; } } int dfs(int x) { int ret = 1; mark[x] = ...
#include <bits/stdc++.h> using namespace std; void task(); int main() { srand(time(0)); task(); return 0; } const int INF = 0x3f3f3f3f; const int N = 1e6 + 10; const int M = 1e7 + 100; const int OLOLO = 0xFFFFFFFF; int n, k; long long int cnt[N]; set<int> vals; long long int ans; v...
#include <bits/stdc++.h> using namespace std; int main() { int mx = 0, a = 0, n; string s; cin >> n; while (cin >> s) { for (char c : s) if (isupper(c)) a++; mx = max(mx, a), a = 0; } cout << mx << endl; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline void ckmax(T& x, T y) { x = (y > x ? y : x); } template <typename T> inline void ckmin(T& x, T y) { x = (y < x ? y : x); } namespace Fread { const int SIZE = 1 << 21; char buf[SIZE], *S, *T; inline char getchar() { ...
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; long long ln, lk, lm; int x[105], y[105], r[105]; string vs[2]; void add(int id, int i, int x) { string str = (((1-abs((t- ; str += to_string(i); str += )))+abs((abs...
#include <bits/stdc++.h> using namespace std; inline int bit(int x, int i) { return (x >> i) & 1; } inline int two(int x) { return 1 << x; } int n, s[110], m, team[110], dp[20][1 << 20]; char op[110]; bool vis[20][1 << 20]; int go(int mi, int ban) { if (mi == m) return 0; int &ret = dp[mi][ban]; ...
#include <bits/stdc++.h> using namespace std; int main() { int a[3], ans; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); ans = (a[1] - a[0]) + (a[2] - a[1]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, numero; cin >> n; if (n < 10) cout << n; else { n -= 9; if (n < 181) { if (n % 2 == 0) { n /= 2; n -= 1; n %= 10; cout << n; } else { n = (n + 1) / 2;...
#include <bits/stdc++.h> using namespace std; int n, p[3000], k, m = 0, c; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= n; i++) { k = p[i]; c = 1; while (k > 0) { c++; k = p[k]; } m = max(c, m); } cout << m;...
#include <bits/stdc++.h> using namespace std; int main() { int n; char st[200010]; cin >> n >> st; queue<int> d, r; for (int i = 0; i < n; i++) { if (st[i] == D ) d.push(i); else r.push(i); } while (!r.empty() && !d.empty()) { int R = r.front(), D = d.f...
#include <bits/stdc++.h> using namespace std; int main() { long long w, h; cin >> w >> h; long long res = 0; if (w == 1 || h == 1) { cout << 0 << endl; return 0; } for (long long i = 1; i < h; i++) { for (long long j = 1; j < w; j++) res += min(i, h - i) * min(j, w - j); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n, k; cin >> n >> k; priority_queue<long long, vector<long long>, greater<long long>> priq; long long cur = 0, co = 0; map<long long, long long> ma; while (n > ...
#include <bits/stdc++.h> using namespace std; string start[1791791]; string fin[1791791]; pair<int, int> diffs[1791791]; int is_in(string a, string b) { string s = a + # + b; int n = (int)s.length(); vector<int> pi(n); for (int i = 1; i < n; ++i) { int j = pi[i - 1]; while (j > 0...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int dist[10010], DD[30][30]; int s[10010]; vector<int> all; vector<int> a; queue<int> q; int dp[1 << 20]; int n; void calc(int x) { memset(dist, -1, sizeof(dist)); q.push(x), dist[x] = 0; while (!q.empty()) { ...
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } dbg; int inf = (1 << 20); int dp[(1 << 21) + 10]; void F(int x, int y) { x += inf; y += inf; dp[x]++; if (x == y...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, j, k, tmp; int a, b, c; cin >> a >> b >> c; int p; if ((c - b + a) % 2 != 0) { printf( Impossible n ); return 0; } p = (c - b + a) / 2; int count1 = 0; if (p == 0) { count1++; } if (...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; map<int, int> m; int c[7000][2]; int a[n + 1]; int b[n + 1]; int mx; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]]++; mx...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; double n, m, a, b, x = 1000000, y; cin >> n >> m; while (n--) { cin >> a >> b; y = a / b; x = min(x, y); } printf( %.8lf n , m * x); }
#include <bits/stdc++.h> using namespace std; long long bigmod(long long p, long long e, long long M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return ret; } long long extended(long long a, long long b, long long &x, long long &y...
#include <bits/stdc++.h> using namespace std; vector<int> prim; const int N = 1e5 + 9; int n, dp[10000], a[N]; bool v[100000]; int pos[100000]; void pre() { for (int i = 2; i < 100000; i++) if (!v[i]) { prim.push_back(i); pos[i] = prim.size() - 1; int k = i << 1; ...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { long long int res = 1; a %= 1000000007; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; } return res; } long long int modI...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; long double Dis(long long a, long long Y, long long b, long long YY) { return sqrt((long double)(b - a) * (b - a) + (Y - YY) * (Y - YY)); } struct PT { long long ID; long double len, Y; PT(long long _ID, long double _Y...
#include <bits/stdc++.h> using namespace std; const int MAXN = 4000 + 10, MOD = (int)1e9 + 9; int n, m, b, w, f[MAXN][MAXN]; int main() { cin >> n >> w >> b; m = max(b, w); f[0][0] = 1; for (int i = 1; i <= m; ++i) { for (int j = 1; j <= i; ++j) f[i][j] = ((long long)f[i - 1][j] * ...
#include <bits/stdc++.h> using namespace std; inline void read(long long &x) { long long f = 1; x = 0; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = x * 10 + c - 0 ; c = getchar(); } ...
#include <bits/stdc++.h> using namespace std; long long n, x, a[200000]; long long bs(long long xx, long long yy, long long k) { long long m = (xx + yy) / 2; if (yy - xx <= 1) return xx; if (a[m] <= k) return bs(m, yy, k); else return bs(xx, m, k); } int main() { cin >> n; ...
#include <bits/stdc++.h> using namespace std; void fastIo() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { fastIo(); int q; cin >> q; while (q--) { int n; cin >> n; string s; cin >> s; if (n == 1) { cout << NO << endl; } el...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s1, s2; cin >> s1 >> s2; bool poss = true; int change[20][20]; memset(change, 0, sizeof(change)); for (int i = 0; i < n; i++) { if (s1...
#include <bits/stdc++.h> const int inf = 1e9; const double eps = 1e-9; const int mod = 1e9 + 7; using namespace std; int mypow(int x, int y) { int res = 1; for (; y >= 1; y >>= 1) { if (y & 1) res = (1ll * res * x) % mod; x = (1ll * x * x) % mod; } return res; } int32_t main() ...
#include <bits/stdc++.h> bool local = false; using namespace std; template <class T> string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> void print(T v) { cout << ((int)(v).size()) << n ; for (auto x : v) cout << x << ; cout << n ; ...
#include <bits/stdc++.h> using namespace std; map<long long, map<long long, long long, greater<long long>>> comp; map<long long, long long, greater<long long>> Add(long long x) { if (x == 0) return {}; if (comp.count(x)) return comp[x]; long long choose = (x - 1) / 2; long long diff = min(choose +...
#include <bits/stdc++.h> using namespace std; template <typename T> void smax(T &a, T b) { if (a < b) a = b; } const double EPS = 1e-9; vector<pair<pair<int, int>, int> > adj[100000 + 10]; long long totSum; pair<pair<int, int>, int> edges[100000 + 10]; int belows[100000 + 10]; int n; pair<long...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { int n, m; scanf( %d %d , &n, &m); string S; set<int> H[n]; set<int> V[m]; for (int i = 0; i < (n); i++) { cin >> S; for (int j = 0; j < (m); j++) if (S[j] != . ) { in...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; cin.ignore(); while (n--) { string str1, str2; getline(cin, str1); getline(cin, str2); bool test = true; long long j = 0, i = 0; char last_ch = str1[0]; while (j < str2.size() ...
#include <bits/stdc++.h> using namespace std; int II() { int q; scanf( %d , &q); return q; } void solve() { long long N, M; cin >> N >> M; long long ar[N + 10], br[N + 10], cr[N + 10]; for (long long i = 1; i <= N; i++) { cin >> ar[i] >> br[i] >> cr[i]; } long long mi =...
#include <bits/stdc++.h> using namespace std; void winter_is_coming() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } int main() { void winter_is_coming(); long long a, b, dis, dis2, ans = 0; cin >> a >> b; dis = abs(a - b); dis2 = dis / 2; dis = dis - d...
#include <bits/stdc++.h> using namespace std; int n, m, fa[100010], siz[100010]; double ans; int getfa(int w) { return (w == fa[w]) ? w : fa[w] = getfa(fa[w]); } struct edg { int nx, ny, val; bool operator<(const edg& e) const { return val > e.val; } } a[100010]; int main() { cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; int n, m, G[1005][1005], ans = 1000000000; char str[1005][1005]; bool vis[1005][1005]; int dfs(int x, int y, int wx, int wy) { vis[x][y] = true; if ((G[x + wx - 1][y + wy] - G[x - 1][y + wy] - G[x + wx - 1][y + 1 - 1] + G[x - 1][y + 1 - 1]) == wx ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); unsigned long long n; unsigned long long a[100050]; unsigned long long b[200050]; scanf( %lld , &n); for (int i = 0; i < n / 2;...
#include <bits/stdc++.h> using namespace std; int main() { int arr[100] = {0}, con = 0, d = 0; ; string x; cin >> x; for (int i = 0; i < x.size(); i++) { if (x[i] == + ) { for (int j = 0; j < con; j++) { arr[d] += (x[i - j - 1] - 48) * pow(10, j); } d++; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); long long t; cin >> t; while (t--) { vector<vector<long long> > a(2); vector<long long> ans; long long n; string b; cin >> n >> b; ...
#include <bits/stdc++.h> using namespace std; int comp(long long a, long long b) { return a > b; } long long arr[100000], cdf[100000]; int main() { int i, m; long long k, n; cin >> n; cin >> arr[0]; for (i = 1; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n, comp); cdf[0]...
#include <bits/stdc++.h> using namespace std; namespace red { inline long long read() { long long x = 0; char ch, f = 1; for (ch = getchar(); (ch < 0 || ch > 9 ) && ch != - ; ch = getchar()) ; if (ch == - ) f = 0, ch = getchar(); while (ch >= 0 && ch <= 9 ) { x = (x << 1) +...
#include <algorithm> #include <cassert> #include <iostream> #include <queue> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> Pii; typedef vector<Pii> VPii; typedef vector<int> Vi; typedef vector<Vi> VVi; typedef vector<ll> Vll; typedef vector<Vll> VVll; ...
#include <bits/stdc++.h> template <typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; } template <typename T> inline T ABS(const T &val) { return val < 0 ? -val : val; } template <typename T> inline T MAX(const T &a, const T &b) { return a > b ? a : b; } templa...
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 7; long long dp[N][N][11][2], n, m, k; string s, t; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k >> s >> t; for (long long l = 1; l <= k; l++) { for (long long i = 1;...
#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 p, f; cin >> p >> f; long long cnt1, cnt2; cin >> cnt1 >> cnt2; long long s, w; cin >...
#include <bits/stdc++.h> using namespace std; inline void in(int &n) { n = 0; int ch = getchar(); int sign = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) sign = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { n = (n << 3) + (n << 1) + ch - 0 , ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } inline int readChar(); template <class T = int> inline T readInt()...
#include <bits/stdc++.h> using namespace std; int read(int &x) { return scanf( %d , &x); } int read(long long &x) { return scanf( %lld , &x); } int read(double &x) { return scanf( %lf , &x); } int read(int &x, int &y) { return scanf( %d%d , &x, &y); } int read(long long &x, long long &y) { return scanf( %ll...
#include <bits/stdc++.h> using namespace std; FILE *in; FILE *out; int n, m, k; char a[64][64]; int blocks[64][64]; int cell[64 * 64][2]; int dyn[64 * 64][4][2]; int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; void fill(int row, int col, int color) { blocks[row][col] = color; for (int i ...
#include <bits/stdc++.h> using namespace std; const int N = 55, M = 105, T = 20005, K = 20; const double S = 1e5, inf = 1e9, PI = acos(-1); template <class T> void read(T &x) { int sgn = 1; char ch; x = 0; for (ch = getchar(); (ch < 0 || ch > 9 ) && ch != - ; ch = getchar()) ; if...
#include <bits/stdc++.h> using namespace std; mt19937 prng(chrono::steady_clock::now().time_since_epoch().count()); void testCase(int caseno) { int n, k, a, b; cin >> n >> k; multiset<int> aa; multiset<int> bb; int sum = 0; for (int i = 0; i < n; i++) { cin >> a; sum += a; ...
#include <bits/stdc++.h> const double g = 9.8; using namespace std; const long long mod = 998244353; long long quick(long long prea, long long bbb) { long long res = 1; while (bbb) { if (bbb & 1) res = res * prea % mod; prea = prea * prea % mod; bbb >>= 1; } return res; } l...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int a, b, r; cin >> a >> b >> r; if (2 * r <= min(a, b)) cout << First ; else cout << Second ; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[m]; for (int i = 0; i < m; i++) { cin >> a[i]; if (a[i] > n - i) { cout << -1 << endl; return 0; } } long long suf_sum[m + 1]; suf_sum[m] = 0; for (int i = m - ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, mod = 998244353; int inv[N], fac[N]; int ksm(int b, int n) { int res = 1; while (n) { if (n & 1) res = 1ll * res * b % mod; b = 1ll * b * b % mod; n >>= 1; } return res; } void init(int n) { fac[0] = 1...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1e9 + 7; int main() { cin.tie(0)->sync_with_stdio(0); int t; cin >> t; while (t--) { string s; cin >> s; vector<int> r; for (string t : { twone , one , two }) { for (size_t pos =...
#include <bits/stdc++.h> using namespace std; int n; int x[2001], y[2001]; int p[2001], mn[2001]; int k[2001], c[2001]; bool used[2001][2001]; unsigned long long dst[2001][2001]; unsigned long long dist(int i, int j) { return (unsigned long long)(k[i] + k[j]) * (unsigned long long)(abs(x[...
#include <bits/stdc++.h> using namespace std; const int N = 100007; int n, k; int s[N]; int main() { scanf( %d %d , &n, &k); for (int i = 0; i < n; i++) scanf( %d , s + i); if (k >= n) { printf( %d n , s[n - 1]); return 0; } int maxi = 0; while (n < 2 * k) { maxi = ma...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); printf( %d n , n / 2 - (n % 2 ? 0 : 1)); return 0; }
#include <bits/stdc++.h> using namespace std; string s, s1; int main() { cin >> s; cin >> s1; reverse(s.begin(), s.end()); reverse(s1.begin(), s1.end()); while (!s.empty() && s[s.size() - 1] == 0 ) s.pop_back(); while (!s1.empty() && s1[s1.size() - 1] == 0 ) s1.pop_back(); if (s.size...
#include <bits/stdc++.h> using namespace std; const int N = 105, mod = 1e9 + 7; int dp[N][N * N]; bool done[N][N * N]; int fact[N], inv[N]; int arr1[N]; int arr2[N]; int n, k; long long m; inline int add(int a, int b) { int res = a + b; if (res >= mod) res -= mod; return res; } inlin...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int a[11], b[11]; scanf( %d %d , &n, &m); for (int i = 0; i < n; i++) { scanf( %d , a + i); } for (int i = 0; i < m; i++) { scanf( %d , b + i); } sort(a, a + n); sort(b, b + m); for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; int in() { int a; scanf( %d , &a); return a; } double din() { double a; scanf( %lf , &a); return a; } int gcd(int a, int b) { while (b) { a %= b; swap(a, b); } return a; } int lcm(int a, int b) { return a / gcd...
#include <bits/stdc++.h> using namespace std; bool sortinrev(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.first > b.first); } void solve() { long long n; cin >> n; long long a[n]; map<long long, long long> mp; for (long long i = 0...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> q; int n; void op(int i, int j) { q.push_back({i, j}); } void f(int l, int r) { if (l >= r) return; int len = (r - l + 1); if (len % 2 == 0) { int m = (l + r) / 2; f(l, m); f(m + 1, r); for (int j = 0; j <...
#include <bits/stdc++.h> long long n, i, k, j, t, b; char a[2500]; bool s; using namespace std; int main() { k = 0; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == H ) k++; } b = n - k; for (i = n + 1; i <= 2 * n; i++) a[i] = a[i - n]; for (i = 1; i <= 2 ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; cout << ((n % 2) ? black : white n1 2 n ) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int i, n, m, ans, x, l, r, tot, a[1000005], b[1000005], last[1000005], to[1000005], Next[1000005], q[1000005], y; inline void add(int x, int y) { Next[++tot] = last[x]; last[x] = tot; to[tot] = y; } inline bool check(int x) { for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; vector<long long> v, ext; long long f[20]; bool vis[20]; bool chck(long long j) { while (j) { if (j % 10 != 4 && j % 10 != 7) break; j /= 10; } return j == 0; } int main() { long long i, n, k, st, sum, j, pre, sz, ans; f[0] = 1;...
#include <bits/stdc++.h> typedef struct val { long int val, ind; } va; int cmp(const void *a, const void *b) { va ka = *(va *)a; va kb = *(va *)b; if (ka.val > kb.val) return -1; else return 1; } int a[2009][2009]; int main() { va v[2009], ba[2009]; long int n, m, t1,...
#include <bits/stdc++.h> using namespace std; int A[1000]; void quicksort(int l, int r) { int b = l; if (r - l < 1) { return; } for (int i = l; i < r; ++i) { if (A[i] < A[r]) { swap(A[i], A[b]); b = b + 1; } } swap(A[r], A[b]); quicksort(l, b - 1); ...
#include <bits/stdc++.h> int inp() { char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); int sum = 0; while (c >= 0 && c <= 9 ) { sum = sum * 10 + c - 0 ; c = getchar(); } return sum; } struct SEG_Tree { struct SEG { int l; int r; int min; ...
#include <bits/stdc++.h> using namespace std; int dp[105][200005]; int main() { int n, k; cin >> n >> k; int a[n + 1], b[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; int off = 1000 * n; for (int i = 0; i < 105; i++) for (int j = 0; j...
#include <bits/stdc++.h> using namespace std; template <typename A> string to_string(A* ptr) { stringstream ss; ss << 0x << std::setw(16) << std::setfill( 0 ) << std::hex << (uint64_t)(uintptr_t)ptr; return ss.str(); } string to_string(char c) { return ((string) + c) + ; } templa...
#include <bits/stdc++.h> using namespace std; string s, t, x; vector<int> lcp; vector<bool> match; constexpr int mxn = int(2e5) + 10; int dp[mxn][3]; int pref[mxn]; const int mod = 1e9 + 7; int ans(int start) { if (dp[start][2] != -1) return dp[start][2]; if (start >= x.size()) return dp[start...
#include <bits/stdc++.h> using namespace std; long long int fun(long long int x, long long int y, long long int p) { long long int s = x / p; if (x % p) s++; long long int e = y / p; return e - s + 1; } void solve() { long long int n, p; cin >> n >> p; vector<pair<long long int, long...
#include <bits/stdc++.h> using namespace std; int n, m, q, sm, mx, x, y, ans; char a[509][509]; int rr[509]; int main() { scanf( %d%d%d , &n, &m, &q); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf( %c , &a[i][j]); for (int i = 1; i <= n; i++) { sm = 0, mx = 0; ...
#include <bits/stdc++.h> const long long INF = 1000 * 1000 * 1000 + 47; const long long LINF = INF * (long long)INF; using namespace std; const int mod = 1000 * 1000 * 1000 + 9; const int MAX = 100005; pair<int, int> pts[MAX]; int n, k; struct node { int x, y, l, r; int dp0, dp1; node() { l ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int main() { long long n; cin >> n; if (n % 2 == 0) { cout << 1ll * n / 2; return 0; } bool flag = true; for (int i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) { cout << 1ll * (n - i) / 2...
#include <bits/stdc++.h> using namespace std; const int maxn = 2005, maxm = 4000005; const double pi = 3.141592653589793; const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0}; const int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; int s[maxn][maxn], v[maxn][maxn], f[maxn][maxn]; int qx[maxm], qy[maxm]; int n, cir, rec; ...
#include <bits/stdc++.h> using namespace std; int N; int A[20]; void Work1() { printf( %d n%d n , A[0], A[0]); } void Work2() { printf( %d n%d %d n%d %d n , A[0] * 2, A[0], A[0], A[0], A[0]); } void Work3() { int i, i00, i01, i02, i11, i21, i20, i22, i10, i12; int sum = 0; for (i = 0; i < 9; ++i...
#include <bits/stdc++.h> using namespace std; const int N = 1000000; int T, tot, prod, mn[1000010]; bool solved[10000][11]; bitset<1000> b[10000][11]; vector<int> V, prime; unordered_map<int, int> id; int main() { scanf( %d , &T); for (int i = 2; i <= N; i++) if (!mn[i]) { if (prim...
#include <bits/stdc++.h> using namespace std; long long a[100005][2]; int dp[100005][3]; enum direction { n, l, r, }; int main() { int N; cin >> N; for (size_t i = 1; i <= N; i++) { cin >> a[i][0] >> a[i][1]; dp[i][n] = dp[i][l] = dp[i][r] = 0; } a[0][0] = -1e18; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 0x3f3f3f3f; const long long llinf = 1e18; const long long nax = 0; int n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> m; vector<int> a(n + 5), b(m + 5...
#include <bits/stdc++.h> using namespace std; int a[3]; int main() { cin >> a[0] >> a[1] >> a[2]; sort(a + 0, a + 3); int res = 0; while ((a[0] + a[1]) <= a[2]) { a[0]++; res++; } cout << res; }
#include<bits/stdc++.h> #include<algorithm> using namespace std; #define ll long long #define ld long double #define rep(i,a,b) for(ll i=a;i<b;i++) #define repb(i,a,b) for(ll i=a;i>=b;i--) #define err() cout<< ================================== <<endl; #define errA(A) for(auto i:A) cout<<i...
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void...
#include <bits/stdc++.h> using namespace std; template <typename T> void MACRO_VAR_Scan(T& t) { cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First& first, Rest&... rest) { cin >> first; MACRO_VAR_Scan(rest...); } template <typename T> void MACRO_VEC_ROW_Init(...
#include <bits/stdc++.h> using namespace std; const int MX = 300300; int t, n, m, i, k[MX], c[MX]; long long r; int main() { cin >> t; while (t--) { int n, x, sum = 0, ctr = 0; cin >> n >> x; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]...
#include <bits/stdc++.h> int main() { int a, b; scanf( %d%d , &a, &b); int c = 0; while (b) { c *= 10; c += b % 10; b /= 10; } printf( %d n , c + a); }
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, fu = 0; char ch = getchar(); for (; ch < 48 || ch > 57; ch = getchar()) fu |= (ch == - ); for (; ch > 47 && ch < 58; ch = getchar()) x = x * 10 + ch - 0 ; return fu ? -x : x; } int n, mx = -1000000000, mn = 100000...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); char a[111][111]; for (long long i = 1; i <= 3; i++) for (long long j = 1; j <= 3; j++) cin >> a[i][j]; if (a[1][1] == a[3][3] && a[3][2] == a[1][2] && a[3][1] == a[1][3] && ...
#include <bits/stdc++.h> using namespace std; int tree[500000]; int a[100000], pos[100001]; void update(int node, int l, int r, int pos, int u) { if (l == r) { tree[node] += u; return; } int mid = (l + r) / 2; if (pos <= mid) update(2 * node, l, mid, pos, u); else upd...
#include <bits/stdc++.h> using namespace std; int n, m; int ans; int a[400050]; int back[400050]; vector<int> edge[400050]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1, u, v; i <= m; i++) { ...
#include <bits/stdc++.h> using namespace std; pair<int, int> p; void sort() { int temp = 0; if (p.first < p.second) { temp = p.first; p.first = p.second; p.second = temp; } } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int op = 0; cin >> p....
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, finish1 = INFINITY, finish2 = INFINITY, start1 = 0, start2 = 0, mx = 0; scanf( %lld , &n); for (int i = 1; i <= n; i++) { scanf( %lld %lld , &a, &b); start2 = max(start2, a); finish1 = ...
#include <bits/stdc++.h> int x[100001] = {0}; int main() { int i, n; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &x[i]); } int sum = 0; int cn = 0; for (i = 0; i < n; i++) { sum = sum + x[i] - x[i + 1]; if (sum < 0) { do { cn++; ...
#include <bits/stdc++.h> int main() { int n, m; scanf( %d%d , &n, &m); int a[n], b[m], i, j; for (i = 0; i < n; i++) scanf( %d , &a[i]); for (i = 0; i < m; i++) scanf( %d , &b[i]); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (b[j] == a[i]) printf( %d , a[i]); } ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; const int maxn = 1e5 + 5, maxa = 71, lim = 1 << 19; ll ev[maxn], od[maxn], dp[2][lim]; int n, a, f[lim], comp[maxa]; vector<int> p; int calc_msk(int x) { int msk = 0, b = 1; for (int y : p) { while ...