solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") using namespace std; void solution() { int m; vector<vector<int> > graph(5); cin >> m; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; u--; v--; graph[u].push_back(v...
5
#include <bits/stdc++.h> using namespace std; template <class A, class B> inline bool mina(A &first, B second) { return (first > second) ? (first = second, 1) : 0; } template <class A, class B> inline bool maxa(A &first, B second) { return (first < second) ? (first = second, 1) : 0; } const int MAXR = 10; const int...
13
#include <bits/stdc++.h> using namespace std; int N, M, D; long long ans; map<int, int> C; set<pair<int, int> > S; int main() { scanf("%d %d %d", &D, &N, &M), C[D] = 1e9 + 3; for (int i = 0; i <= M; i++) { int x, c; if (i != 0) scanf("%d %d", &x, &c); else x = c = 0; if (!C.count(x)) ...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 2100; bool l[MAXN][MAXN], r[MAXN][MAXN], d[MAXN][MAXN], u[MAXN][MAXN]; char c[MAXN][MAXN]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> c[i][j]; for (int i = ...
15
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > v; vector<bool> th(1010), ch(1010); bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) retur...
9
#include <bits/stdc++.h> using namespace std; int main() { long long _; cin >> _; while (_--) { long long n; cin >> n; vector<long long> a(n), b(n); vector<long long> cnt1(n), cnt2(n); for (long long i = 0; i < n; i++) { cin >> a[i] >> b[i]; cnt1[a[i] - 1]++, cnt2[b[i] - 1]++; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; if (x == y && z == 0) cout << 0 << endl; else if (x > y) { if (x > y + z) cout << "+" << endl; else cout << "?" << endl; } else { if (y > x + z) cout << "-" << endl; else cou...
0
#include <bits/stdc++.h> using namespace std; inline long long read() { long long first = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9';) { if (ch == '-') f = -1; ch = getchar(); } for (; ch >= '0' && ch <= '9';) { first = first * 10 + ch - '0'; ch = getchar(); } return first ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, d; int f(int x) { return x + ceil((double)d / (x + 1)) - n; } int main() { int T; scanf("%d", &T); while (T--) { bool v = false; scanf("%d %d", &n, &d); int l = 0, r = n, mid; while (l <= r) { mid = (r + l) / 2; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, d, s = 0, i; cin >> n >> d; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } if ((n - 1) * 10 + s > d) cout << "-1"; else cout << (d - s) / 5; return 0; }
1
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, m, i, x; cin >> n >> m; priority_queue<int> pq; priority_queue<int, vector<int>, greater<int>> gq; for (i = 0; i < m; i++) { cin >> x; pq.push(x); gq.push(x); } long long int mx = 0, mn = 0, tmp; while (n--) { ...
3
#include <bits/stdc++.h> int n, k, p[100005], w[100005], num, v, x, ac, part; int parent(int x) { if (x == p[x]) return x; int y = p[x]; int z = parent(p[x]); w[x] += w[y]; w[x] = w[x] % 1000000007; p[x] = z; return z; } int main() { scanf("%d", &n); num = 0; ac = 0; while (n--) { ++num; p...
12
#include <bits/stdc++.h> using namespace std; int R, C; char M[501][501], F[501][501][9]; int main() { while (scanf("%d %d", &R, &C) == 2) { for (int i = 0; i < R; i++) scanf("%s", M[i]); for (int i = 0; i + 1 < R; i++) { for (int j = 0; j + 1 < C; j++) { int mask = 0; if (M[i][j] == '*'...
12
#include <bits/stdc++.h> using namespace std; map<string, set<string> > file, folder; char s[105][105]; int main() { int i, j, k = 0, T; while (scanf("%s", s[k]) != EOF) { string S = s[k]; vector<string> current; string x = "", y = ""; for (int i = 0; i < S.size(); i++) { x += S[i]; if (...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1002000; int n, k, fa[maxn]; vector<int> g[maxn]; int dep[maxn], minn[maxn]; int f[maxn], d[maxn]; void read() { scanf("%d%d", &n, &k); for (int i = 2; i <= n; i++) { scanf("%d", &fa[i]); g[fa[i]].push_back(i); } } void dfs(int now, int dp) { ...
17
#include <bits/stdc++.h> using namespace std; vector<long long> fb(1000010 + 1, 0), fe(1000010 + 1, 0); void update(long long which, long long idx, long long val) { if (which == 1) { while (idx < 1000010) { fb[idx] += val; idx += idx & -idx; } } else { while (idx < 1000010) { fe[idx] +...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long pw = 1; const long long X = 1000000009; for (int i = 0; i < m; ++i) { pw = (pw * 2) % 1000000009; } pw = pw % 1000000009; long long all = 1; for (int i = 1; i <= n; ++i) { long long r; if (pw - i ...
5
#include <bits/stdc++.h> using namespace std; const int MaxN = 100005; int a[MaxN], ax[MaxN], r[MaxN], mp[MaxN]; long long s[MaxN]; int N, M, K, cnt; long long tr[2][MaxN]; bool cmpR(const int& i, const int& j) { return ax[i] < ax[j]; } void init() { ax[N] = 0; for (int i = 0; i <= N; i++) { r[i] = i; s[i] ...
12
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 200; const int MAXCARD = 6 * MAXN; int n, ncard; int col[MAXCARD]; vector<vector<int>> an...
24
#include <bits/stdc++.h> using namespace std; string compare(string x) { if (x.size() % 2) return x; string a = compare(string(x, 0, x.size() / 2)); string b = compare(string(x, x.size() / 2, x.size())); if (a < b) return a + b; else return b + a; } int main() { ios_base::sync_with_stdio(false); c...
9
#include <bits/stdc++.h> using namespace std; void print(vector<int> x) { for (int i = 0; i < x.size(); i++) cout << x[i] << " "; cout << endl; } vector<int> dp1[500], dp2[500]; void F(int n) { dp1[n] = dp2[n - 1]; dp2[n] = {0}; dp2[n].insert(dp2[n].end(), dp1[n].begin(), dp1[n].end()); for (int i = 0; i < ...
14
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T a) { return ((a < 0) ? -a : a); } template <typename T> inline T sqr(T a) { return a * a; } const int INF = (int)1E9 + 7; const long double EPS = 1E-9; const long double PI = 3.1415926535897932384626433832795; string s; int n; struct...
15
#include <bits/stdc++.h> #pragma GCC optimize("fast-math") #pragma GCC optimize("unroll-loops") using namespace std; const long long INF = 1e9 + 228; const long long INFLL = 1e18; const long long MOD = 1e9 + 7; const long double eps = 1e-4; const long double eps2 = 1e-9; const long long MOD2 = 998244353; const long lon...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n, d, songc = 0, k; cin >> n >> d; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; songc += arr[i]; } songc += (n - 1) * 10; if (songc <= d) { cout << (d - songc + (n - 1) * 10) / ...
1
#include <bits/stdc++.h> using namespace std; set<int> v[100 + 50]; int main() { long long n, m; cin >> n >> m; long long aios = 0LL; for (long long i = 1; i <= m; i++) { long long tmp = 0; for (long long j = 1LL; j <= m; j++) { if ((i * i + j * j) % m == 0LL) { tmp++; } } tm...
8
#include <bits/stdc++.h> using namespace std; struct Tedge { int v, pre; } edge[200010 * 2]; int n, k, en, cur[200010], val[200010], fa[200010], tot, h[200010], typ[200010], siz[200010], dis[200010], vst[200010]; int getint() { int x, f = 1; char ch; while (!isdigit(ch = getchar())) f = ch == '-' ? -1 : 1; ...
18
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long ch[130], n; string s; long long jc[100005], inv[100005]; long long mul; long long dp[100005]; long long ans[130][130]; void init() { jc[0] = 1; for (int i = 1; i <= 100000; i++) jc[i] = jc[i - 1] * i % mod; inv[1] = inv[0] = 1;...
18
#include <bits/stdc++.h> using namespace std; struct debugger { static void call(const char* it) {} template <typename T, typename... valT> static void call(const char* it, T val, valT... rest) { string var = ""; for (; *it && *it != ','; it++) if (*it != ' ') var += *it; cerr << var << '=' << v...
0
#include <bits/stdc++.h> using namespace std; using cd = complex<double>; mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count()); const unsigned long long N = 1e6 + 5; unsigned long long p[N], n, c[N], sum, h[N]; map<unsigned long long, unsigned long long> us; int main() { ios::sync_with_stdio(0); c...
21
#include <bits/stdc++.h> int main(int n) { std::cin >> n; std::cout << n * 2 - 1 << " " << 2 << std::endl << 1 << " " << 2; }
6
#include <bits/stdc++.h> using namespace std; int a[105][105], c[105], r[105]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { c[j] += a[i][j]; r[i] += a[i][j]; } ...
13
#include <bits/stdc++.h> using namespace std; int n, i, j, k, rez, sol, v[1010]; int main() { scanf("%d", &n); v[1] = 1000; for (int i = 1; i <= n; ++i) scanf("%d", &v[i]); for (int i = 1; i <= n; ++i) { sol = 19999; for (int cif = 1; cif <= 9; ++cif) { rez = v[i] + ((cif - (v[i] / 1000) % 10) * 1...
9
#include <bits/stdc++.h> using namespace std; int main() { long long int n, f; cin >> n >> f; long long int k[n], l[n], a[n], sum = 0; for (int i = 0; i < n; i++) { cin >> k[i] >> l[i]; sum += min(k[i], l[i]); a[i] = min(2 * k[i], l[i]) - min(k[i], l[i]); } sort(a, a + n); for (int i = n - f; ...
5
#include <bits/stdc++.h> int n, k, t; int main() { scanf("%d%d%d", &n, &k, &t); if (t <= k) printf("%d", t); else if (t <= n) printf("%d", k); else printf("%d", k - (t - n)); return 0; }
0
#include <bits/stdc++.h> using namespace std; int TN = 1; const int N = 1e5 + 1; void solve() { int n, k; long long m; cin >> n >> m >> k; long long b[n]; vector<pair<long long, int> > x; for (int i = 0; i < n; i++) { cin >> b[i]; if (i > 0) { x.push_back({b[i] - b[i - 1], i}); } } if ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int a, b, s; cin >> a >> b >> s; s -= abs(a) + abs(b); if (s < 0 || s % 2) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; long long int qs(int a, int b) { long long int i = 1; for (a; a <= b; a++) { i *= a; i %= 1000000007; } return i; } int main() { int n, i, j, eve = 0; long long int a, b = 2, c = 1; cin >> n; for (i = 0; i < n; i++) { cin >> j; if (j % 2 == 1...
16
#include <bits/stdc++.h> using namespace std; struct edge { int s, t, cap, next; } e[5010]; int head[5010], cnt; void addedge(int s, int t, int cap) { e[cnt].s = s; e[cnt].t = t; e[cnt].cap = cap; e[cnt].next = head[s]; head[s] = cnt++; } int n, m, k, u, v, w; int degree[5010], ans[5010]; long long f[5010][...
10
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 10; const ll inf_ll = 1e18 + 10; using ld = long double; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<string> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int m = a[0].size(); ve...
18
#include <bits/stdc++.h> using namespace std; bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); } long long C(long long n, long long k) { if (k > n) return 0; if (k * 2 > n) k = n - k; if (k == 0) return 1; long long result = n; for (long long i = 2; i <= k; ++i) { result *= (n - i + 1); ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; string s, t; cin >> s >> t; int ox = 0, rx1 = 0, rx2 = 0; for (i = 0; i < (2 * n); i = i + 1) { if (s[i] == '1' && t[i] == '1') { ox++; } else if (s[i] == '1') { rx1++; } else if (t[i] == '1') { rx2+...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); int minv = 1e8; for (int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x, &y); minv = min(minv, y - x + 1); } printf("%d\n", minv); for (int i = 1; i < n; i++) printf("%d ", i % minv); printf("%d\n",...
9
#include <bits/stdc++.h> int a[1010], b[1010], n; void sort(int sta, int end) { if (sta >= end) return; int i, j, t; i = sta; j = end; while (i != j) { while (a[j] >= a[sta]) { if (i >= j) break; j--; } while (a[i] <= a[sta]) { if (i >= j) break; i++; } t = a[i]; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 10 + 5; bool t[N][N]; int r, c, n, k; int main() { cin >> r >> c >> n >> k; int help1, help2; for (int i = 0; i < n; ++i) { cin >> help1 >> help2; t[help1 - 1][help2 - 1] = true; } int help; int ans = 0; for (int x1 = 0; x1 < r; ++x1) ...
3
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); long long n, k; cin >> n >> k; int max_val = 0; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i], max_val = max(max_val, a[i]); auto ck = [&](long long mid) { double sum = 0; for (int i =...
16
#include <bits/stdc++.h> using namespace std; const int K = 52 + 1; const int N = 2e6; const int INF = 1e9; long long a[K][K], f[N], s[N]; vector<int> ans; int getNum(char c) { if (c >= 'a' && c <= 'z') return 1 + c - 'a'; else return 1 + 26 + (c - 'A'); } char getChar(int n) { if (n <= 26) return (ch...
15
#include <bits/stdc++.h> using namespace std; const long long M = 1000000007; const int maxn = 211111; long long n, k, p[maxn], ans, cnt[maxn], phi[maxn], mu[maxn], f[maxn]; vector<int> h[maxn]; void cc(int x, int y) { for (auto v : h[x]) { int r = y / v; for (auto vv : h[v]) cnt[vv] += mu[v / vv] * r; } } ...
23
#include <bits/stdc++.h> using namespace std; int n, w, m; vector<pair<int, double> > v[55]; int main() { cin >> n >> w >> m; double sum = w * n / double(m); double curCup = 0.0; int cur = 0; for (int i = 0; i < n; ++i) { double curMilk = w; if (curCup + curMilk - 1e-6 > sum) { v[cur].push_back(...
11
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5 + 5; const int inf = 1e8; const double PI = acos(-1.0); const long long mod = 100000007; int n, k; set<pair<int, int> > vis; struct node { int i, j, water; void inti() { i = 0; j = 0; water = -1; } }; queue<node> que; node op1(node x) ...
6
#include <bits/stdc++.h> using namespace std; int n; int test(int xl, int yb, int xr, int yt) { if (xl <= xr && xr <= n && xl >= 1 && yb <= yt && yt <= n && yb >= 1) { printf("? %d %d %d %d\n", xl, yb, xr, yt); fflush(stdout); int t; scanf("%d", &t); return t; } else return 0; } int mxl, myb...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; static long long ans; static int N, K, D, pos[MAXN], val[MAXN], lft[MAXN], rgt[MAXN], num[MAXN << 2], dsc[MAXN << 2]; static pair<int, int> bot[MAXN]; inline int get_dsc(int x) { return lower_bound(dsc, dsc + D, x) - dsc + 1; } inline int lowbi...
14
#include <bits/stdc++.h> using namespace std; const long long int Mod = 998244353; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t-- > 0) { long long int a, b, c, d; cin >> a >> b >> c >> d; long long int e, f; e = a + b; f = d + c; e =...
1
#include <bits/stdc++.h> using namespace std; typedef struct _Query { int from, to, leftPt, rightPt; } Query; vector<Query> que; map<pair<int, int>, vector<pair<int, int> > > mp; long long int ans[300010], val; int parent[300010 << 1], siz[2][300010 << 1], qNum; stack<pair<int *, int> > stk; int getParent(int cntPt) ...
18
#include <bits/stdc++.h> using namespace std; long long l, r; int len(long long x) { int res = 0; while (x) res++, x /= 10; return res; } int last(long long x) { return x % 10; } int first(long long x) { int res = 0; while (x) { res = x % 10; x /= 10; } return res; } long long in(long long n) { ...
7
#include <bits/stdc++.h> using namespace std; const long long LINF = 1e18 + 9; const int INF = 1e9 + 7; const int SIZE = 2 * 1e5 + 10; const long long MOD = 1e9 + 7; int n, m, x, y, z, k, c, r, l; long long lans; int ans[5][5]; int toi[5] = {0, 0, 0, 1, -1}; int toj[5] = {0, 1, -1, 0, 0}; string second; void solve() { ...
1
#include <bits/stdc++.h> const int maxn = 1e6 + 10; const int maxm = 1e5 + 10; const int mod = 1e9 + 7; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; int a[maxn], ans[maxn], pre[maxn]; int find(int x) { return x == pre[x] ? ...
5
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool smin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <typename T> inline bool smax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int maxn = 1e5 + 10, maxA = 1e4 + 10, sq = 322; int n, m, ar[maxn], cnt[sq][maxA], l...
16
#include <bits/stdc++.h> using namespace std; int main() { int k, a, b, v; cin >> k >> a >> b >> v; for (int i = 0; i < 1005; i++) { int sect = min(i * k, b + i); if (v * sect >= a) { cout << i; return 0; } } }
3
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = 2e5 + 5, mod = 998244353, M = 1e7 + 7; const long long MAX = 5e18; int n; pair<int, int> a[N]; long long ans; struct BIT { long long s[N][2], sum[2]; void init() { memset(s, 0, sizeof s); sum[0] = sum[1] = 0; } void ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x1, y1, x2, y2; double ans = 0; cin >> n >> k; cin >> x1 >> y1; for (int i = 1; i < n; i++) { cin >> x2 >> y2; ans += sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); x1 = x2; y1 = y2; } printf("%.9lf\n", ans / 50 * k...
1
#include <bits/stdc++.h> using namespace std; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; int f[27]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, l, k; cin >> n >> l >> k; string s; cin >> s; sort((s).begin(), (s).end()); for (int i = s.size()...
10
#include <bits/stdc++.h> using namespace std; int a[(1 << 22) + 10], b[(1 << 22) + 10], c[(1 << 22) + 10], d[30]; void sc(int e) { if (b[e]) sc(b[e]); printf("%d ", c[e]); } int main() { int e, f; scanf("%d%d", &e, &f); memset(a, 0x3f, sizeof(a)); for (int g = 1; g <= e; g++) d[g] = 1 << (g - 1); for (int...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, d = 0, t = 0, k; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; t = max(t, k = max(i + 1, a[i])); if (i + 1 == t) d++; } cout << d; return 0; }
2
#include <bits/stdc++.h> using namespace std; int t; string isPalindrome(string str) { string str1 = ""; t = 0; int ln = str.length(); int ln1 = ln / 2; if (ln % 2 == 0) { ln1--; } for (int i = 0, j = ln - 1; i <= ln1; i++, j--) { if (str[i] != str[j]) { str1 += str[i]; t++; j++;...
3
#include <bits/stdc++.h> using namespace std; const long long INFLL = 1e18; const int INF = 1e9 + 1; const int MAXC = 1e6; mt19937 gen(time(0)); vector<int> e(MAXC + 5); void precalc() { vector<int> p; for (int i = 2; i <= MAXC; i++) { if (e[i] == 0) { e[i] = i; p.emplace_back(i); } for (int...
24
#include <bits/stdc++.h> using namespace std; const double PI = acos(0) * 2; const double EPS = 1e-8; const long long MOD = 1e9 + 7; const int MAXN = 3e5 + 5; const int oo = 1e9; const double foo = 1e30; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { retu...
10
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 1; struct node { int a, b, k, vt; }; int n, m, res[MAX], cnt; node data[MAX]; multimap<int, int> myMap; multimap<int, int>::iterator itSet; bool cmp(const node& x, const node& y) { if (x.a != y.a) return x.a > y.a; if (x.b != y.b) return x.b < y....
13
#include <bits/stdc++.h> using namespace std; long long n, mx = 0, mn = 1e18; int main() { scanf("%lld", &n); for (int i = 1; i * i * i <= n; i++) { for (int j = 1; j * j * i <= n; j++) { if (n % (i * j) == 0) { long long a = i; long long b = j; long long c = n / (i * j); m...
8
#include <bits/stdc++.h> using namespace std; int main() { double d, l, v1, v2, k; cin >> d >> l >> v1 >> v2; k = l - d; k /= (v1 + v2); printf("%.6f\n", k); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n % 2 == 0) cout << n - 4 << " " << 4; else cout << n - 9 << " " << 9; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 7; int n, m; bool Prime[N]; int p[N >> 3], phi[N], mns[N], pin[N], tot, tnt[N]; void xxs(int x) { phi[1] = 1; for (int i = (2); i <= (x); ++i) { if (!Prime[i]) p[++tot] = i, phi[i] = i - 1, pin[i] = 1; for (int j = 1; j <= tot && p[j] * i <= ...
19
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> a[150000]; map<long long, long long> t; vector<int> v; map<int, vector<int> > g; void add(long long x, long long v) { for (; x <= 1000000100; x |= (x + 1)) t[x] += v; } long long get(long long x) { long long r = 0; for (; x >= 0; x = (x & (x +...
9
#include <bits/stdc++.h> using namespace std; const int MX = 1147483646; const long long MX2 = 3223372036854775800; const int MOD = 998244353; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } vector<pair<int, int> > v; void ans() { cout << "Possible\n"; for (pair<int, int> x : v) cout << x.first << " " << x....
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> s(n); for (int i = 0; i < n; i++) cin >> s[i]; if (n == 1) { cout << "YES" << '\n'; cout << s[0] << '\n' << 0 << '\n'; return 0; } vector<int> id(n); iota(id.b...
16
#include <bits/stdc++.h> using namespace std; long long a[1010]; long long c[1010][1010]; void preDeal() { c[0][0] = c[1][0] = c[1][1] = 1; for (int i = 1; i < 1010; i++) { c[i][i] = c[i][0] = 1; for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007; } } int main() { i...
7
#include <bits/stdc++.h> const int LIM = 1e5; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<vector<int>> h(n, vector<int>(2)); vector<vector<long long>> dp(n, vector<long long>(2)); long long ans = 0; for (int i = 0; i < 2; i++) for (int j...
6
#include <bits/stdc++.h> using namespace std; int n, k; long long arr[(int)3e5 + 5]; bool solve(int num) { for (int i = num; i < 1e6; i += num) { int l = 0, r = n - 1, mid, ans = -1; while (l <= r) { mid = (l + r) / 2; if (arr[mid] >= i && arr[mid] < i + num) ans = arr[mid], l = mid + 1; ...
13
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 44; int n, t[4 * N]; int getMax(int v, int vl, int vr, int l, int r) { if (vl > r || vr < l) return 0; else if (vl >= l && vr <= r) return t[v]; else { int vm = vl + (vr - vl) / 2; return max(getMax(2 * v + 1, vl, vm, l, r), ...
10
#include <bits/stdc++.h> inline long long sbt(long long x) { return __builtin_popcount(x); } using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&....
15
#include <bits/stdc++.h> using namespace std; void enable_io() {} template <typename T> void debug(vector<T> v) { for (auto it : v) { cout << it << " "; } cout << endl; } int n, k; vector<int> adj[1001]; void solve() { for (int i = 0; i < 1001; i++) { adj[i].clear(); } cin >> n >> k; for (int i = ...
8
#include <bits/stdc++.h> using namespace std; int freq[1000005], arr[1000005], ans[1000005]; int main(void) { int n, m, i, j, x, y, k; cin >> n; k = n + 1; for (i = 0; i < n; i++) { cin >> arr[i]; } for (i = 0; i < n; i++) { for (j = 0; j <= n; j++) freq[j] = 0; int maxTillNow = 0, idx = i; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int M = 2e6 + 7; const int lim = 2e5; const int mod = 998244353; const int inf = 0x3f3f3f3f; int a[N]; int main() { int n, k, t = 1, sum = 0, ans; scanf("%d%d", &n, &k); while (k > t) k -= t, t++; for (int i = 1, x; i <= n; i++) { sc...
2
#include <bits/stdc++.h> using namespace std; long long l, r, k = 1, ans, d = 1, jog; string s1, s2; int main() { cin >> l >> r; for (int i = 1; i <= 63; i++) { if (l & k) s1 += '1'; else s1 += '0'; if (r & k) s2 += '1'; else s2 += '0'; k *= 2; } reverse(s1.begin(), s...
9
#include <bits/stdc++.h> using namespace std; void sc(int& a) { scanf("%d", &a); } void sc(long long int& a) { scanf("%lld", &a); } void sc(int& a, int& b) { sc(a); sc(b); } void sc(long long int& a, long long int& b) { sc(a); sc(b); } void sc(int& a, int& b, int& c) { sc(a, b); sc(c); } void sc(long long i...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int cont = -1; for (int i = 1; i < n + 1; i++) { for (int j = 1; j < m + 1; j++) { if (i % 2 != 0) cout << '#'; else { if (cont % 2 != 0) { if (j == m) cout << "#"; ...
0
#include <bits/stdc++.h> const long double PI = 3.141592653589793236L; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; t = 1; cin >> t; while (t--) { long double n, ans; cin >> n; ans = 1 / tan(PI / 2 / n); printf("%Lf\n",...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; stack<pair<int, int>> lef, rig; long long n, arr[maxn], l[maxn], r[maxn]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { while (lef.size() && lef.top().first > arr[i]) { le...
7
#include <bits/stdc++.h> using namespace std; bool check(string s, string t) { if (s == t) return true; int l = s.length(); int m = s.length(); if (l & 1 || l == 0 || m == 0 || m & 1) return false; if (check(s.substr(0, l / 2), t.substr(m / 2, m / 2)) && check(s.substr(l / 2, l / 2), t.substr(0, m / 2))...
9
#include <bits/stdc++.h> using namespace std; int main() { long long n, z = 0, o = 0; string s; cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == '0') z++; else o++; } if (o != z) cout << 1 << endl << s; else { cout << 2 << endl << s[0] << " "; for (int i = 1; i <= n...
0
#include <bits/stdc++.h> using namespace std; int n, ans[100010]; int main() { while (scanf("%d", &n) == 1) { int i; if ((n & 3) == 2 || (n & 3) == 3) { puts("-1"); continue; } for (i = 1; i <= n / 2; i += 2) { ans[i] = i + 1, ans[n - i + 1] = n - i; ans[i + 1] = n - i + 1, ans...
6
#include <bits/stdc++.h> using namespace std; const long long int inf = 2E+9; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, m; cin >> n >> m; if (n == 1 && m == 2) { cout << 0 << endl; cout << 1 << " " << 1 << endl; cout << 1 << " " << 2 << endl; ...
12
#include <bits/stdc++.h> using namespace std; int n, f[2 * 100005], res = 0, Max = 0; pair<int, int> a[100005]; vector<int> x; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].first >> a[i].second; a[i].second--; x.push_back(a...
5
#include <bits/stdc++.h> using namespace std; long long pwr(long long base, long long exp, long long mod = (1000000007LL)) { long long res = 1; while (exp > 0) { if (exp % 2) { res = (res * base) % mod; } base = (base * base) % mod; exp /= 2; } return res; } long long gcd(long long a, long...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int tc = 0; tc < t; ++tc) { int n; cin >> n; int len = 2; while (len * (len + 1) / 2 <= n) ++len; n -= len * (len - 1) / 2; assert(n >= 0); assert(n <= 45000); string s = "133"; while (n > 0) { ...
11
#include <bits/stdc++.h> using namespace std; int len, k; void sw(string &str, int k) { string ss = str.substr(0, k + 1); reverse(ss.begin(), ss.end()); for (int i = 0; i <= k; i++) str[i] = ss[i]; } int main() { string str; scanf("%d", &len); scanf("%d", &k); cin >> str; map<char, int> make_pair; for...
4
#include <bits/stdc++.h> using namespace std; char ss[100]; int main() { cin >> ss; int ans = 0; for (int i = 0; i < strlen(ss); i++) { if (ss[i] == 'a' || ss[i] == 'e' || ss[i] == 'i' || ss[i] == 'o' || ss[i] == 'u') { ans++; } else if (ss[i] == '1' || ss[i] == '3' || ss[i] == '5' || ss[i] ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, result = 0; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { if (arr[i] == 0 && arr[i + 1] == 1 && arr[i - 1] == 1) { result++; if (arr[i + 2] == 0 && arr[i + 3] == 1) { i +=...
2
#include <bits/stdc++.h> using namespace std; ifstream fin("AAtest.in.txt"); string s, s1; long long t, n, k, mit, pal, l; vector<pair<long long, long long> > p; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> t; while (t--) { cin >> n >> k; cin >> s; s1 = ""; ...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> g[N]; int n, m, depth[N], chain[N]; pair<int, int> edges[N]; set<int> white[N]; void dfs(int u, int pa, int chain_id, int dpth = 1) { depth[u] = dpth; chain[u] = chain_id; for (int v : g[u]) { if (v == pa) continue; dfs(v, u,...
13
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int p[N]; int find(int x) { if (x == p[x]) return x; return p[x] = find(p[x]); } int main() { int n, m; cin >> n >> m; vector<int> val[m]; int disc[n]; int ans = n - 1; for (int i = 0; i < m; i++) p[i] = i; for (int i = 0; i < n; i++...
15