func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int MXN = 1000100; const long long inf = 1e15; const int mod = 1000000007; char s[MXN]; int was[2 * MXN]; int main() { scanf( %s , s); int n = strlen(s); if (s[n - 1] == L ) { for (int i = 0; i < (n); i++) { if (s[i] == R ) ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000 * 1000 * 1000 + 7; const int INF = 1000 * 1000 * 1000; const long long LINF = (long long)INF * INF; struct Query { int l, r, ind, k; }; int n, m; int c[100100]; vector<int> adj[100100]; int cnt[100100], bnd[100100]; int ans[100...
#include <bits/stdc++.h> using namespace std; void solve() { long long st = 1, mod = 998244353; int n; cin >> n; vector<long long> ans(n + 1); ans[n] = 10; ans[n - 1] = 20; for (int i = n - 2; i >= 1; i--) { ans[i] = ans[i + 1] + 9; } for (int i = n - 1; i >= 1; i--) { ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = s * 10 + ch - 0 , ch = getchar(); return s * w; } c...
#include <bits/stdc++.h> using namespace std; void sc() {} template <typename T, typename... Args> void sc(T& a, Args&... args) { cin >> a, sc(args...); } template <typename T> void pr(T a) { cout << a; } template <typename T, typename... Args> void pr(T a, Args... args) { cout << a << ...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z = 0, k, t = 0, e, g; vector<int> zero; vector<int> po; vector<int> ne; cin >> x; g = x; while (x--) { cin >> y; if (y < 0) { ne.push_back(y); k *= y; } if (y > 0) { po.p...
#include <bits/stdc++.h> using namespace std; const int oo = 1e9 + 9; const long long inf = 1e18 + 18; const int max6 = 1e6 + 6; const int modx = 1e9 + 123; const int mody = 997; const int base = 137; int a[max6], dd[max6], cnt[max6]; int main() { int t; cin >> t; while (t--) { int n...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); const int N = 3e5 + 5, K = 30; int tam[N] = {1}, g[N][K], _g[N][K]; vector<int> v; int res[N]; pair<int, int> merge(int a, int b) { if (!a) return pair<int, int>(b, 0); if (!b) return pair<int...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<long long> a(n); for (size_t i = 0; i < n; i++) { cin >> a[i]; } long long ans = a[n - 1] - a[0]; multiset<long long> s; for (long long i = 1; i < n; i++) { s.insert(a[i - 1] ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LNF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1000000007; const double EPS = 1e-8; const long double EUL = 2.71828182845904523536; const long double PII = 3.14159265358979323846; int main() { ios_base::sync_with_st...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; struct Rec { pair<int, int> interval[4]; } recs[100005]; bool check(set<pair<pair<int, int>, int>> st[]) { int n = st[0].size(); if (n == 1) return true; set<pair<pair<int, int>, int>>::iterator iter[4]; for (int i =...
#include <bits/stdc++.h> #pragma optimize( O3 ) using namespace std; const long long MOD = 998244353; const long long INF = 1e8 + 7; const int base = 2e5 + 1; const long long MAX = 3 * 1e5 + 1; const double EPS = 1e-9; const double PI = acos(-1.); const int MAXN = 5 * 1e5 + 47; mt19937 rng(chrono::s...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; int n, k; struct st { int v, p; }; bool cmp(st a, st b) { return a.v < b.v; } st a[MAX]; void solve() { sort(a + 1, a + n + 1, cmp); int t = 0; for (int i = 2; i <= n; ++i) { if (a[i].p == a[i - 1].p + 1) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 50010; int n; char s[maxn]; int main() { while (scanf( %s , s) != EOF) { n = strlen(s); int len = 1; while (len <= n / 2) { int cnt = 0, start = len; for (int i = len; i < n; i++) { if (cnt == len) b...
#include <bits/stdc++.h> using namespace std; long long arr[200000]; int main() { int n, cnt = 0, cntz = 0; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %lld , &arr[i]); if (arr[i] < 0) cnt++; else if (arr[i] == 0) cntz++; } if (cnt % 2 == 0 && cntz =...
#include <bits/stdc++.h> using namespace std; const int sizeS = 100 + 5; const int sizeN = 50 + 5; int a[sizeS], na, n; int dpmax[sizeS][sizeN][3], dpmin[sizeS][sizeN][3]; void Nhap() { char s[sizeS]; scanf( %s , s); na = int(strlen(s)); for (int i = 0; i < na; i++) if (s[i] == F ) a[...
#include <bits/stdc++.h> using namespace std; int a[10], n; int main() { int T; scanf( %d , &T); while (T--) { scanf( %d , &n); int m = 0; for (int i = 0; i < 7; ++i) { int x; scanf( %d , &x); if (x) a[m++] = i; } int ret = 1e9; for (int x = ...
#include <bits/stdc++.h> using namespace std; int dx8[8] = {1, -1, 0, 0, 1, 1, -1, -1}; int dy8[8] = {0, 0, 1, -1, 1, -1, 1, -1}; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } int main() { file(); int n, s; cin >> n >> s; if (n...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; int n; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; if (n % 2 == 0) { cout << n / 2; cout << n ; for (int i = 0; i < n / 2; ++i) { cout << 2 ; } return 0; ...
//////////////////////////// **** JAI SHREE RAM **** ////////////////////////// #include<bits/stdc++.h> #include<unordered_map> using namespace std; #define int long long int #define double long double void fun() { #ifndef ONLINE_JUDGE freopen( input.txt , r , stdin);freopen( output.txt , w , stdo...
#include <bits/stdc++.h> using namespace std; int n, k, x[105], y[105]; double s; int main(void) { cin >> n >> k; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; int j = 1; while (j < n) { s += sqrt((double)(y[j] - y[j - 1]) * (y[j] - y[j - 1]) + (double)(x[j] - x[j - 1]) ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool mineq(T a, T b) { if (a > b) { a = b; return true; } return false; } void print(long long a) { string str; while (a) { str.push_b...
#include <bits/stdc++.h> using namespace std; long long get(long long n) { for (long long i = 2; i * i <= n; ++i) if (n % i == 0) return i; return n; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; int c = 0; while ...
#include <bits/stdc++.h> using namespace std; int n, m, r, ans, b[505], c[505], a[505][505], s[505][505], sm[505][505], mxl[505][505], sl[505][505], mxr[505][505], sr[505][505]; long long t; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) i...
#include <bits/stdc++.h> using namespace std; struct H { int i, x, y; }; int k, m, n, b[200004]; H w[200004]; int C(H a, H b) { return a.x < b.x || a.x == b.x && a.i > b.i; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; fill(b + 1, b + n + 1, 1 << 3...
#include <bits/stdc++.h> using namespace std; int n, m, q, x, y, maxi = 0, buf = 1, max_row[501]; bool arr[501][501]; int main() { cin >> n >> m >> q; for (int i = 0; i < n; i++) { max_row[i] = 0; for (int j = 0; j < m; j++) cin >> arr[i][j]; } for (int i = 0; i < n; i++) { buf...
#include <bits/stdc++.h> using namespace std; inline int read() { int first = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) { if (ch == - ) f = -1; } for (; isdigit(ch); ch = getchar()) { first = first * 10 + ch - 48; } return first * f; } const int...
#include <bits/stdc++.h> using namespace std; int n, m; char mp[111][111]; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> mp[i][j]; int ans = 0; for (int i = 0; i < n; ++i) { bool f = 1; for (int j = 0; f && j < m; ++j) { bool...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) using namespace std; inline int read() { int x = 0, neg = 1; char op = getchar(); while (!isdigit(op)) { if (op == - ) neg = -1; op = getchar(); } while (isdigit(op)) { x = 10 * x + op - 0 ; op...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int len = 20000; string di; int mo; string ans[2] = { NO , YES }; bool yes = 1; for (int i = 0; i < n; ++i) { cin >> mo >> di; if (len == 20000 && di != South ) yes = 0; if (len == 0 && di...
#include <bits/stdc++.h> using namespace std; template <class T, size_t N> ostream& operator<<(ostream& os, const array<T, N>& v); template <class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << ( << p.first << , << p.second << ) ; } template <class T> ostr...
#include <bits/stdc++.h> using namespace std; const int INFINITE = 0x3f3f3f3f; char grid[500][501]; int m, n; int memo[500][27][27][2], memoCost[500][27][2]; bool mark[500][27][27][2], markCost[500][27][2]; int choice[500][27][27][2]; int GetCost(int row, char c, int next) { int& cost = memoCost[row...
#include <bits/stdc++.h> using namespace std; const int N = 5005; int n, A, B, C, D; int be[N], fa[N], sz[N]; vector<int> e[N]; bitset<N> bit; int main() { scanf( %d , &n); scanf( %d%d%d%d , &A, &B, &C, &D); for (int i = (int)(2); i <= (int)(n); i++) { scanf( %d , &fa[i]); e[fa[i]]...
#include <bits/stdc++.h> using namespace std; int main() { int t[105][105]; int n; int x1, y1, x2, y2; while (cin >> n) { for (int i = 0; i < 105; i++) { for (int j = 0; j < 105; j++) t[i][j] = 0; } for (int z = 0; z < n; z++) { cin >> x1 >> y1 >> x2 >> y2; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; long long int w[n]; long long int h[n]; for (int i = 0; i < n; i++) { cin >> w[i]; cin >> h[i]; } arr[0] = max(w[0], h[0]); for (int i = 1; i < n; i++) { if (max(w[i], h[i]) ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 10, maxe = 15; long long n, k, x, ans = -1; long long fact[maxe], A[maxe], use[maxe]; void lucky_generator(long long a) { if (a > x) return; ans++; lucky_generator(a * 10 + 4); lucky_generator(a * 10 + 7); } bool is...
#include <bits/stdc++.h> using namespace std; long long POW(long long A, long long N, long long MOD) { if (N == 0) return 1 % MOD; if (N == 1) return A % MOD; long long tmp = POW(A, N / 2, MOD) % MOD; if (N % 2) return ((tmp * tmp) % MOD * A % MOD) % MOD; else return (tmp * tmp) % MO...
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const long long INFL = (long long)9e18; const int MAXINT = ((~0) ^ (1 << 31)); const long long MAXLL = ((~0) ^ ((long long)1 << 63)); template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool min...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000006; int n, k; int main() { int i, j; cin >> n >> k; if (k > n) { printf( -1 ); return 0; } if (k == 1 && n == 1) { printf( a ); return 0; } if (k == 1 && n > 1) { puts( -1 ); retur...
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 20, INF = 1e9 + 20; int n, h[N], pmx[N], pmn[N], ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) pmx[i] = i ? max(h[i], pmx[i - 1]) : h[...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<map<int, vector<string> > > A(m + 1); for (int x = 0; x < n; x++) { string name; int r, points; cin >> name >> r >> points; A[r][points].push_back(name); } for (int x = 1; x <= ...
#include <bits/stdc++.h> using namespace std; int n, k; int a[5005]; int q, x; bool bfind(int p) { int lf = 0; int rt = n - 1; int mid; while (lf <= rt) { mid = (lf + rt) / 2; if (a[mid] < p) { lf = mid + 1; } else if (a[mid] > p) { rt = mid - 1; } else ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); long long n, m, k, s; cin >> n >> m >> k >> s; vector<vector<long long>> a(2, vector<long long>(n)); for (long long i = 0; i < 2; ++i) { for (long long j = 0; j <...
#include <bits/stdc++.h> using namespace std; set<int> v; int num[300005]; int main() { int n, m; scanf( %d%d , &n, &m); int l, r, x; memset(num, 0, sizeof(num)); for (int i = 1; i <= n; i++) { v.insert(i); } set<int>::iterator it, s; bool flag = true; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; const int mx = 100005; const int mod = 998244353; int a[mx], y, z; long long sum[mx]; int as[mx], bs[mx]; bool v[mx]; map<int, int> r[mx]; int query(long long i, int x) { long long ans = 0; if (i == 0) return 0; if (x == 1) return sum[i]; i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; const int LOGN = 20; int n, k; vector<int> graph[MAXN + 5]; int pa[LOGN + 1][MAXN + 5]; int depth[MAXN + 5]; int par[MAXN + 5]; void dfs(int u, int p, int d) { depth[u] = d; par[u] = p; pa[0][u] = p; for (int j = 1; j ...
#include <bits/stdc++.h> using namespace std; int main() { int t, i; cin >> t; for (i = 0; i < t; i++) { int n, k1, k2, j, f; cin >> n >> k1 >> k2; int a[100], b[100], sum, hum; for (j = 0; j < k1; j++) { cin >> a[j]; } sum = a[0]; for (j = 0; j < k1; j+...
#include <bits/stdc++.h> using namespace std; const int Maxn = 100010; int ans = -1, ansd, a[Maxn], b[Maxn], n, m; inline int Pow(int x, int y, int mod) { int s = 1; for (; y; y >>= 1, x = 1ll * x * x % mod) if (y & 1) s = 1ll * s * x % mod; return s; } inline bool find(int *a, int n, int ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int arr[MAXN]; int main() { int N, ans = 0; cin >> N; for (int i = 0; i < N; i++) cin >> arr[i]; sort(arr, arr + N); for (int i = 0, j = 1; i < N; i++) { while (arr[i] >= arr[j] && j <= N - 1) j++; if (j == ...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, dp[108][108][28], dis[108][108]; int DP(int s, int t, int w) { if (dp[s][t][w - a ] >= 0) return dp[s][t][w - a ]; for (int i = 1; i <= n; ++i) if (dis[s][i] >= w && (DP(t, i, dis[s][i]) == 0)) return dp[s][t][w - a ] = 1; ...
#include <bits/stdc++.h> using namespace std; long long n, nn, p, pp, tt; int k, _s, t; char s[105]; int main() { for (scanf( %d , &t); t--;) { _s = k = 0; p = 1; scanf( %lld , &n); nn = n; while (nn) { nn /= 4; p *= 4; k++; } p /= 4; ...
#include <bits/stdc++.h> int main() { int a, b, c; std::cin >> a >> b >> c; int weeks = std::min(a / 3, std::min(b / 2, c / 2)); a -= weeks * 3; b -= weeks * 2; c -= weeks * 2; int ans(0); for (int i = 1; i <= 7; ++i) { int ac = a; int bc = b; int cc = c; int zi...
#include <bits/stdc++.h> using namespace std; map<string, int> ma; vector<int> ind; vector<int> adj[205]; string x[205], y; int vis[205], ht[205]; void dfs(int u) { vis[u] = 1; for (int i = 0; i < adj[u].size(); i++) { int cur = adj[u][i]; if (!vis[cur]) { vis[cur] = 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int gcd(int x, int y) { return !y ? x : gcd(y, x % y); } int rev(int num) { int dig[10], tot = 0, s = 0; for (; num; num /= 10) dig[tot++] = num % 10; for (int i = 0; i < tot; i++) s = s * 10 + dig[i]; return s; } pair<in...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0); int opx, t, c; cin >> t >> c; int dfx = 1; long long lorenzo = 0; while (c--) { cin >> opx; if (dfx != 1) lorenzo += t - dfx + 1; dfx = opx + 1; } cout << lorenzo; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, c; cin >> n >> m >> c; vector<int> v1, v2; for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; long long int bit[1000010] = {0}; long long int get_sum(int i) { long long int ans = 0; while (i > 0) { ans += bit[i]; i -= i & (-i); } return ans; } void update(int i, int n) { while (i <= n) { bit[i] += 1; i += i & (-i...
#include <bits/stdc++.h> using namespace std; long long n, s, ans, a[200001], f[200001]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (register long long i = 1; i <= n; ++i) { cin >> a[i]; s ^= a[i]; long long x = a[i]; for (register ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const long double eps = 1e-11; const long double pi = acos(-1); const int oo =...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b, c; scanf( %lld%lld%lld , &a, &b, &c); long long ans = 0x7f7f7f7f7f7f7f7f; long long ca, cb, cc; for (long long i = 1ll; i <= 15000ll; i++) { long long a1, c1; ...
#include <bits/stdc++.h> using namespace std; int n, m, adj[25], pode[1 << 23]; int main() { scanf( %d%d , &n, &m); if (m == n * (n - 1) / 2) { puts( 0 ); return 0; } for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1 - 2 * ((0) > (n))) adj[i] |= 1 <<...
#include <bits/stdc++.h> using namespace std; int col[501]; int tcol[501]; int edge[501][501]; void docol(int v, int c) { col[v] = c; for (int i = 1; i <= v; ++i) { if (edge[v][i] && col[i] == -1) { docol(i, c); } } } int main(void) { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> int main() { int n, s, i = 1, count = 1; scanf( %d %d , &n, &s); while (i * n < s) { count++; i++; } printf( %d , count); }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, P = 1e9 + 7; struct Edge { int v, nxt, col; long long w; } e[N << 1]; int head[N], size = 1, ext; long long ans = 1; long long qpow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int max_points = -(50 * 50 + 1); string leader; for (int i = 0; i < n; i++) { string handle; int plus, minus, a, b, c, d, e; cin >> handle >> plus >> minus >> a >> b >> c >> d >> e; if (plus * 100...
#include <bits/stdc++.h> using namespace std; long long mod(long long a, long long b) { long long ans; if (b == 0) return -1; else { ans = (a < 0 ? mod(((a % b) + b), b) : a % b); } return ans; } vector<int> cntl(100003, 0), cntr(100003, 0), cntt(100003, 0), cntb(100003, 0); in...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize( Ofast ) using namespace std; namespace ywy { inline int get() { int n = 0; char c; while ((c = getchar()) || 23333) { if (c >= 0 && c <= 9 ) break; if (c == - ) goto s; } n = c ...
#include <bits/stdc++.h> using namespace std; int a[10][10]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { scanf( %d , &a[i][j]); } } for (int k = 0; k < n; ++k) { for (int i = 0; i < n; ++i) { for (int j = 0;...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( -ffloat-store ) using namespace std; const long long mod = 998244353; long long powmod(long long a, long long b) { long long res = 1; a %= mod; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const int MAXN = 1000100; long long mpow(long long b, int e) { if (e == 0) return 1; long long v = mpow(b, e / 2); v = (v * v) % MOD; if (e & 1) v = (v * b) % MOD; return v; } long long inv(long long b) { retu...
#include <bits/stdc++.h> using namespace std; int t; vector<vector<int> > nod; vector<int> sol; void bfs(int n) { sol = vector<int>(n + 10); sol[1] = 1; queue<int> Q; Q.push(1); while (!Q.empty()) { int a = Q.front(); Q.pop(); for (int j = 0; j < nod[a].size(); j++) ...
#include <bits/stdc++.h> using namespace std; int main() { int seq[60]; int yea[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; for (int i = 1; i <= 12; i++) { seq[i - 1] = yea[i - 1]; seq[12 + i - 1] = yea[i - 1]; seq[24 + i - 1] = yea[i - 1]; seq[36 + i - 1] = yea[i - 1...
#include <bits/stdc++.h> using namespace std; int n, a[3] = {6, 10, 15}; int main() { ios::sync_with_stdio(false); cin >> n; if (n == 2) return cout << -1, 0; if (n == 1) return cout << 2, 0; cout << a[0] << endl << a[1] << endl << a[2] << endl; for (int i = 3; i < n; i++) cout << i * a[0]...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e7 + 5; const int MAXM = 105; int st[MAXN], top, tree_cnt; int ls[MAXN], rs[MAXN], rt[MAXM], val[200005]; inline int read() { int x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) { x = x...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200001, MOD = 1000000007; int n, l, r; long long one = 0, two = 0, zero = 0, dp[MAXN][3]; int main() { cin >> n >> l >> r; for (; l % 3 != 0 && l <= r; l++) if (l % 3 == 1) one++; else if (l % 3 == 2) two++; ...
#include <bits/stdc++.h> using namespace std; long long p[500002], d[200004], c, n, fix[200004]; vector<pair<long long, long long> > g; vector<long long> v[200005]; void go(long long x, long long par, long long dep) { p[x] = par; d[x] = dep; for (int i = 0; i < v[x].size(); i++) if (v[x][i] ...
#include <bits/stdc++.h> const int N = 300010; int n, m, i, j, js, root, mx; int a[N], x[N], y[N], num[N], f[N], next[N * 2], last[N * 2], tov[N * 2], bh[N * 2], ans[N * 2]; bool dir[N * 2], bz[N]; int gf(int xx) { if (f[xx] == xx) return xx; int jl = gf(f[xx]); f[xx] = jl; return jl; ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> void chkmax(T1 &x, T2 y) { if (x < y) x = y; } inline void debug(int x) { fprintf(stderr, ycx has aked ioi %d times n , x); } na...
#include <bits/stdc++.h> using namespace std; int ar[7]; int N, K; map<vector<int>, double> M[5]; int bit[20]; void update(int x) { while (x <= N) { bit[x] += 1; x += (x & -x); } } int qry(int x) { int rs = 0; while (x) { rs += bit[x]; x -= (x & -x); } ret...
#include <bits/stdc++.h> using namespace std; int read() { static int x; static char ch; static bool pd; pd = true; x = 0; for (ch = getchar(); ch > 9 || ch < 0 ; ch = getchar()) if (ch == - ) pd = false; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = (int)2e5 + 100; const int mod = (int)1e9 + 7; int cnt[MAX_N]; inline int mul(int x, int y) { return (long long)x * y % mod; } inline int powMod(int x, int n) { int ret = 1; while (n > 0) { if (n & 1) ret = mul(ret, x); x = m...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; bool vi[1002]; memset(vi, 0, sizeof vi); int a = 0, i = 0; while (i < n) { a = (a + i % n) % n; if (vi[a]) { cout << NO << endl; return 0; }; vi[a] = 1; i++; } ...
#include <bits/stdc++.h> using namespace std; int diez(int x) { int x1 = 0; int s = 0; while (x != 0) { x1 = x % 10; x = x / 10; s += x1; } if (s == 10) return (1); else return (0); } int main() { int n; while (cin >> n) { int s = 18; int...
#include <bits/stdc++.h> using namespace std; long long op[1000010]; int main() { op[1] = 1LL; for (int i = 2; i <= 1000000; i++) { op[i] = op[i - 1] * 2 + 1; op[i] %= 1000000007; } string s; cin >> s; long long cnt = 0; int a = 0; int b = 0; for (int i = 0; i < s.s...
#include <bits/stdc++.h> using namespace std; string rows[1000]; int dist[1000][1000]; bool disc[1000][1000]; int r, c; void bfs(int row, int col) { queue<pair<int, int> > q; q.push(make_pair(row, col)); while (!q.empty()) { pair<int, int> cur = q.front(); disc[cur.first][cur.second]...
#include <bits/stdc++.h> using namespace std; constexpr int mod = (int)998244353; long long mod_mul(long long a, long long b) { a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod; } long long mod_add(long long a, long long b) { a = a % mod; b = b % mod; return (((a + b) % m...
#include <bits/stdc++.h> using namespace std; bool flag = 0; int work(int a, int n, int p) { int t = a * 1ll * n / p; if (!t) { if (!flag) return a; return max(a, p - a * n); } flag = 1; int a1, n1, p1; a1 = min(p % a, a - (p % a)); n1 = t; p1 = a; if (a * 1ll * n %...
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define fast ios::sync_with_stdio(false);cin.tie(0); typedef long long ll; typedef long double ld; typedef unsigned long long ull; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); map<pair<in...
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 5; const int maxM = 1e6 + 5; const long long INF = 1e18; const long long MOD = 1e9 + 7; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long sq(long long x) { return (x * x) % MOD; } long long modP(long ...
#include <bits/stdc++.h> using namespace std; int n; const int prime[8] = {2, 3, 5, 7, 11, 13, 17, 19}; long long mul(long long x, long long y, long long mo) { long long ret = 1; while (y) { if (y % 2 == 1) ret = ret * x % mo; x = x * x % mo; y /= 2; } return ret; } bool is...
#include <bits/stdc++.h> const double INF = 1e18, eps = 1e-18; double a, b, c, x_1, y_1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, ans; double sqr(double x) { return x * x; } double dis(double x_1, double y_1, double x2, double y2) { return sqrt(sqr(x2 - x_1) + sqr(y_1 - y2)); } int main() { scanf( %l...
#include <bits/stdc++.h> struct Node; Node* null; struct Node { Node* insert(int l, int r, int k) { if (k < l || r < k) { return this; } if (l == r) { return new Node{count + 1, null, null}; } int m = l + r >> 1; return new Node{count + 1, left->insert(l, m,...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int T, n, m, u, v, sum, ans; int col[N]; bool vis[N]; int cnt, head[N]; struct edge { int next, to; } e[N << 1]; inline void add(int u, int v) { cnt++; e[cnt].next = head[u]; e[cnt].to = v; head[u] = cnt; } qu...
#include <bits/stdc++.h> using namespace std; long long n, d, a, b, p[100005], x[100005], y[100005], c, ans[100005]; long long cmp(long long A, long long B) { return x[A] * a + y[A] * b < x[B] * a + y[B] * b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> d; cin >> a ...
#include <bits/stdc++.h> using namespace std; string s; bool mark = false; int main() { cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 0 && mark == false) { mark = true; continue; } if (mark == false && i == s.size() - 1) return 0; cout << s[i]; ...
#include <bits/stdc++.h> using namespace std; int n, k; struct trie { int cnt, whole; trie *next[26]; trie() { cnt = 0; for (int i = 0; i < 26; ++i) next[i] = NULL; } } *root = new trie(); void ins(char *s) { trie *p = root; for (int i = 0; s[i]; ++i) { int c = s[i] -...
#include <bits/stdc++.h> using namespace std; function<void(void)> ____ = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }; const int MAXN = 4e5 + 7; int n; pair<int, int> A[MAXN]; struct Disjoint_Set_Union { int fa[MAXN], sz[MAXN]; void clear() { for (int i = ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int maxn = 300009; long long fac[maxn], invfac[maxn], A[33], B[33], in[maxn], idx[maxn]; vector<int> L[maxn], R[maxn]; int n, m; long long mpw(long long a, long long b) { long long c = 1; while (b) { if (b &...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e+18; int main() { cin.tie(0); ios::sync_with_stdio(0); int n, c = 0; cin >> n; while (n != 0) { string str = to_string(n); int maxi = 0; for (int i = 0; i < str.size(); i++) { if ((str[i] - 0 ) > m...
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point() {} Point(int a, int b) { x = a; y = b; } }; double hypt(Point A, Point B) { return sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y)); } int main() { int k, n; cin >> n >> k; v...