solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> const int MAXN = 4e5 + 5; template <typename _T> void read(_T &x) { x = 0; char s = getchar(); int f = 1; while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s - '0'), s = getchar(); } x *= f; ...
18
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const int MON[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int saniye = 86400; int n, m; char A[10000000]; int sum[10000000 * 4]; void print() { for (int i = 0; i <= 18; i++) cout << A[i]; cout << endl; } int mai...
12
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("-ffloat-store") using namespace std; clock_t time_p = clock(); void aryanc403() { time_...
14
#include <bits/stdc++.h> using namespace std; vector<int> a; void ask(vector<int> v) { cout << v.size() << '\n'; for (int x : v) { cout << x + 1 << ' '; a[x] = 1; } cout << endl; int x; cin >> x; --x; for (int i = 0; i < v.size(); ++i) a[(x + i) % a.size()] = 0; } void solve(int n) { a.assign(...
18
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long arr[n]; long long rem[n]; for (long long i = 0; i < n; i++) { cin >> arr[i]; rem[i] = arr[i] % k; } sort(rem, rem + n); long long element =...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, a = 0, b = 0, c = 0, d = 0; int f = 0; cin >> n; int s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == 4) d++; if (s[i] == 3) c++; if (s[i] == 2) b++; if (s[i] == 1) a++; } int q = c; int w = b; f += d; ...
3
#include <bits/stdc++.h> using namespace std; void USACO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } void FHC(string s, string o) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((s).c_str(), "r", stdin); ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 40; char word[MAXN][MAXN]; int N; char ans[MAXN], tmp[MAXN]; bool found; bool mystrstr(char* s, char* t) { int lens = strlen(s), lent = strlen(t); if (lens < lent) return false; for (int i = 0; i < lens; i++) { int length = 0, j = 0; while (j ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; long long int n; cin >> n; for (long long int i = n; i < 2 * n; i = i + 1) { cout << i << " "; } }
4
#include <bits/stdc++.h> using namespace std; string ms(string s) { int l = s.length(); if (l & 1) return s; else { string a = ms(s.substr(0, l / 2)); string b = ms(s.substr(l / 2, l)); return a < b ? a + b : b + a; } } int main() { string s1, s2; cin >> s1 >> s2; if (ms(s1) == ms(s2)) { ...
9
#include <bits/stdc++.h> using namespace std; int numOfDigits(long long n) { int c = 0; while (n != 0) { c++; n = n / 10; } return c; } int main() { int T, n; cin >> T; while (T--) { cin >> n; string s = to_string(n); long long res = 100, l = pow(10, 18); for (long long i = 1; i < ...
5
#include <bits/stdc++.h> int DBG = 0; using namespace std; const double eps = 1e-9; const int oo = 1000000000; const int N = 0; int compute(int R, int r) { if (r > R) return 0; if (r * 2 > R) return 1; double x = asin(r * 1.0 / (R - r)); return int(acos(-1) / asin(r * 1.0 / (R - r)) + eps); } int main() { int...
9
#include <bits/stdc++.h> using namespace std; struct line { int x, l, r; bool operator>(const line& i) const { return r > i.r; } bool operator<(const line& i) const { return make_pair(x, make_pair(l, r)) < make_pair(i.x, make_pair(i.l, i.r)); } }; struct point { int x, y; line operator()(int t) const { ...
18
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000010, MAXNLG = 20; int v[MAXN], c[MAXN]; int vp[MAXNLG][MAXN], cp[MAXNLG][MAXN]; double mej[MAXN]; int lg[MAXN]; inline int maxV(int a, int b) { int q = lg[b - a + 1]; return max(vp[q][a], vp[q][b - (1 << q) + 1]); } inline int minC(int a, int b) { ...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); if (k > n) { printf("%d", -1); return 0; } int *a = new int[n]; for (int i = 0; i < n; i++) scanf("%d", a + i); sort(a, a + n); printf("%d %d", a[n - k], a[n - k]); }
1
#include <bits/stdc++.h> using namespace std; char str[300002]; int ar[300002]; int main() { int ln, q; cin >> ln >> q; cin >> str; memset(ar, 0, ln); int con = 0; for (int i = 0; i < ln; i++) { if (str[i] != '.') { ar[i] = 0; con = 0; } else if (con > 0) ar[i] = 1; else ...
8
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > v; long long n; double calculate(double x) { double radius = 0.0; for (long long i = 0; i < n; i++) { double xi = v[i].first; double yi = v[i].second; radius = max(radius, abs((1.0 * (xi - x) * (xi - x) + ...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int nu = 0; for (int i = 1; i <= 9; i++) { if (n % i == 0) nu = i; } if (n % nu == 0) { cout << n / nu << endl; for (int i = 0; i < n / nu; i++) { cout << nu << " "; } } else { cout << ((n / nu) + 1) << e...
0
#include <bits/stdc++.h> using namespace std; int t, n, a[50006][5]; int main() { for (scanf("%d", &t); t--;) { scanf("%d", &n); int m = n; for (int i = 0; i < n; i++) scanf("%d%d%d%d%d", a[i], a[i] + 1, a[i] + 2, a[i] + 3, a[i] + 4); vector<int> v; for (int i = 0; i < n; i++) v.push_back(i)...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; map<long long, long long> ind; long long n, c, arr[N], pref[N]; vector<long long> vals[N]; long long prevind[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> c; pref[0] = 0; for (long long ...
12
#include <bits/stdc++.h> using namespace std; const long long maxn = 1000008; int n, k, pp; long long A[maxn]; long long y[maxn]; long long inv[maxn]; long long w[maxn]; long long quickpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = 1ll * res * x % 1000000007; x = 1ll * x * x...
18
#include <bits/stdc++.h> using namespace std; int a[10001]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n - 1; i++) k -= a[i]; if (k < 0) cout << "NO"; else cout << "YES"; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a; vector<pair<long long int, long long int>> v; for (int i = 1; i <= n; i++) { cin >> a; v.push_back({a, i}); } sort(v.begin(), v.end()); ...
4
#include <bits/stdc++.h> using namespace std; inline int in() { int x; cin >> x; return x; } template <typename T> istream &operator>>(istream &in, vector<T> &vec) { for (int i = 0; i < vec.size(); ++i) in >> vec[i]; return in; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) { ...
3
#include <bits/stdc++.h> using namespace std; char a[1000005]; int p(char c) { if (c >= 'a' && c <= 'z') return 1; if (c >= 'A' && c <= 'Z') return 1; return 0; } int main() { scanf("%s", a); int n = strlen(a); long long m = 0; for (int i = 0; i < n; i++) { long long x = 0, y = 0; if (a[i] == '@')...
11
#include <bits/stdc++.h> int inp() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); } return sum; } int f[210][210][410]; char s[210], t[210]; int fi[210][210][410], fj[210][210][410], fu[210][210][41...
14
#include <bits/stdc++.h> using namespace std; int a[305]; long long dp[305][305], ncr[305][305], fact[305]; map<int, int> m; long long nCr(int n, int r) { if (r == n || r == 0) return 1; if (r == 1) return n; if (ncr[n][r] != -1) return ncr[n][r]; return (ncr[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)) % 100000...
17
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int w = 1, c = 0; for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) c = (c << 1) + (c << 3) + (ch ^ 48); return w * c; } const int M = 1e6 + 10; vector<int> c[M]; int s[M], ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); { string s; cin >> s; long long n = s.size(); vector<long long> v; for (long long i = 0; i < n; i++) { if (s[i] == 'r') cout << i + 1 << "\n"; else ...
4
#include <bits/stdc++.h> using namespace std; using LL = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); LL A, B, C; LL x1, y1, x2, y2; cin >> A >> B >> C >> x1 >> y1 >> x2 >> y2; if (A * B == 0 || x1 == x2 || y1 == y2) { cout << abs(x1 - x2) + abs(y1 - y2) << endl; return 0; } ...
11
#include <bits/stdc++.h> using namespace std; long long MOD = 1; long long power(long long x, long long n, long long mod) { if (n == 0) { return 0; } long long temp = power(x, n / 2, mod); if (n % 2 == 1) { return (x * temp * temp) % mod; } else { return (temp * temp) % mod; } } long long abs(lo...
7
#include <bits/stdc++.h> using namespace std; int n; vector<int> e[200005]; int u[400005], v[400005], w[400005]; int l[200005], r[200005], t; long long d0[200005], tmh[200005]; void dfs(int x, long long d) { l[x] = ++t; d0[x] = d; for (int eid : e[x]) { dfs(v[eid], d + w[eid]); } r[x] = t; } const int MAX...
13
#include <bits/stdc++.h> using namespace std; int l[100005], r[100005], col[100005], target[200005], pre[200005], last[100005], tot; void add(int x, int y) { target[++tot] = y; pre[tot] = last[x]; last[x] = tot; } void dfs(int x, int c) { col[x] = c; for (int i = last[x]; i; i = pre[i]) { int tar = ta...
24
#include <bits/stdc++.h> using namespace std; const int MM = 1e9 + 7; const int INF = INT_MAX; const long double PI = 3.1415926535897; const long double EPS = 1e-12; int n, c; long double x, y, z, res = -1e100; bool ls; string M[] = {"", "x^y^z", "x^z^y", "(x^y)^z", "(x^y)^z", "y^x^z", "y^z^x", ...
16
#include <bits/stdc++.h> using namespace std; int n; int main(int argc, char const *argv[]) { cin >> n; if (n <= 2) cout << "No"; else { cout << "Yes" << endl; cout << "2 1 " << n << endl; cout << n - 2 << " "; for (int i = 2; i <= n - 1; i++) cout << i << " "; } return 0; }
3
#include <bits/stdc++.h> int main() { int n, k; int i, j; scanf("%d %d", &n, &k); if (n < 3 * k || n < 6) printf("-1\n"); else { for (i = 0; i < n; i++) { if (i / k == 2) { if (i % k == 0) printf("%d ", k); else printf("%d ", i % k); } else print...
7
#include <bits/stdc++.h> using namespace std; long long n, k, q; long long la = 75, lb = 34, lc = 32, ld = 2; string a = " What are you doing at the end of the world? Are you busy? Will you save " "us?"; string b = " What are you doing while sending \""; string c = " \"? Are you busy? Will you send \""; string ...
9
#include <bits/stdc++.h> using namespace std; void solve(); signed main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); } void solve() { int n, q, m; cin >> n >> q >> m; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int cmd[q]; int l[q]; int r[q]; for (int i = 0; i < q; i++) { ...
10
#include <bits/stdc++.h> const int maxn = 200001, maxf = 19; const long long INF = 0x3f3f3f3f3f3f3f3fLL; int n, q, tot, lnk[maxn], dep[maxn], fa[maxn][maxf]; struct Edge { int v, nxt; } e[maxn << 1]; template <class T> void swap(T& x, T& y) { const T t = x; x = y; y = t; } template <class T> const T& min(const ...
24
#include <bits/stdc++.h> using namespace std; int maxx(int a, int b) { return a > b ? a : b; } int minn(int a, int b) { return a < b ? a : b; } long double abss(long double a) { return a < 0 ? (-a) : a; } const long double eps = 1e-7; void cmp(double, double, double, int); long double res[4]; int num[4]; char *exps[15]...
16
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 55; const int INF = 1e9 + 77; const long long INFINF = 1e18 * 2; const int MOD = 1e9 + 7; const double PI = acos(-1.0); vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; long long power(long long x, long long y) { if (y == 0) ...
4
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << "("; os << v.first << "," << v.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; long long sz = v.size...
7
#include <bits/stdc++.h> typedef double (*dfun)(double, double); using namespace std; const int N = 2e5 + 3; double delta[N]; double last; double avg; int n, cur = 1; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int type; scanf("%d", &type); switch (type) { case 1: double ad...
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:65536000") using namespace std; const long long mod = (int)1e9 + 7; const int MAX_SEG = 1048576; struct SegmentTree { vector<int> sum; vector<int> max_sum; SegmentTree() { sum.resize(MAX_SEG * 2 + 10); max_sum.resize(MAX_SEG * 2 + 10); } void up...
14
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int64_t a, b, x; cin >> a >> b; x = a % b; if (x == 0) { cout << "0\n"; } else { cout << (b - x) << '\n'; } } }
0
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; bool prime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; r...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; long long int a[27334]; a[0] = 2; for (long long int i = 1; i < 27334; i++) { a[i] = a[i - 1] + i + 2 * (i + 1); } while (t--) { long long int n; cin >> n; long long int count = 0; while (n >= a[0]) {...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; for (long long int i = 2; i <= 29; i++) { long long int rem = (pow(2, i) - 1); if (n % rem == 0)...
1
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int MAX = 5e3 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int c1 = 0, c2 = 0; for (int i = 0; i <= s.size() - 1; ++i) { if (s[i] == '-') c1++; else c2++; } if (!c1 || ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC optimize("no-stack-protector,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const long long N = 1e6 + 100, OO = 1e9 + 7, M = 1e9 + 7, P = 6151, T = 2e3, ...
20
#include <bits/stdc++.h> using namespace std; long long int cnt[1000009], revcnt[1000009]; long long int val[1000009], revval[1000009]; long long int nm[1000009], vec[1000009]; vector<long long int> ans, pp; bool vis[10000009]; int main() { long long int a, b, c, d, e, i, j, k, l, n, m, x, y, t, p, r, sz, cc, aa; l...
13
#include <bits/stdc++.h> using namespace std; const int NMAX = 1005; const int MMAX = 30005; const int INF = 2e9 + 15; int n, m, s, t; struct Edge { int a, b, w; bool tree = false; Edge(int _a = 0, int _b = 0, int _w = 0) : a(_a), b(_b), w(_w) {} inline int other(int node) { return (a ^ b ^ node); } } edges[MMA...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; int a[N], ax[N << 10], ay[N << 10]; int main() { for (int n; ~scanf("%d", &n);) { for (int i = 0; i < n; i++) scanf("%d", a + i); int p1, p2 = 0, p3 = 1, an = 0; for (int i = 2; i < n; i++) for (p1 = i;;) { if (a[p1] > a[p...
22
#include <bits/stdc++.h> using namespace std; template <class R> inline void Readin(R &K) { bool F = K = 0; char C = getchar(); while (C < '0' || C > '9') { if (C == '-') F = 1; C = getchar(); } while (C <= '9' && C >= '0') K = (K << 1) + (K << 3) + C - '0', C = getchar(); if (F) K = -K; } template ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n + 1]; for (long long i = 1; i <= n; i++) cin >> a[i]; long long dp[n + 1]; for (long long i = 1; i <= n; i++) dp[i] = a[i]; dp[0] = 0; for (long long i = 1; i <= n; i++) dp[i] += dp[i - 1]; long long t; c...
6
#include <bits/stdc++.h> using namespace std; void test() { int n, i; cin >> n; if (n == 2 || n == 3) cout << -1 << endl; else { if (n % 2 == 0) { for (i = n - 1; i >= 1; i -= 2) cout << i << " "; cout << "4 2 "; for (i = 6; i <= n; i += 2) cout << i << " "; cout << endl; } e...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long long MOD = 1e9 + 7; long long pow(long long a, long long n) { long long re = 1; for (; n; n /= 2, a = a * a % MOD) if (n & 1) re = re * a % MOD; return re; } int main() { long long n, k, ans = 1, a[9] = {0, 1, 2, 9, 64, 6...
7
#include <bits/stdc++.h> #pragma GCC optimize("-O3") using namespace std; int n, m, sx, sy, fx, fy, ide[100005]; long long dist[100005], ans; pair<int, int> x[100005], y[100005]; map<pair<int, int>, int> id; vector<pair<int, long long> > edge[100005]; set<pair<long long, int> > q; int main() { ios::sync_with_stdio(0)...
15
#include <bits/stdc++.h> using namespace std; int a, b, c, d; int main() { int i, j, s; while (~scanf("%d%d%d%d", &a, &b, &c, &d)) { s = 4; if (a == b || a == c || a == d) s--; if (b == c || b == d) s--; if (c == d) s--; printf("%d\n", 4 - s); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int M = 510; const int N = 65536 + 10; const long long mod = 1e9 + 7; int n; int m; char mde[M]; int ls[M]; int rs[M]; int trc[200]; int typ[M]; long long dp[300][N]; int val[10]; int ex; int L; int ct; long long sub1[N]; long long sub2[N]; inline void trs_or(long lon...
22
#include <bits/stdc++.h> using namespace std; long long n; long long sum = 0; int main() { cin >> n; cout << (n - 1) / 2 << "\n"; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int arr[6]; for (int i = 0; i < 6; i++) arr[i] = str.at(i) - 48; int s1 = arr[0] + arr[1] + arr[2]; int s2 = arr[3] + arr[4] + arr[5]; sort(arr, arr + 3); sort(arr + 3, arr + 6); if (s1 == s2) { cout << 0; exit(...
8
#include <bits/stdc++.h> using namespace std; long long common(pair<long long, long long> &a, pair<long long, long long> &b) { if (a.first == b.first || a.first == b.second) return a.first; if (a.second == b.first || a.second == b.second) return a.second; return 0; } int main() { ios_base::sync_with_stdio(false...
11
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3, s4, now; int n, num1 = 0, num2 = 0; scanf("%d", &n); cin >> s1; while (n--) { cin >> s2; s3 = s2.substr(0, 3); s4 = s2.substr(5, 3); s1 == s3 ? num1++ : num2++; } if (num1 == num2) printf("home\n"); else ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t, c = 0, d = 0, e = 0; cin >> t; int a[t]; for (int i = 0; i < t; i++) cin >> a[i]; if (t == 2) { c = a[0]; d = a[1]; } else if (t == 1) c = a[0]; else { for (int i = 0; i < t; i++) { ...
0
#include <bits/stdc++.h> using namespace std; int n, K, A[2005], dp[2005]; bool okok(int d) { for (int i = 1; i <= n; ++i) { dp[i] = i - 1; for (int j = i - 1; j; --j) if (abs(A[i] - A[j]) <= (long long)d * (i - j)) dp[i] = min(dp[i], dp[j] + i - j - 1); if (dp[i] + n - i <= K) return 1; }...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> k >> n; int ans = n; for (int i = 0; i < k; i++) { int x; cin >> x; if (n % x == 0) ans = min(ans, n / x); } cout << ans << "\n"; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(void) { long long int a, b, t; cin >> a >> b; t = a / b; cout << (t % 2 ? "YES" : "NO") << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; inline bool checkBit(long long n, int i) { return n & (1LL << i); } inline long long setBit(long long n, int i) { return n | (1LL << i); ; } inl...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; long long b[maxn], num[maxn << 2]; struct node { long long x, y; node(long long x = 0, long long y = 0) : x(x), y(y) {} bool operator<(const node& g) const { if (y != g.y) return y > g.y; return x < g.x; } } a[maxn]; void update(int...
12
#include <bits/stdc++.h> using namespace std; vector<unsigned int> v; map<unsigned int, int> mm; int mul[374][374]; int n, m, to[100005], wa[100005], wb[100005], val[100005], vis[100005], dp[2][374]; vector<pair<int, int>> vv[100005]; vector<int> tv; bool sp[100005]; void add(int& a, int b) { a += b; if (a >= 1...
22
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const int INF = 0x3f3f3f3f; const int MAXN = 233; int main() { int n; while (scanf("%d", &n) != EOF) { int a, b; if (n % 2) { b = 9; a = n + 9; } else { b = 4; a = n + 4; } ...
0
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n; if (n <= 5) { cout << -1 << '\n'; } else { for (int i = 2; i <= 4; i++) { cout << i - 1 << " " << i << '\n'; } for (int i = 5; i <= n; i++) { if (i % 2 == ...
7
#include <bits/stdc++.h> using namespace std; string fun(string &s, int i, int n) { int j = 0, k = i; string ans = ""; while (j < n) { if ((s[k] - s[i]) < 0) ans.push_back('0' + (s[k] - s[i] + 10)); else ans.push_back('0' + (s[k] - s[i])); k++; k = k % n; j++; } return ans; } i...
7
#include <bits/stdc++.h> const int MAXN = 20001; using namespace std; int fa[MAXN]; bool vis[MAXN]; pair<int, int> f_range[MAXN]; int node_idx; pair<int, int> calc_range(int num_nodes) { if (vis[num_nodes]) return f_range[num_nodes]; vis[num_nodes] = true; if (num_nodes == 0) return f_range[num_nodes] = make_pair...
14
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; inline long long rd() { register long long x = 0, w = 1; register char ch; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch =...
12
#include <bits/stdc++.h> using namespace std; int n, m, k, banyak, hasil = 0; bool visit[55][55]; char kotak[55][55]; string temp; vector<pair<int, pair<int, int> > > danau; bool valid(int aa, int bb) { return (aa >= 0 && aa <= n + 1 && bb >= 0 && bb <= m + 1); } void dfs(int x, int y, int jenis) { if (valid(x, y) ...
8
#include <bits/stdc++.h> using namespace std; int prefix_sum[100010]; int n, m; int busca(int i) { int ini = i; int fim = n; int j = 0; while (ini <= fim) { int meio = (ini + fim) / 2; if (prefix_sum[meio] - prefix_sum[i - 1] <= m) { j = meio - (i - 1); ini = meio + 1; } else { fim...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[100][4] = {0}; int k = 0; int count = 1; while (k < n && count <= m) { a[k][0] = count++; if (count <= m) { a[k][3] = count++; } k++; } k = 0; while (count <= m) { a[k][1] = count++; ...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const long long INF = 1e18; const int MX = 1000001; int N, K, P; vector<int> a[2]; int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> N >> K >> P; for (int i = (0); i < (N); ++i) { int cur; cin >> cur; a[cur % 2].push_back...
9
#include <bits/stdc++.h> using namespace std; int get(int bit, int n) { if (n > bit) return 0; else if (n == 0 || n == bit) return 1; else if (n == 1 || n == bit - 1) return bit; else { return get(bit - 1, n) + get(bit - 1, n - 1); } } int main() { string s1, s2; int pos1, pos2, q, t; po...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; int a[maxn], vis[maxn]; int main() { int i, j, k, n, l, ans; scanf("%d", &n); j = -1; for (i = 1; i <= n; i++) { scanf("%d", &a[i]); j = max(j, a[i]); } ans = 0; memset(vis, 0, sizeof(vis)); for (i = 1; i <= n; i++) { i...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; const ll INF = 1e18 + 1; ll bucket_size; struct Query { int idx, l, r; Query(int i, int left, int right) { idx = i; l = left; r = right; } bool operator<(const Query& other) const { return make_pair(l / bu...
10
#include <bits/stdc++.h> using namespace std; using namespace std; int a[1005][1005]; set<int> r[1005], c[1005]; map<int, int> rm[1005], cm[1005]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i{0}; i < n; i++) for (int j{0}; j < m; j++) scanf("%d", &a[i][j]); for (int i{0}; i < n; i++) { for (...
8
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e2 + 13; long long t, f[maxN], dp1[maxN], dp2[maxN]; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; f[1] = 1; f[2] = 2; for (long long i = 3; i <= 90; i++) { f[i] = f[i - 1] + f[i - 2]; } while ...
15
#include <bits/stdc++.h> using namespace std; long long n, k, h; int main() { cin >> n >> k; if (k >= n / 2) cout << "0 0 " << n; else if (k == (n / 2 - 1)) cout << 1 << " " << k << " " << n - (k + 1); else if (k < n / 2) { h = n / 2; if (h % (k + 1) != 0) { h -= h % (k + 1); } cou...
0
#include <bits/stdc++.h> using namespace std; int h, w, q, a, b, c, d, f[507][507]; string s[507]; bool in(int x, int y) { return (x >= 1 && x <= h && y >= 1 && y <= w); } int main() { cin >> h >> w; for (int i = 1; i <= h; i++) cin >> s[i], s[i] = "0" + s[i]; for (int i = 1; i <= h; i++) { for (int j = 1; j ...
7
#include <bits/stdc++.h> using namespace std; int main() { int puzzles, children; cin >> children >> puzzles; vector<int> gifts(puzzles); for (int i = 0; i < puzzles; i++) { cin >> gifts[i]; } sort(gifts.begin(), gifts.end()); vector<int> sums(puzzles - children + 1); for (int j = 0; j < puzzles - c...
1
#include <bits/stdc++.h> using namespace std; bool ok; char c; int n; int X[200000 + 5], SUM[200000 + 5], swp[200000 + 5], pos[200000 + 5]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> X[i]; pos[X[i]] = i; } for (int i = 1; i <= n - 1; i++) { cin >> c; swp[i] = (c == '1'); SU...
6
#include <bits/stdc++.h> using namespace std; function<void(void)> ____ = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }; using LL = int_fast64_t; const LL MOD = 998244353; LL n, m, L, R; LL qpow(LL a, LL b) { if (a == 0) return 0; LL ret = 1; while (b) { if (b & 1) ret = ret * a % ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, k, a, b; cin >> n >> a >> b >> k; a -= 1; b -= 1; long long** d = new long long*[k + 1]; for (int i = 0; i <= k; i++) { d[i] = new long long[n]; for (int j = 0; j < n; j++) d[i][j] = 0; } d[0][a] = ...
11
#include <bits/stdc++.h> const int maxn = 1e6; using namespace std; struct Point { int x, y, num; } p[maxn + 5]; int n; bool cmp(Point a, Point b) { if (a.x / 1000 != b.x / 1000) return a.x < b.x; else { if (a.x / 1000 & 1) return a.y > b.y; else return a.y < b.y; } } int main() { scan...
13
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } x *= f; } inline unsigned int R() { static unsigned in...
17
#include <bits/stdc++.h> using namespace std; const long long INF = 1ll << 32; int main() { long long t; cin >> t; int flag = 0; long long ans = 0; long long multi = 1; stack<long long> ss; ss.push(1); for (int i = 0; i < t; ++i) { string s; cin >> s; if (s.compare("add") == 0) { ans +...
8
#include <bits/stdc++.h> using namespace std; long long n; int cyfr[20], wyn = 100, pom, poma, pomb; int main() { ios_base::sync_with_stdio(0); cin >> n; if (n % 25 == 0) { cout << 0 << endl; return 0; } int k = 0; while (n > 0) { cyfr[k] = n % 10; n /= 10; k++; } poma = -1; pomb =...
13
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; using pii = pair<long long, long long>; map<pair<string, string>, long long> g; long long cal(string a, string b) { if (g.find({a, b}) != g.end()) return g[{a, b}]; if (a == b) return 1; long long n = a.length(); if (n % 2) return 0...
9
#include <bits/stdc++.h> using namespace std; int a, s, d, f, g, h, j, k, l, i, n, m; string x; vector<int> v; int main() { cin >> n >> m >> k; j = k; for (i = 0; i <= j / n + 1; i++) { if (k % m == 0 && k >= 0) { cout << "Yes"; return 0; } k -= n; } cout << "No"; }
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T, i, k, j; string a[1000], b[1000]; bool sudah[1000]; memset(sudah, false, 1000); cin >> T; for (i = 0; i < T; i++) { cin >> a[i] >> b[i]; } k = 0; for (i = 0; i < T - 1; i++) { ...
3
#include <bits/stdc++.h> using namespace std; const int lt = 100005; long long int mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int l; cin >> l; string s; cin >> s; if ((int)(s).size() % l != 0) { for (int i = 0; i < ((int)(s).size() / l +...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int c = 0, c1 = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '+') c++; else if (s[i] == '-') c--; if (c < 0) c = 0; } if (c < 0) cout << c << endl; else cout << c << e...
0