solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { long n, m, a[100], i, c, d; vector<long> v(100, 0); cin >> n >> m; while (m--) { c = 0; d = 0; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] > c) { c = a[i]; d = i; } } ++v[d]; } c = v[0]; d ...
3
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; map<char, set<char>> g; map<char, int> used; for (int i = 0; i < s1.size(); ++i) { if (s1[i] != s2[i]) { g[s1[i]].insert(s2[i]); g[s2[i]].insert(s1[i]); } else { used[s1[i]] = 1; } } fo...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); cout << a[(int)n / 2] << "\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; int cnt[100005], d[100005]; char c[100005], first[100005]; bool vis[100005], can[100005]; vector<int> ans; set<int> st; bool test(int i, int m) { int k = d[i]; set<int> s; while (i <= m) { if (c[i] == '+') s.insert(d[i]); else s.erase(s.find(d[i]))...
10
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int INF((1 << 30) - 1); const int MAXN(4105); int pi[MAXN]; void Prefix_Function(string a) { pi[1] = 0; int k = 0; for (int i = 2; i <= a.size(); i++) { while (k > 0 && a[k] != a[i - 1]) k = pi[k]; if (a[k] == a[i - 1]) k++; ...
12
#include <bits/stdc++.h> int main() { int a, b, ans, r; fscanf(stdin, "%d%d", &a, &b); ans = 0; for (r = 1; r < b; r++) { ans = (ans + (r * (long long)(a + (b * (long long)((a * (long long)(a + 1) / 2) % 1000000007)) % ...
8
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; int N, a[1505], S, M, K, DP[1505][1505], b[1505], sum[1505], nex[1505]; pair<int, int> seg[1505]; int check(int mid) { sum[0] = 0; for (int i = 1; i <= N; ++i) { sum[i] = sum[i - 1] + (b[i] <= mid ? 1 : 0); } memset(DP, 0, sizeof(DP)); ...
17
#include <bits/stdc++.h> using namespace std; vector<int> adj[10005]; void min_steps(int current, int &count, int parent, int color[]) { if (color[current] != color[parent]) count++; for (auto v : adj[current]) { min_steps(v, count, current, color); } } int main() { int n; cin >> n; int parent, i; for...
4
#include <bits/stdc++.h> inline long long read() { char c = getchar(); long long x = 0, s = 1; while (c < '0' || c > '9') { if (c == '-') s = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * s; } using namespace std; const int N = 1e5 + ...
7
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const double EPS = 1e-9; int mods(long long a, long long b) { return (b + (a % b)) % b; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q; long long sum, a, b, c; cin >> q; while (q--) { sum = 0; ...
0
#include <bits/stdc++.h> using namespace std; const int mm = 2e5 + 100; long long int d[mm], ans[mm]; bool vis[mm]; int main() { long long int n, m, i, j, t, a, b, c, p, k, kk; cin >> n; for (i = 1; i <= n; i++) scanf("%lld", &d[i]); long long int s; k = 0; for (i = 1; i <= n; i++) { s = 1; if (vis[...
7
#include <bits/stdc++.h> using namespace std; int main() { map<string, string> mp; string s, t, k; int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> s >> t; mp[s] = t; } for (int i = 0; i < n; i++) { cin >> k; if (k.length() <= mp[k].length()) { cout << k << " "; } el...
2
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { if (b == 0) return 1; long long int p = (power(a, b / 2)) % 1000000007; if (b % 2 == 0) return (p * p) % 1000000007; else return ((a % 1000000007) * (p * p) % 1000000007) % 1000000007; } long int gcd(lo...
8
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int n, l[300], c[300]; cin >> n; for (int i = 0; i < n; i++) cin >> l[i]; for (int i = 0; i < n; i++) cin >> c[i]; unordered_map<int, int> um; for (int i = 0; i < n; i++) if (um.find(l[i]) ...
11
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; if (x % 2 == 0) cout << "0" << endl; else cout << "1" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<int> heavy, parent, head, size_, end_, pos, orgpos; vector<list<int> > adj; int curr = 1; void dfs(int i) { size_[i] = 1; int maxsize_ = 0; for (auto it : adj[i]) { if (it != parent[i]) { parent[it] = i; dfs(it); size_[i] += size_[it]; ...
16
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,a,b,mn[2000005],mx[2000005],cnt[2000005],vis[1005],m=20; int c[1005],p[1005],rp[1005],t; bool f[2000005]; char s[100005],ans[105]; bool check(int x) { return 1ll*a*(mx[x]-mn[x]+1)<=1ll*cnt[x]*b; } bool cmp(const int x,const int y) { ret...
27
#include <bits/stdc++.h> using namespace std; int b[100][100]; int n; int valid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; } int fillp(int x, int y) { if (!valid(x, y) || b[x][y]) return 0; b[x][y] = 1; return true; } int fill(int x, int y) { if (b[x][y]) return true; return fillp(x, y) && fil...
1
#include <bits/stdc++.h> using namespace std; int main() { int k, r; scanf("%d%d", &k, &r); for (int i = 1;; i++) { if ((i * k) % 10 == 0) { printf("%d\n", i); break; } else if (((i * k) % 10) - r == 0) { printf("%d\n", i); break; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; int arr[110][110]; int main() { int ans = 0; int x, y; int n; cin >> n; if (n == 1) { cout << 1 << endl; return 0; } for (x = 1; x <= n; x++) { arr[1][x] = 1; } for (x = 2; x <= n; x++) { for (y = 1; y <= n; y++) { if (y == 1) { ...
0
#include <bits/stdc++.h> using namespace std; void solve() { int n, x; cin >> n >> x; int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < n; i++) { if (a[i] + b[n - i - 1] > x) { cout << "NO" << "\n"; return; } ...
0
#include <bits/stdc++.h> const char road[1000] = "C:" "\\Users\\lis\\Desktop\\百度网盘\\百度云同步盘\\testcheck\\席位安排\\data" "\\"; char roadnum[1000] = ""; char roadin[1000] = ""; char roadout[1000] = ""; void writeIntoFile(char num[]) { strcpy(roadnum, num); strcpy(roadin, road); strcat(roadin, roadnum); str...
16
#include <bits/stdc++.h> int main() { int n, i; scanf("%d", &n); for (i = 0; i < n; i++) if (i % 3 == 0) printf("%d %d\n", i / 3 * 2, 0); else if (i % 3 == 1) printf("%d %d\n", i / 3 * 2 + 1, 0); else printf("%d %d\n", i / 3 * 2 + 1, 3); return 0; }
18
#include <bits/stdc++.h> using namespace std; map<int, int> add, diff; map<int, int>::iterator it; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int i, j, t, n, m, k, l, r, temp, result, mini, maxi, flag; long long int sum = 0, cnt; cin >> n; for (i = 0; i < n; i++) { cin >> l >> r; add[...
5
#include <bits/stdc++.h> using namespace std; const int inf = 2e9 + 10; struct pp { int value, id; bool operator<(const pp &temp) const { return value > temp.value; } }; pp heap[110000], now; int n, l, st, a[110000], rt[110000], now_in; int ix, pos[110000], size, cnt_list, ans; long long now_sum; bool vis[110000]; ...
21
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n, ans = 0, mod = 998244353; cin >> n; long long a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] *= (i + 1) * (n - i); } sort(a, a + n); for (int i ...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, ans = 0; scanf("%I64d", &n); n--; for (long long i = 1; i <= n; i <<= 1) ans += ((n - i) / (i << 1) + 1) * i; printf("%I64d", ans); }
11
#include <bits/stdc++.h> using namespace std; int a[2000], ans, n, nl; int main() { cin >> n; nl = (1 << n + 1); for (int i = 2; i < nl; i++) cin >> a[i]; for (int i = nl - 2; i > 1; i -= 2) { ans += abs(a[i] - a[i + 1]); a[i / 2] += max(a[i], a[i + 1]); } cout << ans; return 0; }
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 5e5 + 9, MOD = 1e9 + 7; int freq[31]; void runtestcase() { int n, x; cin >> n; memset(freq, 0, sizeof freq); for (int i = 0; i < n; ++i) { cin >> x; for (int j = 0; j < 30; ++j) { if (x & (1 << j)) ++freq[j]; } } bool...
11
#include <bits/stdc++.h> using namespace std; queue<int> q; long long Ans; int n, m, s, t, cnt; int dis[605], cur[605]; int head[605], w[200005], to[200005], Next[200005]; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } ...
21
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (b == 0LL ? a : gcd(b, a % b)); } long double dist(long double x, long double arayikhalatyan, long double x2, long double y2) { return sqrt((x - x2) * (x - x2) + (arayikhalatyan ...
18
#include <bits/stdc++.h> using namespace std; const int N = 1000050; const int INF = 1e9; const int MOD = 1e9 + 7; string s; int main() { ios::sync_with_stdio(0); cin >> s; long long ans = 0; int n = s.length(); bool ok = true; for (int i = 0; i < n; i++) { if (isdigit(s[i])) { long long x = 0; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l, m; float n; cin >> i >> j >> k >> l; n = (float)(j - i) / (k + l); printf("%f", n); }
0
#include <bits/stdc++.h> using namespace std; priority_queue<long long int, vector<long long int>, greater<long long int> > ti; vector<long long int> p[100005], a(2000005), f(200005, 0), d(200005, 0), b(1000005); long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; ++i) scanf("%d", &x[i]); sort(x.begin(), x.end()); x.resize(unique(x.begin(), x.end()) - x.begin()); n = x.size(); int a, b; cin >> a >> b; int cnt = 0; while (a != b) { int a1 ...
14
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, root, tot, t, a, b, c, y, Y, cnt, u, v, A, B, now; int fa[21][100011], dep[100011], S[100011], E[100011], ent[100011]; int Left[4000011], Right[4000011], stop[4000011]; vector<int> e[100011]; int lca(int a, int b) { if (dep[a] > dep[b]) swap(a, b); wh...
21
#include <bits/stdc++.h> using namespace std; using lli = long long; using ld = long double; mt19937 rnd(time(nullptr)); lli GetResult(vector<lli> data, vector<lli> buffer) { lli answer = 0; for (lli i = 0; i < buffer.size(); i++) { lli index = -1; for (lli j = i; j < data.size(); j++) { if (buffer[i]...
6
#include <bits/stdc++.h> using namespace std; namespace jumpmelon { const int MAXN = 7, MAXM = 8, MAXK = 4, INF = 0x3f3f3f3f; const char COL[MAXK] = {'B', 'R', 'W', 'Y'}; char Str[MAXM + 1]; bool Vis[MAXN][MAXM]; int n = 7, m = 8, k = 4, M[MAXN][MAXM], C0[MAXK][MAXK]; int c, C1[MAXK][MAXK], CC[MAXK][MAXK], B[MAXN][MAXM...
21
#include <bits/stdc++.h> using namespace std; using ll = long long int; const ll mod = 1000000007; const ll M = 1000000000000000000ll; inline ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); } inline ll sub(ll a, ll b) { return ((a % mod - b % mod + mod) % mod); } inline ll mult(ll a, ll b) { return (((a % mod)...
3
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ldb; typedef pair<int,int> pii; const int MAXN = 1e5 + 5; const int MAXL = 3e5 + 5; const int mod = 998244353; const ldb eps = 1e-10; inline void add_mod(int &a,int b){ a+=b; if(a>=mod) a-=mod;} inline ll pw(ll a,ll b) { ll res = ...
13
#include <bits/stdc++.h> using namespace std; const int num = 60; int main() { int n; cin >> n; vector<long long> b(n); vector<vector<int>> cnt(num); int maxSize = 0; for (int i = 0; i < n; i++) { cin >> b[i]; long long bi = b[i]; int cnt2 = 0; while (bi % 2 == 0) { bi /= 2; cnt2...
11
#include <bits/stdc++.h> using namespace std; int a[300010], ans0[300010], ans1[300010], tans0, tans1, n, x, y; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { y = min(i - 1, n - i) * 2 + 1; if (a[i] <= a[i - 1] || a[i] <= a[i + 1]) ans1[...
20
#include <bits/stdc++.h> using namespace std; long long n, m, d, aa[500069], a[500069]; int main() { long long i, k, lh, rh, md, zz, sm, z; scanf("%lld%lld%lld", &n, &m, &d); for (i = 1; i <= n; i++) { scanf("%lld", aa + i); } for (lh = 0, rh = 2e18; lh <= rh;) { md = (lh + rh) / 2; sm = 0; z ...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 6010; int v[MAXN], ans, m; int f[MAXN]; vector<int> edg[MAXN]; void Go(int u, int fa) { int ps = lower_bound(f, f + m, v[u]) - f, vv = f[ps]; f[ps] = v[u]; if (ps == m) ans = max(ans, m++); for (__typeof(edg[u].begin()) it = edg[u].begin(); it != ed...
14
#include <bits/stdc++.h> using namespace std; int n, pos0, pos1; void print(int a, int b, int out, int in) { if (a == b) { if (in == 0) pos0 = a; else pos1 = a; return; } int ans; int mid = (a + b) / 2; int s1 = mid - a + 1; int s2 = b - mid; cout << "? "; for (int i = 1; i < a; ...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, t; cin >> s >> t; string suma = to_string(stoi(s) + stoi(t)); string a, b, sum; for (char c : s) { if (c != '0') { a += c; } } for (char c : t) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { long long a, b; cin >> a >> b; if (a < b) cout << a << endl; else { if (a % b != 0) cout << a << endl; else { vector...
7
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; using VVI = vector<VI>; using VB = vector<bool>; using VVB = vector<VB>; using VS = vector<string>; using PII = pair<int, int>; using VPII = vector<PII>; using VL = vector<long long>; using VVL = vector<VL>; int k; int minWidth() { string line; g...
11
#include <bits/stdc++.h> using namespace std; vector<int> v[3001]; int viz[3001], d[3001], cost[3001], a[3001], n, maxim; void dfs(int nod) { viz[nod] = 1; for (vector<int>::iterator it = v[nod].begin(); it != v[nod].end(); it++) if (viz[*it] == 0) { d[*it] = d[nod] + cost[*it - 1]; dfs(*it); } ...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int a[n + 2]; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } sort(a, a + n); if (sum >= m) cout << m << endl; else ...
0
#include <bits/stdc++.h> using namespace std; const long long N = 200100; long long color[N][2]; vector<long long> g[N], rg[N]; bool dfs(long long u, long long t) { color[u][t] = 1; for (long long v : (t ? g[u] : rg[u])) { if (color[v][t] == 0) { if (dfs(v, t)) return true; } else if (color[v][t] == 1...
18
#include <bits/stdc++.h> using namespace std; const int N = 300010; const int M = 20; int mx[N][M], mn[N][M], n; void init() { for (int i = 1; i <= n; i++) mx[n + n + i][0] = mx[n + i][0] = mx[i][0], mn[n + n + i][0] = mn[n + i][0] = mn[i][0]; for (int j = 1; j < log2(3 * n); j++) { for (int ...
12
#include <bits/stdc++.h> using namespace std; inline int ReadInt() { static int n, ch; n = 0, ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar(); return n; } inline long long ReadLL() { static long long n; static int ch; n = 0, ch = getchar(); ...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, u, v, l, r, md; bool vis[N]; set<int> adj[N]; vector<pair<int, int>> g; void topSortUtil(int v, bool vis[], stack<int>& St) { vis[v] = true; set<int>::iterator i; for (i = adj[v].begin(); i != adj[v].end(); ++i) if (!vis[*i]) topSo...
10
#include <bits/stdc++.h> using namespace std; long long data[2000][2000]; long long answer[2000]; bool used[2000]; long long n, ai; int32_t main() { ios_base::sync_with_stdio(false); long long maximum = pow(10, 15); cin >> n; for (long long i = 0; i < n; i++) { used[i] = false; for (long long j = i + 1;...
19
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 1; int x[N], p[N]; int main() { int n, m, s, d; cin >> n >> m >> s >> d; x[0] = -1; for (int i = 1; i <= n; i++) cin >> x[i]; sort(x, x + n + 1); int mxr = 0; int mxl = -1; for (int i = 0; i <= n; i++) { if (i < n && x[i + 1] == x[...
8
#include <bits/stdc++.h> using namespace std; struct exam { int s, d, c, idx; }; int main() { ios_base::sync_with_stdio(0); int n, m, x, y, z; cin >> n >> m; vector<int> ans(n + 1, 0); vector<exam> v(m); for (int i = 0; i < m; i++) { cin >> v[i].s >> v[i].d >> v[i].c; v[i].idx = i + 1; ans[v[i...
9
#include <bits/stdc++.h> using namespace std; long long modpow(long long b, long long e, long long mod) { long long ans = 1; for (; e; b = b * b % mod, e /= 2) if (e & 1) ans = ans * b % mod; return ans; } const int N = 2020; const int mod = 998244353; long long dp[N][N], c[N][N], pot[N]; string s; int32_t ma...
18
#include <bits/stdc++.h> using namespace std; const int N = 100005; int vmax[N << 1], col[N << 1]; inline int ID(int l, int r) { return l + r | l != r; } void push_up(int l, int r) { int m = l + r >> 1; vmax[ID(l, r)] = max(vmax[ID(l, m)], vmax[ID(m + 1, r)]); } void update(int p, int v, int l, int r) { if (l == ...
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int x1 = 3 * a; x1 /= 10; int x2 = a / 250; x2 *= c; int y1 = 3 * b; y1 /= 10; int y2 = b / 250; y2 *= d; int z1 = max(x1, a - x2); int z2 = max(y1, b - y2); if (z1 > z2) { cout << "Misha"; ...
1
#include <bits/stdc++.h> using namespace std; long int gcd(long int a, long int b) { if (b == 0) { return a; } return gcd(b, a % b); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; long long int ans = 0; for (int i = 2; i < n; i++) { ans += i * (i + 1); ...
4
#include <bits/stdc++.h> using namespace std; int T, n, m, p, k, a[8010], sum[8010]; bool can[8010]; int main() { scanf("%d", &T); while (T--) { int ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { can[i] = 0; scanf("%d", &a[i]); sum[i] = sum[i - 1] + a[i]; } for (int i...
7
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int MOD = 998244353; const int INF32 = 1 << 30; const long long INF64 = 1LL << 60; const long double pi = acos(-1); long long gcd(long long...
8
#include <bits/stdc++.h> using namespace std; const int maxi = 1e6 + 10; const long long mo = 1e18; mt19937 rng(time(0)); int n; int a[maxi]; long long p[maxi]; int cnt[maxi]; long long solve(int l, int r) { if (r < l) return 0; set<int> active; int mid = (l + r) / 2; long long ans = 0; map<long long, int> mp...
17
#include <bits/stdc++.h> using namespace std; int k; string s; int cnt[100]; int main() { while (cin >> k) { cin >> s; memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < s.size(); i++) cnt[s[i] - 'a']++; bool ok = 1; string ans; for (int i = 0; i < 26; i++) { if (cnt[i] % k == 0) { ...
2
#include <bits/stdc++.h> using namespace std; bool check(long long n, long long pos) { return n & (1LL << pos); } long long Set(long long n, long long pos) { return n = n | (1LL << pos); } long long a[100005]; long long b[100005]; long long mp[100005]; long long x; long long getNextX() { x = (x * 37 + 10007) % 100000...
15
#include <bits/stdc++.h> int main() { long n, m, a; scanf("%ld%ld", &n, &m); if (n == 1 && m == 1) a = 1; else if (n % 2 == 0) { if (m <= n / 2) a = m + 1; else if (m > n / 2) a = m - 1; } else { if (m <= n / 2) a = m + 1; else if (m > n / 2) a = m - 1; } printf...
5
#include <bits/stdc++.h> class Scanner { private: static const int BUFFER_SIZE = 1 << 18; char buff[BUFFER_SIZE]; char *buffPos, *buffLim; FILE* file; public: Scanner(FILE* file) { this->file = file; buffLim = buff + fread(buff, 1, BUFFER_SIZE, file); buffPos = buff; } private: inline voi...
0
#include <bits/stdc++.h> using namespace std; int ni() { int a; scanf("%d", &a); return a; } double nf() { double a; scanf("%lf", &a); return a; } char sbuf[100005]; string ns() { scanf("%s", sbuf); return sbuf; } long long nll() { long long a; scanf("%lld", &a); return a; } template <class T> voi...
16
#include <bits/stdc++.h> using namespace std; const int N = 2050; const int M = 1e6 + 500; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int LOG = 20; const int ALP = 30; const int BASE = 31337; const double EPS = 1e-9; const double PI = 3.1415926535; int a[20][N], n, m; int dp[20][5000], mx[20][5000], naj...
12
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { char str[13]; for (int i = 1; i <= 12; ++i) cin >> str[i]; bool ok[7]; for (int i = 1; i <= 6; ++i) ok[i] = 0; bool flag = 0; for (int i = 1; i <= 12; ++i) if (str[i] == 'X') { flag = 1;...
2
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int t; cin >> t; int n; while (t--) { cin >> n; long long a[n]; priority_queue<int> mq; long long ma, md = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (i) { ma = ...
7
#include <bits/stdc++.h> using namespace std; const int M = 100005; int n, m, sz, a[M], cnt[M], t, ans[M]; struct node { int le, ri, b, id; } p[M]; bool cmp(node u, node v) { if (u.b != v.b) return u.b < v.b; return u.ri < v.ri; } void add(int x) { if (a[x] > n) return; if (cnt[a[x]] == a[x]) t--; cnt[a[x]]...
10
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INF64 = 0x3f3f3f3f3f3f3f3f; const double EPS = 1e-8; const double PI = acos(-1.0); const int MOD = 1000000007; const int N = 2e3 + 10; const int M = 1e5 + 10; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ci...
3
#include <bits/stdc++.h> int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int n, i, j; char a[103][103], temp[1000]; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%s", a[i]); for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (strlen(a[i]) > strlen(a[j])...
3
#include <bits/stdc++.h> using namespace std; int dp[2][201][200 * 25 + 1], t[2][201][200 * 25 + 1]; int main() { int n, k; cin >> n >> k; for (int x = 0; x < 2; ++x) for (int i = 0; i <= n; ++i) for (int j = 0; j < 200 * 25 + 1; ++j) dp[x][i][j] = INT_MIN; dp[0][0][0] = dp[1][0][0] = 0; for (int tx...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int a[maxn]; int main() { int n; string ss; vector<int> L, R; cin >> n >> ss; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (ss[i] == 'R') R.push_back(a[i]); else L.push_back(a[i]); } ...
2
#include <bits/stdc++.h> using namespace std; double ans[100100]; int n; double a, d; int main() { scanf("%d%lf%lf", &n, &a, &d); double tmp = sqrt(d * 2 / a); for (int i = 1; i <= n; i++) { double x, y; scanf("%lf%lf", &x, &y); double cur = y * y / a / 2; if (cur >= d) ans[i] = x + tmp; ...
8
#include <bits/stdc++.h> using namespace std; vector<int> out[2]; int main() { int n, m, k; cin >> n >> m >> k; int cnt = 0; if (k == 1) { for (int i = 1; i <= n + m; i += (n - 1)) out[0].push_back(i); } else { for (int i = 1; i <= n + m; i += n) out[0].push_back(i); out[1].push_back(out[0][0]); ...
10
#include <bits/stdc++.h> using namespace std; int n, cmp[200100], cnt, anss[200100]; vector<pair<int, int> > vec; vector<int> g[200100], gg[200100]; bool used[200100]; vector<int> topol; void dfs1(int v) { used[v] = 1; for (int i = 0; i < g[v].size(); i++) { int to = g[v][i]; if (!used[to]) dfs1(to); } ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y; cin >> n >> m >> x >> y; if (n == x) cout << x + (y - m) << " " << m << " " << x + (y - m) << " " << y << endl; else if (m == y) cout << n << " " << y + (x - n) << " " << x << " " << y + (x - n) << endl; else if (abs(n - x) != ...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; string s; cin >> n; cin >> s; int o = 0; int g = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == ')') o--; else o++; if (o < 0) { o++; ...
2
#include <bits/stdc++.h> using namespace std; int K, Q, N; long long F[6], ans; long long dp[1000010], dd[1000010]; bool vis[1000010]; int main() { int i, j, k; cin >> K; K--; K *= 3; for (i = 0; i < 6; i++) cin >> F[i]; int p = 1; memset(dp, -1, sizeof dp); dp[0] = 0; for (i = 0; i < 6; i++) { in...
22
#include <bits/stdc++.h> using namespace std; const int maxn = 85; const int INF = int(1e9) + 7; int n, m; int a[maxn][maxn]; void read() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]); return; } const int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}...
15
#include <bits/stdc++.h> using namespace std; const unsigned int mod = 1e7 + 7; const long long int N = 1e5; long long int lazy[400009], segtree[400009], x, y, n, d, color[200009], cnt; bool visit[100009] = {false}; vector<long long int> v[100009]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long double l, d, v, g, r; cin >> l >> d >> v >> g >> r; l /= v; d /= v; long long c = d / (g + r); long double f = 1.0 * (g + r) * c; if (f <= d && d < f + g) { cout << fixed << setprecision(9) << l << endl; ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int MOD = 1e9 + 7; int A[105]; string S[105]; int main() { ios::sync_with_stdio(false); int T, n; cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> A[i]; S[i].clear(); } S[0].clear(); ...
4
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T &t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T &t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "URDL"; const long long MOD2 = (long lon...
21
#include <bits/stdc++.h> using namespace std; int H[10][1000005], cnt[10][1000005]; int find(int x, int n) { if (n <= 0) return 0; if (cnt[x][n] != -1) return cnt[x][n]; int y = 0, k = 0, tmp = n; while (tmp) { y = max(y, tmp % 10); tmp /= 10; } y = max(x, y); cnt[x][n] = find(x, n - y) + 1; if ...
16
#include <bits/stdc++.h> const int N = 5050; int sa[N], t[N], t2[N], c[N], wt[N]; bool cmp(int *r, int a, int b, int l) { return r[a] == r[b] && r[a + l] == r[b + l]; } void build_sa(char *s, int n, int m) { int p = 1, *x = t, *y = t2; for (int i = 0; i < m; i++) c[i] = 0; for (int i = 0; i < n; i++) c[x[i] = s...
15
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-8; int pre[3010] = { 4784, 4194, 4003, 3920, 3831, 3791, 3726, 3667, 3669, 3591, 3642, 3612, 3532, 3554, 3507, 3500, 3517, 3449, 3496, 3432, 3462, 3406, 3394, 3376, 3378, 3445, 3362, 3368, 3371, 3305, 3369, 3386, 3336, 3320, 3302, 32...
14
#include <bits/stdc++.h> using namespace std; const long long MAXN = 3e6; long long q; string s, t, z; long long m, n, k; vector<long long> vertex[MAXN]; long long ok = 1; long long vitri[MAXN]; long long cnt; long long check[MAXN]; long long po[MAXN]; void dfs(long long x, long long color, long long cnt) { po[x] = c...
10
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = (int)1e6 + 7, mod = 1000000007, M = 2e9; int n, a[N]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (a[n - 1] == 1) a[n - 1] = 2; else a[n - 1] = 1; sort(a, a + n); for (int...
5
#include <bits/stdc++.h> using namespace std; pair<unsigned long long, unsigned long long> f( pair<unsigned long long, unsigned long long> a, pair<unsigned long long, unsigned long long> b) { pair<unsigned long long, unsigned long long> w; unsigned long long c = (b.first - a.first) * (b.second - a.second); ...
7
#include <bits/stdc++.h> using namespace std; vector<long long int> vec; map<long long int, long long int> vis; map<long long int, long long int> vis1; long long int ara[1000006]; string str; int main() { long long int t; scanf("%lld", &t); for (long long int i = 1; i <= t; i++) { long long int n; scanf("...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using ull = unsigned long long; using int2 = pair<ll, ll>; using int3 = tuple<ll, ll, ll>; template <typename A> string to_string(const A &v); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const ch...
14
#include <bits/stdc++.h> using namespace std; const int LIM = 1e5 + 5, MOD = 998244353; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long fastpowMOD(long long a, long long p, long long MOD) { if (p == 0) return 1; long long z = fastpowMOD(a, p / 2, MOD); z = (z ...
11
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include<bits/stdc++.h> using namespace std; string s,s1,s2; vector<int>v[100000+10],v1,v0; long long int i,j,k,l,m,n,p,q,z,sum,cnt,mn,mx,t,x,y; //long long int a[100+10],b[100+10]; long long int dp[410][410],a[3*100000+10],b...
8
#include <bits/stdc++.h> using namespace std; const long long r = 1000000007LL; int h[10]; int n, k, m, i, j; long long a[100001], b[100001]; long long ans, x, y, z, cnt1, cnt2; int main() { cin >> n >> k; m = n / k; for (i = 1; i <= m; i++) cin >> a[i]; for (i = 1; i <= m; i++) cin >> b[i]; h[0] = 1; for (...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) cout << "Mahmoud"; else cout << "Ehab"; }
0