func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> int main() { int n, i, r; std::string s; scanf( %d/n , &n); for (i = 0; i < n; i++) { std::cin >> s; long long y = 0, ans; int x = s.size() - 4; for (int j = 0; j < x; j++) { y *= 10; y += s[j + 4] - 0 ; } if (x == 1) { ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long mod = 1000000007; long long r(pair<int, int> a) { long long x = a.first; long long y = a.second; return x * x + y * y; } pair<int, int> ...
#include <bits/stdc++.h> using namespace std; int n, x, y, z, q, sum; int main() { ios_base::sync_with_stdio(0); for (cin >> n; n; --n) cin >> x >> y >> z >> q, sum += (z - x + 1) * (q - y + 1); cout << sum << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int N(200009); struct LnkNode { int v, w, nxt; } edge[N << 3]; int etot = 1, fst[N], cur[N]; void addedge_(int u, int v, int w) { ++etot; edge[etot].v = v; edge[etot].w = w; edge[etot].nxt = fst[u]; fst[u] = etot; } void addedge...
#include <bits/stdc++.h> using namespace std; const int nmax = 123456; int n; int a[nmax], b[nmax], c[nmax]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) if (i == a[i]) { printf( YES n ); for (int j = 1; j <= n; j...
#include <bits/stdc++.h> using namespace std; int main() { long a[5], b[5], n, cu, medal, x, y; cin >> a[1] >> a[2] >> a[3]; cu = a[1] + a[2] + a[3]; cin >> b[1] >> b[2] >> b[3]; medal = b[1] + b[2] + b[3]; cin >> n; if (cu % 5 == 0) x = cu / 5; else x = cu / 5 + 1; i...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int si, lef, t0; int a1, t1, p1; int a2, t2, p2; int main() { cin >> si >> lef >> t0; cin >> a1 >> t1 >> p1; cin >> a2 >> t2 >> p2; if (t1 > t2) { swap(a1, a2); swap(t1, t2); swap(p1, p2); } l...
#include <bits/stdc++.h> using namespace std; struct comp { double x, y; } a[65600], b[65600], c[65600], fft[65600], tp[17][65600]; double pi = acos(-1.0); comp operator+(comp a, comp b) { return (comp){a.x + b.x, a.y + b.y}; } comp operator-(comp a, comp b) { return (comp){a.x - b.x, a.y - b.y}; } co...
#include <bits/stdc++.h> using namespace std; vector<int> g[26]; int visited[26]; int p[26], deg[26]; string ans; bool fail; void dfs(int u) { visited[u] = 2; ans += (char)(u + a ); for (int i = 0; i < (int)g[u].size(); i++) { int v = g[u][i]; if (visited[v] == 0) { p[v] =...
#include <bits/stdc++.h> using namespace std; int main() { int bench, more, temp; vector<int> v; cin >> bench >> more; for (int i = 0; i < bench; i++) { cin >> temp; v.push_back(temp); } int min, max = *max_element(v.begin(), v.end()); ; min = *min_element(v.begin(), v.en...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; inline int read() { static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = p1 == p2 &&...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10; int n, k; int v[MAXN]; int f[MAXN]; int search(int num) { int l = 1, r = n; while (l < r) { int mid = (l + r) / 2; if (v[mid] < num) { l = mid + 1; } else { r = mid; } } return l;...
#include <bits/stdc++.h> using namespace std; struct node { bool visited; short prex; short prey; short val; node() { visited = false; } void print() { cout << visited << ( << prex << , << prey << ) << val << endl; } }; struct coord { int x, y; coord(int x, int...
#include <bits/stdc++.h> using namespace std; int n; void chis(int x) { switch (x) { case 0: cout << zero << endl; break; case 1: cout << one << endl; break; case 2: cout << two << endl; break; case 3: cout << three << end...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; if (n == 1) cout << 1 ; else if (n <= 5 && n != 3) cout << 3 ; else if (n <= 13) cout << 5 ; else if (n <= 25) cout << 7 ; else if (n <= 41) cou...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, x, y, a, b; cout << YES n ; cin >> n; while (n--) { cin >> x >> y >> a >> b; cout << (abs(2 * (x % 2)) + abs(y % 2)) + 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, a, b, ms[111][111], d[111], w[111], dd[111]; double f[111], ff[111], ans; int main() { cin >> n >> m; memset(ms, 63, sizeof(ms)); for (int i = 0; i < m; i++) { cin >> a >> b; a--; b--; ms[a][b] = ms[b][a] = 1; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e3; int a[N]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + 1 + n); cout << a[n - k + 1]; }
#include <bits/stdc++.h> using namespace std; int main() { int d, L, v1, v2; cin >> d >> L >> v1 >> v2; printf( %lf n , 1.0 * (L - d) / (v1 + v2)); }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 77, Mod = 1e9 + 7; int n, d1[N], d2[N], P1, P2, Mx, deg[N], p1[N], p2[N]; long long A; vector<pair<int, pair<int, int> > > R; vector<int> a[N]; void dfs(int v, int prev, bool t) { for (int u : a[v]) { if (u == prev) { cont...
#include <bits/stdc++.h> using namespace std; int main() { long int a, b, c; cin >> a >> b >> c; long int temp = b - a; if (c == 0 || b == a) { if (b == a) cout << YES ; else cout << NO ; } else if (temp % c == 0) { if ((temp < 0 && c < 0) || (temp > 0 && c > ...
#include <bits/stdc++.h> using namespace std; long long i, j, k, m, n, t, x; string s, u; int main() { for (scanf( %lld , &t); t--;) { i = 1; cin >> x >> s; for (; s.size() < x; i++) { if (s[i - 1] > 49) { u = s.substr(i); for (k = s[i - 1] - 48; --k;) s += u; ...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); template <typename T> T abs(T x) { return x > 0 ? x : -x; } template <typename T> T sqr(T x) { return x * x; } template <typename T> bool chmin(T &x, T y) { if (x > y) { x = y; return true; }...
#include <bits/stdc++.h> using namespace std; long long n, A, cf, cm, m; long long L, ans[100005], f, ansA, ansL; long long s[100005]; struct data { long long id, v; } a[100005]; bool cmp(data a, data b) { return a.v < b.v || a.v == b.v && a.id < b.id; } long long findL(long long m, long long R) { ...
#include <bits/stdc++.h> using namespace std; const long long N = 3E5 + 7, mod = 998244353; long long n, a[N], inv[N], ans; signed main() { scanf( %lld , &n); for (long long i = 1; i <= n << 1; i++) scanf( %lld , &a[i]); sort(a + 1, a + 2 * n + 1); for (long long i = 1; i <= n; i++) ans = (ans -...
#include <bits/stdc++.h> using namespace std; int main() { long int n; cin >> n; int a[n], b[n], i; for (i = 0; i < n; ++i) cin >> a[i] >> b[i]; for (i = 0; i < n; ++i) { if (a[i] != b[i]) break; } if (i == n) { for (i = 1; i < n; ++i) { if (a[i] <= a[i - 1]) ...
#include <bits/stdc++.h> using namespace std; constexpr int MOD = 1000000007; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (...
#include <bits/stdc++.h> using namespace std; int main() { int i, n; char a[1000][10]; cin >> n; cin >> a[0]; for (i = 1; i <= n; i++) { cin >> a[i]; } if (n % 2 == 0) cout << home ; else cout << contest ; return 0; }
#include <bits/stdc++.h> using namespace std; int n; vector<int> v[1010]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { int aux, aux2; scanf( %d , &aux); for (int j = 0; j < aux; ++j) { scanf( %d , &aux2); v[i].push_back(aux2); } sort(v[i].begi...
#include <bits/stdc++.h> using namespace std; int n, m, a[110]; double f[110][110][110], C[110][110]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) scanf( %d , &a[i]); C[0][0] = 1; for (int i = 1; i <= 55; i++) { C[i][0] = 1; for (int j = 1; j <= i; j++) C[i][j] = ...
#include <bits/stdc++.h> using namespace std; int b[111111], n; int check(int k) { int l = n / k; for (int i = 0; i < l; i++) { int ok = 1; int cur = i; for (int j = 0; ok && j < k; j++) { if (!b[cur]) ok = 0; cur += l; cur %= n; } if (ok) return 1; ...
#include <bits/stdc++.h> using namespace std; int main() { double a, b, h; cin >> a >> b; h = (b * b - a * a) / (2 * a); h = h + (1 / 1000000); cout << fixed << setprecision(13) << h << endl; }
#include <bits/stdc++.h> using namespace std; int n, m; int a, b, t, p; int Pow(int x, int a) { int ret = 1; while (a) { if (a & 1) ret = ret * 1ll * x % 1000000007; a >>= 1, x = x * 1ll * x % 1000000007; } return ret; } int pr[200006]; int J[200006], iJ[200006]; int C(int a,...
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[3]; int s = 0; int count = 0; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> a[j]; if (a[j] == 1) count++; } if (count >= 2) s++; count = 0; } ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void amin(T &a, const T &b) { if (b < a) a = b; } template <class T> inline void amax(T &a, const T &b) { if (a < b) a = b; } struct Data { int sx, sy; int le, ri, to, bo; bool operator<(const Data &y) const { re...
#include<cstdio> #include<cstring> #include<vector> typedef long long ll; int main() { int t,a[120]; scanf( %d ,&t); while(t--) { int n,u,v; scanf( %d%d%d ,&n,&u,&v); for(int i=1;i<=n;i++) { scanf( %d ,&a[i]); } ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < 0 || _tc > 9 ) && _tc != - ) _tc = getchar(); if (_tc == - ) _tc = getchar(), _tmp = -1; while (_tc >= 0 && _tc <= 9 ) _x...
#include <bits/stdc++.h> using namespace std; int main() { int n; string one, two; map<string, string> m; cin >> n; for (int i = 0; i < n; i++) { cin >> one >> two; bool found = false; for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) { if (it->sec...
// Author: HolyK // Created: Thu Jul 8 09:48:07 2021 #include <bits/stdc++.h> #define dbg(a...) fprintf(stderr, a) template <class T, class U> inline bool smin(T &x, const U &y) { return y < x ? x = y, 1 : 0; } template <class T, class U> inline bool smax(T &x, const U &y) { return x < y ? x =...
#include <bits/stdc++.h> using namespace std; void computeLcp(string &s1, string &s2, int LCP[][5005]) { for (int i = ((int)s1.size()) - 1; i >= 0; i--) { for (int j = ((int)s2.size()) - 1; j >= 0; j--) { if (s1[i] == s2[j]) { LCP[i][j] = 1 + LCP[i + 1][j + 1]; } else { ...
#include <bits/stdc++.h> using namespace std; int n, x; void solve() { cin >> n >> x; int left = x - 1; int right = n - x; if (left >= right) cout << (x - 1 == 0 ? 1 : x - 1) << endl; else cout << (x + 1 > n ? n : x + 1) << endl; } int main() { ios_base ::sync_with_stdio(fa...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > res; int n; int tx[1000000], add[1000000]; void up(int i, int l, int r, int a, int b, int x) { if (b < l || a > r) return; if (a <= l && b >= r) { tx[i] += x; add[i] += x; return; } int m = (l + r) / 2; ...
#include <bits/stdc++.h> using namespace std; int n, ans = 1, res = 1, x, mn = 0, mx = 1e9; set<int> S; set<int>::iterator it; char s[10]; int main() { scanf( %d , &n); S.insert(1e9), S.insert(0); for (int i = 1; i <= n; ++i) { scanf( %s%d , s, &x); if (s[1] == D ) S.insert(...
#include <bits/stdc++.h> using namespace std; int n; vector<int> g[100005]; int dep[100005], f[20][100005], mrk[100005], ans[100005]; map<pair<int, int>, int> mp; void dfs(int x, int p, int d) { for (int i = 0; i < g[x].size(); i++) if (g[x][i] != p) dfs(g[x][i], f[0][g[x][i]] = x, dep[g[x][i]] = ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const long long INF = 1e18; const int MAXN = 1e5 + 1; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int b, g, n; cin >> b >> g >> n; cout << min(b, min(g, n)) + 1 - max(0, n - max(b, g)); ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; int n, l[100100], r[100100]; int rs[100100], dp[2][100100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> l[i]; for (int i = 1; i <= n; i++) cin ...
#include <bits/stdc++.h> using namespace std; double dist(int x, int y, int a, int b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } int main() { ios_base::sync_with_stdio(false); cout.tie(0); cout << fixed; cout.precision(10); int n, m; cin >> n; int c, r; vector<pa...
#include <bits/stdc++.h> using namespace std; int p[2001]; int a[2001]; int find(int v) { if (p[v] != v) p[v] = find(p[v]); return p[v]; } void merge(int u, int v) { int pu = find(u); int pv = find(v); p[pu] = pv; } int main() { int n, m, k, i, l, r; cin >> n >> m >> k; f...
#include <bits/stdc++.h> int main() { long long int n, a, b, i, t; scanf( %lld %lld %lld , &n, &a, &b); t = n / a + 1; for (i = 0; i < t; i++) { if ((n - (a * i)) % b == 0 && n - (a * i) >= 0) { printf( YES n%lld %lld , i, (n - (a * i)) / b); return 0; } } printf( N...
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(long long int a, long long int b) { if (a < b) return a; else return b; } const int dx[4] = {-1, 1, 0, 0}; con...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { char c; bool nega = 0; while ((!isdigit(c = getchar())) && (c != - )) ; if (c == - ) { nega = 1; c = getchar(); } x = c - 48; while (isdigit(c = getchar())) x = x * 10 + c -...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, s = 0, i, x, vs = 0; vector<int> a; cin >> n; for (i = 0; i < n; i++) { cin >> x; a.push_back(x); vs += x; } sort(a.begin(), a.end(), std::greater<int>()); if (n == 1) cout << a[0] << endl...
#include <bits/stdc++.h> using namespace std; struct pp { int val; int same; }; vector<pp> with[100005]; vector<int> v[100005]; int color[100005]; int currcolor[100005]; bool ending = false; void dfs(int parent, int curr) { if (ending == true) return; for (int i = 1; i <= with[curr][0]...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int m[N]; int main(void) { int n, a, b, k; scanf( %d %d %d %d , &n, &a, &b, &k); int ans = 0; for (int i = 1; i <= n; i++) { scanf( %d , &m[i]); m[i] = m[i] % (a + b); if (m[i] == 0) { m[i] = a + b; ...
#include <bits/stdc++.h> using namespace std; int v[55]; double dp[55][55][55]; int main() { int n, p, sum = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &v[i]); sum += v[i]; } scanf( %d , &p); if (sum <= p) { printf( %d n , n); return 0; } ...
#include <bits/stdc++.h> using namespace std; vector<int> p; bool first[5000] = {0}; void gen() { p.push_back(0); for (int i = 2; i <= 500; i++) { if (!first[i]) { p.push_back(i); for (int j = 2 * i; j <= 500; j += i) { first[j] = 1; } } } } bool isp...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, k; cin >> n >> k; if (k == 0) { cout << 0 0 ; return 0; } if (n == k) cout << 0; else cout << 1; cout << ; if (n % 2 == 0) { long long temp = 3 * k; if (temp <= n) ...
#include <bits/stdc++.h> using namespace std; int n, a, b; char seats[200001]; int main() { scanf( %d%d%d , &n, &a, &b); scanf( %s , seats); int ans = 0; char prev = . ; for (int i = 0; i < n; ++i) { if (seats[i] == * ) { prev = . ; continue; } if (prev =...
#include <iostream> #include <vector> #include <algorithm> #include <map> using namespace std; const int64_t INF = 1e15; struct Dinic { struct Edge { int v; int64_t f, c; Edge(int _v = 0, int64_t _f = 0, int64_t _c = 0): v(_v), f(_f), c(_c) {}; }; int n; vector<int> idx, ...
#include <bits/stdc++.h> using namespace std; const int N = 3000020, M = 120; int L, R, p, ans, tot, cnt, g[N], f[N], P[M]; bool buc[N], vis[M]; void dfs(int k, int res) { g[++cnt] = res; for (int i = k; i <= tot; i++) { if (1ll * P[i] * res <= 1ll * R) dfs(i, res * P[i]); } } signed mai...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; cout << n << endl; } }
#include <bits/stdc++.h> const long long oo = 1e9; const long long mod = 95542721; const long long MAX = 1e9; const long long ARR = 1e5; using namespace std; int main() { ios_base::sync_with_stdio(false); long long n, m; set<long long> x, y; cin >> n >> m; for (long long i = (0); i < (lo...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, x, y; cin >> a >> b >> x >> y; if (a == x || b == y) { cout << abs(x - a) + abs(b - y) << n ; goto v; } else cout << abs(a - x) + abs(b - y) + 2 << n ; ...
#include <bits/stdc++.h> using namespace std; char s[92], sl[10][10], str[10]; bool cmp(char* a, char* b) { for (int i = 0; i < 10; i++) if (a[i] != b[i]) return false; return true; } int main() { scanf( %s , &s); for (int i = 0; i < 10; i++) scanf( %s , sl[i]); for (int i = 0; i < 8...
#include <bits/stdc++.h> using namespace std; double p[210]; int a[210]; double dp[210][210][210]; int main(void) { int N, L, K, i, j, k; cin >> N >> L >> K; for ((i) = 0; (i) < (int)(N); (i)++) cin >> p[i]; for ((i) = 0; (i) < (int)(N); (i)++) cin >> a[i]; for ((i) = 0; (i) < (int)(N); (i...
#include <bits/stdc++.h> using namespace std; bool F = true; long long sum = 0; void DFS(int v, int par, vector<vector<int>> &g, vector<long long> &s, vector<long long> &a) { if (s[v] == -1) { if (g[v].size() == 0) return; long long m = 2e9; for (int u : g[v]) m = min(s[u], m); ...
#include <bits/stdc++.h> using namespace std; struct Data { int64_t value; int64_t supports; int64_t supportedBy; }; bool isTop(map<pair<int64_t, int64_t>, Data> const& cubes, pair<int64_t, int64_t> const& pos) { bool top = true; for (int64_t i = -1; i <= 1; ++i) { map<pai...
#include <bits/stdc++.h> using namespace std; template <class T> inline void remax(T& A, T B) { if (A < B) A = B; } template <class T> inline void remin(T& A, T B) { if (A > B) A = B; } string ToString(long long num) { string ret; do { ret += ((num % 10) + 0 ); num /= 10; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1005; map<pair<int, int>, int> mapa; int main() { int n, h, m; scanf( %d , &n); int c = 0; for (int i = 0; i < n; i++) { scanf( %d%d , &h, &m); int x = ++mapa[make_pair(h, m)]; if (x > c) c = x; } printf( %d ...
#include <bits/stdc++.h> using namespace std; const int N = 1001000; int n; void add(long long* a, int x, long long y) { for (; x <= n; x += x & -x) a[x] += y; } long long gsm(long long* a, int x) { long long ret = 0; for (; x; x &= x - 1) ret += a[x]; return ret; } long long sum0[N], su...
#include <bits/stdc++.h> using namespace std; int const MAXN = 5e5 + 10; int n, a[MAXN], ans; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i < n; i++) { if (a[i] != a[i + 1]) { int pt = i + 1, tam = 1; while (a[pt] != a[pt + 1] ...
#include <bits/stdc++.h> using namespace std; int32_t main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n, m; cin >> n >> m; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; vector<long long> dp(n); dp[0] = v[0]; for (long lon...
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, use[200010], culoare[200010], v[200010], x, y, a; vector<int> v2[200010]; vector<pair<int, int> > G[200010]; void DF(int nod) { use[nod] = 1; for (auto it : G[nod]) { if (!use[it.first]) { if (it.second == 1) { cu...
#include <bits/stdc++.h> using namespace std; struct Tans { long a; long b; }; struct mstr { long num; long val; }; bool operator<(mstr a, mstr b) { return a.val < b.val; } bool operator>(mstr a, mstr b) { return a.val > b.val; } bool operator==(mstr a, mstr b) { return a.val == b.val; }...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i, sum = 0; cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; sum = sum + a[i]; } sort(a, a + n); i = 0; while (1) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, *animals, i, j, temp; bool turn = 0; cin >> n; animals = new int[n]; for (i = 0; i < n; i++) cin >> animals[i]; vector<pair<int, int> > segmant; pair<int, int> seg; for (i = 0; i < (n - 1); i++) { if (animals[i] ...
#include <bits/stdc++.h> using namespace std; const long long LLINF = 1e18 + 7; const long long INF = 1e9 + 7; const long long EPS = 1e-9 - 7; const long long MAX = 1e2 + 7; const long long MOD = 1e9 + 7; int n, d, dp[MAX]; string s; bool can[MAX], flag = false; int main() { memset(dp, MAX, size...
/* Mbak Sana Dong Mbak Chaeyoung Dong Mbak Eunha Dong Mbak Seulgi Dong Mbak Wendy Dong Stream https://www.youtube.com/watch?v=LmBYPXGqtss */ #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization ( unroll-loops,O3 ) #include<bits/stdc++.h>...
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { return a > b ? b : a; } int main() { int n, m; cin >> n >> m; cout << min(n, m) + 1 << endl; for (int i = 0; i <= min(n, m); i++) cout << i << << min(n, m) - i << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; char buf[1 << 21], *p1 = buf, *p2 = buf; inline int gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF ...
#include <bits/stdc++.h> using namespace std; int n, m, a, b; int x[205], y[205], c[205], siz[75], ans[75]; int info[75], Prev[205 << 1], to[205 << 1], cst[205 << 1], cnt_e; void Node(int u, int v, int ct) { Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v, cst[cnt_e] = ct; } int F[75], bl[75],...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int, int>> v(n); for (auto &x : v) cin >> x.first >> x.second; if (is_sorted(v.rbegin(), v.rend())) { bool ok = true; for (auto x : v) if ...
#include <bits/stdc++.h> using namespace std; int inf = (1 << 29) - 1; int n, m, S, T, ans; int a[20000], b[20]; struct edge { int b, len; edge *nxt, *op; } e[100000], *le(e); edge *head[20000]; void add(int u, int v, int w) { le->b = v, le->len = w, le->nxt = head[u], le->op = le + 1, head[...
#include <bits/stdc++.h> using namespace std; int dist[2005][2005]; char f[2005][2005]; int n, m, r, c, x, y; int main() { scanf( %d%d%d%d%d%d , &n, &m, &r, &c, &x, &y); x = min(x, 10000000); y = min(y, 10000000); r--; c--; for (int i = 0; i < n; i++) scanf( %s , &f[i]); for (int i...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const int maxn = 500100; int n; v...
#include <bits/stdc++.h> using namespace std; long long judge(long long mid) { long long b; long long cnt = 0; for (b = 2;; b++) { cnt += mid / b / b / b; if (mid / b / b / b == 0) break; } return cnt; } int main() { long long m; cin >> m; long long r = 1e16, l = 0; ...
#include <bits/stdc++.h> struct task { task() : pc(-1), indegree(0), outgoing() {} int pc; int indegree; std::vector<int> outgoing; }; int solve(int pc, std::vector<task> tasks) { std::queue<int> todo[3]; for (__decltype((tasks).begin()) t = (tasks).begin(), t_end = (tasks).end(); ...
#include <bits/stdc++.h> using namespace std; int N, K; int h[100005]; bool isok[100005]; int check(int L) { deque<int> A, B; int ret = 0; for (int i = 1; i <= N; ++i) { while (A.size() && A.front() + L <= i) A.pop_front(); while (B.size() && B.front() + L <= i) B.pop_front(); wh...
#include <bits/stdc++.h> using namespace std; const int size = 110000, mod = 1000000007, inf = 0x3f3f3f3f; const double pi = acos(-1.0); int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int nex[2][4] = {0, 1, 0, -1, 1, 0, -1, 0}; long long cal(long long a, int n) { long long s = 1 % ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, x; cin >> n >> x; int temp, cnt = 0; for (int i = 0; i < n; i++) { cin >> temp; cnt += temp; } if ((cnt + n - 1) == x) cout << YES << endl; else cout << NO << en...
#include <bits/stdc++.h> using namespace std; int X; vector<int> v[100010]; int all, all2; bool used[800 + 10]; int dp[800 + 10], dp2[800 + 10]; void calc(int x) { int i; for ((i) = 0; (i) < (int)(800); (i)++) used[i] = false; for ((i) = 0; (i) < (int)(v[x].size()); (i)++) used[v[x][i]] = true...
#include <bits/stdc++.h> using namespace std; template <class T> inline void cmin(T &a, T b) { ((a > b) && (a = b)); } int cmax(int &a, int b) { return a < b ? a = b, 1 : 0; } char IO; template <class T = int> T rd() { T s = 0; int f = 0; while (!isdigit(IO = getchar())) f |= IO == - ; ...
#include <bits/stdc++.h> using namespace std; vector<long long> graph[100005]; vector<pair<long long, long long> > graph_p[100005]; vector<pair<long long, long long> > op; vector<long long> vis(100005, 0); long long power(long long x, long long y) { long long res = 1; x = x % 1000000009; if (x =...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, k, a[maxn]; vector<int> ans; long long sum; int main() { ios::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum += a[i]; } int partsum = sum / k; int tmp = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int maxm = 300005; struct segtree { int tree[30 * maxm], L[30 * maxm], R[30 * maxm]; int sz = 0; int root[maxm]; int update(int pre, int l, int r, int pos, int val) { if (l > r || pos < l || pos > r) return pre;...
#include <bits/stdc++.h> using namespace std; void doRoutine() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; } signed main() { doRoutine(); vector<long long int> a(6); long long i...
#include <bits/stdc++.h> using namespace std; const int dd = (int)2e6 + 7; int A[dd], cnt[dd]; long long tmp[dd]; pair<int, int> msk[20]; int count2[20], w; long long pw[20]; long long ans = 0; void get(int i, long long k) { if (i == w) { ans += tmp[k]; return; } if (count2[i] ...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& o, const vector<T>& v) { o << [ ; int b = 0; for (const auto& a : v) o << (b++ ? , : ) << a; o << ] ; return o; } template <typename T, typename U> ostream& operator<<(ostream& o, cons...
#include <bits/stdc++.h> using namespace std; long long pwr(long long base, long long p, long long mod = (1000000007LL)) { long long ans = 1; while (p) { if (p & 1) ans = (ans * base) % mod; base = (base * base) % mod; p /= 2; } return ans; } long long gcd(long long a, long lon...
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; using pii = std::pair<long long, long long>; using namespace std; const long long maxn = 5e5 + 5; long long n, a[maxn], origvals[maxn], bit[2][maxn]; long long sum(long long dir, long long idx) { long long curans = 0; for (++idx; idx > 0; idx -...