solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; inline int getint() { int x; scanf("%d", &x); return x; } int main() { int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) v.push_back(getint()); sort(v.begin(), v.end()); for (int i = n - 1; i > 0; i--) { if (v[i] == v[i - 1] || v[n - 1] % v[i...
3
#include <bits/stdc++.h> using namespace std; vector<int> fail_func(vector<int> &s) { vector<int> re(s.size(), 0); re[0] = -1; re[1] = 0; int cnd = 0; int pos = 2; while (pos < s.size()) { if (s[pos - 1] == s[cnd]) { cnd++; re[pos] = cnd; pos++; } else if (cnd > 0) { cnd = re...
10
#include <bits/stdc++.h> inline long long gi() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f ? x : -x; } char s[1010]; int n, ans; int I, A[1010], B[1010], cnt, fir[2010], nxt[100010], dis...
16
#include <bits/stdc++.h> using namespace std; char s[1000006]; int n, k, P[1000006], a[1000006], p[1000006]; inline long long read() { long long x = 0, c = getchar(), f = 1; while (c < 48) c = getchar(); while (c > 47) x = x * 10 + c - 48, c = getchar(); return x * f; } void print(long long x) { if (x > 9) pr...
14
#include <bits/stdc++.h> int main() { int n, m; while (scanf("%d%d", &n, &m) != EOF) { int i, t, j, sum = 0; long long int b[1001] = {0}; for (i = 0; i < n; i++) { scanf("%lld", &b[i]); } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { t = b[i]; if (abs(b[j] -...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { long long n, x; cin >> n >> x; x *= 2; cout << x << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; set<pair<int, int>> stt[20]; long long ans = 0; long long cum[1000005]; int arr[100005]; void pre() { for (int i = 0; i < 20; ++i) { stt[i].insert({-5, -5}); stt[i].insert({1e6, 1e6}); } for (int i = 1; i <= 100000; ++i) { cum[i] = cum[i - 1] + i; } } vo...
13
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long INF = mod * mod; const long double eps = 1e-6; const long double pi = acos(-1.0); vector<pair<long long, long long>> resol(long long l, long long r) { vector<pair<long long, long long>> res; for (int i = 0; i < 60; i++) {...
23
#include<iostream> #include<queue> #include<unordered_map> #include<unordered_set> #include<deque> #include<bitset> #include<stack> #include<cstdlib> #include<cstring> #include<cmath> #include<set> #include<map> #include<algorithm> #include<string> #define ll long long #define md 1000000007 #define md2 500000005 using ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n; int p[N][N]; bool f[N]; double d[N], K[N], B[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { scanf("%d", &p[i][j]); if (i == j) p[i][j]; } for (int i = 1; i <= n; ++i) { d...
19
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, int> cnt; for (int i = 0; i < n * n; ++i) { int a; cin >> a; cnt[a] += 1; } vector<vector<int>> ans(n, vector<int>(n)); { int one = -1; vector<int> two; for (const auto& p : cnt) { if (p.seco...
9
#include <bits/stdc++.h> using namespace std; int b[300]; int n, k; int a[100005]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; memset(b, -1, sizeof(b)); for (int i = 0; i < n; i++) { if (a[i] == 0) { b[0] = 0; } else if (a[i] > 0) { if (b[a[i]] == -1) { int t...
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 9; const int maxnode = 2000; int n, m; int ch[maxnode][26], tot = 0, f[maxnode], last[maxnode], val[maxnode], dp[1007][201][11]; char s[20]; void ins(char *s, int len) { int u = 0; for (int i = int(0); i <= int(len - 1); ++i) {...
17
#include <bits/stdc++.h> using namespace std; int n, yy; int x[1100]; int y[1100]; int can[10000]; bool calc(int x1, int y1, int x2, int y2, double &tmp) { if (y1 == y2) return false; tmp = (double)(x2 - x1) / (y2 - y1) * (yy - y1) + x1; return true; } long long cha(long long x1, long long y1, long long x2, long ...
17
#include <bits/stdc++.h> using namespace std; const int nmax = 100100; pair<int, string> p[nmax]; int bonus1[nmax]; int bonus2[nmax]; int bonus[nmax]; int b[nmax]; int n; struct I1 { int ind; I1(int iind = -1) : ind(iind) {} bool operator<(const I1& other) const { int v1 = p[ind].first + bonus2[ind]; int ...
12
#include <bits/stdc++.h> using namespace std; using Integer = long double; int main() { ios_base::sync_with_stdio(false); cin.tie(0); Integer l; Integer r; Integer k; cin >> l >> r >> k; size_t number{}; Integer power = 1; for (; power < l; power *= k) { } for (; power <= r; power *= k) { cout...
7
#include <bits/stdc++.h> int main(int argc, const char* argv[]) { std::uint16_t x[3]; std::cin >> x[0]; std::cin >> x[1]; std::cin >> x[2]; if (x[0] <= x[1]) { if (x[1] <= x[2]) { std::cout << x[2] - x[0] << std::endl; return 0; } if (x[2] <= x[0]) { std::cout << x[1] - x[2] << s...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 10000000 + 10; long long A, N, L, R; int month[MAXN]; int main() { cin >> A >> N; L = A, R = A + N - 1; memset(month, 0, sizeof(month)); for (int i = 1; i <= (int)R; ++i) { long long x = i; x *= x; long long v = 1; while (x * v <= R)...
7
#include <bits/stdc++.h> using namespace std; const int len = 1e4 + 10; const double pi = acos(-1.0); const long long mod = 998244353; const int inf = 0x3f3f3f3f; long long p[len]; long long Pow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = a * ans % mod; a = a * a % mod; b...
10
#include <bits/stdc++.h> using namespace std; int N, M; vector<int> R[1000005]; vector<pair<int, int>> E[1000005]; vector<pair<int, int>> adjList[1005]; int main(int argc, const char* argv[]) { cin >> N >> M; for (int i = 0, a, b, l, r; i < M; i++) { cin >> a >> b >> l >> r; R[l].push_back(r); E[l].push...
12
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b, long long int m) { long long int ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } vector<pair<long long int, long long int> > v[300009], v1[300009]; long l...
9
#include <bits/stdc++.h> using namespace std; int read() { int ret = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar(); return ret * f; } int main() { int n = read(), t = r...
2
#include <bits/stdc++.h> const int N = 105; bool Happy[2][N]; int main() { int n, m, x, i, cnt = 0; scanf("%i %i", &n, &m); scanf("%i", &x); cnt += x; while (x--) scanf("%i", &i), Happy[0][i] = 1; scanf("%i", &x); cnt += x; while (x--) scanf("%i", &i), Happy[1][i] = 1; for (i = 0; i <= 100000000; i++)...
5
#include<bits/stdc++.h> using namespace std; const int MAXN=200005; int a[MAXN],b[MAXN],A[MAXN],B[MAXN],N,M,suf[MAXN]; map<int,int> ada; int solve(){ A[N+1]=1e9+1; suf[N+1]=0; for(int i=N;i>=1;i--){ suf[i]=suf[i+1]+ada.count(A[i]); } int ret=0,id=1; deque<int> dq; for(int i=1;i<=N;i++){ // cout << i << endl...
11
#include <bits/stdc++.h> using namespace std; long long a[600001], ans[600001]; priority_queue<pair<long long, long long> > q; int main() { long long answer = 0, i, j, n, k; cin >> n >> k; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= k; i++) q.push({a[i], i}); for (i = k + 1; i <= n + k + 1; i++) { ...
7
#include <bits/stdc++.h> using namespace std; bool han(vector<int> &a, int d) { int count = 0; for (int i = 0; i < a.size(); i++) { count += (a[i] / d) % 2; } return count < 2; } int gcd(int a, int b) { if (a > b) swap(a, b); while (a > 0) { b %= a; if (b == 0) return a; a %= b; } return...
17
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; vector<char> x, a, b; for (int j = 0; j < n; j++) { char c; cin >> c; x.push_back(c); } a.push_back('1'); b.push_back('1'); bool swap = false...
4
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const int MOD = 1e9 + 7; const int oo = MOD; long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); } long long n, m, k; long long calc(long long x) { long long ret = 0; for (int i = 1; i < n + 1; i++) ret += min(m, (...
10
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAX_N = 1e3 + 5; int a[MAX_N]; int main() { int N; cin >> N; for (int i = 1; i <= N; i++) scanf("%d", &a[i]); int ans = -1, cost = INF; for (int i = 1; i <= 100; i++) { int tmp = 0; for (int j = 1; j <= N; j++) { ...
3
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long fast_exp(long long a, long long n, long long mod1) { if (n == 0) return 1; else if (n == 1) return a; if (n % 2 == 0) return fast_exp((a * a) % mod1, n / 2, mod1); else return (a * fast_exp((a * a) % mod1, n ...
3
#include <bits/stdc++.h> using namespace std; const int MM = 1e9 + 7; const double eps = 1e-8; const int MAXN = 2e3 + 10; int n, m; int a[MAXN][MAXN]; void read() { scanf("%d", &n); } void solve() { m = n * n; int nn = (n + 1) / 2; int p = 1, q = 2; for (int i = 1; i <= n; i++) { a[nn][i] = p; p += 2; ...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 300001; int n, l, r, t = -1 << 30, x, y, a[MAXN], b[MAXN], c[MAXN]; int main() { cin >> n >> l >> r; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> x, b[x] = i; for (int i = 1; i <= n; i++) { if (t + a[b[i]] < l) ...
9
#include <bits/stdc++.h> int main(void) { char s[100], t[100]; int i, j, l, n; gets(s); gets(t); n = strlen(t); j = 1; l = 0; for (i = 0; i < n; i++) { if (s[l] == t[i]) { l++; j++; } } printf("%d\n", j); return 0; }
0
#include <bits/stdc++.h> using namespace std; struct Node { int min, max, d; }; const int MAX_N = 1e5 + 5, MAX_M = 305; int a[MAX_N]; pair<int, int> b[MAX_M]; Node t[MAX_N * 4]; void push(int v) { t[v * 2 + 1].d += t[v].d; t[v * 2 + 2].d += t[v].d; t[v].d = 0; } void build(int v, int tl, int tr) { if (tl + 1 ...
10
#include <bits/stdc++.h> using namespace std; int ans[2 * 1000000 + 10]; int net[2 * 1000000 + 10]; int vis[2 * 1000000 + 10]; int g[2 * 1000000 + 10]; int main() { int n; while (~scanf("%d", &n)) { memset(ans, -1, sizeof(ans)); memset(net, -1, sizeof(net)); memset(vis, 0, sizeof(vis)); int u, v; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1000005; const int inf = 1000 * 1000 * 1000; const int mod = 1000 * 1000 * 1000 + 7; int n; bool used[N]; bool mark[N]; vector<int> g; int main() { cin >> n; int k = n, t; for (int i = 2; i <= n; i++) { int z = 0; while (k % i == 0) { k /= ...
9
#include <bits/stdc++.h> using namespace std; int max2power(int n) { for (int i = 0; i < 31; i++) { if (1 << i == n) { return i; } else if (1 << i > n) return i - 1; } } void swap(int &a, int &b) { int temp = a; a = b; b = temp; } int main() { ios::sync_with_stdio(0); int n; cin >> n...
17
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const int MAXN = 1000 + 5; const int MAXM = 3e4 + 5; struct Edge { int nxt, cost, id, to; bool used, cut; } edge[MAXM << 1]; int head[MAXN], tot; int visd[MAXN]; void init() { tot = 0; memset(head, -1, sizeof(head)); } void add_edge(int u...
18
#include <bits/stdc++.h> using namespace std; void view_arr(int a[], int n) { for (int i = 0; i <= n; i++) { if (!i) printf("%d", a[i]); else printf(" %d", a[i]); } puts(""); } int get_digit(int a, int str[]) { int t = a, cnt = 0; while (t) { int r = t % 10; t /= 10; str[cnt++]...
5
#include <bits/stdc++.h> double solve(double x, double n) { double a = atan(1) * 4 / n; double h = sqrt(3 * tan(a) * tan(a) - 1) / tan(a); double s = n / tan(a); return pow(x / 2, 3) * h * s / 3; } int main() { double ans = 0; for (int i = 3; i <= 5; i++) { double x; scanf("%lf", &x); ans += sol...
9
#include <bits/stdc++.h> using namespace std; int main() { int i, a[28] = {}, flag = 0; string s; cin >> s; for (i = 0; i < s.size(); i++) { a[s[i] - 97]++; if ((s[i] == 'b' && a[0] == 0) || (s[i] == 'c' && a[1] == 0)) flag = 1; if ((s[i] == 'a' && a[1] > 0) || (s[i] == 'b' && a[2] > 0)) flag = 1; ...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; static const int _ = []() { ios::sync_with_stdio(false); cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }(); template <typename T, typename ...
1
#include <bits/stdc++.h> using namespace std; int N, M, K, S, n; int s[100005]; vector<pair<int, int> > A[10]; int extreme[10][4]; int m[10][10]; int minS[10], maxS[10], minD[10], maxD[10]; int main(int argc, const char* argv[]) { cin >> N >> M >> K >> S; for (int i = 0; i < 10; i++) { minS[i] = INT_MAX; ma...
14
#include<bits/stdc++.h> #define int long long #define hell 1000000007 #define endl "\n" #define ff first #define ss second #define pb push_back #define pii pair<int,int> #define sz(x) (int)x.size() #define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define rep(i...
8
#include <bits/stdc++.h> const long long mod = 1000000007; int Inf = (int)2e9; using namespace std; int main() { int n; scanf("%d", &(n)); int k; scanf("%d", &(k)); vector<int> a(n); for (int(i) = 0; (i) < n; (i)++) scanf("%d", &(a[i])); long long ans = 0; map<int, int> tmp; map<int, int> cnt; tmp[a...
11
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2, typename T3> class triple { public: T1 first; T2 second; T3 third; triple() { first = 0; second = 0; third = 0; } }; const int maxn = 1e6 + 10; int n; pair<int, int> a[maxn]; multiset<int> s; bool sortfunc(pair<int,...
11
#include <bits/stdc++.h> using namespace std; long long a[int(3 * 1e5 + 5)], AN[int(3 * 1e5 + 5)], w, h, i, m, ans, k, l, j, q, x, n, ma, mi, ma1, ma2; string s; pair<long long, long long> d[int(3 * 1e5 + 5)]; char c[int(3 * 1e5 + 5)]; map<int, int> mp1, mp2; int par2[int(3 * 1e5 + 5)]; long long siz1[int(3 * 1e5 +...
7
#include <bits/stdc++.h> using namespace std; int M; int rel[11][11]; int main() { while (cin >> M) { memset(rel, false, sizeof(rel)); bool ok = false; for (int i = 0; i < (int)M; i++) { int a, b; cin >> a >> b; a--, b--; rel[a][b] = rel[b][a] = true; } for (int i = 0; i < ...
5
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } int n, k, v; int a = 0, b = 0; const long long mod = 1e9 + 7; inline void...
13
#include <bits/stdc++.h> using namespace std; int main() { int k, s = 0, n, res = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> k; s += k; if (s < 0) { res += -s; s = 0; } } cout << res << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int Log(long long n, int base) { int ans = 0; while (n != 0) { ans++; n /= base; } return ans; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n, k; cin >> n >> k; if (k == 1) { cout << n; return 0; } long long ...
5
#include <bits/stdc++.h> using namespace std; bool isPrime(int num) { if (num == 2) return true; if (num < 2 || num % 2 == 0) return false; int limit = sqrt(num); for (int i = 3; i <= limit; i += 2) if (num % i == 0) return false; return true; } int main() { int n, k, counter = 0; cin >> n >> k; vec...
2
#include <bits/stdc++.h> using namespace std; int n, x, y, p; int64_t ans; const int64_t mod = 1e9 + 9; map<pair<int, int>, int> m; vector<int> from[100001], e[100001]; int indeg[100001]; set<int> can; char LG = 1, deld[100001]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d%d", &x, &y), m[{y, ...
13
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &output, const vector<T> &v) { if (v.empty()) return output; for (int i = 0; i < v.size() - 1; i++) output << v[i] << " "; output << v.back(); return output; } template <typename T> istream &operator>>(istream &input...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, x1, y1, x2, y2, t = 1 << 20, l = 1 << 20, r = -1, b = -1, ars = 0; cin >> n; for (int i = (0), _e = (n); i < _e; i++) { cin >> x1 >> y1 >> x2 >> y2; ars += abs((x1 - x2) * (y1 - y2)); t = min(y1, t); l = min(x1, l); r = max(x2, ...
7
#include <bits/stdc++.h> using namespace std; int p[100010]; int cnt; int solve0(int n) { if (n == 1) return ++cnt; int l = solve0(n / 2), r = solve0(n / 2); p[l] = p[r] = cnt + 1; return ++cnt; } int solve1(int n) { int base = 1 << (31 - __builtin_clz(n)), l, r; if (n + 1 == base * 3 / 2) l = solve0(ba...
20
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=100000,mod=1000000007; int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;} int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;} int mul(int a,int b,int p=mod){return 1LL*a*b%p;} void sadd(int &a,int b,int p=mod){a=add(a,b,p);} voi...
18
#include <bits/stdc++.h> using namespace std; void get(long long a[], long long n, long long k) { long long res = 0; for (long long i = 1; i < n; i++) { if (a[i] + a[i - 1] < k) { res += k - a[i - 1] - a[i]; a[i] = k - a[i - 1]; } } cout << res << "\n"; for (long long i = 0; i < n; i++) co...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; ++i) cin >> arr[i]; long long max_index = 0, digi_add = a...
0
#include <bits/stdc++.h> using namespace std; int T, n, m, k; unordered_set<int> g[100003]; int v[100003]; vector<int> ans; int sol() { ans.clear(); priority_queue<pair<int, int> > q; for (int i = 1; i < n + 1; ++i) { v[i] = 0; q.push(make_pair(-g[i].size(), i)); } while (!q.empty()) { auto t = q....
18
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); int64_t t; cin >> t; while (t--) { int64_t n; cin >> n; if (n % 4) cout << ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<vector<int> > adjList(N); vector<int> target(N), color(N); for (int i = 1; i < N; i++) { int u; cin >> u; u--; adjList[u].push_back(i); } for (int i = 0; i < N; i++) ...
4
#include <bits/stdc++.h> int main() { int n, a, b, c, j1, j2, i, k1, k2; while (~scanf("%d", &n)) { j1 = 0; j2 = 0; k1 = 0; k2 = 0; for (i = 0; i < n; i++) { scanf("%d%d%d", &a, &b, &c); if (a == 1) { j1 += b; j2 = j2 + b + c; } else { k1 += b; k...
0
#include <bits/stdc++.h> using namespace std; const double pi = (acos(-1.0)); const double eps = 1e-8; const long long INF = 1e18 + 10; const int inf = 1e8 + 10; const int maxn = 3000 + 500; const int mod = 1e9 + 7; char s[30], t[30]; int erase_leading0(int st, int ed) { int cnt = 0; if (ed < st) return 0; for (i...
13
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const long long INFL = (long long)9e18; const int MAXINT = ((~0) ^ (1 << 31)); const long long MAXLL = ((~0) ^ ((long long)1 << 63)); template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool mineq(T& a, T b) { retu...
11
#include <bits/stdc++.h> using namespace std; int main() { int w1, h1, w2, h2; cin >> w1 >> h1 >> w2 >> h2; w1 = (w1 > w2) ? w1 : w2; cout << 2 * (h1 + h2) + 4 + (2 * w1) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int a[100005], b[100005]; int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i]; sort(a, a + n); int ans = 0; for (int i = 0; i < n; i++) if (a[i] != b[i]) ans++; if (ans <= 2) cout << "YES"; else cout << "NO"; re...
5
#include <bits/stdc++.h> using namespace std; int main() { int a[500], i, n, j; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n - 1; i++) { for (j = 0; j < a[i]; j++) cout << "PRL"; cout << "R"; } for (i = 0; i < a[n - 1]; i++) cout << "PLR"; cout << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i; cin >> n >> m; string s; vector<string> v; map<string, long long int> mp; vector<pair<long long, long long>> ans; for (i = 0; i < n; i++) { cin >> s; v.push_back(s); mp[s] = i; reverse(s.begin(), s.end()); if...
3
#include <bits/stdc++.h> using namespace std; char s[50010]; int n; int main() { scanf("%s", s); n = strlen(s); register int i, j; int b, len; for (i = 1; i <= n / 2; i++) { b = 0; len = 0; for (j = 0; j + i < n; j++) { if (len == i) break; if (s[j] == s[j + i]) len++; el...
20
#include <bits/stdc++.h> using namespace std; const int N = 2010; int arr[N]; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; if (n == 1) { cout << 1; return 0; } int cnt2 = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 2) { cnt2++; } ...
10
#include <bits/stdc++.h> using namespace std; int n, P[210][15], lv[210]; vector<int> a[210]; bool c[210]; bool d[210]; int up[210], down[210]; void dfs(int u, int level) { c[u] = 1; lv[u] = level; for (int i = 0; i < a[u].size(); i++) { int v = a[u][i]; if (c[v] == 1) continue; P[v][0] = u; dfs(v...
11
#include <bits/stdc++.h> using namespace std; struct Hash { __int128_t mod = 1000000000000000003, base = 163; vector<__int128_t> p, h; long long len; Hash() {} Hash(string str) : len(str.size()) { p = vector<__int128_t>(len + 1, 1); h = vector<__int128_t>(len + 1, 0); for (long long i = 1; i <= le...
15
#include <bits/stdc++.h> using namespace std; vector<long long> v; void solve() { long long n; cin >> n; v.clear(); while (n) { v.push_back(n % 3); n /= 3; } v.push_back(0); for (long long i = (long long)v.size() - 2; i >= 0; i--) { if (v[i] == 2) { v[i + 1]++; for (long long j = i...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, b; cin >> n >> b; int arr[n], mn[n]; int ans = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (i > 0) { mn[i] = min(mn[i - 1], arr[i]); if (arr[i] - ...
6
#include <bits/stdc++.h> using namespace std; struct node { long long val, mask, high; }; signed main() { ios ::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); long long n; cin >> n; vector<node> a(n); long long sum = 0; for (long long i = 0; i < n; i++) { long long val, msk, high = -1;...
19
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int x[N], y[N], a, b; bool bound_check(int s, int t) { if (s <= a && t <= b) return 1; else return 0; } int main() { int n; cin >> n >> a >> b; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; } int mx = 0; for (int i =...
7
#include <bits/stdc++.h> using namespace std; void solve() { int n, sx, sy; cin >> n >> sx >> sy; int d[4] = {}; int a, b; for (int i = 0; i < n; ++i) { cin >> a >> b; if (a != sx) d[a > sx ? 0 : 2]++; if (b != sy) d[b > sy ? 1 : 3]++; } int m = -1, key = -1; for (int i = 0; i < 4; ++i) ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 45; pair<int, int> a[N]; multiset<pair<int, int> > s; vector<pair<int, int> > ev; vector<int> rem; bool obrisan[N]; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) { return a.second > b.second; } return a.first < b.first;...
10
#include <bits/stdc++.h> using namespace std; void solve() { int x, y, n; cin >> x >> y >> n; int ans = n / x * x + y; if (ans > n) ans -= x; cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("codeforces" ".inp", "r")) { freopen( ...
0
#include <bits/stdc++.h> using namespace std; int main() { int k, n, w, price; cin >> k >> n >> w; price = 0; for (int i = 1; i <= w; i++) price += i * k; if (price - n <= 0) cout << "0" << endl; else cout << price - n << endl; }
0
#include <bits/stdc++.h> using namespace std; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_heap = priority_queue<T>; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5...
5
#include <bits/stdc++.h> using namespace std; long long comp(long long n) { n = n * (n - 1) / 2; return n; } void solve() { long long n, x = 1, y, z, k = 0, sum = 0; cin >> n; long long a[n], b[n]; pair<long long, long long> p[n]; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; p[i].first = a[i...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; long long a, b, n, m; for (cin >> t; t--;) { cin >> a >> b >> n >> m; if (a < b) swap(a, b); puts(b >= m && n + m <= a + b ? "yes" : "no"); } return 0; }
5
#include <bits/stdc++.h> using namespace std; int C[110][110]; int f[2][110][110][110]; int main() { int n, m, k, i, j, x, y, l, ans; scanf("%d%d%d", &n, &m, &k); for (i = 0; i <= n; i++) { C[i][0] = 1; for (j = 1; j <= i; j++) { C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; if (C[i][j] > 100) C[i]...
20
#include <bits/stdc++.h> using namespace std; bool get(long long x) { cout << "? " << x << endl; long long sol; cin >> sol; if (sol) return true; return false; } void solve() { long long n; cin >> n; vector<long long> ord; long long li = 0, ri = n; long long mid; while (li + 1 < ri) { mid = (l...
19
#include <bits/stdc++.h> using namespace std; int main() { int t, h, m; scanf("%d", &t); scanf("%d:%d", &h, &m); if (t == 12 && h == 0) h = 1; if (t == 24) t--; if (h > t || h < 10) { h %= 10; if (t == 12 && h == 0) printf("10:"); else printf("0%d:", h); } else printf("%d:", h)...
5
#include <bits/stdc++.h> using namespace std; template <class T> inline T rin(T &r) { int b = 1, c = getchar(); r = 0; while (c < '0' || '9' < c) b = c == '-' ? -1 : b, c = getchar(); while ('0' <= c && c <= '9') r = (r << 1) + (r << 3) + (c ^ '0'), c = getchar(); return r *= b; } template <class T> inlin...
26
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vec; int main() { int n, m, x, y, z, p; cin >> n >> m >> x >> y >> z >> p; x %= 4; y %= 2; z %= 4; for (int i = 0; i < p; i++) { int a, b; cin >> a >> b; vec.push_back({a, b}); } while (x--) { for (int i = 0; i < vec.s...
7
#include <bits/stdc++.h> int N, X, Y; int queryset(const std::vector<int>& set) { if (set.empty()) { return 0; } printf("? %d", static_cast<int>(set.size())); for (int v : set) { printf(" %d", v + 1); } printf("\n"); fflush(stdout); int res; scanf("%d", &res); if (res == -1) { exit(0); ...
16
#include <bits/stdc++.h> using namespace std; using LL = long long; using PII = pair<int, int>; template <class T> struct RangeST { const int n, h; vector<T> V, D; vector<char> B; function<T(T, T)> op; function<T(T, T, int)> al; RangeST( const vector<T>& A, function<T(T, T)> op = plus<T>(), func...
16
#include <bits/stdc++.h> using namespace std; const int maxN = 1e6 + 9; long long p, s, n, sum; vector<long long> color; vector<long long> adj[maxN]; bool mark[maxN]; void input() { cin >> n; for (int i = 1; i <= n; i++) { cin >> s; adj[i].push_back(s); } } void dfs(int v) { mark[v] = true; p++; for...
7
#include <bits/stdc++.h> using namespace std; int n, k, ans = 1, cnt, a[16], st[16]; bool used[16]; int dfs(int x) { if (x == 1) return 1; if (x == a[x]) return -1; if (!st[x]) st[x] = -1; if (used[x]) return st[x]; used[x] = true; st[x] = dfs(a[x]); return st[x]; } bool check() { for (int i = 1; i <= k...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 100; int arr[maxn]; stack<int> v; void solve() { int n, p, z, y, x, k; scanf("%d", &n); scanf("%d", &k); int next_min = 1; for (int i = 1; i <= k; i++) scanf("%d", &arr[i]); for (int i = 1; i <= k; i++) { if (arr[i] == next_min) ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int main() { int n; long long hist[N]; memset(hist, 0, N * sizeof(long long)); cin >> n; for (int i = 0; i < n; ++i) { int val; cin >> val; hist[val]++; } for (int i = 2; i < N; ++i) { hist[i] = max(hist[i - 1], hist[i - ...
7
#include <bits/stdc++.h> using namespace std; void R() {} template <class T> void _R(T &x) { cin >> x; } void _R(signed &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%I64d", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } template <...
0
#include<bits/stdc++.h> #define ll long long int using namespace std; int dp[505][505]; /* 00300 02220 11111 */ int main() { int t; scanf("%d", &t); while(t--) { memset(dp, 0, sizeof(dp)); int n, m; scanf("%d%d", &n, &m); for(int i = 0;i < n;i++) { for...
6
#include <bits/stdc++.h> using namespace std; int main() { int a[100005] = {0}, i, j, ans = 0, start = INT_MAX, n, found = 0; bool asc = 1; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; if (i > 1) if (a[i] < a[i - 1]) asc = 0; } if (asc == 1) { cout << "0"; return 0; } else { ...
4
#include <bits/stdc++.h> using namespace std; map<string, string> m; map<string, int> ma; string a, b, c; int n; int main() { cin >> n; ma["void"] = 1; while (n--) { cin >> a; if (a == "typedef") { cin >> b >> c; string s = ""; int d = 0, d1; for (int i = 0; i < b.length(); i++) { ...
10
#include <bits/stdc++.h> using namespace std; inline void proc_status() { ifstream t("/proc/self/status"); cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl; } template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> i...
21