solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; char a[105][105], s[30]; vector<int> v[26]; int c[26], sn; queue<int> q; inline bool add(char* x, char* y) { int i; for (i = 0; x[i] && y[i]; i++) if (x[i] != y[i]) { v[x[i] - 'a'].push_back(y[i] - 'a'); c[y[i] - 'a']++; return 0; } if (x[i])...
8
#include <bits/stdc++.h> using namespace std; int a[100005] = {0}; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) scanf("%d", &a[i]); int ob = a[0]; for (int i = 1; i < n; ++i) { int t1 = a[i]; int t2 = ob; int c; if (t1 < t2) swap(t1, t2); while (t1 % t2 != 0) { c = t1 % ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 0, sum = 0; cin >> n; int a[n]; map<int, int> mp, tmp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; if (mp[a[i]] > 1) { m++; sum = INT_MAX; } } for (int i = 0; i < n; i++) { tmp = mp; int x ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int k; string str, res; cin >> str >> k; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; vector<int> freq(26); for (char ch :...
4
#include <bits/stdc++.h> using namespace std; struct line { int v, next; } e[200005]; int t, b[100005], n, x, y, sz[100005], X[100005], Y[100005], f[100005]; double s[100005], p[100005]; inline void build(int x, int y) { e[++t].v = y; e[t].next = b[x], b[x] = t; } void dfs(int u) { s[u] = p[u], sz[u] = 1; for...
17
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; int A[10], B[10]; const int INF = 1e9 + 9; long long int a, b; void solve() { while (a % 2 == 0) { a /= 2; A[2]++; } while (a % 3 == 0) { a /= 3; A[3]++; } while (a % 5 == 0) { a /= 5; A[5]++; }...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int a, b, c, d; cin >> n >> k >> a >> b >> c >> d; bool t1, t2; t1 = t2 = false; if (a > b) { swap(a, b); t1 = true; } if (c > d) { swap(c, d); t2 = true; } vector<int> res1, res2; if (a == c && b == d) { res1...
8
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 5e5 + 5; int a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; int now1 = 0, now2 = 0; for (int i = 0; i < n; i++) { if (s[i] == '(') { if ...
7
#include <bits/stdc++.h> using namespace std; const int Maxn = 50005; int n, q, tree_ct, cnt, top, a[Maxn], head[Maxn], lson[20 * Maxn], rson[20 * Maxn], fa[Maxn], anc[Maxn], dep[Maxn], sta[Maxn], f[Maxn][261]; struct edg { int nxt, to; } edge[2 * Maxn]; void add(int x, int y) { edge[++cnt] = (edg){head[x], y};...
24
#include <bits/stdc++.h> using namespace std; const int N = (1 << 21) + 1; int n, res, a[N], c[N], have[N]; void add(int mask, int id) { if (c[mask] > 1 || have[mask] == id) return; c[mask]++; have[mask] = id; for (int j = 0, ggd = 21; j < ggd; j++) if (mask & (1 << j)) add(mask ^ (1 << j), id); } int get(i...
18
#include <bits/stdc++.h> using namespace std; struct rect { long long x1, y1, x2, y2; rect() {} rect(long long x1, long long x2, long long y1, long long y2) { this->x1 = x1; this->x2 = x2; this->y1 = y1; this->y2 = y2; } }; rect find(long long up, long long down, long long left, long long right)...
14
#include <bits/stdc++.h> int main() { long long c, d; std::cin >> c >> d; long long n, m; std::cin >> n >> m; long long k; std::cin >> k; long long need = n * m - k; if (need <= 0) { std::cout << 0 << '\n'; return 0; } long long div = need / n; long long rem = need % n; long long v1 = di...
7
#include <bits/stdc++.h> using namespace std; const int BUFFER_SIZE = (1 << 16); char buffer[BUFFER_SIZE]; int position = BUFFER_SIZE; inline char getChar() { if (position == BUFFER_SIZE) { position = 0; fread(buffer, BUFFER_SIZE, 1, stdin); } return buffer[position++]; } inline int getInt() { register ...
21
#include <bits/stdc++.h> using namespace std; int main() { long n, m, l; long long a[200000] = {0}; long res, p, d, dem = 0; cin >> n >> m >> l; for (int i = 1; i <= n; i = i + 1) { cin >> a[i]; if (a[i] > l && a[i - 1] <= l) dem = dem + 1; } for (int k = 1; k <= m; k = k + 1) { cin >> res; ...
5
#include <bits/stdc++.h> using namespace std; const int N = 5010, inf = 0x3f3f3f3f; int n, a[N], ans, dp[N][N >> 1][2]; int main() { scanf("%d", &n); for (int i = (1); i <= (n); i++) scanf("%d", &a[i]); memset(dp, 0x3f, sizeof(dp)); for (int i = (0); i <= (n); i++) dp[i][0][0] = 0; dp[1][1][1] = 0; for (int...
11
#include <bits/stdc++.h> using namespace std; long int q, s[10]; long long n, m, qq; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> q; for (long int ec = 1; ec <= q; ec++) { cin >> n >> m; qq = m % 10; for (long int i = 1; i <= 9; i++) s[i] = (qq * i) % 10 + s[i - 1]; ...
4
#include <bits/stdc++.h> using namespace std; double dis(pair<double, double> a, pair<double, double> b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); } int main() { std::ios_base::sync_with_stdio(false); cout.precision(10); cout.setf(ios...
10
#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf; inline int qread() { register char c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++); register int x = 0, f = 1; while (c < '0' || c > '9') { if (c == '-...
15
#include <bits/stdc++.h> using namespace std; long long n, L, a, sum = 0, res = 0; int t[100005], l[100005]; int main() { cin >> n >> L >> a; if (n == 0) { cout << L / a; return 0; } for (int i = 1; i <= n; i++) cin >> t[i] >> l[i]; for (int i = 1; i <= n; i++) { if (t[i] == sum) { sum += l[...
2
#include <bits/stdc++.h> using namespace std; int u[1000]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int t; cin >> t; u[t]++; } int s = 0; for (int i = 0; i <= 1000; i++) { s += u[i] / 2; } cout << s / 2; }
2
#include <bits/stdc++.h> using namespace std; int fa[3010 * 6010]; int find(int x) { if (fa[x] != x) fa[x] = find(fa[x]); return fa[x]; } int ax[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; int ay[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int n, m, Q; bool inside(int x, int &y) { if (x < 0 || x >= n) return false; if (y == -1) y ...
21
#include <bits/stdc++.h> const double EPS = 1e-9; const int MOD = 1000003; const int INF = 2000 * 1000 * 1000; const int MAX = 4000000; using namespace std; int popcount(int n) { bitset<32> b(n); return b.count(); } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b)...
2
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int main() { int n, k; std::vector<std::vector<int> > a(1000001); cin >> n; int x; for (int i = 0; i < n; i++) { cin >> x; a[x].push_back(i); } int maxnum = 0; int l = 0, r = 9999999; for (int i = 1; i < 1000001; i++) { ...
5
#include <bits/stdc++.h> using namespace std; void solve() { long long alice, bob; cin >> alice >> bob; long long n = alice + bob; if (n == 1) { cout << "2\n0 1\n"; return; } set<long long> ans; { long long a = alice; long long b = bob; long long p = min(a, b); long long a_end = 1e...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long qpow(long long a, long long b, long long p) { long long res = 1; while (b) { if (b & 1) res = res * a % p; b >>= 1; a = a * a % p; } return res; } map<long long, long long> ma; long long dfs(long long x) { if (m...
12
#include <bits/stdc++.h> using namespace std; int main() { string s; getline(cin, s); vector<char> a = {}; for (int i = 1; i < s.length(); i++) { if (s[i] == '{' || s[i] == '}' || s[i] == ',' || s[i] == ' ') { continue; } int c = 0; for (int j = 0; j < a.size(); j++) { if (a[j] == s[...
0
#include <bits/stdc++.h> using namespace std; int n; map<int, int> m, mem; void f(int x) { for (int i = 2; i * i <= x; i++) { int ct = 0; while (x % i == 0) x /= i, ct++; if (ct) m[i] |= (1 << (ct - 1)); } if (x > 1) m[x] |= (1 << 0); } int solve(int x) { if (mem.count(x)) return mem[x]; int ct = ...
14
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<string> a(N + 2); for (int i = 1; i <= N; ++i) cin >> a[i], a[i] = " " + a[i]; vector<int> row(N + 2, 0), col(N + 2, 0); reverse(a.begin() + 1, a.begin() + N + 1); int sol = 0; for (int i = 1; i < N; ++i) for (int j =...
12
#include <bits/stdc++.h> using namespace std; void FWT(long long *A, int l) { for (int len = 1; len < l; len <<= 1) for (int i = 0; i < l; i += len << 1) for (int j = 0; j < len; ++j) { long long x = A[i + j], y = A[i + j + len]; A[i + j] = (x + y); A[i + j + len] = (x - y); } ...
18
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long arr[n]; long long mini = LONG_MAX; int flag = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); long long ans = 0; for (int i = 1; i < n; i++) { long long val = arr[i] - ar...
1
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') neg = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x * neg; } inline void print(long long x) { if (x < 0)...
9
#include <bits/stdc++.h> using namespace std; vector<int> adj[200200]; bool rev[200200]; int pa[200200], son[200200][2], val[200200], sz[200200], flag[200200]; int mx[200200]; int B[200200 << 1], N; void update(int u, int d) { for (; u <= N; u += u & -u) B[u] += d; } int calc(int u, int ans = 0) { for (; u; u -= u ...
26
#include <bits/stdc++.h> using namespace std; const long long modulo = 1000000007; const int inf = 0x3f3f3f3f; const long long ll_inf = 0x3f3f3f3f3f3f3f3f; int main() { int n, M; cin >> n >> M; int a[n]; int baseline = 0; int lasti = 0; bool on = true; for (int i = 0; i < n; i++) { cin >> a[i]; if...
7
#include <bits/stdc++.h> using namespace std; int main() { string s, st; bool b = 0, ans = 1; cin >> s; int n; cin >> n; while (n--) { cin >> st; b = 0; if (st.size() != s.size()) continue; for (int i = 0; i < st.size(); i++) { if (s[i] == toupper(st[i])) continue; else i...
4
#include <bits/stdc++.h> using namespace std; template <typename T> T in() { char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == '-') { ng = true; ch = getchar(); break; } if (ch >= '0' && ch <= '9') break; } while (1) { n = n * 10 + (ch - '0'); ...
14
#include <bits/stdc++.h> using ll = long long; const int maxn = 5e5 + 22; int n, nxt[maxn]; ll d, m, ans; struct station { ll x, c; } p[maxn]; int main() { scanf("%lld%lld%d", &d, &m, &n); for (int i = 1; i <= n; ++i) scanf("%lld%lld", &p[i].x, &p[i].c); std::sort(p + 1, p + n + 1, [](station a, station b) { re...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int x[100], d[100]; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> d[i]; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (x[i] + d[i] == x[j] && x[j] + d[...
2
#include <bits/stdc++.h> using namespace std; long long n, cnt, x, y, arr[3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> x >> y; for (long long i = 0; i <= 2; i++) arr[i] = y; while (arr[0] != x) { arr[0] = min(arr[1] + arr[2] - 1, x); sort(arr, arr + 3); cnt++; } cout << cn...
8
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long mod = 1e9 + 7; const long long N = 1e5 + 10; inline long long add(long long x, long long y) { x += y; if (x >= mod) x -= mod; return x; } inline long long mul(long long x, long long y) { x = (1LL * x * y) % mod; return x...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 8; inline bool check(const long long &a, const long long &b, long long &suml, const long long &t, const long long &m, const long long &mid) { if (a + (mid - 1) * b > t) return false; if ((2 * a + (mid - 1) * b) ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 5, maxm = 2e5 + 5; int l[maxn], id[maxn]; int mx[maxn]; int f[maxn]; bool vis[maxm]; int read() { int x = 0, y = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') y = -1; ch = getchar(); } while (ch >= '0' && ch <...
13
#include <bits/stdc++.h> using namespace std; long long int n, k, l, m, t, a, b, s, r, c, temp1, temp2, x, y, temp, q, d, mod = 1e9 + 7, w; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; deque<char> dq; for (int i = 0; i < s.length(); i++) { while (!dq.empty() && s...
3
#include <bits/stdc++.h> using namespace std; const int MIN = (int)(-1e9 - 2e5); const int MAX = (int)(+1e9 + 2e5); vector<int> get(int lower, int upper, int n) { vector<int> res(n); if (lower >= 0) { for (int i = 0; i < n; ++i) { res[i] = lower + 1 + i; } } else if (upper <= 0) { for (int i = 0...
14
#include <bits/stdc++.h> using namespace std; int fa[1000001], m, n, q, i, v, r, c; int find(int x) { if (x == fa[x]) { return x; } fa[x] = find(fa[x]); return fa[x]; } int main() { cin >> n >> m >> q; for (i = 1; i <= m + n; i++) { fa[i] = i; } for (i = 1; i <= q; i++) { cin >> r >> c; ...
11
#include <bits/stdc++.h> using namespace std; const int MMax = 1500; int N, M; map<pair<pair<int, int>, long long>, pair<vector<long long>, vector<long long> > > Map; int X[MMax], Y[MMax], R[MMax]; long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } pair<pair<int, int>, long long> getline(...
16
#include <bits/stdc++.h> const int kMaxn = 505, kMaxm = 1e6 + 10, kLg = 11, MOD = 998244353; int n, m; int C[kMaxm]; int low[kLg][kMaxn << 1], DP[kMaxn << 1][kMaxn << 1]; int pw[kLg], Lg[kMaxn << 1]; std::vector<int> pos[kMaxn]; int Low(int l, int r) { int p = Lg[r - l + 1]; return std::min(low[p][l], low[p][r - pw...
18
#include <bits/stdc++.h> using namespace std; char Map[2005][2005]; queue<pair<int, int> > q; int mox[4] = {-1, 0, 1, 0}; int moy[4] = {0, 1, 0, -1}; char cg[4] = {'v', '<', '^', '>'}; int n, m; bool ispoint(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m && Map[x][y] == '.'); } int deg(int x, int y) { i...
12
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream& operator<<(ostream& out, const pair<T1, T2> p) { out << '(' << p.first << ',' << p.second << ')'; return out; } template <class T1, class T2> istream& operator>>(istream& in, pair<T1, T2>& p) { in >> p.first >> p.second; return...
18
#include <bits/stdc++.h> using namespace std; const int NMAX = (int)15e4; int N, K, Q; int t[NMAX]; set<int> window; void addonline(int i) { --i; window.insert(-t[i]); if (window.size() > K) { set<int>::iterator it = window.end(); --it; window.erase(it); } } bool checkonline(int i) { --i; return...
4
#include <bits/stdc++.h> using namespace std; set<int, greater<int> > se; int main() { int N; scanf("%d", &N); for (int i = 0; i < N; i++) { int a; scanf("%d", &a); while (true) { if (se.find(a) == se.end()) { se.insert(a); break; } se.erase(a); a++; } } ...
8
#include <bits/stdc++.h> using namespace std; int s(int x) { int y = 0; while (x) y++, x /= 10; return y; } long long n, z = 0, k, x; int a[] = {4, 7, 44, 77, 47, 444, 447, 474, 477, 744, 777, 747, 744, 774}; int main() { long long T; T = 1; while (T--) { string s, a; cin >> s >> a; if (s.size()...
0
#include <bits/stdc++.h> using namespace std; string ret[256] = {"!x&x", "!(x|y|z)", "!x&!y&z", "!x&!y", "!x&!z&y", "!x&!z", "!(!y&!z|x|y&z)", "!(x|y&z)", "!x&y&z", ...
16
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; int i = 0, j = 0; int lens1 = s1.size(); int lens2 = s2.size(); while (s1[i] == '0') { i++; } while (s2[j] == '0') { j++; } if (lens1 - i > lens2 - j) { printf(">\n"); } else if (lens1 - i < lens...
1
#include <bits/stdc++.h> using namespace std; namespace FGF { int n, m; const int N = 2e5 + 5; int a[N], b[N], p[N], vis[N], cnt, head[N], fa[N], ins[N], ok[N]; vector<int> V, tmp; struct edg { int to, nxt, w; } e[N]; void add(int u, int v, int w) { cnt++; e[cnt].to = v; e[cnt].nxt = head[u]; head[u] = cnt; ...
23
#include <bits/stdc++.h> int main() { int l, i, j; char ch[100]; char ch1[] = {'H', 'Q', '9'}; scanf("%s", ch); l = strlen(ch); for (i = 0; i < 3; i++) { for (j = 0; j < l; j++) { if (ch[j] == ch1[i]) { printf("YES"); return 0; } } } printf("NO"); }
1
#include <bits/stdc++.h> using namespace std; struct node { int x, y, z; bool operator<(const node &b) const { return x < b.x; } } p[500020]; int n; int my[500020], mz[500020]; int P, Q, R; int mx[500020 << 2], mi[500020 << 2]; long long sum[500020 << 2], lazy[500020 << 2]; void upd(int x, int ll, int rr, int i) { ...
20
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, a[N]; double ans, ans1, t[N]; void change(int x, int v) { for (; x <= n; x += x & (-x)) t[x] += v; } double ask(int x) { double s = 0; for (; x; x -= x & (-x)) s += t[x]; return s; } int main() { scanf("%d", &n); for (int i = (int)(1...
16
#include <bits/stdc++.h> using namespace std; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first < b.first; else return a.second > b.second; } int main() { int t; int n; cin >> t; while (t--) { cin >> n; pair<int, int> ar[n]; int bl[n + 1]; for (int...
6
#include <bits/stdc++.h> using namespace std; int n, a[10]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); bool ans = 1; for (int i = 1; i < n; i++) { if (abs(a[i - 1] - a[i]) >= 2) ans = 0; } if (ans) return 0 * puts("YES"); puts("NO"); return 0; }
8
#include <bits/stdc++.h> using namespace std; const long long MAX = 100005; const long long mod = 1.0e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; long long n = s.length(); long long i, j, sum = 0; map<long long, long long> mp; for (i = 0...
12
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; string x; cin >> x; bool z = false; for (int i = 0; i < n; i++) { if (z) { cout << '0'; continue; } if (x[i] == '2') cout << '1'; i...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int P = 998244353, g = 3; int power(int a, int b) { int ans = 1; int t; for (t = a; b; b >>= 1) { if (b & 1) ans = 1ll * ans * t % P; t = 1ll * t * t % P; } return ans; } int wn[30]; void get_wn()...
21
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; cout << "2" << endl; for (long long i = 2; i <= n; ++i) { cout << (i + 1) * (i + 1) * i - (i - 1) << endl; } return 0; }
8
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> adj[1005]; int sz[1005]; void dfs(int node, int par) { sz[node] = int(adj[node].size()) - 1; for (auto it : adj[node]) { if (it != par) { dfs(it, node); sz[node] += sz[it]; } } } signed main() { ios::sync_with_st...
8
#include <bits/stdc++.h> using namespace std; const int N = 400005; int n; struct point { int id, x, y; bool operator<(point a) const { return y < a.y; } }; vector<point> qe[1005]; int main() { cin >> n; int i, j, k1, k2; int fg1[1005]; memset(fg1, 0, sizeof(fg1)); for (i = 1; i <= n; i++) { scanf("%d...
13
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; int m = (long long int)sqrt((double)n); for (long long int i = 3; i <= m; i += 2) { if (n % i == 0) return false; } return true; } int main(voi...
10
#include <bits/stdc++.h> using namespace std; void input(int &n, int &k, int *&stress) { cin >> n >> k; stress = new int[k + 1]; for (int i = 0; i <= k; i++) { stress[i] = 0; } int last1 = 0, last2 = 0, temp = 0; for (int i = 0; i < n; i++) { last1 = last2; last2 = temp; cin >> temp; if ...
8
#include <bits/stdc++.h> using namespace std; long long n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; cout << n - ((n / 2) + (n / 3) + (n / 5) + (n / 7) - (n / 6) - (n / 10) - (n / 14) - (n / 15) - (n / 21) - (n / 35) + (n / 30) + (n / 42) + (n ...
3
#include <bits/stdc++.h> using namespace std; vector<int> s, x, y; istream& operator>>(istream& is, vector<int>& p) { string in; cin >> in; for (int i = (0); i < (int)(in.length()); ++i) p.push_back(in[i] - '0'); return is; } struct node { int next[10], go[10], par, link; int chr; bool leaf; node() { ...
24
#include <bits/stdc++.h> using namespace std; vector<vector<int> > Gr(1e5 + 5); vector<bool> Vis(1e5 + 5, 0); stack<int> Sk; map<int, bool> Map; bool flag = 1; void Topo(int S) { if (!flag) return; Vis[S] = 1; Map[S] = 1; for (auto i = Gr[S].begin(); i != Gr[S].end(); i++) { if (Map[*i]) { flag = 0; ...
8
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double EPS = 1e-9; const long long MOD = 1e9 + 7; const int INF = 1e9; long long addMod(long long a, long long b) { if (a + b >= MOD) return a + b - MOD; return a + b; } long long mulMod(long long a, long long b) { return (a * b) % MOD;...
15
#include <bits/stdc++.h> using namespace std; bool visited[300000]; long long int parent[300000]; void initialise() { for (long long int i = 0; i < 300000; i++) { visited[i] = false; parent[i] = i; } } pair<long long int, long long int> dfs( vector<pair<long long int, long long int>> adj[], long long in...
10
#include <bits/stdc++.h> using namespace std; struct info { int x, y, z; long long int c; info() {} info(int xx, int yy, int zz, long long int cc = 0) { x = xx; y = yy; z = zz; c = cc; } }; int n, q, sub[100000 + 10], vis[100000 + 10]; info edge[100000 + 10]; vector<int> graph[100000 + 10]; in...
11
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); map<char, int> mp; int k = 0; for (char j = '0'; j <= '9'; j++) { mp[j] = k; k++; } for (char j = 'A'; j <= 'Z'; j++) { mp[j] = k; k++; } string s; cin >> s; string s1 = "...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string a, b; cin >> a >> b; int n1 = a.length(), n2 = b.length(); int n3 = max(n1, n2); int dp[n1 + 1][n2 + 1][n3 + 1]; array<int, 4> prv[n1 + 1][n2 + 1][n3 + 1]; for (int i = 0; i <= n1; i++) ...
14
#include <bits/stdc++.h> using namespace std; void in() {} map<char, int> mp; int main() { in(); string str; int n, cnt = 0; cin >> n >> str; for (int i = 0; i < n; ++i) mp[str[i]]++; for (char ch = 'a'; ch <= 'z'; ++ch) { int k = mp[ch] - 1; cnt += max(0, k); for (char c = 'a'; c <= 'z'; ++c) {...
2
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return a > b; } void solve() { string s; cin >> s; bool div3 = false, div2 = false, onezero = false, morezero = false; long long int ans = 0; for (long long int i = 0; i < s.length(); i++) { int dig = s[i] - '0'; ans += dig; i...
2
#include <bits/stdc++.h> using namespace std; int n, m, a[501][501]; void solve() { cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> a[i][j]; } } for (int i = 1; i <= n; ++i) { int firstValue = a[i][1]; for (int j = 2; j <= m; ++j) { if (firstValue ...
8
#include <bits/stdc++.h> int main() { int n, k, i, l, sum = 0, count = 0; scanf("%d %d", &n, &k); l = 240 - k; i = 1; for (i = 1; i <= n; i++) { sum = sum + 5 * i; if (sum <= l) { count++; } } printf("%d\n", count); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const long long linf = (long long)1e18; template <class TAT> inline void read(TAT &res) { char c; res = 0; bool neg = false; while (c = getchar(), c != '-' && (c < '0' || c > '9')) ; if (c == '-') neg = true, c = getchar(); do res =...
17
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5+2; int mp[MAXN]; vector<int> v[MAXN]; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int n, m; cin >> n >> m; vector<int> a(n+1), b(n+1); for(int i = 1; i...
8
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; cin >> n >> s; bool fl = false, fll = false; string ans; int cnt = 0, i, j; for (i = 0; i < n; ++i) { if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') { if (s[i] == 'a' ...
8
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; void go() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long int N = 2e5 + 2; struct node { int val; int a, b, c; node() { val = a = b = c = 0; } node(int val1, int a1, int b1, int c1) { ...
2
#include <bits/stdc++.h> using namespace std; long long mul(long long a, long long b) { return ((a % 998244353) * (b % 998244353)) % 998244353; } long long add(long long a, long long b) { return ((a % 998244353) + (b % 998244353)) % 998244353; } long long sub(long long a, long long b) { return ((a % 998244353) - ...
10
#include <bits/stdc++.h> using namespace std; int m[10]; int w[10]; int getScore(int index, int m_value, int w_value) { int score = (index + 1) * 500; int value1 = score / 10 * 3; int value2 = score - m_value * score / 250 - 50 * w_value; return max(value1, value2); } int main() { int i, j, t; int hack1, ha...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, p, c = 0, c4, c7, q; cin >> n; p = n; while (p != 0) { p = p / 10; c++; } if (c % 2 == 0) { i = 0, p = 0, q = 0; while (i != c / 2) { p = p * 10 + 7; q = q * 10 + 4; i++; } i = 0; whi...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; char a[222][222]; bool flag[222]; int main() { int n, m; while (cin >> m >> n) { memset(a, 0, sizeof(a)); map<int, bool> no; for (int i = 0; i < m; i++) scanf("%s", a[i]); vector<int> vec(n); bool equ = true; for (int i = ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int s, x = 0, y = 0, count; int q; cin >> q; while (q--) { count = 0; cin >> s; while (s) { count += (s - (s % 10)); x = s / 10; s = s % 10; s += ...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { int n, m, f[100000], b[100000]; cin >> n >> m; int cnt[100001]; memset(cnt, 0, sizeof(cnt)); bool ok = false; for (int i = 0; i < (n); i++) { scanf("%d", &f[i]); cnt[f[i]]++; } for (int i = 0; i < (m); i++) { sca...
7
#include <bits/stdc++.h> using namespace std; int main() { long long t, i, x, cnt, sum, tmp; cin >> t; while (t--) { string s; cnt = 0, sum = 0, tmp = 0; cin >> s; for (i = 0; i < s.length(); i++) { x = s[i] - '0'; if (x == 0) cnt++; else if (x % 2 == 0) tmp++; ...
2
#include <bits/stdc++.h> using namespace std; int N, cartomap[1000006], rtol[200006], ltor[200006]; set<pair<int, int> > validp; struct ss { int left, right; int nxt, dist; ss() {} ss(int l, int r) { left = l, right = r; if (l == 1) { nxt = 1; dist = r - l + 1; return; } if (r ...
14
#include <bits/stdc++.h> using namespace std; void solve() { int n, qq; set<int> p; multiset<int> d; auto Add = [&](int x) { auto ret = p.insert(x); assert(ret.second); auto it = ret.first; if (next(it) != p.end() && it != p.begin()) { d.erase(d.find(*next(it) - *prev(it))); } if (...
13
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int a[200003]; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n, x, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x; v.push_back({x, i}); } sort(v.begin(), v.end()); long lon...
6
#include <bits/stdc++.h> using namespace std; long long a[1000005]; set<long long> s; int main() { long long n, i, t; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; s.insert(a[i] + i); } long long sz = s.size(); if (sz == n) { i = 1; for (auto it = s.begin(); it != s.end(); it++) { ...
14
#include <bits/stdc++.h> using namespace std; int n, num, a, sum, cnt, mn = 1e7; int main() { scanf("%d", &n); num = 2 * n - 1; for (int i = 0; i < num; i++) { scanf("%d", &a); if (a < 0) cnt++; sum += abs(a); if (abs(a) < mn) mn = abs(a); } if (!(n % 2) && (cnt % 2)) sum -= 2 * mn; printf("...
10
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; vector<int> ls[110]; class UFDS { vector<int> ps, size; int n; public: UFDS(int N) : ps(N + 1), size(N + 1), n(N) { for (int i = 1; i <= n; ++i) { ps[i] = i; size[i] = 1; } } bool same_set(int i, int j) { return par...
6
#include <bits/stdc++.h> using namespace std; const int m = 1e9 + 7; int u, v, mod, x, a[105]; map<int, vector<int> > mp; inline int myrand() { return x = (1LL * x * 17 + 13) % m; } inline int ksm(int x, int n) { int ret = 1; while (n) { if (n & 1) ret = 1LL * ret * x % mod; n >>= 1; x = 1LL * x * x % m...
19
#include <bits/stdc++.h> using namespace std; long long a[5]; long long book[5]; string s; const long long inf = 1e18 + 5; long long ans; void dfs(long long p) { if (p == 3) { for (long long i = 0; i < 4; i++) if (!book[i]) ans = min(ans, a[i]); return; } for (long long i = 0; i < 4; i++) { for ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t = 1; cin >> t; while (t--) { int n; cin >> n; string a, b; cin >> a >> b; vector<int> v1, v2; a += '0'; b += '0'; for (int i = 1; i <= n; i++)...
5
#include <bits/stdc++.h> using namespace std; using namespace std; pair<int, int> pnts[100100]; pair<long double, long double> line(int x1, int x2, int y1, int y2) { long double m = ((long double)(y1 - y2) * (1.0)) / (x1 - x2); long double c = (long double)(y1) - (m * x1); return make_pair(m, c); } long double di...
10