func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int Maxn = 3e5 + 10; const int lim = 1000; int prime[Maxn], M[Maxn], H[Maxn], cnt; bool vis[Maxn]; struct node { int v, c, l; } a[Maxn]; int cmp(node A, node B) { return A.l < B.l; } int n, k; int main() { int cnt = 0; vis[0] = vis[1] =...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; struct TreeNode { int L, R; pair<double, double> val; } tree[maxn << 2]; int a[maxn], b[maxn], n, q; void pushUp(int root) { tree[root].val.first = tree[root << 1].val.first * tree[root << 1 | 1].val.first; t...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, minn = 1000; long long res = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d%d , &a, &b); minn = min(minn, b); res += minn * a; } printf( %d , res); return 0; }
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; bool mysort(pair<long long, long long> A, pair<long long, long long> B) { return A.second > B.second; } long long moduloMultiplication(long long a, long long b, long long mod) { long long res = 0; a %= mod; while (b) { ...
#include <bits/stdc++.h> using namespace std; int main() { int k, a, b, v, nr = 0; cin >> k >> a >> b >> v; while (a > 0) { ++nr; if (b + 1 >= k) { b = b + 1 - k; a = a - k * v; } else { a = a - (b + 1) * v; b = 0; } } cout << nr; retur...
#include <bits/stdc++.h> using namespace std; int m; char s[15]; int ans[1005]; bool num[15]; bool dfs(int suml, int sumr, int cot, int pre) { if (cot == m + 1) return true; if (cot & 1) { for (int i = 1; i <= 10; i++) if (num[i] && i != pre && suml + i > sumr) { ans[cot] = i...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; inline int qpow(int a, int p) { int ans = 1; while (p) { if (p & 1) ans = (long long)ans * a % MOD; a = (long long)a * a % MOD; p >>= 1; } return ans; } inline int add(const int& x, const int& y) { r...
#include <bits/stdc++.h> using namespace std; char s[600010]; int a[600010]; int main() { int n; cin >> n >> s + 1; for (int i = n + 1; i < 2 * n; i++) s[i] = s[i - n]; for (int i = 1; i < 2 * n; i++) { a[i] = a[i - 1] + (s[i] == ( ? 1 : -1); } if (a[n] != 0) { cout << 0 <<...
#include <bits/stdc++.h> using namespace std; inline const char nl = n ; inline const long long MOD = 1000000007; inline const long double pi = 3.141592653589793238; struct query { int a, b; } q[105]; bool vis[105]; int n, cnt; void dfs(int x) { vis[x] = 1; for (int i = 1; i <= cnt; i++)...
#include <bits/stdc++.h> using namespace std; ifstream inp( inp.txt ); ofstream out( out.txt ); const int N = 1e5 + 5; const long long B = 73; int builtin_popcount(int &mask) { int kol = 0; for (int bit = 0; bit < 20; bit++) kol += int(bool(mask & (1 << bit))); return kol; } signed main() { ...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_str...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > allModify; class Polygon { private: int n; vector<int> label; vector<set<int> > adj; void splitPolygon(Polygon &a, Polygon &b, int x, int y) const { if (x > y) return (splitPolygon(a, b, y, x)); for (int i = (x), ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500 + 10; const int pN = 1e6; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; void add(long long &x, long long y) { x += y; x %= MOD; } int u, v, n, m; void Solve(int x, int y, int z) { int row = n, cul = m; int nx, ny...
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } long long int Ceil(long long int a, long long int b) { if (a % b == 0) return a / b; els...
#include <bits/stdc++.h> using namespace std; long n, m, a, b, ar[200][200], ans; long arp[10000], fl, l; void dfs(long v, long par) { arp[v] = 1; l++; for (int i = 1; i <= n; i++) if (ar[v][i] == 1) { if (i == par) continue; if (arp[i] == 1) { fl = 1; retur...
#include <bits/stdc++.h> using namespace std; int S[2][500005 * 4], pre[500005], suf[500005]; long long hpr1[3][500005], hpr2[3][500005], hsf1[3][500005], hsf2[3][500005], pww[3][500005]; int n, m, k; long long pr[3] = {79, 103, 211}; bool flag; char a[500005], b[500005]; vector<int> sss[500005], ...
#include <bits/stdc++.h> int read() { int r = 0, t = 1, c = getchar(); while (c < 0 || c > 9 ) { t = c == - ? -1 : 1; c = getchar(); } while (c >= 0 && c <= 9 ) { r = (r << 3) + (r << 1) + (c ^ 48); c = getchar(); } return r * t; } const int N = 200010; in...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<pair<long long, char> > v; vector<long long> freq(27, 0); string s2(s.length(), 1 ); vector<long long> vis(s.length() + 1, 0); for (long long i = 0; i < s.length(); i++) { freq[s[i] - a ]++; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 405; int a[MAXN], v[MAXN]; int n; void work(int x) { memset(v, 0, sizeof(v)); for (int i = 1; x != 0; i++) { v[i] = x / a[i]; x %= a[i]; } } int work2(int x) { int res = 0; for (int i = 1; x != 0; i++) { r...
#include <bits/stdc++.h> using namespace std; typedef int arr32[5000010]; arr32 x, rk, l, r; int n; long long ans; bool cmp(const int &a, const int &b) { return x[a] < x[b]; } void erase(int x) { r[l[x]] = r[x], l[r[x]] = l[x]; } int main() { cin >> n; for (int i = 1; i <= n; ++i) { scanf(...
#include <bits/stdc++.h> int main() { int ss, x, y, flag = 0, kk, flag2 = 1; scanf( %d%d%d , &ss, &x, &y); if (x == 1 || x == ss) flag++; if (y == 1 || y == ss) flag++; if (x >= ss / 2 && x <= ss / 2 + 1 && y >= ss / 2 && y <= ss / 2 + 1) flag2 = 0; if (flag == 0) kk = 9; if (flag ==...
#include <bits/stdc++.h> using namespace std; long long ans, n, k, a, b; int main() { scanf( %I64d %I64d , &n, &k); scanf( %I64d %I64d , &a, &b); long long t = n - 1; t *= a; if (k == 1) { printf( %I64d , t); return 0; } while (n > 1) { if (n % k == 0) ans +=...
#include <bits/stdc++.h> using namespace std; const int N = 60 + 5; char a[N][N]; int l[N][N]; int r[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int m, n; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> (a[i] + 1); in...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 2; unsigned long long h[N]; int p[N]; bool ed[N], flg[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count()); unordered_map<unsigned long long, int> mp; ...
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long a, b; cin >> a >> b; while (a != 0 && b != 0) { if (a >= 2 * b) { a = a % (2 * b); } else if (b >= 2 * a) { b = b % (a * 2); } else break; } cout << a << << b << endl; ...
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433; const int mod = 1000000007; const long long inf = 3e18; long long n, m, k; long long dp[5001][5001]; vector<long long> v; long long mkc(long long i, long long j) { if (j == 0 or i >= v.size()) { r...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long x, y, n; cin >> x >> y >> n; long long rem = n % x; long long ans = n -...
#include <bits/stdc++.h> using namespace std; template <typename T0, typename T1> bool chkmin(T0 &a, const T1 &b) { return a > b ? a = b, 1 : 0; } template <typename T0, typename T1> bool chkmax(T0 &a, const T1 &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f, Max_val = 314000000; ...
#include <bits/stdc++.h> int INF = 2147483647; double INFD = 2147483647; double PI = 3.14159265359; using namespace std; struct Child { Child(long long v_, long long d_, long long p_) { gone = false; v = v_; d = d_; p = p_; } bool gone; long long v; long long d; ...
#include <bits/stdc++.h> using namespace std; const int N = 55; int res[N][N][N][N]; int tmp[N][N], dat[N][N]; string s[N]; int n, m, q, a, b, c, d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; for (int i = 1; i <= n; i++) { cin >> s[i];...
#include <bits/stdc++.h> using namespace std; long long t, n, k, a[200005]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n >> k; for (long long i = 0; i < n; i++) cin >> a[i]; long long Min = k; for (long long i ...
#include <bits/stdc++.h> using namespace std; long long ax, ay, bx, by, cx, cy; void check(long long xx, long long yy) { if (cx == 0 && cy == 0) { if (xx == 0 && yy == 0) { cout << YES ; exit(0); } else return; } if ((cx * (yy)-cy * (xx)) % (cx * cx + cy * cy) != 0...
#include <bits/stdc++.h> using namespace std; const int N = 356438; int from[N], to[N], limL, nextp[N], headp[N], p[N], Lcnt[N], chcnt[N], num, a[N], b[N], sz, c[N]; bool taboo[N], boo[N]; long long limW, W[N], Wcnt[N], ans; inline int lowbit(int x) { return x & (-x); } inline int ask(int x) { i...
#include <bits/stdc++.h> using namespace std; const int K = 7; const int N = 2005; int a[K][N]; vector<int> s[N]; int d[N], n, k, p; void read() { cin >> n >> k; for (int i = 0; i < int(k); ++i) { for (int j = 0; j < int(n); ++j) { cin >> p; --p; if (i == 0) ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long ans = 0; for (int i = ...
#include <bits/stdc++.h> using namespace std; using point = pair<int, int>; int D(point a, point b, point c) { return a.first * (b.second - c.second) - a.second * (b.first - c.first) + (b.first * c.second - b.second * c.first); } int main() { int n, d; cin >> n >> d; vector<point> p...
#include <bits/stdc++.h> using namespace std; vector<long long> prevSmall(vector<long long> &a, long long n) { vector<long long> res(n, -1); for (long long i = 1; i < n; ++i) { long long j = i - 1; while (j >= 0 && a[j] >= a[i]) j = res[j]; res[i] = j; } return res; } vector<lo...
#include <bits/stdc++.h> using namespace std; int arr[int(1e7 + 100)]; void aum(int i) { if (i % 2) { arr[i / 2 + 1] += arr[i]; arr[i / 2] += arr[i]; } else arr[i / 2] += 2 * arr[i]; } int main() { ios_base::sync_with_stdio(0); set<int> conj; memset(arr, 0, sizeof arr); ...
#include <bits/stdc++.h> using namespace std; int n, k; int value, ans; int bads[200010], maxDelay[200010], extraDelay[200010], a[200010], v[200010]; vector<int> T[200010], val[200010], pre[200010], post[200010]; void dfs(int x, int f) { bads[x] = 0; maxDelay[x] = 0; extraDelay[x] = 0; for (...
#include <bits/stdc++.h> using namespace std; bool dbg = 0; void bad(string mes = Impossible ) { cout << mes; exit(0); } template <typename T> string bin(T x, int st = 2) { string ans = ; while (x > 0) { ans += char( 0 + x % st); x /= st; } reverse(ans.begin(), ans.en...
#include <bits/stdc++.h> using namespace std; const double _PI = 3.141592653589793; double n, m, k, ans = 0; signed main() { scanf( %lf %lf %lf , &n, &m, &k); ans += ((n * n * sqrt(3)) / 4) * (sqrt(n * n * 2 / 3)) / 3; ans += (m * m) / 3 * (sqrt(m * m / 2)); double S = (k * k * 5) / (4 * tan(_PI...
#include <bits/stdc++.h> using namespace std; int main() { long long b, d, s, mx, sm = 0; cin >> b >> d >> s; mx = max(b, max(s, d)); if (mx != b) b++; if (mx != d) d++; if (mx != s) s++; sm += mx - b; sm += mx - d; sm += mx - s; cout << sm << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, h, x[2010], fall[2][2010]; double p, dp[2010][2010][2][2]; double solve(int l, int r, int fl, int fr) { if (l > r) return 0; if (dp[l][r][fl][fr] != -1) return dp[l][r][fl][fr]; dp[l][r][fl][fr] = 0; double res = 0; int nl = min(r, l + fal...
#include <bits/stdc++.h> const int MAX_N = 300000; const int MAX_M = 300000; std::vector<int> types[1 + MAX_N]; std::vector<int> neighbours[1 + MAX_N]; int c; int colours[1 + MAX_M]; bool used[1 + MAX_M]; void dfs(int u = 1, int father = 0) { for (int type : types[u]) if (colours[type] != 0) u...
#include <bits/stdc++.h> using namespace std; const long long MAXN = (long int)3e5 + 5; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; y = y >> 1; x = (x * x) % 1000000007; } return res; } long long gcd(...
#include <bits/stdc++.h> using namespace std; int ni() { int a; scanf( %d , &a); return a; } double nf() { double a; scanf( %lf , &a); return a; } char sbuf[100005]; string ns() { scanf( %s , sbuf); return sbuf; } long long nll() { long long a; scanf( %lld , &a)...
#include <bits/stdc++.h> using namespace std; const int n = 10, dir[4][2] = {{1, 0}, {0, 1}, {1, -1}, {1, 1}}; int main() { char b[n][n]; for (int i = 0; i < 10; i++) for (int j = 0; j < n; j++) scanf( %c , &b[i][j]); bool found = false; for (int i = 0; !found && i < n; i++) for (int ...
#include <bits/stdc++.h> using namespace std; const int MAX_ROW = 2000 + 7; const int MAX_COLUMN = 200 + 7; const int BASE = 2807; const int MOD = 1e7 + 7; int n, m; char TableA[MAX_ROW][MAX_COLUMN], TableB[MAX_COLUMN][MAX_ROW]; int HashA[MAX_ROW][MAX_COLUMN], HashB[MAX_COLUMN][MAX_ROW], Pow2807[MAX_ROW...
#include <bits/stdc++.h> using namespace std; int main() { long long aa[15]; long long bb[15]; for (int i = 0; i < 14; i++) { scanf( %lld , &aa[i]); bb[i] = aa[i]; } long long maxx = 0; for (int i = 0; i < 14; i++) { if (!aa[i]) continue; long long sum = 0; int ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimization( unroll-loops ) const int N = 1e5 + 5; const long long int mod = 1e9 + 7; const long long int Mod = 998244353; const long double Pi = acos(-1); const long long int Inf = 4e18; using namespace std; int n, m; vector<pair<i...
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); vector<long long int> v; long long int n, i; cin >> n; if (n == 1) { cout << 1; return 0; } for (long long int i = 1; i * i <= n; ++i) { if (n % i == 0) { if (i * i...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; long long qpow(long long a, long long b) { long long res = 1; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } struct graph { int head[maxn], ...
#pragma GCC target ( avx2 ) #pragma GCC optimize ( O3 ) #pragma GCC optimize ( unroll-loops ) #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef priority_queue<pl, vector<pl>, greater<pl> > pq; ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int mod = 1000000007; const int inf = 2012345678; const long long infl = 9012345678901234567; const double pi = 3.1415926535897932384626433832795; const int N = 20; const int M = 100010; char buf[M]; int a[M]; int ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; char cur = s[0]; int count = 1; for (int i = 1; i < s.length(); i++) { if (cur == s[i]) { count++; if (count == 7) { cout << YES << endl; return 0; } } else { ...
#include <bits/stdc++.h> using namespace std; const long long int M = 1e9 + 7; const long long int N = 2e5 + 5; const long long int inf = 2e18; long long int mod(long long int x) { return (x % M); } long long int mod_minus(long long int a, long long int b) { long long int ans = (mod(a) - mod(b)); if...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; string words[100005]; int type[100005]; int gender[100005]; void reverse(string &c) { for (int i = (0); i < (int((c).size()) / 2); i++) { char tmp = c[i]; c[i] = c[int((c).size()) - i - 1]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; int a1[maxn], a2[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n >> k; long long ans = (n + 1) * n / 2; for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; long long total = 0; struct c { int can; int tru; }; int main() { double a, b, c; scanf( %lf%lf%lf , &a, &b, &c); printf( %.100f n , a * (b) / (b + c)); }
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( avx2 ) #pragma GCC optimize( Os ) using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string str; long long i, j, k, x = 0, y = 0, n, m, t, sum ...
#include <bits/stdc++.h> using namespace std; struct node { int x, i; } a[100020], b[100020], c[100020]; bool f(node a, node b) { return a.x < b.x; } bool g(node a, node b) { return a.i < b.i; } int main() { int i, n, j; cin >> n; cout << YES n ; for (i = 1; i <= n; i++) { cin >> ...
#include <bits/stdc++.h> using namespace std; vector<long long> g[1100]; map<long long, bool> visited; long long a, b; map<long long, long long> parent; void dfs(long long v) { visited[v] = 1; if (v > 1e9 || v == b) { return; } if (!visited[2 * v]) { parent[2 * v] = v; dfs(...
#include <bits/stdc++.h> using namespace std; unsigned long long X, Y, sum, exor, l, m; int main() { cin >> sum >> exor; if (sum < exor || sum % 2 != exor % 2) { cout << -1 << endl; return 0; } X = (sum - exor) / 2; Y = sum - X; cout << X << endl << Y << endl; }
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> ans; int row[5], col[20]; vector<int> v[3]; bool vis[20][11][11][11][11][11][1 << 5]; bool solve(int x, int r1, int r2, int r3, int r4, int r5, int mask) { if (x == m) { if (r1 + r2 + r3 + r4 + r5) return false; return tru...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const unsigned long long base = 2333; const int maxn = 1e2 + 55; const int maxm = 1e4 + 50; const int maxv = 1e6 + 5; const int mod = 51123987; long long Cal(string s, long long p) { long long len = s.size(); long long sum...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m, x, y; cin >> n >> m >> x >> y; char a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } int county = 0, c...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[110]; int n, k; vector<int> ans; void solve() { cin >> n >> k; for (int i = (1); i <= (n); ++i) { int x; cin >> x; a[i].first = x; a[i].second = i; } sort(a + 1, a + 1 + n); int s = 0; for (int i = 1...
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000 + 9; const long long MOD = 1000 * 1000 * 1000 + 7; const double EPS = 1e-9; const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int N = 505; int n, k; int a[N][N]; int b[N][N]; int s[N][N]; int q; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using i3 = pair<int, ii>; using li = pair<ll, int>; using lii = pair<ll, ii>; using vi = vector<int>; using vl = vector<ll>; using vli = vector<li>; using vii = vector<ii>; using vi3 = vector<i3>; usin...
#include <bits/stdc++.h> using namespace std; void seive(bool a[], long long int n) { for (int i = 2; i * i <= n; i++) { if (a[i] == true) { for (int j = i * i; j <= n; j += i) a[j] = false; } } } int np(bool a[], long long int ppr, long long int n) { ppr++; while (ppr <= n) ...
#include <bits/stdc++.h> using namespace std; int n, z, p, i, j, k, ans, t, a[105], b[105], d[105], f[105][10005]; bool cmp(int x, int y) { return x > y; } int main() { scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]), z += a[i]; for (i = 1; i <= n; i++) scanf( %d , &b[i]), d[i] = b[i]; ...
#include <bits/stdc++.h> using namespace std; int m[100002]; int main() { memset(m, 255, sizeof m); int runs; scanf( %d , &runs); for (int j = 0; j < runs; j++) { int x, y, ret = 0; scanf( %d%d , &x, &y); for (int i = 1; i * i <= x; i++) if (x % i == 0) { if (m[...
#include <bits/stdc++.h> using namespace std; const int N_MAX = 1e5; bool in[N_MAX + 1]; int t, n, a[N_MAX], m[N_MAX], pr[N_MAX + 1]; vector<int> inc; vector<vector<int>> sol; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> t; while (t--) { cin >> n; for (int ...
#include <bits/stdc++.h> using namespace std; long long n, m, i1; long long cont = 0; int main() { cin >> n; for (long long i = 0; i < n; ++i) { long long x, y; cin >> x >> y; if (x - y != 1) { cout << NO << endl; } else { long long p = x + y, s = 0; for...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> bool Max(T1& a, T2 b) { return a < b ? a = b, 1 : 0; } template <typename T1, typename T2> bool Min(T1& a, T2 b) { return a > b ? a = b, 1 : 0; } const int N = 200002, inf = 1e9 + 1; int s[N], g[N], ans[N]; boo...
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; const int N = 1000005; long long frac[N + 5], inv[N + 5]; int n, a[N], y[N], Max; long long ans; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; c...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; template <typename T> using v = vector<T>; const long long mod1 = 1e9 + 7; const long long mod2 = 36028797018963913; const long long inf = 2e18; void read() {} void print() {} void debug() { cerr << endl; } long long gcd(l...
#include <bits/stdc++.h> using namespace std; int blacks(int *pos, int n); int whites(int *pos, int n); int main() { int n; cin >> n; int board[100]; for (int i = 0; i < n; i++) { board[i] = 0; } for (int i = 0; i < n / 2; i++) { int temp; cin >> temp; board[temp ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int i, n, f = 0; cin >> n; vector<int> v(n); vector<int> use(n + 1, 0); for (i = 0; i < n; i++) { cin >> v[i]; if (v[i] < (i + 1)) { f = 1; } } ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double PI = acos(-1), eps = 1e-6; const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}; const int N = 1e6 + 5, M = 2e6 + 5, mod = 1e9 + 7; int n; int p[N], c[N]; int main() { ios::sync_with_stdio(false); cin.tie(0)...
#include <bits/stdc++.h> using namespace std; constexpr int maxn = 2e5 + 100; int n, val[maxn]; void solve() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , val + i); set<int> s; for (int i = 0; i < n; i++) s.insert((((i + val[i]) % n) + n) % n); puts((s.size() == n) ? YES : NO...
#include <bits/stdc++.h> using namespace std; struct Timer { chrono::time_point<chrono::high_resolution_clock> start, end; chrono::duration<float> dur; Timer() { start = chrono::high_resolution_clock::now(); } ~Timer() { end = chrono::high_resolution_clock::now(); dur = end - start; ...
#include <bits/stdc++.h> using namespace std; int cnt[2][2]; string s; int main() { ios_base::sync_with_stdio(0); cin >> s; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { cnt[i][j] = 0; } } for (int i = 0; i < s.length(); i++) { cnt[i & 1][s[i] - a ]++...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const double pi = 3.14159265358979323846; const long long mxN = 2e5 + 2; void _print(long long t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(double t) { cerr << t; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1024; int size[MAXN], in[MAXN], deg[MAXN]; bitset<MAXN> a[MAXN], c; vector<pair<int, int> > edges; set<pair<int, int> > was; int main() { int n; scanf( %d , &n); bool star = 1; for (int i = 0; (i) < (n); ++i) { scanf( %d ...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double PI = acos(-1); const long long mod = 1e9 + 7; const long long OO = 2e18; const int N = 3e5 + 5; int parent[N]; set<int> st; set<int>::iterator it1, it2; int n, m, l, r, x; int main() { ios::sync_with_stdio(0)...
#include <bits/stdc++.h> using namespace std; bool dp[1001][1001]; int data[1001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; if (n > m) { cout << YES << n ; return 0; } else { for (int i = 1; i <= n; i++) { ci...
#include <bits/stdc++.h> using namespace std; const int N = 100009; vector<int> edges[N]; vector<int> a; int n, m; int main() { while (cin >> n >> m) { a.clear(); for (int i = 1; i <= n; ++i) edges[i].clear(), a.push_back(i); for (int i = 0; i < m; ++i) { int ac, b; cin...
#include <bits/stdc++.h> using namespace std; long long ans; int main() { int n, i; long long a; cin >> n; ans = 0; for (i = 1; i <= n; i++) { cin >> a; ans = ans + (1 + (a - 1) * (long long)i); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e4 + 5; int dp[53][maxn], mxp[53][maxn], mxs[53][maxn], n, m, a[53][maxn], k, sum[53][maxn], h1, h2, t1, t2; pair<int, int> q1[maxn], q2[maxn]; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; ++i) for (int j ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int tot = 0; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (tot + a <= 500) { tot += a; cout << A ; } else { tot ...
#include <bits/stdc++.h> using namespace std; mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 2e5 + 10; const double pi = acos(-1); int main() { int cas; cin >> cas; double n; while (cas--) { cin >> n; printf( %.10lf n , cos(pi / 4.0 / n) / ...
#include <bits/stdc++.h> using namespace std; long long int a[1000001]; long long int b[1000001]; bool marked[1000001]; int main() { long long int n, i, j, k, x, y, fin_ans = 0, sum = 0; cin >> n >> k; a[0] = 0; for (i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; fin_ans += ...
#include <bits/stdc++.h> using namespace std; vector<bool> visited; vector<vector<int>> adj; vector<int> depth; void dfs(int v, int d) { if (visited[v]) { return; } visited[v] = true; depth[d]++; for (int i : adj[v]) { dfs(i, d + 1); } } int main() { int n; cin ...
#include <bits/stdc++.h> using namespace std; int P[111111]; int sz[111111]; int find(int x) { return (P[x] == x ? x : P[x] = find(P[x])); } void Union(int x, int y, int type) { x = find(x), y = find(y); if (sz[x] < sz[y]) swap(x, y); if (x == y) { if (type == -1) P[x] = 0; return; ...
#include <bits/stdc++.h> using namespace std; int main() { int arr[5009], n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); int cnt = 0; int ans = 0; int chk; bool fs = false; while (cnt < n) { fs = false; for (int i = n - 1; i >= 0; i--) { ...
#include <bits/stdc++.h> using namespace std; const int INF = numeric_limits<int>::max(); const long long LLINF = numeric_limits<long long>::max(); const unsigned long long ULLINF = numeric_limits<unsigned long long>::max(); const double PI = acos(-1.0); int sz = 1; vector<int> compressed; vector<pair<i...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; const int OO = (int)1e9 + 7; const int MAX = 109; char c1, c2, c3; string s1, s2, s3; long long n, m, k, t, a, b, c, d, e, f, x, y, z, sol = 0, ans = 0; long long ar[1000009]; map<long long, bool> vis; int fun(int i) { int re...
#include <bits/stdc++.h> using namespace std; template <typename... Ts> void do_nothing(Ts &&...vals) {} constexpr long long MOD = 1000000007; constexpr int INF = 0x7f7f7f7f; constexpr double EPS = 1e-8; long long fastPow(long long num, long long exp, long long modNum) { if (exp == 0) return 1; if...