solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; bool misort(pair<int, int> p1, pair<int, int> p2) { return p1.first > p2.first; } int main() { long long int maxi[100500]; long long int maxi2[100500]; int quien1[100500]; int quien2[100500]; for (int i = 0; i < 100500; ++i) { maxi[i] = 0; maxi2[i] = 0; ...
9
#include <bits/stdc++.h> using namespace std; class Solution { public: int numOfShift(int n, int m) { vector<NumberOf> number(n); string s; int ans = 1000; for (int i = 0; i < n; ++i) { cin >> s; for (int j = 0; j < m; ++j) { int temp = min(j, m - j); number[i].data[type(s...
7
#include <bits/stdc++.h> int n, root[400010], L[5000010], R[5000010], sum[5000010], tot = 0; void insert(int &n, int N, int l, int r, int p) { n = ++tot; L[n] = L[N], R[n] = R[N], sum[n] = sum[N]; if (l == r) return sum[n]++, void(); int mid = (l + r) >> 1; if (p <= mid) insert(L[n], L[N], l, mid, p); e...
11
#include <bits/stdc++.h> const int mod = 1000000007; const int inf = 1000000009; const long long INF = 1000000000000000009; const long long big = 1000000000000000; const long double eps = 0.000000000000000000001; using namespace std; int d = 0; vector<int> P[100005]; vector<pair<int, int> > W; void dfs(int n, int t, in...
18
#include <bits/stdc++.h> using namespace std; int main() { ifstream in("input.txt"); ofstream out("output.txt"); int n, k, t[100], a; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &t[i]); if (t[1] > 15) { printf("%d\n", 15); return 0; } for (int i = 2; i <= 75; i++) { if (t[i] - ...
0
#include <bits/stdc++.h> using namespace std; int a, b; int ans; void init() { cin >> a >> b; } int main() { init(); ans = 0; while (a <= b) { ans++; a *= 3; b *= 2; } cout << ans; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const double EPS = (long double)1e-7; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int x = (0); x < (int)((1 << n)); ++x) { for (int y = (0); y < (int)((1 << n)); ++y) { cout << ((__builtin_popc...
10
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); int n, k, t, pre = 0, buf = INT_MAX, bef = 0; cin >> n >> k; bool flag = false, fz = false; for (int i = 0; i < n; i++) { cin >> t; if (fz) { fz = false; buf = t; } if (k ==...
1
#include <bits/stdc++.h> using namespace std; const int N = 100 + 10, K = 1000; int a[N], n, k, choose[N][N], tedad; double dp[K + 10][N][N], ans, p_one; double ehtemal(int i, int l, int r, int tedad) { return ((double)(1.0 * tedad * p_one * dp[i][l][r])); } void fillchoose() { for (int i = 0; i < N; i++) choose[i]...
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long gcd(long long a, long long b) { while (a && b) a > b ? a %= b : b %= a; return a + b; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cin.exceptions(cin.failbit); long long x, a, b; cin >> x; ...
6
#include <bits/stdc++.h> std::set<std::pair<int, int> > set; int head[3010], nxt[6010], b[6010], k, n, u, v, fa[3010], cnt, rt; bool vis[3010]; long double ans; void push(int s, int t) { nxt[++k] = head[s]; head[s] = k; b[k] = t; } void getloop(int x, int f) { if (vis[x]) { u = x, v = f; return; } v...
22
#include <bits/stdc++.h> using namespace std; int N, S[1508], mom[1508], num[1508]; vector<int> con[1508], arr; queue<int> que; struct Z { int y, x, n; double ang; bool operator<(const Z &b) const { return ang < b.ang; } } A[1508]; void dfs(int n, int a, int b) { int i, k, p = a; for (i = a + 1; i <= b; i++) ...
14
#include <bits/stdc++.h> using namespace std; const int N = 2100; const int mod = 998244353; long long p[N * (N + 1)], _p[N * (N + 1)], ni_p[N * (N + 1)]; int n, a, b; long long f[N][N], s[N][N], g[N][N], w[N], E[N]; long long help[N]; long long add(long long x, long long y) { return (x + y) % mod; } long long mul(long...
20
#include <bits/stdc++.h> using namespace std; long long n, a[100005], t; char c[100005]; bool f[100005]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> c[i]; for (int i = 0; i < n; i++) { cin >> a[i]; c[i] == '>' ? a[i] = a[i] : a[i] = -a[i]; } while (1) { if (a[t] > n || a[t] < -n) { ...
2
#include <bits/stdc++.h> using namespace std; const long long int Max = 1e13; const long long int SIZE = 1e5 + 100; const long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long int t; cin >> t; while (t--) { long long int n, k, one = 0; cin >> n >> k; ...
7
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238; bool DBG = false; template <typename T, typename S> std::ostream& operator<<(std::ostream& os, const std::pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> std::ostream& operator<...
11
#include <bits/stdc++.h> using namespace std; int main() { char c; string a, b; long long n = 0, i, j; cin >> c; cin >> a >> b; if (a[1] == c && b[1] != c) n = 5; else if (a[1] == b[1]) { if (a[0] == 'T') i = 10; else if (a[0] == 'J') i = 11; else if (a[0] == 'Q') i = 12;...
2
#include <bits/stdc++.h> using namespace std; const int mm = 1009; char s[][13] = {"S", "M", "L", "XL", "XXL"}; int f[11]; int main() { int k; for (int i = 0; i < 5; i++) cin >> f[i]; cin >> k; char z[13]; int x; for (int i = 0; i < k; i++) { cin >> z; for (int j = 0; j < 5; j++) if (strcmp(z,...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; vector<string> v = {"Anka", "Chapay", "Cleo", "Troll", "Dracul", "Snowy", "Hexadecimal"}; map<string, long long> mp; bool like[10][10]; long long gett(vector<long long> &perm, long long a, long long b) { long ...
6
#include <bits/stdc++.h> int n, k; int v[101101]; int ans[101101], la = 0; int main() { scanf("%d%d", &n, &k); long long int sum = 0LL; for (int i = 0; i < n; i++) { scanf("%d", &v[i]); sum += v[i]; } if (sum % k != 0) { puts("No"); return false; } int s = 0, cnt = 0, todo = sum / k; for...
3
#include "bits/stdc++.h" #define ll long long using namespace std; void solve() { int n, k; cin >> n >> k; vector<vector<int>> a(n, vector<int>(2)); bool sw = 1; for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; for(int i = 0; i < n; i++) { bool flag = 0; for (int ...
2
#include <bits/stdc++.h> using namespace std; int a, b; int main() { scanf("%d %d", &a, &b); for (int x = 0; x <= 1000; x++) { for (int y = 0; y <= 1000; y++) if (x && y && x * x + y * y == a * a) { for (int i = 1; i <= 1000; i++) if (!(i * x % y)) { int j = -i * x / y; ...
8
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, long long> > g[2], f[4]; long long ask(int x, int y, int z, int zz) { printf("%d %d %d %d\n", x, y, z, zz); long long v; fflush(stdout); scanf("%lld", &v); return v; } bool cmp(pair<int, long long> a, pair<int, long long> b) { return a.se...
15
#include <bits/stdc++.h> using namespace std; using ll = long long; inline ll read(); const int M = 500016, MOD = 1000000007; struct BinaryIndexTree { ll bit[M], n; inline void modify(ll p, ll x) { for (; p <= n; p += p & -p) bit[p] += x; } inline ll sum(ll p) { ll res = 0; for (; p; p -= p & -p) re...
11
#include <bits/stdc++.h> using namespace std; const int N = 1000; vector<pair<int, int>> edge[N]; int rt; int w[N], fa[N], dep[N], leaf[N]; vector<tuple<int, int, int>> sol; void add(int u, int v, int x) { sol.push_back({u + 1, v + 1, -x}); while (u != v) { if (dep[u] > dep[v]) { w[u] += x; u = fa[u...
8
#include <bits/stdc++.h> using namespace std; void Fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); } inline int D() { int t; scanf("%d", &t); return t; } inline long long llD() { long long t; scanf("%lld", &t); return t; } long long MOD = 1e9 + 7; const int...
11
#include <bits/stdc++.h> using namespace std; int mx = 0; char a[5], b[5]; int aint[5], bint[5]; bool iscarry(int i) { if (i == 4) return false; if (aint[i] + bint[i] >= mx) return true; else if (aint[i] + bint[i] < mx - 1) return false; else return iscarry(i + 1); } int main() { cin >> a >> b; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long int power(long long int x, long long int y) { long long int temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } long long int GCD(long long int A, long lon...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int power(int x, int p) { if (p == 0) return 1; if (p % 2) return (x * 1LL * power(x, p - 1)) % MOD; int y = power(x, p / 2) % MOD; return (y * 1LL * y) % MOD; } const int LOG_A = 20; const int N = 1e5; int basis[N][LOG_A]; int sz[N]; int to...
16
#include <bits/stdc++.h> using namespace std; template <int mod> struct modulo { int w; template <typename type> operator type() const { return static_cast<type>(w); } modulo() {} modulo(int w) { this->w = w; fix(); } void inline fix() { if (w >= mod || w < -mod) w %= mod; if (w < 0)...
20
#include <bits/stdc++.h> using namespace std; const int MAXN = 222222; vector<int> G[MAXN]; bool isLeaf[MAXN]; bool isFirst[MAXN]; int valueRank[MAXN]; int n, m; int dfs(int fa, int u, int step) { isFirst[u] = !(step & 1); if (G[u].size() == 0) { valueRank[u] = 1; } else { valueRank[u] = isFirst[u] ? INT_...
14
#include <bits/stdc++.h> using namespace std; char a_z[30]; void init() { char a = 'a'; for (int i = 0; i < 26; i++) { a_z[i] = a + i; } } void change(char a, char b) { for (int i = 0; i < 26; i++) { if (a_z[i] == a) { a_z[i] = b; } else if (a_z[i] == b) { a_z[i] = a; } } } int mai...
4
#include <bits/stdc++.h> using namespace std; const int inft = 1000000009; const int MAXN = 1000006; void solve() {} pair<int, int> P[MAXN]; int E[MAXN]; int main() { int n; scanf("%d", &n); for (int i = 0; i < (n); ++i) scanf("%d%d", &P[i].first, &P[i].second); sort(P, P + n); int t = 0; E[t++] = -(1 << 30...
10
#include <bits/stdc++.h> char NotPrime[1001]; int Prime[1001]; int PrimeCnt; int PrimeExp[1001]; int Ans[1001]; int Size; void Sieve() { int i, j; for (i = 2; i < 1001; ++i) { if (!NotPrime[i]) { Prime[PrimeCnt++] = i; for (j = i + i; j < 1001; j += i) { NotPrime[j] = 1; } } } } ...
7
#include <bits/stdc++.h> int xabs[1000100]; int nx[2020]; std::vector<std::pair<int, std::pair<int, int>>> evt; std::set<std::pair<int, int>, std::greater<std::pair<int, int>>> bst; std::vector<std::pair<int, int>> rb; std::vector<std::pair<int, int>> st; std::vector<int> pi; int main(void) { int n, m; scanf("%d %d...
12
#include <bits/stdc++.h> using namespace std; bool ok[3005]; bool check(char x) { return x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'; } int main() { string s; cin >> s; int n = s.length(); for (int i = 0; i <= n - 3; i++) { if (!check(s[i]) && !check(s[i + 1]) && !check(s[i + 2]) && !...
7
#include <bits/stdc++.h> using namespace std; struct Node { unordered_set<int> adj; int cnt; }; int n; vector<Node> graph; struct Change { int fromX; int fromY; int toY; }; vector<Change> changes; int calcCnt(int v, int parent) { int cnt = 1; for (auto next : graph[v].adj) if (next != parent) cnt += c...
18
#include <bits/stdc++.h> using namespace std; vector<int> d[10000]; int mark[10000]; int c = 0; void dfs(int x) { if (mark[x] == 2) return; if (mark[x] == 1) { c = 1; return; } mark[x] = 1; for (int i = 0; i < d[x].size(); i++) { dfs(d[x][i]); } mark[x] = 2; } int32_t main() { ios_base::sync...
13
#include <bits/stdc++.h> int x, y, u, v, d, a, b; int main() { scanf("%d%d", &a, &b); d = 1; while (a) { switch (b % 4) { case 0: u = y, v = x; break; case 1: u = x, v = y + d; break; case 2: u = x + d, v = y + d; break; case 3: u...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; const int MOD = 1000000007; int s[MAXN][MAXN]; int fac[MAXN]; int cnn[MAXN * 2][MAXN]; int ckn[MAXN * 2]; int inv[MAXN * 2]; int PowerMod(int a, int n) { int c = 1, d = a; while (n) { if (n & 1) c = (1LL * c * d) % MOD; d = (1LL * d * d) %...
15
#include<iostream> #include<stdio.h> #include<string> #include<string.h> #include<map> #include<set> #include<unordered_map> #include<unordered_set> #include<queue> #include<stack> #include<deque> #include<utility> #include<vector> #include<algorithm> #include<cmath> #include<iomanip> #define fi first #define se second...
2
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int resx, resy; int n, m, dx, ...
12
#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}; long long int n, m; int main() { int a, b, c; cin >> a >> b >> c; vector<int> v(a); for (int i = 0; i < a; ++i) cin >> v[i]; if (c >= b) { puts("0"); return 0; } sort(v.rbe...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m; char s[N]; struct node { int sum, pmx, lmx, mn, mx, d; node(int sum = 0, int pmx = 0, int lmx = 0, int mn = 0, int mx = 0, int d = 0) : sum(sum), pmx(pmx), lmx(lmx), mn(mn), mx(mx), d(d) {} } t[4 * N]; void update(int k) { t[k].s...
19
#include <bits/stdc++.h> using namespace std; long long n, m, a, b, ra[5003], md[5003], tp; int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) md[i] = 1e9; for (int i = 0; i < m; ++i) { cin >> a >> b; if (b >= a) { md[a] = min(md[a], b - a); } else { md[a] = min(md[a], n - a + b); ...
9
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "URDL"; const long long MOD2 = (long lon...
13
#include <bits/stdc++.h> using namespace std; const int OO = (int)1e6; const double EPS = (1e-7); vector<vector<int> > v; vector<int> vis; bool valid(int r, int c, int n, int m) { return (r >= 0 && r < n && c >= 0 && c < m); } int dx[] = {1, 0, -1, 0, -1, 1, -1, 1}; int dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; int main() ...
9
#include <bits/stdc++.h> using namespace std; void solve() {} const long long maxn = 300500; long long n; long long a[2][maxn]; long long pref[2][maxn], suf[2][maxn]; long long psa[2][maxn]; long long f(long long i, long long j, long long time) { if (j == n + 1) { return 0; } long long val = f(i ^ 1, j + 1, t...
10
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int N = 23; int adj[N]; int dp[1 << N]; pair<int, int> pp[1 << N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; ...
16
#include <bits/stdc++.h> int main() { int n, s; long pa = 0, pb = 0; std::cin >> n; std::vector<int> middleOnes; for (int i = 0; i < n; i++) { std::cin >> s; if (s % 2 == 0) { for (int j = 0; j < s; j++) { int x; std::cin >> x; if (j < s / 2) pa += x; el...
12
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } const long long MAXVAL = 10004205361450475LL; const int MAXK = 10000; const int MAXQ = 5; long long cnt[MAXQ + 1][MAXK + 1]; long long cur[MAXK]; void solve(int i, int j, long long lo) { cur[0] = cnt[i - 1][j] +...
22
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, 0, 0, -1}; int dy[] = {0, 0, 1, -1, 0}; const long long mod = 1000000000 + 7; int main() { int n, m; scanf("%d", &n); scanf("%d", &m); vector<string> words(n); for (int i = 0; i < n; i++) cin >> words[i]; int ans = 1; for (int j = 0; j < m; j...
6
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int M = 1e3 + 10; const int mod = 1e9 + 7; long long a[M], sum[M], f[M]; int k; long long mul(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return ...
7
#include <bits/stdc++.h> using namespace std; map<vector<int>, int> ma; int n; int ask(int x1, int y1, int x2, int y2) { if (x1 > n || x2 > n || y1 > n || y2 > n) return 0; int ans; if (ma.find({x1, y1, x2, y2}) == ma.end()) { cout << "? " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl; cin >> ans; ...
14
#include <bits/stdc++.h> using namespace std; int leap[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int nonleap[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int XX, YY, ZZ; bool func(int x, int y, int z) { if (y > 12 || y == 0) return false; if (z % 4 == 0) { if (x == 0 || x > leap[y - 1])...
9
#include <bits/stdc++.h> using namespace std; long long n, m, d; long long c[1111]; long long sum = 0; long long res[1111]; int main() { cin >> n >> m >> d; for (int i = 0; i < n; i++) { cin >> c[i]; sum += c[i]; } long long curPos = 0; long long curPlatform = -1; long long lastPlatform = -1; long...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; long long m, sum = 0, sum2 = 0; cin >> n >> m; long long a[n]; for (int i = 0; i < n; i++) { long long x, b; cin >> x >> b; a[i] = x - b; sum = sum + b; sum2 = sum2 + x; } if (sum > m) cout << "-1" << endl; else { ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, p = 0, q = 0; cin >> n; int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int i = 0; for (i = 0; i < n; i++) { if (a[i] ...
4
#include <bits/stdc++.h> using namespace std; int n, m; int tot, num; int head[100005], dep[100005], fa[100005], sz[100005], son[100005], top[100005], id[100005]; struct Edge { int to, next; } edge[2 * 100005]; struct E { int x, y; } e[100005]; void add_edge(int u, int v) { edge[tot].to = v; edge[tot].next ...
11
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int dis[][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; const int MOD = 1e9 + 7; const int N = 1e5 + 10; int main() { int T; cin >> T; while (T--) { int n; cin >> n; in...
10
#include <bits/stdc++.h> using namespace std; int n; int gr[505][505]; char s[505]; bool mark[505]; bool dfs(int i, char c) { if (mark[i]) return s[i] == c; mark[i] = true; s[i] = c; char hlp = 'c' - c + 'a'; for (int j = 1; j <= n; j++) { if (j == i) continue; if (!gr[i][j]) { if (!dfs(j, hlp))...
10
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383279; const long double EPS = 1e-8; const int NONE = 1e9 + 7; const long long MOD = 1e9 + 7; const int LOG = 20; const int BIAS = 50000; const long long maxn = 100002; const long long HASH_MODS[] = {1000000007333ll, 1000000...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
11
#include <bits/stdc++.h> using namespace std; const int64_t INF = 1e17; inline int64_t mul(int64_t a, int64_t b) { return (INF / a > b ? a * b : INF); } inline int64_t add(int64_t a, int64_t b) { return (a + b >= INF ? INF : a + b); } int main() { int n; cin >> n; vector<int> a(n); for (int &x : a) cin >> x; ...
7
#include <bits/stdc++.h> int main() { int n, ct = 0, a[305], i, ans[305] = {0}; scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%d", &a[i]); if (a[i] == 0) ++ct; } while (ct != n) { for (i = 0; i < n - 1; ++i) { if (ans[i] < a[i]) { printf("P"); ++ans[i]; if (ans[i]...
4
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int N = 100010; const int M = 320; struct Block { int l, r; }; Block B[M]; vector<int> prepos[N]; int arr[N], pre[N], ori[N], belong[N]; int unit, bcnt; void reset(int bx) { sort(pre + B[bx].l, pre + B[bx].r + 1); } void init(int n) { ...
14
#include <bits/stdc++.h> using namespace std; int a[1010], b[1010], dp[1010]; struct ro { int w, b; vector<int> t; } c[1010]; int father[1010]; int find(int x) { if (father[x] == x) return x; return father[x] = find(father[x]); } void Union(int x, int y) { x = find(x); y = find(y); if (x > y) father[x] = ...
8
#include <bits/stdc++.h> using namespace std; vector<int> phi; vector<int> spf; void banao(int n) { phi.resize(n + 1); for (int i = 0; i < n + 1; i++) phi[i] = i; for (int k = 2; k < n + 1; k++) { if (phi[k] == k) { phi[k] = k - 1; for (int i = 2 * k; i <= n; i += k) { phi[i] = (phi[i] / k...
9
#include <bits/stdc++.h> using namespace std; int ct[301]; int ct2[301]; bool comp(int i, int j) { return i > j; } int main() { int n, a, b, k, f, i, x; cin >> n >> a >> b >> k >> f; string s1, s2; map<string, int> m; for (i = 0; i < n; ++i) { cin >> s1 >> s2; if (m.find(s1) == m.end()) { x = m....
10
#include <bits/stdc++.h> using namespace std; char a[1510][1510]; int f[1510][1510], n, m; pair<int, int> vis[1510][1510]; int dd[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int bfs(int si, int sj) { f[si][sj] = 1; vis[si][sj] = make_pair(si, sj); queue<pair<int, int> > qu; pair<int, int> t, tt; qu.push(make_...
12
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f; long long dict[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; long long n; long long ans; void dfs(long long k, long long sum, long long cnt) { if (cnt > n) return; if (cnt == n) { ans = min(ans, sum); } long ...
12
#include <bits/stdc++.h> using namespace std; int N; map<int, int> c; const int maxn = 200010; struct node { int val, val2, pos; bool operator<(const node &a) const { return val2 < a.val2; } } a[maxn]; int main() { cin >> N; for (int i = 1; i <= N; i++) { scanf("%d", &a[i].val); a[i].val2 = a[i].val - N...
14
#include <bits/stdc++.h> using namespace std; long long x[100005], n, y[100005]; bool be[100005]; bool rect(long long i, long long j, long long k) { long long x1 = x[i] - x[j], x2 = x[i] - x[k], y1 = y[i] - y[j], y2 = y[i] - y[k]; return (x1 * y2 - x2 * y1) == 0; } bool nice(long long a, long long b) { ...
12
#include <bits/stdc++.h> using namespace std; void debug(vector<int> v) { cout << "DEBUG " << endl; for (auto k = v.begin(); k != v.end(); k++) cout << *k << " "; cout << endl; } long long int P1[1002][1002], P2[1002][1002], grid[1002][1002], PS1[1002][1002], PS2[1002][1002]; int n, m; long long int val_for(i...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int r, c; scanf("%d %d", &r, &c); for (int i = 1; i <= r / 2; ++i) { for (int j = 1; j <= c; ++j) { printf("%d %d\n", i, j); printf("%d %d\n", r + 1 - i, c + 1 - j); ...
10
#include <bits/stdc++.h> using namespace std; int x, y, z, t1, t2, t3; int s, e; int main() { cin >> x >> y >> z >> t1 >> t2 >> t3; s = abs(x - y) * t1; e = (3 * t3) + (abs(x - y) * t2) + (abs(z - x) * t2); if (e <= s) return cout << "Yes" << endl, 0; return cout << "No" << endl, 0; }
0
#include <bits/stdc++.h> int a[10]; int sm() { int gg = 0; for (int i = 1; i <= 9; i++) gg += a[i] * i; return gg; } int main() { int n, bf; scanf("%i", &n); for (int i = 1; i <= n; i++) { scanf("%i", &bf); a[bf]++; } if (a[0] == 0) { printf("-1"); exit(0); } int i, gg = 0, flg = 1; ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; const long long inf = 0x3f3f3f3f; const long long mod = 998244353; long long fac[maxn]; long long fp(long long a, long long n) { long long ans = 1; while (n) { if (n & 1) ans = ans * a % mod; n >>= 1; a = a * a % mod; } return a...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[100000]; for (int i = 0; i < n; i++) cin >> a[i]; int b[100000]; for (int i = 0; i < n; i++) cin >> b[i]; int r[100000], l[100000]; int min = 0; int tmp = 0; for (int i = 1; i < n; i++) { tmp -= b[i - 1]; if (t...
12
#include <bits/stdc++.h> #pragma comment(linker, "/stack:16777216") namespace Template { using namespace std; struct debugger { template <typename T> debugger &operator,(const T &v) { cerr << v << " "; return *this; } } dbg; template <typename T> void sci(T &t) { cin >> t; } template <typename T, typena...
12
#include <bits/stdc++.h> using namespace std; bool isPrime = true; bool prime(int p) { if (p == 0 || p == 1) { return false; } else { for (int i = 2; i <= p / 2; ++i) { if (p % i == 0) { return false; break; } } } return true; } int main() { int n; cin >> n; for (in...
0
#include <bits/stdc++.h> using namespace std; inline long long rd() { long long _x = 0; int _ch = getchar(), _f = 1; for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar()) ; if (_ch == '-') { _f = 0; _ch = getchar(); } for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0...
20
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int N, ans = 0, arr[100099]; cin >> N; for (int A = 1; A <= N; A++) cin >> arr[A]; sort(arr, arr + N + 1); for (int B = 1; B <= N; B++) { if (arr[B] > ans) ans++; } cout << ans + 1; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int t; long long ans, n, l, r; string s; cin >> t; while (t--) { cin >> s; n = s.size(); ans = l = r = 0; for (int i = 0; i < n; i++) { if (s[i] == '-') r > 0 ? r-- : l++; else r++, l = 0; if (r < l) a...
5
#include <bits/stdc++.h> std::string s; int l; std::string work(int opt, std::string s) { int tl = l, last_carry = 0, need_carry = opt; if (opt == 1) tl--; std::string ret(tl, '0'); for (int i = 0; i <= tl - i - 1; i++) { bool conc = false; if (!last_carry && need_carry && s[i] == '9' && s[tl - i - 1] =...
16
#include <bits/stdc++.h> const long long inf = 0x3f3f3f3f3f3f3f3LL; const long long mod = 1e9 + 7; using namespace std; template <class T> void smin(T& a, T val) { if (a > val) a = val; } template <class T> void smax(T& a, T val) { if (a < val) a = val; } template <typename T> inline std::ostream& operator<<(std::o...
12
#include <bits/stdc++.h> using namespace std; const int N = 1100; const int M = 2000000; const long long mod = 1e9 + 7; int n, m; long long a[N]; long long solve(string p) { long long ans = 0, b = 1; for (int i = (int)p.length() - 1; i >= 0; i--) { if (i != (int)p.length() - 1) b *= (long long)2; if (p[i] =...
13
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, x, y; long long findnot(long long result) { if (result == 0) return 1; for (int i = 0; i * i <= result; i++) { if (i * (i + 1) == result) { return i + 1; } } return -1; } int main() { cin >> a >> b >> c >> d; a *= 2; d *= 2;...
11
#include <bits/stdc++.h> using namespace std; constexpr static int MAXN = 3000 + 10; constexpr static int MOD = 998244353; int64_t cnt[MAXN][MAXN]; void add_mod(int64_t& x, int64_t y) { x += y; if (x >= MOD) x -= MOD; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, t; cin >> s >> t...
14
#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; } namespace fastIO { const unsigned int BUFFER_SIZE = (unsigned int)1 << 15; char buffer[BUFFER_SIZE], *cur, *ed; inlin...
23
#include <bits/stdc++.h> using namespace std; long long n, s[200005], cnt, k, sum; int main() { cin >> n >> k; if (n < (k * (k + 1) / 2) || (k == 2 && n == 4) || (k == 3 && n == 8)) return cout << "NO", 0; cout << "YES" << endl; sum = (n - k * (k + 1) / 2) / k; for (int i = 1; i <= k; i++) s[i] += sum + i...
11
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, a, b, c; cin >> n >> k; a = n / (2 * (k + 1)); b = k * a; c = n - (a + b); cout << a << " " << b << " " << c << endl; return 0; }
0
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); printf("%d", (n - 1) / 2); return 0; }
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int N = 2e5 + 10; const int M = 1e7 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const int INF = 2e9; int n; char a[N], b[N], c[N]; int main() { int t; scanf("%d", &t); while (t--) { scanf("%s%s%s", a + 1, b + 1, c + 1)...
0
#include <bits/stdc++.h> using namespace std; int f[1 << 23]; bool vis[1 << 23]; int n; long long a[30]; vector<pair<int, int> > p[25]; inline int bits(int x) { int ans = 0; while (x) { if (x & 1) ans++; x /= 2; } return ans; } int main() { while (cin >> n) { for (int i = 0; i < n; ++i) cin >> a[i...
14
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:100000000") int matrix[101][101][101]; int vis[101][101][101]; int dx[3] = {1, 0, 0}; int dy[3] = {0, 1, 0}; int dz[3] = {0, 0, 1}; int itt = 0; int wx, wy, wz, mx, my, mz; int go(int x, int y, int z) { if (vis[x][y][z] == itt) return 0; ...
10
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long m) { a %= m; long long ret = 1; while (b) { if (b & 1) ret = ((ret % m) * (a % m)) % m; a = ((a % m) * (a % m)) % m; b >>= 1; } return ret; } long long cache = 2; int main() { ios_base::sync_with_st...
9
#include <bits/stdc++.h> using namespace std; long long int pw(long long int n, long long int m) { long long int sum = 1; for (long long int i = 1; i <= m; i++) { sum *= n; } return sum; } int main() { long long int T, n, i, j, cunt, temp, m, dis, sum, sz, mx, mn; cin >> n; temp = n * 3; if (temp % ...
2
#include <bits/stdc++.h> using namespace std; const long long maxn = 71; long long n, m, k; long long grid[maxn][maxn], best[maxn][maxn]; void the_best(long long *g, long long *res) { long long m2 = m / 2; long long d[m + 1][m2 + 1][k]; fill(d[0][0], d[m][m2] + k, INT_MIN); d[0][0][0] = 0; for (long long i = ...
13
#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}; void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } long long pw(long long a, long long p) { if (p == 1) return a; if (p == 0) return 1; long long ret =...
5