func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int nmax = 1010; const int inf = 1000000007; int n; pair<int, int> a[nmax]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second; long double ans = 1e15; a[n + 1] = a[1];...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 666; long long saveori[maxn]; long long save[maxn]; long long getcnt(long long x) { long long cnt = 0; while (x) { if (x & 1) cnt++; x = x >> 1; } return cnt; } long long cnt[maxn][2]; long long pre[ma...
#include <bits/stdc++.h> using namespace std; #define int long long int void next(char &x){ if(x<= b ){ x++; }else{ x= a ; } } void solve() { int n,k; cin>>n>>k; char cur= a ; for(int i=0;i<n;i++){ cout<<cur; next(cur); } ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) const int mod = 1e9 + 7; using ll = int64_t; using namespace std; template <int MOD_> struct modnum { static constexpr int MOD = MOD_; static_assert(MOD_ > 0, MOD m...
#include <bits/stdc++.h> using namespace std; int n, a[105], z, x; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , a + i); if (a[i] % 2) x++; z += a[i]; } if (z % 2) printf( %d , x); else printf( %d , n - x); }
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005, mod = 1000000007; vector<int> pri; bool vis[80]; int pos[80], a[maxn], n; long long w[80]; long long dp[1 << 21], dp2[1 << 21], f[maxn]; void prework() { for (int i = 2; i < (71); ++i) { if (!vis[i]) { pri.push_bac...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; ; const int maxn = 410; unsigned long long powmod(unsigned long long n, unsigned long long k) { unsigned long long ret = 1; while (k) { if (k & 1) ret = ret * n % mod; n = n * n % mod; k >>= 1; } return...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long Query(long long L, long long R) { cout << L << << R << endl; fflush(stdout); string s; cin >> s; if (L == R && s == Yes ) exit(0); return s == Yes ; } int3...
#include <bits/stdc++.h> using namespace std; const long long MOD = (1e9 + 7); const long long INF = (1e9 + 123456789); const long long INFL = (INF * INF); inline long long addm(long long a, long long b, long long m = MOD) { return ((a + b) % m); } inline long long subm(long long a, long long b, long ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 100; long long a[N]; pair<long long, long long> ask(long long l, long long r) { cout << ? << l << << r << endl; long long first; cin >> first; if (first == -1) exit(0); long long f; cin >> f; return {first...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops,fast-math ) using namespace std; const int MAXN = 102, K = 900; int n, m, k, u, v, x, y, t, a, b; int A[MAXN]; short F1[MAXN][MAXN][2 * MAXN]; short F2[MAXN][MAXN][2 * MAXN]; short F3[MAXN][MAXN][2 * MAXN]; double dp[2][MAXN][MAXN]; i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int tab[n]; long long s = 0; for (int i = 0; i < n; i++) { cin >> tab[i]; if (i == tab[i]) { s++; tab[i] = -1; } } bool bo = false; for (int i = 0; i < n; i++) { if (ta...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; string conv(int n) { string kq = ; while (n != 0) { int r = n % 26; if (r == 0) r = 26; kq = char(r - 1 + A ) + kq; n = (n - r) / 26; } return kq; } int conv(string s) { int kq = 0; int ...
#include <bits/stdc++.h> using namespace std; void solution() { long long n; cin >> n; vector<vector<long long>> v(n, vector<long long>(n, 0)); if (n % 2 != 0) { v[n - 1][(n - 1) / 2] = 1; v[(n - 1) / 2][n - 1] = 1; } for (long long i = 0; i < n; i++) { for (long long j = 0...
#include <bits/stdc++.h> std::vector<int> V[200010], V2[200010]; int check[200010]; std::stack<int> St; void init(int k) { if (check[k] == 1) return; check[k] = 1; for (int i = 0; i < V[k].size(); i++) init(V[k][i]); St.push(k); } int color[200010]; void makeSCC(int k, int c) { if (col...
#include <bits/stdc++.h> int n, ust, x, y, mark[10]; int main() { scanf( %d , &n); scanf( %d , &ust); for (int i = 0; i < n; i++) { scanf( %d %d , &x, &y); mark[x] = 1; mark[y] = 1; mark[7 - x] = 1; mark[7 - y] = 1; if (!mark[7 - ust]) for (int j = 0; j < 7; j...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; cout << n / (2520LL); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000001; int n, kt[N], a[N], cnt, x[N]; long long k, s; long long cal(int i) { long long res = i; return res * (res + 1) / 2; } int main() { scanf( %d%lld , &n, &k); if (k < cal(n)) { printf( -1 ); return 0; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; vector<vector<int>> r(n), c(m); for (int i = 0; i < q; ++i) { int x, y; cin >> x >> y; --x; --y; r[x].push_back(y); c[y].push_back(x); ...
#include <bits/stdc++.h> bool canWin(long long b, long long e) { if (e % 2 == 1) { return b % 2 == 0; } else if (e < 2 * b) { return b % 2 == 1; } else if (e < 4 * b) { return 1; } else { return canWin(b, e / 4); } } bool canLose(long long b, long long e) { if (e < ...
#include <bits/stdc++.h> using namespace std; using namespace std; const long long N = 4e7 + 5, N_ = 4e6 + 5; int cnt = 0, prime[N_]; bitset<N> vis; void pre() { for (int i = 2; i < N; ++i) { if (!vis[i]) prime[cnt++] = i; for (int j = 0; i * prime[j] < N; ++j) { vis[i * prime[j]] = ...
#include <bits/stdc++.h> using namespace std; long long n, m; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 3) + (x << 1) + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; int n, k; int pr(int i) { return (i - 1 + n) % n; } int nx(int i) { return (i + 1) % n; } int get(int i, int j) { if (i > j) swap(i, j); return min(j - i, n - j + i); } char no(char el) { if (el == B ) return W ; else return B ; ...
#include <bits/stdc++.h> using namespace std; vector<int> g[100100]; int aa[100100]; long long dfs(int u, int fa) { vector<long long> tmp; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (v != fa && aa[v] - 1 >= 0) { aa[v] -= 1; tmp.push_back(dfs(v, u)); } ...
#include <bits/stdc++.h> using namespace std; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int TESTS, k, a, n, b, c, d, m, x, i, y, z; cin >> TESTS; while (TESTS--) { cin >> n; cin >> s; long long int ans = n; for...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) cout << -1; else cout << (n % 2 == 0 ? n : n - 1) << 2 ; return 0; }
#include <bits/stdc++.h> using namespace std; const int limit = 10000; int query(vector<long long> &v) { int n = (int)v.size(); cout << n << ; for (int i = 0; i < n; i++) { cout << v[i] << (i == n - 1 ? n : ); } int k; cin >> k; if (k == -1) { exit(0); } else i...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 10; int sx[MAXN], sy[MAXN], sz[MAXN]; char s[MAXN]; void solve(int x, int y, int z) { if (x + y + z < 3) { printf( YES n ); return; } int e = (x + y + z) / 3; vector<int> v; v.push_back(x); v.push_bac...
#include <bits/stdc++.h> using namespace std; const long long int siz = 3e5 + 5; map<int, vector<int>> adjList; long long int ans[siz] = {0}; long long int cum[siz] = {0}; map<long long int, long long int> q[siz]; void dfs(int cur, int parent, int level, long long int val) { for (pair<long long int, l...
#include <bits/stdc++.h> using namespace std; unsigned long long n, a[130], i, b = 1, f[10002]; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; f[a[i]]++; } sort(a + 1, a + n + 1); cout << a[n] << ; for (i = 1; i < n; i++) { if (f[a[i]] == 1 && a[n] % a[...
#include <bits/stdc++.h> using namespace std; long long MOD = 998244353; inline long long Msum(long long x) { return x; } template <typename... Rest> inline long long Msum(long long x, Rest... rest) { return (x + Msum(rest...)) % MOD; } inline long long Mprod(long long x) { return x; } template <typ...
#include <bits/stdc++.h> using namespace std; const int N = 1111111; int a[N]; int n, k; vector<int> prime, p; void Getprime() { for (int i = 2; i <= 1000; i++) { bool bo = 1; for (int j = 2; j * j <= i; j++) { if (i % j == 0) { bo = 0; break; } } ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void smn(T &a, const T &b) { if (b < a) a = b; } template <class T> inline void smx(T &a, const T &b) { if (b > a) a = b; } template <class T> inline T gcd(T x, T y) { return y ? gcd(y, x % y) : x; } namespace std ...
#include <bits/stdc++.h> using namespace std; inline int upd(int& a, int b) { return a = min(a, b); } inline int _abs(int x) { return x > 0 ? x : -x; } char c; int n, cnt[3], type[80]; int pos[3][80], leq[3][80]; int dp[80][80][80][80]; void getpos(void) { for (int p = 0; p <= 2; p++) { cnt[p]...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000000; int xx[1111111], yy[1111111]; int pos[1111111], n, m, op[1111111], np[1111111], ff; int owner[3333333], first[3333333]; int ans[1111111]; bool used[1111111]; void imp() { puts( -1 ); exit(0); } inline int sum(int x) { ...
#include <bits/stdc++.h> using namespace std; long long spf[100001]; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; r...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<long long> v[N]; long long vis[N]; long long col[N]; set<long long> che; void dfs(long long x) { vis[x] = 1; che.insert(x); for (auto it : v[x]) { if (!vis[it]) { dfs(it); } } } void solve()...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; int zD = 1; int zABC = 0; for (int i = 1; i <= n; i++) { int nzD = zABC * 3LL % 1000000007; int nzABC = (zABC * 2LL + zD) % 1000000007; zD = nzD; zABC = nzABC; } cout << zD; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; auto chk = [&](int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; }; vector<int> nxt(n * m, -1)...
#include <bits/stdc++.h> using namespace std; void addmod(int &a, long long b) { a = (a + b); if (a >= 1000000007) a -= 1000000007; } void mulmod(int &a, long long b) { a = (a * b) % 1000000007; } int gi() { int a; scanf( %d , &a); return a; } long long gll() { long long a; sca...
#include <bits/stdc++.h> using namespace std; const long long BIG = 1000000000000000000LL; void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } long long nbBoxes; long long reqSom = 0; bool cycor[1 << 15]; pair<long long, pair<long long, long long...
#include <bits/stdc++.h> using namespace std; long long n, k, a[300010], sum[300010], ans; int main() { scanf( %lld%lld , &n, &k); for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i]; ans += k * sum[n]; sort(sum + 1, sum + n); for (int...
#include <bits/stdc++.h> using namespace std; using LL = long long; using LD = long double; using ULL = unsigned long long; template <class T1, class T2> using P = pair<T1, T2>; using PII = P<int, int>; using PLL = P<LL, LL>; using PLD = P<LD, LD>; template <class T> using V = vector<T>; using V...
#include <bits/stdc++.h> using namespace std; int seq[100]; int main() { int n; int acc, t, pen; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , seq + i); } sort(seq, seq + n); acc = 10; t = 0; pen = 0; for (int i = 0; i < n; i++) { acc += seq[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if ((n * n) % 2 == 0) { cout << 2 n ; } else { cout << 1 n ; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long maxx = 1e5 + 20, sqr = 150, mod = 1e9 + 7; long long len, n, dp[maxx][sqr][2], q, pw25[maxx], pw26[maxx], pwmod[maxx], fac[maxx], tmp[maxx]; string s; long long pw(long long a, long long b) { if (!b) return 1ll; long long x = pw(a, b ...
#include <bits/stdc++.h> using namespace std; vector<array<int, 2>> tree(1); int terminal[110]; unsigned long long inf = (1ull << 63) - 1; int s; struct Mat { vector<unsigned long long> data; Mat() { data.assign(s * s, inf); } }; Mat operator*(const Mat& a, const Mat& b) { Mat r; for (in...
#include <bits/stdc++.h> #pragma GCC optimize -O3 using namespace std; const int MAXN = 310000; int n; int a[MAXN]; vector<int> pr; int bb[MAXN]; int go[MAXN]; int cc[MAXN]; int ans[MAXN]; vector<int> fc[MAXN]; int gcd(int a, int b) { while (b) { int q = a % b; a = b; b =...
#include <bits/stdc++.h> using namespace std; int n, x, m; priority_queue<int> s; int main() { scanf( %d , &n); m = n; for (int i = 0; i < int(n); i++) { scanf( %d , &x); if (x < m) { s.push(x); cout << ; } else if (x == m) { cout << x << ; m--...
#include <bits/stdc++.h> using namespace std; char s[12000]; int n, i, j; vector<int> ans; int cek(int v, int t, string e) { if (v >= strlen(s) - 1) return v; int i = v; do { string tmp = ; for (i = i;; i++) { tmp.push_back(s[i]); if (s[i] == > ) break; } ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; long double scal(long double x, long double y, long double x1, long double y1) { return x * y1 - x1 * y; } int n, m; int a[20][2], b[20][2]; int aa[20][10], bb[20][10]; int p[10]; int main() { cin >> n >> m; for (int ...
#include <bits/stdc++.h> using namespace std; int n, p, k; int a[333333]; long long ans; map<int, int> mp, mpb; int main() { scanf( %d%d%d , &n, &p, &k); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) { mp[a[i]]++; } for (map<int, int>::iterator it = ...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long fac[1000006]; inline long long exp(long long x, long long n) { long long r = 1; x = x; while (n) { if (n % 2) r = (r * x) % 10000000000000007; x = (x * x) % 10000000000000007; n = n / 2; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i % 2 == 0) { if (j % 2 == 0) { cout << W ; } else { cout << B ; } } else { ...
#include <bits/stdc++.h> using namespace std; int main() { int first, second; cin >> second >> first; if ((second == 1 && first == 0) || first == 0) { cout << NO ; return 0; } else if (first == 1 && second == 0) { cout << YES ; return 0; } int tot = first; int c...
#include <bits/stdc++.h> using namespace std; long long n, x, k, lb, ub, ans = -1; int main() { long long l, r; scanf( %lld%lld%lld%lld , &n, &l, &r, &k); x = (r >= l ? r - l + 1 : r + n - l + 1) % n; for (long long i = k, j, r; i; i = j) { j = k / (k / i + 1); r = k / i; ub = mi...
#include <bits/stdc++.h> using namespace std; char p[][20] = { vaporeon , jolteon , flareon , espeon , umbreon , leafeon , glaceon , sylveon }; char s[20]; int main() { int n, k, i; scanf( %d , &n); scanf( %s , s); for (k = 0; k < 8; k++) { int fl = 1; for (...
#include <bits/stdc++.h> using namespace std; const long double epsilon = 1e-9; int main() { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; vector<pair<int, int> > moves; for (int i = 0; i < n; i++) { if ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long a, b, c, d, e, first; cin >> a >> b >> c >> d >> e >> first; b = min(c, b); if (d < a && d < b) cout << d * max(e, first); else { long long p = min(a, d) * e ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long n; cin >> n; string s; cin >> s; for (long long i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { cout << YES << endl; cout << i + 1 << << i ...
#include <bits/stdc++.h> using namespace std; const int maxn = 21; int a[1 << maxn], n; long long ans[maxn][2]; void mergesort(int l, int r, int dep) { if (r - l <= 1) return; int m = (l + r) / 2; mergesort(l, m, dep - 1); mergesort(m, r, dep - 1); for (int i = l; i < m; i++) { ans[d...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const long long inf = (((long long)1) << 61) + 5; const int N = 100005; int f[N]; int g[N]; int a[N]; int bit[N]; int ans[N]; int sum1(int x) { int ans = 0; fo...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; template <typename T> inline void read(T &x) { x = 0; T fl = 1; char ch = 0; for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) fl = -1; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = (x << 1) ...
#include <bits/stdc++.h> using namespace std; long long a, i, j, n, aux, cnt, ans, div1[10000010], v[10000010]; int main() { cin >> a >> n; v[1] = 1; for (i = 3; i * i <= a + n - 1; i += 2) if (!div1[i]) { div1[i] = i; for (j = i * i; j <= a + n - 1; j += 2 * i) div1[j] = i; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; vector<long long> v; unordered_map<long long, long long> m; long long falla(long long n) { if (m.count(n)) { ...
#include <bits/stdc++.h> using namespace std; long long dp[200005][2]; bool vst[200005][2]; long long A[200005], n; long long go(long long v, bool b) { if (vst[v][b]) return dp[v][b]; vst[v][b] = true; long long val = 0; if (!b) { if ((v - A[v]) > 1) val = go(v - A[v], b ^ 1); ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const double Pi = 3.1415926535897932; const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1}; const int maxn = 1e4 + 5; struct EDGE { int a, b; int A, B; } edge[maxn]; int n, m; int last[maxn]; vector<int> G[maxn], tree[maxn];...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> a[200]; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].second; long long tmp = a[i].second; while (tmp % 3 == 0) { a[i].first--; tmp /= 3; } } sort(a + 1, a ...
#include <bits/stdc++.h> using namespace std; int main() { long long arr[3]; scanf( %I64d%I64d%I64d , &arr[0], &arr[1], &arr[2]); sort(arr, arr + 3); if (arr[0] == arr[1] && arr[1] == arr[2]) printf( 0 n ); else if (arr[2] == arr[1] && arr[1] > arr[0]) { printf( %I64d n , arr[2] - ar...
#include <bits/stdc++.h> using namespace std; long long const modul = 1; long long mod_sum(long long x, long long y) { return (x + y) % modul; } long long mod_sub(long long x, long long y) { if (x > y) { return (x - y) % modul; } else { return (modul + x - y) % modul; } } long long m...
#include <bits/stdc++.h> using namespace std; void sove() {} int main() { int n; cin >> n; int nums[n]; for (int i = 0; i < n; ++i) { cin >> nums[i]; } for (int i = 0; i < n / 2; i += 2) { int temp = nums[i]; nums[i] = nums[n - i - 1]; nums[n - i - 1] = temp; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; vector<int> e[maxn]; int dp[maxn], root[maxn], d[maxn], sz[maxn]; pair<int, int> dfs(int v, int st, int par) { if (root[v] == -1) sz[st]++; root[v] = st; pair<int, int> p = make_pair(0, -1); for (int i = 0; i < e[v].size(...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; t = 1; for (long long int _ = 0; _ < t; _++) { long long int n, m, b, mod; cin >> n >> m >> b >> mod; vector<long long int> v(n + 1); for...
#include <bits/stdc++.h> using namespace std; int n, m; set<string> a, b, c; void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) { string s; cin >> s; a.insert(s); } for (int i = 1; i <= m; i++) { string s; cin >> s; if (a.count(s)) c.insert(s); b...
#include <bits/stdc++.h> using namespace std; int main() { int n, d, res = 0, a = 0, b; cin >> n >> d; for (int i = 0; i < n; i++) { cin >> b; if (a >= b) { res += ceil((a - b + 1) / (double)d); b += ceil((a - b + 1) / (double)d) * d; } a = b; } cout << re...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > g[100010]; int N, K, in[100010], dp[100010][2]; vector<pair<int, int> > num[100010]; void dfs(int u, int fa) { for (pair<int, int>& e : g[u]) { int v = e.first, cost = e.second; if (v == fa) continue; dfs(v, u); ...
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { while (b) b ^= a ^= b ^= a %= b; return a; } long long LCM(long long a, long long b) { return a * (b / GCD(a, b)); } const double EPS = 10e-9; const long long INF = (1LL << 30); using namespace std; template ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int inf = 1e17; const long long int N = 5005; long long int n; long long int a[N]; long long int dp[N][N]; long long int go(long long int idx, long long int flag) { long long int &ans = dp[idx][flag];...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; bool chk(string s) { int l = s.size(); for (int i = 0, j = l - 1; i <= j; i++, j--) { if (s[i] != s[j]) return false; } return true; } int main() { int t; cin >> t; while (t--) { string s; cin >...
#include <bits/stdc++.h> int main() { int n, m; scanf( %d%d , &n, &m); int num = n + m; int a = m / 2, aa = m % 2, aaa = a + aa; if (n == m) { for (int i = 0; i < n; i++) { printf( 01 ); } } else if (n < m) { if (aaa <= n + 1) { a = m - (n + 1); m -= a...
#include <bits/stdc++.h> using namespace std; long long k, d, t; int main() { scanf( %lld%lld%lld , &k, &d, &t); t *= 2; long long round = ceil((double)k / d) * d; long long num = k * 2 + (round - k); long long cnt = t / num; long long left = t - cnt * num; double ans = 0.0; if (le...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 0, last = 0, current = 0; while (n > 0) { ans++; current = last + ans; last = current; n -= current; if (n < 0) { ans--; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; int head, tail, n, q[100100]; long long f[100100], a[100100], b[100010]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); for (int i = 1; i <= n; i++) scanf( %I64d , &b[i]); f[1] = 0; head = tail = 1; q[head] ...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 5005; void update(int &a, int b) { a += b; a %= MOD; } int add(int a, int b) { return (a + b) % MOD; } int multiply(int a, int b) { return (a * 1LL * b) % MOD; } int quick_power(int a, int n) { int res = 1...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long double n, h; cin >> n >> h; cout << setprecision(20); for (long double i = 0; i < n - 1; i++) { cout << h * sqrt((i + 1) / n) << ; } }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const long long N = 1e5 + 5, M = 1e9 + 7; char ulta[500]; set<char> ache; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ulta[ U ] = D ; ulta[ D ] = U ; ulta[ R ] = L ; ulta[ L ] = R ; string s;...
#include <bits/stdc++.h> using namespace std; struct State { int len, link; map<char, int> nxtc; } SA[2 * 2006]; bool vis[2 * 2006]; char str[2006], pref[2 * 2006], suf[2006]; class SuffixAutomata { int sz, last; void init(int idx) { SA[idx].len = 0, SA[idx].link = -1; SA[idx].nx...
#include <bits/stdc++.h> using namespace std; const int MAX = 200005; int main() { int n, k, q, i, a, b, p[MAX] = {0}, c[MAX] = {0}; scanf( %d %d %d , &n, &k, &q); while (n--) { scanf( %d %d , &a, &b); p[a]++; p[b + 1]--; } for (i = 1; i < MAX; i++) { p[i] += p[i - 1]; ...
#include <bits/stdc++.h> using namespace std; class base { public: long double a, b; base(void) { a = 0; b = 0; } base(long double _a, long double _b) { a = _a; b = _b; } base(long double _a) { a = _a; b = 0; } base operator*(const base& b2) { ...
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long int #define pb push_back #define pob pop_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define f0(i,n) for(i=0;i<n;i++) #define rf0(i,n) for(i=n-1;i>=0;i-...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 10000; const double eps = 1e-9; using namespace std; int n, m, cur; set<int> s; void dfs(int x, int y) { if (y == 0) { int tmp = abs(abs(x) - n...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int MAX = 400005; const int MAX1 = 2007; const int MAX2 = 4007; const int LEN = 21; const int BASE = 1000000000; const double EPS = 1e-7; const int MOD = 1234567891; vector<pair<char, int> > vec; int main(void) { i...
#include <bits/stdc++.h> using namespace std; int num; int likes[7][7]; map<string, int> heroes; int getNum(string s) { if (!heroes.count(s)) heroes[s] = num++; return heroes[s]; } int getMaxSymp(int n1, int n2) { vector<int> p, groups(7, 0); for (int i = 0; i < 7; i++) { p.push_back...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long inv[5050 + 10], fac[5050 + 10], ifac[5050 + 10]; void setComb() { inv[0] = 1; inv[1] = 1; fac[1] = 1; ifac[1] = 1; fac[0] = 1; ifac[0] = 1; for (int i = 2; i < 5050; i++) { inv[i] = (-MOD /...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; vector<int>::iterator it; int n, q, x, count1 = 0, x1; cin >> q; while (q--) { cin >> n; while (n--) { cin >> x; v.push_back(x); } it = v.end() - 1; x1 = *it; for (it = v...
#include <bits/stdc++.h> long long ans; int F[50000001], n, m, N; char str[10001]; void dfs(int x, int bit, int key) { if (x > 3) { if (bit) F[bit] += key; return; } dfs(x + 1, bit, key); int v = str[x] - a ; dfs(x + 1, bit | (1 << v), -key); } int main() { scanf( %d , &...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10, MAXM = 100; int A[MAXN][MAXM], B[MAXN][MAXM], C[MAXN][MAXM]; int order[MAXM]; int ib, is; bool cmp(int a, int b) { return B[is][a] - A[ib][a] > B[is][b] - A[ib][b]; } int main() { int n, m, k, ans = 0, tmp; int cur_hold, nx, p; ...
#include <bits/stdc++.h> using namespace std; void init() {} void _print(long long int t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(...
#include <bits/stdc++.h> using namespace std; long long int b[100005], p[100005]; int n, m, a; bool check(int x) { int temp_a = a; for (__typeof((x)) i = (0); i < (x); i += 1) { int t = x - 1; if (p[i] > b[t - i]) { if (temp_a < p[i] - b[t - i]) { return false; } el...
#include <bits/stdc++.h> using namespace std; long long a00, a01, a10, a11; char *s; bool isSquare(long long x, long long &res) { long long t = sqrt(x); for (long long i = max(t - 10, 1LL); i <= t + 10; i++) { if (i * i == x) { res = i; return true; } } return false; ...