solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 50; char s[505]; int main() { int T; cin >> T; while (T--) { cin >> (s + 1); int n = strlen(s + 1); s[0] = '#'; set<char> v; int tot = 1; for (int i = 2; i <= n; i++) { if (s[i] == s[i - 1]) tot++; els...
2
#include <bits/stdc++.h> using namespace std; int n, h, a, b, k; int main() { scanf("%d%d%d%d%d", &n, &h, &a, &b, &k); for (int i = 1; i <= k; i++) { int x, y, p, q; scanf("%d%d%d%d", &x, &y, &p, &q); if (x > p) swap(x, p), swap(y, q); if (x == p) { printf("%d\n", abs(y - q)); continue; ...
2
#include <bits/stdc++.h> using namespace std; bool isprime(long long q) { for (long long i = 2; i * i <= q; i++) if (q % i == 0) return 0; return 1; } int main() { long long q; cin >> q; if (isprime(q)) { cout << 1 << endl << 0; return 0; } vector<long long> p; long long temp = q; for (lon...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k, i, j; cin >> n >> k; string s; cin >> s; char c[k]; for (i = 0; i < k; i++) { cin >> c[i]; } vector<long long int> v; for (i = 0; i < n; i++) { long l...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; int a[1000]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n, [=](int a, int b) { return a > b; }); for (int i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1001000, M = 1001000; struct edge { int n, v; } e[M]; int n, f[N], fa[N], hd[N], fl, ans, x1[N], x2[N]; void add(int u, int v) { e[++fl] = (edge){hd[u], v}; hd[u] = fl; } int upd(int u, int v) { if (f[u] < x2[v]) return 0; if (f[u] > x1[v]) x2[v]...
18
#include <bits/stdc++.h> using namespace std; vector<bool> seive(int n) { vector<bool> v(n, true); v[0] = false; v[1] = false; for (int i = 2; i * i <= n; i++) { if (v[i]) { for (int j = i * i; j < n; j = j + i) { v[j] = false; } } } return v; } int gcd(int a, int b) { if (a ==...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; string str; cin >> n >> str; string newStr = ""; for (int i = 0; i < n; i++) { if (i < n - 1) { if ((str[i] == 'U' && str[i + 1] == 'R') || (str[i] == 'R' && str[i + 1] == 'U')) { newStr += "D"; ++i; ...
0
#include <bits/stdc++.h> using namespace std; mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); long long inf = 1e18, MOD = 1e9 + 7; string s, s1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ti = 1; while (ti--) { int n, m, k; cin >> n >> m >> k; ...
15
#include <bits/stdc++.h> double xp, yp, vp, x, y, v, r, xpr, xpa; int ok(double tim) { double jd = tim * vp / xpr; double xpnow = cos(xpa + jd) * xpr; double ypnow = sin(xpa + jd) * xpr; double dis1 = sqrt(x * x + y * y); double hd1 = acos(r / dis1); double dis2 = sqrt(xpnow * xpnow + ypnow * ypnow); doub...
16
#include <bits/stdc++.h> using namespace std; int n, m, arr[500005], l[500005], r[500005], ord[500005], ans[500005], bit[500005]; map<int, int> mm; bool cmp(int x, int y) { return r[x] < r[y]; } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &arr[i]); for (int i = 0; i < 500005;...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, maxneg = -1005, nrneg = 0, val, s = 0, i; scanf("%d", &n); for (i = 1; i <= n + n - 1; ++i) { scanf("%d", &val); if (val < 0) { if (maxneg < val) maxneg = val; ++nrneg; val = 0 - val; } if (maxneg < 0 - val) maxneg...
10
#include <bits/stdc++.h> struct node { bool val; char op; int l, r; }; int n, a; char c, emp; node mas[1000001]; short inp[1000001]; void rek(int nom) { if (nom != 0 && mas[nom].op != 'I') { rek(mas[nom].l); rek(mas[nom].r); if (mas[nom].op == 'X') mas[nom].val = mas[mas[nom].l].val xor mas[ma...
12
#include <bits/stdc++.h> using namespace std; char local = 'O'; template <typename T> void read(T &a) { cin >> a; } template <typename T, typename T1> void read(T &a, T1 &b) { cin >> a >> b; } template <typename T, typename T1, typename T2> void read(T &a, T1 &b, T2 &c) { cin >> a >> b >> c; } template <typename ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5; const int mod = 1e9 + 7; long long fac[maxn], a[maxn]; void inist() { fac[0] = 1; fac[1] = 1; for (int i = 2; i <= maxn - 10; i++) { fac[i] = (fac[i - 1] * (i % mod)) % mod; } } void exgcd(long long a, long long b, long long& x, long long& ...
14
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int sum; set<int> s; set<int>::iterator it; void combinationUtil(int arr[], int n, int r, int index, int data[], int i); void printCombination(int arr[], int n, i...
5
#include <bits/stdc++.h> using namespace std; struct Point { int x, y, type; void print() { cout << "[" << x << ", " << y << ", " << (type == 0 ? "Red" : "Blue") << "]\n"; } Point operator-(const Point& o) const { return {x - o.x, y - o.y, type}; } long long operator*(const Point& o) const { ...
18
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int tc = 0; tc < t; tc++) { int h, m; cin >> h >> m; long long int x = ((24 - h - 1) * 60) + (60 - m); cout << x << endl; } }
0
#include <bits/stdc++.h> using namespace std; long long n, s, p = 0, w = 0, ans = 0; long long d[19]; long long f[19]; long long g[10]; bool r[19]; long long gcd(long long n, long long m) { if (m == 0) return n; return gcd(m, n % m); } long long fac(long long x, long long y) { long long a = 1, b = 1; for (int h...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; string s; cin >> n >> x >> y >> s; if (s[x - 1] == s[y - 1]) { cout << 0; } else { cout << 1; } }
4
#include <bits/stdc++.h> using namespace std; int main() { long long i = 1, n, h, a, result = 0; cin >> n; cin >> h; while (i <= n) { cin >> a; if (a > h) result += 2; else result += 1; i++; } cout << result; return 0; }
0
#include <bits/stdc++.h> using namespace std; int L[200000], R[200000], PS[200001]; vector<int> V; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ((void)0); ((void)0); ((void)0); int N, M; string s; long long ans = 0; cin >> s; N = s.size(); L[0] = s[0] == '0'; R[N - ...
18
#include <bits/stdc++.h> using namespace std; void solve() { int n, s; cin >> n >> s; if (s - n + 1 > (s + 1) / 2) { cout << "YES\n"; for (int i = 1; i < n; i++) cout << 1 << " "; cout << s - n + 1 << endl; cout << (s + 1) / 2; } else cout << "NO"; return; } int main() { ios_base::sync_w...
6
#include <bits/stdc++.h> const int MAXN = 1e6 + 1, P = 1e9 + 7; int i, j, k, n, q, r, d[MAXN], f[MAXN][20]; int main() { for (i = 2; i < MAXN; i++) if (!d[i]) for (j = i; j < MAXN; j += i) d[j] = i; for (i = 0; i < MAXN; *f[i++] = 1) ; for (d[1] = i = 1; i < 20; f[0][i++] = 2) ; for (i = 1; i ...
17
#include <bits/stdc++.h> using namespace std; long long rdtsc() { long long tmp; asm("rdtsc" : "=A"(tmp)); return tmp; } inline int sign(double x) { return x < -(1e-4) ? -1 : x > (1e-4); } struct pt { double x, y; pt(double _x = 0, double _y = 0) : x(_x), y(_y) {} inline pt operator-(const pt &p) const { re...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int MOD1 = 1781601607; const int MOD2 = 1138640077; int n; char str[N]; long long has1[N], has2[N]; long long pw1[N], pw2[N]; long long hash1(int p, int q) { long long ans = has1[q]; long long cnt = has1[p - 1] * pw1[q - p + 1]; cnt %= MOD...
15
#include <bits/stdc++.h> using namespace std; const long long N = 200005, INF = 2000000000000000000; long double pi = 3.1415926535897932; long long power(long long a, long long b, long long p) { if (a == 0) return 0; long long res = 1; a %= p; while (b > 0) { if (b & 1) res = (res * a) % p; b >>= 1; ...
10
/* -> Written by <- ----------- |K_A_Z_A_M_A| |___________| | ___ | | (^_^) | | /( | )\ | |____|_|____| H O A N G */ #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define Task "" #define F first #defin...
4
#include <bits/stdc++.h> using namespace std; const int Max = 1e5 + 110; int main() { int n; string str; cin >> n >> str; int i = 0, ans = 0; while (i < n && str[i++] == '1') ans++; int k = 0; for (int i = 0; i < str.size(); i++) if (str[i] == '0') k++; if (k) ans++; cout << ans; }
1
#include <bits/stdc++.h> auto constexpr maxn = 300007; auto constexpr maxl = 20; auto constexpr inf = 1 << 30; int a[maxn]; int f[maxn][maxl]; int last[maxl]; int n, q; bool work(int l, int r) { for (auto i = 0; i < maxl; i++) { if (!(a[r] & (1 << i))) continue; if (f[l][i] <= r) return true; } return fal...
14
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; const long long int LINF = 1LL * INF * INF; const int MAXN = 2e5 + 10; const int MAXM = 5e3 + 10; priority_queue<int> pq; vector<vector<int> > graph; queue<int> que; int A[MAXN]; char S[MAXN]; int main() { int n, m, k, a, b, x, y; int sum = 0; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> ans; int s = 0; int cnt = 0; for (int i = 1; i <= n; i++) { if (n - s - i > i) { s += i; cnt++; ans.push_back(i); } else { cnt++; ans.push_back(n - s); break; } } cout ...
2
#include <bits/stdc++.h> using namespace std; int x[200005]; int cha[200005]; int n; int t = 0; int gcd(int m, int n) { t = m > n ? n : m; m = m > n ? m : n; n = t; if (m % n == 0) return n; return gcd(m % n, n); } int main() { scanf("%d", &n); int maxn = 0; for (int i = 1; i <= n; i++) { scanf("%d"...
5
#include <bits/stdc++.h> using namespace std; int s[30010]; int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; ++i) scanf("%d", &s[i]); int sum = 0; for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (s[i] > s[j]) ++sum; if (sum % 2 == 1) sum ...
11
#include <bits/stdc++.h> using namespace std; int a, b; char s[300005]; vector<int> v; int judge(int x) { if (x >= b && x < a) return 0; if (x >= a && x < (b << 1)) return 1; if (x >= (b << 1)) return 2; return -1; } int main() { int t; scanf("%d", &t); while (t--) { v.clear(); scanf("%d %d", &a, ...
17
#include <bits/stdc++.h> using namespace std; char mapp[51][51]; bool vis[51][51]; char temp; bool yes = false, first_layer; int originx, originy; int n, m; void dfs(int i, int j, int fromx, int fromy) { if (i == originx && j == originy && !first_layer) { yes = true; return; } if (vis[i][j] == true) retur...
7
#include <bits/stdc++.h> using namespace std; char chr[1000][10]; int arr[15][10]; map<char, int> m; bool brr[15]; struct Qnode { int index; int rate; } qnode[15]; int judge(int x) { int res = 1; for (int i = 1; i <= x; i++) { res *= 10; } return res; } bool cmp(Qnode n1, Qnode n2) { return n1.rate > n2...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); srand(time(nullptr)); int n; cin >> n; vector<vector<int>> p; p.reserve(n); vector<int> c(n); for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; p.push_back({x, y, i}); } long ...
15
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int ans = 0; for (int i = n - 1; i >= 0; i--) { if (k % a[i] == 0) { ans = k / a[i]; break; } } cout << ans << endl; }
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; void __never(int a) { printf("\nOPS %d", a); } void __die(int a) { printf("%d", (a * a) / (a + a)); } double eps = 1e-6; double pi = 3.14159265358979323; int n, R, r; void init() { freopen("input.txt", "r", stdin); freopen("out...
9
#include <bits/stdc++.h> using namespace std; char _buf[1048576], *_is = _buf, *_it = _buf; inline char rdc() { if (_is == _it) _it = (_is = _buf) + fread(_buf, 1, 1048576, stdin); return *_is++; } inline void rdi(int &x) { int f = 0; register char ch = rdc(); while ((ch < '0' or ch > '9') and (ch ^ '-')) ch ...
18
#include <bits/stdc++.h> using namespace std; const int N = 2005; const int mod = 1e9 + 7; void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } int mul(int x, int y) { return 1ll * x * y % mod; } int n, k; string s; int f[N][N], g[N][N]; int main() { ios_base::sync_with_stdio(false); cin >> n >> k >> s; ...
17
#include <bits/stdc++.h> using namespace std; typedef long long i64; typedef unsigned long long ui64; typedef vector<i64> vi; typedef vector<vi> vvi; typedef pair<i64, i64> pi; #define pb push_back #define sz(a) i64((a).size()) #define all(c) (c).begin(), (c).end() #define REP(s, e, i) for(i=(s); i < (e); ++i) inlin...
0
#include <bits/stdc++.h> using namespace std; #define int long long void read (int &x) { char ch = getchar(); int f = 0; x = 0; while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x; } const int N = 1024; int m, k, y, p, a[...
22
#include <bits/stdc++.h> using namespace std; using seq = vector<int64_t>; int64_t n, k, a[100]; seq sep[100], D{1}; seq unite(seq a, seq b) { seq c(a.size() + b.size()); c.resize(set_union(a.begin(), a.end(), b.begin(), b.end(), c.begin()) - c.begin()); return c; } seq jumps(int a) { seq res; for ...
15
#include <bits/stdc++.h> using namespace std; const long long int mod = 998244353; char c[200001]; void solve() { cin >> c; int a[3] = {-10000000, -10000000, -10000000}; int ans = 10000000; for (int i = 0; c[i]; i++) { a[c[i] - '1'] = i; ans = min(ans, 1 + i - min({a[0], a[1], a[2]})); } cout << (an...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, x; cin >> n; map<long long, long long> mp; vector<long long> v; for (i = 0; i < n; i++) { cin >> x; v.push_back(x); mp[x]++; } map<long long, long long, std::greater<long long> > occ; for (map<long long, long long>...
7
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> v1, v2; for (long long i = 0; i < 2 * n; i++) { long long x; cin >> x; if (x % 2 == 0) v1.push_back(i + 1); else v2.push_back(i + 1); } if (v1.size() % 2 == 0) { long long a ...
3
#include <bits/stdc++.h> int n, m, i, j, p, q, r, s, u, v, k; int a[100001]; double dp[100001][101], buf[101], ncr[1001][1001]; double ans; int min(int a, int b) { return a < b ? a : b; } void init() { int i, j; ncr[0][0] = 1; for (i = 1; i < 1001; i++) for (j = 0; j <= i; j++) { ncr[i][j] += ncr[i - 1]...
18
#include <bits/stdc++.h> using namespace std; int main() { int n, r; double R, temp; cin >> n >> r; temp = sin(3.14159265 / n); R = r * temp / (1 - temp); cout << setprecision(7) << fixed; cout << R << endl; }
4
#include <bits/stdc++.h> using namespace std; long long power(long long a, int n) { long long r = 1; while (n) { if (n & 1) { --n; r *= a; } else { a *= a; n >>= 1; } } return r; } bool compare(const vector<long long>& a, const vector<long long>& b) { if (a.size() != b.size...
5
#include <bits/stdc++.h> using namespace std; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; typename vector<T>::const_iterat...
7
#include <bits/stdc++.h> using namespace std; int cx[] = {0, -1, -1, -1, 0, 0, 1, 1, 1}, cy[] = {0, -1, 0, 1, -1, 1, -1, 0, 1}, arg[] = {0, 30, 45, 75, 88, 19}; int N, T, Ans1, Ans2, A[2005][2005], B[2005][2005]; vector<pair<int, int> > G[2005]; void DFS(int x, int y) { if (!A[x][y]) return; G[T].push_back(make...
11
#include <bits/stdc++.h> long long int n, m; void merging(long long arr[], long long start, long long mid, long long end); void sort(long long arr[], long long start, long long end) { long long mid; if (end - start + 1 > 1) { mid = (start + end) / 2; sort(arr, start, mid); sort(arr, mid + 1, end); m...
7
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b; cin >> t; while (t--) { cin >> a >> b; if (a < b) { cout << b - a << endl; } else { (a % b == 0) ? cout << 0 << endl : cout << (b * ((a / b) + 1)) - a << endl; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; int n; long long k; long long cache[55]; const long long pp = 1e18; long long solve(int idx) { if (idx == n) return 1; long long &ret = cache[idx]; if (ret != -1) return ret; ret = 0; for (int i = idx, j = 0; i < n && j < 2; i++, j++) { ret += solve(i + 1); ...
11
#include <bits/stdc++.h> using namespace std; int n, m; vector<vector<int> > b(1e6 + 10); void bfs(int dist) { queue<pair<int, int> > q; vector<int> d; int x[] = {1, 1, 1, 0, 0, -1, -1, -1}; int y[] = {1, -1, 0, 1, -1, -1, 0, 1}; int k = 8; for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= m + 1; j+...
14
#include <bits/stdc++.h> using namespace std; int e[311][311]; int n, np, deg[311]; int main() { scanf("%d", &n); if (n % 2 == 0) puts("NO"); else if (n == 1) { puts("YES"); printf("%d %d\n%d %d\n", 2, 1, 1, 2); } else { puts("YES"); memset(e, 0, sizeof(e)); for (int i = 1; i <= n + 1; i...
11
#include <bits/stdc++.h> using namespace std; string st[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen"...
2
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k, s; cin >> n >> k >> s; long long sml = s / k; long long rem = s - sml * k; if (sml == 0 || sml >= n) { cout << "NO\n"; return; } if (rem && sml + 1 >= n) { cout << "NO\n"; return; } cout << "YES\n"; long lon...
8
#include <bits/stdc++.h> using namespace std; long long n, a[1000000], k, k1, p; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = n; i > 1; i--) { if (a[i] < a[i - 1]) { k = i; break; } } a[n + 1] = 1000000001; for (int i = 1; i < n; i++) { if (a[i] > a[i...
5
#include <bits/stdc++.h> using namespace std; const int N = 720, Mod = 1e9 + 7; int f[N][N][10], dig[N], cnt, Ans, v1[N]; inline int Dynamic(int d, int p, int k, int up, int f0) { if (p < 0) return 0; if (d == 0) return !f0 && !p; if (!up && !f0 && f[d][p][k] != -1) return f[d][p][k]; int lim = (up ? dig[d] : 9...
20
#include <bits/stdc++.h> using namespace std; int const N = 1e6 + 1; int n, k; string s; char alpha[] = {'0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'z'}; void test(string an) { int x = 0; for (int i = 0...
5
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans...
6
#include <bits/stdc++.h> inline void MAXR(int &a, int b) { if (a < b) a = b; } using namespace std; int main() { double a, d, x, y, dist = 0; int n, cnt = 0; cin >> a >> d; n = ({ int x; scanf("%d", &x); x; }); for (int(i) = (0); i < n; i++) { dist += d; int quot = dist / a; if (qu...
7
#include <bits/stdc++.h> using namespace std; int a[3]; int main() { cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); cout << (a[2] - a[1]) + (a[1] - a[0]) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int x, a, b, n; cin >> n >> a >> b; x = n - (b + 1); cout << (a > x ? (n - a) : (b + 1)); return 0; }
2
#include <bits/stdc++.h> using namespace std; struct Edge { int nex, to; } edge[105 << 1]; int E, n, m, x, y, head[105], sz[105], f[105][105][2], g[105][2], c[105][105], ans[105]; void add(int x, int y) { edge[E].nex = head[x]; edge[E].to = y; head[x] = E++; } void dfs(int k, int fa) { sz[k] = f[k][0][0] ...
18
#include <bits/stdc++.h> using namespace std; using namespace rel_ops; int n; int m; int k; unordered_set<int> gov; vector<vector<int> > adj; vector<int> dfs_num; bool is_gov = false; pair<int, int> dfs(int u) { if (gov.count(u)) is_gov = true; dfs_num[u] = 1; int edges = adj[u].size(); int nodes = 1; for (in...
7
#include <bits/stdc++.h> using namespace std; set<pair<string, string> > lks; set<string> names; int n; int a, b, c; vector<string> t1, t2, t3; vector<string> avlNames; long long minDif = 999999999999999, maxLaik = -5555555555555; void comp() { if (avlNames.size()) { string dummy; t1.push_back(avlNames.back()...
6
#include <bits/stdc++.h> using namespace std; int main() { int frieds, bottles, mililiters, limes, pieces, salt, necesaryliters, necesarysalt; cin >> frieds >> bottles >> mililiters >> limes >> pieces >> salt >> necesaryliters >> necesarysalt; int toast = (bottles * mililiters) / necesaryliters; int...
0
#include <bits/stdc++.h> using namespace std; int n, k, cnt, ans, a[200010]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) if (a[i] == a[i - 1]) ++cnt; else if (a[i] <= a[i - 1] + k) cnt = 1; else...
4
#include <bits/stdc++.h> using namespace std; int inf = 1 << 30; vector<int> tams; int sz; int pos = 0; string s; void recurse() { int cnt = 0; pos += 7; while (true) { if (s[pos + 1] == '/' && s[pos + 2] == 't' && s[pos + 3] == 'a') break; else if (s[pos + 2] == 'd') pos += 4; else if (s[...
9
#include <bits/stdc++.h> using namespace std; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.second < b.second) return true; else return false; } int main() { int n, m, k; while (cin >> n >> m >> k) { int a, b, c; vector<pair<int, int> > v[n], t; for (int i = 0; i < m; i++) { cin...
12
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const int mod = 1e9 + 7; long long qpow(long long n, long long k) { long long res = 1; while (k) { if (k & 1) res = res * n % mod; n = n * n % mod; k >>= 1; } return res; } long long fac[N], inv[N]; long long C(int n, int k) { ret...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, l, i; long long a[100010], sum[100010]; cin >> n >> l; memset(sum, 0, sizeof(sum)); for (i = 1; i < n; i++) scanf("%lld", &a[i]); for (i = 1; i < n; i++) sum[i] = sum[i - 1] + a[i]; long long ans = 10000000000; for (i = l; i < n; i++) ...
11
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; int i = 0; int j = n - 1; string res = ""; int prev = 0, ct = 0; while (j >= i) { if (arr[j] > prev && arr[i] < prev) { prev = arr[j]; res.push_b...
5
#include <bits/stdc++.h> using namespace std; int ans, n, k, vis[(int)(1e2 + 5)][(int)(5 * 1e1 + 5)][(int)(1e2 + 5)][2]; char s[(int)(1e2 + 5)]; void solve(int cur, int kal, int poz, int yon) { if (vis[cur][kal][poz][yon] || kal < 0) return; vis[cur][kal][poz][yon] = 1; if (cur == n + 1) { if (kal == 0) ans =...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 1; j <= n / 2; j++) { cout << i * n / 2 + j << " " << n * n - i * n / 2 - j + 1 << " "; } cout << "\n"; } return 0; }
2
#include <bits/stdc++.h> using namespace std; inline void INPUT(const string &s) { freopen((s).c_str(), "r", stdin); } inline void OUTPUT(const string &s) { freopen((s).c_str(), "w", stdout); } string str; int main() { cin >> str; for (int i = 0; i < str.size(); ++i) { if (str[i] >= 'A' && str[i] <= 'Z') { ...
2
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int cap = 0, small = 0; for (int i = 0; i < s.length(); i++) { if (s[i] >= 'a' and s[i] <= 'z') small++; if (s[i] >= 'A' and s[i] <= 'Z') cap++; } if (cap > small and small != 0) { for (int i = 0; i < s.length(); i++)...
0
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> pt; vector<int> block[1488]; int tp = 0; bool cmp(int i, int j) { return pt[i] < pt[j]; } int main() { int n; scanf("%d", &n); pt.resize(n); for (int i = 0; i < n; ++i) { scanf("%d %d", &pt[i].first, &pt[i].second); block[pt[i].second ...
13
#include <bits/stdc++.h> using namespace std; const long long int N = 200010; const long long mod = 1000000007; const long long inf = 1000000000000000000; const long double pi = 3.14159265358979323846264338; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m; cin >> n >> m; ma...
2
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; if (k < 2 * n) { if (k > n) cout << (2 * n - k + 1) / 2; else cout << (k - 1) / 2; } else cout << 0; return 0; }
2
#include <bits/stdc++.h> using namespace std; int a[102]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int q; int c, n, k, d; cin >> q; while (q--) { cin >> n >> k >> d; int mn = INT_MAX; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (...
2
#include <bits/stdc++.h> using namespace std; int T; int exgcd(int x, int y, int &a, int &b) { if (!y) return a = 1, b = 0, b; int g = exgcd(y, x % y, a, b); int t = b; b = a - x / y * b; a = t; return g; } int inv(int x, int p) { int a, b; exgcd(x, p, a, b); return (a % p + p) % p; } int F(int a, int...
22
#include <bits/stdc++.h> using namespace std; long long int psum[800] = {0}; long long int arr[800]; long long int pmin[800]; int n; bool f(long long int x, int cnt) { priority_queue<long long int, vector<long long int>, greater<long long int>> pq; long long int sum = x; for (int i = 1; i <= n; i++) { p...
15
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int n, m, x, y, w, i, t, length, u; cin >> n >> m; vector<vector<pair<unsigned long long int, unsigned long long int>>> adj(n); vector<unsigned long long int> dist(n, 1e13); while (m--) scanf(" %llu%llu%llu", &x, &y, &w), adj[x ...
12
#include <bits/stdc++.h> using namespace std; char c[10] = {'a', 'e', 'i', 'o', 'u', 'y'}; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; string s; cin >> s; string ans; bool t = 0; for (int i = 0; i < s.size(); i++) { bool is = 0; for (int j = 0; j < 6; j++) { i...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = int(2e3); const int LOG2 = 14; const int MOD = int(1e9) + 7; const int oo = INT_MAX; int n, tc; int ans1, ans2, ans3; string s; int a[255]; int mn[MAXN][LOG2]; int seen[MAXN][MAXN]; int dp1[MAXN][MAXN]; int dp3[MAXN][MAXN]; void build() { for (int i = 0; ...
9
#include <bits/stdc++.h> using namespace std; namespace NetFlow { const int MAXN = 100000, MAXM = 500000, inf = 1e9; struct Edge { int v, c, f, nx; Edge() {} Edge(int v, int c, int f, int nx) : v(v), c(c), f(f), nx(nx) {} } E[MAXM]; int G[MAXN], cur[MAXN], pre[MAXN], dis[MAXN], gap[MAXN], N, sz; void init(int _n)...
17
#include <bits/stdc++.h> using namespace std; bool f[100500]; int d1[100500]; int d2[100500]; int ans[100500]; int sd1 = 0, sd2 = 0; vector<int> g[100500]; int deg[100500]; void dfs(int u, int dol) { f[u] = true; if (dol) { d1[sd1++] = u; } else { d2[sd2++] = u; } for (int i = 0; i < (int)(g[u].size()...
17
#include <bits/stdc++.h> using namespace std; long long INF = 1e9 + 7; long long MOD = 998244353; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; ; cin >> n; ; long long dp[n + n]; dp[0] = n; long long fact[n + 1]; fact[0] = 1; fact[1] = 1; for (long lo...
25
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int a[maxn]; int main() { int T; cin >> T; while (T--) { int f = 0; int x; string s; cin >> s >> x; for (int i = 0; i < s.size(); i++) { a[i] = 1; } for (int i = 0; i < s.size(); i++) { if (s[i] == '0')...
7
#include <bits/stdc++.h> using namespace std; struct Tries { int sz; Tries *child[2]; Tries() { sz = 0; for (int i = 0; i <= 1; i++) child[i] = NULL; } }; Tries T; bool bit(int x, int i) { return (x >> i) & 1; } void upd(Tries *p, int x, int h, int val) { p->sz += val; if (h < 0) return; for (int ...
12
#include <bits/stdc++.h> using namespace std; bool good(string s[], int g[][4], int x); bool f(string s[], int g[][4], int x, int m); int main() { string s1[3], s[4]; int cnt = 0; bool p[4][4] = {}; int g[4][4] = {}; for (int i = 0; i < 5; i++) { cin >> s1[0] >> s1[1] >> s1[2]; int t1 = cnt; for (...
10
#include <bits/stdc++.h> using namespace std; int n; char dir[200047]; long long l[200047]; int main() { scanf("%d", &n); scanf("%s", dir); for (int i = 0; i < n; i++) scanf("%lld", l + i); long long ans = -1; for (int i = 0; i < n - 1; i++) if ((dir[i] == 'R') && (dir[i + 1] == 'L')) { if (ans == -...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll, ll>; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll fpow(ll b, ll p) { if (p == 0) return 1; ll h = fpow(b, p / 2); if (p % 2) return h * b % (ll)(998244353) * h ...
6
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int fast_pow(int a, int b) { int res = a, ret = 1; while (b > 0) { if (b % 2) ret = (ret * res) % mod; res = (res * res) % mod; b /= 2; } return ret; } map<int, int> u, first; int t[444444], p[444444], x, i, ai, aj, n, ii, ans[44...
9
#include <bits/stdc++.h> using namespace std; using db = double; using dbl = long double; using ll = long long; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using gr = vector<vector<int> >; using grl = vector<vector<ll> >; mt19937 rnd(chrono::high_resolution_clock::...
0