solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { long long t, i; cin >> t; while (t--) { long long n, c = 0; cin >> n; while (n % 2 == 0 || n % 5 == 0 || n % 3 == 0) { if (n % 5 == 0) n = 4 * n / 5; else if (n % 3 == 0) n = 2 * n / 3; else n = n / 2;...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { string s; cin >> s; long long int c1 = 0; long long int c0 = 0; for (long long int i = 0; i < s.length(); ++i) { if (s[i] == '0') { c0++; } else { c1++; } }...
3
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) { if (x < y) x = y; } void read() { long long q; cin >> q; while (q--) { long long x; ...
0
#include <bits/stdc++.h> using namespace std; const int INF = 987654321; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int N, M; int main() { int t; scanf("%d", &t); while (t--) { char arr[101]; scanf("%s", arr); int tmp = 0; vector<int> num; for (int i = 0; i < strlen(arr); i++) { ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 210000; set<pair<long long, long long>> s; long long a[maxn]; int main() { long long n, k, x; cin >> n >> k >> x; int cnt = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] < 0) cnt++; s.insert(make_pair(abs(a[i]), i)); } for ...
12
#include <bits/stdc++.h> #define itn int #define all(x) (x).begin(), (x).end() #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) using namespace std; inline int nxt() { int x; scanf("%d", &x); return x; } void solve() { int n = nxt(); vector<char> flipped(n); vector<int> id(2 *...
18
#include <bits/stdc++.h> using namespace std; void read() { freopen("pudge.in", "r", stdin); freopen("pudge.out", "w", stdout); } void faster() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void pudge() { long long n, k; cin >> n >> k; string s; cin >> s; long long cnt = 0; for (l...
7
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10, M = 2 * N, mod = 998244353; long long inv[N], fac[N], ifac[N]; void init(int n) { inv[1] = fac[0] = fac[1] = ifac[0] = ifac[1] = 1; for (int i = 2; i <= n; i++) { inv[i] = (mod - mod / i) * inv[mod % i] % mod; fac[i] = fac[i - 1] * i % mo...
12
#include <bits/stdc++.h> using namespace std; namespace fastIO1 { inline char read() { static const int IN_LEN = 1000000; static char buf[IN_LEN], *s, *t; return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++); } template <class T> inline void read(T &x...
26
#include <bits/stdc++.h> using namespace std; void ASS(bool b) { if (!b) { ++*(int*)0; } } #pragma comment(linker, "/STACK:106777216") struct chash { vector<int> p, a; void init(const string& s, int h) { p.resize(s.size() + 1); a.resize(s.size() + 1); p[0] = 1; a[0] = 0; for (int i = 0; ...
13
#include <bits/stdc++.h> int d[] = {0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12}; bool OK(int k) { for (int i = 2; i * i <= k; ++i) { int tk = k; while (tk % i == 0) tk /= i; if (tk == 1) return false; } return true; } int main() { int n, ...
15
#include <bits/stdc++.h> using namespace std; namespace IO { const int sz = 1 << 15; char inbuf[sz], outbuf[sz]; char *pinbuf = inbuf + sz; char *poutbuf = outbuf; inline char _getchar() { if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf; return *(pinbuf++); } inline void _putchar(char x) { if...
18
#include <bits/stdc++.h> #pragma comment(linker, "/stack:20000000") using namespace std; double __begin; template <typename T1, typename T2, typename T3> struct triple { T1 a; T2 b; T3 c; triple(){}; triple(T1 _a, T2 _b, T3 _c) : a(_a), b(_b), c(_c) {} }; template <typename T1, typename T2, typename T3> bool ...
13
#include <bits/stdc++.h> using namespace std; int main() { long long n, ans = 0; cin >> n; string cur1[1010], cur2; unordered_map<string, string> m; unordered_set<string> s; for (int i = 0; i < n; ++i) { cin >> cur1[i] >> cur2; s.insert(cur2); m.insert(make_pair(cur1[i], cur2)); } for (int i...
3
#include <bits/stdc++.h> using namespace std; int get(vector<int>& v, int x) { auto it = upper_bound(v.begin(), v.end(), x); return it - v.begin(); } int cnt(vector<int>& v, int l, int r) { return get(v, r - 1) - get(v, l - 1); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vecto...
13
#include <bits/stdc++.h> using namespace std; int nr[53][53]; int nrc[53][53]; int ans; int main() { ios::sync_with_stdio(0); int n = 0; cin >> n; ans = 1; char str[n + 1]; for (int i = 0; i < n + 2; i++) nr[0][i] = 0; for (int i = 0; i < n; i++) { cin >> str; nr[i + 1][0] = 0; for (int j = 0;...
9
#include <bits/stdc++.h> using namespace std; const int inf = 0x7fffffff; int main() { long long h, n; cin >> h >> n; long long t = 1; for (int i = 0; i < h; i++) t *= 2; long long ans = 0; int hehe = 1; for (int i = 0; i < h; i++) { t /= 2; if (n > t) { if (hehe == 1) ans += t * 2; ...
9
#include <bits/stdc++.h> using namespace std; long long int f(long long int x, long long int y) { long long int res = 1; x = x % 1000000007; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; y = y >> 1; x = (x * x) % 1000000007; } return res; } long long int power[60]; long long int fun(lon...
10
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const int inf = 0x3f3f3f3f; int n, x; int a[N], f[N], l[N], f1[N], l1[N]; int main() { scanf("%d%d", &n, &x); memset(f, 0x3f, sizeof(f)); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (f[a[i]] == inf) f[a[i]] = i; l[a[i]] = i...
13
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "inline", "-ffast-math") #pragma GCC target("abm,avx,mmx,popcnt,sse,sse2,sse3,ssse3,sse4") inline long long read() { long long x = 0, y = 1; long long c = getchar(); while (c < '0' || c > '9') { if (c == '-') y = -1; c = getchar(); } while (c >= '...
3
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1005; int c[MAX_N]; int rv[MAX_N]; int main() { int n, m, d, suml; cin >> n >> m >> d; for (int i = 1; i <= m; i++) cin >> c[i]; for (int i = m, pos = n; i >= 1; i--) { for (int j = 0; j < c[i]; j++) { rv[pos - j] = i; } pos -= c[...
9
#include <bits/stdc++.h> using namespace std; ; int m, n, j, k, l, i, o, p, __t, Tot, t; string Map[1100]; vector<int> X, Y; int C[1100][1100], tl, cx[10000], cy[10000]; void cover(int x, int y) { if (C[x][y] != tl) C[x][y] = tl, Tot++; } bool Cover(int x1, int x2, int y1, int y2) { for (int i = (y1); i <= (y2); i+...
18
#include <bits/stdc++.h> int d[5002], mx[5002]; int a[5002]; int id[5002], l[5002], r[5002], p[5002]; int main() { int n, m, i, j, Max; scanf("%d %d", &n, &m); for (i = 1; i <= n; i++) mx[i] = 1000000000; for (i = 0; i < m; i++) { scanf("%d %d %d %d", id + i, l + i, r + i, p + i); if (id[i] == 1) { ...
9
#include <bits/stdc++.h> using namespace std; long long N, D, T; int v[5015]; int v2[5015]; int v3[5015]; void pre() { for (int i = 1; (i) <= int(5010); (i)++) { v[i + 1] = (i * (i + 1)) / 2; v3[i + 1] = i; } int cont, cont2 = 1, x = 0; int valor = 0; while (cont2 < 5010) { cont = 0; valor++; ...
14
#include <bits/stdc++.h> using namespace std; int main() { int nn, ss; cin >> nn >> ss; cout << ss / nn + ((ss % nn) != 0) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; map<int, string> STL; int main() { int n; while (cin >> n) { string name; int p, m, a, b, c, d, e; int maxs = -10000000, index = -1; for (int i = 1; i <= n; i++) { int sum = 0; cin >> name >> p >> m >> a >> b >> c >> d >> e; STL[i] = na...
2
#include <bits/stdc++.h> using namespace std; int n; int v[200010]; set<long long> S; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> v[i]; if (v[i] == 0) S.insert(i); } int mn = -1; for (int i = 1; i <= n; i++) { int h = -1; if (S.lower_bound(i) != S.end()) h = *S.lower_bound(i);...
4
#include <bits/stdc++.h> using namespace std; bool leap(int y) { return (y % 400 == 0) || (y % 4 == 0 && y % 100 != 0); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long y; cin >> y; bool is_leap = leap(y); int d = 0; do { d++; if (leap(y)) d++; y++; d %= 7; } while (d...
8
#include <bits/stdc++.h> using namespace std; const int MAX = 1e9; const int MAX_N = 2e3 + 1; const int dir[2][2] = {{1, 0}, {0, 1}}; typedef struct Node { int x, y; Node(int x, int y) : x(x), y(y) {} Node() {} } Node; queue<Node> q; int d1[MAX_N][MAX_N], d2[MAX_N][MAX_N], n, k, x, y, pos, xx, yy, flag; char a[MA...
11
#include <bits/stdc++.h> using namespace std; const int B = 11; const int N = 61; const long long inf = 1e18; long long dp[B][N][1 << (B - 1)]; void pre() { for (int b = 2; b < B; ++b) { unsigned long long h = 1; dp[b][0][0] = 1; for (int w = 1; h <= inf; ++w, h *= b) { for (int s = 0; s < (1 << b);...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 400005; struct Node { int x, y; Node(int X = 0, int Y = 0) { x = X; y = Y; } Node top() { if (!x) return Node(-1, -1); if (!y) return Node(0, 0); int lx = x & -x, ly = y & -y; return lx > ly ? Node(x, y ^ (y & (lx - 1))) : No...
27
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int MAXN = 20010; const int INF = 0x3f3f3f3f; const double eps = 0.0000001; const long long mod = 1e9 + 7; long long n, m, x, y, z, k, cnt, t, len; long long x1[50]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); lon...
14
#include <bits/stdc++.h> using namespace std; const int N = 15; const int INF = 1E9 + 7; int dp[N + 1][1 << N][N + 1]; pair<int, int> p[N + 1][1 << N][N + 1]; int n, a[N], sum[1 << N]; void work() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < (1 << n); i++) { sum[i] = 0; for (in...
22
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); vector<int> used(n, 0); vector<int> loops; int root = -1; int curUse = 1; int cur, next; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } cur = 0; for (in...
9
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3f; const long long mod = 998244353; const double eps = 1e-8; const int maxn = 3e5 + 10; const int maxm = 200005; int n; int ans[20] = {1, 4, 10, 20, 35, 56, 83, 116, 1...
12
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000009; #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("fast-math") #pragma GCC optimize "-O3" void solve() { long long a, b; ci...
0
#include <bits/stdc++.h> int main() { int a, b, c, rest = 0; scanf("%d %d %d", &a, &b, &c); rest = a * c - b * c; a = rest % b ? (rest / b) + 1 : rest / b; printf("%d", a); return 0; }
2
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); void solve() { string s; long long n; cin >> n; cin >> s; long long cnt1 = 0; long long ans = 0; for (long long i = 0; i < (long long)s.size(); ++i) { if (s[i] == '1') { ans = max(ans, 2 * max(i + 1, n - i)); } ...
2
#include <bits/stdc++.h> using namespace std; bool isprime(long long int n) { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; cin >> n; if (n == 2) cout << 1; else if (n % 2 == 0...
8
#include <bits/stdc++.h> using namespace std; int n; char a, b; int aa[27]; int sum = 0; int main() { cin >> n; for (int i = 1; i < n; i++) { cin >> a >> b; aa[a - 'a']++; if (aa[b - 'A'] == 0) sum++; else aa[b - 'A']--; } cout << sum; return 0; }
3
#include <bits/stdc++.h> const int maxn = 1e6 + 10; using namespace std; int n, b[maxn], dp[maxn]; struct hehe { int pos, dis; } a[maxn]; bool cmp(const hehe& a, const hehe& b) { return a.pos < b.pos; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &a[i].pos, &a[i].dis); sort(a, a + n,...
8
#include <bits/stdc++.h> using namespace std; int expo(int x, int y) { int res = 1; while (y) { if (y % 2) res = (res * x % 1000000007) % 1000000007; x = (x * x) % 1000000007; y /= 2; } return res; } bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 ...
10
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; struct point { long long x, y; point() {} point(long long _x, long long _y) : x(_x), y(_y) {} }; struct seg { point a, b; seg(){}; seg(point _a, point _b) : a(_a), b(_b){}; }; seg Seg[3]; int equal(point a, point b) { return a.x == b.x ...
12
#include <bits/stdc++.h> long long md = 1000000007; using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { ios::sync_with_stdio(false); ...
12
#include <bits/stdc++.h> using namespace std; struct Nodes { double x, y; } p[1010]; struct Cir { double r; Nodes s; } cir[1010]; int n, m, nm; double sqr(double x) { return x * x; } double dis(Nodes p1, Nodes p2) { return sqr(p1.x - p2.x) + sqr(p1.y - p2.y); } int isin(int a, int b) { double len = dis(p[a], ci...
12
#include <bits/stdc++.h> using namespace std; namespace IO { int len = 0; char ibuf[(1 << 20) + 1], *iS, *iT, out[(1 << 25) + 1]; inline void flush() { fwrite(out, 1, len, stdout); len = 0; } inline long long read() { register char ch = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), ...
17
#include <bits/stdc++.h> using namespace std; int n, a[70][70], c[70]; int pos[70 * 70][2]; struct queue { int x, y; } q[70 * 70]; int fr = 0, bk = 0, ans[70 * 70][4], m = 0; bool visited[70][70] = {0}; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &c[i]); for (int i = 0; i < n; i++) ...
7
#include <bits/stdc++.h> using namespace std; long long cr[200009], cg[200009], cb[200009]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t, n, k, i, ans, e; cin >> t; string s, r; while (t--) { ans = LLONG_MAX; cin >> n >> k >> s; s = '!' + s; i =...
8
#include <bits/stdc++.h> using namespace std; const int mm = 2e5 + 9; const int oo = 1e9; int dis[mm]; int n; double a, b, c, len = oo; void ok(int x, int y) { if (y < 0) y = 0; int z; z = dis[x] - dis[0]; z = max(dis[y] - dis[min(x + 1, n - 1)], z); z = max(dis[n - 1] - dis[min(y + 1, n - 1)], z); if (z < ...
10
#include <bits/stdc++.h> using namespace std; const int N = 200015; const int inf = 1e9 + 10; const int mod = 1e9; const int base = 1000 * 1000 * 1000; int n, a[N], s, in, ind, k; vector<int> g[N], ans; bool u[N]; void dfs(int v, int p) { u[v] = 1; for (int i = 0; i < g[v].size(); i++) { int to = g[v][i]; i...
9
#include <bits/stdc++.h> using namespace std; const long long INFLL = 0x3f3f3f3f3f3f3f3fLL; int _w; long long f, T, t0, a1, t1, p1, a2, t2, p2; bool nosol() { long long t = min(t0, min(t1, t2)); return f * t > T; } long long solve(long long a1, long long t1, long long p1, long long a2, long long t2,...
15
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 20; bitset<1 << 12> mm[MAX]; int an[12][MAX]; int k, n, q; int main() { scanf("%d %d %d", &n, &k, &q); for (int i = 0; i < k; ++i) for (int j = 0; j < n; ++j) scanf("%d", &an[i][j]); for (int i = 0; i < k; ++i) { for (int mask = 0; mask <...
21
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double eps = 1e-10; const long long INF = 1e18; const int N = 2e5 + 10; vector<int> adj[N]; vector<long long> ans; vector<pair<int, int>> v; long long dfs(int i, int par) { long long ret = v[i].first; for (auto it : adj[i]) { if (it !=...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { double n, d; cin >> n >> d; if (n >= d) { cout << "YES" << endl; continue; } double x = 1, f = 0; double y; for (int i = 0; i < d; i++) { y = double(d / (x + 1)); y = ceil(...
3
#include <bits/stdc++.h> using namespace std; const int BUF = 10 * 1000 * 1000 + 13; const int N = 300 * 1000 + 13; const int M = 300 * 1000 + 13; const int P = 400; struct query { int t, x, y; int e0, e1; }; int n, m; query q[M]; int p[N], rk[N]; int cnt; int *where[BUF]; int val[BUF]; void rollback() { while (c...
18
#include <bits/stdc++.h> using namespace std; bool use[1800][1800]; int nRow, nCol, map[1800][1800]; int movex[] = {1, 0, 0, -1}; int movey[] = {0, 1, -1, 0}; void Read(int &digit) { digit = 0; char c; for (c = getchar(); c < '0' || c > '9'; c = getchar()) ; for (; c >= '0' && c <= '9'; digit = digit * 10 +...
15
#include <bits/stdc++.h> void cheat(); int testscore(int a, int b); using namespace std; int n = 0; int t[125][5]; int sc[125]; int va[5]; int robot[5]; int p[5]; int rb = 0; int main(void) { cin >> n; for (int i = 0; i < n; i++) { cin >> t[i][0] >> t[i][1] >> t[i][2] >> t[i][3] >> t[i][4]; } cheat(); cou...
12
#include <bits/stdc++.h> using namespace std; signed main() { cin.tie(0); cout.tie(0); ios_base ::sync_with_stdio(0); long long t; cin >> t; for (long long i = 0; i < t; i++) { long long n; cin >> n; long long a[n]; long long ans[n]; bool used[n + 1]; for (long long i = 0; i < n; i++...
4
#include <bits/stdc++.h> using namespace std; int p[3000 + 10]; int m[3000 + 10]; int m1[3000 + 10]; queue<pair<int, int> > q; int d[3000 + 10][3000 + 10]; int n, k; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> p[i]; for (int i = n - 1; i >= 0; i--) { if (i + 1 != n) { m[i] = m[i + 1];...
14
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long ar[12]; ar[1] = 9; ar[2] = 90ll * 2; ar[3] = 900ll * 3; ar[4] = 9000ll * 4; ar[5] = 90000ll * 5; ar[6] = 900000ll * 6; ar[7] = 9000000ll * 7; ar[8] = 90000000ll * 8; ar[9] = 900000000ll * 9; ar[10] = 90...
4
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int a = 0, b = 0; if (s.length() != t.length()) { cout << "No"; return 0; } string c = "aeiou"; for (int i = 0; i < s.length(); i++) { if ((find(c.begin(), c.end(), s[i]) == c.end() && find(c.begin(...
2
#include <bits/stdc++.h> using namespace std; double tt; string v[] = {"", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se...
14
#include <bits/stdc++.h> using namespace std; const char s[12][10] = {"x^y^z", "x^z^y", "(x^y)^z", "(x^z)^y", "y^x^z", "y^z^x", "(y^x)^z", "(y^z)^x", "z^x^y", "z^y^x", "(z^x)^y", "(z^y)^x"}; int main() { long double a[12]; long double x, y, z; int n = 0; cin >> x ...
16
#include <bits/stdc++.h> using namespace std; inline void file() { freopen( "adr" ".in", "r", stdin); freopen( "adr" ".out", "w", stdout); } inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ...
21
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, ans(0); cin >> n >> m >> a >> b; if (m * a <= b) cout << a * n; else cout << (n / m) * b + min(b, (n % m) * a); return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[2 * n]; unordered_map<int, vector<int>> mp; for (int i = 0; i < 2 * n; i++) { cin >> arr[i]; mp[arr[i]].push_back(i); } for (int i = 0; i < 2 * n - 1; i++) { if (arr[i] == arr[i + 1]) { arr[i] = -1; ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int q, c = 0, n, s = 0; cin >> q; for (int i = 0; i < q; i++) { c = 0; s = 0; cin >> n; if (n <= 6) { cout << 1 << endl; continue; } int a = n / 6; for (int j = 0; j < a...
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1061109567; const long long LINF = 4557430888798830399ll; const int MOD = 998244353; int n, m, k, s; int a[200005]; int b[200005]; struct Node { int id; int t; int c; long long s; Node() {} Node(int id, int t, int c,...
12
#include <bits/stdc++.h> using namespace std; vector<string> ds; int cnt[10], cntcnt[10]; char s[1000005]; char cs[20]; int main() { char c; while ((c = getchar()) >= '0' && c <= '9') cnt[c - '0']++; scanf("%s", s); int n; int len = 0; for (int i = 0; i < 10; i++) len += cnt[i]; if (len == 2 && cnt[0] == ...
15
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; using vll = vector<long long>; using vii = vector<pair<int, int>>; char grid[64][64]; int main() { int t; for (scanf("%d", &t); t; t--) { int r, c; scanf("%d%d", &r, &c); for (int i = 0...
10
#include <bits/stdc++.h> using namespace std; string solve(int n) { int x = n * 4 - n; x /= 4; string s = ""; for (int i = 0; i < x; i++) { s += '9'; } while (s.length() < n) { s += '8'; } return s; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while ...
2
#include <bits/stdc++.h> using namespace std; int main() { int i, n, c, arr[105], diff = 0, s; scanf("%d %d", &n, &c); for (i = 0; i < n; i++) scanf("%d", &arr[i]); for (i = 0; i < n - 1; i++) { if ((arr[i] - arr[i + 1]) > 0) { if ((arr[i] - arr[i + 1]) > diff) { diff = arr[i] - arr[i + 1]; ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); long long q, n; cin >> q; for (int i = 0; i < q; i++) { cin >> n; long long a[n]; cin >> a[0]; for (int j = 1; j < n; j++) { cin >> a[j]; } sort(a, a + n); ...
13
#include <bits/stdc++.h> using namespace std; template <class Num> Num mabs(Num A) { if (A < 0) return -A; return A; } void solve() { int x, y; scanf("%d %d", &x, &y); vector<int> cost(6); for (int i = (0); i < (6); i++) scanf("%d", &cost[i]); long long ans = (long long)2e18; vector<pair<int, int> > del...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, l[101] = {}, r[101] = {}, cl = 0, sl[101] = {}; cin >> n; for (int i = 1; i <= n; ++i) { cin >> l[i] >> r[i]; if (l[i] == 0) sl[cl++] = i; } for (int i = 0; i < cl - 1; ++i) { int j = sl[i]; while (r[j] != 0) { j = r[j]; ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int64_t T, n, k, l; cin >> T; while (T--) { cin >> n >> k >> l; int64_t left = 0, right = 4 * k; bool possible = true; for (int64_t t = 0; t < n; t++) { int64_t d; cin >> d; int64_t new...
14
#include <bits/stdc++.h> using namespace std; const int N = 100002; int n; pair<int, int> p[N]; int lv[N], cnt[N]; int main(void) { scanf("%d", &n); for (int i = 0; i < n - 1; i++) { scanf("%d", &p[i].first); p[i].second = i + 2; } sort(p, p + n - 1); lv[1] = 1, cnt[1] = 1; for (int i = 0; i < n - 1...
7
#include <bits/stdc++.h> using namespace std; struct node { int x, y; }; node a[100010]; bool cmp(node a, node b) { return a.x < b.x; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) scanf("%d%d", &a[i].x, &a[i].y); sort(a, a + n, cmp); int flag = 0; for (int i = 1; i < n; i++) { if (a[i].y...
3
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 10, mod = 1e9 + 7; int n, lens, lent, a, b, p, q; char s[N], t[N]; long long pw2[N], ans, fac[N], inv[N], ifac[N], f[N], Ans; int mu[N], mark[N], pri[N], tot; void Add(long long &x, long long y) { x = (x + y) % mod; } long long add(long long x, long long...
26
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; long long dp[51][2051]; long long a[100]; void go() { long long n, s, k; cin >> n >> s >> k; for (long long i = 1; i <= n; i++) { cin >> a[i]; } memset(dp, -1, sizeof(dp)); string color; cin >> color; priority_queue<pair<long...
12
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; const int N = 405; bool check(string s1, string s2) { int j = 0; for (int i = 0; i < s1.size() && j < s2.size(); i++) { if (s1[i] == s2[j]) j++; } return j == s2.size(); } int f[N]; int main() { int _;...
14
#include <bits/stdc++.h> using namespace std; int main() { int x = 0, y = 0, z = 0; string s1; for (int i = 0; i < 3; i++) { cin >> s1; if (s1[1] == '>') { if (s1[0] == 'A') x++; else if (s1[0] == 'B') y++; else if (s1[0] == 'C') z++; } else { if (s1[2] ...
4
#include <bits/stdc++.h> using namespace std; const int Maxn = 2505; int n, m; char B[Maxn][Maxn]; int S[Maxn][Maxn]; int res = Maxn * Maxn; int Get(int r1, int c1, int r2, int c2) { r2 = min(r2, n); c2 = min(c2, m); return S[r2][c2] - S[r1 - 1][c2] - S[r2][c1 - 1] + S[r1 - 1][c1 - 1]; } int main() { scanf("%d ...
6
#include <bits/stdc++.h> using namespace std; long long int m, n, c, d, j, k, l[50000], r[50000], x, t, y, u, z, i, e, f, g, h, a = 1, b; int main() { cin >> n >> m; string s; for (i = 0; i < n; i++) { cin >> s; j = i % 2 * (m - 1); k = 1 - i % 2 * 2; for (; 0 <= j && j < m; j += k) if (...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, maxi, ans = 0; cin >> a >> b >> c; maxi = max(a, max(b, c)); if (a < maxi) ans += (maxi - 1) - a; if (b < maxi) ans += (maxi - 1) - b; if (c < maxi) ans += (maxi - 1) - c; cout << ans; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { string s = ""; int n, t; cin >> n >> t; if (t == 10 && n == 1) { cout << -1 << endl; } if (t == 10 && n > 1) { for (int i = 1; i <= n - 1; i++) { cout << 1; } cout << 0 << endl; } if (t < 10) { for (int i = 1; i <= n; i...
2
#include <bits/stdc++.h> using namespace std; inline char gc() { return getchar(); } inline void pc(char c) { putchar(c); return; } char buffer[25], en; inline long long read() { long long x = 0, f = 1; char c = gc(); while (c < '0' || c > '9') { if (c == '-') f = -f; c = gc(); } while (c >= '0' &...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; long long int ans = 0; for (long long int i = 0; i <= a; i++) { long long int cost = min(d, i) * e + (min(b, mi...
0
#include <bits/stdc++.h> using namespace std; const int N = 400000; int ans, rmax, n; void read(int &x) { scanf("%d", &x); } struct node { int l, r; } a[N]; bool cmp(node x, node y) { return (x.r < y.r || x.r == y.r && x.l < y.l); } int main() { read(n); for (int i = 1; i <= n; i++) { int x, y; read(x); ...
10
#include <bits/stdc++.h> using namespace std; const int M = 412345; struct TwoSAT { vector<int> v[M]; int n; bool f[M]; int s[M], si; void init(int _n) { n = _n; for (int i = 0; i < n * 2; i++) v[i].clear(); memset(f, 0, sizeof(f)); } bool solve() { for (int i = 0; i < n * 2; i += 2) { ...
18
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = 3.14159265358979323846; const int MAXN = 3e5; const int MAXM = 1500; inline double lineAngle(const complex<double>& p1, const complex<double>& p2) { double a = atan2((((p2) - (p1))).imag(), (((p2) - (p1))).real()); if (a < -EPS...
16
#include <bits/stdc++.h> using namespace std; char BUFFER[100000 + 5]; bool readn(int &n) { return scanf("%d", &n) == 1; } bool readl(long long &n) { return scanf("%I64d", &n) == 1; } bool readd(double &n) { return scanf("%lf", &n) == 1; } bool reads(string &s) { s = ""; int n = scanf("%s", BUFFER); if (n == 1) s...
12
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <unordered_set> #include <string> #include <map> #include <unordered_map> #include <queue> #include <assert.h> #include <cmath> #include <sstream> using namespace std; typedef long long ll; typedef long double ld; #define all(x) x.begi...
13
#include <bits/stdc++.h> using namespace std; int main() { string s; while (cin >> s) { long long int n = s.size(); cout << (n + 1) * 26 - n << endl; } }
1
#include <bits/stdc++.h> using namespace std; void check(string str) { int flag = 0; if (str.size() % 2 != 0) { cout << "NO" << endl; } else { int n = (str.size() - 1) / 2; for (int i = 0; i <= n; i++) { if (str[i] != str[n + 1 + i]) { flag = 1; } } if (flag == 1) { c...
0
#include <bits/stdc++.h> using namespace std; class ItemCounter { unordered_map<int, int> cnt; int frequentCnt = 0; int limit; public: ItemCounter(int limit) : limit(limit) {} void add(int item) { if (cnt[item] == limit) frequentCnt++; cnt[item]++; } void remove(int item) { cnt[item]--; ...
11
#include <bits/stdc++.h> using namespace std; bool debug = false; int in[500005], out[500005], N; vector<int> adj[500005]; long long MOD = 1000000007, f[500005]; void prepare() { f[0] = 1; for (long long i = 1; i < 500005; i++) f[i] = (f[i - 1] * i) % MOD; } int p[500005], r[500005]; int findSet(int x) { return p[x...
25
#include <bits/stdc++.h> using namespace std; int a[102][3]; int i, j, l, m, n; double k; int main() { ios_base::sync_with_stdio; cin >> n >> m; for (i = 0; i < n; i++) cin >> a[i][1] >> a[i][2]; k = 0; for (i = 0; i < n - 1; i++) k += sqrt((a[i][1] - a[i + 1][1]) * (a[i][1] - a[i + 1][1]) + ...
1
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, k; cin >> n >> k; int64_t ans = 0; while (n < k) { ans += (k / n); k = k % n; } if (k > 0) { ans++; } cout << ans << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int maxn = (int)(1e5) + 5; const int MAX = (int)(1e5) + 1; int a[maxn]; int C[maxn]; int L[maxn], R[maxn]; int n, m; inline int sum(int x) { int ret = 0; for (; x; x -= ((x) & (-x))) ret = max(ret, C[x]); return ret; } inline void add(int x, int v) { for (; x ...
11