func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; struct Maxflow { static const int oo = 100000005; static const int maxn = 5555 * 2; static const int maxm = 5555 * 4; int T, S; struct node { int to, nxt, cap; } ed[maxm * 2]; int head[maxn], cur[maxn], cnt, ans, ndnum; int h[maxn];...
#include <bits/stdc++.h> using namespace std; inline long long valabs(long long x) { if (x < 0) return -x; return x; } inline long long max2(long long a, long long b) { return (a > b ? a : b); } int main() { long long x, y, xx, yy; cin >> x >> y >> xx >> yy; cout << max2(valabs(x - xx), va...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int inf = 0x3f3f3f3f; int deep[maxn], fa[maxn][32]; vector<int> edge[maxn]; int flag[maxn]; void dfs(int u) { flag[u] = 1; for (auto i : edge[u]) { int t = i; if (flag[t]) continue; deep[t] = deep[u] + 1...
#include <bits/stdc++.h> using namespace std; int n; int mh, currx = 1, level[110], l = 0; char sc[110]; char mas[4 * 110][4 * 110]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> sc[i]; if (sc[i] == [ ) { l++; level[i] = l; } else { level[i] ...
#include <bits/stdc++.h> using namespace std; string rep(string s, int x) { string res; while (x--) res += s; return res; } int ask(string str) { cout << str << n ; fflush(stdout); int x; cin >> x; return x; } int main() { int a = ask( a ); if (a == 0) return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c; bool yes = true; int length, i; cin >> a >> b; length = a.length(); for (i = 0; i < length; i++) { if (a[i] < b[i]) { yes = false; break; } } if (yes == false) { cout << -1 <<...
#include <bits/stdc++.h> int read() { int x = 0, c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + c - 0 , c = getchar(); return x; } const int maxn = 205, mod = 1000000009; std::vector<int> G[maxn]; int ins[maxn]; int stack[maxn], sp; int dfn[maxn], low[ma...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); int m; cin >> m; int a[m]; for (int i = 0; i < m; i++) { cin >> a[i]; } sort(a, a + m); for (int i = 0; i * 2 < s.size(); i++) { int pos = upper_bound(a, a + m, i + ...
#include <bits/stdc++.h> using namespace std; struct data { int x, y; } t[800001]; int n, m, k, x, y, sum, cnt, tot, h[400001], st[400001], f[400001], fa[400001], p[400001], idfn[400001], dfn[400001], low[400001], son[400001], dep[400001], sz[400001], tr[1600001]; char ch[11]; vector<int> v[...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { if (i % 4 == 0 || i % 4 == 1) { printf( a ); } else { printf( b ); } } }
#include <bits/stdc++.h> using namespace std; inline long long rd() { long long x = 0; int ch = getchar(), f = 1; while (!isdigit(ch) && (ch != - ) && (ch != EOF)) ch = getchar(); if (ch == - ) { f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch...
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000000000000000; int c[1001][1001]; int main(void) { int n, m; scanf( %d %d , &n, &m); long long s = 0, sij = 0, si = 0, sj = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { int p = (i - 1) * 4...
#include <bits/stdc++.h> using namespace std; int n, m; inline int read() { int t = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) f = (ch == - ) ? -1 : f, ch = getchar(); while (ch >= 0 && ch <= 9 ) t = t * 10 + ch - 0 , ch = getchar(); return t * f; } struct orz { c...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string myNumber; cin >> myNumber; int temp; int fhalf = 0, shalf = 0; for (int i = 0; i < n / 2; ++i) { temp = myNumber[i] - 0 ; if (temp != 4 && temp != 7) { cout << NO ; goto exit;...
#include <bits/stdc++.h> int main() { int n, i, ans = 0, a[200001] = {0}; scanf( %d , &n); for (i = 0; i < n; i++) { int x; scanf( %d , &x); if (a[100000 + x] == 0 && x != 0) { ans++; a[100000 + x] = 1; } } printf( %d n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); unordered_map<int, int> ma; int x, y, z, l; cin >> x >> y; vector<int> vec(x); vector<int> vec1(x); for (int i = 0; i < x; i++) cin >> vec[i]; vec1 = vec; for (int...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (i % 2 == 1) { if (i % 4 == 1) if (j == m - 1) cout << # ; else cout << . ; ...
#include <bits/stdc++.h> using namespace std; int n, k; struct node { int mn[11], mx[11], sz; bool operator<(const node &p) const { for (int i = 1; i <= k; i++) if (mx[i] > p.mn[i]) return 0; return 1; } } now; set<node> S; set<node>::iterator it; int main() { scanf( %d...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 3; vector<int> adj[MAXN]; int sz[MAXN], rt = -1, ok[MAXN], k; int dfs1(int u, int p) { for (int i = 0; i < adj[u].size(); i++) if (adj[u][i] != p) sz[u] += dfs1(adj[u][i], u); return sz[u]; } pair<int, int> dfs2(int u, int ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int g = 0; pair<int, int> A[1000], B[1000]; for (int i = 1; i <= n; i++) { cin >> A[i].first >> A[i].second; cin >> B[i].first >> B[i].second; g += (((B[i].first - A[i].first) + 1) * ((B[i].se...
#include <bits/stdc++.h> int main() { int n, m, x, nn, j, mm, y, z, i, tmp, p; int a, b; scanf( %d%d%d%d%d%d , &nn, &mm, &x, &y, &z, &p); for (j = 1; j <= p; j++) { n = nn; m = mm; scanf( %d%d , &a, &b); x %= 4; z %= 4; if (y % 2 == 0) { for (i = 1; i <= (x ...
#include <bits/stdc++.h> const int maxn = 400000 + 5; int f[maxn]; int n, m, q; int ans; inline int Read() { register int ret; register char r; register bool f = false; while (r = getchar(), r < 0 || r > 9 ) if (r == - ) f = true; ret = r - 48; while (r = getchar(), r >= 0 ...
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; int main() { int q; cin >> q; vector<P> v(q); for (int qi = 0; qi < q; qi++) { int t; cin >> t; if (t == 1) { int x; cin >> x; v[qi] = {x, 0}; } else { int x, y; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 12e4 + 5; struct node { int minn, cnt, lazy, time; long long sum; } tree[maxn << 2]; int n, q; int p[maxn], stk_min[maxn], stk_max[maxn], top_min, top_max; long long ans[maxn]; pair<pair<int, int>, int> querys[maxn]; inline void ad...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAXN = 305; const int MAXT = 100005; int a[MAXN], e[MAXN], d[MAXN]; long long dp[MAXT]; long long t, cnt; void dfs(int u, int acc) { if (t < 0) { return; } ++cnt; a[u] += acc; if (e[u] != 0) { ...
#include <bits/stdc++.h> using namespace std; queue<int> q[300005]; set<int> all; int main() { int n, quer; scanf( %d%d , &n, &quer); int t, x, v; int in = 1; for (int i = 1; i <= quer; i++) { scanf( %d%d , &t, &x); if (t == 1) { q[x].push(in); all.insert(in); ...
#include <bits/stdc++.h> using namespace std; struct SegmentTree { private: int n; vector<pair<int, int>> a; vector<pair<int, int>> tree; public: SegmentTree(vector<pair<int, int>> &a) { this->a = a; this->n = (int)a.size(); tree.resize(4 * n); build(1, 1, n); } ...
#include <bits/stdc++.h> using namespace std; int n, m, a[101], s[101], ans, l, r; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i < n + 1; i++) cin >> a[i]; for (int i = 1; i < n + 1; i++) s[i] = s[i - 1] + a[i]; ans = 0; for (int i = 0; i < m; i++) { cin ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n; struct node { int op; long long l; long long r; } q[N + 5]; int cnt; long long Hash[3 * N + 5]; int len; struct T { int sum; int lazy; } tree[12 * N + 5]; void pushup(int k) { tree[k].sum = tree[k << 1].sum...
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0), eps = 1e-10; long double det(long double a11, long double a12, long double a21, long double a22) { return a11 * a22 - a12 * a21; } struct pt { long double x, y; pt(long double x, long double y) : x(x...
#include <bits/stdc++.h> using namespace std; int n; long long sum = 0, m1 = 0; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) { int x; scanf( %d , &x); sum += x; m1 = max(m1, (long long)x); } if (m1 <= sum / 2 && sum % 2 == 0) printf( YES n ); else ...
#include <bits/stdc++.h> using namespace std; const int N = 200004 * 4 + 11; long long k[N], add[N]; int a[200004]; int n, m; int x, y; long long z; long long ans; int build(int l, int r, int o) { add[o] = 0; if (l == r) return k[o] = a[l]; int mid = ((l + r) >> 1); return k[o] = build...
#include <bits/stdc++.h> int main() { int n, q; scanf( %d , &n); scanf( %d , &q); int i; long ans[q + 1]; long val; std::set<long> valores; for (i = 0; i < n; i++) { scanf( %ld , &val); valores.insert(val); } std::set<long>::iterator ite; std::multiset<long> dif...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m; struct Query { int l, r, x; Query() {} Query(int ll, int rr, int xx) { l = ll, r = rr, x = xx; } }; vector<Query> q[N]; int lson[N], rson[N]; void init() { int cnt = 0, p = 1; for (int i = 1; i < N; ++i) {...
#include <bits/stdc++.h> using namespace std; int main() { int q; scanf( %d , &q); while (q--) { int n; scanf( %d , &n); int sum = 0, a; for (int i = 0; i < n; ++i) { scanf( %d , &a); sum += a; } printf( %d n , (int)ceil(sum * 1.0 / n)); } retu...
#include <bits/stdc++.h> using std::map; using std::max; using std::min; using std::set; using std::string; using std::vector; constexpr long long magic_mod = 1000000007; constexpr long long big = 1ll << 60; struct Matrix { long long size; vector<long long> f; Matrix(long long size, long l...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 20; const int INF = 1e9; struct Edge { int to, next, w; } e[2 * N]; int n, head[N], M, num; map<int, int> mp, sp; long long ans; void add(int u, int v, int w) { e[num].next = head[u]; e[num].to = v, e[num].w = w; head[u]...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b; b = r; } return a; } long long power(long long x, long long y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y /...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed; int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; int cost = 0; if (e > f) { int suits = min(a, d); cost += e * suits; a -= suits; d -= ...
#include <bits/stdc++.h> using namespace std; char a; int r, c; bool side(int x) { if (x == 1 or x == 8) return true; return false; } int type(int x, int y) { if (side(x) and side(y)) return 1; if (side(x) or side(y)) return 2; return 3; } int main() { scanf( %c%d , &a, &r); ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:251700000 ) using namespace std; const int INF = 2e9; const double eps = 1e-6; const int M = 1e5 + 5; int n; string s[M]; bool us[M]; char SS[M]; string get_s() { scanf( %s , &SS); return string(SS); } int main() { scanf( %d ,...
#include <bits/stdc++.h> using namespace std; int main() { int c, d, n, m, k, needed; cin >> c >> d >> n >> m >> k; needed = n * m - k; cout << ((needed <= 0) ? 0 : min(needed * d, min(needed / n * c + needed % n * d, (int)(cei...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; const int N = 1e5 + 5; int n; long long x, y, ans; bool comp[N]; vector<long long> primes; long long add(long long a, long long b) { return (a + b) % MOD; } long long mul(long long a, long long b) { return (a * b) % MOD; } long l...
#include <bits/stdc++.h> using namespace std; const int MAXN = 300010; pair<pair<int, int>, pair<int, int> > allNums[MAXN * 2]; set<pair<int, int> > startTimes; pair<int, int> v[MAXN]; int main() { int N; scanf( %d , &N); for (int i = 0; i < N; ++i) { scanf( %d%d , &v[i].first, &v[i].secon...
#include <bits/stdc++.h> using namespace std; const int MaxN = 5e5; const int Inf = 1 << 30; int mpx[MaxN + 5]; vector<int> s, t[MaxN + 5]; bool cmp(int x, int y) { return x > y; } int main() { int n, m, x, u, v, ans, S, p; while (~scanf( %d %d , &n, &m)) { ans = 0; for (int i = 1; i <...
#include <bits/stdc++.h> int N, K; int use[8]; int per[8]; int level[8]; int A; double res; void dfs(int depth, int st) { int i, j, sum, all, dame; double p, ok, tmp; if (depth == K) { tmp = 0; for (i = 0; i < 1 << N; i++) { p = 1; sum = all = dame = 0; for ...
#include <bits/stdc++.h> using namespace std; void jizz() { cout << -1 << endl; exit(0); } int s[200005], l[200005], r[200005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> s[i] >> l[i]; r[i] = s[i] + l[i]...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <class T, class U> void mod_partial_sum(const T& v, U* out, ll mod) { auto it = begin(v); ll val = 0; for (auto& x : *out) x = (val += *(it++)) %= mod; } int main() { cout << fixed << setpr...
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int a, b, c, ar[maxn], al[maxn]; bool gg = false; int main() { cin >> a >> b >> c; for (int i = 0; i < b; i++) cin >> ar[i]; for (int j = 0; j < c; j++) cin >> al[j]; for (int i = 1; i <= a; i++) { for (int j = 0; j < b;...
#include <bits/stdc++.h> using namespace std; int main(void) { long double a, b, c, p, q, r; cin >> a >> b >> c; p = b * b - 4 * a * c; if (a == 0 && b == 0 && c == 0) cout << -1 << endl; else if (a == 0 && b == 0 && c != 0) cout << 0 << endl; else if (p < 0) cout << 0 << e...
#include <bits/stdc++.h> int main() { long long int t, i = 0; long long ans = 0; scanf( %lld , &t); for (i = 0; i < t; i++) { long long int n; scanf( %lld , &n); ans = ans + i * (n - 1) + n; } printf( %lld n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, k, ans = 0; cin >> x >> k; while (x--) { int a, b; cin >> a >> b; ans += abs(a - b) + 1; } int ans2 = 0; while (true) { if (ans % k == 0) { cout << ans2; break; } else { an...
#include <bits/stdc++.h> #pragma GCC optimize 03 using namespace std; const long long int inf = 1e15; const long long int MOD = 1e9 + 7; const long long int N = 2e5 + 5; struct SegTree { struct data { long long int val; data() : val(0){}; template <typename T> void apply(T v) {...
#include <bits/stdc++.h> using namespace std; int n; int a[2][200005]; int dp[2][200005][19]; void gao(int c) { for (int i = 1; i <= n; ++i) dp[c][i][0] = a[c][i]; for (int j = 1; (1 << j) <= n; ++j) { for (int i = 1; i + (1 << (j - 1)) <= n; ++i) { if (c == 0) dp[c][i][j] = ma...
#include <bits/stdc++.h> int n, m, k; char s[2505][2505]; long long a[2505][2505]; inline long long sum(int r1, int c1, int r2, int c2) { return a[r2][c2] - a[r1 - 1][c2] - a[r2][c1 - 1] + a[r1 - 1][c1 - 1]; } inline long long go(int r1, int c1, int r2, int c2) { if (r1 == r2 && c1 == c2) return sum...
#include <bits/stdc++.h> using namespace std; int main() { int n, l; cin >> n >> l; deque<int> v; while (n--) { int m; cin >> m; v.push_back(m); } sort(v.begin(), v.end()); int a = v[0]; int b = v[v.size() - 1]; v.push_front(a * (-1)); v.push_back(2 * l - b)...
#include <bits/stdc++.h> using namespace std; int n = 8; struct point { int x; int y; }; bool f(point a, point b) { if (a.x != b.x) return a.x > b.x; return a.y > b.y; } int main() { point a[8]; for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y; int t1 = 0, t2 = 0; for (i...
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; long long fe(long long e) { if (e == 0) return 1; long long ans = fe(e / 2); ans = (ans * ans) % md; if (e % 2) ans *= 2; return (ans % md); } int main() { long long x, y; cin >> x >> y; if (y % x) { ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); signed main() { std::ios::sync_with_stdio(false); string str; cin >> str; long long int n = str.size(); string prf = ; vector<long long int> v(n, 0); for (long long int ...
#include <bits/stdc++.h> using namespace std; long long u[11]; int main() { long long x, y, n, i, j, k = 0, l, arr[200009]; cin >> n; for (i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (i = 0, j = 1; i < n; i++) { if (arr[i] >= j) { k++; j++; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const int inf32 = 1e9 + 9; const long long inf64 = 1e18 + 18; const int N = 6e5 + 5; const long long mod = 1e9 + 7; map<int, int> mp; vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; int n, mx; voi...
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ; cerr << endl; } int n, len; char s[1000005]; int var[1000005][4]; int cnt, ind; int parse() { if (s[ind] == 0 ) var[cnt][0] = ...
#include <bits/stdc++.h> using namespace std; int n, m, n1, m1; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; n1 = n, m1 = m; if ((n1 == m1 + 1 and !(n1 + m1 % 2)) or n1 > m1 + 1 or m1 / 2 + (m1 % 2) > n1 + 1 or (m1 / 2 + (m1 % 2)) == n1 + 1 and !(m1...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, d, k; cin >> n >> t >> k >> d; int a; a = (d + t) / t; if (a * k < n) cout << YES ; if (a * k >= n) cout << NO ; }
#include <bits/stdc++.h> using namespace std; int fact[100005]; void criba() { for (int i = 2; i * i < 100005; i++) if (fact[i] == 0) for (int j = i * i; j < 100005; j += i) fact[j] = i; for (int i = 2; i < 100005; i++) if (fact[i] == 0) fact[i] = i; } bool vis[100005]; set<pair<...
#include <bits/stdc++.h> using namespace std; ifstream in( pairs.in ); ofstream out( pairs.out ); const int DIM = 1e5 + 5; int nxt[DIM], val[DIM], pos[DIM]; pair<int, int> tdp[DIM][2], cdp[DIM], arr[2][DIM]; deque<int> chn; bitset<DIM> oki, mrk, ist; vector<pair<int, int>> sol; vector<int> edg[DIM];...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = 1e6 + 7; const int INF = 1e9 + 7; int n, m; int mid = 0; int ile[70]; long long mnoz = 1; long long ans = 0; bitset<128> maska; void backtrack(int poz = 1) { ans += mnoz; if (poz > mid) return; for (...
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, bool> > v[300100]; set<pair<int, int> > Bridges; vector<pair<pair<int, int>, int> > All; bool vis[300100], F = 0; int cnt = 0, num[300100], low[300100], Size[300100], par[300100], a, b; bool Ok[300100]; void init() { for (int...
#include <bits/stdc++.h> using namespace std; typedef long double LD; typedef long long ll; #define int ll #define ff(i,a,b) for (int i = a; i < b; i++) #define bf(i,a,b) for (int i = a; i >= b; i--) #define all(v) v.begin(),v.end() #define show(a) for(auto xyz:a)cout<<xyz<< ;cout<<endl; #defi...
#include <bits/stdc++.h> using namespace std; int entries[1010000][2]; long long has[1010000]; long long power[1010000]; int main() { int i, j; long long ans = 0; int n, m, u, v, p = 31; scanf( %d%d , &n, &m); power[0] = 1; for (i = 1; i <= n; i++) power[i] = power[i - 1] * p; for ...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ii = pair<int, int>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<ii>; using graph = vector<vi>; using matrix = graph; const int MAXN = 1e6 + 5; const int INF = 0x3f3f3f3f; const ll INFL = 1e18 + 4; ...
#include <bits/stdc++.h> using namespace std; long long bigmod(long long base, long long power, long long mod) { if (power == 0) return 1; else if (power % 2 == 1) { long long p1 = base % mod; long long p2 = (bigmod(base, power - 1, mod)) % mod; return (p1 * p2) % mod; } else if ...
#include <bits/stdc++.h> using namespace std; int main() { string str1, str2; cin >> str1 >> str2; int siz = str1.size(); siz--; while (siz > -1) { if (str1[siz] == z ) { str1[siz] = a ; siz--; } else { str1[siz]++; break; } } if (siz =...
#include <bits/stdc++.h> using namespace std; const int size = 1000007; const long long modulo = 1000000007; const long long INF = 1e9; const double EPS = 1e-10; int main() { cin.sync_with_stdio(0); int n, m, k; cin >> n >> m >> k; int ans = 0; for (int i = 0; i < n; i++) { int a; ...
#include <bits/stdc++.h> using namespace std; vector<int> G[505000], S[505000]; unordered_map<int, int> f[505000]; int n, m, dep[505000], fa[505000], bel[505000], used[505000]; void dfs(int x, int fff) { fa[x] = fff; dep[x] = dep[fff] + 1; for (auto y : G[x]) if (y != fff) { if (!dep...
#include <bits/stdc++.h> int main(void) { int h, m; scanf( %d:%d , &h, &m); while (1) { m++; if (m == 60) { m = 0; h = (h + 1) % 24; } if ((m % 10 == h / 10) && (h % 10 == m / 10)) { printf( %02d:%02d , h, m); return 0; } } }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, cnt = INT_MAX, c = 0; cin >> n >> k; string s, temp = ; cin >> s; int freq[26]; memset(freq, 0, sizeof(freq)); for (int i = 0; i < n; i++) freq[s[i] - A ]++; for (int i = 0; i < k; i++) { if (!freq[i]) retu...
#include <bits/stdc++.h> using namespace std; int n, k; int a[222], sum[222]; struct node { int a, id; } b[222]; bool cmp(node s, node d) { return s.a < d.a; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i], b[i].a = a[i], b[i].id = i; ; sum[0] = a[0]; for (int...
#include <bits/stdc++.h> using namespace std; int main() { int n, x(0); cin >> n; string s; while (n--) { cin >> s; if (s[1] == + ) { ++x; } else { --x; } } cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long mod = 1e9 + 7; const long long N = 1e5 + 10; int main() { ios::sync_with_stdio(false); long long n; cin >> n; vector<pair<long long, long long> > v(n); for (long long i = 0; i < n; i++) cin >> v[i].fi...
#include <bits/stdc++.h> const int N = 4e5 + 7, M = 2760000; int a[N], prime[N], m, flg[M], f[M], x[N], y[N], nn, mm, tot[M]; template <typename Tp> inline void read(Tp &x) { x = 0; bool f = true; char ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) f ^= ch == - ; for (; ch >= ...
#include <bits/stdc++.h> #define ll long long #define db long double #define x first #define y second #define mp make_pair #define pb push_back #define all(a) a.begin(), a.end() using namespace std; struct Pair { int x; int y; int def_stack; }; bool cmp(Pair &a, Pair &b) { ...
#include <bits/stdc++.h> using namespace std; bool const TO_FILE = false; string const FILENAME = ; void prepare() { if (TO_FILE) { freopen((FILENAME + .in ).c_str(), r , stdin); freopen((FILENAME + .out ).c_str(), w , stdout); } } void solve() { int n, m, k; cin >> n >> m ...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using P = pair<int, int>; constexpr int INF = 1 << 30; template <typename Monoid> struct SegmentTree { private: using F = function<Monoid(Monoid, Monoid)>; int N; vector<Monoid> node; F f; Monoid e; public: ...
#include <bits/stdc++.h> using namespace std; const long long int dx[] = {0, 1, -1, 0, 1, -1, -1, 1}; const long long int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1}; long long int gcd(long long int x, long long int y) { return (y != 0 ? gcd(y, x % y) : x); } long long int lcm(long long int x, long long int y) {...
#include <bits/stdc++.h> using namespace std; long long int a[30], b[30]; char s[1000005]; struct st { long long int x, y; } ara[30]; bool comp(struct st x1, struct st x2) { return x1.y < x2.y; }; int main() { long long int i, j, k, l, m, n, ans = 1LL, t; scanf( %lld %lld , &n, &k); scanf(...
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { while (b) b ^= a ^= b ^= a %= b; return a; } template <class T> inline T lcm(T a, T b) { a = abs(a); b = abs(b); return (a / gcd(a, b)) * b; } template <class T> inline T my_strrev(T array) { ...
#include <bits/stdc++.h> using namespace std; double a, ay, b, by, dx, dy, x[100011], y[100011], before[100011], after[100011], r = 1e18, dist; int n, i, pos; int main() { cin >> a >> ay >> b >> by >> dx >> dy >> n; for (i = 1; i <= n; i++) { cin >> x[i] >> y[i]; dist += 2 * sqrt((dx -...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& a) { static char c; static bool b; for (c = getchar(), b = false; !isdigit(c); c = getchar()) if (c == - ) b = true; for (a = 0; isdigit(c); c = getchar()) a = a * 10 + (c - 0 ); if (b) a = -a; } templ...
#include <bits/stdc++.h> using namespace std; const int n = 1e7; int main() { long long a, b, c, ans = 0; cin >> a >> b >> c; long long mx = max(a, max(b, c)); long long sum = (a + b + c) - mx; if (sum * 2 <= mx) cout << sum << endl; else cout << (a + b + c) / 3 << endl; }
#include <bits/stdc++.h> using namespace std; int n, m, cnt[10], sta[10], g[10][10], f[10][10], pru[10], deg[10], tag[10]; char s[10]; int cal(int x) { int res = 0; while (x) { res++; x /= 10; } return res; } int read() { scanf( %s , s); int res = 0; for (int i = 0; s...
#include <bits/stdc++.h> using namespace std; const int MaxN = 2000005; int n, t; long long sum[MaxN]; int nums[MaxN]; int main() { scanf( %d , &n); t = 0; for (int i = 1; i <= n; ++i) { long long ns; scanf( %lld , &ns); int nn = 1; while (t && ns * nums[t] <= sum[t] * nn...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) using namespace std; int q, a, b, c; vector<array<int, 3>> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); for (int a = 1; a <= 10e4; ++a) { for (int b = a; b <= 10e4; b += a) { for (...
#include <bits/stdc++.h> const int N = 3200; using namespace std; int n, l; int a[N][3], b[N][3]; int dp[N][105][3]; void add(int &a, int &b) { a += b; if (a >= 1000000007) a -= 1000000007; } int main() { ios_base::sync_with_stdio(0); cin >> n >> l; for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int MAX = 3e3 + 3; int p[MAX], cycle[MAX], nocycles, n, m; void dfs(int v) { cycle[v] = nocycles; if (cycle[p[v]] == 0) dfs(p[v]); } void gen() { nocycles = 1; memset(cycle, 0, sizeof cycle); for (int i = 1; i < n + 1; i++) if (no...
#include <bits/stdc++.h> using namespace std; const long long fuck = 4e17; long long n, arr[100010]; vector<long long> ans; bool chk(long long x) { vector<int> diffs; for (int i = 0; i + 1 < n; i++) { long long next = arr[i + 1]; if (arr[i] <= x) next = min(arr[i + 1], x); long long ...
#include <bits/stdc++.h> using namespace std; const int SEED = chrono::steady_clock::now().time_since_epoch().count(); mt19937 rng(SEED); const int B = 3000; struct Query { int l, r, t, idx, bl, br; Query(int l, int r, int t, int idx) : l(l), r(r), t(t), idx(idx), bl(l / B), br(r / B) {} b...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1000000001; const long long LINF = 1000000000000000001LL; struct ITree { vector<vector<long long>> T; int p = 1; int par(int x) { return (x - 1) / 2; } ITree(vector<long long> &E) { int n = (int)(E)...
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << ( << p.first << , << p.second << ) ; return out; } template <typename T> ostream& operator<<(ostream& out, vector<T> const& v) { long long l = v.s...
#include <bits/stdc++.h> using namespace std; class trip { public: long long first; long long second; long long third; trip() {} }; bool comp1(trip a, trip b) { if (a.first == b.first) { if (a.second == b.second) { return a.third < b.third; } return a.second < b....