func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, l, r; int Niz1[100001], Niz2[100001], hes[100001], time1[100001], time2[100001]; int main() { scanf( %d %d %d , &n, &l, &r); for (int i = 1; i <= n; i++) { scanf( %d , &Niz1[i]); hes[i] = Niz1[i]; } for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long cur = 1; long long ans = 0; long long now = n; while (cur <= now) { now -= cur; cur *= 2; ans++; } if (now != 0) ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int a[100009]; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int t = 0; long long sum1 = 0; sort(a, a + n); int m = 0, l = 0, token = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] > k) { ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long k = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { k = k * 10 + ch - 0 ; ch = getchar(); } r...
#include <bits/stdc++.h> using namespace std; const int maxn = 500; const int maxm = 500000 + 10; struct Edge { int next, v; Edge() {} Edge(int next, int v) : next(next), v(v) {} } e[maxm << 1]; int n, m, timer, num, len; int head[maxm], cnt; int dfn[maxn], low[maxn], belo[maxn]; bool inst...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; int n, A[maxn]; int main() { cin.sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) cin >> A[i]; int cnt = 0; for (int i = 2; i <= n - 1; ++i) if ((A[i] > A[i - 1] && A[i] > A[i + 1]) || (A[i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); double h, w; cin >> h >> w; int ans1, ans2, mx = 0; long long int i = 1; while (i * 2 <= h && i * 2 <= w) { i *= 2; } ans1 = min((long long int)h, (long...
#include <bits/stdc++.h> using namespace std; int main() { char str[100005]; scanf( %s , str); int l = strlen(str); int pr = -1, i, j; for (i = z ; i >= a ; i--) for (j = 0; j < l; j++) { if (str[j] == i && j > pr) { cout << str[j]; pr = j; } } ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int a[n + 1]; for (long long int i = 1; i < n; i++) cin >> a[i]; long long int i = 1; long long int sum = 1; while (i < n) { if (sum >= k) break; sum = i + a[i]; i = ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long A, long long b) { if (b == 0) return A; else return gcd(b, A % b); } long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; ...
#include <bits/stdc++.h> using namespace std; int n, na, nb, nc; vector<int> a, b; vector<int> start; int solve(vector<pair<int, int> > &c, vector<pair<int, int> > &b) { int nb = b.size(); int nc = c.size(); int ans = 0; sort(c.begin(), c.end()); sort(b.begin(), b.end()); int i = 0, j ...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, l, r, x; cin >> n >> l >> r >> x; long long c[n]; for (long long i = 0; i < n; i++) cin >> c[i]; long long ans = 0; for (long long i = 0; i < (1 << n); i++) { long long mn = INT_MAX; long long mx = 0; ...
#include <bits/stdc++.h> using namespace std; int n; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; if (n & 1) cout << (n / 2) * (n / 2 + 1); else cout << (n / 2) * (n / 2); cout << n ; for (int i = 1; i <= n / 2; i++) for (int j = n / 2 + 1; j <= n...
#include<bits/stdc++.h> using namespace std; #define FOR(i, j, k) for(int i = j; i <= k; i++) #define ROF(i, j, k) for(int i = j; i >= k; i--) #define PB push_back #define MEM(n, val) memset((n), val, sizeof(n)) #define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define F first #...
#include <bits/stdc++.h> using namespace std; const int N = 234567; int n; vector<int> e[N]; int f[N]; void dfs(int u, int p) { int go_before_parent = 0; int go_after_parent = 0; for (int i = 0; i < e[u].size(); ++i) { int v = e[u][i]; if (v == p) { continue; } df...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int x[N], z[2 * N], n, m, k; struct node { int v, i; } y[N]; bool com(node k1, node k2) { return k1.v < k2.v; } bool f(int w) { int o = 0, i = 1, j = w, l; while (i <= n && j <= m) { if (x[i] <= y[j].v) z[++o]...
#include <bits/stdc++.h> using namespace std; const int M = 50 * 1000 * 1000, LG = 40; int get(long long x, int y) { return (x >> y) & 1; } int main() { int n, p; cin >> n >> p; for (int i = 0; i < M; i++) { long long x = (long long)n - 1ll * p * i; if (x >= i && __builtin_popcount(x) <=...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a; cin >> a; int count1 = 0, count2 = 0, count3 = 0, count4 = 0; for (int i = 0; i < a.length(); i++) { if (a[i] == r && i % 2 == 0) count1++; if (a[i] == b && i % 2 == 0) count3++; if (a...
#include <bits/stdc++.h> using namespace std; const int maxN = 2000 * 100 + 100; vector<pair<int, int> > c[maxN]; bool mark[maxN]; bool used[maxN]; int arr[maxN], ind; int st[maxN]; struct Ans { int x, y, z; }; void dfs(int s) { mark[s] = true; st[s] = ind; arr[ind++] = s; for (a...
#include <bits/stdc++.h> using namespace std; vector<int> dijkstra(vector<vector<int>> &edges, int s) { vector<int> dist(edges.size(), 1e9); queue<int> pq; dist[s] = 0; pq.push(s); while (!pq.empty()) { auto u = pq.front(); pq.pop(); auto d = dist[u]; if (d == dist[u]) ...
#include <bits/stdc++.h> using namespace std; 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)) % md; } else { long long y = bigmod(b, p / 2, md); return (y * y) % md; } } int cnt[70]; c...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3 ) int i, j, k, n, m, res, kilk, cnt; vector<int> nums; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> m; if (n < 3) return cout << Yes << n , 0; while (m) { if (m % n == 0 || m...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); char in[n]; int result = 0; scanf( %s , in); for (int i = 0; i < n; i++) { if (in[i] == < ) { result++; } else { break; } } for (int i = n - 1; i >= 0; i--) { i...
#include <bits/stdc++.h> using namespace std; const int len = 3050; int d[len]; int ans(int n) { int sum = 0; while (true) { int i; if (!d[0]) break; for (i = 0; i < n;) { if (i == n - 1) { sum++; break; } if (i < n - 2 && d[i + 2]) ...
#include <bits/stdc++.h> using namespace std; void mul(unsigned long long int F[2][2], unsigned long long int M[2][2]) { unsigned long long int x = F[0][0] * M[0][0] % 1000000007 + F[0][1] * M[1][0] % 1000000007; unsigned long long int y = F[0][0] * M[0][1] % 1000000007 + F[0][1] * M[1][1] %...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int count = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == B && count > 0) { count--; } else { count++; } } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n / 2) + n; }
#include <bits/stdc++.h> using namespace std; int dp[51][51], n; int len[2]; bool ok[2][26][51][51]; char str[50][51], s[2][51]; void Init(int id) { int st, ed, L, mid; for (int i = 0; i < len[id]; i++) ok[id][s[id][i] - a ][i + 1][i + 1] = true; for (L = 2; L <= len[id]; L++) for (st = 1...
#include <bits/stdc++.h> using namespace std; vector<vector<long long>> matrixMul(vector<vector<long long>> lft, vector<vector<long long>> rit, long long mod = 1e9 + 7) { int n = lft.size(), s = rit.size(), m = rit.back().size(); ve...
#include <bits/stdc++.h> using namespace std; const int base = 1000 * 1000 * 1000, inf = 1000 * 1000 * 1000; int buf = 0; long long gcd(long long a, long long b) { while (b) b ^= a ^= b ^= a %= b; return a; } int p[10], e[10][10]; string a[10]; int main() { int n, k, ans = inf; cin >> n ...
#include <bits/stdc++.h> using namespace std; char s[2000], t[2000]; int f[2000]; int main() { int n, m, q; scanf( %d%d%d , &n, &m, &q); scanf( %s , s + 1); scanf( %s , t + 1); for (int i = 1; i <= n - m + 1; i++) { int flag = 1; for (int j = 1; j <= m; j++) if (s[i + j -...
#include <bits/stdc++.h> const int maxn = 3e5 + 1; inline long long max(long long a, long long b) { return a > b ? a : b; } inline long long min(long long a, long long b) { return a < b ? a : b; } long long rev[19], n, m, opt, k, x, l, r; struct Segment_Tree { long long val[maxn << 2]; inline void pus...
#include <bits/stdc++.h> using namespace std; inline void normal(long long int& a) { a = (a + 1000000007) % 1000000007; } inline int modMul(long long int a, long long int b) { a %= 1000000007, b %= 1000000007; normal(a), normal(b); return (a * b) % 1000000007; } inline int modAdd(long long int a, ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, oo = inf; inline long long read() { register long long x = 0; char f = 0; register char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == - ); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; int n, p, first[N], second[N]; double tmin = 1e9; pair<double, int> d[N]; bool ok(double x) { double tp = x * p; for (int i = 0; i < n; ++i) { tp -= max(first[i] * x - second[i], 0.0); } return tp >= 0; } int mai...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MOD2 = (int)1e8 + 7; 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) { lo...
#include <bits/stdc++.h> using namespace std; const int iinf = 1e9 + 7; const long long linf = 1ll << 60; const double dinf = 1e60; template <typename T> inline void scf(T &x) { bool f = 0; x = 0; char c = getchar(); while ((c < 0 || c > 9 ) && c != - ) c = getchar(); if (c == - ) {...
#include <bits/stdc++.h> using namespace std; namespace solve { long long int a[200007], sum[200007], dpDown[200007], dpUp[200007]; vector<int> graph[200007]; void rec(int u, int p) { sum[u] = a[u]; for (int v : graph[u]) { if (v == p) continue; rec(v, u); dpDown[u] += dpDown[v] + su...
#include <bits/stdc++.h> using namespace std; int N; string board[30]; int mask[42][30]; int dp[42][1 << 20]; int func(int i, int j, int c, bool first) { if (dp[i][j] != 10000) return dp[i][j]; int next; int ans = -(1 << 29); if (i == 2 * (N - 1)) { ans = 0; } else { for ((ne...
#include <bits/stdc++.h> using namespace std; long long in() { long long re = 0, f = 1; char x = getchar(); while (x < 0 || x > 9 ) { if (x == - ) f = -1; x = getchar(); } while (x >= 0 && x <= 9 ) re = re * 10 + x - 48, x = getchar(); return re * f; } void out(long lo...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 1; vector<int> g[maxn]; int n, m, k, num[maxn], pre[maxn], maxx = 0, flag = 0; void dfs(int u, int fa, int deep) { num[u] = deep; pre[u] = fa; for (int to : g[u]) { if (flag) return; if (to == fa) continue; if (...
#include <bits/stdc++.h> using namespace std; int m, n, l, r, mid, t; int a[200002], b[200002], ida[200002], idb[200002], to[200002]; long long ans[200002] = {}; template <class T> void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) f |= (ch == - ), ch = ge...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<long long>; using vpi = vector<pair<long long, long long>>; using vvi = vector<vi>; using tp = tuple<long long, long long, long long>; using pi = pair<long long, long long>; void __READ__() { ios_base ::sync_with_s...
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> #define rep(i, a, n) for (ll i=a;i<=...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; int te, A, B, C, num[maxn + 5], AB, AC, BC, ABC, sum[8]; long long ans; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } inline bool check(int i, int j, int k) { return (i & 1) && (j & 2) && (k & 4); } inline long long C3(long l...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 15, OO = 1e6 + 3; int n, q, t1, t2; int inv[N], y[15], de[15]; long long MOD(long long a, long long b) { a %= b; if (a < 0) a += b; return a; } void rangeInv(long long m) { inv[1] = 1; for (long long i = 2; i < m; ++i) i...
#include <bits/stdc++.h> using namespace std; int n, m, cnt, b[1000100], dfn[1000100], low[1000100], q[1000100], tot, top, sccflag[1000100], pre[1000100], nxt[1000100]; int cnt2, cnt3, cntc; int cntans, ans[1000100]; vector<int> p[1000100]; struct edge { int v; edge *next; } pool[2 * 1000100...
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n; cin >> n; vector<long long> apr(n + 1), arr(n); long long now = 1, next = 2; for (long long i = 0; i < n - 1; i++, next++) { long long a = 0, b = 0; cout <...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 101; int a[MAX_N]; int n; vector<vector<int>> ans; pair<int, int> pop(multiset<pair<int, int>, std::greater<pair<int, int>>> &s) { pair<int, int> x = *s.begin(); s.erase(s.begin()); return x; } bool check(int d) { ans.clear(...
#include <bits/stdc++.h> namespace _ { const int inf = 1e9 + 7; namespace _in { template <class T> inline T read() { char ch; bool flag = 0; T x = 0; while (ch = getchar(), !isdigit(ch)) if (ch == - ) flag = 1; while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); return fla...
#include <bits/stdc++.h> using namespace std; template <typename T> T mabs(const T &a) { return a < 0 ? -a : a; } const int mod = 1e9 + 7; const int Row = 14, Mask = 4782969; int D[2][2][Mask]; int setbit[Mask][3]; int getbit[Mask][3]; int p3[20] = {1}; inline int setBit(int mask, int pos, int...
#include <bits/stdc++.h> using namespace std; char cc[8][9]; int win; void dfs(int t, int i, int j) { int x, y; if (win) { return; } if (i < 0 || i >= 8 || j < 0 || j >= 8) { return; } if (i - t >= 0 && cc[i - t][j] == S ) { return; } if (i + 1 - t >= 0 && i + ...
#include <bits/stdc++.h> using namespace std; int main() { long long int l1, l2, r1, r2, k, temp, ans, st, en; cin >> l1 >> l2 >> r1 >> r2 >> k; if (l1 <= r1) { st = r1; } else st = l1; if (l2 <= r2) en = l2; else en = r2; if (k >= st && k <= en) ans = (en -...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, b, a, c; cin >> n >> k; a = n / k; if (a % 2 == 0) cout << NO << endl; else cout << YES << endl; }
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; int n, fa[100005], p[100005], size[100005], tsize[100005], q, d[100005]; long long ans = 0, sum[100005]; void dfs(int x, int f) { p[x] = f, fa[x] = x, size[x] = tsize[x] = 1, d[x] = d[f] + 1, ans += 1ll * (n - 2) * (n - 1); for (...
#include <bits/stdc++.h> int n, ans, a[15][15]; inline void maxx(int& a, int b) { a = (a > b ? a : b); } inline void minx(int& a, int b) { a = (a < b ? a : b); } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]); for (int k = 1; k <= ...
#include <bits/stdc++.h> using namespace std; int N, K, ans; vector<int> ady[1000005]; set<int> dfs(int x, int p) { set<int> s; if (ady[x].size() == 1) { s.insert(0); return s; } for (auto v : ady[x]) { if (v == p) continue; set<int> tmp = dfs(v, x); for (auto aux :...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; struct rec { double x, y; } a[110], s, e, f[2]; int g[2], n, m, i; double ans; double XJ(rec a, rec b, rec c) { return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); } double dist(rec a, rec b) { return sqrt((a...
#include <bits/stdc++.h> using namespace std; long long a[2500000]; int main() { int all; scanf( %d , &all); for (int i = 1; i <= all; i++) { scanf( %I64d , &a[i]); } sort(a + 1, a + all + 1); reverse(a + 1, a + all + 1); long long sum = 0; for (int fro = 1; fro <= all; fro =...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n + 1); vector<vector<int> > inc(n + 1); vector<vector<int> > dec(n + 2); for (int i = 0; i < n; i++) { cin >> a[i + 1]; } for (int i = 0; i <= n; i++) { if (i == 0) ...
#include <bits/stdc++.h> using namespace std; const int zsern = 1e6 + 1000; const long long mod = 1e9 + 7; const double pi = acos(-1.0); long long n, k; long long a[zsern]; std::vector<long long> num; void gst(int id, int zser) { if (id - 1 >= 0 && id - 1 != zser) gst(id - 1, zser); else i...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(), c = 0, c1 = 0, k = 0, k1 = 0; if (n % 2 != 0) cout << -1; else { for (int i = 0; i < n; i++) { if (s[i] == R ) c++; else if (s[i] == L ) c1++; ...
#include <bits/stdc++.h> using namespace std; const int32_t mod = 1e9 + 7; const long long inf = 1e18; set<long long> S; void doq() { for (long long i = 0; i < 40; i++) { for (long long j = 0; j < 40; j++) { long long a = 3 * i + 7 * j; if (a <= 100) S.insert(a); } } } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int n, x, d = 0; cin >> n >> x; while (n--) { long long int t; char s; cin >> s; cin >> t; if (s == + ) { x += t; } else { if (x - t...
#include <bits/stdc++.h> using namespace std; void setIO(string s = ) { ios_base::sync_with_stdio(0); cin.tie(0); if ((int)s.size()) { freopen((s + .in ).c_str(), r , stdin); freopen((s + .out ).c_str(), w , stdout); } } int main() { setIO(); int n; string s; ci...
#include <bits/stdc++.h> using namespace std; const long long N = 1000; bool fg[55][55]; long long n, m, dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1}; bool flag; char s[55][55]; void dfs(long long x, long long y, long long st, long long ed) { fg[x][y] = true; for (long long i = 0; i < 4; i++) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb push_back #define endl n #define F first #define S second #define pp pop_back ll mod = 1e9+7; ll dp[200200][2]; ll st[200200]; ll n; ll rec(ll level,int curr){ if(st[level]==1||st[level]==0){ if(...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; long long a[n][m]; vector<long long> b(n); for (int i = 0; i < n; i++) { long long k = 0; for (int j = 0; j < m; j++) { ...
#include <bits/stdc++.h> using namespace std; int a[100010]; int b[100010]; int ans[100010]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[a[i]] = i; } ans[b[n]] = 0; for (int i = n - 1; i >= 1; i--) { int idx = b[i]; int flag = 0; ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e7; vector<long long> primes; vector<long long> p(N, 1); signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, p, w, d; cin >> n >> p >> w >> d; long long l = 0, r = n; while (r - l...
#include <bits/stdc++.h> using namespace std; struct chip { int l; int r; int u; int d; }; vector<char> a[5005]; vector<chip> link1[5005], link2[5005]; int n, m, kq, res; void nhap() { ios_base::sync_with_stdio(0); cin >> n >> m; char x; for (int i = 1; i <= n; ++i) a[i].pu...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); vector<vector<pair<int, int> > > e(n, vector<pair<int, int> >()); for (int i = 1; i < n; ++i) { int u, v, d; scanf( %d%d%d , &u, &v, &d); e[--u].push_back(make_pair(--v, d)); } vecto...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 2e6 + 7; const double eps = 0.00000001; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <typename ...
#include <bits/stdc++.h> const int N = 1e6 + 5; const int mod = 1e9 + 7; const int MOD = mod - 1; const double eps = 1e-18; const double PI = acos(-1.0); using namespace std; char s[200]; int main() { int n, m; scanf( %d , &n), scanf( %d , &m); scanf( %s , s + 1); int l = strlen(s + 1); ...
#include <bits/stdc++.h> using namespace std; long long M = 1000000007; int sum(int n) { int ans = 0; while (n) { ans += n % 10; n = n / 10; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k; cin >> k; int an...
#include <bits/stdc++.h> using namespace std; template <typename X> inline X abs(const X& a) { return a < 0 ? -a : a; } template <typename X> inline X sqr(const X& a) { return a * a; } long long combine(long long n, int k) { long long ans = 1; for (int i = 0; i < k; i++) ans = (ans * (n ...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[210000], b[2100000]; vector<pair<int, int> > ans; int main() { int N, M, i, j, k; scanf( %d%d , &N, &M); if (N <= M) { puts( -1 ); return 0; } for (i = 0; i < N; i++) scanf( %d%d , &a[i].first, &a[i].second); sort...
#include <bits/stdc++.h> using namespace std; long long N, L, W; vector<long long> neg, pos; long long INF32 = 0x7fffffff; inline long long div_floor(long long a, long long b) { return (long long)floor(1.0 * a / b); } int main() { cin >> N >> L >> W; for (int i = 0; i < N; ++i) { long lo...
#include <bits/stdc++.h> using namespace std; int n, m; int l[5005], r[5005], v[105][105], t[105][105]; double res[105], c[5005], f[105][105], cc[105][105]; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < m; i++) { int a, b, x; scanf( %d%d%d , &a, &b, &x); l[i] = (--a); ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000000000000; const int mod = 1000000007; int n, m, k; int s[1000010]; long long a[1000010]; bool pos[1000010]; int lst[1000010]; long long get(int l) { int r = 0; int i = -1; long long res = 0; while (r < n) { ...
#include <bits/stdc++.h> using namespace std; int Pow10(int deg) { int res = 1; while (deg-- > 0) res *= 10; return res; } int ToInt(const string& from) { int res = 0; for (int i = 0; i < ((int)(from).size()); ++i) res = 10 * res + from[i] - 0 ; return res; } void Solve() { stri...
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 1, mod = 1000000007; vector<long long int> adj[N]; signed main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long int pro = 1, temp, t, n, i, m, k, j, l, r, mid, x, y, z, rem, carry ...
#include <bits/stdc++.h> #pragma GCC optimization( O3 ) using namespace std; template <typename T> inline void Cin(T& first) { char c; T sign = 1; first = 0; for (c = getchar(); c < 0 || c > 9 ; c = getchar()) if (c == - ) sign = -1; for (; c >= 0 && c <= 9 ; c = getchar()) firs...
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = URDL ; cons...
#include <bits/stdc++.h> using namespace std; const int OHT = 100100; const int MAXINF = (2 << 26); const int MININF = (~(2 << 26)); int vis1[110], vis2[110]; int main() { int n, m, i, j; cin >> n >> m; vector<pair<int, int> > v; for (i = 2; i <= n; i++) v.push_back(make_pair(i, 1)); for...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; long long POW(long long a, long long b, long long MMM = MOD) { long long ret = 1; for (; b; b >>= 1, a = (a * a) % MMM) if (b & 1) ret = (ret * a) % MMM; return ret; } long long gcd(long long a, long long b) { re...
#include <bits/stdc++.h> using namespace std; int main() { string n; int index = 0; cin >> n; int l = n.length(); for (int i = l - 1; i > -1; i--) { if (n[i] == 4 ) index += pow(2, (l - 1 - i)); else index += 2 * pow(2, (l - 1 - i)); } cout << index << endl; ...
#include <bits/stdc++.h> using namespace std; const int N = 113; int add(int x, int y) { x += y; if (x >= 1000000007) x -= 1000000007; return x; } int sub(int x, int y) { if (x < y) x += 1000000007; x -= y; return x; } int mul(int x, int y) { return (long long)x * y % 1000000007; }...
#include <bits/stdc++.h> using namespace std; int read() { int res = 0, p = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) p = -1; ch = getchar(); } while (isdigit(ch)) res = res * 10 + ch - 0 , ch = getchar(); return res * p; } const int mod = 1e9 + 7; int ...
#include <bits/stdc++.h> using namespace std; int n, p, flag; char s[1111]; int a[1111]; void dfs(int x) { if (!x) { flag = 0; return; } while (1) { a[x]++; if (a[x] > p) { dfs(x - 1); a[x] = 0; continue; } if (!(x > 1 && a[x] == a[x - 1]...
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; long long powmod(long long a, long long b) { long long r = 1; while (b) { if (b & 1) r = (r * a) % mod; a = (a * a) % mod, b >>= 1; } return r; } long long modd(long long a, long long b) { return ((a % b) + b)...
#include <bits/stdc++.h> using namespace std; int main() { int n, b, cnt[105] = {0}; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { cin >> b; a.push_back(b); cnt[a[i]] = cnt[a[i]] + 1; } int y = 0; int x; x = *max_element(a.begin(), a.end()); for (int i ...
#include <bits/stdc++.h> using namespace std; template <class T, class U> inline bool chkmax(T& a, U b) { return (a < b) ? (a = b, true) : false; } template <class T, class U> inline bool chkmin(T& a, U b) { return (a > b) ? (a = b, true) : false; } template <class T> inline vector<T> uniq(vec...
#include <bits/stdc++.h> using namespace std; int main() { int m, k, d[2000], s[2000], n = 0, big = 0, ans = 0; cin >> m >> k; for (int i = 0; i < m; i++) cin >> d[i]; for (int i = 0; i < m; i++) cin >> s[i]; for (int i = 0; i < m; i++) { n += s[i]; if (s[i] > big) big = s[i]; ...
#include <bits/stdc++.h> using namespace std; template <class T> void rd(T &x) { x = 0; int f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) x = (x << 3) + (x << 1) + ch - 0 , ch = getchar(...
#include <bits/stdc++.h> using namespace std; long long int MOD = 998244353; long long int INF = 1e18; long long int vv; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int i, j, k = 0, l = 0, r = 0, m = 0, n, c, p = 0, cnt = 0, c...
#include <bits/stdc++.h> using namespace std; long long n, m; long long a[201]; char s[30]; long long b[30]; long long dp[2000000]; long long f(long long mask) { if (mask == (1 << m) - 1) return 0; if (dp[mask] != -1) return dp[mask]; long long count = __builtin_popcount(mask); char ch = s...
#include <bits/stdc++.h> using namespace std; int a[2010], b[2010]; bool vis[2010]; char *p1, *p2, buf[100000]; int rd() { int x = 0, f = 1; char c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++); while (c < 48) { if ...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; inline long long input() { long long n; cin >> n; return n; } string base2(long long n) { string a = ; while (n >= 2) { a += (char)(n % 2 + 0 ); n /= 2; } a += (char)(n + 0 ); reverse((a).b...