func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> const long long MAX_N = 450 + 100; const long long MOD = 1e9 + 7; using namespace std; int main() { int n, k; cin >> n >> k; cout << 3 * n + min(k - 1, n - k); return 0; }
#include <bits/stdc++.h> using namespace std; int n; int m, q; int a[3]; string dday; int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; string tostring(int x) { string temp = ; for (int i = 0; i < 2; i++) { temp = (char)( 0 + x % 10) + temp; x /= 10; } return ...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); if (n == 0) { printf( 1 ); } else if (n % 2 == 0) { if (n % 4 == 0) { printf( 6 ); } else { printf( 4 ); } } else if (n % 2 != 0) { if (n % 4 == 1) { printf( 8 ); } else { ...
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; using ll = long long; using pii = pair<int, int>; constexpr double eps = 1e-8; constexpr int NINF = 0xc0c0c0c0; constexpr int INF = 0x3f3f3f3f; constexpr ll mod = 1e9 + 7; constexpr ll N ...
#include <bits/stdc++.h> using namespace std; inline int read() { int 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 * 10 + ch - 0 ; ch = getchar(); } return x * f;...
#include <bits/stdc++.h> using namespace std; const int oo = 1e9 + 5; const int N = 1e6 + 5; long long ans = 0; int main() { int n; cin >> n; int a[n + 1]; for (int(i) = (0); (i) < (n); i++) { cin >> a[i]; } sort(a, a + n); int x; x = (n - 1) / 2; cout << a[x]; re...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int n; cin >> n; int a[n]; bool ok = true; bool f = true; for (int i = 0; i < n; i++) { cin >> a[i]; if (!ok) continue; if (f && a[i] < i) { f =...
#include <bits/stdc++.h> using namespace std; map<char, int> mp1; int main() { ios_base::sync_with_stdio(0); string s, p, q; long long int a, b, c, d, i, j, k, u, v, w = 0, x, y, z; cin >> p; for (i = 0; i < p.length(); i++) mp1[p[i]] = 1; cin >> s; cin >> k; while (k--) { w ...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 7; const long long MOD = 1e9 + 7; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn], x[maxn], y[maxn], sk[maxn], top, cnt; int main() { int n, P, ly = -1, fl = 0; scanf( %d , &n), P = n; for (int i = 1; i <= n; i++) scanf( %d , a + i); for (int i = n; i >= 1; i--) { if (a[i] == 1) { ...
#include <bits/stdc++.h> using namespace std; struct point { double x, y; }; int main() { point p; double a, b, c, d; point v; scanf( %lf%lf%lf%lf%lf%lf%lf%lf , &p.x, &p.y, &v.x, &v.y, &a, &b, &c, &d); double lenth = sqrt(v.x * v.x + v.y * v.y); v.x /= lenth; v.y /= lenth; a ...
#include <bits/stdc++.h> using namespace std; long long N, M, K, R, l, r, A, B, X, Y, Z, C, D, Q, a, b, c, d, i, j, k, first, mx, ans, cnt, T, P; void solve() { cin >> N >> K; long long A[N]; long long lar = INT_MIN, sma = INT_MAX; for (long long int i = 0; i < N; i++) { cin >> A[i]; ...
#include <bits/stdc++.h> using namespace std; long long mini(long long a, long long b) { if (a < b) return a; return b; } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; sort(a.begin(), a.end()); rev...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long INFLL = 2e18; const int MOD = 1e8 + 7; const int N = 4e5 + 10; int fx[8] = {+0, +0, +1, -1, +1, +1, -1, -1}; int fy[8] = {+1, -1, +0, +0, +1, -1, +1, -1}; int timer; int used[N]; int tin[N], low[N]; char bridge; v...
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int a, b, c; cin >> a >> b >> c; int sum1 = a + b; int cnt = 0; while (sum1 <= c) { if (a > b) swap(a, b)...
#include <bits/stdc++.h> using namespace std; int g[100000]; int res[100000]; int main() { int N; scanf( %d , &N); ; g[0] = 0; g[1] = 0; res[0] = res[1] = -1; for (int(n) = 2; n < (int)N + 1; n++) { set<int> s; vector<int> v; for (int i = 2; i * i <= 2 * n; i++) { ...
// // main.cpp // D - Epic Transformation // // Created by LiZnB on 2021/3/25. // #include <cstdio> #include <cstring> #include <algorithm> #define ls tree[pos].l #define rs tree[pos].r using namespace std; const int INF = 0x3f3f3f3f; const int N = 200000 + 10; int arr[N]; s...
#include <bits/stdc++.h> using namespace std; int n, type[100001], a[100001], lead[100001], cur[100001]; bool vs[100001]; void input() { scanf( %d , &n); for (int i = 1, _b = n; i <= _b; i++) scanf( %d , &type[i]); int x; memset(lead, 0, sizeof(lead)); memset(a, 0, sizeof(a)); for (int i...
#include <bits/stdc++.h> using namespace std; struct stra { int x, y, z; } arr[100000]; bool cmp(stra a, stra b) { return a.x > b.x; } bool cmp1(stra a, stra b) { return a.y < b.y; } int n, k = 1, g = 1; int main() { std::ios::sync_with_stdio(false); cin >> n; for (int i = 0; i <= n - 1; i...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const long long N = 1e6 + 10; const long double eps = 1e-9; const long long inf = 1e18; long long a[N], b[N], c[N], d[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; ...
#include <bits/stdc++.h> using namespace std; double b[10], a[10], c[10] = {500, 1000, 1500, 2000, 2500}; double Max(double x, double y) { return x > y ? x : y; } int main() { int n, m1, m2, m3, m4, m5, i, j, k; while (~scanf( %lf , &a[0])) { for (i = 1; i < 5; i++) scanf( %lf , &a[i]); for ...
#include <bits/stdc++.h> using namespace std; void s() { puts( Stannis ); } void d() { puts( Daenerys ); } int main() { int n, k; scanf( %d %d , &n, &k); int odd = 0; int even = 0; long long tot = 0; for (int i = 0; i < n; i++) { int x; scanf( %d , &x); if (x % 2 == 0) ...
#include <bits/stdc++.h> using namespace std; const int N = 201110; int lab[N], val[N]; vector<int> gr[N]; map<string, int> mp; int n, m, q; int root(int u) { if (lab[u] < 0) return u; else return lab[u] = root(lab[u]); } void join(int type, int u, int v) { if (lab[u] < lab[v])...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; deque<int> dq; bool is[N], can[N]; vector<vector<int> > adj(N); int n, m, d, cur, mx, ans[N], x; void dfs(int u, int p) { ans[u] = ans[p] + 1; can[u] &= (ans[u] <= d); if (ans[u] > mx && is[u]) mx = ans[u], x = u; for (a...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100000; int n; int x[MAXN]; int ret[MAXN]; bool used[MAXN + 1]; void run() { scanf( %d , &n); for (int i = (0); i < (n); ++i) scanf( %d , &x[i]); mems...
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, line[35], column[35], var, count; cin >> n; for (i = 1; i <= n; ++i) line[i] = column[i] = 0; for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) { cin >> var; line[i] += var; column[j] += var; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 1020; int main() { int n; cin >> n; if (n % 2 == 0) { cout << -1 << endl; } else { cout << 0; for (int i = 1; i < n; i++) { cout << << i; } cout << endl; cout <...
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { if (a <= b) { return a; } else { return b; } } int max(int a, int b) { if (a >= b) { return a; } else { return b; } } int main() { int l, r, a; cin >> l >> r >> a; int MAX, MIN; ...
#include <bits/stdc++.h> using namespace std; int dp[1002][20002]; int main() { ios_base::sync_with_stdio; int n, m, x, y, i, j, a; cin >> n; long long ans = 0; for (i = 1; i <= n; i++) { cin >> a; dp[i][10000 + a]++; dp[i][10000 - a]++; for (j = 0; j < a; j++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 3; int n; vector<int> G[N]; int h[N], cnt[N]; int res = 0; void dfs(int u, int p) { cnt[h[u]]++; for (int v : G[u]) if (v != p) { h[v] = h[u] + 1; dfs(v, u); } } int main() { ios::sync_with_stdio(...
#include <bits/stdc++.h> using namespace std; inline int Max(int x, int y, int z) { return max(max(x, y), z); } const int N = 100005; int n, m; char s[N]; long long f[N][10]; int st[3], to[3]; long long ans; inline int R(int b, int a[3]) { if (a[1] != b && a[1] != b - 1) return 8; int x = (a[1...
#include <bits/stdc++.h> using namespace std; void frepn() { freopen( .in , r , stdin); freopen( .out , w , stdout); } const int N = 50500; const long long INF = (1e17) + 777; const int mod = (1e9) + 7; int n, a[N], k, t; int ans, ans2, a...
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e9+1; const ll mod=1e9+7; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m,k; cin>>n>>m>>k; int hori[n][m-1]; for(int i=0;i<n;i++){ for...
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - 0 + c, c = getchar(); x *= f; } const int N = 110...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) long long int power(long long int x, long long int n) { long long int result = 1; while (n) { if (n % 2 == 1) result = result * x; n = n / 2; x = x * x; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s = 0; bool kt; cin >> n >> m; char a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { kt = true; for (int j = 0; j < m...
#include <bits/stdc++.h> using namespace std; int n, ans, len; int a[2333]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); a[0] = 0; a[n + 1] = 1001; for (int i = 1; i <= n + 1; i++) { if (a[i] == a[i - 1] + 1) len++; else { ans = m...
#include <bits/stdc++.h> using namespace std; long long a[8][8], n, m, u, v, k = INT_MAX; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; cin >> n >> m; for (long long i = 0; i < m; i++) { cin >> u >> v; a[u][v] = 1; a[v][u] = 1; } if (n <= 6) ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 9; int n, p, q; string s, t, a, b; int c[2005], d[2005], h[2005], invH[2005], k[2005], invK[2005]; vector<pair<int, int>> memo; int mul(int aa, int bb) { return ((long long)aa * bb) % MOD; } int add(int aa, int bb) { return (aa + bb) % ...
#include <bits/stdc++.h> using namespace std; int n; long long a, b, x, vx, vy; map<long long, long long> mo; map<long long, long long>::iterator it; map<pair<long long, long long>, long long> ex; map<pair<long long, long long>, long long>::iterator ti; int main() { scanf( %d%I64d%I64d , &n, &a, &b)...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int N = 5005; int n, m; double ans, F[N][N]; bool vis[N][N]; double cal(double b, double x, double y, double ps) { return (1 - b) * ps * x + min(1 - ps, ps * b + (1 - ps) * (1 - y)); } double f(int a, int b, int fl) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; vector<long long int> v(n), vv; for (int i = 0; i < n; i++) cin >> v[i]; long long int mx = *max_element(v.begin(), v.end()); int len = 0, fg = 0; for (long long int i = 0; i < n; i++) { if (v[i] ...
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; int powmod(int a, int b) { int tmp = 1; a %= (1000000007); for (; b; b >>= 1) { if (b & 1) tmp = tmp * a % (1000000007); a = a * a % (1000000007); } return tmp; } long long gcd(l...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000 + 2; const int MAX_M = 100000 + 2; int weight[MAX_N]; struct Edge { int v, x; } E[MAX_M * 10]; int tot; template <int N> struct AdjList { int l[N]; inline void addEdge(int u, int v) { E[tot] = (Edge){v, l[u]}; ...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int MOD = 1e9 + 7; int n; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; cin >> n; int dp[] = {1, 0}; for (int i = 1; i < n; i++) dp[i % 2] = (dp[i % 2] + dp[1 - i % 2] + 1) % MOD; co...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, i = 0, j, k = 0, l = 0, m = 10e9, a = 0, b = 0, c, sum = 0, x = 0, y = 0, z = 0; cin >> n; long long arr[n + 1]; for (i = 1; i <= n; i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, i, j, q = 0; string s, k, p = go ; cin >> n >> s; vector<string> st(100); st[0] = ogo ; for (i = 1; i < 100; i++) { st[i] = st[i - 1] + p; } ...
#include <bits/stdc++.h> using namespace std; const int MAX = 60; const int A = 26; const int INF = 1000000001; char G[MAX + 2][MAX + 3]; int D[MAX + 2][MAX + 2]; bool ok[A + 1]; pair<int, int> S, T; vector<char> ans; vector<int> K; int n, m, k; inline int con(char c) { return a <= c && c <= ...
#include <bits/stdc++.h> using namespace std; char inp[2000]; int toNum(char x) { if (x >= 0 && x <= 9 ) return x - 0 ; return 10 + x - A ; } char toChar(int x) { if (x < 10) return 0 + x; return A + (x - 10); } long long ato10(int a) { int len = strlen(inp); int lw = 0; ...
#include <bits/stdc++.h> using namespace std; long long int k; long long int ways(long long int n) { long long int calc, ways = 0; for (int k = 2; k <= 10000000; k++) { calc = n / (1ll * k * k * k); ways += calc; if (calc == 0) { break; } } return ways; } long l...
#include <bits/stdc++.h> using namespace std; namespace whatever { const long long inf = 1000000000000000001ll; template <typename type> type read() { char ch = getchar(); while (!isdigit(ch)) ch = getchar(); type value = ch - 0 ; ch = getchar(); while (isdigit(ch)) { value = value ...
#include <bits/stdc++.h> const long long N = 2e5 + 17; using namespace std; long long i, mn, ans = 0, als = 0, v, ii, r4 = 0, r1, r2, r3, mx, p, q, d, l, r, m, n, k, j; string d1, d3, d2, s; char kl, km, mk, lk; double fg; int inout() { freopen( input.txt , r , stdin); freopen(...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 51; int n, x; int res[MAXN]; inline int read() { register int num = 0, neg = 1; register char ch = getchar(); while (!isdigit(ch) && ch != - ) { ch = getchar(); } if (ch == - ) { neg = -1; ch = getchar...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long sum = 0, sum2 = 0; scanf( %d , &n); int nav[200005]; for (int i = 0; i < n; i++) scanf( %d , &nav[i]), sum += nav[i]; for (int i = 0; i < n; i++) { sum2 += nav[i]; if (sum2 >= (sum + 1) / 2) { pri...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353, N = 3e5 + 6; long long n, k, t; void solve() { cin >> n >> k; long long t = 1; while (t * 10 <= n) t *= 10; while (k > 1) { t = 1; while (t * 10 <= n) t *= 10; while (n - t < k - 1) t /= 10; co...
#include <bits/stdc++.h> using namespace std; int main() { int n; int sa = 0, sb = 0; int ca, cb; char* c; int i = 0; scanf( %d , &n); c = (char*)malloc(sizeof(char) * n); while (n--) { scanf( %d %d , &ca, &cb); if (sb + cb > sa + 500) { sa = sa + ca; c[i+...
#include <bits/stdc++.h> using namespace std; void pause() {} bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) { return a.second > b.second; } int rec(int n, int i, int a[], int c) { c++; if (n == i) return c; rec(a[n - 1], i, a, c); } int main() { ios_base::sync_wi...
#include <bits/stdc++.h> using namespace std; int xx[8] = {0, 0, 1, -1, 1, -1, 1, -1}; int yy[8] = {-1, 1, 0, 0, 1, -1, -1, 1}; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int n; cin >> n; bool flag = true; vector<long long int> v(n); for (long ...
#include <bits/stdc++.h> using namespace std; int main() { int c, v0, v1, a, l; cin >> c >> v0 >> v1 >> a >> l; int d = 1; int r = v0; int tmp = v0; while (1) { if (r >= c) break; tmp = tmp + a; if (tmp > v1) tmp = v1; r += (tmp - l); d++; } cout << d <<...
#include <bits/stdc++.h> using namespace std; const int N = 2010; int n, a[N], m; double f[N][N], p, ans; inline int read() { int x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - 48, ch = getchar(); return x; } int main...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2200; char s[MAXN], t[MAXN]; int l[MAXN], r[MAXN]; int main() { int T; scanf( %d , &T); while (T--) { int n, k, m = 0; scanf( %d%d%s , &n, &k, s + 1); for (int i = 1; i < k; i++) t[2 * i - 1] = ( , t[2 * i] = ) ; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; long long mulmod(long long a, long long b, long long MOD) { if (b == 0) return 0; long long res = mulmod(a, b >> 1, MOD); res += res; res %= MOD; return (b & 1) ? (a + res) % MOD : res; } int main() {...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; map<long long, long long> row, col; row.clear(); col.clear(); long long aRow = 0, aCol = 0, res = n * n; while (k--) { long long x, y; cin >> x >> y; if (!row[x] && !col[y]) { ...
#include <bits/stdc++.h> using namespace std; void solve() { int l, r; cin >> l >> r; int a{r}, b{max(r / 2 + 1, l)}; cout << a % b << n ; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t{1}; cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, d, start = 0; cin >> n >> d; vector<string> s(d); for (string &e : s) cin >> e; vector<int> win(d); for (int i = 0; i < s.size(); i++) { string q = s[i]; if (q.find( 0 ) <= q.length()) { win[start]++; ...
#include <bits/stdc++.h> using namespace std; struct arra { long long int d = 0, idx; } arr[200008]; bool comp(struct arra a, struct arra b) { return a.d > b.d; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k, a, temp, ans; cin >> n >> k; ...
#include <bits/stdc++.h> using namespace std; bool solve(int cn) { int n, k; cin >> n >> k; vector<int> soldiers(n); for (int i = (0); i < (n); i++) cin >> soldiers[i]; soldiers.push_back(1 << 30); int coins = 0; while (soldiers[0] < k) { coins++; for (int i = (0); i < (n); i...
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; if (x == 1) cout << -1 << endl; else cout << x << << x << endl; return 0; }
#include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const int maxn = 105; int n, m, k; vector<set<int>> mp(maxn); vector<int> g, ans; int vis[maxn], pre[maxn], pres[maxn][maxn*maxn]; ll dp[maxn][maxn*maxn]; ...
#include <bits/stdc++.h> int CH, NEG; template <typename TP> inline void read(TP& ret) { ret = NEG = 0; while (CH = getchar(), CH < ! ) ; if (CH == - ) NEG = true, CH = getchar(); while (ret = ret * 10 + CH - 0 , CH = getchar(), CH > ! ) ; if (NEG) ret = -ret; } int n, data...
#include <bits/stdc++.h> using namespace std; long long s[100001]; int main() { int n, c = 1; long long sum = 0; cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; sort(s, s + n); sum += s[0]; for (int i = 1; i < n; i++) { if (sum <= s[i]) { c++; sum += s[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, tlen = 0, dir, i; string temp; cin >> n >> m >> k; cin >> temp >> temp; if (temp == head ) dir = -1; else dir = 1; cin >> temp; if (m < k) m = 1; else m = n; for (i = 0; i < temp....
#include <bits/stdc++.h> using namespace std; vector<long long> factors(long long n) { vector<long long> first; long long tem = 1; for (long long x = 2; x * x <= n; x++) { while (n % x == 0) { first.push_back(x); n /= x; } } if (n > 1) first.push_back(n); return f...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } int n, cnt[100010]; int main() { scanf( %d , &n); set<int> s; for (int i...
#include <bits/stdc++.h> using namespace std; int n, a[200200]; int main() { int i, j; scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &a[i]); } for (i = 1; i < n; i++) { if (a[i] % 2) { a[i] = 1; if (a[i + 1] == 0) { cout << NO ; return...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; const int M = 1000000007; const double PI = atan(1) * 4; const int oo = 1000000000; long long A, B, n, x; long long pw(long long x, long long p) { if (!p) return 1; long long d = pw(x, p / 2); d = (d * d) % M; if (p %...
#include <bits/stdc++.h> using namespace std; const double PI = M_PI; const int INF = -1 * 1e9; const long long limit = 1 * 1e12; const int MOD1 = 1e9 + 711; const int MOD2 = 1e9 + 933; const int MOD3 = 1e9 + 993; const int maxn = 1e6 + 100; int main() { cout.tie(0); cin.tie(0); ios_base::...
#include <bits/stdc++.h> using namespace std; long long ax, ay, bx, by, cx, cy; int solve(long long x2, long long y2) { if (cx == 0 && cy == 0) { if (x2 == 0 && y2 == 0) return 1; return 0; } else if (cx == 0) { long long g, h; g = x2 / cy; h = y2 / cy; if (g * cy == x2...
#include <bits/stdc++.h> using namespace std; int g[100100]; int suff[100100]; char S[1024]; set<int> crim; char T[100100]; int R[100100], neg[100100]; int main() { int n, m, tot = 0; scanf( %d , &n); scanf( %d , &m); for (int i = 0; i < n; i++) { scanf( %s , S); int l = strl...
#include <bits/stdc++.h> using namespace std; int su[3000000]; vector<int> vec; int vv[3000010]; int main() { memset(su, 0, sizeof(su)); memset(vv, 0, sizeof(vv)); vec.push_back(2); for (int i = 3; i <= 2750131; i++) { for (int j = 0; j < vec.size(); j++) { if (vec[j] * vec[j] > ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; vector<pair<int, int>> d(n); for (auto &i : d) cin >> i.first, i.second = &i - &d[0] + 1; sort(d.begin(), d.end()); vector<pair<int, int>> e; vector<int> a; a.pus...
#include <bits/stdc++.h> int main() { int count, i, a, x, max, tc; scanf( %d , &tc); for (int j = 0; j < tc; j++) { count = 0, max = 0; scanf( %d , &x); char s[x]; scanf( %s , s); for (i = x - 1; i >= 0; i--) { if (s[i] == P ) { count += 1; } else {...
#include <bits/stdc++.h> using namespace std; const int M = 23e4 + 5; int sum[M], n, fen[M]; int Get(int p) { int u = p; int ans = 0; for (; p > 0; p -= p & -p) ans += fen[p]; for (u++; u < M; u += u & -u) fen[u]++; return ans; } int get(int p) { int cur = 0; for (int i = 17; ~i;...
#include <bits/stdc++.h> using namespace std; string s; long long pos = -1; const long long N = 5005; long long gundy[N]; long long mex[N]; void game() { long long len = s.length(); long long totXo = 0; gundy[0] = 0; for (long long i = 1; i < N; i++) { for (long long j = 0; j < N; j+...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; long long a = 0; long long ret = 0; long long x = n; while (x >= 10) { a = a * 10 + 9; ret += 9; x /= 10; } long long...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long int n, z = 0, o = 0; cin >> n; string s; cin >> s; if (n == 1) { cout << s << endl; ...
#include <bits/stdc++.h> using namespace std; const int S = 100003; const int MOD = 1e9 + 7; const double pi = 2 * acos(0.0); inline int _Int() { int x; scanf( %d , &x); return x; } inline long long _LLi() { long long x; scanf( %lld , &x); return x; } void pruts() { puts( N...
#include <bits/stdc++.h> using namespace std; long long n, k, A, B, ans = 0; long long fmin() { long long pros = (n - (n / k)) * A; if (B < pros) { n = n / k; return B; } else { n = n / k; return pros; } } int main() { cin >> n; cin >> k; cin >> A; cin >...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, t = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) t = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(); r...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const double EPS = 1e-9; const int INF = 1 << 29; int main() { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int x, y; cin >> x >> y; int dx = abs(x1 - x2), dy = abs(y1 - y2); if (dx % x || dy % y) { puts( ...
#include <bits/stdc++.h> using namespace std; int a, s, d[100002], f, g, h, j, k, l, i, n, m; string x; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> d[i]; } for (i = 0; i < n; i++) { scanf( n ); getline(cin, x); for (a = 0; a < x.size(); a++) { if (x[a...
#include <bits/stdc++.h> using namespace std; bool v[1005][1005][4][3]; char grid[1005][1005]; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int n, m; int xx, yy; bool dfs(int x, int y, int dir, int turns) { if (x < 0 || x == n || y < 0 || y == m || turns > 2 || grid[x][y] == * ) return...
#include <bits/stdc++.h> using namespace std; const int maxn = 300000; vector<long long> st; void add(vector<long long>& st, int x, long long inc) { while (x < st.size()) { st[x] += inc; x |= x + 1; } } long long sum(const vector<long long>& st, int x) { long long s = 0; while (x...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; void dfs(long long int par, long long int node, vector<pair<long long int, string>> adj[], vector<long long int> &nodes, vector<bool> &visited) { visited[node] = true; nodes.push_back(node); for (auto child ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 * 100 + 10; int a[MAXN], b[MAXN]; int dp[MAXN][310]; vector<int> vec1[MAXN], vec[MAXN]; long long n, m, second, E; bool ok(int k) { long long need = second; for (int i = k - 1; i < n; i++) if (dp[i][k] < m) need = min(need, ...
#include <bits/stdc++.h> using namespace std; inline int readInt() { char c; int tmp = 0, x = 1; c = getchar(); while (c > 9 || c < 0 ) { if (c == - ) x = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { tmp = tmp * 10 + c - 0 ; c = getchar(); } return...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int pre[N], rak[N]; int find(int first) { if (pre[first] == -1) return first; return pre[first] = find(pre[first]); } void unions(int first, int second) { first = find(first); second = find(second); if (first == second)...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; int t; void solve(); struct Node { long long q, w, e, r, t; }; int n; vector<Node> a; vector<bool> ans; int res = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(0); t = 1; for (...
#include <bits/stdc++.h> int main(void) { int w = 1; int h = 1; int n = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { char op[10] = {0}; scanf( %s , op); if (strcmp(op, UL ) == 0 || strcmp(op, DR ) == 0) w++; else if (strcmp(op, UR ) == 0 || strcmp(op, DL ) ...