func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 10; long long ans[M << 2], tag[M << 2]; int a[M], p[M]; void push_up(int p) { ans[p] = min(ans[p << 1], ans[p << 1 | 1]); } void ps(int p, int l, int r, long long x) { ans[p] += x; tag[p] += x; } void push_down(int p, int l, int r...
#include <bits/stdc++.h> using namespace std; const int N = 9; const double eps = 1e-11; const int inf = (int)2e9; const int mod = (int)1e9 + 7; const double pi = 3.1415926535897932384626433832795; int a[N]; int main() { int n, k; scanf( %d %d , &n, &k); int ex = 0; for (int i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; int main() { int h, n, a, c = 0; cin >> n >> h; for (int l = 0; l < n; ++l) { cin >> a; if (a <= h) { c++; } else c += 2; } cout << c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; int dir[405][405], dic[405][405]; int main() { memset(dir, 63, sizeof(dir)); memset(dic, 63, sizeof(dic)); scanf( %d %d , &n, &m); for (int i = 1, x, y; i <= m; i++) { scanf( %d %d , &x, &y); dir[x][y] = dir[y][x] = 1; } ...
#include <bits/stdc++.h> using namespace std; int n, d[100001], b[100001], x, ans = 0; int main() { scanf( %d , &n); for (int i = 1; i < n; i++) { scanf( %d , &x); d[i] = d[--x] + 1; b[d[i]]++; } for (int i = 1; i < n; i++) ans += b[i] % 2; printf( %d , ans + 1); return 0...
#include <bits/stdc++.h> using namespace std; int n; char promocode[1100][10]; int strdif(char a[], char b[]) { int cnt = 0; for (int ii = 0; ii < 6; ii++) { if (a[ii] != b[ii]) cnt++; } return cnt; } int main() { scanf( %d n , &n); for (int ii = 1; ii <= n; ii++) { scanf...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int y = 1; for (; y <= n / 2 + 1; y++) { for (int x = 1; x <= n; x++) { if (x <= n / 2 + 1 - y || x >= n / 2 + 1 + y) cout << * ; else cout << D ; } ...
#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 ans; ans = (n - 2) * (n - 2); cout << ans << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1605; int n, m, tot; int a[MAXN][MAXN]; int sz[MAXN * MAXN]; int ans[MAXN * MAXN]; int cnt[MAXN * MAXN]; int fa1[MAXN * MAXN]; int fa2[MAXN * MAXN]; double v[MAXN][MAXN]; double t[MAXN][MAXN]; int getroot(int *fa, int u) { return...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int main() { int n, k; scanf( %d %d , &n, &k); vector<int> A(n), acc(n); for (int i = (0); i < (n); ++i) cin >> A[i]; acc[0] = A[0]; for (int i = (1); i < (n); ++i) acc[i] = A[i] + acc[i - 1]; int rsp = -inf; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; struct node { int v, w, next; } edges[maxn << 2]; int head[maxn], cnt; int n, k; void add_edge(int u, int v, int w) { edges[++cnt] = {v, w, head[u]}; head[u] = cnt; } long long dp[maxn][2]; void dfs(int rt, int fa) ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } inline int read() { int res = 0, fl = 1; char r = getchar(...
#include <bits/stdc++.h> using namespace std; struct node { node *bit[2]; int cnt = 0; int index = -1; }; node *root; void insert(string &s, int id) { node *cur = root; for (char x : s) { int ch = x - 0 ; if (!cur->bit[ch]) cur->bit[ch] = new node(); cur = cur->bit[ch]; ...
#include <bits/stdc++.h> using namespace std; int a[200020], b[200020], c[200020]; int main(void) { int n, k; int m; int i; int o; scanf( %d %d , &n, &k); for (i = 1; i <= n; i++) scanf( %d , &a[i]); for (i = 1; i <= n; i++) scanf( %d , &b[i]); for (i = 1, m = o = 0; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; char ans[100010 * 100]; char s[100010 * 10]; int f[100010 * 100]; int getf(int k) { return k == f[k] ? k : f[k] = getf(f[k]); } int main() { int n, k, LEN = 0, id; cin >> n; for (int i = 0; i < 100010 * 100; i++) f[i] = i; for (int i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; void foobar() { long long int n, i; cin >> n; vector<long long int> arr(n); long long int mm = INT_MAX; for (i = 0; i < n; ++i) { cin >> arr[i]; mm = min(mm, arr[i]); } for (i = 0; i < n; ++i) { arr[i] -= mm; if (arr[i...
#include <bits/stdc++.h> using namespace std; int main() { ofstream out( output.txt ); auto start = chrono::high_resolution_clock::now(); long long t = 1; for (long long test = 1; test <= t; test++) { long long n; cin >> n; vector<long long> a(n); pair<long long, long long> b...
#include <bits/stdc++.h> using namespace std; const int N = 500043; const int K = 750; int a[N]; int sum[K][K]; int main() { int q; scanf( %d , &q); for (int i = 0; i < q; i++) { int t, x, y; scanf( %d %d %d , &t, &x, &y); if (t == 1) { a[x] += y; for (int i = 1...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool cmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool cmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } int read() { int x = 0, f = 1; char ch; for (ch = getchar(...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.length(); int x = t.length(); vector<int> lft(x); vector<int> rgt(x); int l = 0; for (int i = 0; i < n && l < x; ++i) { if (s[i] == t[l]) { lft[l++] = i; } } l...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, i; cin >> a >> b; int arr[a + 1]; for (i = 1; i <= a; i++) cin >> arr[i]; for (i = 1; i <= a; i++) { b -= (86400 - arr[i]); if (b <= 0) break; } cout << i << endl; }
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } signed main() { std::ios::sync_with_stdio(false); cin.tie(N...
#include <bits/stdc++.h> using namespace std; vector<int> primes; int dp[101][1 << 18], n, a[111], man, ansd[111], loc[100]; vector<int> fact[100]; int rec(int i, int mask) { if (i == n) return 0; if (dp[i][mask] != 1000000000) return dp[i][mask]; int dif = abs(a[i] - 1); int ans = rec(i + 1, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 10; string a[maxn], ans[maxn]; int main() { int n; while (cin >> n) { int cnt[2][26]; memset(cnt, 0, sizeof cnt); for (int i = 0; i < n; ++i) cin >> a[i], ++cnt[0][a[i][0] - A ]; multiset<string> Q; for (...
#include <bits/stdc++.h> using namespace std; bool check(int left, int right, int m) { left ^= right; if (left > m) return false; else return true; } void solve() { int n, m; cin >> n >> m; if (n > m) { cout << 0 << n ; return; } int ans = 0; for (in...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100 * 1000 + 10; const int inf = (int)1e9; const double eps = 1e-6; int main() { int r, g, b; cin >> r >> g >> b; int rr = (((r + 1) / 2) - 1) * 3 + 30; int gg = (((g + 1) / 2) - 1) * 3 + 31; int bb = (((b + 1) / 2) - 1) * 3 +...
#include <bits/stdc++.h> using namespace std; const int SOURCE = 0, SINK = 1; struct edge { int to, idx, cap; }; vector<vector<edge>> adj; vector<int> lvl, ptr; int totalflow; int dfs(int n, int f) { if (n == SINK) { totalflow += f; return f; } if (lvl[n] == lvl[SINK]) return...
#include <bits/stdc++.h> using namespace std; class TwoSAT { private: const static int maxm = 100010 * 2; int S[maxm], c; vector<int> G[maxm]; bool DFS(int u) { if (vis[u ^ 1]) return false; if (vis[u]) return true; vis[u] = 1; S[c++] = u; for (auto &v : G[u]) ...
#include <bits/stdc++.h> using namespace std; double d, h, v, e; int main() { ios_base::sync_with_stdio(false); cin >> d >> h >> v >> e; v = v / (acos(-1) * d * d / 4); double t = h / (v - e); if (t < 0 || fabs(v - e) < 1e-8) { printf( NO n ); return 0; } printf( YES n%.12l...
#include <bits/stdc++.h> using namespace std; using namespace std; inline int read() { char ch; bool sign = 0; int res = 0; while (!isdigit(ch = getchar())) if (ch == - ) sign = 1; while (isdigit(ch)) res = res * 10 + (ch ^ 48), ch = getchar(); if (sign) return -res; else ...
#include <bits/stdc++.h> using namespace std; map<long long, long long> zipx; long long unzipx[2000]; long long inf = 1LL << 50; long long compressx(vector<long long>& x) { sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); for (long long i = 0; i < x.size(); i++) { zipx...
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> mapa; vector<int> tab; int main() { ios_base::sync_with_stdio(false); int n, k, a; cin >> n >> k; int aktIlosc = n; for (int i = 0; i < n; i++) { cin >> a; if (mapa[a] == 0) tab.push_back(a); mapa[a]++; ...
#include <bits/stdc++.h> using namespace std; using namespace chrono; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _p...
#include <bits/stdc++.h> using namespace std; char dif(char c1) { if (c1 == a ) return b ; return a ; } char dif2(char c1, char c2) { if (c1 != a && c2 != a ) return a ; if (c1 != b && c2 != b ) return b ; return c ; } int main() { int n, t; cin >> n >> t; string ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; const long long mod = 998244353; int n, m, k, x; bool a[55][maxn]; int main() { scanf( %d%d , &m, &n); for (int i = 1; i <= (m); i++) { scanf( %d , &k); for (int j = 1; j <= (k); j++) { scanf( %d , &x); ...
#include <bits/stdc++.h> using namespace std; int sum(long int c) { int somme = 0; while (c) { somme = somme + c % 10; c = c / 10; } return (somme); } int main() { long int k, c = 19; cin >> k; while (k) { if (sum(c) == 10) k--; c += 9; } cout << c - 9...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int M = 100005; const int MOD = 1e9 + 7; long long c[100005], x, k, tot = 0; vector<long long> son[100005]; void dfs(int n, int m) { if (tot >= 100000) return; if (n == 0 || m == 0) { printf( %I64d , c[n]); ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; const double PI = acos(-1.0); long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } pair<long long, int> all[2000111]; long long cntA, cntB; int cnt; int main() { long...
#include <bits/stdc++.h> long long R = 7 + 1e9, NUMTESTCASE; const int NN = 10 + 1e5; const double pi = acos(-1.0); int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1}, DI[8] = {1, 1, 0, -1, -1, -1, 0, 1}, DJ[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; int main() { int x, t, n, mx, k; ...
#include <bits/stdc++.h> using namespace std; int stop, n, k, x, i, ind, j, y[1000001], mini[2001][2001]; string s[2001]; struct name { int a[26]; int cnt; } trie[1000001]; vector<int> d[1000001]; int m; void add(int v, int pos) { if (pos > s[i].length()) return; if (trie[v].a[s[i][pos] ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); vector<int> vet, mat; int n, x; cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x != 0) vet.push_back(x); } for (int i = 0; i < n; i++) { cin >> x; if (x != 0) mat.push_b...
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return a < b; } int main() { stack<int> s; int N, t; cin >> N; while (N--) { cin >> t; if (s.empty()) { s.push(t); } else { if (((s.top()) & 1) == (t & 1)) s.pop(); else ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using vpii = vector<pair<int, int>>; using vpll = vec...
#include <bits/stdc++.h> int n, h; char name[10]; long double p[70], cont[70]; int main() { scanf( %s%d%d , name, &n, &h); if (name[0] == B ) { printf( %d n , n); return 0; } long double ans = n; p[0] = cont[0] = 1.0; for (int i = 1; i <= h; i++) { p[i] = p[i - 1] / 2....
#include <bits/stdc++.h> using namespace std; long long n, m, c1, c2, v, q; long long xs, xe, ye, ys; long long pos1[100005]; long long pos2[100005]; long long solve(int pos, int v) { long long ans = abs(pos - xe) + abs(pos - xs); long long y = abs(ye - ys); ans += (y - 1) / v + 1; return an...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int n, m, q, p[N], dis[N], far, cur, sz[N]; vector<int> g[N]; unordered_map<int, double> dp[N]; vector<pair<int, long long>> v[N]; int get(int u) { return p[u] == u ? u : p[u] = get(p[u]); } void dfs(int u, int p, int depth) { dis[...
#include <bits/stdc++.h> using namespace std; int n, m, k, arr[105][105]; int check(int c[105], int ctC, int secRow) { int ans = INT_MAX; if (ctC > 10) return ans; for (int i = 0; i < (1 << ctC); i++) { int ct = 0; for (int r = 2; r <= n; r++) { if (r != secRow) { int sam...
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i,n) for(int i=0;i<n;i++) #define endl ( n ) #define pb push_back #define mp make_pair #define pl pair<ll, ll> #define vl vector<ll> #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define M 1000000007 ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 7; const int M = 60; const int inf = 1e9 + 7; const long long base = 1e18; const double pi = acos(-1); const double ep = 1e-18; int n; int a[N]; void solve() { cin >> n; for (int i = 0; i < n; i++) scanf( %d , a + i); int ...
#include <bits/stdc++.h> int main() { long long a, b, c; scanf( %lld %lld , &a, &b); c = (b > (a + 1) / 2) ? 2 * (b - (a + 1) / 2) : 2 * b - 1; printf( %lld , c); return 0; }
#include <bits/stdc++.h> using namespace std; long long x; int n, d; struct cmp { bool operator()(pair<int, int> x, pair<int, int> y) { return x.first > y.first; } }; set<pair<int, int>, cmp> que; set<pair<int, int>, cmp>::iterator it; vector<int> num; int a[100005], c[100005]; bool b[...
#include <bits/stdc++.h> using namespace std; string yes = YES , no = NO ; void solve() { long long n, k; scanf( %lli%lli , &n, &k); long long qwe = n - k + 1; long long rty = n - 2 * k + 2; if (qwe > 0 and qwe % 2 == 1) { cout << yes << endl; for (int i = 0; i < k - 1; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 400; int n, m, wynik, A[N], B[N]; map<double, bitset<120> > mapa; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> A[i]; for (int i = 1; i <= m; i++) cin >> B[i]; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long double pi = acos(-1); const long long maxn = 200001; template <class T> ostream &operator<<(ostream &out, vector<T> &A) { for (auto x : A) out << x << ; return out; } template <class T1, class T2> T1 ...
#include <bits/stdc++.h> using namespace std; int mp[2123][2123]; int prehb[2123][2123]; int prehs[2123][2123]; int prelb[2123][2123]; int prels[2123][2123]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { map...
#include <bits/stdc++.h> using namespace std; int n, a, b; int primect = 0; int primes[40000]; int arr[1000000]; set<int> pset; long long costl[1000000]; long long costr[1000000]; long long minCosts[30]; long long inf = numeric_limits<long long>::max(); void fillInPrimes() { primes[0] = 2; ...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int type[200010]; int weight[200010]; map<int, long long int> M; long long int power(long long int a, int b) { a %= mod; long long int res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline int size(T x) { return x.size(); } long long k[3], t[3]; int num_done[100005] = {}; queue<int> waiters[3]; set<pair<long long, int> > Q; void try_putinto(int pid, int qnr, long long tijd) { if (!k[qnr]) { waiters[qnr...
#include <bits/stdc++.h> using namespace std; struct point { double x; double y; }; int compare(const void *a, const void *b) { point *aa, *bb; aa = (point *)a; bb = (point *)b; if (aa->x > bb->x) return 1; else if (aa->x < bb->x) return -1; else return aa->y > ...
#include <bits/stdc++.h> using namespace std; bool check = false; string s; int maxi, n, i, j, a; int main() { cin >> n; vector<int> v; for (i = 0; i < n; i++) { maxi = 0; for (j = 0; j < n; j++) { cin >> a; maxi = max(maxi, a); } if (check == false && maxi ...
#include <bits/stdc++.h> using namespace std; int n, p[200005]; int ans[200005]; queue<int> q; int main() { int Q; cin >> Q; while (Q--) { memset(ans, 0, sizeof(ans)); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= n; i++) { if (ans[i]) con...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(51); signed main() { ios::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } deque<pair<long long, long long>> q; for (long long i = 0;...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; string s; cin >> s; vector<long long> l_r, r_l; long long count = k + 1; for (long long i = 0; i < n; i++) { if (s[i] == 1 ) { count = 0; l_r.push_back(0); } else if (...
#include <bits/stdc++.h> using namespace std; int n, i, a, b, aux1, aux2, cs, cd, mij, rsp; char s[200005]; int u[200005], r[200005], l[200005], d[200005]; int main() { ios::sync_with_stdio(false); cin >> n; cin >> s; cin >> a >> b; if (abs(a) + abs(b) > n) { cout << -1; return...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; string ans; ans = s; sort(ans.begin(), ans.end()); int cnt = 0; for (int i = 0; i < n; i++) { if (ans[i] != s[i]) c...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ld eps = 1e-8; template <class U, class V> ostream& operator<<(ostream& out, const pair<U, V>& p) { return out << ( << p.first << , << p.second << ) ; } template <size_t i, class T> ostream& pri...
#include <bits/stdc++.h> using namespace std; vector<long long int> factors(long long int n) { vector<long long int> v; for (long long int i = 1; i * i <= n; i++) { if (n % i == 0) { if (i * i == n) v.push_back(i); else { v.push_back(i); v.push_back(n / i)...
#include <bits/stdc++.h> using namespace std; using vec_i = vector<int>; using pii = pair<int, int>; using ll = long long; using vec_ii = vector<pii>; using vec_ll = vector<ll>; template <typename T> using vec = vector<T>; ll gcd(ll x, ll y) { ll m; while (y > 0) { m = x % y; x = y...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || 9 < ch) f = (ch ^ - ) ? f : -1, ch = getchar(); while ( 0 <= ch && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x * f; } int const N = 310; double con...
#include <bits/stdc++.h> using namespace std; multiset<int, greater<int> > s1; multiset<int> s2; int bs1, bs2, n, a[500500], b[500500], ct, nomb[500500], cr, noma[500500]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); noma[a[i]] = i; } for (int i =...
#include <bits/stdc++.h> int main() { int numDominoes; char dominoes[3005]; int fallen = 0; int count = 0; int isL = 0; int seenR = 0; scanf( %d , &numDominoes); for (int i = 0; i <= numDominoes; i++) { scanf( %c , &dominoes[i]); } for (int i = 1; i <= numDominoes; i++) {...
#include <bits/stdc++.h> using namespace std; int n, a, b; int M[256 + 1]; int main() { scanf( %d %d %d , &n, &a, &b); if (a & 1) a++; if (b & 1) b++; int round = 1; for (;;) { a /= 2; b /= 2; if (a == b) break; round++; if (a & 1) a++; if (b & 1) b++; ...
#include <bits/stdc++.h> using namespace std; int a, b, diff, n_div; int main() { int i; cin >> a >> b; diff = a - b; if (diff < 0) { cout << 0 << endl; } else if (diff == 0) { cout << infinity << endl; return 0; } else { for (i = 1; i * i <= diff; i++) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2010; vector<int> G[maxn]; int n, m, d[maxn], par[maxn], a[maxn], vis[maxn], flag = 1; char s[1005][1005]; int find(int u) { if (par[u] != u) par[u] = find(par[u]); return par[u]; } struct node { int u, w; node(int a, int b) ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long prod = 1; for (int i = 1; i < n; i++) prod *= i; prod *= 2; prod /= n; cout << prod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const double eps = 1e-8; const int maxn = 1e6 + 5; const int INF = 1e9; const int maxnode = 7e6 + 5; const int sigma_size = 2; void tran2(int num, int s[]) { for (int i = 0; i < 31; i++) { s[i] = (num >> (30 - i)) & 1; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 4 * 100000 + 10; char ss[MAXN]; int main() { scanf( %s , ss); int cis; int len = strlen(ss); int l = len; for (int i = 0; i < len; i++) { ss[i + len] = ss[i]; } len = strlen(ss); int ans = 1; int maxx = 1; ...
#include <bits/stdc++.h> using namespace std; int n, m, ptr; bool mark[100010]; bool bad[100010]; int ord[100010]; vector<int> dir[100010]; vector<int> rev[100010]; vector<int> adj[100010]; bool dfs(int idx) { bool ret = bad[idx]; mark[idx] = true; for (int i = 0; i < adj[idx].size(); i++)...
#include <bits/stdc++.h> using namespace std; static int io_sync_off = []() { ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }(); long long Pow(long long a, long long b, long long mod) { long long res = 1; a %= mod; while (b) { if (b & 1) (res *= a) %= mod; (a *= a)...
/* _/_/_/_/_/_/ _/_/_/_/_/ _/_/_/_/_/ _/_/_/_/_/ _/_/_/_/_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/_/ _/_/_/ _/_/_/_/_/ _/_/_/_/_/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/_/_/_/_/ _...
#include <bits/stdc++.h> using namespace std; int main() { int b, k; cin >> b >> k; int ans = 0; for (int i = 1; i <= k; i++) { int x; cin >> x; if (i != k) ans = (ans + b * x % 2) % 2; else ans = (ans + x % 2) % 2; } if (ans % 2 == 0) { cout << ...
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, m; map<string, int> h; string name[N], str[N], re[N]; bool f[N][N]; int g[N][N]; void print(int x, int y) { if (x == 0) { return; } print(x - 1, g[x][y]); cout << name[y] << re[x - 1] << endl; } void work()...
#include <bits/stdc++.h> using namespace std; int main() { int l, b, M, N; cin >> M; cin >> N; l = std::max(M, N); b = std::min(M, N); if (b >= 2) { cout << (b * (l / 2) + (b / 2) * (l % 2)); } else cout << (b * (l / 2)); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int xa[300005] = {0}; for (int i = 1; i <= 300000; i++) { xa[i] = (xa[i - 1] ^ i); } int t; cin >> t; while (t--) { long long a, b; cin >> a >> b; long long x = xa[a - 1]; if (x == b) { cout << a...
#include <bits/stdc++.h> using namespace std; int n, m, x[101]; double e[2][101 * 1001], sume[101 * 1001]; int main(int argc, const char* argv[]) { scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) scanf( %d , x + i); if (m == 1) { puts( 1.00 ); return 0; } int cur = 0, pre = 1;...
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, tp, f, g, h, p[100], pi, q[100], qi, pas; map<pair<long long, long long>, long long> m; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> a; for (b = 1; b <= a; b++) { cin >> tp; if (tp ==...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int K = 20; int go[N][K]; int tin[N], tout[N]; vector<int> g[N]; int timer = 0; int perm[N]; int where[N]; pair<int, int> t[4 * N]; int n; void dfs(int u, int p = 0) { go[u][0] = p; tin[u] = timer++; for (int ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7; int n; int tmp[N]; int a[N], val[N], sta[N]; int dpl[N], dpr[N]; void init(int n, int *dp) { int top = 0; int mx = 0; for (int i = 1; i <= n; i++) { int ma = 0; while (top && a[sta[top]] > a[i]) { ma...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; char s[maxn]; int tp[maxn >> 3], sz[maxn >> 3], n, cnt; long long ans; int main() { scanf( %d , &n); int l; for (int i = 1; i <= n; i++) { scanf( %s , s + 1); l = strlen(s + 1); for (int k = 1; k <= l; k++)...
#include <bits/stdc++.h> using namespace std; struct comp1 { bool operator()(const long long &a, const long long &b) { return (a > b); } }; typedef struct node { long long num; vector<node *> des; } node; int n; long long arr[8]; int best; node *root; vector<node *> imp; bool prime[100...
#include <bits/stdc++.h> using namespace std; const long long N = 505, mod = 1e9 + 7; long long c[N][N], s[N][N], p[N], inv[N]; long long l, r; long long k, ans; long long add(long long a, long long b) { return a + b >= mod ? a + b - mod : a + b; } long long dec(long long a, long long b) { retur...
#include<bits/stdc++.h> #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define len(x) (int)(x).size() typedef long long ll; typedef long double ld; using namespace std; const int N = 1001; const int mo...
#include <bits/stdc++.h> using namespace std; const int maxN = 105; int n, s, c[maxN], sum1, sum2; vector<int> d; bool cmp(int A, int B) { return A > B; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> s; for (in...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, ans = 0; cin >> n; vector<int> a(n + 5), b(n + 5), c(n + 5); map<long long, long long> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i ...
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a <= b ? true : false; } template <class T> bool uax(T &a, T b) { return a >= b ? true : false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << ...
#include <bits/stdc++.h> using namespace std; long long arr[1002][1002]; long long store[2][1000002]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, m, k, p; cin >> n >> m >> k >> p; for (long long i = 1; i <= n; i++) for (long long j = 1; j <...
#include <bits/stdc++.h> using namespace std; int n, i, j, m, ans, p = 51123987, i1, i2, i3, la[3], nt[151][3], f[151][53][53][53]; char s[201]; int main() { scanf( %d , &n); scanf( %s , s + 1); for (i = n; i; i--) { la[s[i] - a ] = i; for (j = 0; j < 3; j++) nt[i...
#include <bits/stdc++.h> using namespace std; long long int arr[10000]; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int a, b, c, i, j, k, n, m, state = 0; for (i = 0; i < 6; i++) cin >> arr[i]; sort(arr, arr + 6); for (i = 0; i < 3; i++) { ...
#include <bits/stdc++.h> using namespace std; template <class T> T Max(const T &a, const T &b) { return a > b ? a : b; } const int SN = 100000 + 10; long long w[SN], f[SN][2], down[SN], g[SN], h[SN], head[SN]; long long u, v, n, num; bool vis[SN]; struct Edge { int from, to, next; } E[SN << ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<pair<long long, long long> > a(n); for (auto &x : a) cin >> x.first; for (auto &x : a) cin >> x.second; long long ans = 0; sort(a.begin(), a.end()); priority_queue<long long> pq; long long ...