solution
stringlengths
53
181k
difficulty
int64
0
27
#include<algorithm> #include<iostream> #include<cstring> #include<iomanip> #include<sstream> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<cmath> #include<stack> #include<set> #include<map> #define rep(i,x,n) for(int i=x;i<=n;i++) #define per(i,n,x) for(int i=n;i>=x;i--) #...
11
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k; int x[3], y[3]; for (i = 0; i < 3; i++) { scanf("%d", &x[i]); scanf("%d", &y[i]); } int area = x[0] * y[0] + x[1] * y[1] + x[2] * y[2]; int side = sqrt(area); char ch[3]; ch[0] = 'A'; ch[1] = 'B'; ch[2] = 'C'; int flag...
9
#include <bits/stdc++.h> int main() { long long a; std::cin >> a; std::cout << (a & 1 ? 1 : 2); return 0; }
4
#include <bits/stdc++.h> using namespace std; int a[100000]; long long int k = 0; void printDivisors(long long int n) { k = 0; for (long long int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) a[k++] = i; else { a[k++] = i; a[k++] = n / i; } } } } i...
6
#include <bits/stdc++.h> using namespace std; int main() { int x, z = 0; cin >> x; for (int i = 0; i < x; i++) { int y = 0; for (int j = 0; j < 3; j++) { int v; cin >> v; y += v; } if (y >= 2) z += 1; } cout << z; }
0
#include <bits/stdc++.h> using namespace std; long long t, n, k, ar[1005], i, pre, ans; int main() { cin >> t; while (t--) { cin >> n >> k; for (i = 1; i <= k; i++) cin >> ar[i]; sort(ar + 1, ar + k + 1); ans = -1; ans = max(ans, (ar[1] - 1) + 1); ans = max(ans, (n - ar[k]) + 1); long lo...
2
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); while (t--) { int x, y, a, b; scanf("%d%d%d%d", &x, &y, &a, &b); int ti = (y - x) / (a + b); if (ti * (a + b) == (y - x)) printf("%d\n", ti); else printf("-1\n"); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, x; cin >> n; for (int i = 1; i <= n; i++) { cin >> x; long long q = x % 14; if (x > 14 && q >= 1 && q <= 6) cout << "YES\n"; else cout << "NO\n"; } }
2
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int r = 0; r < t; r++) { long long n, k, x, ma = -2 * 1e9 - 1; cin >> n >> k; vector<int> a; for (int i = 0; i < n; i++) { cin >> x; a.push_back(x); if (x > ma) { ma = x; } } fo...
0
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int main() { int n; cin >> n; int h; cin >> h; for (int i = 1; i <= n - 1; ++i) { double res = sqrt((double)i / n) * h; printf("%f ", res); } cout << endl; return 0; }
4
#include <bits/stdc++.h> int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for (auto &x : v) cin >> x; int ind1 = 0, ind2 = n - 1; while (v[ind1] == 0) ++ind1; while (v[ind2] == ...
0
#include <bits/stdc++.h> using namespace std; inline void chkmax(long long &a, long long b) { if (a < b) a = b; } inline void chkmin(long long &a, long long b) { if (a > b) a = b; } inline long long read() { long long a = 0, fh = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') fh = -1; ...
17
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e9 + 9; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(10); cout << fixed; unsigned int tet; cin >> tet; while (tet--) { int n; cin >> n; int a[n + ...
5
#include <bits/stdc++.h> int stc[1000005], n, i, x, t; int main() { scanf("%d", &n); for (i = 0; i < n; ++i) { for (scanf("%d", &x); t > 0 && stc[t] >= i - x; --t) ; stc[++t] = i; } printf("%d", t); }
4
#include <bits/stdc++.h> using namespace std; int main() { double d; int x[2], y[2], r[2]; cin >> x[0] >> y[0] >> r[0]; cin >> x[1] >> y[1] >> r[1]; d = (sqrt(pow(x[0] - x[1], 2) + pow(y[0] - y[1], 2))); if (d < r[1] + r[0]) { if (d + r[1] < r[0]) d = r[0] - d - r[1]; else if (d + r[0] < r[1])...
10
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> ar[500010]; int mr[500010]; vector<pair<int, int> > v; int up[20][500010]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> ar[i].first >> ar[i].second; mr[...
14
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; for (int i = (0); i < (n); ++i) sum += v[i]; return sum; } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_wit...
15
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 300005; pair<int, int> st[4 * N]; int lz[4 * N]; void prop(int p, int L, int R) { if (lz[p]) { st[p].first += lz[p]; if (L < R) { lz[2 * p] += lz[p]; lz[2 * p + 1] += lz[p]; } lz[p] = 0; } } pair<int, int> ...
22
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 7; int n, m; long long t, d; long long ans, sum; int pos = 1; struct node { int idx; long long val; } a[M]; long long cnt[M], val[M]; bool cmp1(const node &a, const node &b) { if (a.val != b.val) { return a.val < b.val; } return a.idx < b.i...
7
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; int a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2; cin >> a >> b >> c >> d >> e >> f; a2 = a + b + c + d + e + f; a1 = a + b + c; b1 = a + b + d; c1 = a + b + e; d1 = a + b + f; e1 = a + c + d; f1 = a + c + e; b2 = a...
2
#include <bits/stdc++.h> using namespace std; int main() { int k, a11 = (1 << 18) - 1, a10 = 1 << 17; cin >> k; cout << 2 << ' ' << 3 << endl << a11 << ' ' << a10 << ' ' << 0 << endl << k << ' ' << a11 << ' ' << k << endl; }
9
#include <bits/stdc++.h> using namespace std; template <typename T> std::ostream &operator<<(std::ostream &out, vector<T> &v) { for (typename vector<T>::size_type i = 0; i < v.size(); ++i) out << v[i] << " "; out << "\n"; return out; } template <typename T> std::ostream &operator<<(std::ostream &out, set<T> &...
8
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int mod = 1e9 + 7; const int N = 1e5 + 10; inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int mul(int x, int y) { x = (1LL * x * y) % mod; return x; } vector<vector<pair<int, int> > > G(200005); ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; pair<int, int> a[n]; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } for (int i = 0; i < n; i++) { int max1 = a[i].first, max2 = a[i].second, in = i; for (int j = i + 1; j < n; j++) { if (...
3
#include <bits/stdc++.h> using namespace std; int main() { string x, z; string y; cin >> x >> z; for (int i = 0; i < x.length(); i++) { if (x[i] < z[i]) { cout << -1 << endl; return 0; } else if (x[i] > z[i]) y.push_back(z[i]); else y.push_back(x[i]); } cout << y << endl;...
1
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n % 2) { cout << -1 << endl; exit(0); } for (int i = 0; i < n; i += 2) { cout << i + 2 << ' ' << i + 1 << ' '; } cout << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int i, l, r, ct, ans = 0, a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 1; i < 2 * n + 1; i++) { l = 0; r = n - 1; ct = 0; ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 500 + 50; long long n, m; long long a[maxn]; long long b[maxn]; vector<long long> v[maxn]; vector<pair<long long, char> > vec; int main() { scanf("%lld", &n); long long x1 = 0, y1 = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); x1 +=...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 1; scanf("%d", &n); int i, a[n], max = 1; for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (i > 0) { if (a[i] >= a[i - 1]) { count++; } else { count = 1; } if (count > max) { max = c...
1
#include <bits/stdc++.h> using namespace std; int sum1[50], sum2[50]; int main() { int n, a[50][50]; scanf("%d", &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) sum1[i] += a[i][j]; for (int i = 0; i < n; i++) ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const int DIM = 300 + 10; int n, a[DIM][DIM]; long long s; int main() { scanf("%d", &n); for (int i = (0); i < (n); i++) { for (int j = (0); j < (n); j++) { scanf("%d", &a[i][j]); s += a[i][j]; } } s /= ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i, j, cnt = 0, p = 0; cin >> n >> k; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { if (a[i] <= k) { cnt++; p++; } else if (a[i] > k) { i = n; break; } else if (p == n) ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i, sum = 0, total; cin >> n; int arr[n]; bool fing[5] = {true}; for (i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } total = n + 1; int count = 0; for (i = 1; i <= 5; i++) { if ((sum + i) % total == 1) { fing[i - ...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 600031; int n; string st; long long len[N], B[N]; long long cur_bal; long long stupid; long long taken_G, taken_W; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >> len[i]; len[i]...
18
#include <bits/stdc++.h> using namespace std; const int N = 300010; int n, m; int t[N], l[N], r[N], x[N]; int arr[N]; int cnt = 0; int seg[4 * N]; bool done[N]; int Mx; int build(int s, int e, int idx) { if (s == e) return seg[idx] = arr[s]; return seg[idx] = max(build(s, ((s + e) >> 1), (idx << 1)), ...
20
#include <bits/stdc++.h> int main() { int N, i; long long s = 0; long long mas[110]; scanf("%d", &N); for (i = 1; i <= N; i++) { scanf("%I64d", &mas[i]); } for (i = 1; i <= N; i++) { s += mas[i]; s += (mas[i] - 1) * (i - 1); } printf("%I64d\n", s); }
3
#include <bits/stdc++.h> using namespace std; int Int() { int x; scanf("%d", &x); return x; } long long Long() { long long x; scanf("%lld", &x); return x; } void err(istream_iterator<string> it) { cout << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args...
14
#include <bits/stdc++.h> using namespace std; int a[60], b[60]; int tota, totb; int ans[10000]; int tot = 0; int convert(int base, int *arr, int size) { int ans = 0, k = 1; for (int i = size - 1; i >= 0; i--) { ans += k * arr[i]; k = k * base; } return ans; } int main() { char tmp; int Max = 0; wh...
8
#include <bits/stdc++.h> using namespace std; long long ara[200005]; int main() { long long n, i, j, k, p, q, x, y; map<long long, long long> ma; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) scanf("%lld", ara + i); for (i = 1; i <= n; i++) ara[i] ^= ara[i - 1]; ma[0]++; for (i = 1; i <= n; i++) { ...
11
#include <bits/stdc++.h> using namespace std; long long rdtsc() { long long tmp; asm("rdtsc" : "=A"(tmp)); return tmp; } inline int myrand() { return abs((rand() << 15) ^ rand()); } inline int rnd(int x) { return myrand() % x; } const int INF = (int)1e9 + 1; const long double EPS = 1e-9; void precalc() {} int gcd...
20
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 16; int lpf[N]; void init() { memset(lpf, -1, sizeof(lpf)); for (int n = 2; n < N; n++) { if (lpf[n] == -1) { lpf[n] = n; if (n < N / n) { for (int m = n * n; m < N; m += n) { if (lpf[m] == -1) lpf[m] = n; } ...
9
#include <bits/stdc++.h> using namespace std; int a[12], b[12]; string s[12]; vector<int> ans; int main() { int i, j, k, l, n, m, p, d1, d2, d3, d4, x1, x2, flag; cin >> n; for (i = 0; i < n; i++) cin >> s[i] >> a[i] >> b[i]; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { if (j == i) continue; ...
9
#include <bits/stdc++.h> using namespace std; int n; char str[1010]; int main() { while (cin >> n) { cin >> str; int len = strlen(str); int biaoji = 0, biaoji1 = 0; int start, end; for (int i = 0; i < len; i++) { if (str[i] == 'L' && biaoji1 == 0) { biaoji1 = 1; start = i; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int x, y, t = 0; cin >> x >> y; while (y > 0) { t = t * 10 + y % 10; y /= 10; } cout << x + t; return 0; }
7
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007ll; long long get(long long a) { if (a % 4 == 0) return a; if (a % 4 == 1) return 1; if (a % 4 == 2) return a + 1; return 0; } void solve() { long long n; cin >> n; long long ans = 0; for (long long i = 1; i <= n; i++) { l...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int k, p; for (int i = 0; i < n; ++i) { if (i - x < 0) { k = 0; } else { k = i - x; } if (i + y > n - 1) { p = n - 1; ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int n, x, y; char str[MAXN]; int main() { scanf("%d%d%d", &n, &x, &y); scanf("%s", str + 1); str[0] = '1'; int cnt = 0; for (int i = 1; i <= n; i++) if (str[i] == '0' && str[i - 1] == '1') cnt++; cout << max(0ll, min(1ll * y * cnt, 1...
7
#include <bits/stdc++.h> using namespace std; long long n, x, y, ans, i; int main() { cin >> n >> x >> y; if (y < n) { printf("-1\n"); return 0; } if (n - 1 + (y - n + 1) * (y - n + 1) < x) { printf("-1\n"); return 0; } for (i = 0; i < n - 1; i++) printf("1\n"); printf("%d\n", y - n + 1); ...
6
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; int cnt[N][26]; int n; char s[N]; int ans[N]; int t[26]; int main() { scanf("%d", &n); scanf("%s", s + 1); for (int i = 1; i <= n; i++) { for (int j = 0; j < 26; j++) { cnt[i][j] = cnt[i - 1][j] + (s[i] - 'a' == j); } } for (...
10
#include <bits/stdc++.h> const double pi = acos(-1); int main() { double w, h, a; scanf("%lf%lf%lf", &w, &h, &a); if (w < h) std::swap(w, h); if (a >= 90.0) a = 180.0 - a; a *= pi / 180.0; if (a > 2.0 * atan(h / w)) { printf("%.10lf\n", h * h / sin(a)); } else { double t = (w + h) / (1.0 + sin(a) ...
12
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long fxp(long long a, long long b) { a %= 1000000007; long long res = 1; while (b > 0) { if (b % 2 == 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b /= 2; } return ...
6
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { return (a % b) == 0 ? b : GCD(b, a % b); } long long mod(long long x) { return ((x % 998244353 + 998244353) % 998244353); } bool cmp(const pair<int, int> &left, const pair<int, int> &right) { return left.first > right.first || ...
5
#include <bits/stdc++.h> using namespace std; const int oo = 999999999; const double PI = 3.1415931; const double eps = 1e-9; int n; double dp_prob[400][10], a[400][100], dp[400][10]; int min_bound(int x, int level) { x >>= (level - 1); x ^= 1; x <<= (level - 1); return x; } int max_bound(int x, int level) { ...
13
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template <typename T> void scan(T &x) { x = 0; bool neg = 0; register T c = getchar(); if (c == '-') neg = 1, c = getchar(); while ((c < 48) || (c > 57)) c = getchar(); for (; c < 48 || c > 57; c = getchar()) ; for (; c > 47 ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; long long dp[MAXN], arr[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> arr[i]; sort(arr + 1, arr + n + 1); for (int i = 1; i <= m; i++) { dp[i] = dp[...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; long long int arr[n]; long long int copy[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; copy[i] = arr[i]; } sort(copy, copy + n); long long int min = c...
5
#include <bits/stdc++.h> int n, i; long long w, sum, max; bool kt; int main() { scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%I64d", &w); sum += w; if (max < w) max = w; } n--; if (sum % n != 0) kt = true; sum = sum / n; if (kt) sum++; if (sum < max) sum = max; printf("%I64d", sum); ...
8
#include <bits/stdc++.h> using namespace std; struct point { double x, y, z; point(double a, double b, double c) { x = a; y = b; z = c; } point() {} void input() { scanf("%lf%lf%lf", &x, &y, &z); } }; double sqr(double z) { return z * z; } double mmdist(point a, point b) { return sqrt(sqr(a.x - ...
17
#include <bits/stdc++.h> using namespace std; long long phi[1000010], sum[1000010], f[3][1000010]; void get_phi() { phi[1] = 0; for (int i = 2; i < 1000010; i++) if (!phi[i]) { phi[i] = i - 1; for (int j = i; j < 1000010; j += i) { if (!phi[j]) { if ((j / i) % i == 0) p...
21
#include <bits/stdc++.h> using namespace std; const double E = exp(1); const int maxn = 1e6 + 10; int n, k; char ch[maxn]; int a[maxn]; bool cmp(int a, int b) { return a > b; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; cin >> ch; int res = 1; for (int i = 0; i < n; i++)...
3
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1}, dy[] = {1, 0}; string mp[1001000]; struct node { int x, y; }; vector<vector<bool> > vis; int n, m; bool dfs(int x, int y) { if (x == n && y == m) { return 1; } if ((x - 1) || (y - 1)) { mp[x][y] = '#'; } for (int i = 0; i < 2; ++...
11
#include <bits/stdc++.h> using namespace std; int tree[1001000], n, m, K, Q, ans[200100]; struct Point { int x, y; bool operator<(Point b) const { return y < b.y; } } point[200100]; struct Query { int x1, x2, y1, y2, id; bool operator<(Query b) const { return y2 < b.y2; } } query[200100]; void build(int t, int ...
16
#include <bits/stdc++.h> using namespace std; int n, m; char cou[3010][3010]; int l[3010][3010], r[3010][3010], ld[3010][3010]; int tree[6005][3005]; vector<pair<int, int> > leftPoint[3010]; void update(int no, int idx, int val) { while (idx <= 3005) { tree[no][idx] += val; idx += (idx & -idx); } } int sum(...
15
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; using PP = pair<P, P>; using VPP = vector<PP>; using VP = vector<P>; using VVP = vector<VP>; using VI = vector<int>; using VVI = vector<VI>; VI pare; VVP G; VI prof; VVI J, mx; int repre(int x) { return (pare[x] == -1 ? x : pare[x] = repre(pare[x])...
13
#include <bits/stdc++.h> using namespace std; int a1[5000]; char s[5010]; int bg, ed, n; long long f(int a, int b, bool bl) { long long r = 0, t; if (bl && bg == a) t = f(bg, ed, 0), a = ed; else t = s[a] - 48; int i = a + 1; while (i < b) { if (s[i] == '*') { if (bl && i + 1 == bg) { ...
13
#include<bits/stdc++.h> #pragma GCC optimize(2) #define ll long long #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,n,a) for(int i=n;i>=a;i--) #define endl '\n' #define eps 0.000000001 #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) #define IO ios::sync_with_stdio(false);cin.tie(0); using namespace ...
12
#include <bits/stdc++.h> using namespace std; template <class AT, class UT> struct SegmentTree { AT I, r; UT NU, v; int N, i, j; vector<AT> A; vector<UT> U; vector<int> L, R; virtual AT op(const AT& i, const AT& j) = 0; virtual AT& us(int p, const UT& v) = 0; SegmentTree(int N, AT I = 0, UT NU = INT_M...
17
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") int TN = 1; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector...
7
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, -1, 1, -1, -1, 1, 1}; int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1}; int n, sz, fsz, flag, last; string str, ch, ans[100], ar[100], nw; map<int, int> mp; bool check(int n) { int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } if (sum < 10) retu...
17
#include <bits/stdc++.h> using namespace std; template <typename T> bool get_int(T &x) { char t = getchar(); bool neg = false; x = 0; for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar()) ; if (t == '-') neg = true, t = getchar(); if (t == EOF) return false; for (; t <= '9' && t >= '0'; ...
22
#include <bits/stdc++.h> using namespace std; int main() { int n, m, flag = 0; cin >> n >> m; int i = 1; while (1) { if (i > n) i = 1; if (m >= i) m -= i; else { flag = 1; break; } i++; } if (flag == 0) cout << 0; else cout << m; }
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; struct Node { int x, id; } b[N]; int n, a[N], pos[N], L[N], R[N], Stack[N], ans; inline int read() { int x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f = ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 3) + (x << 1) + ch...
14
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e9; int n, m; vector<int> a; int doit(int p, int q, int plu) { if (p <= q) { return min(q, p + plu); } else { if (p + plu >= m) return min(p + plu - m, q); else return m + 1; } } int f(int dist) { vector<int> b = a; b...
9
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma G++ optimize("O3") using namespace std; const double PI = acos(-1.0); const int MAXN = 3e5 + 55; const int INF = 0x3f3f3f3f; const int NINF = 0x80808080; const long long NLINF = 0x8080808080808080; const long long LINF = 0x3f3f3f3f3f3f3f3f; const long long mo ...
12
#include <bits/stdc++.h> using namespace std; map<string, int> day; void init() { day["sunday"] = 0; day["monday"] = 1; day["tuesday"] = 2; day["wednesday"] = 3; day["thursday"] = 4; day["friday"] = 5; day["saturday"] = 6; } int main() { ios::sync_with_stdio(false); cin.tie(0); string s, e; cin >>...
2
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double int main() { ll t; cin >> t; while(t--) { ll p, a, b, c; cin >> p >> a >> b >> c; ll pos1=p/a; ll pos2=p/b; ll pos3=p/c; if(p%a) pos1++; if(p%b) ...
0
#include <bits/stdc++.h> using namespace std; inline int Read() { int x = 0, f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -f; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } struct node { int l, ...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n, p; cin >> n >> p; long long cnt = 2 * n + p, flag = 0; for (long long i = 1; i < n; i++) { for (long long j = i + ...
7
#include <bits/stdc++.h> using namespace std; int a[1005], used[1005]; map<int, int> vis; inline int dfs(int i, int j) { vis[j]--; int ret = 0; if (vis[i + j]) { ret = dfs(j, i + j) + 1; } vis[j]++; return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int z...
12
#include <bits/stdc++.h> using namespace std; pair<int, int> pp[10]; pair<int, int> pt[10]; long long dist(pair<int, int> a, pair<int, int> b) { return ((long long)(a.first - b.first) * (long long)(a.first - b.first)) + ((long long)(a.second - b.second) * (long long)(a.second - b.second)); } bool chkSQ(pair<...
8
#include <bits/stdc++.h> const double PI = 3.1415926535897932384626433; const int KL = 2e5 + 10; const long long MOD = 1e9 + 7; using namespace std; int n, m; long long ans; string t, s; long long st[27][KL], nd[27][KL]; int main() { scanf("%d", &n); cin >> t >> s; string v = "&"; v += t; string u = "&"; u ...
12
#include <bits/stdc++.h> using namespace std; int n, m, q; map<string, int> dict; const int maxn = 100010; int fa[maxn]; int ran[maxn]; void Init(int n) { for (int i = 0; i <= n; i++) { fa[i] = i; ran[i] = 0; } } int Find(int x) { if (x == fa[x]) return fa[x]; int y = Find(fa[x]); ran[x] = (ran[x] + r...
12
#include <bits/stdc++.h> const int N = 1e5 + 5; const int block = 320; int p[N], pre[N], to[N]; int n, q; inline int Read() { char ch; int f = 1; while ((ch = getchar()) < '0' || ch > '9') if (ch == '-') f = -1; int x = ch ^ 48; while ((ch = getchar()) >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (c...
16
#include <bits/stdc++.h> using namespace std; const int mods = 1e9 + 7; const int maxn = 50 + 10; const int N = 1e5 + 10; const int E = 1e6 + 10; long long n, p, m; struct node { int x, y; node(int x, int y) : x(x), y(y) {} }; vector<node> a; bool good[maxn][maxn]; char h[maxn][maxn]; bool vis[maxn][maxn]; int b[4]...
9
#include <bits/stdc++.h> using namespace std; int a[100001]; long long int n, i, j, k, l, s, m, d, ans; int main() { cin >> n >> d; k = 2; for (i = 1; i <= n; i++) cin >> a[i]; ans = 0; j = 2; for (i = 1; i <= n; i++) { while (a[j] - a[i] <= d && j <= n) j++; l = j - i - 1; ans += (l * (l - 1)) ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; int nums[100]; cin >> n; for (int i = 0; i < n; i++) { cin >> nums[i]; } sort(nums, nums + n); int sn = 0; for (int i = 0; i < n - 1; i++) { if (nums[i] == nums[i + 1]) { sn++; i++; } } cout << sn / 2 << endl; ...
2
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char c = getchar(), bz = 0; for (; c < 48 || c > 57; c = getchar()) if (!(c ^ 45)) bz = 1; for (; c >= 48 && c <= 57; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); bz ? x = -x : x; } struct edge { in...
27
#include <bits/stdc++.h> using namespace std; int sg[5010]; int dfs(int x) { if (x < 0) return 0; if (sg[x] != -1) return sg[x]; int visit[5010]; memset(visit, 0, sizeof(visit)); for (int i = 0; i < x; i++) { visit[dfs(i - 1) ^ dfs(x - i - 2)] = 1; } for (int i = 0;; i++) if (!visit[i]) return sg[...
15
#include <bits/stdc++.h> using namespace std; int gi() { int a; scanf("%d", &a); return a; } long long gli() { long long a; scanf("%I64d", &a); return a; } int v[100][100]; int a[100]; int s[100]; int idx = 0, n, m; bool fn(int a, int b) { return v[a][m - 1] - v[a][idx] > v[b][m - 1] - v[b][idx]; } int cl...
9
#include <bits/stdc++.h> using namespace std; const int INF = 1e8; const int MN = 1e5 + 7; long long n, d, x, a[MN], b[MN]; long long getNextX() { x = (x * 37 + 10007) % 1000000007; return x; } void initAB() { int i; for (i = 0; i < n; i = i + 1) { a[i] = i + 1; } for (i = 0; i < n; i = i + 1) { swa...
15
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << " " << a.second; return out; } t...
15
#include <bits/stdc++.h> using namespace std; namespace jumpmelon { const int MAXN = 300000, P = 998244353; bool Vis[MAXN + 1]; int tim, Col[MAXN + 1], Dfn[MAXN + 1], Fa[MAXN + 1], Dep[MAXN + 1]; int F[MAXN + 1][2]; struct edge { int u, v; } E[MAXN]; vector<int> G[MAXN + 1], G1[MAXN + 1], V[MAXN + 1]; inline bool cmp...
10
#include <bits/stdc++.h> using namespace std; const unsigned int mod = 1e9 + 7; const unsigned int N = 3e6 + 10; unsigned int add(unsigned int a, unsigned int b) { return a + b < mod ? a + b : a + b - mod; } unsigned int sub(unsigned int a, unsigned int b) { return a < b ? a + mod - b : a - b; } unsigned int mul(un...
17
#include <bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ int n; cin >> n; map<int, int> m, mi; int index = -1; for(int i = 0;i < n;i++){ int temp; cin >> temp; m[temp]++; mi[temp] = i+1; ...
0
#include <bits/stdc++.h> using namespace std; bool sortBySecond(const pair<long long, long long> &a, const pair<long long, long long> b) { return a.second > b.second; } int ncr[1001][1001]; bool vis_ncr[1001][1001]; long long NCR(int n, int r) { if (n < r) return 0; if (vis_ncr[n][r]) return ncr...
0
#include <bits/stdc++.h> using namespace std; int n, m, cl, ce, v; int stair[100005]; int ele[100005]; void solve(int x1, int y1, int x2, int y2) { int ans = 0x3f3f3f3f; if (x1 == x2) { cout << abs(y1 - y2) << endl; return; } int p = lower_bound(stair, stair + cl, y1) - stair; if (p != cl) ans = m...
8
#include <bits/stdc++.h> int main() { int n, m, k, l, count, p = 0; scanf("%d %d", &n, &m); int ara[n], i; for (i = 0; i < n; i++) { count = 0; scanf("%d", &ara[i]); k = ara[i]; for (; k % 10 != 0 || k / 10 != 0; k = k / 10) { l = k % 10; if (l == 7 || l == 4) { count++; ...
0
#include <bits/stdc++.h> using namespace std; int main() { bool ans = true; int n, i, j, k; char a; string s; cin >> s; n = s.length(); a = 'a'; for (i = 0; i < n; i++) { if (i == 0) { if (s[i] > 'a') { ans = false; break; } } else { if (s[i] == a + 1) { ...
3
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > edge[101]; bool dp[101][101][26]; bool vis[101][101][26]; bool f(int i, int j, int prev) { if (vis[i][j][prev]) return dp[i][j][prev]; bool ans = false; int k, v, w; for (k = 0; k < edge[i].size(); k++) { v = edge[i][k].first; w = edg...
9