solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 7; long long n; int main() { cin >> n; int flag = 0; for (int i = 2; (long long)i * i <= n; i++) { if (n % i == 0) { flag = i; break; } } if (!flag) { puts("1"); return 0; } if (n % 2 == 0) cout << n / 2 << ...
2
#include <bits/stdc++.h> using namespace std; inline bool equal(double _x, double _y) { return _x > _y - 1e-9 && _x < _y + 1e-9; } int a[25][5005]; int main() { int n, k, q, x; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[1][i]); for (int j = 2; j <= k; j++) a[j][i] = a[1][i] * j;...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; int n; cin >> n; int i, j; int a[n]; std::map<int, int> map; for (i = 0; i < n; i++) { cin >> a[i]; map[a[i]]++; } int dist = map.size(); std::vector<int> v; for (auto it ...
1
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long n, m, ans = 0; int main() { cin >> n >> m; for (long long i = 1; i <= n; i++) ans += (i + m) / 5 - i / 5; cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> int n, m, t[500005], rk[500005]; int vis[500005]; int cmp(int a, int b) { return t[a] < t[b]; } std::vector<int> E[500005]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; ++i) { int u, v; scanf("%d%d", &u, &v); E[u].push_back(v); E[v].push_back(u); } for (in...
4
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class ...
6
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, mod = 1e9 + 7; int n, t, w, x[N], y[N], a[N], b[N], p[N], f[N], s[N], d[N]; int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]), a[++t] = x[i], b[...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m, h; while (cin >> n >> m >> h) { int i, tot = 0, sh, tem; for (i = 1; i <= m; i++) { cin >> tem; tot += tem; if (i == h) sh = tem; } if (tot - 1 < n - 1) { printf("-1.0\n"); continue; } if (tot ...
4
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long n = 1, n2, a[200010], sum[200010]; vector<long long> dat[800010]; struct stane { string val; bool isneg; } ans; void INIT(int k, int lb, int ub) { if (lb == ub) return; INIT(k * 2 + 1, lb, (lb + ub) / 2); INIT(k * 2 + 2, (l...
7
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; const long double PI = acos(-1); const long long INF = LLONG_MAX; const long long M = 1e5 + 10; const long long mod = 1e9 + 7; const long double eps = 1e-9; void read(long long t[], long long n) { for (int i ...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, p[2][N], sgt[2][4 * N], ord[N], sgtAns[4 * N], ans[N]; void build(int sgt[], int tl = 0, int tr = n - 1, int u = 1) { if (tl == tr) { sgt[u] = 1; return; } int tm = (tl + tr) / 2; build(sgt, tl, tm, 2 * u); build(sgt, tm + 1,...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long a; cin >> a; long long b = -1; string s; cin >> s; if (s != "R") { b = 0; for (long long i = 0; i < s.length(); i++) { b *= 10; b += s[i] - '0'; } } cin >> s; long long num ...
6
#include <bits/stdc++.h> using namespace std; string s; int a, b; int main() { cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'o') a++; else b++; } if (a == 0) cout << "YES" << endl; else if (b % a == 0) cout << "YES" << endl; else cout << "NO" << endl; return 0...
0
#include <bits/stdc++.h> using namespace std; int n, ans[1000005]; char s[1000005]; struct Hash { int mod = 998244353, h[1000005], pow[1000005]; void build(char s[], int len) { pow[0] = 1; for (int i = 1; i <= len; i++) pow[i] = 26ll * pow[i - 1] % mod; for (int i = 1; i <= len; i++) h[i] = (26ll * h[i ...
9
#include <bits/stdc++.h> using namespace std; ifstream filein("practice.inp"); ofstream fileout("practice.out"); int t, n, a[5001]; void input() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; } string xl() { for (int i = 1; i <= n; ++i) { if (a[a[a[i]]] == i) return "YES"; } return "NO"; } int main...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 10e4 + 5; int main() { int n; cin >> n; string string1 = ""; int maxi = 0; for (int i = 0; i < n; i++) { char a; cin >> a; if (a == '1') maxi++; string1 += a; } vector<pair<int, int>> v; for (int i = 0; i < n; i++) { pair<...
2
#include <bits/stdc++.h> using namespace std; const long long LLINF = 8e18; const int MOD = 1e9 + 7; const int INF = 2e9; const int N = 5000; int n, m, mx, ans, tmx; int a[N], b[N], cnt[N], mn1[N], mn2[N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; fill(mn1, mn1 + n, INF); ...
5
#include <bits/stdc++.h> using namespace std; vector<int> v[102], divisor; int lcm[102][102], gcd[102][102], res[102]; bool flag, visited[102][102], vis[102]; void findDivisiors(int x) { for (int i = 1; i <= (int)(ceil(sqrt(x))); i++) { if (x % i == 0) { divisor.push_back(i); if (i != x / i) divisor.p...
6
#include <bits/stdc++.h> using namespace std; int N, k; string S; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> S; for (int i = 0; i < N; i++) { if (S[i] == 'X') k++; } if (k <= N / 2) { cout << N / 2 - k << '\n'; for (int i = 0; i < N && k < N / 2; i++) { ...
0
#include <bits/stdc++.h> using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar(); if (_tc == '-') _tc = getchar(), _tmp = -1; while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char str[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, n, k; cin >> t; while (t--) { cin >> n >> k; cin >> (str + 1); sort(str + 1, str + 1 + n); if (k == 1) cout << (str + 1) << "\n";...
4
#include <bits/stdc++.h> using namespace std; int hour[10]; int mini[10]; int main() { memset(hour, 0, sizeof(hour)); memset(mini, 0, sizeof(mini)); string s; cin >> s; string s1 = ""; string s2 = ""; int i = 0; for (i = 0; i < s.size(); i++) { if (s[i] != ':') { s1 += s[i]; } else { ...
4
#include <bits/stdc++.h> using namespace std; void bad(string mes = "Impossible") { cout << mes; exit(0); } template <typename... T> void shit(T&... x) {} template <typename... T> void dec(T&... x) { shit(--x...); } template <typename... T> void inc(T&... x) { shit(++x...); } template <typename T> string bin(T ...
3
#include <bits/stdc++.h> using namespace std; int X[] = {-1, -1, -1, 0, 1, 1, 1, 0}; int Y[] = {-1, 0, +1, 1, 1, 0, -1, -1}; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } std::vector<pair<int, int> > g[105]; bool visited[105], color[105]; int m, n; bool dfs(int u) { visited[u] = 1; for (int i = 0; i < g[u...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; const int hashnum = 3; long long base[] = {233, 23, 97}; long long mod[] = {122420729, 1000000007, 1000000009}; int sum[maxn]; char s[maxn]; long long power[hashnum][maxn]; int n; struct node { long long hv[hashnum]; int pref, suf, len; }; ...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5; vector<int> dv[N + 2]; void dvv() { for (int i = 1; i <= N; i++) { for (int j = i; j <= N; j += i) dv[j].push_back(i); } } int ls[N + 2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); dvv(); int n; cin >> n; for (int i = 1; i ...
5
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; cin>>t; while(t--){ string s; cin>>s; int flag=1; int len=s.size(); map<int,int>mp; for(int i=0;i<len;i++){ mp[s[i]-'a']++; if(mp[s[i]-'a']>1){ flag=0; break; } if(s[i]-'a'>=len){ flag=0; ...
0
#include <bits/stdc++.h> using namespace std; int n, m, ans, len1, len2; vector<int>::iterator it; int main() { cin >> n >> m; len1 = 1; len2 = 1; for (int a = 7; a < n; a *= 7) len1 += 1; for (int b = 7; b < m; b *= 7) len2 += 1; if (len1 + len2 <= 7) for (int i = 0; i != n; i++) for (int j = 0; ...
4
#include <bits/stdc++.h> using namespace std; long long MOD_EXPO(long long b, long long p, long long m) { if (p == 0) return 1; long long ret = MOD_EXPO(b, p / 2, m) % m; ret = (ret * ret) % m; return ((p & 1) ? (ret * b) % m : ret % m); } long long POWER(long long N, long long K) { long long i, ans = 1; fo...
6
#include <bits/stdc++.h> int main() { int t, a, b, i, s; scanf("%d", &t); for (i = 1; i <= t; i++) { scanf("%d%d", &a, &b); s = ((24 - a) * 60) - b; printf("%d\n", s); } }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.begin(), a.end()); vector<long long> b(n), s(n); for (int i = 1; i < n; ++i) { b[i] = a[i] - a[i - ...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 0x7FFFFFFF; const int MIN = 0x80000000; int main() { int a, b; cin >> a >> b; int h1[1024], h2[1024], v1[1024], v2[1024]; int temp, count_h1 = 0, count_h2 = 0; for (int i = 1; i < a; i++) { temp = (int)sqrt(double(a * a - i * i)); if (temp ...
4
#include <bits/stdc++.h> using namespace std; int rev[(1 << 21)], mlgn; double omega[(1 << 21)][2]; double FA[(1 << 21)][2], FB[(1 << 21)][2]; inline void mult(double A[2], double B[2], double C[2]) { C[0] = A[0] * B[0] - A[1] * B[1]; C[1] = A[0] * B[1] + A[1] * B[0]; } void calc_rev(int n = (1 << 21)) { while ((...
8
#include <iostream> #include <iomanip> #include <algorithm> #include <vector> #include <cmath> #include <queue> #include <map> #include <set> #include <utility> #include <math.h> #include <string> #include <cstring> #include <cassert> #include <climits> using namespace std; const double PI = acos(-1); const int N=1e5...
3
#include <bits/stdc++.h> using namespace std; double a[10000] = {0}; double b[10000] = {0}; double c[10000] = {0}; int main() { int i, j, k, l, m, n, r = 0; double x, y, z; scanf("%i", &n); for (i = 0; i < n; i++) scanf("%lf", &a[i]); scanf("%i", &m); for (i = 0; i < m; i++) scanf("%lf", &b[i]); scanf("%i...
2
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { ifstream from; const long long nmmin = 1, nmmax = 50, abmin = 1, abmax = 50; long long n, m, res, rt, i, i0, j, j0, k, t, ax, a, b; if (0) from.open("test.txt"); cin >> n >> m; vector<vector<long long> > v(n); for (i = 0; i < ...
2
#include <bits/stdc++.h> int main() { int x, reverse = 0; scanf("%d", &x); while (x) { if (x % 10 == 0) x = x / 10; else break; } int b = x; while (x) { int a = x % 10; reverse = reverse * 10 + a; x = x / 10; } if (reverse == b) { printf("YES"); } else printf("N...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; int a[maxn], b[maxn]; int main() { long long ans; long long t, n, k, x, y; scanf("%lld", &t); while (t--) { scanf("%lld %lld", &x, &y); if (x > y) swap(x, y); long long z = y ...
1
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; int pa[N][22]; int psum[N]; int n; string s, news; int get(int x, int lv) { x = x + n; for (int i = 0; lv; i++, lv >>= 1) if (lv & 1) { x = pa[x][i]; } return x - n; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); c...
9
#include <bits/stdc++.h> using namespace std; using INT = long long; using pii = pair<int, int>; char str[1000010]; int a[111]; int main() { int n; cin >> n; cin >> str + 1; for (int i = 1; i <= n; i++) { char ch = str[i]; if (ch == 'L') { for (int i = 0; i <= 9; i++) if (a[i] == 0) { ...
0
#include <bits/stdc++.h> using namespace std; template <class T> void read(T& x) { char c = getchar(); T p = 1, n = 0; while (c < '0' || c > '9') { if (c == '-') p = -1; c = getchar(); } while (c >= '0' && c <= '9') { n = n * 10 + c - '0'; c = getchar(); } x = p * n; } template <class T, c...
9
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; inline 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(); }...
7
#include <bits/stdc++.h> using namespace std; string s; char ch; long long ans; int find() { cout << "? 0 1" << endl; fflush(stdout); cin >> ch; if (ch == 'x') { cout << "! 1" << endl; fflush(stdout); return 0; } cout << "? 0 2" << endl; fflush(stdout); cin >> ch; if (ch == 'x') { cout...
6
#include <bits/stdc++.h> using namespace std; int main() { long long ans = 0; long long n; cin >> n; long long it = 0; while (true) { if (n - 9 * pow(10, it) < 0) { it++; break; } n = n - 9 * pow(10, it); it++; } for (int i = 0; i < it - 1; i++) { ans += (i + 1) * 9 * pow(1...
2
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; cout << (long long)(n - 2) * (n - 2); }
1
#include <bits/stdc++.h> using namespace std; long long n, m, a[500001], b[500001], ans, sum, cnt; inline bool check(long long x) { sum = cnt = 0; priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > > q; for (...
8
#include <bits/stdc++.h> using namespace std; const int mn = 2e5 + 10; char ch[mn]; int deep[mn]; struct TREE { int dma, dmi, dab, dbc, dabc; int lazy; } tr[4 * mn]; void pushup(int id) { int ls = 2 * id, rs = 2 * id + 1; tr[id].dma = max(tr[ls].dma, tr[rs].dma); tr[id].dmi = min(tr[ls].dmi, tr[rs].dmi); tr...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } int cnt = 0, j = 0; bool swapped = false; for (int i = 1; i < n; i++) { int temp = a[i]; for (j = i; j > 0 && temp < a[j - 1]; j--) { ...
4
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e5 + 5; const long long mod = 1e9 + 7; long long n; vector<long long> vc[maxN]; long long cnt; long long order[maxN]; long long in[maxN]; long long out[maxN]; long long a[maxN]; long long h[maxN]; long long par[maxN]; long long x, y; long long root; ...
8
#include <bits/stdc++.h> using namespace std; int n; long long k; int a[100000]; int main() { cin >> n; cin >> k; long long tmpsum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; tmpsum += a[i]; } if (tmpsum < k) { cout << -1; return 0; } int l = 0, r = 1000000000; int times = 0; whi...
5
#include <bits/stdc++.h> using namespace std; unsigned long long mat[2100][40]; int binaryJordanGauss(int r, int c, int right) { int b = (c + right + 63) / 64; int rnk = 0; for (int _n(c), j(0); j < _n; j++) { int i = rnk; for (; i < r; ++i) if (mat[i][j >> 6] & (1ull << (j % 64))) break; if (i ...
9
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
4
#include <bits/stdc++.h> int main() { char a[200], b[100]; scanf("%s", a); int i, j; for (i = 0; i < strlen(a); i = i + 1) { if (a[i] == 'W' && a[i + 1] == 'U' && a[i + 2] == 'B') { a[i] = ' '; a[i + 1] = '0'; a[i + 2] = '0'; } } for (i = 0, j = 0; i < strlen(a); i = i + 1) { i...
0
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 10; const int maxn = 5e3 + 10; const int maxq = 1e2 + 10; const int alf = 26; const long long dlm = 1e9 + 7; const int del = 1234234; const int eps = 1e-7; string O[] = {"YES", "NO", "Yes", "No"}; int a[maxn]; pair<int, int> dp[maxn][maxn]; int m...
5
#include <bits/stdc++.h> using namespace std; const int max_n = 111, inf = 1111111111; int n; string s; int main() { cin >> n >> s; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (s[i] == '*' && s[j] == '*') { int d = j - i, x = j, f = 0; for (int k = 0; k < 3; ++k) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2, k1, k2; scanf("%d%d%d%d", &n1, &n2, &k1, &k2); if (n2 >= n1) puts("Second"); else puts("First"); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long infLL = 0x3f3f3f3f3f3f3f3fLL; const int maxn = 100000 + 5; const int mod = 1000000007; int n; vector<int> ch[maxn]; bool vis[maxn]; int f[maxn][2]; void dp(int u) { if (vis[u]) return; vis[u] = true; f[u][0] = 0; f[u][1] =...
9
#include<bits/stdc++.h> using namespace std; const long long inf=1000000000000000000ll; int q[2000200],l,r,cnt,n,d,x,hd[2200],la[2200],f[2200],lo[2200]; struct node{int to,next,c,val;}e[2000010]; char s[1100]; bool inq[2200]; long long dis[2200]; vector<int> pa; void add(int x,int y,int c,int val) { e[++cnt]=(node){...
9
#include <bits/stdc++.h> using namespace std; int n, k, ans, y, t; vector<int> a, v, h, sf; int main() { cin >> t; while (t--) { cin >> n >> k; sf.clear(); sf.resize(n + 2, 0); a.resize(n + 1, 0); v.resize(n + 1, 0); h.resize(n + 1, 0); for (int i = 1; i <= n; ++i) cin >> a[i]; for (...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e5; bool vis[2500], check = 0; long long counter, maxi = 0; vector<vector<long long>> adj(N); void dfs(int node, int levels) { vis[node] = 1; levels++; for (long long i = 0; i < adj[node].size(); i++) { int child = adj[node]...
0
#include <bits/stdc++.h> using namespace std; char s[200000 + 5]; int a[200000 + 5]; int main() { int n; while (~scanf("%d", &n)) { scanf("%s", s); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int minn = 1000000000, flag = 0; for (int i = 0; i < n; i++) { if (s[i] == 'R' && s[i + 1] == 'L')...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long t; while (a % b) { t = a % b; a = b; b = t; } return b; } int main() { long long a, b, l; cin >> a >> b; l = (a * b) / gcd(a, b); a = a; b = b; long long fir, sec; fir = (l - 1) / a; sec...
3
#include <bits/stdc++.h> using namespace std; int x[4]; int y[4]; int ii[4] = {1, -1, 0, 0}; int jj[4] = {0, 0, -1, 1}; int main() { ios_base::sync_with_stdio(0); int x1, x2, x3, y1, y2, y3; for (int i = 1; i <= 3; i++) { cin >> x[i] >> y[i]; } set<pair<int, int>> s; long long xx = 0, yy = 0; long lon...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1.5e5 + 70; const int INF = 2.1e9; const int MOD = 1e9 + 7; const double eps = 1e-7; const double PI = acos(-1.0); int n, m, k; int f[maxn]; vector<int> G[maxn]; void init(int n) { for (int i = 1; i <= n; i++) { G[i].clear(); G[i].push_back(i); ...
4
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; const double pi = 2 * acos(0.0); const int N = 3e5 + 5; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, t; cin >> t; while (t--) { cin >> n; int x, z = 0, tot = 0; for (int i = 0; i < n; i++) {...
0
#include <bits/stdc++.h> using namespace std; constexpr int MAXN = 2e5 + 1; constexpr int MAGIC = 4; using ll = long long; using Arr = array<int, MAGIC>; int N, M, K; string s; int x[MAXN], y[MAXN], len[MAXN]; Arr MOD, BASE; inline int norm(int a, const int& mod) { while (a >= mod) a -= mod; while (a < 0) a += mod;...
7
#include <bits/stdc++.h> using namespace std; int a[500005]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; int ans = 0; for (int i = 1; i <= n;) { int j = i; while (j + 1 <= n && a[j] != a[j + 1]) ++j; int len = j - i + 1; if (a[i] == a[j]) { for (int k = i + 1;...
4
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") const int MAXN = 3e5 + 10; const int LOG = 20; using namespace std; struct Seg { int soma[MAXN * 4]; int mx[MAXN * 4]; int m(int l, int r) { return (l + r) >> 1; } void upd(int pos, int l,...
8
#include <bits/stdc++.h> using namespace std; int T, n, m; bool check(int k) { if (n == 1) return 1; long long num = (long long)m * k, res = 1, C = 1; for (int i = 1; i <= k; i++) { if (num < i) return 0; if ((long long)(k - i + 1) * C >= (long long)n * i) C = n; else C = C * (k - i + 1) /...
9
#include <bits/stdc++.h> using namespace std; int mark[1000001], dp[1000001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, a, ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; mark[a] = 1; dp[a] = 1; } for (int i = 1; i < 1000001; i++) if (mark[i]) { ans...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1000], i, j; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n - 1; i++) { for (j = 0; j < n - 1; j++) { if ((min(a[i], a[i + 1]) < min(a[j], a[j + 1]) && min(a[j], a[j + 1]) < max(a[i], a[i + 1]) && ...
3
#include <bits/stdc++.h> using namespace std; const int N = 5005; pair<pair<int, int>, int> p[N]; pair<pair<int, int>, int> v[2 * N]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; p[i] = pair<pair<int, int>, int>(pair<int, int>(a, b), i); v[2 * i] = pair<pair...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1e8; const int MAXN = 100000; void solve() { vector<string> v(8); for (int i = 0; i < 8; ++i) cin >> v[i]; int minA = 10; for (int j = 0; j < 8; ++j) { int curA = 0; while (curA < 8 && v[curA][j] == '.') curA++; if (curA < 8 && v[curA][j]...
2
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int r = 1; x = x % p; while (y) { if (y & 1) r = r * x % p; y = y >> 1; x = x * x % p; } return r; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());...
3
#include <bits/stdc++.h> using namespace std; char str[100007]; int ar[100007]; int ans[100007]; int main(void) { scanf("%s", str); int n = strlen(str); int i, ps, mx = 0; for (i = n - 1; i >= 0; i--) { if (str[i] == ')' || str[i] == ']') continue; if (str[i] == '(' && str[i + 1] == ')') { ar[i] =...
4
#include <bits/stdc++.h> using namespace std; template <class T> T abss(T a) { return a > 0 ? a : -a; } const static double eps = 0.001; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); size_t _q_; cin >> _q_; while (_q_--) { int64_t angle; cin >> angle; uint64_t n...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, a[N], b[N]; int sum = 0; bool check(int x) { bool vis[N] = {0}; int cur = x - m - sum; int cnt = 0; while (x) { if (cur < 0) return false; if (a[x] != 0 && !vis[a[x]]) { cnt++; vis[a[x]] = true; cur += b[a[x...
4
#include <bits/stdc++.h> int main() { int T; scanf("%d", &T); while (T--) { double a, b; scanf("%lf %lf", &a, &b); double x, y; if (b >= (a / 4)) { x = (b + a / 8) * a; y = a * 2 * b; } else if (b < (a / 4)) { x = a * b + (2 * a - 4 * b) * b / 2; y = a * 2 * b; } ...
5
#include <bits/stdc++.h> using namespace std; const int BIT = (1 << 17), M = 110, N = 25; int n, m, cnt[BIT], a[M]; long long f[BIT][N], b[N], p[N], year; void solve(int x) { memset(f, 0, sizeof(f)); f[0][0] = 1; int maxb = (1 << n); for (int i = 0; i < maxb; i++) { for (int j = 0; j <= n; j++) { int ...
8
#include <bits/stdc++.h> using namespace std; long long sum(long long a, long long b) { return ((b * (b + 1)) - ((a - 1) * a)) / 2; } long long ind(long long a, long long val) { double D = sqrt((2 * a - 1) * (2 * a - 1) + 8 * val); return (long long)((1 - 2 * a + D) / 2); } int main() { ios_base::sync_with_stdi...
2
#include <bits/stdc++.h> using namespace std; void see(int x) { cout << x; } void see(long long int x) { cout << x; } void see(long double x) { cout << x; } void see(char x) { cout << '\'' << x << '\''; } void see(string x) { cout << '\"' << x << '\"'; } template <typename T, typename V> void see(const pair<T, V> &x) {...
6
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; bool a[N]; int ps[N]; int n, k; int canDo(int x) { for (int i = 0; i + x <= n; i++) if (ps[i + x] - ps[i] <= k) return i; return -1; } int main() { ios::sync_with_stdio(false); cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; fo...
4
#include <bits/stdc++.h> bool H[9][9][9][9]; char t[4]; int n; void set() { int i; for (i = 0; i < 4; i++) t[i] = t[i] - '0'; } void look(int i, int j, int k, int l) { H[j][k][l][i] = H[j][k][l][i] = H[k][l][i][j] = H[l][i][j][k] = false; } int main() { int i, j, k, l, s = 0; char tm[3]; scanf(" %d", &n); ...
2
#include <bits/stdc++.h> using namespace std; void bug() { cout << " " << endl; } template <class T> void bug(T a) { cout << a << " "; } template <class T> void bug(T* a, int n) { for (int i = 0; i < (n); i++) bug(a[i]); } priority_queue<pair<long long, int> > q; int n, m; vector<pair<int, long long> > g[1111111];...
9
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6; pair<int, int> a[maxn]; long long b[maxn]; int n, m; long long getLen(int i) { if (a[i].second == -1) return 1; return 1ll * a[i].first * a[i].second; } int main() { scanf("%d", &m); vector<int> v; for (int i = 0; i < m; ++i) { int t...
4
#include <bits/stdc++.h> using namespace std; int main() { { ios_base::sync_with_stdio(false); cin.tie(NULL); }; int n; cin >> n; vector<int> v; int sum = 0; for (int i = 0; i < 500; i++) { sum += i; v.push_back(sum); } int ara[27] = {0}; int ch = 0; if (n == 0) { cout << 'a'; ...
4
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); const int MAXN = 400003; int ad[MAXN]; int vl[MAXN]; int x[MAXN]; int lv; void modify_rmq(int v, int l, int r) { if (l == r) { if (x[l] == 0) vl[v] = ad[v] = -1; else vl[v] = ad[v] = 1; return; } int md = (l +...
7
#include <bits/stdc++.h> using namespace std; const int MAX = 3005; int dp[MAX][2]; int n, a[MAX], b[MAX], c[MAX]; int go(int id, int fed) { if (id == n - 1) { if (fed) return b[id]; else return a[id]; } int& ans = dp[id][fed]; if (ans != -1) return ans; ans = 0; if (fed) { ans = max...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; signed long long t; cin >> t; while (t--) { string s; cin >> s; signed long long x; cin >> x; int n = s.length(); vector<bool> vis(n, false); string w(n, '1')...
3
#include <bits/stdc++.h> using namespace std; string s; char token[10500]; int cnt = 0; vector<long long> st; vector<char> op; int prior[128]; inline int next(int i) { if (!token[i + 1]) return i + 2; return i + 1; } inline void process(char o) { long long a = st.back(); st.pop_back(); long long b = st.back()...
6
#include <bits/stdc++.h> using namespace std; int n, m, id[200100], cnt = 1; struct Suffix_Automaton { int ch[26], len, fa; } t[400100]; int Add(int x, int c) { int xx = ++cnt; t[xx].len = t[x].len + 1; for (; x && !t[x].ch[c]; x = t[x].fa) t[x].ch[c] = xx; if (!x) { t[xx].fa = 1; return xx; } int...
9
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int n) { if (n == 1) { return false; } for (long long int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } int power(int x, unsigned int y, int p) { int res = 1; x = x % p; if (x == 0) return 0; while ...
4
#include <bits/stdc++.h> int main() { char a[1005]; scanf("%s", &a); if (a[0] >= 'a' && a[0] <= 'z') { a[0] = a[0] - 32; } printf("%s\n", a); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, x, y; vector<int> vec; bool check(int i) { int l = i - 1, r = i + 1; while (l >= 0 && abs(l - i) <= x) { if (vec[l] < vec[i]) return false; l--; } while (r < n && abs(r - i) <= y) { if (vec[r] < vec[i]) return false; r++; } return true; } ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; bool nw = 0; while (t--) { if (nw) cout << '\n'; nw = 1; int n, k; cin >> n >> k; vector<int> a(n); for (int& x : a) cin >> x; string ac; if (n == 1 && a[0] =...
6
#include <bits/stdc++.h> using namespace std; const int MAX_N = 513; int a[MAX_N], b[MAX_N], last[2 * MAX_N], d[MAX_N][MAX_N]; pair<int, int> pr[MAX_N][MAX_N]; set<int> s; map<int, int> ma; vector<int> numbers; int main() { int n, m; scanf("%d", &n); for (int i = 0; (i) < (n); ++i) scanf("%d", &a[i]), s.insert(a[...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100005, maxm = 25; struct node { int I, Sum[2], Max[2], L[2], R[2], Lmax[2], Lto[2], Rmax[2], Rto[2]; bool boo; } tree[maxn << 2]; struct data { int Sum, Max, L, R, Lmax, Lto, Rmax, Rto; data() {} data(int A, int B, int C, int D, int E, int F, int...
10
#include <bits/stdc++.h> using namespace std; int main() { int x, n, m; cin >> n >> m; vector<pair<int, int> > v; vector<int> res(n); for (int i = 0; i < n; i++) { cin >> x; v.push_back(make_pair(x, i)); } sort(v.begin(), v.end()); for (int i = 0; i < n; i++) { if (i % 2 != 0) res[v[i]...
4
#include <bits/stdc++.h> using namespace std; const int nMax = 100100; vector<int> e[nMax]; int n; int s[2][nMax * 3]; int t[2], k[2]; void M(int *a, int x) { while (x < nMax * 3) { a[x]++; x += (x & (-x)); } } int S(int *a, int x) { int res = 0; while (x) { res += a[x]; x -= (x & (-x)); } r...
4
#include <bits/stdc++.h> using namespace std; const int N = 201000; int n, x, zz[N], k, pos, ans[N], c[N], m; vector<pair<int, int>> ret[N]; pair<int, int> p[N]; void modify(int x, int s) { for (; x <= n; x += x & -x) c[x] += s; } int query(int s) { int z = 0; for (int j = 19; j >= 0; --j) { if (z + (1 << j) ...
5