solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int n, a, b, sum = 0, sum1, m; cin >> n >> a >> b; for (int i = 0; i < n; i++) { cin >> m; v.push_back(m); } sort(v.begin(), v.end()); if (v[b - 1] >= v[b]) { cout << 0 << endl; return 0; } sum1 = v[b] - v[b - 1]...
0
#include <bits/stdc++.h> using namespace std; int N, K, T, AnsX[100005], AnsY[100005]; bool V[100005]; bool Equ(double a, double b) { return abs(a - b) <= (1e-9); } struct Nod { double x, y; bool operator==(const Nod& a) { return Equ(x, a.x) && Equ(y, a.y); } } D[100005]; struct Lin { double A, B, C; void Rd() ...
10
#include <bits/stdc++.h> using namespace std; int father[100005], mark[100005]; int head[100005], tot, Cnt[100005]; int sum[100005]; struct Edge { int to, index, next; } edge[100005 * 10]; struct node { int x, y, v, index; long long tree; } s[100005]; long long Ans[100005]; bool cmp(node a, node b) { return (a.v ...
7
#include <bits/stdc++.h> int m, n, k, R[27], C[27], r, c, y, x; char a[101][102], s[1001]; int main() { scanf("%d%d%d", &m, &n, &k); for (int i = 1; i <= m; i++) { scanf("%s", a[i] + 1); for (int j = 1; j <= n; j++) if (islower(a[i][j])) { R[a[i][j] - 'a'] = i; C[a[i][j] - 'a'] = j; ...
7
#include <bits/stdc++.h> namespace chtholly { inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) f ^= c == '-'; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0'); return f ? x : -x; } template <typename mitsuha> inline bool read(mitsuha &x) { x =...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 111111; int N, p[MAXN]; long long cnt[MAXN]; int find(int x) { if (p[x] == x) return x; return p[x] = find(p[x]); } bool lucky(int k) { if (!k) return false; while (k) { int tmp = k % 10; if (tmp != 4 && tmp != 7) return false; k /= 10; ...
5
#include <bits/stdc++.h> using namespace std; void add(int& a, int b, int mod) { a = (a + b) % mod; } void sub(int& a, int b, int mod) { a = ((a - b) % mod + mod) % mod; } void mul(int& a, int b, int mod) { a = (a * 1ll * b) % mod; } template <class T> bool umin(T& a, const T& b) { return a > b ? a = b, true : false;...
10
#include <bits/stdc++.h> using namespace std; int n, m, cnt; int head[205], Next[50005], vet[50005]; void add(int x, int y) { cnt++; Next[cnt] = head[x]; head[x] = cnt; vet[cnt] = y; } struct node { int id; long long dis; friend bool operator<(node a, node b) { return a.dis > b.dis; } }; long long dis[205...
5
#include <bits/stdc++.h> using namespace std; int prime[1000]; bool bo[10001]; int prime_table() { int i, j, flag = 0; memset(bo, 0, sizeof(bo)); bo[0] = bo[1] = 1; for (i = 2; i <= 100; i++) if (!bo[i]) { j = i * i; for (; j <= 10000; j += i) bo[j] = 1; } for (i = 0; i <= 10000; i++) ...
2
#include <bits/stdc++.h> using namespace std; int getBit(unsigned int, int); void setBit(unsigned int &, int); void clearBit(unsigned int &, int); void reverseBit(unsigned int &, int); int INF = 1e9; int m, n, k; int sx, sy; string a[20]; int f[20][20][1 << 8][1 << 8]; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}...
9
#include <bits/stdc++.h> const int N = 1e6 + 5; const int mod = 998244353; using namespace std; int n, g[N], f[N], fac[N], inv[N], ans; template <typename T> inline T read() { T x = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <...
8
#include <bits/stdc++.h> using namespace std; int n, d, a, b; struct person { int x, y, index; bool operator<(const person &t) const { return x * a + y * b < t.x * a + t.y * b; } }; vector<int> ans; int main() { ios_base::sync_with_stdio(false); cin >> n >> d >> a >> b; vector<person> arr(n); for (int...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1E6 + 77; const int mod = 1E9 + 7; long long P[maxn], D[maxn], S[maxn]; long long N, K, ans; long long Pow(long long v, int p) { long long ret = 1; while (p) { if (p & 1) ret = (ret * v) % mod; v = (v * v) % mod; p >>= 1; } return ret; }...
8
#include <bits/stdc++.h> using namespace std; const int Maxn = 300005; int q; int a, b; char str[Maxn]; int slen; vector<int> seq; bool Solve() { if (seq.empty() || seq[0] < a) return false; if (seq.size() >= 2 && seq[int(seq.size()) - 2] >= 2 * b && seq.back() >= 2 * b) return false; if (seq.back() < 2...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll t; cin >> t; while (t--) { ll n, m, k; cin >> n >> m >> k; k--; k--; if (m > n * (n - 1) / 2 || m < n - 1) { cout << "nO" << '\n'; continue; } if (k > 1) { if (m > n - 2) { cou...
2
#include <bits/stdc++.h> using namespace std; struct data { long long t; int s, f, r; } a[100010]; bool operator<(const data &a, const data &b) { return a.t < b.t; } int n, m, cur; int F[100010]; long long tg, kq[100010]; set<pair<int, int> > u1, u2, d1, d2; void nhap() { cin >> n >> m; for (int i = 1; i <= n; ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, total = 0, num; cin >> n; for (i = 0; i < n; i++) { cin >> num; total += num; if (num != 1) total += (num - 1) * i; } cout << total << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; char a[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) a[i][j] = 'S'; if (k <= (n * n + 1) / 2) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i % 2 == 0 && j % 2 =...
3
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 2000010; int n, cnt[N], mx = 0; int pri[N], d[N], ds[N]; bool ty[N]; inline int add(const int &x, const int &y) { return x + y < mod ? x + y : x + y - mod; } inline int sub(const int &x, const int &y) { return x - y < 0 ? x - y + m...
10
#include <bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VL = vector<LL>; using PII = pair<int, int>; using PLL = pair<LL, LL>; void dout() { cerr << endl; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << H << ...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long tavmd(long long a, long long b) { if (b == 0) { return 1; } if (b % 2 == 0) { long long x = tavmd(a, b / 2); return (x * x) % MOD; } else { return (a % MOD * tavmd(a, b - 1) % MOD) % MOD; } } const long long...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n % 5) % 3 + 1; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 110; const int mod = 1e9 + 7; string s[N]; struct info { int a, b, a2, b2, a3, b3; }; void cam(int i, int j) { if (s[i][j] == '1') s[i][j] = '0'; else s[i][j] = '1'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); in...
5
#include <bits/stdc++.h> using namespace std; vector<long long> vec[(long long)1e6]; vector<long long> comp; long long vis[(long long)1e6]; long long dis[(long long)1e6]; long long a[(long long)1e6]; long long DFS(long long x) { vis[x] = true; for (long long i = 0; i < vec[x].size(); i++) { if (!vis[vec[x][i]])...
2
#include <bits/stdc++.h> using namespace std; int dp[200010], a[200010]; pair<int, int> p[200010]; int tree[200010 << 2]; inline void pushUp(int rt) { tree[rt] = tree[rt << 1] + tree[rt << 1 | 1]; if (tree[rt] >= 1000000007) tree[rt] -= 1000000007; } void update(int x, int val, int L, int R, int rt) { if (L == R)...
4
#include <bits/stdc++.h> using namespace std; int main() { unordered_map<char, int> rank; rank.insert(make_pair('6', 1)); rank.insert(make_pair('7', 2)); rank.insert(make_pair('8', 3)); rank.insert(make_pair('9', 4)); rank.insert(make_pair('T', 5)); rank.insert(make_pair('J', 6)); rank.insert(make_pair(...
1
#include <bits/stdc++.h> using namespace std; int powmod(int a, int l, int md) { a %= md; int res = 1; while (l) { if (l & 1) res = res * a % md; l /= 2; a = a * a % md; } return res; } int binpow(int a, int l) { int res = 1; while (l) { if (l & 1) res = res * a; l /= 2; a = a * a;...
8
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); long long friends; std::cin >> friends; long long w[friends], h[friends], hp[friends + 1], hs[friends + 1]; long long wsum = 0; for (long long i = 0; i < friends; i++) { std::cin >> w[i] >> h[i]; wsum += w[i]; } hs[friends] ...
1
#include <bits/stdc++.h> using namespace std; const double OO = 1e18; const double eps = 1e-10; const long long one = 1000000LL; int n, t; struct problem { long long scsmall, sclarge, tsmall, tlarge; double pfail; bool operator<(const problem &st) const { double t1 = tlarge * (1.0 - pfail) * st.pfail + ...
10
#include <bits/stdc++.h> using namespace std; inline int lowbit(int x) { return x & (-x); } inline int read() { int X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; } inline...
6
#include <bits/stdc++.h> using namespace std; long long n, ai; vector<vector<long long> > data; vector<deque<vector<long long> > > lengths; vector<deque<long long> > treb, how; vector<deque<vector<pair<long long, long long> > > > pluss; vector<long long> answer, where, ls; vector<long long> freem; bool cmp(long long fi...
9
#include <bits/stdc++.h> using namespace std; int main() { double t1, t2, num, n, l, v1, v2, k; cin >> n >> l >> v1 >> v2 >> k; num = (int)n / (int)k + ((int)n % (int)k != 0); t2 = l / ((1 + (v2 - v1) / (v2 + v1)) * (num - 1) * v1 + v2); t1 = (l - t2 * v2) / v1; printf("%.10lf", t1 + t2); return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1]; string s[n + 1]; for (int i = 0; i < n; i++) { cin >> a[i]; } getchar(); vector<int> v; for (int i = 0; i < n; i++) { string b; getline(cin, b); int count = 0; for (int j = 0; j < b.length(); ...
2
#include<bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #endif #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef std::vector<vector<int> > vv...
6
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; int n; bool has[2020]; void check(int now){ int lb = 0, ub = now - 1; while(lb <= ub){ int mid = (lb + ub) >> 1; cout << "? " << mid + 1 << " 1" << endl; rep(i, mid+1) cout << i+1 << " "; cout << endl; cout << now + ...
9
#include <bits/stdc++.h> using namespace std; template <typename T = int> T input() { T res; cin >> res; return res; } template <typename It> void input_seq(It begin, It end, istream &in = cin) { generate(begin, end, input<typename remove_reference<decltype(*begin)>::type>); } template <class It> voi...
7
#include <bits/stdc++.h> int a[100009], hash[100009]; int main() { int i, n, k, cot, p, min; scanf("%d%d", &n, &k); memset(hash, 0, sizeof(int)); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n; i++) { cot = i % k; hash[cot] += a[i]; } min = hash[0], p = 0; for (i = 0; i < k; i++) ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2100; long long a[maxn], b[maxn]; long long pre[maxn]; long long ini[maxn]; long long bn[maxn]; int k, n; set<long long> ans, init, bset, tmp; bool bs(long long des) { int l = 0, r = n - 1; while (l <= r) { int m = (l + r) / 2; if (b[m] == des) ...
4
#include <iostream> #include <vector> #include <bits/stdc++.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; #define ll long long int #define lll unsigned long long #define ssl signed long long #define pb push_back bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { retur...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e9 + 5; int main() { long long a, b, c; long long answer; cin >> a >> b >> c; if (a > b) swap(a, b); if (b > c) swap(b, c); if (a > b) swap(a, b); if (c % 2 == b % 2) answer = c; if (c % 2 == a % 2) answer = c; if (b % 2 == a % 2) answer ...
6
#include <bits/stdc++.h> using namespace std; bool isprime(long n) { for (int i = 2; (long long int)i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int findgrouplcm...
4
#include <bits/stdc++.h> int main() { int n, top = 0, i, b; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &b); top += b; } printf("%lf", (double)top / n); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, L, a, t, l, s = 0, b = 0; scanf("%d %d %d", &n, &L, &a); for (int i = 0; i < n; i++) { scanf("%d %d", &t, &l); b += (t - s) / a; s = t + l; } b += (L - s) / a; printf("%d\n", b); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n; cin >> n; for (int i = 0; i < n; ++i) { int l, r, k; cin >> l >> r >> k; --l, --r, --k; k %= (r - l + 1); rotate(s.begin() + l, s.begin() + r - k, s.begin() + r + 1); } cout << s << endl; return 0; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1000000 + 3; int n; int typ[N], val[N], chg[N], sum[N]; int kid[N][2]; char opt[5]; void dfs1(int p); void dfs2(int p); int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%s", opt); if (opt[0] == 'A') typ[i] = 1; if (opt[0] == ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i; cin >> n; int a[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; cin >> m; int x[m + 1], y[m + 1]; for (i = 1; i <= m; i++) cin >> x[i] >> y[i]; for (i = 1; i <= m; i++) { a[x[i] - 1] = y[i] - 1 + a[x[i] - 1]; a[x[i] + 1] = a[x...
0
#include <bits/stdc++.h> int a[105]; int main() { int n, m, i, k, max, t; while (scanf("%d%d", &n, &m) != EOF) { for (i = 0; i < n; i++) scanf("%d", &a[i]); if (a[0] > m) { if (a[0] % m == 0) max = a[0] / m; else max = a[0] / m + 1; } else max = 1; k = 0; for (i...
1
#include <bits/stdc++.h> using namespace std; int d[3100][3100]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<long double> p(n); vector<int> pref(n); vector<int> full(n); for (long double &e : p) { cin >> e; } pref[n - 1] = p[n - 1] != 0; for...
7
#include <bits/stdc++.h> using namespace std; const int MAX = 110; int a[MAX]; double dist(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int main() { int i, j, k; int p, q; int n; int t0, t1, t2; int x1, x2; double r3, r4; int r2, r1; int x...
5
#include <bits/stdc++.h> using namespace std; int main() { long long d, k, a, b, t; cin >> d >> k >> a >> b >> t; if (d <= k) cout << d * a; else { long long cnt = d / k; cout << min(k * a + (d - k) * b, cnt * (k * a + t) + min(d % k * b - t, d % k * a)); } }
5
#include <bits/stdc++.h> using namespace std; int a, b; int main() { int t; scanf("%d", &t); while (t--) { scanf("%d%d", &a, &b); if (a == b) cout << 0 << endl; else { if (a < b && (b - a) % 2) cout << 1 << endl; else if (a > b && (a - b) % 2 == 0) cout << 1 << endl; ...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 9; int a[MAX], x[2 * MAX], y[MAX], pf[MAX]; vector<int> ans; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) x[i] = a[i ...
8
#include <bits/stdc++.h> using namespace std; using ll = long long int; const ll mod = 1000000007; const ll M = 1000000000000000000ll; inline ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); } inline ll sub(ll a, ll b) { return ((a % mod - b % mod + mod) % mod); } inline ll mult(ll a, ll b) { return (((a % mod)...
4
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(long long int a, long long int b) { if (a < b) return a; else return b; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; ...
4
#include <bits/stdc++.h> using namespace std; string button1(string s) { for (int i = 0; i < s.size(); i++) { int n = s[i] - '0'; n++; n = n % 10; s[i] = (char)(n + '0'); } return s; } string button2(string s) { char a = s[0]; for (int i = 1; i < s.size(); i++) { char b = s[i]; s[i] = ...
3
#include <bits/stdc++.h> using namespace std; const double eps = 0.000001; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; while (cin >> n >> m) { if ((m == 0 || m == 1) && n) { cout << "no" << endl; continue; } n -= m - 1; if (n < 0 || (n & 1)) cout << "no" <<...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; int p[51][51]; int a[51]; int pos[51]; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cin >> p[i][j]; } for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) pos[i] = 0; for (int i = 1; i <= n; i++...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, ans = 0, ai; cin >> n; map<int, bool> hap; vector<int> cur(1, 0); while (n--) { cin >> ai; int s = cur.size(); vector<int> newi; map<int, bool> si; for (int i = 0; i < s; i++) { ...
4
#include <bits/stdc++.h> using namespace std; struct _ { _() { ios_base::sync_with_stdio(0); } } _; template <class A, class B> ostream &operator<<(ostream &o, pair<A, B> t) { o << "(" << t.first << ", " << t.second << ")"; return o; } template <class T> string tostring(T first, int len = 0, char c = '0') { str...
7
#include <bits/stdc++.h> using namespace std; const int MAX = 5123; const int INF = 0x3f3f3f3f; const long long MOD = 1000000007; int n, T; int s[MAX]; double dp[MAX][MAX]; double p[MAX]; int main() { scanf("%d %d", &n, &T); for (int i = 1; i <= n; i++) { scanf("%lf %d", &p[i], &s[i]); p[i] *= .01; } dp...
8
#include <bits/stdc++.h> using namespace std; #define all(nums) nums.begin(), nums.end() #define allr(nums) nums.rbegin(), nums.rend() #define len(a) int((a).size()) typedef long long int ll; const ll imax = INT64_MAX; const ll imin = INT64_MIN; typedef vector<vector<int>> graph; graph g; template<class T>T cal(T n) {r...
3
#include <bits/stdc++.h> using namespace std; void solve() { int a, b; cin >> a >> b; if (a > b) swap(a, b); int x = min(a, b - a); long long ans = 0; for (int z = max(0, x - 10); z <= (x + 10); z++) { if (z * 2 > b || z > a) continue; ans = max(ans, (long long)z + (min(a - z, b - 2 * z) / 3) * 2); ...
1
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { long long n, i, j = 0, x; cin >> n; string s = ""; stack<long long> q; deque<long long> d; for (i = 0; i < (n); i++) { cin >> ...
2
#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...
4
#include <bits/stdc++.h> using namespace std; struct UnionFind { int par[1001000], rank[1001000]; void init(int N) { for (int i = 0; i < N; i++) { par[i] = i; rank[i] = 0; } } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { ...
8
#include<bits/stdc++.h> #define fre(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout) #define ll long long using namespace std; inline int read(){ int x=0,f=1;char c=getchar(); while(c<'0'||c>'9') { if(c=='-') f=-1;c=getchar(); } while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=getchar(); return x*f; } cons...
3
#include <bits/stdc++.h> using namespace std; const int N = 310; int n, visited[N], mat[N][N]; vector<int> gp[N], aux, pos; string tmp; void DFS(int x, int a[]) { visited[x] = 1; pos.push_back(x); aux.push_back(a[x]); for (int j = 1; j <= n; j++) if (!visited[j] && mat[x][j]) DFS(j, a); } void func(int a[])...
4
#include <bits/stdc++.h> using namespace std; int used[444444]; int A, B; int DX = 100000; void brute(int i, int val) { if (used[i] != -1) return; if (i > val) val = i; used[i] = val; if (i - B >= 0) brute(i - B, val); if (i + A <= A + DX) brute(i + A, val); } int main() { int m; scanf("%d%d%d", &m, &A, &...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) ...
5
#include <bits/stdc++.h> using namespace std; string a[1009]; int n; set<string> s; string h; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; for (int j = 0; j < a[i].size(); j++) { char l = a[i][j]; if (a[i][j] == 'u') { h += "oo"; } else if (a[i][j] == 'k') { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n > 0) { int x, y, Sum = 0; cin >> x >> y; if (x < y) swap(x, y); while (y != 0) { Sum += x / y; x %= y; if (x < y) swap(x, y); } cout << Sum << endl; n--; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1, 0}; const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1, 0}; const int inf = 1 << 30; long long a[100500], sum; int i, n, t; int main() { srand(time(0)); scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%I64d", a + i); for (i = 1...
1
#include <bits/stdc++.h> int main() { int t; char s[105]; scanf("%d", &t); while (t--) { int l, i, count, z = 0, o = 0; scanf("%s", &s); l = strlen(s); for (i = 0; i < l; i++) { if (s[i] == '0') { z++; } else { o++; } } if (o > z) { count = z; ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <typename T> using matrix = vector<vector<T>>; constexpr int INF = (int)1e9 + 7; constexpr int MAXN = (int)1e3 + 1; constexpr int MOD = (int)1e9 + 7; constexpr double EPS = 1e-9; vector<pii> t; bool check(int s, int...
4
#include <bits/stdc++.h> using namespace std; int main() { long long a, i, x, y; scanf("%I64d ", &a); while (a--) { scanf("%I64d %I64d", &x, &y); i = ceil(cbrt(x * y)); if (x % i == 0 && y % i == 0 && (x * y) == i * i * i) { printf("Yes\n"); } else printf("No\n"); } }
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, sm, x, i, j, k, gen[11] = {0}; cin >> n >> m; for (i = 0; i < n; i++) { cin >> k; gen[k]++; } sm = 0; x = 1; for (i = 1; i <= m; i++) { for (j = i + 1; j <= m; j++) { x = gen[i] * gen[j]; sm = sm + x; ...
1
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = 3.14159265359; vector<long long> primes; void GeneratingPrimes(int top) { vector<bool> p(top + 1, 1); p[0] = p[1] = 0; for (int i = 2; i <= sqrt(top); i++) { if (p[i]) { for (int j = i * i; j <= top; j += i) { ...
5
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 10; int par[maxN]; int n, k; bool isPower(int n) { int dd = (n + 1); return ((dd & (dd - 1)) == 0); } bool can[105][105]; bool ok(int n, int k) { if (n < 100) { if (!can[n][k]) { return false; } } else { if (k == 0) { i...
10
#include <bits/stdc++.h> using namespace std; #define int long long //#define mp make_pair #define pb push_back const int INF = (int)1e18; const int N = 111; const int MAXN = (int)1e9; const int md = (int)1e9 + 7; const int DEBUG = 0; mt19937 rnd(time(nullptr)); vector<int> ans; int ask(int t,int i,int j,int x){ ...
6
#include <bits/stdc++.h> using namespace std; vector<int> in[2 * 100000 + 5], out[2 * 100000 + 5]; bool cycle; int visited[100000 + 5]; int done[100000 + 5]; int offset = 1; void dfs(int v) { visited[v] = offset; for (int i = 0; i < out[v].size(); ++i) { int u = out[v][i]; if (visited[u] == 0) { dfs(u...
7
#include <bits/stdc++.h> using namespace std; int n; string c; set<int> s[2]; int numL, numR; int ans[100001]; inline void work(int type) { int p = 0; for (int i = 1; i <= n; i++) { if (s[type].lower_bound(p) == s[type].end()) { ans[0]++; p = *s[type].begin(); } else { p = *s[type].lower_b...
9
#include <bits/stdc++.h> using namespace std; inline int add(int a, int b) { return (a + b >= 1000000007) ? a + b - 1000000007 : a + b; } inline void inc(int &a, int b) { a = add(a, b); } inline int mul(int a, int b) { return 1ll * a * b % 1000000007; } int dp[55][55][2] = {{0}}; int comb[55][55] = {{0}}; const int i...
9
#include <bits/stdc++.h> using namespace std; int ans[100005]; int dp[100005]; int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); int q, k; cin >> q >> k; dp[0] = 1; for (int i = 1; i <= 100000; i++) { if (i < k) dp[i] = dp[i - 1]; else dp[i] = dp[i - 1] + dp[i - k]; dp[...
4
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7, INF = 0x3f3f3f3f; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long qpow(long long a, long long n) { long long r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } long lo...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int count = 0; int k = 0; int r = 0; for (int i = 0; i < n; i++) { if (a[i] == 0 && k == 0) continue; else if (a[i] == 1) { if (r == 1) { c...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; char s[N]; int ans; void dfs(int l, int r, int cnt, char c) { if (l == r) { if (s[l] != c) cnt++; ans = min(ans, cnt); return; } int cnt1 = 0, cnt2 = 0, mid = l + r >> 1; for (int i = l; i <= mid; i++) if (s[i] != c) cnt1++; ...
3
#include <bits/stdc++.h> using namespace std; int n, top, zhan[500001]; long long ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); while (top > 1 && zhan[top - 1] >= zhan[top] && zhan[top] <= x) { ans += min(zhan[top - 1], x); top--; } zhan[++...
8
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) using namespace std; typedef unsigned long long ull; typedef pair <int, int> pii; typedef long long ll; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar()...
9
#include <bits/stdc++.h> using namespace std; int vocala(char c) { if (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U') return 1; if (c == 'y' || c == 'Y') return 1; return 0; } int isprime(long long n) { if (n <= 1) return 0; for ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false), cout.tie(0), cin.tie(0); int n, x; cin >> n >> x; int ans = 0, last = 0; while (n--) { int l, r; cin >> l >> r; ans += (l - last - 1) % x; ans += r - l + 1; last = r; } cout << ans << endl; ...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 13; int n; int cnt[MAXN]; int fr[MAXN]; int sum_from_root[MAXN]; int mx_from_bot[MAXN]; int added[MAXN]; int main() { cin >> n; for (int i = 2; i <= (1 << (n + 1)) - 1; i++) { cin >> cnt[i]; } int max_cnt = 0; for (int i = (1 << n); i <= ...
3
#include <bits/stdc++.h> using namespace std; int n, k, l = 0, r = 10000, a[1000], b[1000]; bool solve(int mid) { int kk = k; for (int i = 0; i < n; i++) { if (mid * a[i] > b[i]) { kk -= (mid * a[i] - b[i]); } if (kk < 0) return false; } return true; } int main() { cin >> n >> k; for (int ...
3
#include <bits/stdc++.h> using namespace std; string s[4][105]; string t[205]; int per[4]; int main() { int n; scanf("%d", &n); for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) cin >> s[i][j]; } per[0] = 0, per[1] = 1, per[2] = 2, per[3] = 3; int ans = 1e9; do { for (int i = 0; i < n; i++...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; unordered_map<int, int> idx; for (int i = 0; i < n; i++) { cin >> a[i]; idx[a[i]] = i; } vector<int> was(n, 0); int flag = 1, id; int f = n, sub_coun...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 20; pair<long long, long long> b[maxn]; long long a[maxn], res[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i].first, b[i].second = i; sort(a, a + n); sort(b, b + n); ...
2
#include <bits/stdc++.h> using namespace std; struct __timestamper {}; void make_op(vector<int>& x, vector<pair<int, int>>& ans, int i, int j) { x[i] ^= x[j]; ans.push_back(make_pair(i, j)); } void make_swap(vector<int>& x, vector<pair<int, int>>& ans, int i, int j) { if (i == j) return; make_op(x, ans, i, j); ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int curr = 0; int energy = 0; int ans = 0; for (int i = 0; i < n; i++) { if (v[i] >= curr) { if (v[i] - curr > energy) { ans = ans + v[i] - curr - ener...
1
#include <bits/stdc++.h> using namespace std; long long int n, k; int a[200005]; int main() { int t; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &k); int pos = 0, mn = 1000000000; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (i > k && a[i] - a[i - k] < mn) { mn = a[i]...
4
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int a[200005], nex[200005], pre[200005], ans[200005]; void NSE(int arr[], int n) { stack<int> s; s.push(1); for (int i = 2; i <= n; i++) { int v = arr[i]; while (!s.empty() && arr[s.top()] > v) { nex[s.top()] = i; s.pop(); } ...
5
#include <bits/stdc++.h> using namespace std; vector<long long> v1[300001], v2[300001]; map<long long, long long> vis; long long n, m, k, xb, xx, yy, s = 1, a[300001]; inline long long read() { long long sum = 0, x = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') x = -1; ch = getcha...
7