func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> #pragma comment(linker, /STACK:167177216 ) using namespace std; const long long MOD = 1000000000 + 7; int main() { ios::sync_with_stdio(false); string s; cin >> s; long long bcount = 0; long long ans = 0; for (int i = s.size() - 1; i >= 0; --i) { if (s[i] ...
#include <bits/stdc++.h> using namespace std; char a[1000005]; char l[1000005]; char r[1000005]; int f[1000005]; int okl[1000005]; int okr[1000005]; int mod = 998244353; char ss[2000005]; int heigh[2000005]; int sa[2000005]; int Rank[2000005]; int length; int val[30]; int c[2000005]; int...
#include <bits/stdc++.h> using namespace std; const int N = 510; const int mod = 1e9 + 7; long long mi1[N], mi[N], C[N][N], dp[N][N]; int main() { int n, m; scanf( %d%d , &n, &m); mi[0] = mi1[0] = 1; for (int i = 1; i <= n; i++) { mi[i] = mi[i - 1] * m % mod; mi1[i] = mi1[i - 1] * ...
#include <bits/stdc++.h> using namespace std; char s[1309]; bool a[5201][5201]; int n, i, j, k, f, dp[2][5201][5201]; int main() { for (scanf( %d , &n), i = 1; i <= n; ++i) for (scanf( %s , s), j = 0; s[j]; k = s[j] - ( 9 < s[j] ? A - 10 : 0 ), a[i][(j << 2) + 1] = 8 &...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; int m, v, m1, m2, v1, v2; cin >> a >> b >> c >> d; m1 = 3 * a / 10; m2 = a - (a / 250) * c; if (m1 > m2) m = m1; else m = m2; v1 = 3 * b / 10; v2 = b - (b / 250) * d; if (v1 > v2) v =...
#include <bits/stdc++.h> using namespace std; /** START OF DESPERATE OPTIMIZATION **/ #pragma GCC target ( avx2 ) #pragma GCC optimization ( O3 ) #pragma GCC optimization ( unroll-loops ) #include<bits/stdc++.h> using namespace std; using ll = long long; using LD = long double; const LD ...
#include <bits/stdc++.h> #pragma GCC optimise( ofast ) #pragma GCC optimise( unroll-loops ) using namespace std; const int N = 200000 + 10; const long long MOD = 1000000000 + 7; const long long INF = 1000000000000000000; const long long LOG = 25; int n, m, k, s1, s2, f, l[N], r[N], val[N], node[N], node...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2500 + 10; int n; pair<int, int> p[MAXN]; pair<int, int> sec[MAXN]; int sz; int half(pair<int, int> p) { assert(p.first || p.second); return p.second > 0 || (p.second == 0 && p.first < 0); } long long dot(pair<int, int> a, pair<int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; string s; cin >> s; long long int temp = 0; for (long long int i = 0; i < n - 1; i++) { if (s[i] > s[i + 1]) { cout << YES << endl <<...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 5; int n, S; int a[N]; long long now[N]; bool check(int x, int& ans2) { for (int i = 1; i <= n; i++) { now[i] = a[i] + 1ll * i * x; } sort(now + 1, now + 1 + n); long long sum = 0; for (int i = 1; i <= x; i++) { ...
#include <bits/stdc++.h> struct book { int t, w; bool operator<(const book &b) const { return w < b.w; } } ones[102], twos[102]; int main() { int n; scanf( %d , &n); int nOnes = 0; int tWidthOnes = 0; int nTwos = 0; int tWidthTwos = 0; for (int i = 0; i < n; i++) { int t,...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int oo = 1e9 + 5; struct seg { seg(int a, int x, int y) : A(a), first(x), second(y) {} int A; int first; int second; }; bool operator<(const seg &M, const seg &N) { return M.A < N.A; } set<seg> segs; int main()...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); int n; cin >> n; int arr[5001] = {0}; int ans = 0; for (int i = 0; i < n; i++) { int x; cin >> x; arr[x]++; } for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, l, j, k, i; cin >> n >> x; long long a[x + 1]; for (i = 1; i <= x; i++) { a[i] = 0; } for (i = 0; i < n; i++) { cin >> l; for (j = 0; j < l; j++) { cin >> k; a[k]++; } } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); string s; cin >> s; long long x = 1; long long zero = 0; set<char> q; bool h = 0, mn = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == ? ) { if (h) zero++; ...
#include <bits/stdc++.h> using namespace std; void fun(long long int n) { int count = 0; while (n) { if (n % 10 == 7 || n % 10 == 4) count++; n = n / 10; } if (count == 0) { cout << NO ; return; } while (count) { int r = count % 10; if (r != 7 && r != 4) ...
#include <bits/stdc++.h> int arr1[500005]; using namespace std; int main() { int t; cin >> t; for (int i = 1; i <= t; i++) { int a; cin >> a; arr1[a] = i; } long long int sum = 0; for (int i = 1; i < t; i++) { sum += abs(arr1[i] - arr1[i + 1]); } cout << sum...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n_Cases = 1; for (long long case_i = 1; case_i <= n_Cases; case_i++) { long long up, down; cin >> up >> down; long long n = up + down + 1; for (long long i = 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int a[N], b[N]; int main() { int i, j, n, m, k, t, x, y, p; long long ax, ay, tx, ty; while (~scanf( %d , &n)) { for (i = 0; i < n; i++) scanf( %d , &a[i]); scanf( %d , &m); for (i = 0; i < m; i++) scanf( %d , &b[i...
#include <bits/stdc++.h> using namespace std; int len; char s[109]; int main() { cin >> len; cin >> s; int interval = 0; for (int i = 0; i < len; i += interval) { cout << s[i]; interval++; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); queue<int> pos; int arr[n]; arr[0] = 0; int lastb = -1; for (int i = 0; i < n; i++) { if (s[i] == b ) { if (i + 3 < n) { if (s.substr(i, 4) == bear ) { ...
#include <bits/stdc++.h> using namespace std; long long p(long long b, long long e) { if (e == 0) return 1; if (e == 1) return b; if (e & 1) { return ((b % 998244353) * p((b * b) % 998244353, e / 2)) % 998244353; } return (p((b * b) % 998244353, e / 2)) % 998244353; } int32_t main() { ...
#include <bits/stdc++.h> using namespace std; const unsigned long long mod = 1000000007; int main() { int x, y; unsigned long long n = 0; cin >> x >> y; unsigned long long t = 0; int power = 2; for (int p = 0; p < 2200; p++) { if (power > y) break; t += y + 1 - power; pow...
#include <bits/stdc++.h> using namespace std; const int MAX = 200020; const long long MOD = (int)1e9 + 7; const int INF = 1e9; const long long LLINF = 0x3f3f3f3f3f3f3f3f; const long double EPS = 1e-7; void get_sub(string s, int size, set<string>& sub) { int n = s.size(); for (int l = 0, r = size -...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> void print(vector<T>& v, bool spaced = true) { int n = v.size(); string space = (spaced ? : ); for (int i = 0; i < n; ++i) { cout << v[i] << space; } cout << n ; } template <class T> vo...
#include <bits/stdc++.h> using namespace std; long long int mod1 = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long int t; t = 1; for (long long int f = 0; f < t; f++) { int n; cin >> n; string A; cin >> A; int i; int x = n - ...
#include <bits/stdc++.h> using namespace std; int g[25][25], n, p, i, T, j, k; bool FLAG; int main() { scanf( %d , &T); while (T--) { for (i = 1; i <= 24; i++) for (j = 1; j <= 24; j++) g[i][j] = 0; scanf( %d%d , &n, &p); for (i = 1; i <= 5; i++) for (j = i + 1; j <= 5;...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int n, long long int m); long long int power(long long int a, long long int n, long long int m) { if (n == 0) return 1; long long int x = power(a, n / 2, m); if (n % 2 != 0) return (((a * x) % m) * (x) %...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char ch; while (!isdigit(ch = getchar())) ; do { x = 10 * x + ch - 0 ; } while (isdigit(ch = getchar())); } const int N = 3e6 + 111; const int INF = 1e9; int n, q, D[N], res...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; scanf( %d%d%d%d%d%d , &a, &b, &c, &d, &e, &f); if (d == 0) { printf( Hermione ); return 0; } if (c == 0) { printf( Ron ); return 0; } if (b == 0) { printf( Hermione ); ret...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a1, a2; vector<int> b1, b2; int subsolve(vector<int>& box, vector<int>& spec) { int N = (int) box.size(); int M = (int) spec.size(); vector<int> good (M+5, 0); int cumulate = 0; for (int i=M-1; i>=0; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; long long int a[n + 1][n + 1]; long long int s = 0; for (int i = 1; i < n + 1; i++) for (int j = 1; j < n + 1; j++) { cin >> a[i][j]; if (i == j) s += a[i][j]; } s %= 2; lo...
#include <bits/stdc++.h> bool fine(int v) { int z = 0, s = 0; while ((v & 1) == 0) { z++; v >>= 1; } while ((v & 1) == 1) { s++; v >>= 1; } return v == 0 && z == s - 1; } int main() { int n; scanf( %d , &n); for (int i = n; i >= 1; i--) { if (n % i...
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <class T> bool umax(T &x, T y) { return y > x ? x = y, 1 : 0; } const int N = 505; int n, m, g[N][N][2]; bitset<N> dp[100][2][N], ok, tmp; signed main() { cin...
#include <bits/stdc++.h> using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ typedef long long ll; typedef long double ...
#include <bits/stdc++.h> using namespace std; int n, arr[101], color, maxi, mini = 101; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> color; for (int i = 0; i < n; i++) { cin >> arr[i]; mini = min(mini, arr[i]); maxi = max(maxi, arr[i]); } if (maxi - ...
#include <bits/stdc++.h> using namespace std; string S; struct State { char p[2][13]; }; int dx[5] = {1, 0, -1, 0, 1}, dy[8] = {0, 1, 0, -1, 1}; bool OK = false; int solve(State &E, int r1, int r2, int depth) { if (OK == true) return 1; if (depth == 27) { for (int i = 0; i < 26; i++) { ...
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; static inline int Rint() { struct X { int dig[256]; X() { for (int i = 0 ; i <= 9 ; ++i) dig[i] = 1; dig[ - ] = 1; } }; static X fuck; int s = 1, v = 0, c; for (; !fuck.dig[c = getchar...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); printf( %d n , (n & 1) ? (n - 1) + (n - 1) * ((n - 3) / 2) / 2 : (n - 2) * (n - 2) / 4 + (n - 2)); if (n & 1) { for (int i = 2; i <= n; i += 2) { printf( %d %d %d %d n , 3, 1, ...
#include <bits/stdc++.h> using namespace std; void in(int &x) { register int c = getchar(); x = 0; for (; (c < 48 || c > 57); c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; } } long long mod; bool prime(int n) { int i; if (n...
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const int mod = (int)1e9 + 7; const double PI = acos(-1.0); const int MAX = 400009; int n; char s[MAX], ans[MAX]; int occ[250]; int main(int argc, char* argv[]) { scanf( %d , &n); scanf( %s , s); for (int i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; long long n, p, i, t, ans, a[101]; char s[101]; int main() { scanf( %I64d%I64d , &n, &p); for (i = 1; i <= n; i++) { scanf( %s n , &s); if (strlen(s) > 4) a[i] = 1; } for (i = n; i; i--) { ans += t * p; if (a[i]) ans += p / 2;...
#include <bits/stdc++.h> using namespace std; char str[5009]; int main() { int a = 0, b = 0, c = 0, i; scanf( %s , str); int n = strlen(str); for (i = 0; str[i] == a ; i++) a++; for (; str[i] == b ; i++) b++; for (; str[i] == c ; i++) c++; if (a && b && n == a + b + c && (a == c || ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, temp; cin >> n; temp = n; vector<pair<long long, int> > v; for (int i = 2; i <= sqrt(n); i++) { int count = 0; while (temp % i == 0) { temp /= i; count++; } if (count != 0) v.push_back...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int k = 0; int i = 1; while (k < n) { if (i % 3 == 0 || to_string(i).back() == 3 ) { } else ...
#include <bits/stdc++.h> using namespace std; int arr[100000]; int n; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q; int rankHash[100000]; int indHash[100000]; vector<pair<int, int> > ans; int main(void) { scanf( %d , &n); for (int i ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; string str; cin >> n >> str; int a = 0; int d = 0; for (int i = 0; i < n; i++) { if (str[i] == A ) { a++; } else { d++; } } if (a > d) { ...
#include <bits/stdc++.h> using namespace std; map<int, int> cnt; int n; int m; int dp[500][100005]; vector<int> num; map<int, int> can; int ind = 0; int dpnum[500]; map<int, int> mpind; map<int, int> mpvis; int main() { scanf( %d%d , &n, &m); int x; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> bool local = false; using namespace std; template <class T> string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> void print(T v) { cout << ((int)(v).size()) << n ; for (auto x : v) cout << x << ; cout << n ; ...
#include <bits/stdc++.h> using namespace std; long long s[110000], a[110000]; int main() { int n; scanf( %d , &n); a[0] = 1; for (int i = 1; i <= 500; i++) a[i] = a[i - 1] * 2 % 1000000007; memset(s, 0, sizeof(s)); for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); if...
#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() {} }; struct cmp { bool operator()(point a, point b) { return (a.x < b.x); } }; struct vec { long long x, y; vec(long long _x, lo...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 125; const int maxm = 305; const int mod = 20090717; vector<int> v; int main() { long long x; scanf( %lld , &x); while (x > 0) v.push_back(x % 2), x /= 2; while (v.size() < 6) v.push_back(0); lon...
#include <bits/stdc++.h> void Solve(); int main() { Solve(); } using namespace std; const int INF = 1e9; const int N = 20; const double e = 1E-10; int hm, am, dm; int check(int ay, int dy) { int m = max(0, ay - dm), y = max(0, am - dy); if (!m) return -1; return (hm / m + (hm % m != 0)) * y ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; n /= k; if (n % 2) cout << YES << endl; else cout << NO << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long Ar[20] = {1, 1, 2, 3, 6, 40, 80, 1260, ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &k) { k = 0; int flag = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) flag = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { k = k * 10 + c - 0 ; c = getchar...
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[15][110], b[15][110], c[15][110]; char buf[15]; int calc(int p, int q) { static pair<int, int> d[110]; int cnt = k, res = 0; for (int i = 1; i <= m; i++) d[i].first = b[q][i] - a[p][i], d[i].second = c[p][i]; sort(d + 1, d ...
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll t; cin>>t; while(t--) { ll x,y; cin>>x>>y; if(x==y) { cout<<x+y<< n ; } else { cout<<2*max(x,y)-1<< n ; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x = 1; map<int, int> m; int y = 1; m[x] = 1; while (y < 1001) { m[y] = 1; int temp = y + x; x = y; y = temp; } m[y] = 1; for (int i = 1; i <= n; i++) { if (m[i] == 1)...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000100; const int INF = 1e9 + 10; int c, n; int a[maxn], b[maxn]; int cnt[maxn]; bool check(int anow, int &now) { int bnow = b[now] - anow; if (bnow <= 0) { if (now <= n && anow + 1 > a[now]) now++; return 0; } int...
#include <bits/stdc++.h> const int MAXN = int(2e5); int n, k, cnt, A, tot[2 * MAXN + 5]; bool flag; long long ans; int read(int &x) { char c = getchar(); int a = 0, b = 1; while ( 0 > c || c > 9 ) b = c == - ? -1 : b, c = getchar(); while ( 0 <= c && c <= 9 ) a = a * 10 + c - 0 , c = ge...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int n, m, k; const int maxn = 1100000; int has[maxn]; pair<int, int> buy[maxn]; int tmp[maxn * 2]; bool test(int mid) { for (int i = 1; i <= n; i++) tmp[i] = has[i]; for (int i = 1; i <= mid; i++) { tmp[i + n] = buy[...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, a, b, j, pos = 0, neg = 0, flag = 0, temp; string st, st2, st3; vector<long long int> v2, v; long long int ar[100001] = {0}; cin >> a >> b; if (a == 1) { cout << b; return 0; } else if (b == 1) ...
#include <bits/stdc++.h> using namespace std; long long ne(long long a) { long long k = pow(a, 0.5); if (k * k == a) { return 0; } return min(a - (k * k), (k + 1) * (k + 1) - a); } int main() { long long n; cin >> n; vector<pair<long long, long long> > a(n, make_pair(0, 0)); ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int nax = 1e6 + 10; vector<int> tree(4 * nax); long long i, j, x, y, k, val; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long r, g,...
#include <bits/stdc++.h> using namespace std; long long a, b, c, d; long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } int main() { scanf( %lld %lld %lld %lld , &a, &b, &c, &d); long long ans = gcd(c, d); long long ans1 = c / ans; long long ans2 = d / ans; ans = min(a ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int mod = (int)1e9 + 7; const int MAXN = (int)3e5 + 5; vector<int> primes[1000005]; int x, p, k; vector<pair<int, int> > v(1 << 7); int calc(int a) { int cnt = 1; int num = 0; int tmp = a; a = 0; for (int i...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e9 + 1; int a[201][201]; int cnt[10][10]; int calc(int x, int y) { if (x * 2 > y) return 500; else if (x * 4 > y) return 1000; else if (x * 8 > y) return 1500; else if (x * 16 > y) return 2000; else if ...
#include <bits/stdc++.h> using namespace std; long long powmod(long long base, long long exp) { base %= ((int)1e9 + 7); long long result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % ((int)1e9 + 7); base = (base * base) % ((int)1e9 + 7); exp >>= 1; } return res...
#include <bits/stdc++.h> using namespace std; int d, m, n, b[210000]; int top, s[210000]; struct node { int x, p; bool operator<(const node &a) const { return x < a.x; } } a[210000]; char Getchar() { static char now[1 << 20], *S, *T; if (T == S) { T = (S = now) + fread(now, 1, 1 << 20,...
#include <bits/stdc++.h> using namespace std; const int N = 1e5, M = 1e4, MOD = 1e9 + 7, INF = 0x3f3f3f3f; const double eps = 1e-8, pi = acos(-1.0); int n, m; vector<int> son[N + 10]; int col[N + 10]; int in[N + 10], out[N + 10], bel[N + 10]; int tot; int k[N + 10]; struct query { int l, r, id; ...
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m >> n; vector<int> sg(n, +1); for (int i = 1, x; i <= n; ++i) { cout << i << n ; fflush(stdout); cin >> x; if (x < 0) sg[i - 1] = -1; if (x == 0) return 0; } int l = n + 1, r = m, pt ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5, mod = 1e9 + 7; long long pwr(long long b, long long p) { long long res = 1; while (p) { if (p % 2) res = res * b % mod; b = b * b % mod; p /= 2; } return res; } long long k, n; string colors[] = { white , ...
#include <bits/stdc++.h> using namespace std; int main() { char c1, c2; int t, n1, n2, ans1, ans2; string s = ^>v< ; cin >> c1 >> c2 >> t; n1 = s.find(c1); n2 = s.find(c2); t = t % 4; ans1 = (n1 + t) % 4; ans2 = (n1 - t); if (ans2 < 0) ans2 += 4; if (ans1 == n2 && ans2 =...
#include <bits/stdc++.h> using namespace std; void upd(long long& x) { x = -x - 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> a(n); for (int j = 0; j < n; j++) { cin >> a[j]; if (a[j] >= 0) upd(a[j]); ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int N = 100010; int n; long long x, y, a[N]; void solve() { for (int i = 0; i < (int)(n); ++i) a[i] = 1; a[0] = y - n + 1; for (int i = 0; i < (int)(n); ++i) x -= ((a[i]) * (a[i])); i...
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const int maxn = 100010; int IN() { int c, f, x; while (!isdigit(c = getchar()) && c != - ) ; c == - ? (f = 1, x = 0) : (f = 0, x = c - 0 ); while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - 0 ; ...
#include <bits/stdc++.h> using namespace std; struct node { char name[55]; int score; int c[50]; } comp[55]; int cmp1(node x, node y) { if (x.score > y.score) return 1; else if (x.score == y.score) { for (int i = 0; i < 50; i++) if (x.c[i] > y.c[i]) return 1; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long k; cin >> k; if (k <= 36) { for (long long i = 1; i <= (k / 2); i++) { cout << 8; } if (k % 2 == 1) { cout << 4; } } else { cout...
#include <bits/stdc++.h> using namespace std; long long int getT(vector<vector<long long int>>&, int, int); void _dp(vector<vector<long long int>>& dp, int n) { for (int j = 0; j < n; j++) dp[0][j] = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 0; k < i; k++) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, a[101], x, y; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; cin >> m; while (m--) { cin >> x >> y; if (x != 1) a[x - 1] += y - 1; if (x != n) a[x + 1] += a[x] - y; a[x] = 0; } for (i = 1; i ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int maxn = (int)1e4 + 10; long long a[maxn], v[maxn], b[maxn]; long long gcd(long long A, long long B) { A = abs(A); B = abs(B); while (B != 0) ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int Ans[MAXN * 2], L, R, n; struct XY { int sz = 0, totid = 0, Ret, ll, rr; int las[MAXN * 10], top[MAXN], en[MAXN], pos[MAXN], siz[MAXN], dep[MAXN], fa[MAXN], deleted[MAXN * 3]; struct Edge { int to, pre; } e...
#include <bits/stdc++.h> using namespace std; int n, a[200007], q; int l[200007], r[200007], prime[1000007], id[1000007]; long long bit[200007], ans[200007], inv[1000007], prd[200007], divide[200007], cal[1000007]; vector<pair<int, int> > query[200007]; vector<int> dv[200007]; const long long mod = ...
#include <bits/stdc++.h> using namespace std; bitset<2005> a[2005]; int n, m, i, j, deg[2005], t, ans[2005], z[2005]; int main() { scanf( %d , &t); while (t--) { scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) { a[i].reset(); deg[i] = 0; } for (i = 1; i <= m; i++)...
#include <bits/stdc++.h> using namespace std; char inc(char &c) { char ret = c; if (c == z ) c = a ; else ++c; return ret; } int main() { int n; cin >> n; char t[4][n]; char c = a ; t[0][0] = t[1][0] = inc(c); for (int i = 1; i < n; ++i) { if (i % 2 =...
#include <bits/stdc++.h> using namespace std; const int MAX = 5e5 + 3; const long long MOD = 998244353; int board[4][52]; int n; vector<pair<int, pair<int, int> > > moves; bool flag; void make_move(int a, int b, int x, int y) { if (board[a][b] == 0 && board[x][y] == 0) return; moves.push_back( ...
#include <bits/stdc++.h> using namespace std; namespace NTT { const int P=998244353,g=3; const int W=22,S=1<<W; const int J=86583718; inline int add(int a,int b) {int r=a+b; return r<P?r:r-P;} inline int sub(int a,int b) {int r=a-b; return r<0?r+P:r;} inline int mul(long ...
#include <bits/stdc++.h> using namespace std; using LL = long long; const int N = 100005; LL a[N]; int main() { int t; scanf( %d , &t); while (t--) { int n; LL sum = 0; LL x; scanf( %d%lld , &n, &x); LL q = n; for (int i = 1; i <= n; ++i) { scanf( %lld ,...
#include <bits/stdc++.h> using namespace std; int num_q; int flag; long long u, v, w; map<long long, long long> hs; int main() { scanf( %d , &num_q); while (num_q--) { scanf( %d%lld%lld , &flag, &u, &v); if (flag == 1) { scanf( %lld , &w); while (u != v) { if (u...
#include <bits/stdc++.h> using namespace std; struct EDGE { int adj, next; } edge[810000]; int n, m, q, top, gh[510000]; int size[510000], dfn[510000], low[510000], cnt, ind, stop, instack[510000], stck[510000], belong[510000]; void addedge(int x, int y) { edge[++top].adj = y; edge[top].ne...
#include <bits/stdc++.h> using namespace std; int squ(vector<long long> &v) { for (int i = 0; i + 3 < v.size(); i++) { if (v[i] == v[i + 1] && v[i] == v[i + 2] && v[i] == v[i + 3]) return v[i]; } return -1; } vector<long long> pa(vector<long long> &v) { vector<long long> q; for (int i ...
#include <bits/stdc++.h> using namespace std; const int MN = 100011; const int inf = 1e9 + 7; int n, m; char c[1000][1000]; int main() { ios ::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = (1), _b = (n); i <= _b; ++i) for (int j = (1), _b = (m); j <= _b; ++j) cin >> c[i][...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int x[N], y[N]; vector<int> xx; vector<int> yy; int n; bool sameline(int tar, int p1, int p2) { return 1LL * (y[tar] - yy[p1]) * (x[tar] - xx[p2]) == 1LL * (y[tar] - yy[p2]) * (x[tar] - xx[p1]); } bool check(int p1, i...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(100, 0); int b; for (int i = 0; i < n; i++) { cin >> b; b--; a[b]++; } sort(a.begin(), a.end()); int s = 0; s = a[99] / k; if (a[99] % k > 0) { s++; }...
#include <bits/stdc++.h> using namespace std; long long a[65]; long long level(long long x) { int sum = 0; for (; x != 1; x /= 2) { sum++; } return sum; } void write(long long a) { if (a == 0) putchar( 0 ); else { static char c[20]; static int c0; c0 = 0; ...
#include <bits/stdc++.h> using namespace std; template <typename T> T fact(T n) { return (n == 1 || n == 0) ? 1 : n * fact(n - 1); } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int subarraysum(int arr[], int n, int sum) { int curr_sum = ar...
#include <bits/stdc++.h> using namespace std; const int N = 132674 + 10; int n, len[2]; int R[2][2 * N]; vector<pair<int, int> > open[2 * N], clos[2 * N]; struct Cord { int x1, asdioayseiowqe12, x2, y2; Cord() {} Cord(int x1, int asdioayseiowqe12, int x2, int y2) : x1(x1), asdioayseiowqe...
#include <bits/stdc++.h> using namespace std; struct hh { int num; int c; }; bool cmp(const hh p, const hh q) { return p.c < q.c; } int main() { int n, k; scanf( %d%d , &n, &k); hh a[1010], b[1010]; int i; int p = 0, q = 0; vector<int> ss[1010]; for (i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 2; long long arr[N]; long long pos[N]; long long chance[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t, i, j; long long n; cin >> n; for (i = 1; i <= n; i++) { cin >> arr[...