solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; if (s.size() == 1) cout << s << '\n'; else { string t = s; for (int i = 1; i < t.size(); ++i) { t[i] = '9'; } if (t > s) --t[0]; els...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; const long long mod = 1e9 + 7, INF = 1 << 30; long long n, r, avg, tl = 0, res = 0; vector<pair<long long, long long> > a; void init(void) { scanf("%I64d%I64d%I64d", &n, &r, &avg); for (int i = 1; i <= n; i++) { pair<long long, long long> x;...
6
#include <bits/stdc++.h> using namespace std; bool sortbysec(long long a, long long b) { return (a > b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n, i, j, a, b, c, d; cin >> n; vector<long long> v(n), v1(n); set<long long int> s, s1; for (long long in...
8
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } int main() { int n, k, x, ans = 0; scanf("%d%d%d", &n, &k, &x); for ...
0
#include <bits/stdc++.h> using namespace std; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void pvp(T a, T b) { for (T i = a; i != b; ++i) cout << "(" << i->first << ", " << i->second << ") "; cout << endl; } template <class T> void ...
17
#include <bits/stdc++.h> using namespace std; int main() { int i, n, a; cin >> n; char s[101]; int len; for (i = 0; i < n; i++) { cin >> s; len = strlen(s); if (len > 10) { cout << s[0] << len - 2 << s + (len - 1) << "\n"; } else { cout << s << "\n"; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; long long in() { int32_t x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%lld", &x); return x; } inline void read(long long *a, long long n) { for (long long i = 0; i < n; i++) a[i] = in(); } inline void readL(long long *a, long lo...
12
#include <bits/stdc++.h> using namespace std; long long a[1001][1001]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> a[i][j]; } } long long t = a[1][2] * a[1][3] / a[2][3]; t = sqrt(t); cout << t << ' '; for (int i = 2; i <= n; i++) cout...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> arr; vector<string> arr_res; arr_res.resize(n); arr.resize(n); for (int i = 0; i < n; i++) { string s; cin >> s; arr[i] = s; arr_res[i] = s; } for (int i = 0; i < n; i++) { for (int j...
3
#include <bits/stdc++.h> using namespace std; string s, s1; long long dp[105][5]; int n; void calc() { memset(dp, 0, sizeof(dp)); if (s[0] != s[1]) { dp[0][0] = 1, dp[0][2] = 1; } else dp[0][0] = 1; for (int i = 1; i < (int)s.size(); i++) { if (s[i] == 'A') { if (s[i - 1] == 'B') dp[i]...
13
#include <bits/stdc++.h> using namespace std; struct candy { int v, u; } c[100100]; int n, m, temp; int x, y, z, p; int main() { scanf("%d %d %d %d %d %d", &n, &m, &x, &y, &z, &p); for (int i = 1; i <= p; i++) scanf("%d %d", &c[i].v, &c[i].u); x %= 4; y %= 2; z %= 4; switch (x) { case 1: for (in...
7
#include <bits/stdc++.h> using namespace std; long long n, b, k, x; long long mod = 1000000007; long long mul(long long a, long long b) { a = a % mod; b = b % mod; return a * b % mod; } long long add(long long a, long long b) { return (a + b) % mod; } vector<vector<long long> > t; vector<vector<long long> > mat_m...
12
#include <bits/stdc++.h> const double eps = (1e-5); using namespace std; int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; } int setBit1(int num, int idx) { return num | (1 << idx); } long long setBit0(long long...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 2100; int n, N, K, B[maxn], An[maxn]; char T[maxn], *A[maxn]; struct Tpair { int x, y; Tpair(int _x = 0, int _y = 0) { x = _x, y = _y; } inline bool operator<(const Tpair &b) const { return x != b.x ? x < b.x : y < b.y; } inline bool operator!...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; long long n; cin >> n; bool found = 0; string arr[n + 1]; for (long long i = 1; i <= n; i++) { cin >> arr[i]; if (arr[i] == s) { found = 1; } } if (foun...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); vector<int> a(n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); sort(a.begin(), a.end()); int ans; if (k == 0) { ans = a[0] - 1; } else { ans = a[k - 1]; } int cnt = 0; for (int i = 0; i < n; ++i...
4
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") const int N = 1e5 + 5; const int M = 105; int n, m, check[N], nex[N]; int dp[N], minn[N], st[4 * N], st1[4 * N]; pair<int, int> ant[M]; void update(int id, int l, int r, int i, int val) { if (l > i || r < i) { return; } if (l == r) { ...
14
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { if (y == 0) return 1; else if (y % 2 == 0) return ((power(x, y / 2)) * (power(x, y / 2))); else return (((x * (power(x, y / 2)))) * (power(x, y / 2))); } long long ceiling(long long d, long long x) { long long ...
9
#include <bits/stdc++.h> using namespace std; int dp[55][55][55][55]; int n, m; int s; vector<pair<int, int> > nei[55]; int cnt[55]; int dist[55][55]; int CountCriminals(int now, int lst) { int sum = cnt[now]; for (auto i : nei[now]) { if (i.first != lst) { sum += CountCriminals(i.first, now); } } ...
19
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long q, c, m, x; cin >> q; while (q--) { cin >> c >> m >> x; long long tmp = min(min(m, c), x), res = tmp; c -= tmp; m -= tmp; if (c == 0 || m == 0) cout << res << "\n"...
4
#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 int N = 2e5 + 7; int p[N], l[N], st[N], en[N], t, lvl[N]; vector<int> adj[N]; void dfs(int u, int P) { p[u] = P; lvl[u] = lvl[P] + 1; st[u] = ++t; for (int v : adj[u]) if (v != P) { dfs(v, u); } en[u] = ++t; } int chk(int a, int b) { return st[...
11
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; long long cnt = 1, lnt = 2; while (true) { a -= cnt; cnt += 2; if (a < 0) { cout << "Vladik"; break; } b -= lnt; lnt += 2; if (b < 0) { cout << "Valera"; break; } }...
0
#include <bits/stdc++.h> using namespace std; constexpr int64_t inf = numeric_limits<int64_t>::max() / 2; int64_t truncAdd(int64_t a, int64_t b) { int64_t c = a + b; if (c > inf) { c = inf; } return c; } struct PWL { int64_t slopeStarts[6]; int64_t yIntercept; friend ostream& operator<<(ostream& o, PW...
18
#include <bits/stdc++.h> using namespace std; string a, b, c; int len1, len2, len3, nu1 = 0, nu2 = 0, nu = 0; unsigned long long h1[2005], h2[2005], b1[2005], b2[2005], h[4000005]; int lo1[2005], lo2[2005]; void pre() { b1[0] = b2[0] = 1; for (int i = 1; i < 2005; i++) { b1[i] = 19760817 * b1[i - 1]; b2[i] ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; scanf("%I64d%I64d", &n, &m); long long sol = max(0LL, n - m * 2); printf("%I64d ", sol); for (int i = 0; i <= n; i++) if (1LL * i * (i - 1) / 2 >= m) { printf("%d", n - i); break; } return 0; }
5
#include <bits/stdc++.h> using namespace std; long long const mod = 1e9 + 7; long long power(long long x, long long y, long long mod = 2e18) { long long ans = 1; x %= mod; while (y) { if (y & 1) ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1; } return ans; } long long gcd(long long a, long long...
2
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 1ll << 60; const double PI = acos(-1.0); const int maxn = 100500; int a[maxn], b[maxn]; int pos[maxn]; int n, m, d, k; long long x; int getNextX() { x = (x * 37 + 10007) % 1000000007; return x; } void initAB() { for (i...
15
#include <bits/stdc++.h> using namespace std; int n, m, k; char s[100][105]; int d[100][100][11], p[100][100][11], pq[100][100][11]; string ans; int main() { scanf("%d%d%d", &n, &m, &k), ++k; for (int i = 0; i < (int)(n); ++i) scanf("%s", s[i]); for (int i = 0; i < (int)(n); ++i) for (int j = 0; j < (int)(m);...
11
#include <bits/stdc++.h> using namespace std; int n, m; double w; double milk[1001]; vector<pair<int, double> > cups[1001]; vector<int> cnt[1001]; bool eps_gt(double a, double b) { if ((a - b) > 1e-8) return 1; return 0; } bool eps_lt(double a, double b) { if ((a - b) < -(1e-8)) return 1; return 0; } bool eps_e...
11
#include <bits/stdc++.h> using namespace std; const int N6 = 1e6 + 6, N3 = 1e3 + 6, oo = 1e9 + 9, base = 1e9 + 7; const long long ool = 1e18 + 9; int n; bool pr[N6], u[N6]; vector<int> v, v2; vector<pair<int, int> > ans; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = 2; i <...
17
#include <bits/stdc++.h> using namespace std; const int MX = 77; int dp[MX][MX][MX][2]; int n, cnt[3][MX]; string str; vector<int> occK, occV, occR; int calc(int V, int K, int R, int flag) { if (V + K + R == n) return 0; int &ret = dp[V][K][R][flag]; if (ret != -1) return ret; ret = (1 << 30); if (V + 1 <= oc...
17
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <vector> #define LSOne(S) ((S) & -(S)) ...
5
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); { string s; cin >> s; long long n = (long long)s.size(); cout << 3 << endl; cout << "L " << n - 1 << endl; cout << "R " << n - 1 << endl; cout << "R " << 2 * n - 1 << endl; ...
6
#include <bits/stdc++.h> using namespace std; int f[5], A[1010][1010], P[1010], n, m, i, j, k, t, q, N, ss; char s[1010][1010], S[1010][1010]; int main() { f[4] = 4; f[3] = 2; f[2] = 3; f[1] = 1; f[0] = 0; scanf("%d%d", &n, &m); P[0] = 1; for (i = 1; i <= n; i++) P[i] = (P[i - 1] * 5ll) % 1000000007; ...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s1, s2; cin >> s1 >> s2; for (long long i = 0; i < s1.length(); i++) { if (s1[i] == '1' && s2[i] == '0') { cout << "1"; } else if (s1[i] == '0' && s2[i] == '1...
0
#include <bits/stdc++.h> using namespace std; int x[2020][2020]; int t[2020][2020]; int main() { int n; cin >> n; memset(x, 0, sizeof(x)); char s; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { cin >> s; if (s == '0') x[i][j] = 0; else x[i][j] = 1; } fo...
12
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; long long a[1010]; cin >> n >> k; long long i, j; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long ans = 0; for (i = 0; i < n; i++) { while (k * 2 < a[i]) { ans++; k = k * 2; } k = max(a[i], ...
8
#include <bits/stdc++.h> using namespace std; int X, Y, A, B, i, j, k, l, P; int main() { scanf("%d%d%d%d", &X, &Y, &A, &B); for (i = A; i <= X; i++) { for (j = B; j <= Y; j++) { if (i > j) P++; } } printf("%d\n", P); for (i = A; i <= X; i++) { for (j = B; j <= Y; j++) { if (i > j) pri...
3
#include <bits/stdc++.h> using namespace std; char ar[1000], er[1000]; void oku() { int i, t, a; scanf("%s", ar); scanf("%d", &t); a = strlen(ar); for (int i = 0; i < a; i++) if (ar[i] <= 'Z') ar[i] += 32; for (int i = 0; i < a; i++) { if (ar[i] < 97 + t) ar[i] = ar[i] - 32; } cout << ar << endl...
6
#include <bits/stdc++.h> using namespace std; int n; int ans = 0, ss[500000]; int main() { scanf("%d", &n); for (int i = 2; i <= n; i += 2) { ss[++ans] = i; } for (int i = 1; i <= n; i += 2) { ss[++ans] = i; } for (int i = 2; i <= n; i += 2) { ss[++ans] = i; } printf("%d\n", ans); for (int...
8
#include <bits/stdc++.h> using namespace std; template <typename T> void print(const vector<T>& a, const string& name = "") { if (!name.empty()) cout << name << ": "; for (const auto& item : a) { cout << item << " "; } cout << endl; } template <typename T1, typename T2> void print(const pair<T1, T2>& p, c...
7
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int cnt = 0; for (int i = 1; i < n - 1; i++) { if (a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1) { if (i + 3 < n && a[i + 2] == 0 && a[i + 3] == 1) { a[i + 1] = 0...
2
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int n, k; cin >> n; pair<int, int> *c = new pair<int, int>[n + 2]; int *a = new int[n + 2]; int *b = new int[n + 2]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { c...
5
#include <bits/stdc++.h> int min(int a, int b) { return a < b ? a : b; } int main() { static char aa[4000 + 1], bb[4000 + 1]; static int dp[4000 + 1][4000 + 1], dq[4000 + 1][4000 + 1], pp[4000][26], qq[4000][26]; int n, m, ti, td, tr, te, i, j, a, b; scanf("%d%d%d%d%s%s", &ti, &td, &tr, &te, aa, bb), n = ...
18
#include <bits/stdc++.h> using namespace std; int n; long double score = 0.0; long double prop[100005]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> prop[i]; score -= prop[i]; } long double bck = 0.0; for (int i = 0; i < n; i++) score += (2.0 * (1 + bck) * prop[i]), bck = (bck + 1.0...
12
#include <bits/stdc++.h> using namespace std; int n, p2[10], p3[10]; long long a[10]; int f[10][10][6666], g[10][444], ans, OR[6666][444], r32[6666], cost[1000000 + 10], prime[1000000 + 10], kA[10], s[444]; int bit2(int mask, int x) { return (mask >> x) % 2; } int bit3(int mask, int x) { return (mask / p3[x]) % 3; ...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int boy, girl, n; cin >> boy >> girl >> n; if (boy + girl == n) { cout << 1 << "\n"; return 0; } if (boy >= n) cout << min(n, girl) + 1 << '\n'; else if (girl >= n) cout << mi...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, b, d, a, wSize = 0, result = 0; cin >> n >> b >> d; for (int i = 0; i < n; ++i) { cin >> a; if (a > b) continue; else { wSize += a; if (wSize > d) { result++; wSize = 0; } } } cout << resu...
1
#include <bits/stdc++.h> using namespace std; const long long N = (long long)2e5 + 7; long long n, l, x[N], y[N]; long long rep(long long x) { x %= n; if (x < 0) x += n; return x; } long long cnt[N]; long long geta(long long i) { return x[i % n] + i / n * l; } long long getb(long long i) { return y[i % n] + i / n...
17
#include <bits/stdc++.h> using namespace std; const int NMax = 1100, MMax = 10000, INF = 1000000000; struct edge { int num, len; edge *next; } * G1[NMax], pool[MMax]; int N, M, F[NMax], F1[NMax], L; void Build(int x, int y, int z) { edge *p = &pool[L++]; p->num = y; p->len = z; p->next = G1[x]; G1[x] = p;...
18
#include <bits/stdc++.h> using namespace std; const int N = 200000; int n, a[N], b[N], A[N], B[N], c[N]; map<int, int> M; int main() { scanf("%d", &n); for (int i = n; i >= 1; i--) { scanf("%d", &b[i]); B[b[i]] = i; } for (int i = n; i >= 1; i--) { scanf("%d", &a[i]); A[a[i]] = i; } M.clear(...
13
#include <bits/stdc++.h> const long long INF = 1e18; const int32_t M = 1e9 + 7; using namespace std; long long isprime(long long n) { long long c = 0; if (n == 2) return 2; else if (n == 3) return 3; else { long long x = (long long)(sqrt(n)); for (long long i = 2; i < x + 1; i++) { if (n %...
0
#include <bits/stdc++.h> char ch; template <class T> inline void read(T &x) { x = 0; ch = getchar(); while (ch <= 32) ch = getchar(); while (ch > 32) { x = x * 10 + ch - 48; ch = getchar(); }; }; template <class T> inline T min(T a, T b) { return a < b ? a : b; } template <class T> inline T max(T a,...
17
#include <bits/stdc++.h> #pragma comment(linker, "/stack:20000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") using namespace std; const int pr = 49999; const int maxn = 899821; const int mod = (int)1e9 + 7; const long double pi = 4 * atan(1); const long double eps = 1e...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; priority_queue<int> Q[maxn]; int num[maxn]; int fa[maxn]; inline int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { scanf("%d", num + i); fa[i] = i; ...
9
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int MN = 200111; pair<long double, int> a[MN]; int x[MN], n, l, v1, v2; long double res[MN]; int main() { while (scanf("%d%d%d%d", &n, &l, &v1, &v2) == 4) { int k = 1; a[k] = make_pair(-1, 0); int cur = 0; for (int i = (...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; for (i = 1; i < n; i++) { if (i % 2 == 0) { cout << "I love that" << " "; } else { cout << "I hate that" << " "; } } if (n % 2 == 0) cout << "I love it" << " "; else ...
0
#include <bits/stdc++.h> using namespace std; long long n, k, ans; unordered_set<string> prefixes; bool isPrefix(string s) { return prefixes.count(s); } bool tryToWin(string s) { bool curr = 0; for (int i = 0; i < 26; i++) { s.push_back(char('a' + i)); if (isPrefix(s)) { if (!tryToWin(s)) curr = 1; ...
11
#include <bits/stdc++.h> using namespace std; long long int exp(long long int a, long long int b, long long int m); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int d = 0; long long int n1 = n...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 5010; int a[maxn]; int Max_l[maxn][maxn], Min_l[maxn][maxn]; int N; void read() { scanf("%d", &N); for (int i = 1; i <= N; ++i) scanf("%d", &a[i]); } void getans() { for (int j = N; j; --j) { Min_l[j][j] = Max_l[j][j] = 0; for (int i = j - 1; ...
11
#include <bits/stdc++.h> using namespace std; long long m, d, w, T; vector<pair<long long, long long>> pq; void readInput() {} void solve() {} signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); readInput(); solve(); cin >> T; while (T--) { cin >> m >> d >> w; if (d == 1 || m == 1) ...
14
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long x; long long a = 1, cnt = 0; cin >> x; while (1) { long long tmp = (a + 1) / 2 * a; x -= tmp; if (x < 0) break; cnt++; a = a * 2 + 1; } cout << cnt << endl; }...
4
#include <bits/stdc++.h> int main() { int n1, n2 = 0, n3 = 0; std::cin >> n1; std::vector<std::vector<char>> v1(n1, std::vector<char>(n1)); for (int i = 0; i < n1; i++) for (int j = 0; j < n1; j++) std::cin >> v1[i][j]; for (int i = 0; i < n1; i++) { for (int j = 0; j < n1; j++) { if (v1[i][j] =...
0
#include <bits/stdc++.h> using namespace std; int main() { long long a[4]; char x[3]; while (scanf("%I64d%I64d%I64d%I64d", &a[0], &a[1], &a[2], &a[3]) == 4) { cin >> x[0] >> x[1] >> x[2]; long long mins = 999999999999999; long long b[3], c, tmp; for (int i = 0; i < 4; ++i) { for (int j = 0; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; cin >> n; map<string, bool> Map; char s[25], tmp[50]; while (n--) { cin >> s; int l = strlen(s); int index = 0, t = 0; while (index < l) { if (s[index] == 'u') { tmp[t++] = 'o'; tmp[t++] = 'o'; ...
5
#include <bits/stdc++.h> using namespace std; inline int getint() { static char c; while ((c = getchar()) < '0' || c > '9') ; int res = c - '0'; while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0'; return res; } const int MaxN = 1000; const int MaxM = 100000; int n, m; vector<int> adj[MaxN...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 10; int n, m, s; int head[maxn], hcnt = 0; struct edge { int v, next; } e[maxn]; void add(int u, int v) { e[hcnt] = edge{v, head[u]}; head[u] = hcnt++; } int dfn[maxn], low[maxn], suo[maxn], scnt = 0, tcnt = 0, vis[maxn]; stack<int> sta; void df...
12
#include <bits/stdc++.h> using namespace std; int main() { int i; string x; cin >> x; bool f = true; for (i = 0; i < x.size(); i++) { if (x[i] == '1' || x[i] == '4') continue; else { f = false; break; } } int c = 0; if (x[0] == '4') f = false; if (f) { for (i = 0; i <...
1
#include <bits/stdc++.h> using namespace std; const long double Pi = 3.14159265359; const long long MOD = 1000 * 1000 * 1000 + 7; const long long MAXN = 2e5 + 10; const long long INF = 1e18; long long q4; long long n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> m; cout << ...
7
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%lld", &x); return x; } const long long maxn = 1e6 + 10; long long pref[maxn]; long long c[maxn], d[maxn]; int32_t main() { long long maxi = 1e18, mini...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n], i, min = 10000, index; for (i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] < min) { index = i + 1; min = arr[i]; } } if (n == 1 || (n == 2 && arr[0] == arr[1])) cout << "-1"; else cout <...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(NULL); const vector<string> elem{ "", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", ...
14
#include <bits/stdc++.h> using namespace std; int ar[100000] = {0}; int main() { int a, b; cin >> a >> b; if (a == b) { cout << 0 << endl; return 0; } int a2 = 0, a3 = 0, a5 = 0; int acheck = a; while (acheck % 2 == 0) { a2++; acheck /= 2; } while (acheck % 3 == 0) { a3++; ache...
5
#include <bits/stdc++.h> using namespace std; long long p[1000100], h[1000100], g[1000100], ans; int main() { int m, n, x, y; cin >> n >> m; for (int i = 0; i <= n; i++) p[i] = (i ? p[i - 1] * 11 : 1); while (m--) { scanf("%d%d", &x, &y); h[x] += p[y]; h[y] += p[x]; } for (int i = 1; i <= n; i++...
15
#include <bits/stdc++.h> using namespace std; string solve(long long int x, long long int y) { if (x == 1 && y == 1) { return "YES"; } if (x == 2 && (y == 1 || y == 3 || y == 2)) { return "YES"; } if (x == 3 && y <= 3) { return "YES"; } if (x >= 4) { return "YES"; } return "NO"; } int ...
2
#include <bits/stdc++.h> using namespace std; int n, k; const int Mod = 1e9 + 7; int a[2010]; long long init[2010]; long long now[2020], d[2020]; void calc() { for (int i = 1; i <= n; i++) { d[i] = now[i]; now[i] = 0; } for (int i = 1; i <= n; i++) { for (int j = i; j >= 1; j--) { now[i] = (now[...
11
#include <bits/stdc++.h> using namespace std; int main() { long long n, cnt; cin >> n; if (n % 2) return cout << 0 << endl, 0; n /= 2; cout << (n - 1) / 2 << endl; return 0; }
2
#include <bits/stdc++.h> using ll = long long; using ld = long double; using namespace std; class A { public: int a, b, c, d, e; A(int a, int b, int c, int d, int e) : a(a), b(b), c(c), d(d), e(e) {} }; double scalar(A a, A b) { double result = 0.0; result += a.a * b.a; result += a.b * b.b; result += a.c *...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000100; int n, m; int anum[2 * MAXN], bnum[MAXN]; int loc[MAXN]; int best; long long poss[2 * MAXN]; int main() { for (int i = 0; i < MAXN; i++) loc[i] = -1; best = 0; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &anum[i]); for...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct node { long long x, y; } a[N]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld%lld", &a[i].x, &a[i].y); int flag = 0; for (int i = 0; i < n; i++) { if (a[(i + 1) % n].x - a[i].x != a[(i + n ...
10
#include <bits/stdc++.h> using namespace std; int HP[2]; int ATK[2]; int DEF[2]; int main() { for (int i = 0; i < 2; ++i) { scanf("%d %d %d", HP + i, ATK + i, DEF + i); } int hc, ac, dc; scanf("%d %d %d", &hc, &ac, &dc); int ans = 1e9; for (int i = 0; i <= 1000; ++i) { for (int j = 0; j <= 1000; ++j...
10
#include <bits/stdc++.h> using namespace std; const int N = 1100; int n, m; int a[N][N]; int main() { scanf("%d%d", &n, &m); int res, res1, res2; res = -1; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf("%d", &a[i][j]); for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) { ...
13
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; long long a[N]; int main() { long long ans = 0, n, maxx, minn; int i; scanf("%I64d", &n); for (i = 0; i < n; i++) { scanf("%I64d", &a[i]); } i = 0; while (i + 1 < n) { while (i + 1 < n && a[i] <= a[i + 1]) i++; maxx = a[i];...
6
#include <bits/stdc++.h> using namespace std; const int N = 1000005; using ll = long long; int n, m, p, a[N]; struct TNode { int l, r; vector<ll> f; ll sum; } t[N << 2]; inline int lc(int pos) { return pos << 1; } inline int rc(int pos) { return pos << 1 | 1; } void pushup(int pos) { t[pos].sum = t[lc(pos)].sum...
25
#include <bits/stdc++.h> using namespace std; const int maxn = 500003; int n; vector<int> v[maxn]; vector<int> lv; void dfs(int root, int pa, int dep) { if (v[root].size() == 1 && v[root][0] == pa) { if (pa != 1) lv.push_back(dep); return; } for (int to : v[root]) { if (to == pa) continue; dfs(to,...
14
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; inline long long input() { long long n; cin >> n; return n; } string base2(long long n) { string a = ""; while (n >= 2) { a += (char)(n % 2 + '0'); n /= 2; } a += (char)(n + '0'); reverse((a).begin(), (a).end()); return a...
13
#include <bits/stdc++.h> using namespace std; long long v[100500]; map<long long, long long> mm; vector<long long> v2; long long t1[400500]; void add_dp(int v, int tl, int tr, int ind, long long val) { if (tl == tr) { t1[v] = val; return; } int tm = (tl + tr) >> 1; int nv = v << 1; if (ind <= tm) ...
12
#include <bits/stdc++.h> using namespace std; int p[1000][1000]; int main() { int n, k, d; cin >> n >> k >> d; k = min(k, 1000); for (int i = 1; i <= k; i++) { int flag = 0, tmp = 1; for (int j = 0; j < d; j++) if ((tmp *= i) >= n) { flag = 1; break; } if (flag) { k...
11
#include <bits/stdc++.h> using namespace std; const int64_t M1 = 998244353; const int64_t M2 = 1000000007; void solve() { int64_t n, x; cin >> n; vector<int64_t> a(n); int64_t y = 0; for (int64_t i = 0; i < n + n; i++) { cin >> x; if (x > y) { a.push_back(0); y = x; } a.back()++; ...
10
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int sum(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; } int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; } int mul(int a, int b) { return (1LL * a * b) % MOD; } int pw(int a, int b) { if (!b) return 1; int r = pw(a,...
18
#include <bits/stdc++.h> using namespace std; long long func(long long n) { return ((n - 1) * (n)) - (((n - 2) * (n - 1)) / 2) + 1; } int main() { cin.tie(0); cin.sync_with_stdio(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; ...
7
#include <bits/stdc++.h> using namespace std; void work() { int n, s; scanf("%d%d", &n, &s); int m = s / n; if (s % n) m++; int der = m * n - s; int x = n / 2; if (n % 2) x++; if ((x - 1) * m >= der) { der = (x - 1) * m - der; int y = der / (n - x + 1); printf("%d\n", m + y); } else { ...
0
#include <bits/stdc++.h> using namespace std; pair<int, int> a[100100]; int n; int kx[100100], ky[100100]; vector<int> first[100100], second[100100]; void read(void) { cin >> n; for (int i = 0, x1, y1; i < n; ++i) { cin >> x1 >> y1; a[i] = make_pair(x1, y1); first[x1].push_back(y1); second[y1].push_...
15
#include <bits/stdc++.h> using namespace std; long long bits[60]; long long ans = 0; long long s, t; void dfs(long long a, long long b, int pos, long long c) { if (a + b == s && (a ^ b) == t) { ans += c; return; } else if (a + b > s) { return; } if ((t & bits[pos]) == bits[pos]) { if ((a + bits[...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 5; long long f(long long x) { if (x % 2) return x * (x - 1) / 2; else return x / 2 + f(x / 2); } int main() { ios_base::sync_with_stdio(false); long long n; vector<long long> ans; cin >> n; for (int t = 0; t < 1; t++) { long ...
10
#include <bits/stdc++.h> #pragma comment(linker, "/stack:225450978") #pragma GCC optimize("Ofast") using namespace std; const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18; const long double Pi = 3.141592653589793116, EPS = 1e-9, Gold = ((1 + sqrt(5)) / 2); long long keymod[] = {1000000007LL, 1...
8
#include <bits/stdc++.h> using namespace std; int a[((int)1e6 + 5)], n, zero, mod, numb[] = {1, 6, 8, 9}, k[4], perm[] = {0, 1, 2, 3}; string s; vector<int> v; int main() { cin >> s; n = s.size(); for (int i = 1; i <= n; i++) a[i] = s[i - 1] - '0'; for (int i = 1; i <= n; i+...
8
#include <bits/stdc++.h> using namespace std; int isvowel(char); int main() { string s, t; cin >> s >> t; int flag = 1; if (s.size() != t.size()) { cout << "No"; return 0; } else { for (int i = 0; i < s.size(); i++) { if (isvowel(s[i]) != isvowel(t[i])) flag = 0; } } if (flag) co...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; string king[n]; long long dp[26][26]; for (long long i = 0; i < 26; i++) { for (long long j = 0; j < 26; j++) dp[i][j] = 0; } for (long long i = 0; i < n; i++)...
7