solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long int n, x; string a; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int u, r, z = 1; u = r = 0; cin >> n; while (n--) { cin >> x >> a; if (a[0] == 'N') { if ((u - x) < 0) z = 0; u = u - x; } else if (a[0]...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string a; string b; cin >> a; cin >> b; char ch1, ch2; int s1, s2; for (int i = 0, j = 0; i < n; i++, j++) { if (a[i] != b[j]) { s1 = i; ch1 = a[s1];...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int &i : a) { cin >> i; } sort(a, a + n); int l = n / 2 - 1, r = n / 2; if (n % 2) { cout << a[r++...
4
#include <bits/stdc++.h> using namespace std; using namespace std; const long long N = 0 ? 15 : 1000005; int n, a[N]; int dp[N][2][2]; pair<int, int> pre[N][2][2]; int main(int argc, const char *argv[]) { int t; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int(i) = (1); (i) <= (long long)(n); (i)+...
20
#include <bits/stdc++.h> using namespace std; double eps = 1e-9; bool isEqual(double a, double b) { return (abs(a - b) < eps); } int main() { ios_base::sync_with_stdio(false); int i, j; double p; int n; cin >> n; ; cin >> p; int t; cin >> t; ; vector<double> prob(n + 1, 0.0); prob[0] = 1.0; fo...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 20; const long long MOD = 1000000007; long long n, x, y; long long dp[MAXN]; long long ans; void read() { int a; scanf("%I64d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a); if (a == 1) x++; else y++; } } void sol...
15
#include <bits/stdc++.h> using namespace std; int n, m, i, j; int64_t a[111111]; int main() { int64_t t, x, y, z, w, i; cin >> n >> m; char c; for (i = 0; i < n; i++) { cin >> x >> c >> y >> c >> z >> c >> w; a[i] = (x << 24) + (y << 16) + (z << 8) + w; } t = 0; set<long long> s; for (i = 0; i <...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long k, f[410][410]; int main() { cin >> k; for (int i = 1; i <= k; i++) f[i][0] = 1; f[1][1] = 1; for (int dep = 2; dep <= k; dep++) { for (int i = 1; i <= (k - dep + 1); i++) { for (int j = 0; j <= i + 1; j++) { ...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n][n]; memset(a, 0, sizeof(a)); if (k > n * n) { cout << -1 << endl; return 0; } for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (i == j && k >= 1) { k--; a[i][j] = 1;...
6
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ' '; cerr << endl; } int n; int a[100005], b[100005], reva[100005], revb[100005]; int mini[100005]; struct segtree { int n, ownN; int val[1200005]; void i...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 5005; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } ...
19
#include <bits/stdc++.h> using namespace std; char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } int getnum() { int x = 0, f = 1; char ch = gc(); while (ch < '0' || ch > '9') { ...
25
#include<bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0) void err(){cout << "\033[39;0m" << endl;} template<template<typename...> class T,typename t,typename... A> void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);} te...
10
#include <bits/stdc++.h> using namespace std; double x[105], y[105]; inline double dist(double a, double b) { return a * a + b * b; } int main(void) { int n, K; double eps, sx, sy; scanf("%d%d%lf%lf%lf", &n, &K, &eps, &sx, &sy); eps /= 1000; double L = 0, R = 0; for (int i = 0; i < n; i++) { scanf("%lf%...
13
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long res = 1ll; while (b > 0) { if (b % 2ll) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b /= 2ll; } return res; } long long GCD(long long a, long long b) { if (b == 0) return a; return GCD...
0
#include <bits/stdc++.h> using namespace std; template <typename T> void r1(T &x) { x = 0; char c(getchar()); int f(1); for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1; for (; '0' <= c && c <= '9'; c = getchar()) x = (x * 10) + (c ^ 48); x *= f; } const int maxn = 50 + 5; const int maxk =...
12
#include <bits/stdc++.h> char F[10]; char M[10]; char S[10]; int main(void) { scanf("%s", F); scanf("%s", M); scanf("%s", S); int f, m, s; if (F[0] == 'p') f = 1; else if (F[0] == 'r') f = 2; else if (F[0] == 's') f = 3; else f = 4; if (M[0] == 'p') m = 1; else if (M[0] == 'r') ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, map<int, int> > m; while (n--) { string s; cin >> s; int i = 0; stack<char> st; while (i < s.length()) { if (!st.empty()) { if (s[i] == ')' && st.top() == '(') { st.pop(); } e...
7
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; int n, a[3000][3000], b[3000], q; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]); for (int i = 1; i <= n; i++) b[i] = a[i][i]; int ans = 0; for (int i = 1; i <= n; i++) ...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v; int x; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } vector<int> ans; for (int i = 0; i < n;) { if (v[i] == 1) { i++; ...
0
#include <bits/stdc++.h> using namespace std; const int p = 1000000007; const int N = 300000; int fac[500000], inv[500000], pow2[500000]; int d[500000][20]; int i, j, k, n, r, s, t; inline int power(int x, int y) { int s = 1; for (int i = 30; i >= 0; i--) { s = 1LL * s * s % p; if (y & (1 << i)) s = 1LL * s...
23
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; typedef vector<pii> vpii; void solve(){ ll n,x,t; cin>>n>>x>>t; ll k = t/x; if(k>n){ c...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long gcd, masks, mask, i, h, d, q, l, r, j, k, n, x, y, z, x1, y1, p, x2, y2, m, root, t, sum, size, ind; cin >> n >> m; string s1[n], s2[m]; for (int i = 0; i < n; i++) cin >> s1[i]; for (in...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; void init() { ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve() { ll size, sum = 0, m = 0, temp; cin >> size; for (int i = 0; i < size; i++) { cin >> temp; sum += temp; m = max(m, temp); } if (sum % 2 == 0 && m <...
7
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k, ans = 0, t = 1; scanf("%lld%lld", &n, &k); --n; while (n > 0 && t < k) { n -= t; t <<= 1; ++ans; } printf("%lld\n", n ? ans + (n + k - 1) / k : ans); } int main() { int t; scanf("%d", &t); while (t--) solve(); r...
3
#include <iostream> #include <list> #include <algorithm> #include <map> #include <math.h> #include <set> #include <string> #include <algorithm> #include <cstdint> #include <list> #include <string.h> #include <unordered_map> #include <unordered_set> #include <assert.h> #include <ctype.h> #include <queue> #include <numer...
10
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define pll pair<ll,ll> #define ldb double template<typename T>void ckmn(T&a,T b){a=min(a,b);} template<typename T>void ckmx(T&a,T b)...
21
#include <bits/stdc++.h> using namespace std; int main() { long long a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); int sum = (a[0] + a[1] + a[2]) / 3; if (a[0] + a[1] < sum) { cout << a[0] + a[1]; } else { cout << sum; } }
10
#include <bits/stdc++.h> using namespace std; using PII = pair<int, int>; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int n, m; vector<string> g; void bfs(queue<PII> &q) { while (!q.empty()) { auto t = q.front(); q.pop(); int x = t.first, y = t.second; g[x][y] = '+'; for (int i = 0; i < 4; i...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 200; const int INF = 0x3f3f3f3f; vector<int> e[MAXN]; int w[MAXN][MAXN], d[MAXN]; int center[MAXN], dp[MAXN][MAXN]; int n, k; void floyd() { for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { if (w[i][k] == INF) { continue; ...
19
#include <bits/stdc++.h> using namespace std; int n; deque<int> adj[1001]; deque<int> leaf; int sze[1001]; bool visit[1001]; int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; adj[x].push_back(y); adj[y].push_back(x); sze[x]++, sz...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 888; const int P = 1000000007; int n; int fa[maxn]; long long f[maxn]; pair<int, int> find(int x) { if (fa[x] == x) return make_pair(x, f[x]); pair<int, int> tp = find(fa[x]); fa[x] = tp.first; f[x] = (f[x] + tp.second) % P; return make_pair...
12
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { (ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0)); int n; cin >> n; vector<int> a(n); int ans = 0, currans = 0; for (int i = (0); i < (n); ++i) { cin >> a[i]; } for (int i = (0); i < (2 * n); ++i) { if (a[i % n...
1
#include <bits/stdc++.h> using namespace std; const long long INF = 1E15; const int MAXN = 1 << 20; tuple<int, int, int> a[MAXN]; pair<long long, int> seg[2 * MAXN]; long long lz[2 * MAXN]; map<int, int> encode; int decode[MAXN]; void prop(int ind) { seg[ind].first += lz[ind]; if (ind < MAXN) { lz[ind * 2] += l...
16
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<ll, ll>; constexpr int MAXN = 400005; int n; ll L; ll a[MAXN], b[MAXN]; bool poss(ll x) { assert(x > 0); vector<pii> intervals; for (int i = 0; i < n; ++i) { ll l = b[i] - x; ll r = b[i] + x; i...
17
#include <bits/stdc++.h> using namespace std; struct Tree { vector<long long> tree; int shift; explicit Tree(int n = 1) { shift = 1; while (shift < n) shift *= 2; tree.assign(2 * shift, 0); } void set(int pos, long long x) { pos += shift; tree[pos] = x; for (pos /= 2; pos; pos /= 2) tr...
17
#include <bits/stdc++.h> using namespace std; int x[3], y[3]; int main() { for (int i = 0; i < 3; i++) cin >> x[i] >> y[i]; if (x[0] == x[1] && x[1] == x[2]) { cout << 1; return 0; } if (y[0] == y[1] && y[1] == y[2]) { cout << 1; return 0; } if (x[0] == x[1]) { int nmax = max(y[0], y[1])...
9
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> v(n + 1), org(n + 1); list<int> rem; org[0] = 0; int ele; for (int i = 0; i < n; i++) { cin >> ele; if (ele != 0) v[ele]++; org[i + 1] = ele; } for (int i = 1; i <= n; i++) { if (v[i] == 0) rem.pu...
7
#include <bits/stdc++.h> using namespace std; long long n, s, a[107], h, m, res; int main() { cin >> n >> s; for (int i = 1; i <= n; i++) { cin >> h >> m; a[i] = h * 60 + m; } a[0] = -(s + 1); a[n + 1] = 100000000000000000; for (int i = 0; i <= n; i++) { if (a[i + 1] - a[i] > s * 2 + 1) { ...
3
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; long long mod = 1e9 + 7; string s; signed main() { ios_base::sync_with_stdio(0); cin.tie(0)...
9
#include <bits/stdc++.h> using namespace std; signed main() { long long n, flag = 1; cin >> n; long long ar[n]; for (long long i = 0; i < n; i++) { cin >> ar[i]; } sort(ar, ar + n); for (long long i = 0; i < n - 2; i++) { if (ar[i] + ar[i + 1] > ar[i + 2]) { cout << "YES" << endl; flag...
2
#include <bits/stdc++.h> using namespace std; void swap(char& a, char& b) { char t = a; a = b; b = t; } struct sq { int w; char c; }; int a[1000][1000], a1[1000][1000]; sq d[1000][1000], d1[1000][1000]; int main() { int n, w, x; x = -1; scanf("%d", &n); for (int i = 0; i < n; i++) for (int j = 0; ...
12
#include <bits/stdc++.h> using namespace std; int n, ans; string s; int pows(int x) { int tmp = 1; for (int j = 0; j < x; j++) tmp = (tmp * 2) % 1000000007; return tmp; } int main() { cin >> s; int nn = s.length(); ans = pows(2 * nn - 1); ans = ((ans + 1000000007) - pows(nn - 1)) % 1000000007; for (int ...
8
#include <bits/stdc++.h> using namespace std; string s; int a[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; int rev(int); int main() { getline(cin, s); for (int i = 0; i < s.length(); i++) { int x = 0; if (i > 0) x = rev(int(s[i - 1])); int y = rev(int(s[i])); if (x >= y) cout << x - y << end...
5
#include <bits/stdc++.h> using namespace std; const int NR = 1e5 + 5; const int MR = 1e5 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; inline int read() { int x = 0; int bei = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') bei = -1; ch = getchar(); } while (ch >= '...
15
#include <bits/stdc++.h> using namespace std; long long a[721][721], b[500010]; int main() { long long T, n, m, k, x, y, t; scanf("%lld", &T); while (T--) { m = 0; scanf("%lld%lld%lld", &t, &x, &y); if (t == 1) { b[x] += y; for (int i = 1; i <= 720; i++) a[i][x % i] += y; } else { ...
13
#include <bits/stdc++.h> using namespace std; void canhazfast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T extgcd(T a, T b, T &x, T &y) { T x0 = 1, y0 = 0, x1 = 0, y1 = 1; while (b...
11
#include <bits/stdc++.h> int main() { int n, c, p[60], t[60], score1 = 0, score2 = 0, i, j, time, temp; scanf("%d%d", &n, &c); for (i = 0; i < n; i++) { scanf("%d", &p[i]); } for (i = 0; i < n; i++) { scanf("%d", &t[i]); } time = 0; for (i = 0; i < n; i++) { time += t[i]; temp = p[i] - (...
0
//#pragma comment(linker, "/STACK:102400000,102400000") #include<bits/stdc++.h> using namespace std; typedef long long ll; //#define int ll typedef pair<int,int>pii; #define ff first #define ss second #define debug(x) std:: cerr << #x << " = " << x << std::endl; const int maxn=2e5+10,inf=0x3f3f3f3f,mod=1000000007; cons...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int maxn5 = 2e3 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const long long mod = 1e9 + 7; const long long inf = 1e18; long long dp[maxn5][20], pw[20][maxn5]; bool notprime[maxn]; int main() { ios_base::sync_with_stdio(...
12
#include <bits/stdc++.h> using namespace std; long long int modp(long long int a, long long int p, long long int n) { long long int d[100]; long long int i, j, k, l; if (n == 0) return 1; for (i = 0; n >= 1; i++) { d[i] = n % 2; n /= 2; } l = i; long long int e = 1; if (d[0] == 1) e *= (a % p); ...
3
#include <bits/stdc++.h> using namespace std; vector<string> Vertex(1000); long long ans = 0; vector<list<int> > g(1000); map<string, int> s; void dfs(int x) { ans += s[Vertex[x]]; s[Vertex[x]]++; for (list<int>::iterator it = g[x].begin(); it != g[x].end(); ++it) { dfs(*it); } s[Vertex[x]]--; } int read(...
9
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int n, m; int f[2000010]; int mi[4000010], inv[4000010]; int ans; inline int mo(int x) { if (x >= MOD) return x - MOD; return x; } inline int C(int x, int y) { if (x < y) return 0; return 1ll * mi[x] * inv[y] % MOD * inv[x - y] % MOD; } vo...
22
#include "bits/stdc++.h" using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c> {i, j}; } ...
18
#include <bits/stdc++.h> using namespace std; const int N = 16; const int M = 10011; int n, m; int a[N][M]; int edge[N][N]; int f[N][1 << N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >...
12
#include <bits/stdc++.h> using namespace std; template <class T> void p(vector<T>& a) { for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; } bool comp(pair<int, int> a, pair<int, int> b) { if (a.first < b.first) return true; else if (a.first == b.first) return a.second < b.second; e...
8
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 2e5 + 10; void test_case() { long long n; cin >> n; vector<long long> v(n), pos(n + 1), res(n); for (int i = 0; i < n; i++) { cin >> v[i]; pos[v[i]] = i; } string s; cin >> s; vector<int> a, b; for...
2
#include <bits/stdc++.h> using namespace std; const int maxm = 2000 + 10; const int maxn = 100000 + 10; const int mod = 1000000000 + 7; int h, w, n; long long fac[2 * maxn]; long long dp[maxm]; pair<int, int> p[maxm]; long long pow_mul(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = ...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<long long> a(n); vector<long long> aa; vector<pair<int, int> > interv; for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> ind(n); ind[0] = 0; aa.push_back(a[0]); for (int i = 1; i < n; i++) { i...
9
#include <bits/stdc++.h> using namespace std; int a[100005], n, m; inline int cal(int o) { int res = (o * (o - 1)) >> 1; if (!(o & 1)) res += ((o - 2) >> 1); return res + 1; } int main() { int i, x, ans = 0; scanf("%d%d", &n, &m); for (i = 1; i <= m; i++) { scanf("%d%d", &x, &a[i]); } sort(a + 1, a ...
12
#include <bits/stdc++.h> using namespace std; vector<int> v[300010]; vector<pair<int, unsigned long long> > ope[300010]; int n; unsigned long long c[300010]; unsigned long long ans[300010]; int lowbit(int x) { return x & (-x); } unsigned long long query(int x) { unsigned long long res = 0; while (x) { res += c[...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 1; mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count()); int n, x[N][N], y[N][N], dx[N] = {0, 0, 1, -1}, dy[N] = {1, -1, 0, 0}; bool vis[N][N]; char ans[N][N]; string is = "RLDU"; int did = 0; void no() { puts("INVALID"); exit(0);...
12
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { cin >> n; if (n % 2 == 1) { s += '7'; n -= 3; } while (n > 0) { s += '1'; n -= 2; } cout << s; return 0; }
4
#include <bits/stdc++.h> using namespace std; long long int n, l, r = 1, sol; vector<int> all; int main() { cin >> n; all.resize(n); for (int i = 0; i < n; i++) { cin >> all[i]; } sort(all.begin(), all.end()); while (r < n) { if (all[l] < all[r]) { l++; r++; sol++; } else { ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt, max; int a[2000000]; while (cin >> n) { cnt = 1; max = 1; for (int i = 0; i < n; ++i) { a[i] = 0; } for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int j = 1; j < n; ++j) { if (a[j - 1] * 2 >= a[...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; int n, m, k, a[MAXN]; long long sum[MAXN]; double ans; int main() { scanf("%d %d %d", &n, &k, &m); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } sort(a + 1, a + 1 + n); for (int i = 1; i <= n; ++i) { sum[i] = sum[i - 1] + a...
9
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; string arr[a]; bool b = 0, bb = 0; for (int e = 0; e < a; e++) { cin >> arr[e]; if ((arr[e][3] == arr[e][4] && arr[e][3] == 'O') || (arr[e][0] == arr[e][1] && arr[e][1] == 'O')) b = 1; } if (b) { cout << ...
0
#include <bits/stdc++.h> using namespace std ; #define int long long #define ull unsigned long long #define N 20000001 #define endl "\n" /* vector <bool> prime(N + 1, true) ; vector <ull> fac(N) ; vector <ull> inverse_fac(N) ; bool check_prime(int n){ if(n == 1) return false ; if(n % 2 == 0) return false ; f...
5
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a; if (a % 2 == 0) cout << 8 << " " << a - 8; else cout << 9 << " " << a - 9; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n & 1) cout << "Ehab"; else cout << "Mahmoud"; }
0
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; const int N = 1e6 + 10; long long factorial[N]; long long power(long long a, long long b) { if (b < 0) return 1; long long res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } long long...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, x; cin >> n >> x; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int odd = 0, even = 0; for (int i = 0; i < n; i++) { if (a[i] & 1) odd++; else even++; } ...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string m[n]; for (int i = 0; i < n; i++) cin >> m[i]; char a = m[1][0], b = m[0][1], c = m[n - 1][n - 2], d = m[n - 2][n - 1]; if (a == b && c == d) { if (a == c) cout <...
3
#include <bits/stdc++.h> namespace IO { static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23; inline char myGetchar() { static char buf[IN_BUF], *ps = buf, *pt = buf; if (ps == pt) { ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin); } return ps == pt ? EOF : *ps++; } template <typename T> inline bool read(...
16
#include <bits/stdc++.h> using namespace std; pair<int, int> p[100001]; int a[100001]; int dp[100001]; int main(int argc, char const *argv[]) { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf(" %d %d ", &p[i].first, &p[i].second); a[i] = p[i].first; } sort(a, a + n); sort(p, p + n); in...
8
#include <bits/stdc++.h> using namespace std; struct node { long long dis, to, next; } e[400303]; inline long long read() { long long x = 0, w = 0; char ch = getchar(); while (!isdigit(ch)) w |= ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar(); return w ? -x ...
17
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, k; long long t; cin >> t; while (t--) { cin >> n; int arr[n]; for (long long i = 0; i < n; i++) { cin >> arr[i]; } for (long long i = 0; i < n; i++) { cin >> k; ...
2
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y); long long gcd(long long a, long long b); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; pair<long long, int> arr[n + 1]; for (int i = 1; i <= n; i++) { cin >> arr[i].first; arr[i]...
12
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 20; const int INF = 1e9 + 7; char s[MAX]; int a[MAX], q[MAX]; int chu(int l, int r, int len) { memset(q, 0, sizeof(q)); int tl = 1, tr = 0, pos = l; int ans = INF; for (int i = l; i <= r; i++) if (i + len - 1 <= r) ans = min(ans, max(a[i], ...
8
#include <bits/stdc++.h> using namespace std; bool isprime(int n) { if (n == 1) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) { if ((n % i == 0) || (n % (i + 2) == 0)) return false; } return true; } long long binpow(long ...
4
#include <bits/stdc++.h> using namespace std; const int N = 500010; const double pi = 4 * atan(1); const double eps = 1e-6; vector<int> adj[N]; int n, m, q, par[N], lv[N], stsz[N], sc[N], node_head[N], new_pos, cost[N], indx[N], res[N], root = 1; int tree[4 * N], lz[4 * N]; void lazy(int l, int r, int pos) { if (...
13
#include <bits/stdc++.h> using namespace std; int n, ci[1 << 22], son[500010], siz[500010], dep[500010]; int hd[500010], nt[500010], D[500010], ans[500010]; int getint() { int w = 0; bool q = 0; char c = getchar(); while ((c > '9' || c < '0') && c != '-') c = getchar(); if (c == '-') c = getchar(), q = 1; w...
21
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; ; long long n; cin >> n; ; string a[n]; int z = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; if (s == a[i]) z = 1; } if (z == 1) { cout << "YES" << "\n"; return; } for (long long i ...
1
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> x(n), y(n); for (int i = 0; i < n; ++i) cin >> x[i] >> y[i]; if (n & 0x01) { cout << "NO" << '\n'; } else { bool yes = true; for (int i = 0; i < n /...
10
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 200000; const int MAXM = MAXN - 1; int n; int fst[MAXN], nxt[2 * MAXM], to[2 * MAXM]; bool been[MAXN]; int par[MAXN]; int q[MAXN], qhead, qtail; int mnme[MAXN], mnop[MAXM], mxme[MAXN], mxop[MAXN],...
14
#include <bits/stdc++.h> using namespace std; struct pt { long double x, y; pt(long double x, long double y) : x(x), y(y) {} pt() {} long double norm2() { return *this * *this; } long double norm() { return sqrt(norm2()); } bool operator==(pt p) { return abs(x - p.x) < 1e-12 && abs(y - p.y) < 1e-12; } pt ...
18
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[1000000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; } inline void read(int &x) { static char c; for (c = getchar(); !('0' <= c && c...
23
#include <bits/stdc++.h> using namespace std; int main() { int n, ar[110][110]; bool fl; vector<int> ans; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> ar[i][j]; for (int i = 0; i < n; i++) { fl = true; for (int j = 0; j < n; j++) if (ar[i][j] == 1 || ar[i][j] ==...
1
#include <bits/stdc++.h> using namespace std; vector<int> v; int months[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int n, m, head; string s; int input(string temp) { int val; stringstream sin; sin << temp; sin >> val; return val; } int main() { ios::sync_with_stdio(0); cin >> n >> m; getlin...
12
#include <bits/stdc++.h> using namespace std; int i1, i2, c, sp, v, n, m, mn = 1001, c1, x2, c2, x1, y2, j, cn, k, jo, d, vv, i = 0, a, b, pa, r1, r2, g1, g2, cnt, x, y, used[101][101]; long long g[1000001]; int bl = 0; int main() { cin >> a >> b; g[0] = b; ...
2
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long INF = ~0ULL >> 1; template <class T> inline void read(T &n) { char c; for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar()) ; n = c - '0'; for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '...
9
#include <bits/stdc++.h> const int N = 600005, mu = 998244353; int n, a[N], pre[N]; void reduce(int &x) { x += x >> 31 & mu; } int ksm(int x, int y) { int ans = 1; for (; y; y >>= 1, x = (long long)x * x % mu) if (y & 1) ans = (long long)ans * x % mu; return ans; } int main() { scanf("%d", &n); for (int i...
18
#include <bits/stdc++.h> using namespace std; long long t, n, r; int main() { cin >> t; while (t--) { cin >> n >> r; if (n > r) { if (r % 2 == 0) cout << 1ll * (r / 2) * (r + 1) << endl; else cout << 1ll * ((r + 1) / 2) * r << endl; } else { if (n % 2 == 0) cout...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int m, n; cin >> m >> n; int b[m][n]; int a[m][n]; memset(a, -1, sizeof(a)); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) cin >> b[i][j]; for (int i = 0; i < m; i++) { for (in...
5
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int dx[8] = {1, 2, 1, 1, -1, -1, 1, 1}; int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; vector<int> adj[200010]; vector<int> par(200010, -1); vector<int> dis(200010, 0); vector<int> vis(200010, 0); vector<int> cn...
13
#include <bits/stdc++.h> using namespace std; int r[2001], p[2001], n; int rmp[2001], pmp[2001]; int va[1000001], vb[1000001]; void printRP() { cout << endl; for (int i = int(0); i < int(n); i++) cout << r[i] << " "; cout << endl; for (int i = int(0); i < int(n); i++) cout << p[i] << " "; cout << endl << endl...
15
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int INF((1 << 30) - 1); const int MAXN(1005); long long h1[MAXN], h2[MAXN], p[MAXN]; int dp[MAXN][MAXN][11], d[MAXN][MAXN]; int main() { int n, m, K; scanf("%d%d%d", &n, &m, &K); string a, b; cin >> a >> b; a = "?" + a; b = "?" +...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int a[55]; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); for (int i = 0; i < n / 2; i++) { int temp; temp = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = temp; } int count ...
8
#include <bits/stdc++.h> using namespace std; const long long int INF = 9223372036854775807LL; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroint-loops") long long int power(long long int b, long long int e, long long int m) { if (b == 0) return 0; if (e == 0) return ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 7, M = 1e9 + 7; bool isp[N]; vector<pair<int, int> > factorize(int x) { vector<pair<int, int> > ans; for (int i = 2; i * i <= x; ++i) { int cnt = 0; while (x % i == 0) cnt++, x /= i; if (cnt) ans.push_back(make_pair(i, cnt)); } if (x ...
21