func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using std::max; using std::min; const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3f; __inline__ __attribute__((always_inline)) unsigned int rnd() { static unsigned int seed = 416; return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int N = 500005; const int MOD = 1e9 + 7; int i, n, m, k, rs, x, y; long long val[N]; map<int, int> p; map<long long, vector<pair<int, int>>> M...
#include <bits/stdc++.h> using namespace std; const int arr = 9e5 + 10; signed main() { long long a, b; cin >> a >> b; a = min(a, b); long long ans = 1; for (long long i = 1; i <= a; i++) ans *= i; cout << ans; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, a[maxn], b[maxn], v[maxn]; unordered_map<int, int> mp; void dfs(int x, int l, int r) { if (v[x] <= r && v[x] >= l) mp[v[x]] = 1; if (a[x] != -1) { if (l < v[x]) dfs(a[x], l, min(v[x] - 1, r)); } if (b[x] != -1)...
#include <bits/stdc++.h> using namespace std; const int N = 205; const int mod = 1e9 + 7; int n, m, t, q; vector<int> G[N]; map<int, int> M; set<int> S; int a[N], in[N], iinn[N], vis[N]; long long sum; void topsort(int id) { int cnt = 0; while (1) { for (int i = (1); i <= (n); i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int len; string s; cin >> len; cin >> s; vector<char> vect; while (len != 0) { if (len % 2 == 1) { vect.push_back(s[0]); } else { vect.insert(vect.begin(), s[0]); } s.erase(0, 1); len = s...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, d; vector<pair<int, int>> v; vector<int> ans; set<pair<int, int>> st; scanf( %d %d %d , &n, &m, &d); ans.resize(n); for (int i = 0; i < n; ++i) { int t; scanf( %d , &t); v.push_back(make_pair(t, i)); ...
#include <bits/stdc++.h> using namespace std; int main() { double d, h, v, e; cin >> d >> h >> v >> e; double V = e * 3.14159265358979 * (d / 2) * (d / 2); if (v <= V) { cout << NO ; } else { double S = 3.14159265358979 * (d / 2) * (d / 2) * h; cout << YES << endl << fixed <...
#include <bits/stdc++.h> using namespace std; int main() { iostream::sync_with_stdio(false); int n; cin >> n; vector<int> nums(n); map<int, int> counts; for (int i = 0; i < n; i++) { cin >> nums[i]; counts[nums[i]]++; } map<int, int> last; int k = 0, previous; for...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long n, ans = 0, cnt = 0; cin >> n; vector<long long> a(n), pref(n + 1); for (auto& i : a) cin >> i; pref[0] = a[0]; for (int i = 1; i < n; ++i) pref[i] += pref[i - 1] + a[i]; ...
#include <bits/stdc++.h> using namespace std; long long int a[100001]; long long int d[100001]; long long int n; long long int max(long long int x, long long int y) { if (x > y) return x; return y; } int main() { cin >> n; long long int i; long long int x; for (i = 0; i < n; ++i) {...
#include <bits/stdc++.h> using namespace std; long long n, i, j, m, x, c, count, nr, OK, suma, k, level, val, y[100], z; void inmultire_y(long long nr) { int i = 0; int j = 0; int Max = 0; for (; i < 100; i++) y[i] = 0; long long x2 = nr; int n = 0; while (x2) { n++; x2 /= ...
#include <algorithm> #include <array> #include <cassert> #include <chrono> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> using namespace ...
#include <bits/stdc++.h> using namespace std; int main() { double a, d, x, y, r; int i, n; scanf( %lf%lf%d , &a, &d, &n); for (i = 1; i <= n; i++) { r = fmod(i * d, 4 * a); if (r <= a) x = r, y = 0; else if (r <= 2 * a) x = a, y = r - a; else if (r <= 3 * a) ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool cap = false, low = false, num = false; for (int i = 0; i < s.size(); ++i) { if (s[i] >= a && s[i] <= z ) low = true; else if (s[i] >= A && s[i] <= Z ) cap = true; else if (s[i]...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 10; long long int vis[N]; vector<vector<int> > v; int dfs(int t) { vis[t] = 1; for (int i = 0; i < v[t].size(); i++) { if (vis[v[t][t]] == 0) { dfs(v[t][i]); } } return 0; } int gcd(int a, int b) { r...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ((void)0); ((void)0); ((void)0); int T, N, M1, M2, s, e; long long X; for (cin >> T; T--;) { M1 = M2 = 0x7fffffff; s = 0; e = 1e9; for (c...
#include <bits/stdc++.h> using namespace std; int sum(int n) { int c = 0; while (n > 0) { c += n % 10; n /= 10; } return c; } void showarr(int arr[], int n) { for (int i = 0; i < n; i++) { cout << arr[i] << ; } cout << n ; } int arr[8001], f[8001]; signed...
#include <bits/stdc++.h> using namespace std; inline int QuickPow(int x, int y) { int Res = 1, Temp = x; while (y) { if (y & 1) Res = Res * Temp % 1000000007; Temp = Temp * Temp % 1000000007; y /= 2; } return Res; } inline void Swap(int &x, int &y) { int Temp = x; x = y...
#include <bits/stdc++.h> struct compare { bool operator()(const int& l, const int& r) { return l > r; } }; using namespace std; priority_queue<int, vector<int>, compare> pq; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int...
#include <bits/stdc++.h> using namespace std; long double pi = 2.0 * acos(0.0); mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); long long int N; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int a, b, c, i, ...
#include<bits/stdc++.h> #define ll long long #define rep(A,B,C) for(A=B;A<C;++A) #define pii pair<int,int> #define pll pair<ll,ll> #define fi first #define se second #define all(A) A.begin(),A.end() using namespace std; ///////////////////////////////////////////////////// #define vv vec...
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; int sz[100005], answer[100005]; long long ans = 0; vector<int> spis; void clears(int v, int pr) { sz[v] = 1; int pos = -1; for (int i = 0; i < (int)g[v].size(); i++) { int u = g[v][i]; if (u == pr) pos = i; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; int main() { int mas[100000]; cin >> n; for (int i = 0; i < (n); i++) { scanf( %d , &mas[i]); if (i < n / 2) ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; int sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } int res = 0; for (int i = 0; i < n; i++) { if ((sum - arr[i]) % 2 == 0) res++; } cout << res <<...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, s; cin >> n >> s; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long l = 0, r = n, total = 0; while (l < r) { long long mid = (l + r) / 2; long...
#include <bits/stdc++.h> #define endl n using namespace std; typedef long long lld; void solve(){ int n; cin>>n; vector<lld> a(n+1), b(n+1), p(n+2,0); for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ cin>>b[i]; p[i]=a[i]*b[i...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long a, b, c, d; cin >> a >> b >> c >> d; if (a > (b * c)) { cout << (-1) << endl; continue; ...
#include <bits/stdc++.h> using namespace std; vector<int> V[500500]; vector<int> SV[500500]; vector<int> MAX1[500500], MAX2[500500], MIN1[500500], MIN2[500500]; vector<pair<int, int>> T; int R[505000]; int main() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc; cin >> tc; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000000 ) using namespace std; const double INF = 2e50; double sqr(double a) { return a * a; } int get_ch(double x, double y) { if (x <= 0 && y <= 0) return 1; if (x <= 0 && y >= 0) return 4; if (x >= 0 && y <= 0) return 2; retur...
#include <bits/stdc++.h> using namespace std; template <typename T> string tos(T a) { stringstream ss; string ret; ss << a; ss >> ret; return ret; } string st; int l, memo[1000009][2]; int get(int pos, int carry) { if (pos < 0) return carry; int &ret = memo[pos][carry]; if ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } signed main() { long long n; cin >> n; for (long long i = 0; i < n; i++) { long long a, b, c, d; cin >> a >> b >> c >> d; long...
#include <bits/stdc++.h> using namespace std; int main() { long long int n = 0, a = 0; cin >> n >> a; long long int ar[n]; long long int i = 0; for (i = 0; i < n; i++) cin >> ar[i]; long long int pos = a - 1; if (n == 1) { if (ar[0] == 1) cout << 1 << endl; else ...
#include <bits/stdc++.h> using namespace std; int arr[100][100]; int main() { int n, a, b; scanf( %d , &n); for (int i = 0; i < n * n; i++) { scanf( %d%d , &a, &b); if (!arr[a][b]) { printf( %d , i + 1); for (int y = 0; y <= n; y++) { arr[a][y] = 1; arr...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename A, typename B = A> using pr = pair<A, B>; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); cout << fixed << setprecision(10); int sy, a, b; cin >> sy >> a >> b; sy = -sy; int n; cin >>...
#include <bits/stdc++.h> using namespace std; const int limit = 3000000; const int tope = 100000; int absolut(int x) { if (x < 0) return -x; return x; } void die() { cout << -1 << endl; exit(0); } int n; int a[limit]; int b[limit]; int add[limit]; long long int nsol; vector<pai...
#include <bits/stdc++.h> using namespace std; priority_queue<int, vector<int>, greater<int> > q; int tar[100005]; int n, k, add; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> tar[i]; long long ans = 0; cin >> add; int tmp; for (int i = 1; i <= n; i++) { cin >> t...
#include <bits/stdc++.h> using namespace std; int tu(int val) { return (1 << val); } bool iset(int mask, int id) { if ((mask & tu(id)) != 0) return true; return false; } void doset(int &mask, int id) { mask |= tu(id); } void dounset(int &mask, int id) { mask = mask & (~tu(id)); } template <typenam...
#include <bits/stdc++.h> using namespace std; string ans_t = YES ; string ans_f = NO ; void judge(int n) { if (n < 6 + 10 + 14 + 1) { cout << ans_f << endl; } else { cout << ans_t << endl; int tmp = n - 6 - 10 - 14; if (tmp == 6 || tmp == 10 || tmp == 14) { cout << 6 1...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= ch == - , ch = getchar(); while (isdigit(ch)) x = 10 * x + ch - 0 , ch = getchar(); return f ? -x : x; } template <typename T> void print(T x) { if (x < 0) putc...
#include <bits/stdc++.h> using namespace std; const int HX = 0x3F3F3F3F; int n, m, p, q; long long k; int f[1111]; int main() { cin >> n >> m >> k; memset(f, 0x3F, sizeof f); for (int i = 0; i < (n); ++i) { cin >> p >> q; f[p] = min(f[p], q); } long long ans = 0; for (int...
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1000 * 100 + 100; int n, m, w[N], deg[N], ans[N]; vector<pair<int, int>> adj[N]; bool vis[N]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> w[i]; for (int i...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adj(601); vector<int> unvisited, even, odd; int d[601], parent[601]; bool visited[601]; map<vector<int>, int> M; void RemoveFromUnvisited(int v) { int i = 0; for (; i < unvisited.size() && unvisited[i] != v; ++i) ; unvisi...
#include <bits/stdc++.h> using namespace std; int pow2[30]; int ar[1000900], mark[1000090]; int main() { int n; int a, b; pow2[0] = 1; for (int i = 1, _n = 30; i < _n; i++) pow2[i] = pow2[i - 1] * 2; while (cin >> n) { memset(mark, -1, sizeof(mark)); int m = n - 1, r = 0; w...
#include <bits/stdc++.h> using namespace std; long long T, n, a[300010], c[300010], l[300010], r[300010]; long long lowbit(long long x) { return x & (-x); } void add(long long x, long long k) { for (long long i = x; i <= n; i += lowbit(i)) c[i] += k; } long long query(long long x) { long long sum = ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<pair<int, int> > v_p; int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x2 < x1) swap(x1, x2); if (y2 < y1) swap(y1, y2); for (int i = y1; i <= y2; i++) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; while (n--) { string s; cin >> s; int szs = s.size(); bool z = 0, e = 0; int sum = 0; for (int i = 0; i < szs; i++) { sum += s[i] - 0 ; e |= (!((s[i] -...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; namespace fastinput { inline int readChar(); template <class T = int> inline T readInt(); template <class T> inline void writeInt(T x, char end = 0); inline void writeChar(int x); inline void writeWord(const char *s); static cons...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; long long S[500005]; void add(int first, int a) { for (int i = first; i < 500005; i += i & -i) { S[i] += a; } } long long query(int first) { long long res = 0; for (int i = first; i > 0; i -= i & -i) { re...
#include <bits/stdc++.h> using namespace std; struct Node { int r, idx; } p, q, t; struct Fin { int x, y, z; Fin(){}; Fin(int _x, int _y, int _z) { x = _x, y = _y, z = _z; } }; bool operator<(Node a, Node b) { return a.r < b.r; } priority_queue<Node> que; vector<Fin> vec; vector<Node> ...
#include <bits/stdc++.h> using namespace std; int ok[1 << 20]; int F[1 << 9][1 << 9]; int d[1 << 9]; int bfs(int n) { d[0] = 0; for (int i = 1; i <= n; ++i) d[i] = -1; queue<int> Q; Q.push(0); while (!Q.empty() && d[n] == -1) { int node = Q.front(); Q.pop(); for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { string s; int pearls = 0, links = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == - ) links++; else pearls++; } if (pearls == 0) cout << yes << endl; else if (links % pearls == 0...
#include <bits/stdc++.h> using namespace std; using namespace std; int n, m, q; int a[210000]; int nxt[210000][20]; int loc[210000]; int p[210000]; int rp[210000]; int ans[210000]; pair<pair<int, int>, int> queries[210000]; int main() { scanf( %d %d %d , &n, &m, &q); for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct Matrix { long long a, b, c, d; Matrix(long long _a = 0, long long _b = 0, long long _c = 0, long long _d = 0) { a = _a; b = _b; c = _c; d = _d; } void normalize(Matrix& mat) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, p = 1e9 + 7; map<int, int> mp; char s[N]; inline void A(int &x, int y) { x = (x + y >= p ? x + y - p : x + y); } inline void Append(int w) { int v1 = 0, v2 = 0; map<int, int>::iterator it; for (it = mp.begin(); it != mp.end() ...
#include <bits/stdc++.h> using namespace std; vector<int> odd, even; int main() { int cnt1 = 0, cnt2 = 0, tem = -1; int n, k, p, x; scanf( %d%d%d , &n, &k, &p); for (int i = 0; i < n; i++) { scanf( %d , &x); if (x % 2 == 0) { cnt2++; even.push_back(x); } else { ...
#include<iostream> #include<stdio.h> using namespace std; int main() {long int max,x,y,t; cin>>t; while(t--) { cin>>x>>y; if(x==y) {cout<<2*x<<endl; continue; } max=x; if(x<y) { max=y; } cout<<2*max-1<<e...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; int L; int R; struct data { int u; int f; int dis; int dep; }; queue<data> q1, q2; struct ed { int v; int val; int siz; int ori; friend bool operator<(ed a, ed b) { return a.siz < b.siz; } ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long fact[200001], invfact[200001]; int n50 = 0, n100 = 0, k = 0; struct node { int l[2], r[2], b; }; long long nways[51][51][51][51][2], shortest[51][51][51][51][2]; queue<node> q; long long pmod(long long base, ...
#include <bits/stdc++.h> using namespace std; unsigned long xor128() { static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } double...
#include <bits/stdc++.h> using namespace std; int a[212345]; int cnts[212345]; int lft[212345]; int rght[212345]; int cumsum[212345]; int get_right_ans(int i) { return cumsum[rght[i]] - cumsum[i]; } int get_left_ans(int i) { if (lft[i]) return cumsum[i - 1] - cumsum[lft[i] - 1]; return cumsum[i ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e10; template <typename T> void cmax(T &a, T b) { a = max(a, b); } template <typename T> void cmin(T &a, T b) { a = min(a, b); } signed main() { string s; cin >> s; long long a[555...
#include <bits/stdc++.h> using namespace std; void solve(double S, double a, double b, double c, double* result) { if ((a == 0) && (b == 0) && (c == 0)) { result[0] = S; } else if ((a == 0) && (b == 0) && (c > 0)) { result[2] = S; } else if ((a == 0) && (b > 0) && (c == 0)) { result[1]...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0) return 0; return gcd(b % a, a) + b / a; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; while (n--) { int a, b; cin >> a >> b; cout << gc...
#include <bits/stdc++.h> using namespace std; long long p, ans, num; int n; string s[500000]; int main() { cin >> n >> p; p /= 2; for (int i = 1; i <= n; ++i) { cin >> s[i]; } for (int i = n; i >= 1; --i) { num *= 2; if (s[i] == halfplus ) num++; ans += num; } ...
#include <bits/stdc++.h> using namespace std; template <typename G1, typename G2 = G1, typename G3 = G1> struct triple { G1 first; G2 second; G3 T; }; const long double eps = 1e-12; int sign(long double x) { return x < -eps ? -1 : x > eps; } int dblcmp(long double x, long double y) { return si...
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; long long powmodM(long long a, long long b, long long c = M) { long long res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b /= 2; } return res; } long long power(long long a, long long b...
#include <bits/stdc++.h> using namespace std; vector<int> temp(100005); vector<int> v(100005); int fn(int l, int h, int x) { while (h - l > 1) { int mid = (h + l) / 2; if (temp[mid] >= x) { h = mid; } else { l = mid; } } if (temp[h] > x) return h; el...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long fastpower(long long x, long long n, long long M) { if (n == 0) return 1; else if (n % 2 == 0) return fastpower((x * x) % M, n / 2, M); else return (x * fastpower((x * x) % M, (n - 1) / 2, M)) % M; } lo...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int main() { int a, b, c, d; scanf( %d%d%d%d , &a, &b, &c, &d); if (a == 0 && b == 0 && c == 0 && d == 0) { printf( 1 n ); } else if (a == 0 && d == 0 && c != 0) { printf( 0 n ); } else if (a != d) { prin...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); long long n, a[5001], cnt = 1, maxn = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) cnt++; if (a[i] !...
#include <bits/stdc++.h> using namespace std; int main() { string s, ans, s1; cin >> s; s1 = s; int l = s.length(), i; int j = l - 1, flag = 0; while (i < j) { if (s[i] != s[j]) { flag = 1; break; } i++; j--; } if (flag) { reverse(s1.begi...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; s[0] = toupper(s[0]); cout << s << endl; return 0; }
#include <bits/stdc++.h> const long long md = 1e9 + 7; const int Inf = 1e9; const long long Inf64 = 1e18; const long long MaxN = 1e6 + 100; const long double eps = 1e-15; using namespace std; long long Tree[4 * MaxN]; long long getSum(long long l, long long r, long long x, long long y, ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const long long MOD = 1e9 + 7; long long a[200012]; long long in[200021], out[200012]; void solve() { long long n, m, i, j, c, sum; i = j = c = sum = 0; cin >> n; for (i = 0; i < n; ++i) { cin >> a[i]; --a[i...
#include <bits/stdc++.h> using namespace std; vector<int> prefix_function(const vector<int>& s) { int n = s.size(); vector<int> pi(n); for (int i = 1; i < n; ++i) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] == s[j]) ++j; pi[i] = j; } return ...
#include <bits/stdc++.h> using namespace std; vector<long long> arr; long long binarySearchCount(long long n, long long key) { long long left = 0, right = n; long long mid; while (left < right) { mid = (right + left) >> 1; if (arr[mid] == key) { while (mid + 1 < n && arr[mid + 1] =...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 2e5 + 5; inline int read() { int res = 0, ch, flag = 0; if ((ch = getchar()) == - ) flag = 1; else if (ch >= 0 && ch <= 9 ) res = ch - 0 ; while ((ch = getchar()) >= 0 && ch <= 9 ) res ...
#include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while(t--) { string s; cin >> s; cout << s.size() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string b; cin >> b; if (b == 1 ) { cout << 0 << endl; return 0; } int n = (int)((b).size()); string a((int)((b).size()), - ); bool flag = true; if (n > 2) { if (b[0] != 1 ) flag = false; for (__ty...
#include <bits/stdc++.h> using namespace std; const int seed = 131; const int maxn = 2e5 + 5; const int mod = 1e9 + 7; int n, k; char a[maxn]; int main() { scanf( %d%d , &n, &k); scanf( %s , a + 1); int cnt1 = 0; int cnt2 = 0; k /= 2; for (int i = 1; i <= n; i++) { if (cnt1 =...
#include <bits/stdc++.h> using namespace std; int byk[3][3]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == B ) byk[i % 3][0]++; if (s[i] == G ) byk[i % 3][1]...
#include <bits/stdc++.h> using namespace std; const long long INF = 501; const long long DIM = 3e5 + 1; int in, n, t, a[DIM]; int main() { ios_base::sync_with_stdio; cin.tie(0); cout.tie(0); in = scanf( %d , &t); while (t--) { in = scanf( %d , &n); set<int> s; for (int i ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, mod = 1e9 + 7; int a[N], st[N][20], pos[N][20]; int seg_query(int l, int r) { int k = log2(r - l + 1); if (st[l][k] > st[r - (1 << k) + 1][k]) return pos[l][k]; else return pos[r - (1 << k) + 1][k]; } long long f[N]...
#include <bits/stdc++.h> using namespace std; typedef struct graph { list<int> edges[1001]; } graph; void dfs(graph *g, int i, int group[], int gn) { for (list<int>::iterator it = g->edges[i].begin(); it != g->edges[i].end(); it++) { if (group[*it] == -1) { group[*it] = gn; ...
#include <bits/stdc++.h> using namespace std; map<vector<int>, int> m; int main() { int i, n, k; cin >> n; int array[n][2]; int ans = n; for (i = 0; i < n; i++) { cin >> array[i][0] >> array[i][1]; } cin >> k; for (i = 0; i < n; i++) { if (array[i][1] >= k) { br...
#include <bits/stdc++.h> using namespace std; const int N = 20; const int inf = 1e9; int dp[N][2]; vector<int> a; void upd(int& at, int val) { at = max(at, val); } int main() { long long n; scanf( %lld , &n); while (n) { a.push_back(n % 10); n /= 10; } for (int i = 0; i < N...
#include <bits/stdc++.h> using namespace std; const int N = 400004; const long long Mod = 1000000007; int Stop, Bcnt, Dindex, Ecnt; int Low[N], Dfn[N], Step[N], Belong[N]; bool instack[N]; struct Edge { int t; int next; } edge[N]; int head[N]; void addEdge(int s, int t) { edge[Ecnt].t = ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long maxn = 3 * 1e5 + 1; void swap(long long *xp, long long *yp) { long long temp = *xp; *xp = *yp; *yp = temp; } void print(vector<long long> v) { long long i, j, n = v.size(); for (i = 0; i < n; i++...
#include <bits/stdc++.h> using namespace std; int n, m, k, arr[1005][1005]; void ch_col(int x, int y) { for (int i = 1; i <= n; i++) swap(arr[i][x], arr[i][y]); } void ch_row(int x, int y) { for (int i = 1; i <= m; i++) swap(arr[x][i], arr[y][i]); } int row[1005], col[1005]; int main() { for...
#include <bits/stdc++.h> using namespace std; long long n, l, t, a[3000010], gx; double Ans; signed main() { scanf( %lld%lld%lld , &n, &l, &t); t *= 2; gx = t / l, t %= l; for (long long i = 1; i <= n; i++) scanf( %lld , &a[i + n]); for (long long i = 1; i <= n; i++) a[i] = a[i + n] - l; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000001; const long long mod = 1000000009; long long f[N]; long long getall(int m) { long long res = 2; for (int i = 1; i < m; ++i) res = (res * 2) % mod; return res - 1; } long long solve(int n, int m) { long long all = getall(m)...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, res = 0, m = 0, mx = 0; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n; i++) { int x = v[i], c = 1; for (int...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:102400000,102400000 ) const long long INF = 1e18 + 1LL; const double Pi = acos(-1.0); const int N = 3e3 + 10, M = 1e3 + 20, mod = 2017, inf = 2e9; int b[N][N], m, n, a[N][N]; vector<int> ans1, ans2, ans3, ans4; int main() { ...
#include <bits/stdc++.h> using namespace std; const int SIZE = 1e5 + 10; int a[SIZE]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T, n; cin >> T; while (T--) { cin >> n; vector<int> ans; for (int i = 1; i <= n; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; Point(long long x_, long long y_) { x = x_; y = y_; } Point() {} Point operator-(const Point &other) const { return Point(x - other.x, y - other.y); } long long dist(const Point &other) const {...
#include <bits/stdc++.h> using namespace std; int n, a[201], dp[201][201][1001]; const long long int MOD = 1e9 + 7; int solve(int i, int g, int k) { if (g < 0 || k < 0) return 0; if (i == n) return (g == 0); if (dp[i][g][k] != -1) return dp[i][g][k]; long long int ret = 0; int nk = k - g * (...
#include<stdio.h> #include<iostream> #include<string.h> #include<vector> #include<queue> #include<map> #include<math.h> #include<algorithm> #include<stdlib.h> #include<string> #include<stack> #include<set> using namespace std; #define pb push_back #define POP pop_back() #define DEBUG cout ...
#include <bits/stdc++.h> using namespace std; char s[120][120]; int n, m; int main() { int i, j, k, res = 30, now = 0; string ss = ; scanf( %d%d , &n, &m); for (i = 0; i < n; i++) scanf( %s , s[i]); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { char c = s[i][j]; ...
#include <bits/stdc++.h> using namespace std; bool within(int x1, int x2, int y1, int y2, int px, int py) { if (x1 <= px and px <= x2 and y1 <= py and py <= y2) { return true; } return false; } int main() { ios::sync_with_stdio(false); int y, x, v, n; cin >> y >> x >> v >> n; i...