solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int ft[4][11][11][100005]; void update(int c, int pos1, int pos2, int i, int v) { for (; i <= 100000; i += (i & -i)) ft[c][pos1][pos2][i] += v; } int query(int c, int pos1, int pos2, int i) { int res = 0; for (; i > 0; i -= (i & -i)) res += ft[c][pos1][pos2][i]; ret...
13
#include <bits/stdc++.h> using namespace std; const int MAX = 3e5 + 9; int n; long long a[MAX], x, memo[MAX][3][3]; long long dp(int i, int flag1, int flag2) { if (i == n) { return 0; } long long& ret = memo[i][flag1][flag2]; if (ret != -1) { return ret; } ret = 0; for (int newFlag1 = flag1; newFl...
11
#include <bits/stdc++.h> int main(void) { int n, num = 1, max = 1, i; scanf("%d", &n); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n - 1; i++) { if (a[i] <= a[i + 1]) num++; else { max = max > num ? max : num; num = 1; } max = max > num ? m...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 11; vector<int> graph[N]; bool visited[N]; vector<int> ans; vector<int> dfs(int u, int par) { visited[u] = true; vector<int> temp1; vector<int> temp2; for (auto v : graph[u]) { if (v != par) { vector<int> temp = dfs(v, u); int sz ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, b, d, num; int s = 0; int a = 0; int flag = 0; cin >> n >> b >> d; for (int i = 0; i < n; i++) { cin >> num; if (num <= b) { s += num; flag = 1; } if (s > d) { s = 0; a++; } } cout << a << endl;...
1
#include <bits/stdc++.h> using namespace std; const bool debug = false; const int oo = 1000000000; int n; double a[4005]; int main() { if (!debug) { ios_base::sync_with_stdio(false); } cout << fixed << setprecision(3); cin >> n; for (int i = 1; i <= n * 2; i++) { cin >> a[i]; } double sum = 0; i...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int arr[n], arr2[m]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < m; i++) { cin >> arr2[i]; } sort(arr, arr + n); sort(arr2, arr2 + m); int v = max(2 * arr[0], arr[n - 1]); if (v >= ar...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 200020; struct Node { int x, y; Node(){}; Node(int _x, int _y) { x = _x; y = _y; } bool operator<(const Node& b) const { return x < b.x || x == b.x && y < b.y; } } low[maxn], up[maxn]; int n, a[maxn], cnt[maxn], ans[maxn]; int main() { s...
17
#include <bits/stdc++.h> using namespace std; int n, ans = -2e9, a[100005], pre[100005], suff[100005], mnsuff[100005], mnid[100005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; mnid[n + 1] = n + 1; for (int i = 1; i <= n; ++i) cin >> a[i], pre[i] = pre[i - 1] + a[i]; fo...
10
#include <bits/stdc++.h> using namespace std; int main() { long long t; t = 1; while (t--) { long long int n, k = 0, z = 0; cin >> n; int a[n]; for (int(i) = 0; (i) < (n); (i)++) cin >> a[i]; sort(a, a + n); for (int(i) = (1); (i) <= (n - 2); (i)++) if (a[i] == a[i - 1] && a[i] == a[...
2
#include <bits/stdc++.h> using namespace std; struct node { int l, r, v; } t[4000010]; struct ask { int op, l, r, x; void in() { scanf("%d%d%d", &op, &l, &r); if (op == 1) { scanf("%d", &x); } } } q[100010]; int n, m, k, Q, a[100010], b[1000010], bk, id[1000010]; int f[100010][25], bit[100010]...
15
#include <bits/stdc++.h> using namespace std; struct PQtree { int type, father; vector<int> child; } t[2010]; int n, pd[2010], w[2010], size[2010], in[5010], B[2010], W[3] = {0, 2, 1}, ans[2010], C[600][600], len, kk; vector<int> rem, A; char getin() { char ch = getchar(); while (ch < '0' || ch > '9') ch = ...
26
#include <bits/stdc++.h> using namespace std; const int M = 5e5 + 5; int n, Q, K, m, D, d[M], a[M], b[M], tt, siz[M], f[M], st[M], top; vector<int> t[M << 2]; int op[M]; int get(int x) { if (f[x] == x) return x; return get(f[x]); } void merge(int x, int y) { int X = get(x), Y = get(y); if (X == Y) return; if ...
17
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; const int M = 1000000007; const double PI = acos(-1); const int oo = 1000000000; long long n, k, allsz; int sz[4]; string s[] = {"What are you doing while sending \"", "\"? Are you busy? Will you send \"", "\"?", "What ...
9
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a[100005]; int cap[100005]; vector<int> all; vector<int> g[100005]; void dfs(int v) { cap[v] = 1; for (int to : g[v]) if (!cap[to]) { dfs(to); } } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < (int)(n); ++i) { int le...
13
#include <bits/stdc++.h> using namespace std; const int N = 1000007; const int MOD = 1000000007; int main() { string s; ios::sync_with_stdio(false); cin >> s; long long ans = 0, bes = 0; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == 'a') { ans = (ans + bes) % MOD; bes = (bes * 2ll) % M...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y, z; cin >> x >> y >> z; int flag = 0; if (max(x, y) < z || max(y, z) < x || max(x, z) < y) cout << "NO" << endl; else { cout << "YES" << endl; cout << max(max(x,...
0
#include <bits/stdc++.h> using namespace std; char a[5][5]; bool ok = false; int main() { ios::sync_with_stdio(false); cin.tie(0); for (int i = 1; i <= 4; ++i) for (int j = 1; j <= 4; ++j) cin >> a[i][j]; for (int i = 1; i <= 4; ++i) for (int j = 1; j <= 4; ++j) if ((a[i][j] == '.' && a[i - 1][j] ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long N; int i, j, k; int area; int x, y; cin >> N; vector<pair<int, int> > a; for (i = 0; i < N; ++i) { cin >> x >> y; a.push_back(make_pair(x, y)); } long long sum = (N * (N - 1) * (N - 2)) / 6; for (i = 0; i < N; ++i) for ...
11
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16000000") #pragma GCC optimize("O4") using namespace std; double eps = 1e-10; struct pt { int x, y; int from; }; int dp[1024][1024]; char arr[1024][1024]; bool used[1024][1024][4]; int n, m; pair<int, int> s, f; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0,...
8
#include <bits/stdc++.h> using namespace std; const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, 1, 0, -1}; const long long MOD = 1e9 + 7; const long long INF = 1e9; const double EPS = 1e-5; int n, r; vector<double> f, s, p; vector<vector<int>> vis(55, vector<int>(6000)); int vf = 0; vector<vector<double>> mem(55, ve...
16
#include <bits/stdc++.h> using namespace std; template <class T> inline T min(T &a, T &b) { return a < b ? a : b; } template <class T> inline T max(T &a, T &b) { return a > b ? a : b; } template <class T> void read(T &x) { char ch; while ((ch = getchar()) && !isdigit(ch)) ; x = ch - '0'; while ((ch = ge...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int a[MAXN]; int n; int Bit[MAXN][40]; void input() { memset(Bit, -1, sizeof(Bit)); for (int i = 1; i <= n; i++) { scanf("%d", a + i); } } void solve() { int j, k; for (int i = 1; i <= n; i++) { k = 1; while (a[i]) { Bit[...
11
#include <bits/stdc++.h> using namespace std; int Substr(string str, string sub) { int nRet = 0, nStart = 0; while (-1 != (nStart = str.find(sub, nStart))) { nStart += sub.length(); ++nRet; } return nRet; } int main() { string s; int n; while (cin >> n >> s) { map<string, int> mp; set<stri...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; int a, b, c, d, i, j, n, m, k; char s1[1002], s2[1002]; inline int gcd(int a, int b) { for (; b; swap(a, b)) { a %= b; } return a; } inline bool win(char a, char b) { if (a == 'R' & b == 'S') { return 1; } else if...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const long long base = 131; const long long mod = 1e9 + 7; long long Hash[maxn], b[maxn]; char ch[maxn]; int n, t, res[maxn / 2]; inline int read() { int t = 0; char ch = getchar(); while (ch < '0' || ch > '9') { ch = getchar(); } whi...
19
#include <bits/stdc++.h> using namespace std; const int N = 5e2 + 7; const int MOD = 1e9 + 7; const double eps = 1e-7; const int INF = 0x3f3f3f3f; int n; int a[N], dp[N][N]; inline int check(const int &l, const int &r) { stack<int> stk; for (int i = l, x; i <= r; ++i) { x = a[i]; while (stk.size() && stk.to...
13
#include <bits/stdc++.h> using namespace std; const int INF = 1000000404; const long long MOD = 1000000007ll; const long double PI = acos(-1.0); const long double EPS = 1e-9; template <typename t1, typename t2> inline void upmax(t1 &a, t2 b) { a = max(a, (t1)b); } template <typename t1, typename t2> inline void upmin...
16
#include <bits/stdc++.h> using namespace std; int const N = 100 + 2; int n, a[N]; void solve() { int n; cin >> n; int mn = N; for (int i = 0; i < (int)(n); ++i) cin >> a[i], mn = min(mn, a[i]); for (int i = 0; i < (int)(n); ++i) a[i] -= mn; for (int i = 0; i < (int)(n); ++i) if (a[i] % 2 == 1) { c...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int i, j, n, m, k, z = 0; string s; cin >> n; int a[n + 7]; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) { for (k = 3; k <= 360; k++) { for (j = 1; j <= k - 2; j...
8
#include <bits/stdc++.h> using namespace std; const int N = 5002; int a[N], n, k, c[1000002], d[1000002]; pair<int, int> v[1000002][6]; int tot[10000002]; int par[N], sz[N]; int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } bool can(vector<pair<int, int> > vec) { for (auto p : vec) { par[p.first...
16
#include <bits/stdc++.h> using namespace std; int n, m, i, j, a[200005], ans[200005], pos[200005], sum[800005]; vector<int> qry[200005]; struct ii { int x, id; } b[200005]; bool cmp(ii x, ii y) { if (x.x != y.x) return x.x > y.x; return x.id < y.id; } void update(int x, int l, int r, int y, int c) { sum[x] += c...
10
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; vector<long long int> q1, q2, q3; long long int a[5]; bool pr(int i, int j) { if (a[i] == 1 || a[j] == 1) return false; if (a[i] != a[j]) return false; a[i] /= 2; a[j] /= 2; a[4]++; return true; } void get() { if (a[0] == a[1] || a[2] ...
7
#include <bits/stdc++.h> using namespace std; int N, Q; int A[200005], W[200005]; long long Arb[2][200005]; const int MOD = 1000000007; void Read() { scanf("%d%d", &N, &Q); for (int i = 1; i <= N; i++) { scanf("%d", &A[i]); } for (int i = 1; i <= N; i++) scanf("%d", &W[i]); } int norm(int x) { if (x < 0) ...
17
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") inline long long read() { char ch = getchar(); long long x = 0, f = 0; while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return...
13
#include <bits/stdc++.h> using namespace std; int main() { int x[105], n, a, b; cin >> n; for (int i = 0; i < n - 1; i++) cin >> x[i]; int ans = 0; cin >> a >> b; for (int i = a; i < b; i++) ans += x[i - 1]; cout << ans; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; bool a[N], b[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, x; cin >> n >> x; int r = -1; for (int i = (int)(0); i < (int)(n); i++) { int y; cin >> y; if (!a[y]) a[y] = 1; else r = 0; } ...
4
#include <bits/stdc++.h> using namespace std; struct para { int a, b; }; vector<int> Z; void Stworz(int n) { for (int i = 0; i < n; ++i) Z.push_back(i); } int Find(int a) { if (Z[a] == a) return a; int fa = Find(Z[a]); Z[a] = fa; return fa; } int Union(int a, int b) { int fa = Find(a); int fb = Find(b);...
16
#include <bits/stdc++.h> using namespace std; long long S[100000]; pair<long long, long long> ps[100000]; pair<long long, long long> tmp[100000]; int n; long long D(pair<long long, long long> a, pair<long long, long long> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.seco...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000000 + 10; map<int, int> cnt; int n; int a[MAXN], fen[MAXN], rem[MAXN]; int get(int idx) { int ans = 0; for (int i = idx; i > 0; i -= (i & -i)) ans += fen[i]; return ans; } int sum(int a, int b) { return get(b) - get(a); } void add(int idx, int val...
10
#include <bits/stdc++.h> using namespace std; namespace Dango { const int MAXN = 105, MOD = 1000000009; vector<int> e[MAXN], root; queue<int> q; int n, m; int du[MAXN]; int size[MAXN]; long long fac[MAXN], inv[MAXN]; long long dp[MAXN][MAXN], res[MAXN], ans[MAXN]; bool vis[MAXN], tag[MAXN]; int read() { int x = 0, f ...
21
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; int a[N], aa[N], b[N], id[N], r[N]; bool cmp(int i, int j) { if (a[i] < a[j]) return 1; return 0; } int main() { int n, h; scanf("%d%d", &n, &h); for (int i = 1; i <= n; i++) scanf("%d", a + i); if (n == 2) { puts("0"); puts("1...
10
#include <bits/stdc++.h> using namespace std; unsigned long long n = 0, m = 100, i, j, k, ans = -1, y, x, z, l, a, b, c, s, o = 0; bool can = false; int main() { std::ios_base::sync_with_stdio(false); cin >> n; if (n < 3) cout << -1; else while (n--) cout << n + 1 << " "; return 0; ...
1
#include <bits/stdc++.h> using namespace std; struct query { int l, r, id; query() : l(0), r(0), id(0){}; query(int l, int r, int id) : l(l), r(r), id(id){}; }; int n, t, a[202020], num[1000001], bb[202020], ll, rr; vector<query> qq[400]; long long ans[202020], cur = 0; bool cmp(query q1, query q2) { if (q1.r <...
14
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; string s; cin >> s; long long dp[n][n + 1]; for (int i = 0; i < n; i++) { for (int j = 0; j <= n; j++) { dp[i][j] = 0; } } dp[0][1] = 1; for (int i = 2; i <= n; i++) { dp[0][i] = 0; } for (i...
12
#include <bits/stdc++.h> int a[501]; int dp[501][501]; int main() { int n, m, b, mod; scanf("%d%d%d%d", &n, &m, &b, &mod); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int r = 1; r <= m; r++) { for (int bb = a[i]; bb <= b; bb++) { ...
10
#include <bits/stdc++.h> using namespace std; const int N = 360360; int f[N + 4], k; long long a, b; long long solve() { memset(f, 0x3f, sizeof(f)); f[a] = 0; for (int i = a; i >= b; i--) { f[i - 1] = min(f[i - 1], f[i] + 1); for (int j = 3; j <= k; j++) f[i / j * j] = min(f[i / j * j], f[i] + 1); } r...
12
#include <bits/stdc++.h> using namespace std; const int N = (1 << 17), inv = 5e8 + 4, mod = 1e9 + 7; mt19937 mt(time(0)); struct data { int to, next, v; } e[N * 2]; long long X[N + 20], XX[N + 20], YY[N + 20], Y[N + 20]; int low[N], dfn[N], n, m, i, j, head[N], bridge[N], cnt, fa[N], size[N], ans, u[N], v[N], w[N...
16
#include <bits/stdc++.h> using namespace std; int visit[1005]; int cnt[1005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> vec[1005]; for (int i = 2; i <= n; i++) { int a; cin >> a; visit[a] = 1; vec[a].push_back(i); cnt[a]++; } f...
4
#include <bits/stdc++.h> using namespace std; int n, m, p, L[1000010]; vector<int> D[1000010]; int f[5050][5050]; int T[1000010]; int pr[5050]; void solve() { scanf("%d%d%d", &n, &m, &p); for (int i = 1; i <= n; i++) { scanf("%d", L + i); } for (int i = 1; i <= n; i++) { D[i].resize(L[i] + 1); } f[1...
18
#include <bits/stdc++.h> using namespace std; int t, a, b, c, d, k, x, y; int main() { cin >> t; for (int j = 1; j <= t; j++) { cin >> a >> b >> c >> d >> k; x = y = 0; x = a / c; if (a % c != 0) x++; y = b / d; if (b % d != 0) y++; if (x + y <= k) cout << x << " " << y << "\n"; ...
0
#include <bits/stdc++.h> using namespace std; bool powerof2(long long x) { if ((x != 0) && (x & x - 1) == 0) return true; else return false; } long long exponent(long long x, long long n) { if (n == 0) return 1; if (n % 2 != 0) { return x * exponent((x * x), (n - 1) / 2); } else return exponen...
5
#include <bits/stdc++.h> using namespace std; struct pp { long long x, y; }; const int base = 1000 * 1000 * 1000; const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int inf = (int)1e9; const int mod = 1e9 + 7; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); ...
6
#include <bits/stdc++.h> using namespace std; inline int read() { int a = 0; char c = getchar(); bool f = 0; while (!isdigit(c) && c != EOF) { if (c == '-') f = 1; c = getchar(); } if (c == EOF) exit(0); while (isdigit(c)) { a = (a << 3) + (a << 1) + (c ^ '0'); c = getchar(); } return ...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, ans = 0; string s; cin >> n >> x >> y; cin >> s; reverse(s.begin(), s.end()); for (int i = 0; i < s.length(); i++) { if (i < y) { if (s[i] != '0') ans += 1; } else if (i == y) { if (s[i] != '1') ans += 1; } else ...
3
#include <bits/stdc++.h> using namespace std; int n; int a[100005]; int emm[31]; bool b[100005][31]; int flag; int main() { scanf("%d", &n); emm[0] = 1; for (int i = 1; i <= 30; i++) emm[i] = emm[i - 1] * 2; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); int x = a[i]; for (int j = 30; j >= 0; j-...
7
#include <bits/stdc++.h> int s[] = {2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, ...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5000; const long double eps = (1e-12); const int logn = 21; const double Pi = acos(-1.0); const long long pp = 1000000000 + 7; int lowbit(int x) { return x & (-x); } const int INF = 1e9 + 9; int dep[MAXN]; int p[MAXN]; int depx[MAXN]; int sz[MAXN]; ve...
17
#include <bits/stdc++.h> using namespace std; int main() { double t, s, q; while (~scanf("%lf %lf %lf", &t, &s, &q)) { double k = (q - 1) / (q); double end = s + k * s; int times = 1; while (s < t) { if (end + k - s - 1 + 0.000001 < 0) { end += s * k; times++; end -= k;...
7
#include <bits/stdc++.h> using namespace std; const int sz = 1e6 + 100; bitset<sz> b; int p[sz], len[sz]; bool used[sz]; int main() { ios_base::sync_with_stdio(false); int n, k, sum = 0, cnt = 0, i; cin >> n >> k; for (i = 0; i < n; i++) { cin >> p[i]; p[i]--; } b[0] = 1; for (i = 0; i < n; i++) ...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; long long int n, temp = 0; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; map<long long int, long long int> m; for (long long int i = 0; i < n; ...
7
#include <bits/stdc++.h> using namespace std; int sg(long long x) { if (x <= 3) return 0; if (x <= 15) return 1; if (x <= 81) return 2; if (x <= 6723) return 0; if (x <= 50625) return 3; if (x <= 2562991875) return 1; return 2; } int main() { int n; while (scanf("%d", &n) != EOF) { long long ans =...
14
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; int flag = 1, j = 0; cin >> a >> b >> n; for (int i = 0; i < 10; i++) { if (((a * 10) + i) % b == 0) { cout << a << i; j++; flag = 0; for (; j < n; j++) cout << "0"; break; } } if (flag == 1) { ...
6
#include <bits/stdc++.h> using namespace std; string s; int M; vector<int> vs[9]; int mod = 1e9 + 7; void add(int& x, int y) { x += y; if (x >= mod) x -= mod; if (x < 0) x += mod; } vector<int> operator+(vector<int> x, vector<int> y) { for (int i = 0; i < (int)(1 << 16); i++) add(x[i], y[i]); return x; } void...
22
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; while (t--) { int n, k; cin >> n >> k; int a[n]; int i; for (i = 0; i < n; i++) { cin >> a[i]; } int s = a[n - 1] - a[0]; vector<int> m; for (i = 0; i < n - 1; i++) { m.push_back(a[i + 1] - a[i]); ...
6
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); double fixAngle(double A) { return A > 1 ? 1 : (A < -1 ? -1 : A); } double dcmp(double a, double b) { return fabs(a - b) < 1e-6 ? 0 : a > b ? 1 : -1; } long long n, m, s, l; vector<pair<long long, long long>> graph[100000 + 10]; long long sol...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6, M = 7e6; int f[N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; cin >> t; while (t--) { int n; string s; cin >> n >> s; int cnt = 0; set<int> st; set<int> r; for (int i = 1; i < n; ...
9
#include <bits/stdc++.h> using namespace std; void solve() { long long n, x, b; cin >> n; stack<long long> stk; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; for (long long i = n - 1; i >= 0; i--) { stk.push(v[i]); } vector<long long> m(n + 1); for (long long i = 1; i <= n...
2
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; int m; cin >> m; int l, r, k; int len = a.length(); for (int i = 0; i < m; i++) { cin >> l >> r >> k; l--; r--; int d = r - l + 1; int e = k % d; string b = ""; string c = ""; if (e == 0) { ...
5
#include <bits/stdc++.h> using namespace std; char s[1000001]; int n; int a[1000001]; int b[1000001]; int k[3]; int main() { scanf("%s", s); int n = strlen(s); for (int i = 0; i < n; ++i) { a[i] = (s[i] == '0') ? 0 : s[i] == '1' ? 1 : 2; ++k[a[i]]; } int s = k[0] + k[1] + k[2]; int s0 = s >> 1; in...
11
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0', c = getchar(); } return x * f; } const long long MAXN = 4e5 + 10; long lon...
23
#include <bits/stdc++.h> using namespace std; int n, a[111], b[111]; vector<int> g[111]; int p[111]; int get(int v) { if (v == p[v]) return v; return p[v] = get(p[v]); } void unite(int u, int v) { u = get(u), v = get(v); if (u != v) p[v] = u; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { ...
8
#include <bits/stdc++.h> using namespace std; int main() { int a, b; while (cin >> a >> b) { int A[1204] = {}; for (int i = 1; i <= a; i++) { cin >> A[i]; } int B[1024] = {}; for (int i = 1; i <= b; i++) { cin >> B[i]; } int vis[1024] = {}; vector<int> num; for (int i...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") using namespace std; const int N = (int)1e6; map<char, int> nxt[N]; vector<pair<int, int> > items[N]; int who[N]; int tot, n = 1; long long ans = 0; void add(string& s, int c, int idx) { int v = 0; for (auto c : (s)) { if (!nxt[v].count(c)) { ...
15
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; const int MAXN = 1e5 + 10; int v[MAXN], i[MAXN], cj[MAXN]; bool cmp(int a, int b) { return v[a] < v[b]; } int main() { int n, h; scanf("%d%d", &n, &h); for (int a = 0; a < n; ++a) { scanf("%d...
10
#include <bits/stdc++.h> using namespace std; int solve() { long long a, b; cin >> a >> b; if (a == b) return 0; else if (b > a) { if ((b - a) % 2 == 0) return 2; else return 1; } else { if ((a - b) % 2 == 0) return 1; else return 2; } } int main() { ios_base::s...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f * x; } const int maxn = 5e5 + 7; con...
8
#include <bits/stdc++.h> using namespace std; void Heavy_Gaurav_Singh() { vector<long long> c(3); for (int i = 0; i < 3; i++) cin >> c[i]; long long ans = 0; for (int i = 0; i < 3; i++) { if (*min_element(c.begin(), c.end()) >= i) { long long t = i; for (auto x : c) t += (x - i) / 3; ans =...
8
#include <bits/stdc++.h> char buf[1 << 21], *p1, *p2; template <typename T> inline void read(T& x) { x = 0; int ch = ((p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)) ? EOF : *p1++); while (ch < 48 || ch > 57) ch = ((p1 == p2 && (p2 = (p1 = buf) ...
20
#include <bits/stdc++.h> using namespace std; void print(const char* msg, ...); int N, M; int edges[300002]; bool visited[300002]; vector<int> used; vector<vector<int>> g; void walk(int ind) { visited[ind] = true; used.push_back(ind); for (int i = 0; i < g[ind].size(); i++) { if (visited[g[ind][i]] == false) ...
7
#include <bits/stdc++.h> using namespace std; const int Maxn = 100001; int n, h, dntchange[Maxn]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &h); if (i < n / 2 && h - i > 0) dntchange[h - i]++; else if (i >= n / 2 && h - (n - 1 - i) > 0) dntchange[h - (n - 1 - i)...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct KDT { int p, xl, xr, yl, yr; } t[N << 2], tq; struct Rec { int xl, xr, yl, yr, h, id; } b[N]; struct Pnt { int x, y, id; } a[N]; int n, m, ans[N], iv[N]; bool cmpX(Pnt x, Pnt y) { return x.x < y.x; } bool cmpY(Pnt x, Pnt y) { return x.y <...
17
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x7fffffffffffffff; const double eps = 1e-10; template <typename _Tp> _Tp gcd(const _Tp &a, const _Tp &b) { return (!b) ? a : gcd(b, a % b); } template <typename _Tp> __inline__ __attribute__((always_inline)) _Tp abs(const _T...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a, b; a = 1023; b = 0; int l = 10; for (int i = 0; i < n; ++i) { char c; int num; cin >> c >> num; if (c == '&') { a &= num; b &= num; } else if (c == '|') { a |= num; b |= num; ...
8
#include <bits/stdc++.h> using namespace std; int s[2][2]; int main() { int n; while (scanf("%d ", &n) != EOF) { vector<long long> x; vector<long long> y; vector<pair<long long, long long> > p; for (int i = 0; i < n; ++i) { int a, b; scanf("%d %d ", &a, &b); x.push_back(a); y...
23
#include <bits/stdc++.h> const int MOD = (int)1e9 + 7; using State = std::vector<int>; int find(State &state, int x) { return state[x] == x ? x : state[x] = find(state, state[x]); } bool merge(State &state, int a, int b) { a = find(state, a); b = find(state, b); if (a == b) return false; state[a] = b; retur...
15
#include<bits/stdc++.h> using namespace std; #define loop(i, l, r) for(int i = (int) l; i <= (int) r; i++) #define rloop(i, r, l) for(int i = (int) r; i >= (int) l; i--) #define vi vector<int> #define ii pair<int, int> #define eb emplace_back #define all(x) begin(x), end(x) #define fi first #define se second #def...
16
#include <bits/stdc++.h> using namespace std; int n, m; struct node { int x, v; bool operator<(const node &ano) const { return x < ano.x; } } A[200010]; int q[200010], C[200010]; int halt() { printf("-1\n"); exit(0); } int main() { int d; scanf("%d%d%d", &d, &n, &m); for (int i = 1; i <= m; ++i) { sca...
14
#include <bits/stdc++.h> using namespace std; void maximize(int &a, int b) { a = std::max(a, b); } void minimize(int &a, int b) { a = std::min(a, b); } int main() { int mx = 2 * 1000 * 1000 * 1000; int mn = -mx; int n; cin >> n; while (n-- > 0) { string s; cin >> s; int x; cin >> x; string...
6
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } int a[511][511]; struct TPoint { int x, y; TPoint(int x, int y) : x(x), y(y) {} TPoint operator+(const...
18
#include <bits/stdc++.h> using namespace std; int main() { long long n, c = 0, j, temp = 0, t2 = 0, i; cin >> n; long long a[n]; for (i = 0; i < n; i++) { cin >> a[i]; c = c + a[i]; } t2 = c; sort(a, a + n); for (j = 0; j < n; j++) { if (j != n - 1) { c = c + a[j]; } temp = a[j...
4
#include <bits/stdc++.h> using namespace std; int arr[210]; int main(int argc, char* argv[]) { int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= m; ++i) scanf("%d", &arr[i]); int maxi = 0; for (int i = 1; i <= n; ++i) { int mini = n + 500; ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long k; cin >> k; long long arr[k]; for (int i = 0; i < k; i++) cin >> arr[i]; sort(arr, arr + k); long long ans = 0; long long prev = 25; for (int i = 0; i < k; i++) { if (arr[i] <= 25) continue; if (prev <= 25) ans += arr[i]...
0
#include <bits/stdc++.h> using namespace std; int c1[310], c2[310]; int main() { int x, t, a, b, da, db; while (scanf("%d %d %d %d %d %d", &x, &t, &a, &b, &da, &db) != EOF) { c1[0] = a, c2[0] = b; for (int i = 1; i < t; i++) { c1[i] = c1[i - 1] - da; c2[i] = c2[i - 1] - db; } c1[t] = 0; ...
4
#include <bits/stdc++.h> using namespace std; 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; } void __print(float x) { cer...
0
#include <bits/stdc++.h> template <typename _Tp> inline void read(_Tp &x) { x = 0; bool fg = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fg ^= 1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (_Tp)(ch ^ 48), ch = getchar(); if (fg) x = -x;...
22
#include <bits/stdc++.h> using namespace std; template <class T> T max(T a, T b, T c) { return ((a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c)); } template <class T> T min(T a, T b, T c) { return ((a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c)); } const int MOD = 1000000000 + 7; const int MAXN = 100000 + 9; int m...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1 || n == 2) cout << "1\n1"; else if (n == 3) cout << "2\n1 3"; else { cout << n << "\n"; for (int i = 2; i <= n; i += 2) cout << i << " "; for (int i = 1; i <= n; i = i + 2) { if (i == n || i == n -...
3
#include <bits/stdc++.h> const int N = 55, mo = (int)1e9 + 7; int n, k, cx, cy, d[N][N][2], f[N][N][2], C[N][N]; struct data { int x, y, s; } q[N * N * 2], *head = q, *tail = q; void renew(int x, int y, int s, int dis, int val) { if (f[x][y][s]) { if (d[x][y][s] == dis) (f[x][y][s] += val) %= mo; return; ...
13
#include <bits/stdc++.h> const int MAX_N = 1e3 + 10; int n, x, y, tot, pl, df, st[MAX_N]; int ask(int n) { printf("? %d ", n); for (int i = 1; i <= n; ++i) printf("%d ", st[i]); printf("\n"); fflush(stdout); int res; scanf("%d", &res); return res; } int find() { int L = 0, R = tot + 1; for (; L + 1 < ...
16