func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long n, cnt1 = 0, cnt2 = 0, l, r; cin >> n; for (int i = 0; i < n; i++) { cin >> l >> r; cnt1 += l; cnt2 += r; } cout << min(cnt1, n - cnt1) + min(cnt2, n - cnt2); }
#include <bits/stdc++.h> using namespace std; long long int Mmax(long long int a, long long int b) { if (a > b) return a; return b; } long long int Mmin(long long int a, long long int b) { if (a < b) return a; return b; } long long int nod(long long int a, long long int b) { while (a && ...
#include <bits/stdc++.h> using namespace std; template <ostream& out = cout, class... T> void prints(T&&...) {} template <ostream& out = cout, class... T> void printe(T&&...) {} template <ostream& out = cout, class... T> void printw(T&&...) {} template <ostream& out = cout, class... T> void printew(T&...
#include <bits/stdc++.h> using namespace std; const int nax = 505; int n; char grid[nax][nax]; int cc[nax][nax]; int cc_size[nax * nax]; int when_added[nax * nax]; const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const char EMPTY = . ; bool inside(int x, int y) { return 0 <= min(...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; const int maxn = 100010; int a[maxn]; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a > b ? b : a; } int main() { int n, l, r, i, j; string s; while (cin >> n) { for (i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; long long i, j, k, n, v[200010], m, a, b, x, y, h, w, l, p, ans, numitor, aux, mini, sum, poz; string s1, s2, second; char c; map<long long, long long> mip; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> x; for (long...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, ex, ey, sx[N], sy[N]; char s[N]; inline bool check(int m) { for (int i = 1; i + m - 1 <= n; i++) { int decx = sx[n] - sx[i + m - 1] + sx[i - 1]; int decy = sy[n] - sy[i + m - 1] + sy[i - 1]; int nedx = ex - decx;...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, i, j, x, y = 0, w, z = 0, e; cin >> a >> b >> c >> d; if (d % c != 0) { cout << 0; return 0; } w = d / c; if (c == d) { if (c >= a && c <= b) cout << 1; else cout << 0; re...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; int tree[4 * MAXN], n, m, a[MAXN], size = 0, less1[MAXN]; vector<int> del, nums; void initialize(int l, int r, int node) { tree[node] = r - l + 1; if (r == l) return; int mid = (l + r) / 2; initialize(l, mid, 2 * node); ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-9; const long long mod = 1e9 + 7; int read() { int x = 0, f = 1; char ch = getchar(); while (ch< 0 | ch> 9 ) { if (ch...
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define int long long void solve() { int n; vector<long long> vect; cin >> n; for (int i = 0; i < n; i++) { long long x; cin >> x; vect.push_back(x); } sor...
// Problem : B. Tree Array // Contest : Codeforces - Codeforces Round #728 (Div. 1) // URL : https://codeforces.com/contest/1540/problem/B // Memory Limit : 256 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; ...
#include <bits/stdc++.h> using namespace std; int read() { int a = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) { f = c == - ; c = getchar(); } while (isdigit(c)) { a = a * 10 + c - 48; c = getchar(); } return f ? -a : a; } const int _ = 1e5 + 1...
#include <bits/stdc++.h> using namespace std; int64_t ans, n, k, m, r[100005]; char s[100005], t[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int64_t tt; cin >> tt; while (tt--) { cin >> n; cin >> s; cin >> t; vector<int> ans; m = n - 1; ...
#include <bits/stdc++.h> using namespace std; vector<int> a; int k, t, n, mx; string s; int main() { cin >> n >> k; cin >> s; for (int i = 0; i < s.size(); i++) if (s[i] == . ) a.push_back(i); for (int i = 0; i < a.size() - 1; i++) mx = max(mx, a[i + 1] - a[i]); if (mx > k) co...
#include <bits/stdc++.h> using namespace std; int w; long long n, k; pair<long long, long long> o = {0, 0}; pair<long long, long long> csop(long long kezd, long long kim) { long long sum = 0, kov = kezd + k; if (kezd <= kim && kim <= kov) { kov++; } sum = (kov - kezd) * (kov - kezd - 1) ...
#include <bits/stdc++.h> using namespace std; int cl[5000010], cr[5000010], ld[5000010], sl = 1; bool yz[5000010]; void pushd(int x) { if (cl[x] == 0) { cl[x] = ++sl; yz[cl[x]] = 1; } if (cr[x] == 0) { cr[x] = ++sl; yz[cr[x]] = 1; } yz[x] = 0; if (ld[x] == 0) retu...
#include <bits/stdc++.h> using namespace std; const int N = 15; long long Get_Num(int num[], int b, int n) { long long number = 0; long long in = 1; for (int i = n - 1; i >= 0; i--) { number += num[i] * in; in = in * b; } return number; } int main() { int x[N], y[N]; in...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long n, m; cin >> n >> m; long sum = 0; if (n == 1 || n == 2) { if (n == 1) cout << 0 << endl; else cout << m << endl; } else { cout << 2 * ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long n, m; int k; int mpow(int a, long long b) { int c = 1; for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) c = 1ll * c * a % mod; return c; } int main() { scanf( %lld%lld%d , &n, &m, &k); if ((n + m...
#include <bits/stdc++.h> using namespace std; int tt(char p) { int s; if (p == > ) s = 8; else if (p == < ) s = 9; else if (p == + ) s = 10; else if (p == - ) s = 11; else if (p == . ) s = 12; else if (p == , ) s = 13; else if (p == [ ) ...
#include <bits/stdc++.h> template <typename T> inline T MIN(T a, T b) { return a < b ? a : b; } template <typename T> inline T MAX(T a, T b) { return a > b ? a : b; } using namespace std; void reop() { freopen( input.txt , r , stdin); } int a[100001] = {0}; int ans = 0, curans = 0; bool t...
#include<bits/stdc++.h> #define int long long #define pii pair<int,int> #define F first #define S second #define pi acos(-1.0) #define pb push_back #define sf(x) scanf( %lld ,&x) #define pf(x) printf( %lld ,&x) using namespace std; const int mod=1e9+7; int a1[2000],ar[2000],ff[2000] ; map<int,in...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 2, M = 1e9 + 7; int tt = 1, n, k; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> tt; while (tt--) { cin >> n; if (n == 1) { cout << a n ; continue; } string second = , ans ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; const long long inf = 1e17 + 7; pair<long long, long long> a[maxn]; pair<long long, long long> A[maxn]; pair<pair<long long, long long>, pair<long long, long long> > S[maxn]; int pos; inline long long elf(pair<long long, long long> ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 3; const long long int M = 1000000007; void solve() { string s; cin >> s; int n = s.length(); for (int i = 0; i < n - 1; ++i) { s += 0 ; } long long int ans = 0; for (int i = 0; i < 2 * (n - 1) + 1; ++i) { ...
#include <bits/stdc++.h> using namespace std; struct like { int id; int change = 0; }; int main() { int n, s, max = 0, idmax = 0, count = 0, k = 0; cin >> n; like *A = new like[n]; for (int i = 0; i < n; i++) { cin >> s; k = 1; for (int j = 0; j < count; j++) { ...
#include <bits/stdc++.h> using namespace std; int H[100000][5], V[100000][5]; long long dp[32]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i < m; ++i) for (int j = 0; j < n; ++j) cin >> H[i][j]; for (int i = 0; i < m; ++i) for (...
#include <bits/stdc++.h> using namespace std; long long int arr[100000], arr1[100000], arr2[100000]; int main() { int n, flag = 0; cin >> n; multiset<long long int> m; multiset<long long int>::iterator it; for (int i = 0; i < n; i++) { cin >> arr[i]; m.insert(arr[i]); if (i =...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1e9 + 7; void dfs(int node, vector<vector<pair<int, int>>>& adj, vector<bool>& vu, ll& cnt) { for (auto& p : adj[node]) { if (!vu[p.first] and p.second == 0) { vu[p.first] = true; ++cnt; ...
#include <bits/stdc++.h> using namespace std; int n, v[5000]; char a[5000][5050]; bool dfs(int x, int from) { v[x] = 1; for (int y = 0; y < n; y++) if (a[x][y] == 1 ) { if (!v[y]) { if (dfs(y, x)) return true; } else { if (a[y][from] == 1 ) { print...
#include <bits/stdc++.h> const double EPS = 0.0000000001; const long long mod1 = 998244353; const long long mod2 = 1000000007; const long long mod3 = 1000000009; const long long mod4 = 998244353; const long long inf = 10000000000000000; using namespace std; signed main() { cin.tie(0); cout.tie(0...
#include <bits/stdc++.h> using namespace std; pair<int, int> x[1024], y[1024]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> x[i].first >> x[i].second; y[i].fi...
#include <bits/stdc++.h> using namespace std; char s[123456]; int main() { scanf( %s , s); stack<pair<int, int> > st; int best = 0, rr = -1; int sqb = 0; for (int i = 0; s[i]; ++i) { if (s[i] == ( || s[i] == [ ) { st.push(make_pair(i, sqb)); sqb = 0; } else if (s...
#include <bits/stdc++.h> template <int MOD_> struct modnum { static constexpr int MOD = MOD_; static_assert(MOD_ > 0, MOD must be positive ); private: using ll = long long; int v; static int minv(int a, int m) { a %= m; assert(a); return a == 1 ? 1 : int(m - ll(minv(m, a...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1}; int dy[] = {-1, 1, 0, 0}; template <class T> T power(T N, T P) { return (P == 0) ? 1 : N * power(N, P - 1); } template <class T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } struct debugger { t...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t > 0) { t--; string s, x; cin >> s; x.push_back(s[0]); for (int i = 1; i < s.size(); i++) { if (i % 2 != 0) x.push_back(s[i]); } cout << x << endl; } return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int q = 1, i, j; while (q--) { int n, r; cin >> r >> n; vector<int> t(n + 1), x(n + 1), y(n + 1); t[0] = 0, x[0] = 1, y[0] = 1; for (i = 1; i < (n + 1); i++) { cin >> t[i] >> x[i] >> y[i]; } vector<i...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, m, a; cin >> n >> m; int l = 1, mx = 0; for (int i = 0; i < n; i++) { cin >> a; if ((a + m - 1) / m >= mx) { mx = (a + m - 1) / m; l = i + 1; } } cout << l << ...
#include <bits/stdc++.h> using namespace std; long long const M = 2000 + 10, M2 = 1e7 + 10, mod = 1e9 + 7, inf = 1e9 + 10, sq = 450; long long a[M][M], ro[M], col[M], all[M]; int32_t main() { long long n, ans = 0; cin >> n; for (long long i = 1; i <= n; i++) { string x; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; long long a[n], b[m]; for (long long i = 0; i < n; ++i) { cin >> a[i]; } for (long long i = 0; i...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, x[maxn], y[maxn]; int solve(set<pair<int, int> >& a, set<pair<int, int> >& b) { set<pair<int, int> >::iterator itl = a.begin(), itd = b.begin(), it1; set<pair<int, int> >::reverse_iterator itr = a.rbegin(), itu = b.rbegin(), ...
#include <bits/stdc++.h> int main() { int t = 1, i, j, n; long long int p, q, temp, arr[90]; for (j = 0; j < t; j++) { scanf( %lld %lld , &p, &q); scanf( %d , &n); for (i = 0; i < n; i++) scanf( %lld , &arr[i]); for (i = 0; i < n; i++) { if (p / q < arr[i]) { prin...
#include <bits/stdc++.h> using namespace std; const int bits = 1000; bitset<bits> node[4 * 100060]; long long int leftOver[4 * 100060]; int n; int treeSize[100060]; vector<int> adj[100060]; int dfsOrder[100060]; int o = 1; void dfs(int curr = 1, int par = -1) { treeSize[curr] = 1; dfsOrder[c...
#include <bits/stdc++.h> using namespace std; const int N = 100010; struct seg { vector<int> t; int n; seg(int n = 0) : t(2 * n), n(n) {} int query(int l, int r) { int ans = 0; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) ans += t[l++]; if (r & 1) ans += t...
#include <bits/stdc++.h> using namespace std; const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; void DBG() { cout << ] << endl; } template <class H, class... T> void DBG(H h, T... t) { cout << to_...
#include <bits/stdc++.h> using namespace std; void Get(int &T) { char C; bool F = 0; for (; C = getchar(), C < 0 || C > 9 ;) if (C == - ) F = 1; for (T = C - 0 ; C = getchar(), C >= 0 && C <= 9 ; T = T * 10 + C - 0 ) ; F && (T = -T); } int N; void Init() { Get(N); } ...
#include <bits/stdc++.h> using namespace std; long long t; long long n; long long tmp; long long gcd(long long a, long long b) { long long temp; if (a < b) { temp = a; a = b; b = temp; } while (b != 0) { temp = a % b; a = b; b = temp; } return a; }...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int max = 0, min = 0; int a[m], b[m]; for (int i = 0; i < m; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a + m, greater<int>()); for (int i = 0; i < n; i++) { if (a[0] != 0) { ...
#include <bits/stdc++.h> using namespace std; bool isPrime[1000005] = {false}; vector<long long int> SPF(1000005); long long int fastPower(long long int a, long long int b) { if (b == 0) return 1; long long int prod = 1; while (b > 0) { if (b & 1) prod = prod * a; b = b >> 1; a = a...
#include <bits/stdc++.h> using namespace std; int main() { long long int m, n, p, count = 0; cin >> m >> n; if (m % n == 0) cout << m / n; else { count = count + (m / n); m = m % n; for (;;) { if (m > n) { if (m % n == 0) { count += m / n; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5; const int MAXM = 20; int n, m; int a[MAXN], b[MAXM]; int num[MAXM]; char ans[MAXN][MAXM]; set<int> states[MAXM]; int getState(int mask, int num[MAXM]) { int res = mask; for (int i = 0; i < n; ++i) { res = res * MAXN + num[...
#include <bits/stdc++.h> using namespace std; const int N = 100500; const int INF = 2 * (1e9); int n, m; vector<pair<int, int> > edge[N]; vector<pair<int, int> > delay[N]; int dist[N]; int main() { cin.sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < m; i++) { int from, to, l...
#include <cstdio> #include <vector> #include <cstring> #include <algorithm> const int Maxn=200000; const int Inf=0x3f3f3f3f; int n; int a[Maxn+5]; std::vector<int> v_lis[Maxn+5]; struct Segment_Tree{ struct Segment_Node{ int minn,maxn; int lazy; }seg[Maxn<<2|5]; void update_tag(int ro...
#include <bits/stdc++.h> using namespace std; vector<int> V[100005]; int main() { int N, M, K, ans = 1; scanf( %d%d%d , &N, &M, &K); for (int i = 1; i <= N; ++i) { int c; scanf( %d , &c); V[c].push_back(i); } for (int c = 1; c <= M; ++c) { int L = V[c].size(), rem = 0, ...
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { string s; cin >> s; string h = s.substr(0, 2); int hour = atoi(h.c_str()); string m = s.substr(3, 2); int minute = atoi(m.c_str()); long long time = 60 * hour + minute; long long add; cin >> add; ...
#include <bits/stdc++.h> using namespace std; int a[7]; int b[7]; int main() { string s; int k; cin >> s >> k; int kol = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 0 ) { kol++; } } if (kol < k) { cout << s.length() - 1; } else { kol = 0...
#include <bits/stdc++.h> using namespace std; char s1[5010], s2[5010], str[5010]; int num[30]; int len1, len2; int dfs(int k, int m) { if (!s1[k]) return m; for (int i = 0; i < 26; i++) if (num[i] && (m || (i >= s2[k] - a ))) { str[k] = i + a ; num[i]--; if (dfs(k + 1, ...
#include <bits/stdc++.h> using namespace std; struct Rectangle { int x1; int x2; int y1; int y2; Rectangle() {} Rectangle(int a, int b, int c, int d) { x1 = a; y1 = b; x2 = c; y2 = d; if (x1 > x2) { swap(x1, x2); } if (y1 > y2) { swap...
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 10; long long q, x, v, u, w, ans; map<long long, long long> len; int main() { cin >> q; for (int i = 1; i <= q; i++) { cin >> x >> v >> u; if (x == 1) { cin >> w; while (v != u) { if (v > u) {...
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000000000000ll; long long x[6], y[6]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; if (n == 1) { cout << -1 << endl; return 0; } if (...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const int N = (int)3e5 + 7; char read_char() { char c; for (;;) { c = getchar(); if (c >= A && c <= Z ) return c; } } long long po...
#include <bits/stdc++.h> using namespace std; map<long long, long long> s; long long n, b[500005], c[500005]; int main() { cin >> n; for (int i = 0; i < n; i++) { long long x; cin >> x; s[x]++; } long long m, mx1 = 0, mx2 = 0, index = 1; cin >> m; for (int i = 0; i < m;...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1010; const double EPS = 0.0000001; struct Point { int x, y; Point() {} Point(int a, int b) : x(a), y(b) {} }; int n; long long k; Point centers[MAX_N]; int radii[MAX_N]; double GetDist(int x1, int y1, int x2, int y2) { ...
#include <bits/stdc++.h> using namespace std; long long calc(const long long &x, const long long &pow, const long long &pp) { long long res = 1, tmp = (x % pp); long long cur = pow; while (cur > 0) { if (cur % 2 == 0) { tmp = (tmp * tmp) % pp; cur = cur / 2; } else { ...
#include <bits/stdc++.h> using namespace std; int n, m; int x[500010], y[500010]; bitset<2010 * 2> A[2010]; void Work() { for (int i = 1; i <= n; i++) { int t = i; for (int j = i + 1; j <= n; j++) if (A[j][i]) t = j; swap(A[i], A[t]); for (int j = 1; j <= n; j++) if...
#include <bits/stdc++.h> const int MAXN = 60; int n, P, A[MAXN]; const int mod = 1000000007; void reduce(int& x) { x += x >> 31 & mod; } int mul(int a, int b) { return (long long)a * b % mod; } int pow(int a, int b, int res = 1) { for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); ...
#include <bits/stdc++.h> using namespace std; int main() { char s[200001], t1[200001]; long long n, x, y, t, con = 0; cin >> n >> x >> y; getchar(); gets(s); t = n - x; for (long long i = t; s[i] != 0 ; i++) { if (i == n - 1 - y && s[i] != 1 ) con++; if (i != n - 1 - y && ...
#include <bits/stdc++.h> using namespace std; int main() { int k, r; cin >> k >> r; int n = 1; while (true) { if ((k * n - r) % 10 == 0 || (k * n) % 10 == 0) { cout << n << n ; return 0; } n++; } }
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c h, c n) { return {h, n}; } template <class c> auto dud(c* r) -> decltype(cerr << *r); template <class c> char dud(...); struct muu { ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 50; vector<int> e[N]; int dp[N], res, deg[N]; void dfs(int u, int pre) { dp[u] = deg[u]; for (int v : e[u]) { if (v == pre) continue; dfs(v, u); res = max(res, dp[u] + dp[v]); dp[u] = max(dp[u], dp[v] + deg[u] - ...
#include <bits/stdc++.h> using namespace std; int n, m; const int maxN = (int)1e6 + 10; vector<int> g[maxN]; int p[maxN]; int a[maxN]; long long s = 0; long long tr[maxN]; set<long long> all; void dfs(int v) { tr[v] = a[v]; for (int to : g[v]) { dfs(to); tr[v] += tr[to]; } ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const int N = (int)2e5 + 7; int tree[N << 1]; void update(int x, int n) { x += n; if (tree[x]) return; while (x) { tree[x]++; x >>= 1; ...
#include <bits/stdc++.h> using namespace std; int main() { double l, p, q; cin >> l >> p >> q; double qq = l / (p + q) * p; cout << setiosflags(ios::fixed); cout << setprecision(4) << qq; }
#include <bits/stdc++.h> using namespace std; long long exp(long long x, long long y) { x %= 1000000007; long long res = 1; while (y) { if (y & 1) res = res * x % 1000000007; x = x * x % 1000000007; y >>= 1; } return res; } long long fact(long long n) { long long res = ...
#include <bits/stdc++.h> using namespace std; const int MAXN = -1; struct disk { long long L; double p; disk(long long L = 0, double p = 0.) : L(L), p(p) {} }; bool operator<(disk a, disk b) { return (a.L * a.p * (1 - b.p)) > (b.L * b.p * (1 - a.p)); } int n; vector<disk> P; int main()...
#include <bits/stdc++.h> using namespace std; long long i, n, now, ans, hh, m, p = 1000000009; int main() { scanf( %lld , &n); if (n == 2) { puts( 10 ); return 0; } m = n / 2; now = 4; hh = 1; for (i = 3; i <= m; i++) { now = now * 2 % p; hh = hh * (now - 3) % p...
#include <bits/stdc++.h> using namespace std; int m(int x, int md) { return (((x) % md) + md) % md; } void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; set<int> st; for (int r = 0; r < n; r++) { st.insert(m(r + a[r], n)); } if (st.size...
#include <bits/stdc++.h> using namespace std; struct event { int pos, type, p; event(int pos = 0, int type = -1, int p = 0) : pos(pos), type(type), p(p) {} bool operator<(const event &e) const { if (pos == e.pos) return type < e.type; return pos < e.pos; } }; const int maxE = 5e5 + 1...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100011; const long long INF = (1 << 29) + 123; const long long MOD = 1000000007; const long double PI = 4 * atan((long double)1); int fenw[2 * MAX_N]; int n; void mod(int i, int v) { while (i <= n) { fenw[i] += v; i += i & -...
#include <bits/stdc++.h> using namespace std; long long V[10005], O[10005], F[1005][10005]; int c[1005], cost[1005]; int n, W, B, X; struct Queue { int p[1005], q[1005]; long long maxp[1005], maxq[1005]; void clear() { *p = 0; *q = 0; maxp[0] = maxq[0] = -1; } void add(in...
#include <bits/stdc++.h> using namespace std; int main() { int n, p1 = 0, p2 = 0; cin >> n; int mid[1000], index = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a % 2 == 0) { for (int j = 1; j <= (a / 2); j++) { int t; cin >> t; p1 += t...
#include <bits/stdc++.h> using namespace std; const int N = 6010; vector<int> a[N]; int L[N], cnt, r[N], n, res = 0; void Refresh() { L[0] = cnt = 0; for (int i = 1; i <= n + 1; i++) L[i] = 10000000; } void DFS(int u, int p) { int Oldval, Oldid, Oldcnt = cnt; if (cnt == 0 || r[u] > L[cnt])...
#include <bits/stdc++.h> using namespace std; long long pow1(int a, int b) { long long res = 1; for (int i = 1; i <= b; i++) res *= a; return res; } int main() { int n; cin >> n; long long sum = 2 * (pow1(2, n) - 1); cout << sum << n ; return 0; }
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int main() { ios_base::sync_wi...
#include <bits/stdc++.h> using namespace std; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const long long linf = 4000000000000000000LL; const long long inf = 998244353; const long double pi = 3.1415926535; void pv(vector<int> a) { for (auto& x : a) cout << x << ; cout << n ; } v...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; int cardsPlayer = n / k; double maxCard; int jokerMax = min(m, cardsPlayer); maxCard = ceil((m - jokerMax) / (k - 1.0)); if (jokerMax - max...
#include <bits/stdc++.h> using namespace std; typedef struct { long long j, x1, x2; } inter; struct comp1 { bool operator()(const inter& a, const inter& b) const { return a.x1 < b.x1; }; }; struct comp2 { bool operator()(const inter& a, const inter& b) const { return (a.x2 == b.x2) ? (a.x1...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long a[2000], dp[2000]; long long qmod(long long y) { long long res = 1, two = (long long)2; for (; y; y >>= 1) { if (y & 1) res = res * two % mod; two = two * two % mod; } return res; } int main() ...
#include <bits/stdc++.h> using namespace std; const int maxN = 200005; const int inf = 214748364; int n, m, g[21][1 << 20], f[maxN], v[maxN], s[maxN]; int cost(int a, int b) { for (int i = m; i >= 0; --i) { if ((a & ((1 << i) - 1)) == (b >> (m - i))) return m - i; } } void init() { char ...
#include <bits/stdc++.h> using namespace std; inline void Input_Output() {} const double eps = 0.000001; const long double pi = acos(-1); const int maxn = 1e7 + 9; const int mod = 1e9 + 7; const long long MOD = 1e18 + 9; const long long INF = 1e18 + 123; const int inf = 2e9 + 11; const int mxn = 1e6...
#include <bits/stdc++.h> using namespace std; bool vis[2][100005]; char c[2][100005]; int main() { queue<pair<int, pair<int, int> > > q; bool flag = 0; int n, k; cin >> n >> k; scanf( %s%s , c[0], c[1]); q.push(make_pair(0, make_pair(0, 0))); while (!q.empty()) { int x = q.fron...
#include <bits/stdc++.h> int n, k, ans; long long s[200005], a[200005], b[200005]; void neg() { for (int i = 0; i <= n; i++) { a[i] = -a[i]; b[i] = -b[i]; } } void trans() { b[n]--; b[0] += 2; for (int i = 1; i < n; i++) b[i]++; for (int i = 0; i < n; i++) { b[i + 1] ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int n, k, sum = 0; cin >> n >> k; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; string s; cin >> s; vector<long long...
#include<bits/stdc++.h> using namespace std; int a[10]; int main() { int T;scanf( %d ,&T); while(T--) { int sum = 0; for(int i = 1;i <= 3;i++) { scanf( %d ,&a[i]); sum += a[i]; } if(sum % 9 == 0) { if(a[1] >= sum / 9 && ...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; using vi = vector<int>; using vll = vector<ll>; using vd = vector<double>; using vvi = vector<vi>; int ctoi(char c) { return c - 0 ; } int slen(string s) { return s.length(); } int vsize(vi a) { return (...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int result = 0; for (int i = 0; i < n; i++) { int k, a; cin >> k >> a; long x = k * a; int c = 0; if (a % 4 == 0) a--; while (a) { a /= 4; c++; } result = (((re...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long x; for (int i = 0; i < m; i++) { cin >> x; if (x > n) cout << 0 << endl; else { if (x % 2 == 1) cout << x / 2 + 1 << endl; else { long lon...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 100010; int x0[maxn], x1[maxn], d[maxn], c[maxn]; int main() { int n, m, y0, y1; scanf( %d %d %d %d , &n, &m, &y0, &y1); for (int i = 0; i < n; ++i) { scanf( %d , &x0[i]); } memset(d, -1, sizeo...
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; long long int x = a.length(); std::vector<long long int> v; long long int c = 0; long long int d = 0; for (long long int i = 0; i < x; i++) { if (a[i] == b ) { d++; } if (a[i] == a ...