solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int MAXN = 55, MAXM = 2e4 + 5; struct SegmentTree { int maxVal, lazy; int l, r; SegmentTree *L, *R; SegmentTree() {} SegmentTree(int l, int r) { this->maxVal = this->lazy = 0; this->l = l; this->r = r; this->L = this->R = nullptr; } void ...
15
#include <bits/stdc++.h> using namespace std; const int m = (int)1e5; long long data[m + 9]; long long cum[m + 9]; void process(string s) { for (int i = 0; i < s.length(); i++) { cum[i + 1] = cum[i] + s[i] - '0'; } return; } int main() { long long n; memset(data, 0, sizeof(data)); memset(cum, 0, sizeof(...
8
#include <bits/stdc++.h> using namespace std; const int Size = 1024; const int mod1 = 1e9 + 7; const int mod2 = 98156437; const int INF = 0x3f3f3f3f; const int maxn = 5e5 + 15; const int base = 307; struct node { int pos, v; } a[maxn]; bool cmp(node a, node b) { return a.v > b.v; } int main() { int n; scanf("%d",...
1
#include <bits/stdc++.h> using namespace std; int const INF = 2 * 10e5 + 123; const int N = 1e5 + 100; int simple(int n) { int i, sq; if (n % 2 == 0) { return 0; } sq = (int)sqrt(n); for (i = 3; i <= sq; i++) { if ((n % i) == 0) { return 0; } } return 1; } long long gcd(long long a, long...
1
#include <bits/stdc++.h> using namespace std; const int SZ = 300; int N; long long add[100005], gadd[100005], gsum[100005]; int col[100005], gcol[100005]; void down(int g) { for (int i = g * SZ; i < (g + 1) * SZ; ++i) col[i] = gcol[g]; gcol[g] = 0; } void updateUnit(int l, int x) { int g = l / SZ; if (gcol[g] !...
16
#include <bits/stdc++.h> using namespace std; int const N = 1024; int const P = 1000000007; long long dp[N][N]; long long sum[N]; int main() { memset(dp, 0, (sizeof dp)); fill(dp[0] + 1, dp[0] + N, 1); for (int t = 1; t < N; ++t) { sum[0] = 0; partial_sum(dp[t - 1], dp[t - 1] + N - 1, sum + 1); for (i...
12
#include <bits/stdc++.h> const int N = 500005; char sa[N], sb[N], ans[N]; int cnt[256], nxt[N]; int main() { scanf("%s%s", sa, sb); for (int i = 0; sa[i]; ++i) ++cnt[sa[i]]; int j = 0; for (int i = 1; sb[i]; ++i) { while (j && sb[j] != sb[i]) j = nxt[j]; if (sb[j] == sb[i]) nxt[i + 1] = ++j; } j = 0...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; int N, K, L[MAXN][2], R[MAXN][2]; int main() { cin >> N >> K; for (int i = 0; i < N; i++) { L[i][1] = N; } for (int i = 0; i < K; i++) { int a, b; string s; cin >> a >> b >> s; if (a >= b) { cout << "IMPOSSIBLE\n"; ...
16
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-10; const long long LINF = 1e18; int main() { if ("" != "") { freopen( "" ".in", "r", stdin); freopen( "" ".out", "w", stdout); } iostream::sync_with_stdio(0); int n, m; cin >> n >>...
9
#include <bits/stdc++.h> int main() { int n, k; scanf("%d %d", &n, &k); int counter = 0; if (n - k > k - 1) { counter += (k - 1) * 2 + (n - k); } else { counter += (n - k) * 2 + (k - 1); } counter += (n - 1) * 2 + 3; printf("%d\n", counter); return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; const long long inf = 1e16 + 10; int c[N]; int a[N]; int main() { int n, k; long long ans; scanf("%d%d", &n, &k); if (n <= 2) { if (n == 2) puts("1"); else puts("0"); } else { long long v = ma...
4
#include <bits/stdc++.h> const long long MOD = 1000000007; using namespace std; const int N = 10e5 + 10; int arr[N] = {0}; int main() { int n, a, b; cin >> n >> a >> b; int maxc = 1; for (int i = 1; i < n; ++i) { int ac = a / i; int bc = b / (n - i); maxc = max(maxc, min(ac, bc)); } for (int i =...
4
#include <bits/stdc++.h> using namespace std; int n, m, a, b; int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } void sol() { scanf("%d%d%d%d", &n, &m, &a, &b); if (n * a == m * b) { printf("YES\n"); int s[n][m]; for (int i = 0; i < n * m; i++) s[i / m][i % m] = 0; int num = 0; for (in...
11
#include <bits/stdc++.h> using namespace std; int n, c, d, b1, b2, ans; vector<pair<int, int> > p, q; priority_queue<pair<int, int> > qq; void doit(vector<pair<int, int> > p, int c) { while (qq.size()) qq.pop(); for (int i = (0); i < (p.size()); i++) qq.push(make_pair(p[i].second, i)); int ptr = p.size() - 1; f...
10
#include <bits/stdc++.h> using namespace std; string ori; string start; string target; int n; char mapping[256]; char mapn[256]; char used[256]; bool apply(int a, int b) { if ((mapping[a] == 0 && used[b] == false) || mapping[a] == b) { mapping[a] = b; used[b] = true; mapn[a]++; return true; } retu...
15
#include <bits/stdc++.h> using namespace std; int a[111111], b[1111], d[111]; long long j, i, n, m = 0, k, t; int ans = 0; int main() { string s, st; cin >> st >> s; sort(s.rbegin(), s.rend()); for (i = 0, j = 0; i < st.size(); i++) if (st[i] < s[j] && j < s.size()) st[i] = s[j++]; cout << st; }
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; vector<pair<int, int> > edge; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; if (a > b) swap(a, b); edge.push_back({a, b}); } sort(edge.begin(), edge.end()); for (int k = 1; k < n;...
11
#include <bits/stdc++.h> using namespace std; double y, a, b; int n1, n2; const double eps = 1e-9; pair<int, int> engel[200007]; map<int, int> pre; double kesis(double a1, double a2, double b1, double b2) { if (a1 >= b2 || b1 >= a2) return 0; if ((a1 <= b1 && a2 >= b2) || (b1 <= a1 && b2 >= a2)) return min(a2 -...
16
#include <bits/stdc++.h> using namespace std; vector<long long> g[100100]; bool us[100100], a[100100]; long long k, m, ans; void dfs(long long s, long long kol) { if (a[s] == 0) kol = 0; else kol++; if (kol > m) return; if (g[s].size() == 1 && s != 1) ans++; for (int i = 0; i < g[s].size(); i++) { ...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 4004; int dp[N][N], a[N]; signed main() { int n, ans = 1, idx = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } map<int, int> mp; for (int i = 0; i < n; i++) { if (mp.find(a[i]) == mp.end()) ...
7
#include <bits/stdc++.h> const double PI = 3.141592653589793; int maxi(int a, int b) { if (b > a) return b; return a; } using namespace std; int main() { int n, l, k, mas[901], che[31], h, sch = 1, m = 1; for (int i = 0; i < 901; i++) mas[i] = 1; for (int i = 0; i < 31; i++) che[i] = 0; scanf("%d %d", &n, &...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout << fixed << setprecision(9); long long ans, gcd, masks, mask, i, h, ma, d, l, r, n, j, k, m, x, y, root, t, sum, size, q, ind; cin >> t; while (t--) { cin >> n; int a[n]; for (int i...
8
#include <bits/stdc++.h> using namespace std; int n, m, a[20001], b[20001], c[20001]; vector<int> v[5001]; bool comp(int i, int a, int b) { if (a < i && b < i) return (a < b); if (a < i && b >= i) return 0; if (a >= i && b < i) return 1; return (a < b); } int ras(int x) { x = (x % n + n) % n; if (x == 0) x ...
9
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 7, inf = 0x3f3f3f3f; int dp[N][N], n, m, i, j, k, len, p, cnt, x; char s[N], ss[N]; int cal(int x) { for (p = m, cnt = 0, k = x; k && p; --k) if (ss[p] == s[k]) p--; else cnt++; if (!p) return cnt; else return inf; } int...
14
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize("Ofast") using namespace std; inline int read() { int r = 0, f = 1; char ch = getchar(); while (ch < 48) { if (ch == '-') f = -1; ch = getchar(); } while (ch > 47) r = r * 10 + (ch ^ 48), ch = getchar(); return r * f; } inline int...
15
#include <bits/stdc++.h> using namespace std; struct Edge { int to, nxt; } edge[1000100]; struct SAM { int len, fa, ch[30]; } point[1001000]; string S[100100]; int n, cnt, head[1000100], lst = 1, idx = 1; long long sum[1000100]; long long ans; void addedge(int x, int y) { edge[++cnt].to = y; edge[cnt].nxt = hea...
19
#include <bits/stdc++.h> using namespace std; void init_code() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void solve() { string s; cin >> s; long long int i; long long int n = s.size(); vector<long long int> ae, ao, b, bo; for (i = 0; i < n; i++) { if (s[i] == 'a') { if (i % 2) { ...
12
//#pragma GCC optimize ("Ofast") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstdarg> #include <cassert> #include <climits> #include <cstring> #include <complex> #include <cstdio> #include <vector> #include <string> #include <queue> #include <cmath> #include <ctime> #include <set> #include <m...
8
#include <bits/stdc++.h> using namespace std; int X[8] = {1, -1, 0, 0, 1, 1, -1, -1}; int Y[8] = {0, 0, 1, -1, 1, -1, 1, -1}; int N, M; bool valid(int i, int j) { if (i >= 0 && j >= 0 && i < N && j < M) return true; return false; } int power(int a, int b) { if (b == 0) return 1; if (b == 1) return a; return p...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; vector<int> v; cin >> n; for (int x, i = 0; i < n; i++) cin >> x, v.push_back(x); sort(v.begin(), v.end()); cout << (n % 2 == 0 ? v[n / 2 - 1] : v[n / 2]); return 0; }
0
#include <bits/stdc++.h> using namespace std; long long in() { long long a; scanf("%lld", &a); return a; } double din() { double a; scanf("%lf", &a); return a; } long long bigmod(long long b, long long p, long long md) { if (p == 0) return 1; if (p % 2 == 1) { return ((b % md) * bigmod(b, p - 1, md)...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = 1e18; const long double pai = acos(-1); long long n, k; long long a[300009]; int main() { cin >> n >> k; k--; for (int i = 0; i < n; i++) cin >> a[i]; long long sum = 0; vector<long long> v; for (int i = n ...
11
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { std ::ios_base ::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t; cin >> t; while (t--) { int n, p; cin >> n >> p; int edges = 2 * n + p; bool flag = true; for (int i = 1; i <= n; ++i) { ...
7
#include <bits/stdc++.h> using namespace std; const int N = 200005; int T, n, m, a[N], uk, vk; long long ans[200001], res = 0; struct babe { int l, r, stt; } x[N]; long long dd[1000005]; bool sosanh(babe x, babe y) { if ((x.l - 1) / T + 1 != (y.l - 1) / T + 1) { return x.l < y.l; } return x.r < y.r; } void ...
14
#include <bits/stdc++.h> const int MOD = 1000000007; const int PMOD = 1000000006; struct Matrix { long long a[5][5]; int n, m; Matrix(int n, int m, bool eye = false) : n(n), m(m) { for (int i = 0; i < n; i++) std::fill(a[i], a[i] + m, 0); if (eye) for (int i = 0; i < n; i++) a[i][i] = 1; } long ...
15
#include <bits/stdc++.h> const int maxn = 100; const int maxm = 1000; const int maxtop = 100000; double f[maxtop + 1], sum[maxtop + 1]; int x[maxn + 1]; int n, m, yao; void init() { int i; scanf("%d%d", &n, &m); yao = 0; for (i = 1; i <= n; ++i) { scanf("%d", &x[i]); yao += x[i]; } } void work() { i...
15
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; vector<int> v; int next = 1; int s = 0; while (s + next <= a + b) { s += next; v.push_back(next++); } int split = v.size(); s = 0; for (int i = 0; i < v.size(); i++) { s += v[i]; if (s >= a) { i...
8
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265; const long long mod = 998244353; const long long N = 1e3 + 5; const long long st = 1e2; const int P0 = 437; const int P1 = 331; int main() { cin.sync_with_stdio(); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> c(n), ...
8
#include <bits/stdc++.h> using namespace std; const int MAX = 100000 + 10; struct Node { Node *lc, *rc, *p; int rev, size, old; int left[2], leftA[2], flagLeft[2]; multiset<int> hash; Node() { lc = rc = p = 0; size = 1; rev = 0; memset(left, 0, sizeof left); memset(leftA, 0, sizeof leftA);...
20
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &v); template <class T> ostream &operator<<(ostream &os, set<T> &v); template <class T1, class T2> ostream &operator<<(ostream &os,...
18
#include <bits/stdc++.h> using namespace std; struct aaa { long long x, y, w; } a[200001]; long long n, m, k, tot, cnt, ans, sum, p[200001], fa[200001], dis[200001], mp[200001], val[200001], e[200001], hd[200001], nt[200001], fr[200001]; queue<long long> q; void build(long long x, long long y, long long w) { to...
18
#include <bits/stdc++.h> using namespace std; long long n, k, M, ans, tot, now, ans_, d, i, j, e; int t[50 + 5]; int main() { for (scanf("%d%d%d", &n, &k, &M), i = 0; i < k; i++) scanf("%d", &t[i]), tot += t[i]; sort(t, t + k); for (e = 0; e <= n; e++) { now = tot * e; if (now > M) break; ans_ = (...
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:33554432") using namespace std; const double PI = 2 * acos(0.0); const double EPS = 1e-8; const int INF = (1 << 30) - 1; const int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1}; struct point { int r, c; point(int r = 0, int c = 0) { this->r = r; this->c ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; map<int, int> x; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; x[arr[i] + arr[j]]++; } } set<int, greater<int>> p; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 500010; char trans['z' + 1]; int n, q; char s[N]; struct tree { int a[N + 1]; void add(int x, int s) { for (; x <= N; x += x & -x) a[x] += s; } int ask(int x) { int s = 0; for (; x >= 1; x -= x & -x) s += a[x]; return s; } } t[4]; set...
17
// Author: Tsukimaru Oshawott // In the name of // // _/_/ _/_/_/ _/_/_/ _/_/_/_/ _/ _/ _/_/_/_/ // _/ _/ _/ _/ _/ _/ _/ _/ _/ // _/_/_/_/ _/_/_/_/ _/ _/_/_/_/ _/ _/ _/_/_/_/ // _/ _/ _/ _/ _/ _/ ...
17
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const long long INF = (long long)1e18 + 123; int n; pair<long long, long long> a[N]; set<int> g; set<pair<long long, int> > l, x; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;...
10
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); long t; std::cin >> t; while (t--) { std::string num; std::cin >> num; long s; std::cin >> s; long cs(0); for (long p = 0; p < num.size(); p++) { cs += (num[p] - '0'); } if (cs <= s) { puts("...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; char str[13]; bool yes[13]; int geshu = 0; cin >> t; for (int i = 0; i < t; i++) { geshu = 0; memset(yes, false, sizeof(yes)); cin >> str; for (int i = 0; i < 12; i++) { if (str[i] == 'X') { yes[1] = true; ...
2
#include <bits/stdc++.h> using namespace std; long j, i, n, c; string s, t, r; char d; int main() { cin >> s; n = s.size(); for (i = 0; i <= n; i++) { for (j = 'a'; j <= 'z'; j++) { t = s; t.insert(t.begin() + i, j); r = t; reverse(r.begin(), r.end()); if (r == t) { c = 1...
3
#include <bits/stdc++.h> using namespace std; struct point { long long x, y; bool out; point() { out = false; } point(long long x, long long y) : x(x), y(y) { out = false; } point operator-(point b) { return point(x - b.x, y - b.y); } long long operator%(point b) { return (x * b.y - y * b.x); } bool opera...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], i, j; long long sum = 0; int m = 0; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; m = max(a[i], m); } for (i = m; i <= 250; i++) { if (n * i - sum > sum) { cout << i << endl; break; ...
0
#include <bits/stdc++.h> const long long MOD = 1000000007; const long long inf = 1e18; using namespace std; std::vector<long long int> fact(400001), inv_fact(400001); long long int modpow(long long int x, long long int n) { long long int res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % M...
13
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; } template <typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; using ...
16
#include <bits/stdc++.h> using namespace std; int pre[100010][3]; int main() { int i, j, m, l, r, diff[3]; string s; cin >> s >> m; for (i = 1; i <= s.size(); i++) { for (j = 0; j < 3; j++) pre[i][j] = pre[i - 1][j] + (s[i - 1] == 'x' + j); } while (m--) { scanf("%d%d", &l, &r); for (j = 0; j < ...
7
#include <bits/stdc++.h> using namespace std; int dp[5005][5005]; int main(){ int n; cin >> n; vector<int> a,b; for(int i=0,c;i<n;i++){ cin >> c; if(c){ a.push_back(i); } else{ b.push_back(i); } } memset(dp,0x3f,sizeof(dp)); dp[0...
10
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (b) { a %= b; swap(a, b); } return a; } int main() { int n, lcm, nik = 0, pol = 0, rest, i = 0, nikrest = 0, polrest = 0; string a, b; map<char, int> pos; pos['R'] = 0; pos['S'] = 1; pos['P'] = 2; cin >> n >> a >> b;...
5
#include <bits/stdc++.h> using namespace std; int n, ans[(int)1e6]; void init() { cin >> n; } void solve() { for (int i = 1; i <= n; i++) { int x; if (i & 1) x = (i >> 1); else x = (i >> 1) + n - 1; int y = n + x - i; ans[x] = ans[y] = i; } for (int i = 0; i <= n * 2 - 1; i++) { ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 101000; long long result; int a[maxn + 1], b[maxn + 1], m, n; void init() { int i, j; scanf("%d%d", &m, &n); result = 0; for (i = 1; i <= m; ++i) { scanf("%d", &a[i]); result += a[i]; } for (i = 1; i <= n; ++i) { scanf("%d", &b[i]); ...
11
#include <bits/stdc++.h> using namespace std; int A, B, C; int Array[1001]; int main(void) { ios::sync_with_stdio(false); register int i; cin >> A >> B >> C; for (i = 1; i <= B; i++) { register int X; cin >> X; register int Pos; if (X > (C >> 1)) { Pos = A; while (Array[Pos] >= X) Po...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; double m, a, b, min = 101; cin >> n >> m; cout << setprecision(8); for (int i = 0; i < n; i++) { cin >> a >> b; if (min > a / b) min = a / b; } cout << m * min; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int c = 0, o = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '(') o++; else if (o > 0) { o--; c += 2; } } cout << c << endl; }
6
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MOD2 = 1007681537; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long long r; while (...
8
#include <bits/stdc++.h> using namespace std; long long x, t, n, m; int main() { cin >> t; while (t--) { bool flag = false; cin >> x; if (x == 0) cout << 1 << " " << 1 << endl; else if (x == 1) cout << -1 << endl; else { for (long long i = 1; i * i <= x; i++) { if ((x %...
9
#include <bits/stdc++.h> using namespace std; template <class T> inline int size(const T& c) { return c.size(); } using namespace std; const int maxn = 1000000 + 10; int a[maxn * 3]; int r, n; int main() { cin >> n; for (int i = (1), _b = (n); i <= _b; i++) a[i] = i; r = 1; for (int i = (2), _b = (n); i <= _b...
14
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a; a.push_back(0); for (long long i = 1; i * i <= n; i++) { if (i < n / i) { a.push_back(i); a.push_back(n / i); } if (i ==...
6
#include <bits/stdc++.h> using namespace std; const int maxN = 800; long long Carr[maxN + 1][maxN + 1]; void PascalPreCompute() { memset(Carr, 0, sizeof(Carr)); Carr[0][0] = 1; for (int n = 1; n <= maxN; n++) { Carr[n][0] = Carr[n][n] = 1; for (int k = 1; k < n; k++) Carr[n][k] = Carr[n - 1][k - 1] ...
5
#include <bits/stdc++.h> using namespace std; int n, pst[4]; int mn(vector<int> vec[], int ind) { if (ind == n) { int res = 0; for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) res += pst[i] > pst[j]; return res; } int ans = 1 << 25; for (int i = 0; i < vec[ind].size(); ++i) { ps...
18
#include <bits/stdc++.h> using namespace std; vector<bool> prime(200002, true); void seive(long long mx) { prime[0] = prime[1] = false; for (long long i = 2; i * i <= mx; i++) { if (prime[i]) { for (long long j = i * i; j <= mx; j += i) { prime[j] = false; } } } } bool cmp(long long x,...
1
#include <bits/stdc++.h> using namespace std; class node { public: vector<int> near; }; node a[100010]; int deg[100010]; vector<int> pp, qq, both; bool tmpx[100010] = {0}, tmpy[100010] = {0}; int x[100010], y[100010]; int main() { int n, m, h, t; cin >> n >> m >> h >> t; int p, q; for (int i = 1; i <= m; i++...
12
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; cout << 25; }
0
#include <bits/stdc++.h> using namespace std; int a[105], pr[60], b[600]; int divisormask[60]; int dp[105][1 << 18]; int ans[105][1 << 18]; int main() { int n, m, cur, hi, i; hi = 60; int total = 0; for (m = 2; m <= hi; m++) { if (a[m] == 0) { pr[total++] = m; for (cur = 2 * m; cur <= hi; cur +=...
12
#include <bits/stdc++.h> using namespace std; int n, k; int num; priority_queue<int, vector<int>, greater<int> > q; int main() { while (scanf("%d%d", &n, &k) != EOF) { for (int i = 1; i <= n; i++) { scanf("%d", &num); if (num) q.push(num); } int flag = 0; while (k--) { if (!q.empty()...
2
#include <bits/stdc++.h> int main() { int a[4], ar, b, c, i, t; for (int i = 0; i < 4; i++) scanf("%d", &a[i]); for (int i = 0; i < 4; i++) { for (int j = i + 1; j < 4; j++) { if (a[i] > a[j]) { t = a[i]; a[i] = a[j]; a[j] = t; } } } ar = a[3] - a[0]; b = a[3] - a...
0
#include <bits/stdc++.h> using namespace std; int main() { char a[10000]; long long c = 0, n, x, sum = 0, pp[10000]; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> a[i] >> pp[i]; } sum = x; for (int i = 0; i < n; i++) { if (a[i] == '-') { if (sum >= pp[i]) { sum -= pp[i]; ...
0
#include <bits/stdc++.h> using namespace std; int n; int sz[1001001], cnt[1001001]; vector<int> v[1001001]; struct modular_arithmetic { int mod; modular_arithmetic() { mod = 998244353; } int add(int x, int y) { return (x += y) < mod ? x : x - mod; } int sub(int x, int y) { return (x -= y) >= 0 ? x : x + mod; } ...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using pii = pair<int, int>; using pll = pair<ll, ll>; void testCase() { string s1, s2; cin >> s1 >> s2; if (s1.length() != s2.length()) { cout << "impossible" << endl; } else { int cnt = 0; for (int i = 0; i < s1....
3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n, a[maxn], b[maxn]; multiset<int> s; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { cin >> b[i]; s.insert(b[i]); s.insert(b[i] + n); } for (int i = 0; i < n; i++) { int n...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j]; int rw[n][m], clm[n][m], mxrw[n], mxclm[m]; for (int j = 0; j < m; j++) { vector<pair<int, int>> v(n); for (int i = 0; i < n; i...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { int m; cin >> m; int t = 0; vector<int> answ; for (int i = 0; m; ++i) { if (m % 10 != 0) { answ.push_back((m % 10) * pow(10, i)); ++t; } m /= 10; } ...
0
#include <bits/stdc++.h> using namespace std; int viz[100], N, M, i, primes[100], nr, j; void ciur() { primes[++nr] = 2; for (i = 3; i <= 100; i += 2) { if (viz[i]) continue; viz[i] = 1; primes[++nr] = i; for (j = i * i; j <= 100; j += i) viz[j] = 1; } } int main() { ciur(); cin >> N >> M; f...
0
#include <bits/stdc++.h> using namespace std; int input, n, m; map<int, int> num; bool check(int x) { if (!x) return true; int t = 0; for (auto p : num) { t += p.second / x; } return t >= n; } int main(void) { cin >> n >> m; for (int i = 0; i < m; i++) { cin >> input; num[input]++; } int l...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int n, d[1007], dp[1007], c[1007][1007]; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%d", &d[i]); } for (int i = 1; i <= 1000; i++) { c[i][0] = 1; c[i][i] = 1; for (int j = 1; j < i; j++) c[i][j] = (c[i - 1]...
11
#include <bits/stdc++.h> using namespace std; int a[22][22], b[22][22], n, m, i, j, u; bool is[22]; int main() { cin >> n >> m; for (i = 1; i <= n; ++i) { is[i] = 1; for (j = 1; j <= m; ++j) { cin >> a[i][j]; if (a[i][j] != j) is[i] = 0; } } bool tri = 0; for (i = 1; i <= n; ++i) { ...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int a[t]; for (int i = 0; i < t; i++) { cin >> a[i]; } sort(a, a + t); int b[t]; int j = 0; int c = 0; for (int i = 1; i < t; i += 2, j++) { b[i] = a[j]; } for (int i = 0; i < t; i += 2, j++) { b[i] = a[j]; ...
2
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const double EPS = 1e-6; long long fib(long long n, long long MOD) { if (n <= 2LL) return 1LL % MOD; n -= 2; long long pow[2][2] = {{1LL, 1LL}, {1LL, 0LL}}; long long mat[2][2] = {{1LL, 0LL}, {0LL, 1LL}}; while (n > 0) { long...
16
#include <bits/stdc++.h> using namespace std; const int N = 2002; int n, k, f[N][N], visit[N][N]; queue<pair<int, int> > q; char a[N][N]; void bfs() { queue<pair<int, int> > tmp; while (q.size()) { auto x = q.front(); q.pop(); tmp.push(x); visit[x.first][x.second] = 1; } q = tmp; while (q.size...
11
#include <bits/stdc++.h> using namespace std; int main() { long long n, ss, m, i, j, q, x, p, t, s, r; cin >> n; long long a[123456]; s = 0; for (i = 1; i <= n; i++) { cin >> a[i]; if (a[i] < 0) s++; } if (s <= 2) { cout << 1 << endl << n << endl; return 0; } cout << (s + 1) / 2 << end...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long double pi = acos(-1); const int MOD = 1e6 + 3; const int MAXN = 102; long long int reta[MAXN][MAXN]; long long int aux[MAXN][MAXN]; long long int ma[MAXN][MAXN]; long long int v[MAXN]; long long int resp[MAXN]; int N; void mul(long lon...
13
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; char currch = '0'; char prevch = '0'; int currcnt = 0; int prevcnt = 0; vector<char> era; for (int i = 0; i < s.length(); i++) { if (s[i] != currch) { prevch = currch; currch = s[i]; prevcnt = currcnt; ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, mx, ans; cin >> a >> b >> c; if (a == b && b == c) cout << "0" << endl; else { mx = max(max(a, b), c); if (mx == a && mx == b) ans = a - c - 1; else if (mx == a && mx == c) ans = a - b - 1; else if ...
4
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; long long dp[20][1 << 16][16]; long long l, r, b[20]; long long dfs(int o, int bit, int ma, bool isTop) { if (o == -1) return bit >> ma & 1; if (~dp[o][bit][ma] && isTop == false) return dp[o][bit][ma]; long long res = 0; int hi = isTop ? b[o] :...
21
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100, inf = 1e9 + 100; vector<int> adj[N]; queue<int> pq; int n, m, mx = 0, idx = -1; bool vis[N]; vector<pair<int, int>> ans; void MST() { pq.push(idx); while (!pq.empty()) { int frm = pq.front(); pq.pop(); for (auto b : adj[frm]) i...
9
#include <bits/stdc++.h> using namespace std; namespace mine { long long qread() { long long ans = 0, f = 1; char c = getchar(); while (c < '0' or c > '9') { if (c == '-') f = -1; c = getchar(); } while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar(); return ans * f; } void write(lon...
26
#include<iostream> using namespace std; typedef long long ll; int main() { int t; cin >> t; while (t--) { int n, s, y, x, z; cin >> n >> s >> y >> x >> z; int q = 0, f = 0, ans = 1; if (y == n)q++; if (z == n)q++; if (y == n - 1)f++; if (z == n - 1)f++; if (s < q || x < q)ans = 0; if (s + x < f+2...
6
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9, maxn = (int)1e5 + 5; const double eps = (double)1e-8; const int mod = (int)1000000007; string s1, s2; bool dfs(string s3, string s4, int d) { if (s3 == s1 && s2 == s4) return true; if (d > 6) return false; string t3 = s3, t4 = s4; if (s3[0]...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, a, b, c, d; cin >> n >> a >> b >> c >> d; long long ans = 0; for (long long x = 1; x <= n; x++) { long long y = x + b - c; long long z = x + a - d; long long w = a + y - d; ...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; long long int mod = 1000000007; long long int inf = 1000000000000000010; long long int ninf = -1000000000000000010; double PI = 3.141592654; template <typename T> inline T gcd(T a, T b) { T t; if (a < b) { while (a) { t = a; a ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; char a[n + 1][n + 1]; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) cin >> a[i][j]; int a12 = a[1][2] - ...
3
#include <bits/stdc++.h> using namespace std; template <class T> void inline maxi(T &a, const T &b) { a = max(a, b); } template <class T> void inline mini(T &a, const T &b) { a = min(a, b); } void shownum(int n, int m) { for (int i = (n); i <= (m); ++i) { cout << setw(6) << i; } cout << endl; } template <...
10