solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; inline long long md(long long m, long long v) { return ((v % m) + m) % m; } const int MAX = 8200; const int NOT = 1e9; void solve() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; vector<vector<int> > idx(MAX + 1); for (int i = ...
8
#include <bits/stdc++.h> using namespace std; long long n, s; long long p; vector<long long> a, b, k; long long f(long long x) { if (x < 0) return -1; long long ans = 0; long long y = p - x; x *= s; y *= s; for (long long i = 0; i < n; ++i) { long long t = k[i]; if (a[i] > b[i]) { long long d ...
5
#include <bits/stdc++.h> using namespace std; struct Edge { int to, pre; } e[100005 * 2]; int h[100005] = {0}, cou = 0, sz[100005], ms[100005], sum, rt, col[100005]; bool vis[100005]; void Addedge(int from, int to) { cou++; e[cou] = ((Edge){to, h[from]}); h[from] = cou; } void calc(int x, int fa) { sz[x] = 0;...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; long long p[maxn], q[maxn], c[maxn], n, a, b; int cmp(int x, int y) { return x > y; } int main() { cin >> n >> a >> b; int t = a + b; for (int i = 0; i < n; i++) { cin >> p[i]; } for (int i = 0; i < n; i++) { cin >> q[i]; } fo...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, first, sec, c = 0; cin >> n; vector<int> v; vector<int> u; while (n--) { cin >> a >> b; v.push_back(a); u.push_back(b); } for (int i = 0; i < v.size(); i++) { for (int j = 0; j < u.size(); j++) { if (v[i] == u[j]...
0
#include <bits/stdc++.h> using namespace std; long long n, a, p; vector<long long> v; long long pp(long long g) { if (g < 0) return g = g * (-1); else return g; } int main() { cin >> n >> a; for (int i = 1; i <= n; i++) { cin >> p; v.push_back(p); } sort(v.begin(), v.end()); long long ans ...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 7340033; long long n, k; long long DP[100][1009], dp[100][1009]; long long DFS(int h, int k); long long dfs(int h, int k) { long long &d = dp[h][k]; if (~d) return d; d = 0; for (int i = 0; i <= k; i++) d = (d + DFS(h - 1, i) * DFS(h - 1, k...
7
#include <bits/stdc++.h> using namespace std; template <typename T> T Bigmod(T b, T p, T m) { if (p == 0) return 1; else if (!(p & 1)) return (Bigmod(b, p / 2, m)) * (Bigmod(b, p / 2, m)) % m; else return ((b % m) * Bigmod(b, p - 1, m)) % m; } int checkprime(int n) { long long ck = 0; for (int j =...
4
#include <bits/stdc++.h> using namespace std; vector<int> gr[500 * 1000 + 10]; vector<int> dep[500 * 1000 + 10]; char s[500 * 1000 + 10]; int depthx[500 * 1000 + 10]; int in[500 * 1000 + 10], out[500 * 1000 + 10]; int timex = 1; void dfstime(int v, int d) { in[v] = timex++; for (int i = 0; i < (int)gr[v].size(); ++...
7
#include <bits/stdc++.h> using namespace std; int main() { int K; string S; bool usd[256] = {}; vector<int> stf; cin >> K >> S; for (size_t i = 0; i < S.size(); i++) { if (stf.size() < K && !usd[S[i]]) { usd[S[i]] = true; stf.push_back(i); } } if (stf.size() < K) { cout << "NO" <...
1
#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}; long long ln, lk, lm; int a[100005], b[100005], c[100005], d[100005]; map<int, int> id; vector<int> vp[100005 * 2]; int cmp(int x, int y) { if (b[x] == b[y]) return x < y; return b[x] > b[y];...
8
#include <bits/stdc++.h> using namespace std; int N, K, H; int weight[100010], v[100010], id[100010]; vector<pair<pair<int, int>, int> > p; int ans[100010], ans2[100010]; bool check(double t) { int i, j = 0; for ((i) = 0; (i) < (int)(K); (i)++) { while (j < N && v[j] < (i + 1.0) / t) j++; if (j == N) return...
6
#include <bits/stdc++.h> using namespace std; struct xy { xy() : x(0), y(0) {} xy(int x, int y) : x(x), y(y) {} int x, y; }; bool compx(xy a, xy b) { if (a.x < b.x) return true; else return false; } bool compy(xy a, xy b) { if (a.y < b.y) return true; else return false; } int main(int argc...
2
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; } inline int read() { int x(0), sgn(1); char ch(getchar()); for (; !isdigit(ch); ch = getchar())...
12
#include <bits/stdc++.h> using namespace std; int vis[500045]; std::vector<int> a[500045]; std::vector<int> order; void dfs1(int pos, int par) { if (vis[pos]) return; vis[pos] = 1; order.push_back(pos); for (int i = 0; i < a[pos].size(); i++) { if (a[pos][i] != par) { dfs1(a[pos][i], pos); } } }...
6
#include <bits/stdc++.h> using namespace std; int dp[5005][5005], f1[5005], f2[5005], f3[5005]; char s1[5005], s2[5005]; void Calc(char *a, char *b, int dp[][5005], int f[]) { int n = strlen(a), m = strlen(b); for (int i = n; i >= 0; i--) for (int j = m; j >= 0; j--) { if (i == n || j == m) dp[i][...
7
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const long long Inf = 1e10; const int P = 1e9 + 7; const int N = 10005; inline long long IN() { long long x = 0; int ch = 0, f = 0; for (ch = getchar(); ch != -1 && (ch < 48 || ch > 57); ch = getchar()) f = (ch == '-'); for (; ch >= 48 && ch...
12
#include <bits/stdc++.h> using namespace std; int N; vector<int> in; int MAX = -1; void update() { stack<int> S; S.push(1000000010); for (int i = N - 1; i >= 0; --i) { while (in[i] > S.top()) S.pop(); if (S.top() != 1000000010) (MAX) = max((MAX), (S.top() ^ in[i])); S.push(in[i]); } } int main() { ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int x; vector<int> v; for (int i = 0; i < n; i++) { scanf("%d", &x); v.push_back(x); } vector<int> vv(n); vv[n - 1] = v[n - 1]; for (int i = n - 2; i >= 0; i--) vv[i] = min(v[i], vv[i + 1]); for (int i = 0; i ...
3
#include <bits/stdc++.h> using namespace std; const int MAX_N = 500000; const int MAX_C = 200000; const int MOD = 1000003; int fs[MAX_N + MAX_C + 1], invfs[MAX_N + MAX_C + 1]; int powmod(int a, int n) { int pm = 1; while (n > 0) { if (n & 1) pm = (long long)pm * a % MOD; a = (long long)a * a % MOD; n >>...
5
#include <bits/stdc++.h> using namespace std; signed long long int a[200001], n, m, i, x, k; signed long long int cautbin(signed long long int val) { signed long long int step = (1 << 18), start = 0; for (; step; step >>= 1) { signed long long int index = step + start; if (index > n) continue; if (a[ind...
2
#include <bits/stdc++.h> using namespace std; string str; int main() { ios_base::sync_with_stdio(false); cin.tie(); cin >> str; for (int i = 0; i <= str.size() - 1; i++) { if (str[i] == '1' || (str[i] == '4' && i > 0 && str[i - 1] == '1') || (str[i] == '4' && i > 1 && str[i - 1] == '4' && str[i - 2]...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; for (int i = 1; i <= 1000000000; i++) { if (i % 2 == 1) { if (a >= i) { a -= i; } else { cout << "Vladik"; return 0; } } else { if (b >= i) { b -= i; } else { ...
0
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (i % 2 == 1 && j % 2 == 1) printf("W"); else if (i % 2 == 0 && j % 2 == 0) printf("W"); else printf("B"); } printf("\n"); } retur...
1
//author: mr_detective #include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); #define endl "\n" #define MOD 1000000007 #define ll long long int int main(){ IOS; ll t; cin >> t; while(t--){ ll n; cin >> n; ll a[n+1] , b[n+1] ,t[n+1] , arrival =0, depart =0 ,wait , tr...
0
#include <bits/stdc++.h> using namespace std; vector<vector<int>> graph, tgraph; vector<bool> vis; vector<int> cost, order, scc; int n, m; long long amount, ways; void dfs1(int u) { vis[u] = true; for (auto to : graph[u]) if (!vis[to]) dfs1(to); order.push_back(u); } void dfs2(int u) { vis[u] = true; scc....
4
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const double eps = 0.000001; int q(int i, int j, vector<int> &ps) { if (i > j) return 0; if (i) return ps[j] - ps[i - 1]; return ps[j]; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; ...
3
#include <bits/stdc++.h> using namespace std; int n, po[22][3], l, r; double dp[1 << 20]; const double pi = acos(-1); const double eps = 1e-7; double cal(double l, double x, double y, double a) { double afa = a * 1.0 / 180 * pi; if (abs(a - 90) < eps && x <= l) return r; if (l - x > eps) { double theta = atan...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 111; int a[maxn], b[maxn], c[maxn], id[maxn], d[111][2009], pre[111][2009], num = 0; void pri(int xx, int mx) { if (xx == 0) { printf("%d\n", num); return; } if (pre[xx][mx] != mx) num++; pri(xx - 1, pre[xx][mx]); if (pre[xx][mx] != mx) { ...
6
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const long long ooo = 9223372036854775807ll; const int _cnt = 1000 * 1000 + 7; const int _p = 1000 * 1000 * 1000 + 7; const int N = 100005; const double PI = acos(-1.0); const double eps = 1e-9; int o(int x) { return x % _p; } int gcd(int a, int b...
13
#include <bits/stdc++.h> using namespace std; string mon[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int main() { string month; int n, s; while (cin >> month >> s) { for (n =...
0
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int t, n, p, c[200005], d[200005]; long long a[200005], b[200005], ans; map<long long, int> mm; inline void updatec(int x) { for (; x <= p; x += (x & -x)) ++c[x]; return; } inline int getc(int x) { int res = 0; for (; x; x -= (x & -x)...
4
#include <bits/stdc++.h> using namespace std; int v[21]; void main2() { int n, a, b; cin >> n >> a >> b; for (int i = 0; i < n; i++) { cin >> v[i]; } int ans = 0; bool can = 1; for (int i = 0; i < n / 2; i++) { if (v[i] != 2 || v[n - 1 - i] != 2) { if (v[i] != 2 && v[n - 1 - i] != 2) ...
1
#include <bits/stdc++.h> using namespace std; long long fpow(long long n, long long k, long long p = 1000000007) { long long r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } long long inv(long long a, long long p = 1000000007) { return fpow(a, p - 2, p); } long long S...
1
#include <bits/stdc++.h> using namespace std; char s_r[300010]; int a, b, c; char s1[300010], s2[300010]; int h1[300], h2[300]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> s1 >> s2; int i1 = 0, i2 = 0; int l = strlen(s1); for (int i = 0; i < l; ++i) h1[s1[i]]++; for (int j = 0; j ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 7; int main() { long long t; cin >> t; while (t--) { int a[N]; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int l[N]; int r[N]; int k = 0; for (int i = 0; i < n; i++) { int mx = 0; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int r, c, n, k; scanf("%d%d%d%d\n", &r, &c, &n, &k); int a[r][c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { a[i][j] = 0; } } int x, y; for (int i = 0; i < n; i++) { scanf("%d %d\n", &x, &y); a[x - 1][y - 1] ...
1
#include <bits/stdc++.h> using namespace std; template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv>& p) { os << "{" << p.first << ',' << p.second << "}"; return os; } const int MAX = 100005; const int INF = 1000000000; long long power(long long n, long long m, long long MOD) { if...
6
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; const long long mod = 1000003; long long f[1010]; long long p(int n) { long long res = 1ll; for (int i = 0; i < n; i++) res = res * 2ll % mod; return res; } long long calc(int n) { if (n == 0) return 0ll; if (n =...
2
#include <bits/stdc++.h> using namespace std; inline int powmod(int a, int b) { int tmp = 1; for (; b; b >>= 1) { if (b & 1) tmp = tmp * a; a = a * a; } return tmp; } template <class T> inline void R(T &xx) { xx = 0; char ch = getchar(); bool F = 0; while ((ch < '0' || ch > '9') && ch != '-') ch...
9
#include <bits/stdc++.h> using namespace std; struct pt { long long x, y; }; int n, p, q; pt projects[100000]; pt cp[100000]; int m; bool pcmp(const pt &a, const pt &b) { if (a.x < b.x) return true; if (a.x > b.x) return false; return a.y < b.y; } long long cross(long long vx, long long vy, long long wx, long l...
8
#include <bits/stdc++.h> using namespace std; int n, m, p, s, q, t, i, j, k, x, y, z, c, d, l, r, lst, a, b, ans, mn, mx, cnt, l1, l2; int main() { cin >> t; for (q = 0; q < t; q++) { cin >> d; if (d < 4 && d > 0) cout << "N\n"; else { cout << "Y "; cout << setprecision(15) ...
2
#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]; vector<pair<int, int>> b; for (int i = 1; i <= 100; i++) { int sum = 0; for (int j = 0; j < n; j++) { if (abs(a[j] - i) > 1) sum += abs(a[j] - i) - 1; } b.push...
1
#include <bits/stdc++.h> using namespace std; int n; vector<long long> v; void solve(long long x, int l) { if (l == 11) return; if (x > 0) v.push_back(x); solve(x * 10 + 4, l + 1); solve(x * 10 + 7, l + 1); } int main() { cin >> n; solve(0, 0); sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000,100000000000") using namespace std; const long long inf = 1e18 + 7; const long long mod = 1e9 + 7; const double eps = 1e-12; const double PI = 2 * acos(0.0); const double E = 2.71828; int n, m; char s[3005][3005]; long long f[3005][3005]; long long c...
8
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { long long n; cin >> n; long long x[n], h[n]; for (long long i = 0; i < n; i++) { cin >> x[i] >> h[i]; } long long ans = 0; long long xl = -9999999999; for (long long i = 0; i < n - 1; i++) { if (x[i] - h[i] > ...
3
#include <bits/stdc++.h> using namespace std; int d[70][70][70], ans[70][70][70]; int m, n, r; const int INF = 1 << 30; void floyd(int t) { for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) d[t][i][j] = min(d[t][i][j], d[t][i][k] + d[t][k][j]); } int main() { c...
5
#include <bits/stdc++.h> using namespace std; struct point : pair<int, int> { point() { cin >> first >> second; } }; struct sum : pair<long long, long long> { sum(long long a = 0, long long b = 0) { first = a, second = b; } friend sum operator+(const sum& a, const point& p) { return sum(a.first + p.first, a.s...
2
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int ct[32]; int main() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; ++i) { cin >> a[i]; for (long long k = 0; k < 32; ++k) { long long x = (long long)((long long)1 << k); if ((a[i] & x) == x) ct[k...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, m, t; cin >> a >> m; while (a < 10000000 && a % m) { a += (a % m); } if (a % m == 0) cout << "Yes"; else cout << "No"; return 0; }
3
#include <bits/stdc++.h> using namespace std; using lint = long long; int a[111111]; int d[111111]; void solve(istream& cin, ostream& cout) { int n, k; cin >> n >> k; for (int i = (0); i < int(n); ++i) { cin >> a[i]; --a[i]; if (a[i] == -1) { d[i] = 1 + min(k, i) + min(k, n - i - 1); } else ...
3
#include <bits/stdc++.h> using namespace std; int main() { int fd[507][507], n, m, x, y, c = 0; string s; cin >> n >> m >> x >> y >> s; cout << "1" << " "; int l = s.length(); for (int i = 0; i < l - 1; i++) { fd[x][y] = 1; if (s[i] == 'U' && x > 1) x--; if (s[i] == 'D' && x < n) x++; ...
4
#include <bits/stdc++.h> using namespace std; int in[105]; int main() { int n, l; scanf("%d %d", &n, &l); for (int i = 0; i < n; i++) scanf("%d", &in[i]); int maxx = 0; for (int h = l; h <= 100; h++) { int w = 0; for (int i = 0; i < n; i++) { w += in[i] / h; } maxx = max(maxx, w * h); ...
3
#include <bits/stdc++.h> using namespace std; long long w[100008], pref[100008]; int main() { long long n, l, r, ql, qr; cin >> n >> l >> r >> ql >> qr; pref[0] = 0; for (int i = 1; i <= n; i++) { cin >> w[i]; pref[i] = pref[i - 1] + w[i]; } long long ans = 100000000000000000LL; for (int i = 0; i ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 50, MAXM = 2e7 + 50, INF = 0x3f3f3f3f, MOD = 1e9 + 9, BASE = 4e5; const double eps = 1e-9; int read() { int cnt = 0, flag = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') flag = -1; c = getchar(); } while...
2
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, k, m, n, x, y, z; int s; cin >> s; for (int i = 1; i <= s; i++) { cin >> a >> b >> c >> d >> k; n = a / c; if (a % c != 0) { x = n + 1; } else { x = n; } m = b / d; if (b % d != 0) { y = m + ...
0
#include <bits/stdc++.h> using namespace std; const double g = 10.0, eps = 1e-12; const int N = 3000 + 10, maxn = 90000 + 10, inf = 0x3f3f3f3f; long long quick(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % 1000000007; a = a * a % 1000000007; b /= 2; } return a...
5
#include <bits/stdc++.h> using namespace std; long double pi = 3.14159265359; long long gcd(long long a, long long b) { if (b == 0) return a; gcd(b, a % b); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; if (N < 6) cout << -1 << "\n"; else if (N == 6) {...
3
#include <bits/stdc++.h> using namespace std; int n, k, x; long long res, r2; vector<long long> V, V2; long long P[2][200002]; int main() { ios_base::sync_with_stdio(0); cin >> n >> k >> x; long long a = 1; for (int i = 0; i < k; i++) a *= x; for (int i = 0; i < n; i++) { int b; cin >> b; V.push_b...
4
#include <bits/stdc++.h> using namespace std; int k, n, cnt; int a[200005]; pair<long long, pair<int, int> > t[200005]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> k; for (int seq = 1; seq <= k; ++seq) { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; long ...
3
#include <bits/stdc++.h> using namespace std; struct ht { int x1; int x2; int y; bool operator<(const ht &rhs) const { return (x1 < rhs.x1); } }; int v[100005]; ht h[100005]; int x[100005 << 2]; int xn; struct BIT { int b[100005 << 2]; int n; BIT(int _n) { n = _n + 1; memset(b, 0, sizeof(b)); } ...
4
#include <bits/stdc++.h> using namespace std; int a[1000001]; int p[1000001]; int fa[1000001]; int e[1000001]; int fact(int x) { int i = 0; int s = 0; while (x != 1 && e[i] * e[i] <= x) { int sign = 0; while (x % e[i] == 0) { sign = 1; x /= e[i]; } if (sign) p[s++] = e[i]; ++i; }...
4
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int T; T = 1; while (T--) { long long int n, x; cin >> n >> x; std::map<long long int, long long int> m; vector<long long int> v(n); for (int i = 0; i < n; ++i) { long long int x; cin >> ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); n = k + 1; map<int, int> cnt; for (int i = 0; i < n; ++i) { printf("? "); for (int j = 0; j < n; ++j) if (i != j) printf("%d ", j + 1); printf("\n"); fflush(stdout); int pos, val; scanf("...
13
#include <bits/stdc++.h> using namespace std; long long ans; long long n, ar[100050], asr[100050], asn; map<long long, int> mii; int main(void) { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> ar[i]; if (mii.count(ar[i])) mii[ar[i]]++; else mii[ar[i]] = 1; } ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i; cin >> n >> m; for (i = 0; i < n; i++) { cout << "5"; } cout << endl; for (i = 0; i < n - 1; i++) { cout << "4"; } cout << "5" << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int main() { int n, len, maxm, i, num; char a[maxn]; while (scanf("%d", &n) != EOF) { getchar(); gets(a); maxm = -1; len = strlen(a); num = 0; for (i = 0; i < len; i++) { if (a[i] != ' ') { if (a[i] >= 'A' &...
0
#include <bits/stdc++.h> using namespace std; int main() { int m, n, c; cin >> m >> n; c = m * n; cout << c / 2 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; unsigned long long n; int mapa[100], pos, conti; long long divi[100], a, b, c, aa, bb, cc; void busca(int ind) { if (ind >= pos) { if ((c + b - a) % 2LL == 0LL && c + b - a > 0LL) { cc = (c + b - a) >> 1LL; bb = c - cc; aa = b - cc; if (aa > 0L...
8
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5, mod = 1e9 + 7; int n, q, x, a[N], b[N], f[N], d[N], g[N], dp[N], t[N], ans; set<int> s; void M(int x, int y) { for (; x <= 2 * n; x += x & -x) (t[x] += y) %= mod; } int Q(int x) { int r = 0; for (; x; x -= x & -x) (r += t[x]) %= mod; return r;...
11
#include <bits/stdc++.h> using namespace std; const int N = (int)4e5 + 7; int curnode = 2; int par[22][N]; long long parsum[22][N]; long long last = 0; long long weight[N]; void add(int node, long long w) { weight[curnode] = w; if (weight[curnode] <= weight[node]) { par[0][curnode] = node; } else { int fr...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, l, r, x, arr[20]; cin >> n >> l >> r >> x; for (int i = 0; i < n; i++) cin >> arr[i]; int ans = 0; for (long long i = 1 << n; i >= 0; i--) { int sum = 0, mn = 9999999, mx = -1; for (int j = 0; j < n; j++) { if (((1LL) << j) & i) {...
3
#include <bits/stdc++.h> using namespace std; static const int maxn = 3000 + 5; static const int maxm = 6000 + 5; static int n, c; static int suf[maxn], pre[maxm], tar[maxm], e; static int vis[maxn], dep[maxn], dis[maxn]; static int deg[maxn], que[maxn], head, tail; static double ans; inline int read() { int k = 0, f...
11
#include <bits/stdc++.h> using namespace std; const int Maxn = 4000; int n, r[Maxn]; vector<int> a; void input() { cin >> n; for (int i = 0; i < n; i++) { cin >> r[i]; a.push_back(r[i]); } } void solve() { sort(a.begin(), a.end()); for (int i = 0; i < n; i++) for (int j = 1; j < n + 1; j++) ...
0
#include <bits/stdc++.h> using namespace std; int n, a[200001], p, rn, cnt[200001] = {0}, rem[200001], done[200001] = {0}; int main() { cin >> n; for (int i = (0); i < (n); i++) { cin >> a[i]; cnt[a[i]]++; } rn = 0; for (int i = (1); i < (n + 1); i++) { if (cnt[i] == 0) { rem[rn++] = i; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, b, p, x, y; while (scanf("%d%d%d", &n, &b, &p) != EOF) { y = n * p; x = 0; int now = 1; while (n != 1) { now = 1; while (now <= n) now *= 2; now /= 2; x += now * b; x += now / 2; now /= 2; ...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; template <class T> T gcd(T x, T y) { while (T t = x % y) x = y, y = t; return y; } const double eps = 1e-9; const double PI = acos(-1.); const int INF = 1000000000; const int MOD = 1000000007; const double E = 2.71...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; cout << n / 2520; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 10; int n, m; long long c[MAXN], g[MAXN], a1[MAXN], a2[MAXN], b1[MAXN], b2[MAXN]; inline void work(long long x, int n, long long *d1, long long *d2) { if (n == 0) { d1[n] = d2[n] = 0; return; } if (n == 1) { d1[n] = (x == 2); d2[...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 10; const long long INF = 1ll << 60; long long dp[N], pd[N], n, c, p[N], s[N]; int main() { while (scanf("%I64d%I64d", &n, &c) == 2) { for (int i = 1; i <= n; i++) scanf("%I64d", &p[i]); for (int i = 1; i <= n; i++) scanf("%I64d", &s[i]); f...
10
#include <bits/stdc++.h> struct Vertex { int v; bool marked; int degree; Vertex(int v = 0) : v{v}, marked{false}, degree{0} {} }; struct Graph { int n; std::vector<std::list<int> > adj; std::vector<Vertex> V; Graph(int n) : n{n}, adj{std::vector<std::list<int> >(n)}, V{std::vector<Vertex>(n)} { ...
3
#include <bits/stdc++.h> using namespace std; long long n; deque<long long> a; int main() { ios::sync_with_stdio(0); cin >> n; a.resize(n); for (long long i = 0; i < n; ++i) { cin >> a[i]; } a.push_front(0); a.push_back(1001); long long len = 1, mx = 1; for (long long i = 1; i < n + 2; ++i) { ...
2
#include <bits/stdc++.h> using namespace std; struct Event { int type; int time; int enemy; int newHealth; Event() = default; Event(int _type, int _time, int _enemy, int _newHealth) : type(_type), time(_time), enemy(_enemy), newHealth(_newHealth) {} }; auto cmp = [](const Event& l, const Event& r) { r...
8
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c[1234567], d, e, i, j, n; map<long long, long long> m; string s; cin >> a >> b; cout << "YES" << endl; for (i = a; i <= b; i += 2) { cout << i << " " << i + 1 << endl; } }
1
#include <bits/stdc++.h> using namespace std; const int inf = (int)(998244353); const long long ll_inf = (long long)(1e18 + 420); const long long N = (long long)(2e5 + 10); const double eps = (double)(1e-9); const double pi = (double)(3.14159265358979); inline void boost() { ios_base ::sync_with_stdio(false); cin.t...
0
#include <bits/stdc++.h> using namespace std; int main() { string s, s1, s2; s = "qwertyuiopasdfghjkl;zxcvbnm,./"; map<char, int> m; cin >> s1 >> s2; for (int i = 0; i < s.size(); i++) { m[s[i]] = i; } if (s1 == "R") { for (int i = 0; i < s2.size(); i++) { if (s2[i] == 'q' || s2[i] == 'q' ||...
0
#include <bits/stdc++.h> using namespace std; pair<long long, long long> a[100005]; bool compare(pair<long long, long long> p1, pair<long long, long long> p2) { if (p1.first == p2.first) return p1.second < p2.second; return p1.first < p2.first; } long long sum[100005]; long long b[100005]; long long b2[100005]; int...
5
#include <bits/stdc++.h> using namespace std; bool f = false; struct node { int id; int val; } p[300005]; bool cmp(node a, node b) { return a.val < b.val; } int n; void solve(int x1, int x2, int flag) { for (int i = 1; i <= n; ++i) { int num = x1 / p[i].val; if (x1 % p[i].val) num++; if (num + i - 1 >...
4
#include <bits/stdc++.h> using namespace std; signed long long int bit[200000 + 5]; signed long long int read(int idx) { signed long long int sum = 0; if (idx == 0) return 0; while (idx > 0) { sum += bit[idx]; idx -= (idx & -idx); } return sum; } void update(int idx, int val) { while (idx <= 200000)...
7
#include <bits/stdc++.h> using namespace std; vector<int> zfunc(string s) { int n = (int)s.size(); vector<int> z(n, 0); for (int i = 1, l = 0, r = 0; i < n; i++) { if (i < r) { z[i] = min(r - i, z[i - l]); } else { z[i] = 0; } while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++; ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> diff(n); long long sum = 0; for (int i = 0; i < (int)(n); ++i) { long long a, b; cin >> a >> b; sum += a; diff[i] = a - b; } sort(diff.rbegin(), dif...
1
#include <bits/stdc++.h> using namespace std; inline int gc() { static const int BUF = 1e7; static char buf[BUF], *bg = buf + BUF, *ed = bg; if (bg == ed) fread(bg = buf, 1, BUF, stdin); return *bg++; } inline int ri() { int x = 0, f = 1, c = gc(); for (; c < 48 || c > 57; f = c == '-' ? -1 : f, c = gc()) ...
5
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5, M = 1e6 + 5, C = 1e3 + 5, MOD = 1e9 + 7, OO = 1e9 + 5; long long a, b, x1, x2, y_1, y2; long long addLine(long long mul, long long x) { return mul * a - x; } long long subLine(long long mul, long long x) { return mul * b + x; } p...
5
#include <bits/stdc++.h> using namespace std; int add(int x, int y) { return ((x + y) % 1000000007 + 1000000007) % 1000000007; } int mul(int x, int y) { return (long long)x * y % 1000000007; } int mypow(int x, int c) { int ret = 1; while (c > 0) { if (c & 1) { ret = mul(ret, x); } c /= 2; x ...
8
#include <bits/stdc++.h> using namespace std; long long fact[14]; void initFact() { fact[0] = 1; for (int i = (int)(1), _m = (int)(14); i < _m; ++i) fact[i] = fact[i - 1] * i; } int digits[11], n; int dp[11][2][2]; int rec(int indx, int smaller, bool first) { if (indx == n) return first; int &ret = dp[indx][sma...
5
#include <bits/stdc++.h> using namespace std; int n, mx = 0, a[200007], b[200007], q; vector<pair<int, pair<int, int>>> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; cin >> n; for (long long i = 1; i <= (long long)n; ++i) cin >> a[i]; cin >> q; for (long long i = 1; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 3405, mo = 1e9 + 7; int a[N], b[N], c[N], f[N][N][2][2], p, k, cnt, n, m, ans; char s[N]; int main() { scanf("%d%d%s", &p, &k, s); n = strlen(s); for (int i = 0; i < n; i++) a[n - i] = s[i] - '0'; for (m = 0; !(n == 1 && a[1] == 0);) { int res = 0;...
12
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int inf = 1000000000000000000; #pragma GCC optimize("-O3") long long int gen() { long long int temp; cin >> temp; return temp; } long long int power(long long int a, long long int b, long long int m) { long long ...
3
#include <bits/stdc++.h> using namespace std; const long long M = 1000000007; class SuffAut { public: vector<map<char, int>> go; vector<int> link; vector<long long> len; int last; vector<vector<int>> a; vector<long long> din; int n; void make_link(int l, int r) { link[l] = r; } int add_vertex(int len...
8
#include <bits/stdc++.h> using namespace std; char S[1000001]; set<pair<int, int>> st; set<pair<int, char>> points; int N; int val[1000001]; void update(int ind) { set<pair<int, char>>::iterator it = points.lower_bound({ind, 'a' - 1}); int cnt = 0; char C = it->second; it++; if (it != points.end()) { if (...
6