func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int OO = 1e8 + 10; const int MOD = 1e9 + 7; const int MAX = 2e5 + 1; const double EPS = (1e-9); map<int, bool> mp; int main() { int n, x, y, l, last, ans; bool f1 = 0, f2 = 0, f3 = 0; cin >> n >> l >> x >> y; for (int i = 0; i < n; i++) {...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int vis[N]; int p[N]; int sum[N]; int main() { int t = 0; for (int i = 2; i <= 1000010; i++) { if (vis[i] == 0) p[++t] = i; for (int j = 1; j <= t && (i * p[j] <= 1000010); j++) { vis[i * p[j]] = 1; if...
#include <bits/stdc++.h> using namespace std; int a[110000], b[110000]; struct Node { int a, b; } node[110000]; int main() { int i, j, h; int n, m, T; int cas = 1; int x, y; while (scanf( %d%d%d%d , &n, &m, &x, &y) != EOF) { for (i = 1; i <= n; i++) { scanf( %d , &a[i]); ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 2e5 + 5; const long long INF = (1LL << 62); const long double pi = 3.14159265359; void SRAND() { auto duration = std::chrono::system_clock::now().time_since_epoch(); auto millis = std::chrono::du...
#include <bits/stdc++.h> using namespace std; vector<int> Ans; int N, M, K; struct Edge { int u, v, w, id; } e1[100005], e2[100005]; int M1, M2; bool Comparew(Edge a, Edge b) { if (a.w == b.w) { if (a.u == 1 || a.v == 1) return 1; else return 0; } else { if (a...
#include <bits/stdc++.h> using namespace std; long long f(vector<int> x, int k) { long long ret = 0; sort(x.begin(), x.end()); for (int i = x.size() - 1; i >= 0; i -= k) { ret += x[i] * 2; } return ret; } void solve() { int n, k, mx = 0; cin >> n >> k; vector<int> x(n), a, ...
#include <bits/stdc++.h> using namespace std; struct cube { int ind, val, h; }; int rcount[101]; int compare1(cube a, cube b) { return a.val < b.val; } int compare2(cube a, cube b) { return a.ind < b.ind; } int main() { int n; scanf( %d , &n); vector<cube> v; vector<int> one, two; ...
#include <bits/stdc++.h> using namespace std; const int iinf = 1e9 + 7; const long long linf = 1ll << 40; const double dinf = 1e10; void scf(int &x) { bool f = 0; x = 0; char c = getchar(); while ((c < 0 || c > 9 ) && c != - ) c = getchar(); if (c == - ) { f = 1; c = getch...
#include <bits/stdc++.h> #pragma GCC optimize( fast-math ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC diagnostic ignored -Woverflow using namespace std; const short INF16 = ~(1 << 15); const int INF32 = 2e9 + 11; const int SZ = 4e5 + 11; const int SZ2 = int(1e6 + ...
#include <bits/stdc++.h> namespace chtholly { char buf[1 << 23], *p1 = buf, *p2 = buf; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) f ^= c == - ; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 0 ); return f ? x : -x; } tem...
#include <bits/stdc++.h> using namespace std; const int maxn = 102; int ar[maxn], ans; int main() { int n; cin >> n; n = 2 * n; for (int i = 1; i <= n; i++) cin >> ar[i]; for (int i = 1; i <= n; i++) if (ar[i - 1] != ar[i] && ar[i + 1] != ar[i]) { int j = i + 1; while (...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; char mn = z ; for (auto c : s) { if (c <= mn) cout << Mike n ; else cout << Ann n ; mn = min(mn, c); } return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; int main() { scanf( %d %d , &n, &k); int w = 240 - k; int ans = 0; for (int i = 1; i <= n; i++) { if (i * 5 <= w) { w -= i * 5; ans++; } } printf( %d n , ans); }
#include <bits/stdc++.h> using namespace std; int v[26]; int main() { int n; int i; int j; scanf( %d , &n); char s[1005]; getchar(); gets(s); char t[30]; memset(v, 0, sizeof(v)); int len = strlen(s); if (len % n != 0) cout << -1 << endl; else { for (i = ...
#include <bits/stdc++.h> using namespace std; long long arr[1001], ans; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 0 ) arr[i]++; } cin >> s; for (int i = 0; i < s.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; string minEqui(string s) { int n = s.size(); if (n % 2 == 1) return s; else { string s1 = minEqui(s.substr(0, n / 2)), s2 = minEqui(s.substr(n / 2, n / 2)); if (s1 < s2) return s1 + s2; else return s2 + s1...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; string s; cin >> s; if (n == 24) { if (s[0] == 2 && s[1] > 3 ) { s[0] = 1 ; } else if (s[0] > 2 ) { s[0] = 1 ; } } else { if (s[0] == 1 && s[1] > 2 ) { s[0]...
#include <bits/stdc++.h> using namespace std; vector<int> tamCopo; priority_queue<pair<int, int> > ordemTam; vector<int> volumeCha; int main() { int i, j, k, aux; int n, w, volume; cin >> n >> w; volumeCha.assign(n, 0); volume = 0; for (i = 0; i < n; i++) { cin >> aux; if (...
#include <bits/stdc++.h> using namespace std; long long int max(long long int x, long long int y) { if (x > y) return x; return y; } long long int min(long long int x, long long int y) { if (x < y) return x; return y; } long long int getSum(long long int n) { int sum; for (sum = 0; n...
#include <bits/stdc++.h> using namespace std; double distance(double v, double a, double t) { return v * t + a * t * t / 2; } double time(double v, double a, double d) { return (-v + sqrt(v * v + 2 * a * d)) / a; } int main(int argc, char* argv[]) { cout.precision(16); double a, v, l, d, w; ci...
#include <bits/stdc++.h> using namespace std; const int N = 200007, inf = 0x3f3f3f3f; struct qu { int op, l, r; }; qu Q[N]; int v[N]; int main() { ios::sync_with_stdio(false); int n, q, m; cin >> n >> q >> m; for (int i = 1; i <= n; ++i) { cin >> v[i]; } for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 7; int n; char s[N]; struct edge { int to, nex, wei; } e[N << 1]; int fir[N], eid; int deg[N], dis[N]; int fa[N]; queue<int> q; int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); } void addedge(int u, int v, int...
#include<bits/stdc++.h> using namespace std; const int MAX_N = 2e5+5; vector<long long> us[MAX_N]; long long pres[MAX_N]; long long res[MAX_N]; int u[MAX_N]; int s[MAX_N]; bool cmp(long long &x, long long &y) { return x > y; } int main() { int t; cin>>t; // iostream::sync...
#include <bits/stdc++.h> using namespace std; int _ = 1, tc = 1; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int getmod(int x, int y, int mod) { return (((x - y) % mod) + mod) % mod; } int MAXN = 46341 + 1; int spf[46341 + 1]; int d, x, y; int gcd(int a, int b) { if (b == 0) return a; ...
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const double E = exp(1); int x[] = {0, 0, -1, 1}; int y[] = {-1, 1, 0, 0}; template <class T1> void deb(T1 e) { cout << e << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << << e2...
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long double EPS = 1e-9; long long binpow(long long b, long long p, long long mod) { long long ans = 1; b %= mod; for (; p; p >>= 1) { if (p & 1) ans = ans * b % mod; b = b * b % mod; } return ans; } voi...
#include <bits/stdc++.h> using namespace std; bool arr[3001]; int main() { int n, i, input; cin >> n; for (i = 1; i <= n; i++) { cin >> input; arr[input] = true; } for (i = 1; i <= 3000; i++) { if (!arr[i]) { cout << i << endl; return 0; } } cout...
#include <bits/stdc++.h> using namespace std; long long c[100001]; void init() { long long n, x; long long ans = 0; cin >> n >> x; for (int i = 0; i < n; i++) cin >> c[i]; sort(c, c + n); for (int i = 0; i < n; i++) { ans += c[i] * x; if (x > 1) x--; } cout << ans << en...
#include <bits/stdc++.h> int main() { int i, gt = 0, arr[4]; char var = C ; char A[102]; for (i = 0; i < 4; i++) { scanf( %s , A); arr[i] = strlen(A) - 2; } for (i = 0; i < 4; i++) { if (i == 0) { if (arr[0] >= (2 * arr[1]) && arr[0] >= (2 * arr[2]) && ar...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; int cnt[200005]; int n, m, k; vector<unsigned long long> polys[200005]; struct cmp { bool operator()(int a, int b) const { return polys[a].size() > polys[b].size(); } }; priority_queue<int, vector<int>, cmp> q; cons...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int n, k, maxn = 2000000001; int b[100001]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 0; i < k; i++) { int r = (n - (k - i) * (k - i - 1) / 2) / (k - i); if (r <= 0) { ...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; } fei1[60], fei2[60]; int _hash[5100]; int main() { int p, q, l, r, i, t, j, x, k; scanf( %d%d%d%d , &p, &q, &l, &r); for (i = 0; i < p; i++) { scanf( %d%d , &fei1[i].x, &fei1[i].y); } for (i = 0; i < q; i++) {...
#include <bits/stdc++.h> int n; char dir[1010]; int len[1010]; int realx[2030], cntx = 0; int realy[2030], cnty = 0; void unique(int *real, int &cnt) { std::sort(real, real + cnt); int t2 = 1; for (int t1 = 1; t1 < cnt; t1++) if (real[t1] ^ real[t1 - 1]) real[t2++] = real[t1]; cnt = t2...
#include <bits/stdc++.h> using namespace std; const int N = 1e7; long long int a[N], ans; int main() { long long int n; cin >> n; long long int l = 0, r = n - 1; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n / 2; i++) { ans += (a[l] + ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, aa, bb; cin >> a >> b >> aa >> bb; if (aa <= bb) aa = bb + 1; vector<pair<int, int> > ans; if (aa > a) { cout << 0; return 0; } else { for (int i = bb; i <= b; i++) for (int j = (aa > i + 1 ? aa : ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10005; short dp[MAXN][MAXN]; int32_t main() { ios::sync_with_stdio(false); string s, t; cin >> s >> t; dp[0][0] = 0; int n = s.size(), m = t.size(); for (int i = 0; i <= n + 3; i++) for (int j = 0; j <= m + 3; j++) dp[i...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1.01e9; const long long infll = (long long)1.01e18; const long double eps = 1e-9; const long double pi = acos((long double)-1); mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x) { return mrand() % x; } ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; const long double pi = acos(-1); const int MOD = 1e9 + 7; int main() { int n; scanf( %d , &n); set<int> tem = {1, 5, 10, 50}; vector<int> v = {1, 5, 10, 50}; if (n == 1)...
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; string s[30]; string ans[30]; string sans[30]; vector<pair<int, int> > v[30]; int get(char c) { if (c <= B ) return c - A ; else return c - a + 2; } ...
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll T,N,K,i,j,k,l,ans; string S; cin>>T; while (T--) { cin>>N>>K; cin>>S; ans=1; for(i=0;S[i]!= * ;i++); for(j=S.length()-1;S[j]!= * ;j--); if(...
#include <bits/stdc++.h> using namespace std; const int MaxN = 5010; int N, l, r; long long ans; int main() { scanf( %d%d , &N, &l); r = l; for (int i = 1, __end = N; i <= __end; ++i) { int u, v; scanf( %d%d , &u, &v); if (max(l, u) <= min(r, v)) { l = max(l, u); ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000 ) using namespace std; int n; char s[2000][2001]; bool A[2000][2000]; int C[2][2000]; int Z[2][2000]; bool F(int x, int y) { return (x >= 0 && y >= 0 && x < n && y < n); } int main() { cin >> n; for (int(i) = (0); (i) < (n); ++...
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x...
#include <bits/stdc++.h> using namespace std; const int maxn = 100501; struct bor { int a[27]; }; bor q[maxn]; int free1 = 0; void add(string &s, int pos, int i) { if (pos == (int)s.size()) { return; } if (q[i].a[s[pos] - a + 1] == 0) { free1++; q[i].a[s[pos] - a + 1]...
#include <bits/stdc++.h> using namespace std; bool cmp(pair<pair<long long int, long long int>, long long int> a, pair<pair<long long int, long long int>, long long int> b) { if (a.first.first != b.first.first) return a.first.first < b.first.first; else return a.first.second < b.first...
#include <bits/stdc++.h> using namespace std; int a[110]; int gcd(int x, int y) { if (!x) return y; else return gcd(y % x, x); } int main() { int n, mx = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; mx = max(mx, a[i]); } int g = a[0]; for (int...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> cnt(1e5 + 2, 0), dp(1e5 + 2, 0); while (n--) { long long x; cin >> x; cnt[x]++; } dp[1] = cnt[1]; for (int i = 2; i < 1e5 + 2; i++) { dp[i] = max(dp[i - 1], dp[i - 2] + c...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f;...
#include <bits/stdc++.h> using namespace std; int main() { string s; int m; cin >> s >> m; while (m--) { int l, r, k; cin >> l >> r >> k; int init = l - 1; int len = r - l + 1; string ns = s; for (int i = init; i < r; i++) { int pos = init + (i - init + k)...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 7; long long n, m, a[maxn], b[maxn]; vector<long long> vt[100]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = 1; i <= n; i++) { cin >> b[i]; long long gau = b[i]; ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; string str[N]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> str[i]; } for (int i = 0; i < ((int)(str[0]).size()); i++) { bool all = true; char only = 0; for (int j = 0; j < n; j+...
#include <bits/stdc++.h> using namespace std; const int inf = 1000 * 1000 * 1000; const int maxn = 20; int n, sz[maxn + maxn], ans, d[maxn + maxn][(1 << maxn)]; vector<int> g[maxn + maxn][26]; bool was[maxn + maxn][(1 << maxn)]; char a[maxn][maxn]; int calc(int v, int mask) { if (was[v][mask]) retur...
#include <bits/stdc++.h> using namespace std; int n; int head[100010], to[200010], nxt[200010], cnt, d[100010]; inline void AddEdge(int u, int v) { ++cnt, to[cnt] = v, nxt[cnt] = head[u], head[u] = cnt; } int mxd, mxu, f[100010]; inline void Find(int u, int p, int d) { if (d > mxd) mxd = d, mxu = ...
#include <bits/stdc++.h> using namespace std; bool good() { string input; cin >> input; stack<int> pm; for (int i = 0; i < input.length(); i++) if (pm.empty() || input[i] != pm.top()) pm.push(input[i]); else pm.pop(); return pm.empty(); } int main() { cout << ...
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; multiset<int> val[maxn]; struct Trie { int next[maxn][26], fail[maxn], end[maxn]; int last[maxn]; int root, L; int newnode() { for (int i = 0; i < 26; i++) next[L][i] = -1; fail[L] = last[L] = end[L] = 0; re...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int WYMIAR = 17; int mod = MOD; struct M { int t[WYMIAR][WYMIAR]; M() { for (int i = 0; i < (WYMIAR); ++i) for (int j = 0; j < (WYMIAR); ++j) t[i][j] = 0; for (int i = 0; i < (WYMIAR); ++i) t[i][i] = 1;...
#include <bits/stdc++.h> int f[5005], g[5005], h[5005], n; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &h[i]); memset(f, 66, sizeof(f)); f[0] = 0; for (int i = 1; i <= n; i++) { int j = i, sum = h[j]; while (j && sum < f[j - 1]) sum += h[--j]; if (sum...
#include <bits/stdc++.h> using namespace std; char symmetric[11] = { A , H , I , M , O , T , U , V , W , X , Y }; bool isPrime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if...
#include <bits/stdc++.h> using namespace std; string nums[1005]; string tostr(int a) { ostringstream ss; ss << a; return ss.str(); } deque<long long> deq; vector<int> ans[200001]; vector<pair<int, int> > graph[200001]; int p[200001]; int cmax = 0; void dfs(int v, int d) { int c = 0; ...
#include <bits/stdc++.h> using namespace std; int bit[100005], n, dt; set<int> ms; vector<int> nums, ops; void add(int pos, int val) { while (pos <= (int)nums.size()) { bit[pos] += val; pos += (-pos) & pos; } } int sum(int pos) { int res = 0; while (pos > 0) { res += bit[...
#include <bits/stdc++.h> using namespace std; int main() { long long n, l, r; cin >> n; pair<pair<long long, long long>, long long> lr[n + 1]; for (long long i = 1; i <= n; i++) { cin >> lr[i].first.first >> lr[i].first.second; lr[i].second = i; } sort(lr + 1, lr + n + 1); fo...
#include <bits/stdc++.h> using namespace std; long long KuriBija[1005]; long long A; long long Cik, lol; int main() { cin >> Cik >> lol; for (long long i = 0; i < lol; i++) { cin >> A; KuriBija[A] = 1; cin >> A; KuriBija[A] = 1; } lol = 1; while (KuriBija[lol] != 0)...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if ((n - 1) * n / 2 <= k) { cout << no solution << endl; return 0; } long x, y; x = y = 0; while (n--) { cout << x << << y++ << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string ent = n ; string space = ; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int zero, one; zero = one = 0; for (int i = 0; i < n; i++) { if (s[i] == 48) zero++; else ...
#include <bits/stdc++.h> using namespace std; struct Query { int prefixe, nombre; int id; bool operator<(const Query& autre) const { return prefixe < autre.prefixe; } }; const int MAXP = 20; const int MAXN = 100 * 1000 + 10; const int MOD = 1000 * 1000 * 1000 + 7; bool prise[MAXP]; int puiss...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long arr[n + 2]; for (int i = 1; i <= n; i++) cin >> arr[i]; long long cume[n + 2], cumo[n + 2], rcume[n + 2], rcumo[n + 2]; cume[0] = 0; cumo[0] = 0; for (int i = 1; i <= n; i++) { if (i % 2) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string s; int x = 0, y = 0; cin >> s; for (int i = 0; i < t; i++) { if (s[i] == L ) { x--; } else { y++; } } cout << y - x + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct __s { __s() {} ~__s() { long long n; cin >> n; } } __S; double mm, back, now, ans; long long m, n; double st(double x) { double res = 1.0; for (long long i = 0; i < (long long)(n - 1); i++) { res *= x / m; } r...
#include <bits/stdc++.h> using namespace std; int N, M; int p[1010]; long long X[1010]; int A[1010]; long long B[1010]; int U[2020]; int V[2020]; int up[1010]; bool chk[2020]; bool vst[1010]; bool chkv[1010]; long long mn[2020]; vector<int> adj[1010]; priority_queue<pair<long long, int>, v...
#include <bits/stdc++.h> #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( O3 , omit-frame-pointer , inline ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) using namespace std; const long long mod = 998244353; mt19937 rng((int)chrono::steady_clock::now...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, c = 1; cin >> n; int a[n + 1]; memset(a, 0, sizeof(a)); for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { if (a[i] != a[i + 1]) c++; } cout << c - 1 << n ; }
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2, k1, k2, d1, d2; scanf( %d %d %d %d , &n1, &n2, &k1, &k2); if (n1 > n2) { printf( First n ); } else { printf( Second n ); } return 0; }
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, /STACK:336777216 ) using namespace std; int IT_MAX = 1 << 18; const long long MOD = 1000000007; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1); const double ERR = 1e-1...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; double p = 0, x = 0, m, n, i; cin >> m >> n; for (i = m; i >= 1; i--) { p += (1 - pow(((i - 1) / m), n) - x) * i; x += 1 - pow(((i - 1) / m), n) - x; } cout << fi...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 40; int v[N], x[N], ct, al[N], col[N], n, lu[N], lv[N]; int read() { int sum = 0, fg = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) fg = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { ...
#include <bits/stdc++.h> using namespace std; long long m, ans; string ss, s; long long i; int main() { cin >> s; for (i = 0; i + 4 < s.length(); i++) { ss = s.substr(i, 5); if (ss == heavy ) { m++; } if (ss == metal ) { ans += m; } } cout << ans...
#include <bits/stdc++.h> using namespace std; int a[1006]; int k; int fun(int x) { int mid, high = k - 1, low = 0, i; while (high >= low) { mid = (low + high) >> 1; if (a[mid] < x) { low = mid + 1; } else if (a[mid] > x) { high = mid - 1; } else break; ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long x, y, k; cin >> x >> y >> k; long long qtd = (((y + 1) * k - 1) + (x - 2)) / (x - 1); cout <<...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; const int maxm = 2e5 + 5; const long long inf = 0x3f3f3f3f3f3f3f3f; int xx[] = {0, 0, 1, -1}; int yy[] = {1, -1, 0, 0}; int N, M, K; vector<pair<int, long long> > vec[maxn]; vector<int> V; vector<long ...
#include <bits/stdc++.h> long long POW(long long m) { long long t = 1; for (long long k = 1; k <= m; k++) t *= 4; return t; } int main() { long long n; scanf( %I64d , &n); if (n == 3) { printf( 24 ); return 0; } long long ans = 4 * (3 * POW(n - 3) * 2 + 9 * POW(n - 4) *...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; long long n, m, cnt[55], used[55], add[55]; bool vis[55]; vector<long long> v[55], p; pair<long long, long long> it[55]; long long fa[55]; long long getfa(long long x) { if (x == fa[x]) return x; else return ...
#include <bits/stdc++.h> using namespace std; const int N = 200010, INF = 0x3f3f3f3f; int n, m, k; struct books { int t, id; bool operator<(const books &w) const { return t < w.t; } } A[N], B[N], C[N], D[N]; int main() { cin >> n >> m >> k; int a = 0, b = 0, c = 0, d = 0; for (int i = 1;...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 1; int n, k, m, a, cnt[maxn], last[maxn], id[maxn], res[maxn]; void Enter() { cin >> n >> k >> m >> a; for (int i = 1; i <= a; ++i) { int g; cin >> g; ++cnt[g]; last[g] = i; } } void Init() { for (in...
#include <bits/stdc++.h> using namespace std; int main() { int S, C = 1; cin >> S; int *N = new int[S]; for (int i = 0; i < S; i++) cin >> N[i]; sort(N, N + S); for (int i = 0; i < S; i++) if (N[i] >= C) C++; cout << C; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); long long cur = n - 1, mid = (n - 2) / 2, res = 0; fo...
#include <bits/stdc++.h> using namespace std; long long int nextAlice[7][7]; long long int nextBob[7][7]; long long int nodeNum[7][7]; pair<long long int, long long int> curScore; pair<long long int, long long int> cycScore; pair<long long int, long long int> gameScore(long long int x, long long int y) { ...
#include <bits/stdc++.h> using namespace std; int last[444444], pr[444444], p[444444], pred[444444]; string s[444444], t; int ans, n, len; void go(int v, int K) { int j = last[v]; while (j > 0) { int k = K, sz = s[j].length(); for (int q = 0; q < sz; q++) { while (k > 0 && s[j][q] ...
#include <bits/stdc++.h> using namespace std; using ld = long double; using vi = vector<int>; using vll = vector<long long int>; 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 (int)a.size(); } ...
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long N = 60, K = 10000 + 5; long long dp[K][N]; long long prob[N][N]; long long n, k; long long inv[N]; long long power(long long a, long long k) { if (k == 0) return 1; long long ans = power(a, k / 2); ans...
#include <bits/stdc++.h> using namespace std; int main() { long long n, d, e; cin >> n >> d >> e; long long a = n, b = n, i; e = 5 * e; for (i = 0; e * i <= n; i++) { a = min(a, (n - (e * i)) % d); } for (i = 0; d * i <= n; i++) { b = min(b, (n - (d * i)) % e); } cout...
#include <bits/stdc++.h> using namespace std; int F[1024]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; char a; int b; for (int mask = 0; mask < (1 << 10); mask++) { F[mask] = mask; } for (int i = 0; i < n; i++) { cin >> a >> b; f...
#include <bits/stdc++.h> using namespace std; void solve() { long long w, h, k, ans = 0; cin >> w >> h >> k; for (long long i = h, j = w; i > 0, j > 0, k > 0; i -= 4, j -= 4) { ans += 2 * i + 2 * j; ans -= 4; k--; } cout << ans << endl; } signed main() { ios_base::sync_...
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int t; std::cin >> t; while (t--) { int n; std::cin >> n; std::string res(n, a ); if (n == 1) 0; else if (n % 2) { res[(n - 3) / 2] = b ; res[n - 1] = c...
#include <bits/stdc++.h> using namespace std; const int XI = INT_MAX, NI = INT_MIN, MOD = 1e9 + 7; string s; int a[400]; int main() { cin >> s; for (int i = 0; i < 26; i++) { a[s[i]]++; } for (int i = 25; i < s.length(); i++) { bool k = 1; int cnt = 0; string second = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 10, inf = 1000000000; int n, k, com[maxn], mn[maxn][maxn], dp[2 * maxn][maxn], ind[maxn][maxn], u = 1; string s[maxn]; void go(int l, int r) { if (l == r) return; ind[l][r] = u++; int pos = l; for (int i = l; i < r; i++) ...
#include <bits/stdc++.h> using namespace std; int n, m, viz[501], a[501][2], l[501], sol[501]; int ABC(int a) { return (a) > 0 ? (a) : (-(a)); } int main() { int i, j, x; cin >> n >> m; for (i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; for (i = 0; i < m; i++) cin >> l[i]; for (i = 0; i < n;...
#include <bits/stdc++.h> int main() { long long int t, sum, ar[32], n, c; for (int i = 0; i <= 31; i++) { ar[i] = pow(2, i); } scanf( %lld , &t); for (int i = 0; i < t; i++) { sum = 0, c = 0; scanf( %lld , &n); for (int i = 0; i < 31; i++) { if (ar[i] <= n) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n < 4) { cout << NO ; return 0; } cout << YES << endl; if (n % 2 == 0) { for (int i = 6; i <= n; i += 2) { cout << i << - << i - 1 << = 1 << endl; } cout << 4 * 3 ...
#include <bits/stdc++.h> using namespace std; const int MAX = 100020; const long long MOD = (int)1e9 + 7; const int INF = 1e9; const long long LLINF = 0x3f3f3f3f3f3f3f3f; const long double EPS = 1e-7; int logv[MAX + 1]; void make_log() { logv[1] = 0; for (int i = 2; i <= MAX; i++) logv[i] = logv...
#include <bits/stdc++.h> using namespace std; pair<int, int> pii[10]; double ans = 0.0; double cal(int n, int p, int vote, int A, int B) { if (n == p) { if (vote > n / 2) return 1.0; else return 1.0 * A / (A + B); } if (pii[p].second == 100) return cal(n, p + 1, vote + 1,...