solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int c = 0; for (int i = 1; i < n - 1; i++) { if (a[i - 1] < a[i] && a[i] > a[i + 1]) c++; else if (a[i - 1] > a[i] && a[i] < a[i + 1]) c++; } cout ...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; pair<int, int> a[MAX]; int main() { int n, d; cin >> n >> d; int A, B, x, y; cin >> A >> B; for (int i = 0; i < n; ++i) { cin >> x >> y; a[i].first = x * A + y * B; a[i].second = i + 1; } sort(a, a + n); int i = 0; whil...
6
#include <bits/stdc++.h> using namespace std; int a[200005]; bool mark[200005]; int x; vector<int> gr[200005]; int dfs(int p, int u) { int i, fl = 0; mark[u] = 1; if (u == a[u]) x = u; for (i = 0; i < gr[u].size(); i++) { int v = gr[u][i]; if (mark[v] == 1 && v != p) fl = v; else if (mark[v] =...
9
#include <bits/stdc++.h> using namespace std; typedef struct { int sum, suf, pre, max; } Node; int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; } const int N = 1e4 + 10; const int inf = 1e9; const int lim = 1e18 + 1; const int mod = 1e9 + 7; const double pi = 3.14159265358979...
10
#include <bits/stdc++.h> using namespace std; int arr[401][401]; int pfx[401][401]; int dp[401][401][401]; int ptl(int y2, int x2, int y1, int x1) { int a1 = pfx[y2][x2] - pfx[y2][x1 - 1] - pfx[y1 - 1][x2] + pfx[y1 - 1][x1 - 1]; int a0 = (y2 - y1 + 1) * (x2 - x1 + 1) - a1; int b1 = pfx[y2 - 1][x2 - 1]...
9
#include <bits/stdc++.h> using namespace std; int tellCount(int n, int s, int k, int kval[]) { int x = 0, present = 0; int step1 = 0, step2 = 0; sort(kval, kval + k); for (x = 0; x < k; x++) { if (kval[x] == s) { present = 1; break; } } if (present == 1) { for (int a = x; a < k - 1; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char stuff[n + 1]; char calvin[n + 1]; cin >> stuff >> calvin; long long less = 1; long long more = 1; long long total = 1; long long equal = 1; for (int i = 0; i < n; i++) { if (stuff[i] == '?' && calvin[i] == '?') { ...
12
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000; long long ans(0); void dfs(long long l1, long long r1, long long l2, long long r2) { if (l1 > r1 || l2 > r2) return; if (ans > min(r1 - l1, r2 - l2)) return; if (l1 > l2) { swap(l1, l2); swap(r1, r2); } if (r2 <= r1) { ...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; vector<long long> grafo[MAXN]; long long v[MAXN]; bool process[MAXN]; long long pot[30]; struct str { long long first, second, tot = 0; }; str dfs(long long x, long long k) { process[x] = true; long long val = v[x] & pot[k]; str resp; resp...
13
#include <bits/stdc++.h> using namespace std; const int N = 100010; vector<int> v[N]; void prime() { for (int i = 2; i < N; i++) { if (v[i].size()) continue; for (int j = i; j < N; j += i) v[j].push_back(i); } } long long cal(long long x) { return x * (x + 1) / 2; } int main() { prime(); long long n, m,...
17
#include <bits/stdc++.h> int main() { int n, i; long long int b; long long int aux = 0; long long int aux2 = 0; scanf("%d %lld", &n, &b); long long int vetor[n]; long long int min = 1e9 + 1; for (i = 0; i < n; i++) { scanf("%lld", &vetor[i]); if (vetor[i] < min) { min = vetor[i]; } }...
1
#include <bits/stdc++.h> using namespace std; int main() { long long a[3]; cin >> a[0] >> a[1] >> a[2]; cout << "First" << endl; cout << max(a[0], max(a[1], a[2])) - min(a[0], min(a[1], a[2])) << endl; int mov; cin >> mov; mov--; a[mov] += max(a[0], max(a[1], a[2])) - min(a[0], min(a[1], a[2])); long ...
18
#include <bits/stdc++.h> int main() { short int q; scanf("%hi", &q); while (q--) { short int n; scanf("%hi", &n); short int Cnt[2049] = {0}; for (short int i = 0; i < n; i++) { int a; scanf("%i", &a); if (a < 2049) Cnt[a]++; } for (short int i = 1; i < 1025; i *= 2) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int one = 0; int n = s.length(); for (int i = 0, _i = (n); i < _i; ++i) { if (s[i] == '1') { for (int j = (i), _j = (n); j < _j; ++j) { if (s[j] == '0') one++; ...
2
#include <bits/stdc++.h> using namespace std; long long pwr(long long base, long long p, long long mod = (1000000007LL)) { long long ans = 1; while (p) { if (p & 1) ans = (ans * base) % mod; base = (base * base) % mod; p /= 2; } return ans; } long long gcd(long long a, long long b) { if (b == 0) r...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; const int M = 600; const long long base = 1e18; const int mod = 999983; const int inf = 1e9 + 7; const double pi = acos(-1); const int maxn = N * 2; const double PI = acos(-1); const double ep = 1e-9; int n; pair<int, int> dp[N][2]; int pa[N]; int cnt...
18
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; int right = 0; int left = 0; for (int i = 0; i < n; i++) { if (s[i] == 'R') { right++; } else { left++; } } cout << left + right + 1 << e...
0
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; struct dp_t { int res0, res1; }; dp_t solve(int v, const vector<vector<int>> &children) { int nc = children[v].size(); if (nc == 0) { return {1, 1}; } else { vector<dp_t> ress; for (int c : children[v]) ress.push_back(solve(c, ...
17
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 14; int n; long long t, a[maxn], x[maxn], b[maxn]; int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n >> t; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> x[i]; if (!is_sorted(x, x + n)) return cout << "N...
15
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <iomanip> #include <fstream> #include <cassert> #include <cstring> #include <numeric> #include <ctime> #include <comple...
11
#include <bits/stdc++.h> using namespace std; inline int gi() { char c; int num = 0, flg = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') flg = -1; while (c >= '0' && c <= '9') { num = num * 10 + c - 48; c = getchar(); } return num * flg; } int n, m, Q; int val[200005]; multiset<int> ...
24
#include <bits/stdc++.h> using namespace std; int main() { int flag = 0; double r; vector<double> v; double xa, ya, xb, yb, xc, yc, xd, yd; cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd; double minx = min(min(min(xa, xb), xc), xd); double miny = min(min(min(ya, yb), yc), yd); double maxx = max(max...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; using pii = pair<int, int>; using vi = vector<int>; const int N = 100005; int t[N], k[N], d[N]; int tim[N]; set<int> fr; int main() { int n, q; scanf("%d%d", &n, &q); for (int i = 1; i <= q; ++i) { scan...
5
#include <bits/stdc++.h> using namespace std; int n, a[255], wrong; double s, P; void work() { n = 250, s = 0, wrong = 0; for (int i = 1; i <= n; i++) scanf("%d", &a[i]), P += a[i]; P /= n; for (int i = 1; i <= n; i++) if ((a[i] < P / 2) || (P * 3 / 2 < a[i])) wrong++; puts(wrong <= 50 ? "poisson" : "unif...
13
#include <bits/stdc++.h> using namespace std; vector<int> v[100005]; int arr[100005][25]; long long dp[100005][25][2], ans[25]; void dfs(int node, int pnode) { long long s[25][2]; memset(s, 0, sizeof(s)); for (int i = 0; i < 25; i++) dp[node][i][arr[node][i]] = 1; for (int i = 0; i < v[node].size(); i++) { ...
13
#include <bits/stdc++.h> using namespace std; inline long long read() { long long neg = 1, num = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') neg = -1; for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c - '0'; return neg * num; } int n, b[200010], f[200010], ans...
16
#include <bits/stdc++.h> using namespace std; long long dp[510][510]; int a[510], n; long long mo(long long a) { if (a >= 0 && a < 1000000007) return a; a %= 1000000007; if (a < 0) a += 1000000007; return a; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 0; i...
15
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 10, INF = 1e9; int n, m, ans[MAXN], u[MAXN][MAXN], l[MAXN][MAXN], r[MAXN][MAXN], dp[MAXN][MAXN], a[MAXN][MAXN]; int mnl[MAXN], mnr[MAXN]; set<pair<int, int> > sl, sr; char t[MAXN]; vector<pair<int, int> > q; bool flag; inline bool check(int x, int...
20
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int n, out; vector<int> in; int dp[12][1 << 11]; bool check() { for (int i = 0; i < (int)n + 1; i++) for (int j = 0; j < (int)1 << n; j++) dp[i][j] = inf; for (int i = 0; i < (int)n; i++) if (in[i] >...
15
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long mod = (1LL << 32), inf = 3e9, mxn = 1e5 + 10; set<int> co[mxn]; int ile[mxn]; vector<pair<int, pair<int, int> > > ans; void tran(int sk, int dok, int ile) { set<int>::iterator it1, it2; vector<int> vec; it2 = co[dok].begin();...
16
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; using ii = pair<int, int>; using ll = long long; const int N = 1e6 + 5; const int mod = 998244353; int lvl[N]; int par[N][22]; int lca(int u, int v) { if (lvl[u] > lvl[v]) swap(u, v); int d = lvl[v] - lvl[u]; for (...
16
#include <bits/stdc++.h> using namespace std; int n, m, k, p; long long h[100010]; long long a[100010]; long long tot[100010]; long long need[100010]; long long cnt[5010]; bool can(long long mx) { long long sum = 0; for (int i = 0; i < n; i++) { need[i] = max(0LL, (tot[i] - mx + p - 1) / p); sum += need[i];...
21
#include <bits/stdc++.h> using namespace std; const int N = 200005; void println() { cout << '\n'; } template <typename T, typename... Ts> void println(const T& value, const Ts&... values) { cout << value << ' '; println(values...); } struct dsu { vector<int> par, sz; void init(int n) { par.assign(n + 5, 0)...
15
#include <bits/stdc++.h> using namespace std; const int MAX = 5e3 + 5; const int MAX_VAL = 1e5 + 5; int memo[MAX][MAX], arr[MAX], memo2[MAX]; vector<int> last[MAX_VAL], last_mod[8]; vector<int> adj[MAX]; int n; int longest_path(int u) { int &ans = memo2[u]; if (~ans) { return ans; } ans = 0; for (auto &ea...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int INF = 1e9 + 7; int cnt, n, m, pos, q, step, ans, fk; int dep[N], si[N], son[N], top[N], w[N], fa[N]; int head[N]; struct node { int u, v, w; int next; } edge[N * 2]; void add(int u, int v, int w) { edge[cnt].u = u, edge[cnt].v = v, edg...
13
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a[100001]; vector<int> e[100001]; vector<int> b; int c, d, ans; int cyc; bool vis[100001]; int used[100001]; void dfs(int x) { if (vis[x]) return; b.push_back(x); vis[x] = true; for (int i = 0; i < e[x].size(); i++) { dfs(e[x][i]); } } vo...
14
#include <bits/stdc++.h> using namespace std; int n, m, q, lim; int pre[200005], las[200005], key[200005]; int f[200005][20]; int A[200005], B[200005], p[20]; int solve(int x) { int step = n - 1, ans = x; for (int i = lim; i >= 0; i--) { if (step >= p[i]) { step -= p[i]; ans = f[ans][i]; } } ...
12
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k; int n, m, x, y, z, p, xx, yy, nn, mm, nx, ny; cin >> n >> m >> x >> y >> z >> p; x %= 4; y %= 2; z %= 4; for (i = 0; i < p; i++) { nn = n; mm = m; cin >> xx >> yy; if (x == 1) { nx = yy; ny = nn - xx + 1; ...
7
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops", \ "omit-frame-pointer", "inline") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native") #pragma GCC option("arch=native", "no-zero-upper") using namespace std...
19
#include <bits/stdc++.h> using namespace std; int b, g, n; int check(int i) { int q = min(i, b) + min(n - i, g); if (q == n) { return 1; } return 0; } int main() { cin >> b >> g >> n; int ans = 0; for (int i = 0; i <= n; ++i) { ans += check(i); } cout << ans; cin >> ans; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n; long long a = 0, g = 0; long long str[n][4]; long long lock = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) scanf("%lld", &str[i][j]); } string str1 = ""; int ii = 0; for (int i = 0; i < n; i++) {...
7
#include <bits/stdc++.h> using namespace std; const int primero = 1 << 21; const int tope = 1 << 22; const int limite = 300001; pair<int, int> minimo[tope]; void inserta(int pos, pair<int, int> val) { pos += primero; minimo[pos] = val; while (pos > 1) { pos /= 2; minimo[pos] = min(minimo[2 * pos], minimo[...
22
#include <bits/stdc++.h> using namespace std; int main() { int n, m, c, amx, amn, mmx, mmn; scanf("%d %d %d", &n, &m, &c); for (int i = 1; i <= c; i++) { int tx, ty; scanf("%d %d", &tx, &ty); if (i == 1) { amx = tx + ty, amn = tx + ty; mmx = tx - ty, mmn = tx - ty; } else { amx =...
13
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int s[N], e[N], sum[N * 2], t[N * 2], d[N], ind[N], pos = 1, par[N]; vector<int> adj[N]; void dfs(int x, int p) { if (p == 1) par[x] = x; if (p > 1) par[x] = par[p]; ind[x] = pos; s[x] = pos++; int u, i; d[x] = d[p] + 1; for (i = 0; i < ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for (int i = 0; i < n; i += 2) { cout << a[i] << " "; } in...
4
#include <bits/stdc++.h> using namespace std; void solve(long long testcase) { long long n; cin >> n; for (long long i = 1; i <= n; i++) { string s = ""; long long f = 0, c = 0; while (s.length() < 2 * n) { if (f != i) { s += '('; f++; c++; } else { if (c ==...
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const int maxn = 1 << 20; struct node { int l, r, id; } q[maxn]; int pos[maxn]; unsigned long long ans[maxn]; unsigned long long flag[maxn]; int a[maxn]; bool cmp(node a, node b) { if (pos[a.l] == pos[b.l]) return a...
14
#include <bits/stdc++.h> const long long INF = 1000000000; const double PI = 3.14159265358979323846; const long long MOD = 1000000000 + 7; using namespace std; bool cmp(long long a, long long b) { if (a > b) return true; else return false; } long long f(long long n) { if (n % 2 == 1) { return n * (n -...
12
#include <bits/stdc++.h> using namespace std; int si(); long long sl(); string ss(int); char sc(); float sf(); double sd(); long double sld(); template <typename T> void print(T, char = '\n'); template <typename T, typename... Args> void print(T, Args...); void pi(const int&, char = '\n'); void pl(const long long&, cha...
17
#include <bits/stdc++.h> using namespace std; int main(void) { int t; cin >> t; for (int i = 1; i <= t; i++) { int a, b; cin >> a >> b; if (a < b) swap(a, b); if (a > 2 * b) cout << a * a << '\n'; else if (b * 2 >= a) cout << b * b * 4 << '\n'; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int j = 1; for (int i = 0; i < n / 2; i++) { b[j] = a[i]; j += 2; } j = 0; for (int i = n / 2; i < n; i++) { b[j] = a[i]; j += 2; ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, candies_arr[1000], min_start, left_ptr, right_ptr, num_moves, a_count, b_count, curr_count; bool is_right, to_perform; cin >> t; for (int i = 0; i < t; i++) { cin >> n; for (in...
5
#include <bits/stdc++.h> using namespace std; int const N = 5e5, oo = 1e9; int mod = oo + 7; long long const OO = 1e18; int rnk[N][20], p[N], counting[N], lcp[N], rev[N]; void suff_arr(string s) { s += char('a' - 1); int n = s.size(); for (int i = 0; i < n; i++) counting[s[i] - 'a' + 1]++; for (int i = 1; i < 2...
16
#include <bits/stdc++.h> using namespace std; map<string, set<string> > host2path; map<string, vector<string> > path2host; int main() { int n, ans = 0; cin >> n; for (int i = 0; i < n; i++) { string s, host = "", path = ""; cin >> s; int pos = 7, len = s.length(); for (; s[pos] != '/' && pos < len...
13
#include <bits/stdc++.h> using namespace std; long long n, a[1000 * 100 + 100]; bool so() { for (long long i = 1; i < n; i++) if (a[i] > a[i + 1]) return false; return true; } bool nou() { for (long long i = 1; i < n; i++) if (a[i] < a[i + 1]) return false; return true; } int main() { ios_base::sync_w...
10
#include <bits/stdc++.h> using namespace std; void __print(int first) { cerr << first; } void __print(long first) { cerr << first; } void __print(long long first) { cerr << first; } void __print(unsigned first) { cerr << first; } void __print(unsigned long first) { cerr << first; } void __print(unsigned long long first...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); int fh = 1; while (ch < '0' || ch > '9') { if (ch == '-') fh = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= fh; } template <typename...
14
#include <bits/stdc++.h> using namespace std; int t, n, a, b, c; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n; a = 0; b = 0; c = 0; int m = n; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { a = i; ...
5
#include <bits/stdc++.h> using namespace std; const long long INF = (1LL << 60); vector<int> v[500005]; int a[500005], dp[20][500005]; long long rasp = 0; int rad; void DFS(int current, int father) { dp[0][current] = father; for (int i = 1; i < 20; ++i) if (dp[i - 1][current] != -1) dp[i][current] = dp[i ...
20
#include <bits/stdc++.h> using namespace std; int n, p, ch[1000005][26], S[1000005], k, on, sz[1000005], sta[1000005], dfn[1000005], dfs_clock, dp[1000005], idx[1000005]; bool isS[1000005]; char s[2]; vector<int> in[1000005], out[1000005]; multiset<int> MS; void dfs(int x) { sta[x] = on + 1; dp[x] = 1E9; dfn[...
18
#include <bits/stdc++.h> using namespace std; const long long ts = 200005; int n; vector<int> f(ts, 1e9), g(ts, 1e9), a(ts); void init() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] -= i; } } int calc() { f[0] = -1e9; g[0] = -1e9; int ans = 0; for (int i = 2; i <= n; i++) { int...
17
#include <bits/stdc++.h> using namespace std; const long long highestApples = 1000000000; int n; long long allApples; long long apples[100000]; long long sons[100000]; long long minAdd[100000]; long long maxApples[100000]; vector<int> edges[100000]; bool seen[100000]; long long gcd(long long a, long long b) { long lo...
13
#include <bits/stdc++.h> using namespace std; map<int, map<int, int> > mp; void add(int v, int t, int val) { for (; t < 1e9 + 100; t += t & -t) { mp[v][t] += val; } } int ans(int v, int t) { int ret = 0; for (; t > 0; t &= t - 1) ret += mp[v][t]; return ret; } int main() { ios::sync_with_stdio(0); int...
12
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e5 + 7; const long double Inf = 1e19 + 9; const long double pi = 3.1415926535897932384626433832795028841971693993751; struct point { long double x, y; }; int n; point p, P[Maxn]; long double operator^(point a, point b) { long double d = (a.x - b.x); ...
11
#include <bits/stdc++.h> using namespace std; const long long infl = 0x3f3f3f3f3f3f3f3fLL; const long long infi = 0x3f3f3f3f; const long long mod = 1000000007; long long gcd(long long a, long long b); long long pow(long long a, long long b); void solve() { long long n; cin >> n; vector<long long> vec(n); for (a...
3
#include <bits/stdc++.h> using namespace std; long long K; long long sgpp[200001][4]; void csgpp() { sgpp[1][0] = K; sgpp[1][1] = K - 1; sgpp[1][2] = K - 1; sgpp[1][3] = K - 2; for (int k = 2; k < int(200001); k++) { sgpp[k][0] = (K * sgpp[k - 1][1]) % 998244353; sgpp[k][1] = ((K - 1) * sgpp[k - 1][1]...
14
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <map> #include <iterator> #include <cmath> #include <set> #include <deque> #include <string> using namespace std; int n, q; char s[110]; bool checkL(int l) { char ch = s[l]; int pL = l - 1; while (pL >= 1) { ...
1
#include <bits/stdc++.h> using namespace std; int n, m, t1[100007], t2[100007]; void gen(int n, int t[100007]) { if (n == 1) { t[0] = 1; return; } if (n == 2) { t[0] = 3; t[1] = 4; return; } if (n & 1) { t[0] = 2; for (int i = 1; i <= n - 2; i++) t[i] = 1; t[n - 1] = (n + 1) / ...
16
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rev(i,a,b) for(int i=a;i>b;i--) #define ll long long #define pii pair<int,int> #define vi vector<int> #define pb push_back #define F first #define S second #define mp make_pair #define se second #define all(a) (a).begin(),(a).end() #define endl '\n...
10
#include <bits/stdc++.h> using namespace std; long long int modexpo(long long int base, long long int power) { long long int result = 1; while (power != 0) { if (power & 1) { result = (result * base) % 1000000007; } base = (base * base) % 1000000007; power = power >> 1; } return result; } ...
11
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") #pragma warning(disable : 4786) using namespace std; int main(void) { long int n, m, i; unsigned long long int t = 0; while (cin >> n >> m) { t = 0; int a = 1, b; for (i = 0; i < m; i++) { cin >> b; if (b >= a) { t...
2
#include <bits/stdc++.h> using namespace std; int main() { int a, ta, b, tb, x, y, ans = 0; scanf("%d%d%d%d", &a, &ta, &b, &tb); scanf("%d:%d", &x, &y); int l = x * 60 + y; int r = x * 60 + y + ta; for (int i = 0;; i++) { int st = 300 + i * b; int ed = 300 + i * b + tb; if (st >= 24 * 60) break;...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn], pre[maxn]; int main() { int t; cin >> t; while (t--) { int n, p, k, ans = 0; cin >> n >> p >> k; pre[0] = 0; for (int i = (1); i <= (n); i++) cin >> a[i]; sort(a + 1, a + 1 + n); for (int i = (1); i <= (n...
6
#include <bits/stdc++.h> using namespace std; int j, nrmin, s1, mij, u, p, nr1, k, max, x, nr, n, i, z, y, a[1100]; char cc, s[1100], b[1100]; int main() { gets(s); scanf("%d", &n); x = strlen(s); for (i = 0; i < x; i++) a[s[i]]++; p = 1; u = 10000; y = -1; while (p <= u) { mij = (p + u) / 2; nr...
6
#include <bits/stdc++.h> using namespace std; const int K = 12; const int N = 111; int a[K][N][N]; int c, q; void solve() { int n; scanf("%d%d%d", &n, &q, &c); c++; while (n--) { int x, y, t; scanf("%d%d%d", &x, &y, &t); a[t][x][y]++; } for (int k = 0; k < c; k++) { for (int x = 1; x < N; x+...
8
#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 = "RDLU"; long long ln, lk, lm; void etp(b...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct segment { int l, r, mx_id; int size() { return r - l; } int unity(int _l, int _r) { return max(0, min(r, _r) - max(l, _l)); } segment(int _l = 0, int _r = 0) { l = _l; r = _r; mx_id = -1; } } seg[N << 2]; int n, _dp[N], p...
12
#include <bits/stdc++.h> using namespace std; const int N = 3500; const int Mod = 1e9 + 7; string s; long long a[N + N]; int p, alp, cnt = 1; inline void Basep() { for (int i = 0; i < s.length(); i++) { for (int j = 1; j <= cnt; j++) a[j] *= 10; a[1] += s[i] - '0'; for (int j = 1; j <= cnt; j++) { i...
25
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; if (t == 10) { if (n == 1) cout << -1; else { for (int i = 0; i < n - 1; i++) cout << 1; cout << 0; } } else for (int i = 0; i < n; i++) cout << t; cout << endl; }
2
#include <bits/stdc++.h> using namespace std; vector<int> g[100500]; vector<int> ans; int a[100500]; int b[100500]; int nn[100500]; int n, m; int sum; int start; void rec(int v) { nn[v] = 1; sum += a[v]; for (int i = 0; i < g[v].size(); ++i) if (!nn[g[v][i]]) rec(g[v][i]); } void bfs(int v) { nn[v] = 1; b...
14
#include <bits/stdc++.h> using namespace std; int main() { vector<string> all; string line; int maxLen = 0; while (getline(cin, line)) { if (maxLen < line.size()) maxLen = line.size(); all.push_back(line); } int unaligned = 0; for (int i = -2; i < maxLen; i++) cout << '*'; cout << endl; for (i...
4
#include <bits/stdc++.h> using namespace std; int e[25]; int f[1 << 22], pres[1 << 22], prep[1 << 22]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; e[u] |= 1 << (v - 1); e[v] |= 1 << (u - 1); ...
16
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); while (t--) { int st, in, ex; scanf("%d%d%d", &st, &in, &ex); if (st <= in) { ex -= (in - st) + 1; st += (in - st) + 1; } if (ex < 0) { printf("0\n"); } else { int mini = (ex < (st - in - 1)) ? ex : (st -...
5
#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") template <class S, class T> ostream& operator<<(ostream& os, const pair<S, T>& p) { return os << "(" << p.first << ", " << p.se...
15
#include <bits/stdc++.h> using namespace std; const int kNmax = 2e5 + 10; const int kMod = 998244353; int n, p[kNmax]; int emptyLeft[kNmax], emptyRight[kNmax]; int countBigger[kNmax], countSmaller[kNmax]; int res; bool seen[kNmax]; class FT { public: FT(int n) { sz_ = n; arr_.resize(sz_ + 5); } int lsb(i...
15
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long s, a, b, c; cin >> s >> a >> b >> c; long long f = s / (a * c); long long ans = (f * (a + b)) + ((s - (f * a * c)) / c); cout << ans << '\n'; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long int maxn = 1e6 + 1; double pie = 3.1415926535; double dp[2002][2002][2][2], p; long long int h, dright[2002], dleft[2002], a[2002]; double go(long long int lidx, long long int ridx, bool s, bool d, long long int ls, long lo...
15
#include <bits/stdc++.h> using namespace std; using i64 = long long; using u64 = unsigned long long; struct debug { ~debug() { cerr << endl; } template <class c> debug& operator<<(c x) { cerr << x; return *this; } template <class c, class d> debug& operator<<(pair<c, d> x) { *this << "(" << x.fi...
11
#include <bits/stdc++.h> using namespace std; char c[2005]; int End[1000005], f[2005 * 2][2005], p, tot = 1, size[1000005], i, j, k, K, n, g[2005], mp[1000005][26]; int now, rel[1000005], T[1000005], G[2005], l; int main() { scanf("%d%d", &n, &K); for (i = 1; i <= n; ++i) { ...
17
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf("%d", &n); if (n % 4 > 1) { puts("NO"); return 0; } puts("YES"); if (n % 4 == 0) for (int i = 1; i <= n; i += 4) { printf("%d %d\n", i + 2, i + 3); printf("%d %d\n", i, i + 2); printf("%d %d\n", i + 1, i + 3)...
23
#include <bits/stdc++.h> using namespace std; long long BIT[1000005]; long long ans[1000005]; int n, k; int now, nxt; bool tambel; void add(int x) { ++x; for (int i = x; i < 1000005; i += i & -i) { ++BIT[i]; } } long long get(int x) { long long ret = 0; ++x; for (int i = x; i > 0; i -= i & -i) ret += BI...
12
#include <bits/stdc++.h> using namespace std; int readInt() { bool minus = false; int result = 0; char ch; ch = getchar(); while (true) { if (ch == '-') break; if (ch >= '0' && ch <= '9') break; ch = getchar(); } if (ch == '-') minus = true; else result = ch - '0'; while (true) { ...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long D[1010], L[110]; int main() { int T; cin >> T; while (T--) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> D[i]; } for (int i = 0; i < n; i++) { cin >> L[i]; } for (int i = 0; i <...
5
#include <bits/stdc++.h> const int MOD = 1000000007; using namespace std; int a[106]; bool isprime(long long n) { if (n <= 1) { return 0; } for (int i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main() { map<long long, long long> mp; long long n; cin >> n; if (isprime(n...
7
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <string> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) #define pb push_back int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for(;t;t--){ ...
8
#include <bits/stdc++.h> using namespace std; int q[200010] = {}; long long a[200010] = {}; vector<int> e[200010]; vector<long long> t[200010]; long long h[200010] = {}; int bj[200010] = {}; int ans[200010] = {}; int p; long long w; int n; int s; void ff1(int x, int y, int o) { if (y != 0) h[x] = h[y] + o; for (int...
11
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n; double a[200]; double cnt[200]; double dat[200]; double ndat[200]; double p[1000000]; int main() { int i, j, k; cin >> n; for (i = 0; i < n; i++) cin >> a[i], a[i] /= 100.; fill(cnt, cnt + n, 1); for (i = 0; i < n; i++) { ...
19
#include <bits/stdc++.h> int area(int x1, int y1, int x2, int y2, int x3, int y3) { int s = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2); return s < 0 ? -s : s; } struct Square { int x[4], y[4]; void read() { for (int i = 0; i < 4; i++) scanf("%d%d", x + i, y + i); } bool in(int a, int b) { int ...
8
#include <bits/stdc++.h> int main() { int a[100], b[100], n, l, i, k = 0, max = 0; scanf("%d%d", &n, &l); for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (l % a[i] == 0) { b[k] = a[i]; k++; } } max = b[0]; for (i = 0; i < k; i++) { if (b[i] > max) { max = b[i]; } } ...
1