solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const double pi = acos(0.0) * 2.0; const double eps = 1e-12; const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; template <class T> inline T abs1(T a) { return a < 0 ? -a : a; } template <class T> inline ...
9
#include <bits/stdc++.h> using namespace std; int a[2005]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } sort(a + 1, a + n + 1); long long sum = 0; for (int i = n; i >= 1; i -= k) { sum += abs(a[i] - 1) * 2; } printf("%lld\n", sum); }
2
#include <bits/stdc++.h> using namespace std; char s[2222222]; int n, p[2222222], a[2222222], b[2222222], m; int main() { scanf("%d%s", &n, s + 1); for (int i = 1, j = 0; i <= n; i++) { p[i] = 0; if (j + p[j] - 1 >= i) p[i] = min(p[2 * j - i], j + p[j] - i); if (i + p[i] - 1 >= j + p[j] - 1) for (...
10
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - '0' + c, c = getchar(); x *= f; } bool fg; void FUCK() { printf("YES"); exi...
9
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; cout << -(n - 1) << " " << n << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t; cin >> t; while (t--) solve(); return 0; }
0
#include <bits/stdc++.h> using namespace std; signed main() { ios ::sync_with_stdio(0); cin.tie(0); string t; cin >> t; string s = ""; long n = t.size(); for (long i = 0; i < n; i++) { s += '0'; } deque<long> a; for (long i = 0; i < n; i++) { if (i % 2) { a.push_back(i); } else { ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int *arr = new int[n]; int *arr2 = new int[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; arr2[i] = arr[i]; } sort(&arr2[0], &arr2[n]); if (arr2[0] == arr2[1]) cout << "Still Rozdil"; else for (int i = 0; i <...
0
#include <bits/stdc++.h> using namespace std; long long const max1 = 1e5 + 5; long long const mod = 1e9 + 7; long long inf = 1e18; vector<long long> adj[max1]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); long long tc = 1; while (tc--) { long long n; cin >> n; long long a[n]; map<long l...
4
#include <bits/stdc++.h> using namespace std; const int inf = (int)1.01e9; const long long infll = (long long)1.01e18; const long double eps = 1e-9; const long double pi = acos((long double)-1); mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x) { return mrand() % x; } void precalc() ...
9
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, k, ans = 0; cin >> n >> k; long long a[n]; map<long long, long long> m1, m2; for (long long int i = 1; i <= n; i++) { cin >> a[i]; m2[a[i]]++; } for (long lon...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t-- > 0) { int n; cin >> n; int a; int f[51] = {0}; for (int i = 0; i < 2 * n; i++) { cin >> a; if (f[a] == 0) { f[a]++; cout << a << " "; } } std::cout << "\n"; } r...
0
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int check(vector<int>& a, int d, int& x) { int n = (int)a.size(); int l = 0, r = 0; int res = 0; while (r < n) { while (r < n && a[r] - a[l] <= d) { if (res < r - l + 1) { res = r - l + 1; x = l; } ++r; ...
4
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); } const long long maxn = 2e6 + 200; long long n, m, k, l, r; vector<long long> arr(maxn, 0); vector<...
4
#include <bits/stdc++.h> using namespace std; string s[1000]; int main() { int n, m, k = 0, l = 0, f = 0, g = 0; cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; if (n == 3 && m == 3 && s[0] == ".*." && s[1] == ".*." && s[2] == ".**") { cout << "YES" << endl << 3 << " " << 2; } else if (n == 3 && m...
3
#include <bits/stdc++.h> using namespace std; namespace myrand { mt19937 mt(chrono::system_clock::now().time_since_epoch() / chrono::microseconds(1)); long long Int(long long l, long long r) { return uniform_int_distribution<long long>(l, r)(mt); } } // namespace myrand using namespace myrand; auto ss = c...
7
#include <bits/stdc++.h> using namespace std; const int N = 1010; int w[N][N]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) { for (int j = i + 1; j <= i + k; ++j) { w[i][j % n] = 1; w[j % n][i] = 0; } } bool ok = true; vector<pair<int, int> > ans; for (int i = (0);...
3
#include <bits/stdc++.h> using namespace std; int n, k, j, a[1000000], b[1000000]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> b[i]; k = b[n - 1]; for (int i = n - 2; i >= 0; i--) { if (k >= b[i]) a[i] = k - b[i] + 1; else k = b[i]; } for (int i = 0; i < n; i++) cout << a[i...
1
#include <bits/stdc++.h> using namespace std; const long long inff = 0x3f3f3f3f3f3f3f3f; int n, a[5008], dp[5008][3], qw, ans[5008]; int main() { cin.tie(0); cout.tie(0); cin >> n; qw = (n + 1) / 2; for (int i(1); i <= (n); ++i) scanf("%d", &a[i]); memset(dp, int(0x3f3f3f3f), sizeof(dp)), dp[0][0] = 0; fo...
5
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar(); return x * f; } int main() { long long...
6
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846264338327950288; using namespace std; 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 fact[1000009]; long long int pow1(long long int x, long long int n) { if...
5
#include <bits/stdc++.h> using namespace std; int DEBUG = 0; int main(int argc, char **argv) { DEBUG = (argc >= 2) ? atoi(argv[1]) : 0; int n; scanf("%d", &n); if (n == 1) { cout << 1 << endl; return 0; } if ((n % 4) == 0 || (n % 4) == 1) { int k = n / 4; for (int i = 1; i <= k; i++) { ...
3
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const long long M = 10000007; long long f, T, t0; long long a1, t1, p1; long long a2, t2, p2; void solv() { scanf("%lld%lld%lld", &f, &T, &t0); scanf("%lld%lld%lld", &a1, &t1, &p1); ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n{}; cin >> n; long long int b[n]; long long int min{}, max{}; long long int min_count{}, max_count{}; for (int i{}; i < n; ++i) { cin >> b[i]; if (b[i] <= min || min == 0) { if (b[i] == min) ++min_count; else { ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 550; const int inf = 1e9 + 7; int a[maxn][maxn]; int b[maxn][maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int a[MAX], b[MAX]; char s[MAX]; int main() { int n; scanf("%d%s", &n, s + 1); for (int i = 1; i <= n; i++) { if (s[i] == 'D') a[i] = 1; else a[i] = 2; } int cnt1 = 0, cnt2 = 0; while (1) { for (int i = 1; i <= n;...
3
#include <bits/stdc++.h> using namespace std; bool* m_criba; void criba(bool*& m, int tam) { m = new bool[tam + 1]; m[0] = m[1] = false; for (int i = 2; i <= tam; ++i) m[i] = true; for (int i = 2; i * i <= tam; ++i) if (m[i]) for (int h = 2; i * h <= tam; ++h) m[i * h] = false; } int* cf; void criba_f...
4
#include <bits/stdc++.h> using namespace std; int visited[1002] = {0}; vector<pair<int, int> > from(1002, {0, 0}); vector<pair<int, int> > to(1002, {0, 0}); class triple { public: int a, b, c; triple(int n, int m, int p) { a = n; b = m; c = p; } }; int val; int dfs(int &u) { visited[u] = 1; if (t...
3
#include <bits/stdc++.h> using namespace std; string s; int Ask(string s, int n) { cout << "? " + s.substr(0, n) << endl; fflush(stdout); int ret; cin >> ret; return ret; } void flip(int l, int r) { for (int i = l; i < r; i++) { if (s[i] == '1') { s[i] = '0'; } else { s[i] = '1'; } ...
6
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> a, bad, sbad, ubound, lbound, az, lb, bl, in, shift; vector<vector<int> > ub, p; set<pair<int, int> > se; vector<pair<int, int> > q; bool cmp(int i, int j) { return a[i] < a[j]; } bool ok() { for (int i = 0; i + k < n; ++i) { bool fl = false; ...
8
#include <bits/stdc++.h> using namespace std; char str[200100]; int n; int q; int C[200100][26]; bool possible(int l, int r) { int l2 = l - 1; if (l2 < 0) l2 = 200050; int distinct = 0; for (int i = 0; i < 26; i++) { distinct += (C[r][i] - C[l2][i]) > 0; } if (l == r) { return true; } if (distin...
5
#include <bits/stdc++.h> using namespace std; long long color[1010]; long long fact[1010]; long long powr(long long a, long long p, long long m) { if (p == 0) return 1; if (p & 1) return (a * (powr(a, p - 1, m))) % m; long long x = powr(a, p / 2, m); return ((x * x) % m); } long long ways(long long n, long long...
3
#include <bits/stdc++.h> using namespace std; int n; string s; map<string, pair<int, int>> mp; pair<int, int> M[41][41][2]; bool ok(string &t) { for (int i = 0; i < n; ++i) { if (equal(s.begin(), s.end(), t.begin())) return true; rotate(t.begin(), t.begin() + 1, t.end()); } return false; } bool ok(int pre...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; const int offset = 1 << 18; struct tournament { int t[2 * offset]; tournament() { for (int i = 0; i < offset; i++) t[i + offset] = 1; for (int i = offset - 1; i >= 0; i--) t[i] = t[2 * i] + t[2 * i + 1]; } void update(int pos) { ...
6
#include <bits/stdc++.h> using namespace std; long long int l1, l2, r1, r2, k; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> l1 >> r1 >> l2 >> r2 >> k; long long int t1 = max(l1, l2); long long int t2 = min(r1, r2); long long int ans = t2 - t1 + 1; if (k >= t1 && k <= t2) ans...
1
#pragma GCC optimize("O3") #pragma GCC target("avx2") #include <iostream> using namespace std; #define f(x,y,z) for(int x=y;x<z;++x) int t, n, c, rem, cur, ans, bar, a[200000], b[200000]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); for(cin >> t; t--;) { cin >> n >...
5
#include <bits/stdc++.h> const int mod = 1e9 + 7; using namespace std; int n, x = 0, y = 0, w = 1, fac[200010], ifac[200010], inv[200010], a[200010]; long long m, sum[200010]; int& qmo(int& x) { return x += (x >> 31) & mod; } void init(int N) { fac[0] = inv[1] = ifac[0] = 1; for (int i = 1; i <= N; i++) fac[i] = 1l...
8
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); using namespace std; map<int, pair<int, int> > M; int k, n; vector<int> result; cin >> k; for (int i = 0; i < k; i++) { cin >> n; vector<int> A(n); for (int j = 0; j < n; j++) cin >> A[j]; int s = accumulate(A.begin(),...
3
#include <bits/stdc++.h> using namespace std; const int N = 100005; int u[N], arr[N]; int root(int a) { if (u[a] != u[u[a]]) u[a] = root(u[a]); return u[a]; } void unionf(int a, int b) { int p = root(a); int q = root(b); u[q] = u[p]; } int main() { int n, s, t; cin >> n >> s >> t; for (int i = 0; i < n ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 100110; const int maxm = 100010; char s[maxn][5]; long long sum[maxm * 4][5][11]; int n; void init() { for (int i = 1; i < maxn; i++) for (int z = 2; z <= 6; z++) { int tp = i % (2 * (z - 1)); if (tp == 0) s[i][z - 2] = 2; el...
6
#include <bits/stdc++.h> using namespace std; int a[2][100007]; int main() { int n, s, p, q, h; char ch; scanf("%d%d", &n, &s); for (int i = 1; i <= n; i++) { getchar(); scanf("%c%*c%d%d", &ch, &p, &q); if (ch == 'S') h = 0; else h = 1; a[h][p] += q; } vector<pair<int, int> >...
2
#include <bits/stdc++.h> using namespace std; signed main() { long long a, b, c, d, t, n; scanf("%lld", &t); while (t--) { scanf("%lld%lld%lld%lld", &a, &b, &c, &d); if (a > b * c) { printf("-1\n"); continue; } n = (a - 1) / b / d; printf("%lld\n", (n + 1) * a - d * (n + 1) * n / 2...
6
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, cc, x, a[N], fa[N]; map<int, int> nxt[N]; long long ans, sum[N]; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); cc = x = ans = 0; sum[x] = 1; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); ...
9
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 10 + 5, inf = 1e9 + 5; int n, boom; char sci[N][N], cap[N][N]; int id[N][N]; pair<int, int> reactor; int dr[] = {-1, 0, 1, 0}; in...
7
#include <bits/stdc++.h> const static int N = 100010, M = N << 1; int head[N], opp[M], nxt[M], q[N], d[N]; bool vis[N]; int n, tot; void ins(int x, int y) { opp[++tot] = y; nxt[tot] = head[x]; head[x] = tot; } int main() { scanf("%d", &n); int x, y; for (int i = (2); i <= (n); i++) scanf("%d %d", &x, &y), i...
7
#include <bits/stdc++.h> using namespace std; inline long long tavan(long long a, long long n, long long mod) { long long p = 1; while (n > 0) { if (n % 2) { p = p * a; p %= mod; } n >>= 1; a *= a; a %= mod; } return p % mod; } long long a, b, c, x, y, z, ans; int main() { ios_...
2
#include<bits/stdc++.h> #define cs const #define pb push_back using namespace std; cs int N = 105; int n, dp[N][N * N], a[N], b[N]; int main(){ #ifdef FSYo freopen("1.in", "r", stdin); #endif cin >> n; int S = 0; memset(dp, -0x3f, sizeof(dp)); dp[0][0] = 0; for(int i = 1; i <= n; i++) { scanf("%d%d", &a[i], ...
6
#include <bits/stdc++.h> using namespace std; void print1D(vector<long long> a) { for (long long i = 0; i < a.size(); ++i) { cout << a[i] << " "; } cout << endl; } void print2D(vector<vector<long long> > a) { for (long long i = 0; i < a.size(); ++i) { for (long long j = 0; j < a[i].size(); ++j) { ...
1
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, m; vector<int> adl[N]; unordered_map<int, bool> gak[N]; int par[N], sz[N]; vector<int> uni[N]; int find(int a) { if (par[a] == a) return a; return par[a] = find(par[a]); } void make(int a, int b) { a = find(a); b = find(b); if (a == ...
6
#include <bits/stdc++.h> using namespace std; const long long int y = 1000; const long long int INF = y * y * y * y * y * y; int main() { int n; cin >> n; vector<int> a(n); int n0 = 0, n1 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0) n0 = i; else n1 = i; } cout << ...
0
#include <bits/stdc++.h> using namespace std; int n; long long p(int k) { long long ret = 1; for (int i = 0; i < k; i++) ret *= 2; return ret; } long long compute(long long l, long long r) { if (l == r) return l; int ret = 0, ind = -1; for (int i = 62; i >= 0 && ind == -1; i--) if (p(i) <= r) ind = i; ...
4
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { assert(y >= 0); x += y; if (x >...
11
#include <bits/stdc++.h> using namespace std; const int SVSZ = 10000001; int spf[SVSZ]; void buildSieve() { vector<int> primes; spf[0] = spf[1] = 1; for (int i = 2; i < SVSZ; i++) { if (spf[i] == 0) { primes.push_back(i); spf[i] = i; } for (int j = 0; j < int(primes.size()) && pri...
6
#include <bits/stdc++.h> using namespace std; long double p[111], a[111]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); a[i] = x / 100.0; } if (n == 1) { puts("1.00000000"); return 0; } long double cur = 1.0; for (int i = 1; i <= n; i++) p[...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; int ans; ans = x % y; if (ans == 0) cout << ans << endl; else { ans = y - ans; cout << ans << endl; } } return 0; }
3
#include <bits/stdc++.h> using namespace std; long long cross(pair<int, int> a, pair<int, int> b) { return 1LL * a.first * b.second - 1LL * a.second * b.first; } long long ccw(pair<int, int> a, pair<int, int> b, pair<int, int> c) { pair<int, int> p = pair<int, int>(b.first - a.first, b.second - a.second); pair<in...
8
#include <bits/stdc++.h> using namespace std; template <typename T> void trace(const char* name, T&& arg1) { cout << name << " : " << arg1 << endl; } template <typename T, typename... Args> void trace(const char* names, T&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comm...
6
#include <bits/stdc++.h> using namespace std; using Int = long long; int main() { int N; cin >> N; vector<int> U(N); for (auto &u : U) cin >> u; map<int, int> counter, numbers; int ans = 0, maxnum = 0; for (int i = 0; i < N; i++) { int k = ++counter[U[i]]; maxnum = max(maxnum, k); numbers[k - ...
3
#include <bits/stdc++.h> using namespace std; int n, i, m, r, Max, x, idx, cur, cnt; int a[100001]; int main() { cin >> n >> m >> r; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= m; i++) { cin >> x; Max = max(Max, x); } sort(a + 1, a + n + 1); idx = 1; while (idx <= n && r && a[idx] < Max...
0
#include <bits/stdc++.h> using namespace std; int n; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; cout << n << "\n"; for (int i = 0; i < n; i++) { cout << 1 << " "; } }
0
#include <bits/stdc++.h> using namespace std; int n; double l, r; double x[30], y[30], a[30]; double dp[1 << 21]; int main() { scanf("%d %lf %lf", &n, &l, &r); for (int i = 0; i < n; ++i) scanf("%lf %lf %lf", &x[i], &y[i], &a[i]), a[i] *= M_PI / 180.0, x[i] -= l; r -= l; l = 0; for (int i = 0; i < (1 << n...
7
#include <bits/stdc++.h> using namespace std; int b[201000], c[201000]; long long a[201000], pow2[70]; int cnt[70], num[70]; int main() { pow2[0] = 1; for (int i = 1; i < 70; i++) pow2[i] = pow2[i - 1] << 1; int n; scanf("%d", &n); long long sum = 0; for (int i = 1; i <= n; i++) scanf("%d", &b[i]), sum += b...
8
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long x, y, n; cin >> x >> y >> n; long long k = n / x; while (k >= 0) { if (((k * x) + y) % x == y && ((k * x) + y) <= n) { break; } k = k - 1; } cout << (k * x) +...
0
#include <bits/stdc++.h> using namespace std; int n, x[1000001], num[100001], m, m2, ans[100001], num2[100001]; char c[1000001]; bool flag; map<int, int> f; int main() { flag = true; scanf("%d", &n); for (int i = 1; i <= 2 * n; i++) { cin >> c[i]; if (c[i] == '+') continue; else scanf("%d"...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll inf = 1000000001, INF = (ll)1e18 + 1; ld sqrd(ld x) { return x * x; } ld dist(pair<ld, ld> a, pair<ld, ld> b) { if (a.first == b.first) return abs(a.second - b.second); if (a.second == b.second) return abs(a.first -...
5
#include <bits/stdc++.h> using namespace std; bool iseq(vector<int> a, vector<int> b) { for (int i = 0; i < (int)a.size(); i++) if (a[i] != b[i]) return false; return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n), b(n); map<int, int> sat; for (int ...
3
#include <bits/stdc++.h> using namespace std; long long cap[350][350]; long long flw[350][350]; char vis[350]; long long maxcr; int in[350], out[350]; int cnum; int from[100000], to[100000]; long long mov[100000]; long long cur[350]; int n, e; long long st, beg; long long scnd; int fulkerson(int u, long long cur) { i...
8
#include <bits/stdc++.h> using namespace std; bool is_good_permutation(vector<int>& vec) { int i = 0; for (auto a : vec) { if (a != ++i) return false; } return true; } void swap_column(vector<vector<int>>& mtx, int first, int second) { for (int i = 0; i < mtx.size(); ++i) { swap(mtx[i][first], mtx[i][...
3
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e18 + 7; const long long MOD = 1e9 + 7; const int MAX = 1e9 + 10; const long long int N = 2e5 + 2; using namespace std; void solve() { int n; cin >> n; vector<int> l(n), r(n); multiset<int> start, end; for (int i = 0; i < n; ++i) { c...
4
#include <bits/stdc++.h> using namespace std; int n, x, cnt[2000100], y, a[500100], b[2000100]; long long pnt[2000100]; int main() { scanf("%d%d%d", &n, &x, &y); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); cnt[a[i]]++; pnt[a[i]] += a[i]; } for (int i = 1; i <= 2000000; i++) { cnt[i] += cn...
6
#include <bits/stdc++.h> using namespace std; int n, len; string s; int a[100]; int main() { cin >> n >> s; len = int(s.size()); for (int i = 0; i < (int)(len); ++i) { a[i] = int(s[i] - '0'); } long long ans = 0; long long mul = 1; while (len) { int best = -1; for (int i = 0; i < (int)(len); +...
6
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } namespace Factor { const int N = 2010000; lo...
10
#include <bits/stdc++.h> using namespace std; int freq[26]; vector<vector<int> > v(26); int main() { ios_base::sync_with_stdio(0); cin.tie(0); string str; cin >> str; int n = str.size(); for (int i = 0; i < n; i++) freq[str[i] - 'a']++, v[str[i] - 'a'].push_back(i); double res = 0; for (int i = 0; i...
4
/* ******************** Author : Samarth Gupta ******************** */ #include <algorithm> #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #define mod (int) 998244353 #define MOD (int) 1e9+7 // Big two primes #define X 1001100011100001111ll #define all(a) a.begin(),a.end...
3
#include <bits/stdc++.h> int main() { int n, c = 0; scanf("%d\n", &n); char p[150]; int i; for (i = 0; i < n; i++) { gets(p); if ((p[0] == '-' && p[1] == '-') || (p[1] == '-' && p[2] == '-')) c--; if ((p[0] == '+' && p[1] == '+') || (p[1] == '+' && p[2] == '+')) c++; } printf("%d\n", c); ret...
0
#include <bits/stdc++.h> using namespace std; vector<long long> g[300000 + 1]; vector<long long> v(300000 + 1, 0); bool check(long long x) { long long cnt = 0; for (auto it : g[x]) { if (v[it] == v[x]) cnt++; } return (cnt > 1); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 100 * 1000 + 20, inf = 1e9; int a[N], ans[N], nxt[N], prv[N], n, dp[N], cnt[N], mx; void read_input() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; } void LIS() { fill(dp, dp + n + 1, inf); dp[0] = -inf; for (int i = 0; i < n; i++) { prv[i...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; const int T = 1 << 11; int MAX = 100009; vector<int> parent(MAX, -1); vector<int> rang(MAX, 0); void make_set(int v) { parent[v] = v; rang[v] = 0; } int find_set(int v) { if (parent[v] == v) return (v); return (parent[v] = find_set(parent[v])...
4
#include <bits/stdc++.h> using namespace std; int n, k, l, r, m, s, t; int main() { cin >> n >> k; l = 0; r = n + 1; while (r - l != 1) { m = (l + r) / 2; s = m; t = k; while (m / t > 0) { s += m / t; t *= k; } if (s >= n) { r = m; } else { l = m; } } ...
3
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long y = 1; for (long long i = 0; i < n; i++) { if (a[i] != i + 1) y = 0; } if (y) { cout << 0 << '\n'; return; } y = 1; for (long lon...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; unordered_map<long long, pair<long long, long long>> sum; vector<long long> a; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long seed; asm("rdtsc" : "=A"(seed)); srand(seed); long long p; cin >> p; for (...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using i32 = int32_t; using i64 = int64_t; using ui32 = uint32_t; using ui64 = uint64_t; using pii = pair<int, int>; using pdd = pair<double, double>; using vpii = vector<pii>; using vpdd = vector<pdd>; int64_t fuse(int i1, int i2) { return (((int64_t)i...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; if (a != c) { cout << a << " " << c << endl; } else if (a != d) cout << a << " " << d << endl; else if (b != c) cout << b << " " << c << endl; ...
0
#include <bits/stdc++.h> using namespace std; int N, a[(int)1e6 + 1][2], chk[801], res[801]; int main() { scanf("%d", &N); for (int i = 2; i <= N * 2; i++) for (int j = 1; j < i; j++) { int x; scanf("%d", &x); a[x][0] = i; a[x][1] = j; } for (int i = 1e6; i >= 0; i--) { if (a[i...
2
#include <bits/stdc++.h> using std ::max; inline int geti() { int x = 0, c = getchar(); while (!isdigit(c)) c = getchar(); for (; isdigit(c); c = getchar()) x = x * 10 + (c & 15); return x; } const int N = 400005; int n, hd[N], cnt, fa[N], siz[N], f[N], g[N], h[N]; struct edge { int to, nxt; } e[N << 1]; void...
7
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int MINF = -1000000000000000000; long long int powmod(long long int a, long long int b) { long long int res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } r...
3
#include <bits/stdc++.h> int N, H; unsigned long long T[36][36], ans; using namespace std; int main() { cin >> N >> H; T[0][0] = 1; for (int i = 1; i <= N; i++) for (int h = 1; h <= i; h++) { for (int r = 1; r <= i; r++) { for (int hr = 0; hr <= h - 1; hr++) T[i][h] += T[r - 1][h - 1] ...
5
#include <bits/stdc++.h> using namespace std; template <typename _t> inline void read(_t &x) { x = 0; _t fu = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fu = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch & 15); ch = getchar();...
7
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; string a[N]; bool sort1(string s, string r) { return s + r < r + s; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, sort1); for (int i = 0; i < n; i++) cout << a[i]; }
4
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; string s = ""; bool f = 0; for (int i = 0; i < a.size(); i++) { if (i == 0) s += a[0]; else if (a[i] < b[0]) s += a[i]; else { s += b[0]; f = 1; break; } } if (f == 0) s += ...
1
#include <bits/stdc++.h> using namespace std; string solve(string s) { if (s.size() % 2 != 0) return s; string s1 = solve(s.substr(0, s.size() / 2)); string s2 = solve(s.substr(s.size() / 2, s.size() / 2)); if (s1 < s2) return s1 + s2; else return s2 + s1; } int main() { ios_base::sync_with_stdio(0)...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 7; const long long M = 998244353; int d[maxn], n, u, v; long long f[maxn], ans; int main() { cin >> n; for (int i = 1; i < n; i++) { scanf("%d%d", &u, &v); d[u]++; d[v]++; } ans = n; f[0] = 1; for (int i = 1; i <= n; i++) f[i] ...
5
#include <bits/stdc++.h> using namespace std; int n, a, b, T; char s[600000]; int sf[600000]; int pf[600000]; int get_best_t(int k) { if (k == 0) { return 0; } int ans = 1234567890; for (int(i) = (0); (i) < (int)(k); ++(i)) { int go_r = pf[i + 1] + i * a; int go_l = sf[i + 1] + i * a; int rest =...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx") using namespace std; const long long INF = (long long)1e18; const int inf = (int)1e9; const int N = (int)10000; const int MOD = (int)1e9 + 7; const int base = 998244353; const double eps = (double)1e-9; c...
0
#include <bits/stdc++.h> using namespace std; map<vector<long long>, long long> df; struct fen { long long n, m; vector<vector<long long>> d; fen(long long n, long long m) { this->n = n; this->m = m; d.resize(n + 13); for (long long i = 0; i <= n; i++) d[i].resize(m + 13); } void sumupdv(long ...
8
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { string str; cin >> n; int ans = 0; while (cin >> str) { int cnt = 0; for (int i = 0; i < str.size(); i++) if (str[i] >= 'A' && str[i] <= 'Z') ++cnt; ans = max(ans, cnt); } cout << ans << "\n"; return 0; }
0
#include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; using pii = pair<int, int>; template<typename... T> void rd(T&... args) {((cin>>args), ...);} template<typename... T> void wr(T... args) {((cout<<args<<" "), ...); cout<<'\n';} int mai...
10
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long MAX = 1e17; long long a[200005], fact[200005], inv[200005], s[105][200005]; long long powmod(long long a, long long b) { if (b == 0) return 1ll; if (b == 1) return a; long long t = powmod(a, b / 2); if (b % 2 == 0) return (t * t) %...
8
#include <bits/stdc++.h> using namespace std; pair<int, int> pii; pair<long long, long long> pll; vector<vector<int>> edge; int main() { int t; cin >> t; while (t--) { long a, b, q; cin >> a >> b >> q; int size = a * b; vector<int> pre(size); for (int i = 0; i < size; i++) { if (i != 0) ...
4
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int N = 100000; const int S = 32; long long a[N], p[S]; int main() { p[0] = 1; for (int i = 1; i < S; i++) p[i] = p[i - 1] * 2; long long ans = -1, ansL = INF; int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { long long q...
4
// **************************** Prajwal ******************************** #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; //template <typename T> using ordered_set = tree<T, nul...
1