func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000 ) using namespace std; int ri() { int x; scanf( %d , &x); return x; } int cnt[1000100]; int main() { int n, m; scanf( %d %d , &n, &m); long long ans = (long long)n * (long long)(n - 1) * (long long)(n - 2) / 6LL; ...
#include <bits/stdc++.h> using namespace std; long long solve() { long long n, T, a, b; cin >> n >> T >> a >> b; vector<long long> hard(n); long long x; long long hardcount = 0, easycount = 0; for (int i = 0; i < n; ++i) { cin >> x; if (x) { hard[i] = b; ++hardcou...
#include <bits/stdc++.h> using namespace std; template <class T> void read(T& x) { cin >> x; } template <class H, class T> void read(pair<H, T>& x) { read(x.first); read(x.second); } template <class A> void read(vector<A>& v) { for (auto& x : v) read(x); } template <class H, class....
#include <bits/stdc++.h> using namespace std; int A[100010]; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1, n, i, j; cin >> n; int cnt = 0; for (i = 0; i < n; i++) { cin >> A[i...
#include <bits/stdc++.h> using namespace std; int main() { int n, lft, curr = 1; scanf( %d , &n); lft = n; while (lft) { if (lft == 3) break; for (int j = 1; j <= (lft + 1) / 2; j++) { printf( %d , curr); } curr *= 2; lft -= (lft + 1) / 2; } if (lft == ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const long long INF = 1e18; const int MOD = 1e9 + 7; const long long dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const long long Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; long long ...
#include <bits/stdc++.h> using namespace std; int l[105], r[105]; int dp[105][100005]; int temp[100005]; int q[100005][2], cntl, cntr; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 1; i <= k; i++) scanf( %d%d , &l[i], &r[i]); k++; l[k] = r[k] = 2 * n; for (int i = 1; i <...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, idx = 0; cin >> n >> k; pair<int, int> inst[n]; vector<int> v; for (int i = 1; i <= n; i++) { int t; cin >> t; inst[i - 1] = make_pair(t, i); } sort(inst, inst + n); while (k >= inst[idx].first && ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long i, j, n, a[100001], b[100001], c[100001], d[100001]; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; b[i] = c[i] = a[i]; } for (i = 0; i < n -...
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; int cnt[2][10]; int main() { int a, b; cin >> a >> b; while (a % 2 == 0 || a % 3 == 0 || a % 5 == 0) { if (a % 2 == 0) { a /= 2; cnt[0][2]++; } if (a % 3 ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll my_exp(ll a, ll b) { if (b == 0) { return 1; } else { ll temp = my_exp(a, b / 2); temp *= temp; if (b % 2 == 1) { temp *= a; } return te...
#include <bits/stdc++.h> using namespace std; int d[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int a, b, res; int main() { scanf( %d%d , &a, &b); for (int i = a; i <= b; i++) { int t = i; while (t) { res += d[t % 10]; t /= 10; } } printf( %d n , res); return 0; }...
#include <bits/stdc++.h> using namespace std; void read() { freopen( in.txt , r , stdin); freopen( out.txt , w , stdout); } bool voi(char c) { return (c == a || c == e || c == i || c == y || c == o || c == u ); } long long log_pow(long long b, long long p) { if (p == 0) return 1...
#include <bits/stdc++.h> const long long N = 50050; const long long Q = 2e18; const long long mod = 1e9 + 7; const long long MAGIC = 30; using namespace std; int a, b, c, n; void solve() { cin >> a >> b >> c >> n; if (a + b - c >= n || c > a || c > b) { cout << -1 << n ; } else { ...
#include <bits/stdc++.h> using namespace std; vector<long long int> vec; map<long long int, long long int> mp; int main() { long long int x = 0, y = 0, z = 0, sum = 0; cin >> x; for (int i = 0; i < x; i++) { cin >> y; vec.push_back(y); mp[y]++; } sort(vec.begin(), vec.end()...
#include <bits/stdc++.h> using namespace std; int main() { printf( YES nNO nNO nYES nNO nNO nNO nNO nNO nYES nYES nYES nYES nYES nYES nYES nNO nYES nNO nYES nYES nNO nYES nNO nNO nYES nNO nNO nYES nYES nNO nYES nNO nYES nNO nYES nYES nYES nNO nYES nYES nNO nYES nYES nNO nYES nYES ...
#include <bits/stdc++.h> using namespace std; using ll = long long; struct State { int bk; string fr; int pos; int cnt; }; bool operator<(State lhs, State rhs) { if (lhs.bk != rhs.bk) return lhs.bk < rhs.bk; if (lhs.fr != rhs.fr) return lhs.fr < rhs.fr; if (lhs.pos != rhs.pos) retu...
#include <bits/stdc++.h> using namespace std; using lli = long long int; using pii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vlli = vector<long long int>; using vpii = vector<pair<int, int>>; const int N = 200005; const int blockSize = ...
#include <bits/stdc++.h> using namespace std; long long bigmod(long long a, int p, long long int m) { if (p == 0) return 1; if (p & 1) { return ((a % m) * (bigmod(a, p - 1, m))) % m; } else { long long tmp = bigmod(a, p / 2, m); return (tmp * tmp) % m; } } int main() { ios_...
#include <bits/stdc++.h> using namespace std; const double eps = 3e-5; double x, h, l; int main() { scanf( %lf , &x); for (double h = 1; h <= 10 + eps; h++) { if (h + eps < x) continue; l = h / (sqrt((h * h) / (x * x) - 1)) * 2.0; for (double q = 1; q <= 10 + eps; q++) if (l - ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[10], b[10]; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i] == b[...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a < b) return gcd(b, a); else if (b == 0) return a; else return gcd(b, a % b); } long long pow(long long b, long long e) { if (e == 0) return 1; else if (e % 2 == 0) { lo...
#include <bits/stdc++.h> using namespace std; const int MID = 1e5; const int MAX = 1e9; int main() { int n; cin >> n; if (n % 2) { cout << n - 9 << << 9; } else { cout << n - 8 << << 8; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7, M = 2e5 + 7; int n, m, k, t; vector<int> b; struct Node { int in, out; long long h; Node() {} Node(int i, int o, long long _h) : in(i), out(o), h(_h) {} } a[N]; bool operator<(const Node &a, const Node &b) { if (a.out...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n % 3 == 0) { cout << n / 3 * 2; } if (n % 3 > 0) { cout << (n - 1) / 3 * 2 + 1; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; vector<long long> vect; vect.assign(n, 0); long long ans = 0; for (int i = 0; i < n; i++) cin >> vect[i]; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; ans += min(vect[a - 1],...
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { T ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; retu...
#include <bits/stdc++.h> using namespace std; struct node { int u, s; node() { u = s = 0; } bool operator<(const node &temp) const { if (this->s < temp.s) return 1; return 0; } }; node black[100005]; node white[100005]; vector<vector<node> > adj; int main() { int n; sca...
#include <bits/stdc++.h> using namespace std; vector<string> vs, vs2; set<string> st; map<string, int> mp, mp1; long long i, j, k, x, y, m, n, a, b, c, d, e, f, g, h, l, o, p, q, t, u, v, w, z, r, ln, neg, pos, sm, ar[500000 + 5], br[500000 + 5], fr[60], cnt; string s, s1, s2, s3; int main() { w...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 22; const int INF = 1e9 + 2; long long n, ans, mark[MAXN]; char str[MAXN]; int main() { cin >> n; cin >> str; for (int i = 0; i < n; i++) { if (mark[str[i]] == 0) { mark[str[i]] = 1; ans++; } } ...
#include <bits/stdc++.h> using namespace std; using LL = long long; using DD = long double; using pii = pair<int, int>; const LL INFLL = 0x7f7f7f7f7f7f7f7fLL; const int INFint = 0x7f7f7f7f; LL exactMatchingSubranges(vector<int> &cumulative, int match) { LL rr = 0; for (int i = 0; i < int((int((cum...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5, maxm = 4e5 + 5; int head[maxn], nume; struct edge { int v, w, c, next; } e[maxm]; inline void init_edge() { memset(head, -1, sizeof head); nume = 0; } inline void add_edge(int u, int v, int w = 0, int c = 0) { e[nume...
#include <bits/stdc++.h> using namespace std; int main() { int k, n, w, q, cem = 0; cin >> k >> n >> w; for (int i = 1; i <= w; i++) { cem = cem + i * k; } if (n <= cem) { cout << cem - n; } else cout << 0; return 0; }
#include <bits/stdc++.h> using namespace std; int cnt_occur(string s, string t) { int cnt = 0; for (int i = 0; i < s.size(); ++i) { if (s.substr(i, 3) == t) cnt++; } return cnt; } long max(int a, int b) { return a >= b ? a : b; } void swap(int &a, int &b) { int temp = a; a = b; ...
#include <bits/stdc++.h> using namespace std; void RI() {} template <typename... T> void RI(int& head, T&... tail) { scanf( %d , &head); RI(tail...); } void RLL() {} template <typename... T> void RLL(long long& head, T&... tail) { scanf( %lld , &head); RLL(tail...); } void print() { ...
#include <bits/stdc++.h> using namespace std; int K, N, M, Q; map<string, int> Basic, F[111]; string st, Comp_St[60]; vector<pair<string, int> > Comp[60]; int main() { cin >> K >> N >> M >> Q; for (int i = 1; i <= N; i++) { cin >> st; Basic[st] = i; } for (int i = 0, k; i < M; i+...
#include <bits/stdc++.h> using namespace std; struct team { string name; int score; int goals_for; int goals_against; int goal_diff() const { return goals_for - goals_against; } }; bool operator<(const team &A, const team &B) { if (A.score != B.score) return A.score > B.score; if (A....
#include <bits/stdc++.h> using namespace std; int read() { int tot = 0, fh = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) fh = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { tot = tot * 10 + c - 0 ; c = getchar(); } return tot * fh; } ...
#include <bits/stdc++.h> using namespace std; struct BIT { static const int N = 200006; long long a[N]; int n; void init(int _n) { n = _n; memset(a, 0, sizeof(a)); } void update(int pos, long long val) { for (int i = pos; n >= i; i += i & (-i)) { a[i] += val; ...
#include <bits/stdc++.h> using namespace std; struct P { int x, y; }; P me; P other; bool white; int N, M; P operator+(P a, P b) { return {a.x + b.x, a.y + b.y}; } P operator-(P a, P b) { return {a.x - b.x, a.y - b.y}; } bool operator==(P a, P b) { return a.x == b.x && a.y == b.y; } bool isItA...
#include <bits/stdc++.h> using namespace std; char s[200005]; bool vis[200005]; int a[200005]; int n, m; double p; void doit() { memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n; ++i) { scanf( %s , s); if (s[0] != ? ) { a[i] = atoi(s); vis[i] = 1; } } ...
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return (a < b); } int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a < b) return a; return b; } long long power(long long a, int x) { while (x--) { a *= a; } return...
#include <bits/stdc++.h> using namespace std; long long int arr[378999]; long long int arr2[234597]; long long int ab[10]; vector<long long int> adj[22222]; map<long long int, long long int> mp, mp2; map<long long int, long long int>::iterator it; vector<long long int> vec; string s; long long int g...
#include <bits/stdc++.h> using namespace std; int a[1505]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); int ans = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= i - 1; j++) if (a[j] > a[i]) ans ^= 1; int q; scanf( %d , &q); ...
#include <bits/stdc++.h> using namespace std; int n; string str; int main() { cin >> str; n = str.length(); string str1 = str + str; reverse(str.begin(), str.end()); string str2 = str + str; int ans = 0; int dp[2][2 * n]; for (int i = 0; i < 2 * n - 1; i++) { dp[0][i] = 1; ...
#include <bits/stdc++.h> using namespace std; int n; int a[1111111]; bool curr_state[22]; long long sum_inversions[22]; long long sum_non_inversions[22]; int tmp_array1[1111111]; int tmp_array2[1111111]; int binary_search(int i, int sz) { if (tmp_array2[0] >= tmp_array1[i]) return -1; int low ...
#include <bits/stdc++.h> using namespace std; vector<int> t; int rec(int k, int sz, int n = 0) { if (t[n] <= k) return k - t[n]; if (n >= sz && t[n]) return n; int a = rec(k, sz, 2 * n + 1); if (a >= sz) return a; else return rec(a, sz, 2 * n + 2); } int main() { ios::sync_...
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long nega = 1; while (!isdigit(ch)) { if (ch == - ) nega = -1; ch = getchar(); } long long ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); }...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool uin(T& a, T b) { return a > b ? (a = b, true) : false; } template <class T> inline bool uax(T& a, T b) { return a < b ? (a = b, true) : false; } const int nax = 2e5 + 10; vector<int> offer[nax]; int K[nax]; int N,...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; struct modint { int n; modint() : n(0) {} modint(int n) : n(n) {} }; modint operator+(modint a, modint b) { return modint((a.n += b.n) >= mod ? a.n - mod : a.n); } modint operator*(modint a, modint b) { return modint(1L...
#include <bits/stdc++.h> using namespace std; int main() { int a, ta; cin >> a >> ta; int b, tb, h = 0, m = 0, num = 0; int totmin; cin >> b >> tb; string s; cin >> s; for (int i = 0; i < 2; i++) { h = h * 10 + (s[i] - 0 ); } for (int i = 3; i < 5; i++) { m = m *...
#include <bits/stdc++.h> using namespace std; const long long MOD = (1ll << 32); const int LOGN = 14; const long long INF = (1ll << 62); long long __gcd(long long a, long long b) { if (b == 0) return a; return __gcd(b, a % b); } bool comp(pair<int, unordered_set<int> >& a, pair<int, un...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); string s1, s2; cin >> s1 >> s2; int temp; vector<int> index; for (int i = 0; i < t; i++) { temp = -1; if (s1[i] == s2[i]) { continue; } for (int j = i + 1; j < t; j++) { ...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr ...
#include <bits/stdc++.h> using namespace std; template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } void solve() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 100; const int MX = 200503; int N, M, k; int arr[MX]; int cnt[MX]; vector<int> G[MX]; int vis[MX]; vector<int> sr; void dfs(int x) { vis[x] = 1; for (int i = 0; i < G[x].size(); i++) { int ch = G[x][i]; if ...
#include <bits/stdc++.h> using namespace std; long long nChooseR(int n, int k); long long gcd(long long a, long long b); vector<string> split(string target, char c); bool isPrime(long long g); long long n, k, r, l, t, x, y, m, a[100003]; long long ans; int main() { string s; cin >> s; revers...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> v; vector<vector<int>> g; int in[N], out[N], col[N], is[N], dp[18][N], depth[N], z; struct node { int l, r, id; node(int a = 0, int b = 0, int c = 0) { l = a; r = b; id = c; } bool operator<(co...
#include <bits/stdc++.h> using namespace std; int n, ls, tp, cx, yy, qq; char s[64]; string ans, cur, st[55555][2], tt; bool quot, found; int main() { scanf( %d n , &n); tp = -1; found = false; qq = 0; for (int _ = 0; _ < n; ++_) { gets(s); ls = strlen(s); quot = false;...
#include <bits/stdc++.h> using namespace std; const int maxL = 70; int mod = 1e9 + 7; long long mod1 = 1e9 + 7; const int inf = 1.2e18; const int maxn = 6e5 + 100; const int baze = 330; const int base = 3; int from[maxn]; int to[maxn]; int w[maxn]; int dis[maxn]; int head[maxn]; int sdfgf[ma...
#include <bits/stdc++.h> using namespace std; long long mod1(long long x) { if (x >= 0) { return x; } return -x; } vector<long long> countDigit(long long n) { vector<long long> ret; while (n != 0) { ret.push_back(n % 10); n = n / 10; } return ret; } long long gc...
#include <bits/stdc++.h> using namespace std; long long power(long long base, long long pow, long long mo) { long long res = 1; while (pow) { if (pow % 2 != 0) res = (res * base) % mo; base = (base * base) % mo; pow /= 2; } return res; } long long inv(long long i) { return powe...
#include <bits/stdc++.h> using namespace std; const int inf = 100010; const int N = 100010; struct e { int v; e *nxt; } es[N << 1], *fir[N]; map<pair<int, int>, int> mp; struct node { int ls, rs; int l, r; int sum; int mid() { return (l + r) >> 1; } } nodes[N << 2]; int n, en, ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n; cin >> n; bitset<6> a(n); string s = a.to_string(); swap(s[1], s[5]); swap(s[2], s[3]); bitset<6> b(s); cout << static_cast<int>(b.to_ulo...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; int main() { int n; scanf( %d , &n); printf( %d , n); for (int i = 1; i < n; i++) printf( %d , i); return 0; }
#include <bits/stdc++.h> const int N = 105; int n, m; char a[N][N]; struct Node { int ax, ay, bx, by, cx, cy; }; void work(int i, int j, int mask) { for (int x = 0; x < 2; ++x) { for (int y = 0; y < 2; ++y) { if (mask >> (x << 1 | y) & 1) { a[i][j] ^= 1, a[i][j + 1] ^= 1, a[i...
#include <bits/stdc++.h> using namespace std; int ans[51][6] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 4, 3, 0, 0, 0, 0, 5, 3, 0, 0, 0, 0, 6, 5, 0, 0, 0, 0, 7, 6, 0, 0, 0, 0, 8, 6, 5, 4, 0, 0, 9, 5, 0, 0, 0, 0, 10, 7, ...
#include <bits/stdc++.h> using namespace std; int main() { int tux; cin >> tux; int foo, bar, baz, quz, pur, oo; foo = bar = baz = 0; quz = 1; while (tux) { cin >> pur; foo += pur; bar++; if (foo * quz > bar * baz) { baz = foo; quz = bar; } ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vii; typedef vector<vi> vvi; typedef vector<pll> vll; typedef vector<vl> vvl; ...
#include <bits/stdc++.h> using namespace std; int n, m, sz, timer; int p[1000005]; vector<int> v[1000005]; int tin[1000005], tout[1000005]; int t[4000005], tt[4000005]; int depth[1000005]; int a[1000005]; pair<int, int> q[1000005]; bool used[1000005]; void dfs(int x, int y = 0) { used[x] = tru...
#include <bits/stdc++.h> int sta[1000001], head, ans[1000001]; char s[1000001]; int main() { int ans1 = 0, ans2 = 1; scanf( %s , s); for (int i = 0; s[i]; ++i) { if (s[i] == ) ) { if (!head) continue; head--; ans[i] = i - sta[head] + 1 + ans[sta[head] - 1]; if (a...
#include <bits/stdc++.h> using namespace std; int t, n; int a[200004]; int main() { cin >> t; while (t--) { cin >> n; for (int i = 0; i < 2 * n; i++) cin >> a[i]; sort(a, a + 2 * n); cout << a[n] - a[n - 1] << n ; } cin >> t; return 0; }
#include <bits/stdc++.h> using namespace std; int T, n, a[30005], b[30005]; long long sum[2]; int main() { scanf( %d , &T); while (T--) { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); a[n + 1] = 0; for (int i = 1; i <= n + 1; i++) b[i] = a[i] - a[i - 1]; ...
#include <bits/stdc++.h> using namespace std; bool g[205][205]; struct coor { int x, y; }; vector<int> ans; int a[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1}; coor Max, Min; int w, h; void dfs(int x, int y) { g[x][y] = 1; for (int i = 0; i < 8; i++) { coor c; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000000, M = 1000000007, D3 = (M + 1) / 3; int T, n, m; int pd[N + 5], pr[N], pn, phi[N + 5]; int f[N + 5], s0[N + 5], s1[N + 5], s2[N + 5]; void init() { phi[1] = 1; for (int i = 2; i <= N; i++) { if (!pd[i]) phi[i] = i - 1, pr[++pn]...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, m; vector<int> tr[1000005]; vector<int> vr[1000005]; pair<int, int> pr[1000005]; int high; long long team[1000005], ir[1000005]; int main() { scanf( %d %d , &n, &m); int x,...
#include <bits/stdc++.h> using namespace std; int a[200001]; int b[200000]; int c[200001]; int main() { int n, i, j; cin >> n; map<int, int> m; for (i = 0; i < n; i++) { cin >> b[i]; m[b[i]]++; a[b[i]] = 1; } vector<int> v; for (i = 1; i <= n; i++) { if (a[i...
#include <bits/stdc++.h> using namespace std; class segtree { public: int val[(1 << 20) * 2]; int le[(1 << 20) * 2]; int ri[(1 << 20) * 2]; void update(int pos, int x) { val[pos + (1 << 20) - 1] = 0; le[pos + (1 << 20) - 1] = 1 - x; ri[pos + (1 << 20) - 1] = x; } void up...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; if ((a + b) % 2 == 0) { cout << Tidak Tidak ; if (b || c) cout << Ya ; else cout << Tidak ; if (a ...
#include <bits/stdc++.h> using namespace std; const int M = 1e6 + 10; int n, ans; void swap(int &x, int &y) { int t = x; x = y; y = t; } int main() { cin >> n; vector<char> x(n), y(n); for (auto &i : x) cin >> i; for (auto &i : y) cin >> i; for (int i = 0; i < n - 1; ++i) { ...
#include <bits/stdc++.h> using namespace std; int const N = 202000; set<int> s; set<int>::iterator it; int edg[N]; vector<int> g[N]; int ans[N]; int cur = 1; int vis[N]; void dfs(int node) { vis[node] = 1; ans[cur]++; vector<int> send; for (it = s.begin(); it != s.end();) { if ...
#include <bits/stdc++.h> int main() { int n, x, m, count; scanf( %d %d , &n, &m); for (x = 1, count = 0; x <= n; x++) { if (m % x == 0 && (m / x) <= n) { count = count + 1; } } printf( %d , count); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int ans = 0; sort(a.begin(), a.e...
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); long long i, t, n, com, midc; cin >> n; map<int, int> m; set<int> s; vector<int> x(n); vector<int> a(3); for (i = 0; i < n; i++) { cin >> x[i]; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long int INF = 1e12; int n, k; int memo[101][101][101]; int solve(string &str, int i, int N, int _max) { _max = max(N, _max); int &a = memo[i][N][_max]; if (a != -1) return a; if (i == n) return a = (_max == k)...
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; int INF = 1000000000; long long INFF = 8000000000000000000LL; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; inline string IntToString(int a) { char x[100]; sprintf(x, %...
#include <bits/stdc++.h> using namespace std; void solve(int x, int y, int n) { vector<int> ans(n + 1); ans[x] = 1; ans[y] = 2; for (int i = 1, j = 3; i <= n; i++) { if (ans[i] == 0) { ans[i] = j++; } } for (int i = 1; i <= n; i++) { cout << ans[i] << ; } ...
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp, vis; vector<long double> vv; vector<pair<long long, long long> > vp; string s, q; char c; int main() { long double t = 0, n, m, l, r, mn = 0, mx = 0, ans = 0, nm = 0, cnt = 0, x, y, z, d, v, g; cin >> l >> ...
#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; } int main() { long long int t, a, b...
#include <bits/stdc++.h> using namespace std; int main() { int a[26][26] = {0}, n, mini = -1; cin >> n; while (n--) { char c[11]; scanf( %s , c); int k = strlen(c), i = c[0] - a , j = c[k - 1] - a ; for (int m = 0; m < 26; m++) if (a[m][i]) a[m][j] = max(a[m][j], a[m][i...
#include <bits/stdc++.h> using namespace std; const int maxn = 500; int dist[maxn][maxn]; long long ans; void modify(int u, int v, int w) { if (dist[u][v] > w) { ans -= (dist[v][u] - w); dist[u][v] = w; } return; } int main() { int n; cin >> n; for (int i = 1; i <= n; i...
#include <bits/stdc++.h> using namespace std; const int N = 1000; const int inf = (int)1e9 + 1; const long long big = (long long)1e18 + 1; const int P = 239; const int MOD = (int)1e9 + 7; const int MOD1 = (int)1e9 + 9; const double eps = 1e-9; const double pi = atan2(0, -1); const int ABC = 26; in...
#include <bits/stdc++.h> inline int Get() { char ch; while ((ch = getchar()) < 0 || ch > 9 ) ; int Num = ch - 0 ; while ((ch = getchar()) >= 0 && ch <= 9 ) Num = (Num << 3) + (Num << 1) + ch - 0 ; return Num; } const int N = 1e5 + 5; int n, m, a[N], count[N << 2], sum[N <...
#include <bits/stdc++.h> using namespace std; void upd(int& a, int b) { a = max(a, b); } int main() { int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < (int)n; ++i) cin >> a[i]; for (int i = 0; i < (int)m; ++i) cin >> b[i]; sort(a.begin(), a.end()); sort(b.begin(), b...
#include <bits/stdc++.h> using namespace std; long long calc2(long long a, long long b, long long c, long long ab, long long ac, long long bc, long long abc) { long long parts[] = {a - ab - ac + abc, b - ab - bc + abc, c - ac - bc + abc, ...
#include <bits/stdc++.h> using namespace std; map<string, int> my; int n, m; string var[5006]; string bit[5006]; int op[5006][2]; int opera[5006]; int ans[5005][1003]; int print1[1005], print2[1005]; int main() { scanf( %d , &n); scanf( %d , &m); for (int i = 1; i <= n; i++) { stri...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long power(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) ans *= a; a = a * a; b >>= 1; } return ans; } long long powm(long long a, long long b) { a %= MOD; long lon...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,avx,avx2 ) const long long maxn = 64, mod = 1e9 + 7, INF = 1e9, lg = 15 + 1, SQRT = 400; int n, a[maxn], par[maxn], SZ_T[maxn], FAC[maxn], INV[maxn]; vector<int> adj1[maxn], adj2[maxn], c...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, s = 0, c = 0; cin >> n; for (long long int i = 0; i < n; i++) { long long x; cin >> x; s += x; if (x % 2 != 0) c = 1; } if ...
#include <bits/stdc++.h> using namespace std; int main() { int n, d, moves = 0; int* b; cin >> n >> d; b = new int[n]; cin >> b[0]; for (int i = 1; i < n; i++) { cin >> b[i]; if (b[i] <= b[i - 1]) { int time = (b[i - 1] - b[i]) / d + 1; b[i] += time * d; m...