func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a = 0, b = 0, c = 0, d = 0, i, e = 0, mine = 0, mn = 0; cin >> n; string s; cin >> s; for (i = 0; i < s.size(); i++) { if (s[i] == z ) a++; if (s[i] == e ) b++; if (s[i] == r ) c++; if (s[i] ==...
#include <bits/stdc++.h> using namespace std; int hm(string s) { int c = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == a || s[i] == e || s[i] == i || s[i] == o || s[i] == u ) c++; } return c; } int main() { string s1, s2, s3; getline(cin, s1); getline(c...
#include <bits/stdc++.h> using namespace std; long long oll = 0; bool comp(const pair<int, int> &a, const pair<int, int> &b) { return a.second < b.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<long long> first, second; lon...
#include <bits/stdc++.h> using namespace std; int dr[] = {-1, 0, 1, 0, -1, 1, 1, -1}; int dc[] = {0, 1, 0, -1, 1, 1, -1, -1}; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; while (cin >> n) { vector<int> arr; int st = 1; int ans = 0; for (int i = (0); i <= (2 * ...
#include <bits/stdc++.h> using namespace std; int main() { string s; char a[100010]; int k; cin >> s; k = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == a[k]) k--; else { k++; a[k] = s[i]; } } if (k == 0) cout << Yes ; else ...
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { if (x < 0) return -x; return x; } template <class T> T sqr(T a) { return a * a; } const double pi = acos(-1.0); const double eps = 1e-8; int ar[150010]; int flag[150010]; int i, n; int main() { while ...
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const long double eps = 1e-07; int n, m; int a[2000]; int main() { scanf( %d %d , &n, &m); for (int i = 0; i < m; ++i) { int x, y; scanf( %d %d , &x, &y); ++a[x]; ++a[y]; } for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; int n, L, a; int t[int(1e5 + 9)], l[int(1e5 + 9)]; int ans; int main() { cin >> n >> L >> a; for (int i = 0; i < n; i++) { cin >> t[i] >> l[i]; } for (int i = 0; i + 1 < n; i++) { int st = t[i] + l[i]; int en = t[i + 1]; if ...
#include <bits/stdc++.h> using namespace std; void _print(long long t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t) { cerr << t; } template <class T,...
#include <bits/stdc++.h> using namespace std; const long long MODULO = 1000000007; void ftime() {} void print_arr(int n, bool arr[]) { for (int i = 0; i < n; i++) { cout << arr[i] << ; } cout << n ; } void print_arr(int n, int arr[]) { for (int i = 0; i < n; i++) { cout << a...
#include <bits/stdc++.h> int main() { int n, m, z, l, k, i = 1, j = 1, p = 0, q = 0, count = 0; scanf( %d%d%d , &n, &m, &z); int a[10000], b[10000]; while ((i * n) <= z) { a[p] = i * n; i++; p++; } while ((j * m) <= z) { b[q] = j * m; j++; q++; } for...
#include <bits/stdc++.h> int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int a[55], b[55], m, i, j, map[55], n, x, y, s; while (~scanf( %d , &m)) { for (i = 0; i < m - 1; i++) { scanf( %d , &a[i]); } for (i = 0; i < m - 1; i++) { scanf( ...
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return + s + ; } template <typename T> string to_string(vector<T>); template <typename U, typename V> string to_string(pair<U, V> p) { return ( + to_string(p.first) + , + to_string(p.second) + ) ; } template <typ...
#include <bits/stdc++.h> using namespace std; int n, a; vector<int> v1, v2; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; v1.push_back(a); v2.push_back(a); } sort(v2.begin(), v2.end()); a = 0; for (int i = 0; i < n; i++) { a += v1[i] != v2[i]; ...
#include <bits/stdc++.h> using namespace std; const int N = 7, M = 20, MOD = 1000 * 1000 * 1000 + 7; int sum(int a, int b) { a += b; if (a < 0) a += MOD; else if (a >= MOD) a -= MOD; return a; } void _sum(int &a, int b) { a = sum(a, b); } int mul(int a, int b) { return 1LL * a * ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 23; const int MOD = 1e9 + 7; const int N = 1000 + 10; int brow[N], bcol[N]; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; for (int i = 0; i < (m); ++i) { int x, y; cin >> x >> y; brow[...
#include <bits/stdc++.h> using namespace std; int n; int dp[100002]; int f(int x) { if (dp[x] != -1) return dp[x]; bool nim[100] = {}; for (int i = 2; i * (i - 1) < 2 * x; i++) { if ((2 * x - i * (i - 1)) % (2 * i) == 0) { int tmp = 0, xx = (2 * x - i * (i - 1)) / (2 * i); for ...
#include <bits/stdc++.h> using namespace std; int main() { int test; scanf( %d , &(test)); for (int t = 1; t <= test; t++) { int n; scanf( %d , &(n)); int a[200], cnt = 0; int sum = 0; for (int i = 0; i < n; i++) { scanf( %d , &(a[i])); if (a[i] == 0) { ...
#include <bits/stdc++.h> using namespace std; const int P = 998244353; int add(int a, int b) { if ((a += b) >= P) a -= P; return a < 0 ? a + P : a; } int mul(int a, int b) { return 1ll * a * b % P; } int kpow(int a, int b) { int r = 1; for (; b; b >>= 1, a = mul(a, a)) { if (b & 1) r =...
#include <bits/stdc++.h> using namespace std; const int MX = 500005; const long long MOD = 1000000007; void setIO(string name) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((name + .in ).c_str(), r , stdin); freopen((name + .out ).c_str(), w , stdout); } int t; int n; void solv...
#include <bits/stdc++.h> using namespace std; long long n, sol = 0, modul = 1000000007; vector<long long> parent, depth; long long where(long long pos) { if (parent[pos] == -1) return pos; long long a = depth[pos]; long long b = parent[pos]; long long c = where(parent[pos]); parent[pos] = c;...
#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 int mod = 1000000007; const int N = 3e5 + 5; const int INF = 1e9 + 7; vector<int> graph[N]; multiset<int, greater<int>> st; int n, a, b, dat[N], ans, cur; void rem(int val) { auto it = st.find(val); st.erase(it); } int main() { ios_base...
#include <bits/stdc++.h> using namespace std; int n, m, k; bool fort[100007]; vector<int> v[100007]; struct tuhla { int vertex; double val; }; double f[100007]; bool used[100007]; double bestval; int id; bool operator<(struct tuhla p1, struct tuhla p2) { return (p1.val > p2.val); } prior...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int k; cin >> k; int x; cin >> x; int* a; a = new int[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } int index; index = n; while (k > 0) { a[index] = x; index--; ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; vector<int> V; int px = 0; while (px < n) { if (a[px] == 1) { if (px < n && a[px + 1] == 1) { px += 2; continue; } ...
#include <bits/stdc++.h> using namespace std; signed main() { long long a[4]; for (long long i = 0; i < 4; i++) cin >> a[i]; sort(a, a + 4); if ((a[3] + a[0] == a[2] + a[1]) || (a[3] == a[0] + a[1] + a[2])) cout << YES << endl; else cout << NO << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string str[51], temp; int main() { int t, f, a; int cnt = 0, ans = 0x3f3f3f3f; scanf( %d , &t); getchar(); for (int i = 0; i < t; i++) { cin >> str[i]; } for (int i = 0; i < t; i++) { cnt = 0; for (int j = 0; j < t; j++) {...
#include <bits/stdc++.h> using namespace std; const int Maxn = 2e5 + 5; vector<int> adj[Maxn]; int sz[Maxn]; int n; long long ret, ans; void dfs_init(int u, int f) { sz[u] = 1; for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i]; if (v == f) continue; dfs_init(v, u); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; long long int sum[N << 2][11], sum2[11], a[N]; int lazy[N << 2][11], vis[11]; void pushdown(int rt) { for (int i = 0; i < 10; i++) vis[i] = lazy[rt << 1][i], sum2[i] = sum[rt << 1][i]; for (int i = 0; i < 10; i++) if (laz...
#include <bits/stdc++.h> using namespace std; long long labs(long long a) { return a < 0 ? (-a) : a; } vector<pair<long long, long long> > v; vector<long long> c; vector<bool> was; int main() { int n, k; cin >> n >> k; long long b; cin >> b; v.resize(n); c.resize(n); for (int(i) ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int a[N]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + n + 1); int lim = n / 2 - 1, res = 1e9 + 7; for (int i = 0; i <= lim; i++) { res = min(res, a[n - (lim...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); ; long long x, y; cin >> x >> y; long long n; cin >> n; long long ans; switch (n % 6) { case 1: ans = x; break; case 2: ...
#include <bits/stdc++.h> using namespace std; int n, a, b, h[20], f[20][20][20][20], g[20][20][20][20][5]; void update(int &f1, int f2, int p[5], int i, int j, int k, int l, int w) { if (f2 < f1) { f1 = f2; p[0] = w; p[1] = i; p[2] = j; p[3] = k; p[4] = l; } } int m...
#include <bits/stdc++.h> using namespace std; const int N = 300000; const long long INF = (1 << 30) - 1; int n; long long a[N + 9], sum[N + 9]; void into() { scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %lld , &a[i]); sum[i] = a[i] + sum[i - 1]; } } int ans; void Get_...
#include <bits/stdc++.h> using namespace std; int a[100000]; vector<int> p; long long fact[100001]; long long inv[100001]; long long finv[100001]; void init(int n) { int i; fact[0] = 1; for (i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % 1000000007; inv[0] = 1; inv[1] = 1; for (i ...
#include <bits/stdc++.h> using namespace std; vector<int> X[105], Y[105]; char s[105]; int main() { int n, i, j; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %s , s); for (j = 0; j < n; j++) { if (s[j] == . ) { X[i].push_back(j); Y[j].push_back(i); ...
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } int main() { int t; cin >> t; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long p1, p2, p3; cin >> p1 >> p2 >> p3; cout << (p1 + p2 + p3) / 2 << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int MOD = 1e9 + 7; const long long M = 1e18; long long qpow(long long a, long long b, long long m) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans...
#include <bits/stdc++.h> using namespace std; int n; bool f, a[(int)1e6 + 9]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < (n == 3 ? 2 : (n >> 1)); i++) { if (n % i == 0) { for (int j = 0; j < i; j++) { if (!a[j]) continue; int...
#include<bits/stdc++.h> #define int long long #define float double #define itn int #define f(j,n) for(int i=j;i<n;i++) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) #define endl n #define Endl n #define ednl n #define Ednl n #define pb push_back #define mp make_pair #...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[100000]; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); cout << min(a[n - 1] - a[1], a[n - 2] - a[0]) << n ; }
#include <bits/stdc++.h> using namespace std; signed main(signed argc, const char* argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int cnt = 0; for (int i = 0; cnt < n; ++i) { cout << 3 << << i << endl; ++cnt; if (cnt == n) break; ...
#include <bits/stdc++.h> using namespace std; const int mn = 410, mm = 101000, inf = 1 << 30; bool vis[mn]; int X[mm], Y[mm], du[mn]; int n, m, K, t, S, T, ans[mm], answer; int dis[mm], pre[mm], Q[mm]; struct network { int tt, la[mn], next[mm], y[mm], f[mm], co[mm]; void clear() { tt = 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}; string direc = RDLU ; long long ln, lk, lm; char s[105][105]; int cal(int x) { return x * (x - 1) / 2; } void fmain() { scanf( %d , &n); for (int(i) = 1; (i) <= (int)(n...
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define pb push_...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int ar[n], i, b; b = n; for (i = 0; i < n; i++) cin >> ar[i]; sort(ar, ar + n); for (i = 0; i < n; i++) { if (ar[i] < b) b--; els...
#include <bits/stdc++.h> using namespace std; int main() { string str, result = , tmp; map<string, int> array; cin >> str; for (long long i = 0; i < 10; i++) cin >> tmp, array[tmp] = i; tmp = ; for (long long i = 0; i < 80; i++) { tmp += str[i]; if ((i + 1) % 10 == 0) result ...
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int32_t main() { fast(); long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; priority_queue<long long> b; priority_queue<long long, vecto...
#include <bits/stdc++.h> using namespace std; int r, h; int main() { scanf( %d%d , &r, &h); double tt = h + r * 1.0 / 2; double re = tt / r - (int)(tt / r); int ans; if (fabs(re) < 0.00001) { ans = (int)(tt / r) * 2; } else { ans = (int)(tt / r) * 2; re = h + r - (int)(tt...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; long long int a, b, n; while (t--) { cin >> a >> b >> n; n %= 3; if (n == 0) cout << a << endl; else if (n == 1) cout << b << e...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q != 0) { int n; cin >> n; int one = 0; if (n == 1) cout << FastestFinger << endl; else if (n == 2) cout << Ashishgup << endl; else if (n % 2 != 0) cout << ...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 0; char ch = 0; while (!isdigit(ch)) f |= (ch == - ), ch = getchar(); while (isdigit(ch)) (x *= 10) += (ch ^ 48), ch = getchar(); return f ? -x : x; } void Ot(int x) { if (x < 0) putchar( - ), x = -x; if (x >=...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 3e5 + 10; const long long mod = 998244353; const double PI = acos(-1); inline int ab(int x) { return x < 0 ? -x : x; } inline int mm(int x, int p) { return x >= p ? x - p : x < 0 ? x + p : x; } int main() { int n...
#include <bits/stdc++.h> using namespace std; vector<int> graph[(int)2e5 + 5]; int visited[(int)2e5 + 5]; vector<int64_t> values; int64_t dfs(int node, int depth) { if (visited[node] == 1) return 0; visited[node] = 1; int64_t child = 0; for (int i = 0; i < graph[node].size(); i++) { if (...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t; cin >> n >> k >> t; cout << (k >= t ? t : (n >= t ? k : k - (t - n))); }
#include <bits/stdc++.h> using namespace std; const int N = 1024; int dp[N]; int n, k; vector<int> ans; int f(int i) { if (i >= n) return 0; if (i + k >= n) return 1e9; if (dp[i] != -1) return dp[i]; return dp[i] = f(i + 2 * k + 1) + 1; } int main() { ios_base::sync_with_stdio(0); ...
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { if (a > b) { return true; } else { return false; } } int main() { int n, k, le[26], cnt = 1; for (int i = 0; i < 26; i++) { le[i] = 0; } char c, ch; cin >> n >> k; getchar(); cin >> c...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 2e5 + 5; struct node { int u, v, ne; } e[maxn << 1]; int n; int head[maxn], len; int ve[maxn], b[maxn]; void add(int u, int v) { e[len].u = u; e[len].v = v; e[len].ne = head[u]; head[u] = len...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; char ch = getchar(); bool f = 0; for (; !isdigit(ch); ch = getchar()) if (ch == - ) f = 1; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 0 ; return f ? -x : x; } void write(long long ...
#include <bits/stdc++.h> using namespace std; using ll = int_fast64_t; constexpr int mod = 1e9 + 7; constexpr int inf = (1 << 30) - 1; constexpr ll infll = (1LL << 61) - 1; #pragma GCC target( avx2 ) #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) int main() { ios::sync_with_stdio(...
#include <bits/stdc++.h> using namespace std; const int N = 3010; long long a[N], b[N], n, m; long long sa = 0, sb = 0, bestSa, bestSb; pair<int, int> ansOne, ansTwo; vector<long long> va, vb; void add(long long *arr, int size, vector<long long> &v) { for (int i = 0; i < size; ++i) for (int j = ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int mod = (int)1e9 + 7; const int MAXN = (int)3e5 + 5; vector<int> primes[1000005]; int x, p, k; vector<pair<int, int> > v(1 << 7); int calc(int a) { int cnt = 1; int num = 0; int tmp = a; a = 0; for (int i...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; int t[n]; for (int i = 0; i < n; i++) { cin >> t[i]; } sort(t, t + n); bool b = true; int j = 0; if (t[0] > 1) { cout << 1; } else { while ((b == true) && (j < n)) { if...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e6 + 500; const long double eps = (1e-12); const int logn = 21; const double Pi = acos(-1.0); const long long pp = 998244353; int lowbit(int x) { return x & (-x); } const long long INF = 1e11 + 7; long long dp[3][205][4]; long long a[MA...
#include <bits/stdc++.h> int min(int a, int b) { return a < b ? a : b; } int next[1 + (200 * (200 - 1) / 2)], jj[1 + (200 * (200 - 1) / 2)]; int link(int l, int j) { static int l_ = 1; next[l_] = l; jj[l_] = j; return l_++; } int ao[200], cc[200], dd[200], qq[3][200]; int solve(int n, int c_...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; struct node { int l, r, id; } p[2][2][maxn]; bool cmp1(node A, node B) { return A.l < B.l; } bool cmp2(node A, node B) { return A.r < B.r; } int n; int sz[2][maxn]; int rid1[maxn], rid2[maxn]; int main() { srand(time(NUL...
#include <bits/stdc++.h> using namespace std; const int N = 100000; const long long INF = 1000000000000000; int a[N]; int main() { int t; cin >> t; for (int q = 0; q < t; q++) { int n, k; cin >> n >> k; for (int j = 0; j < n; j++) { cin >> a[j]; } long long an...
#include <bits/stdc++.h> using namespace std; long long pw[20][120], p[120], V, B, fA, fB, fC, ans; int num[120], n, T, i, j; void dfs_B(int l, long long x) { if ((double)x * x > V) return; if (l == n + 1) { B = max(B, x); return; } for (int i = 0; i <= num[l]; ++i) dfs_B(l + 1, x * ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, g, b; cin >> n >> g >> b; long long sure_fire = (n + 1) / 2; long long sum = 0; if (g >= b) { sum = n; } else { long long a1 = (sure_fire + g - 1) / ...
#include <bits/stdc++.h> using namespace std; inline bool smax(long long &a, long long b) { if (a < b) { a = b; return true; } else return false; } const long long MAXN = 1e5 + 100; long long dp[MAXN][4], par[MAXN][4], choose[MAXN][4], id[MAXN]; pair<long long, long long> p[MAXN], ...
#include <bits/stdc++.h> using namespace std; const int N = 3010, Mo = 1000000007; int tt, n, D; int f[N][N], rev[N * 2], head[N], to[N], nxt[N]; inline int gi() { int x = 0, o = 1; char ch = getchar(); while (ch != - && (ch < 0 || ch > 9 )) ch = getchar(); if (ch == - ) o = -1, ch = get...
#include <bits/stdc++.h> using namespace std; vector<long long int> g[300005]; long long int n, m, flag = 1; map<pair<long long int, long long int>, long long int> ans; long long int visit[300005]; long long int color[300005]; void dfs1(long long int src, long long int col) { visit[src] = 1; color...
#include <bits/stdc++.h> using namespace std; long long MOD = 998244353; double eps = 1e-12; void solve() { long long n, x; cin >> n >> x; int a; map<int, int> mr; map<int, int> mc; for (int i = 0; i < n; i++) { for (int j = 0; j < x; j++) { cin >> a; if (a) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 1; int N, Q, nums[MAXN], ans[MAXN], BIT[MAXN + 5]; vector<pair<int, int> > queries[MAXN]; void upd(int i) { i++; while (i > 0) { BIT[i]++; i -= i & -i; } } int get(int i) { i++; int ret = 0; while (i <...
#include <bits/stdc++.h> using namespace std; double start_moment = 0; double get_runtime() { return 1.0 * clock() / CLOCKS_PER_SEC; } void reset_timer() { start_moment = get_runtime(); } double timer_time() { return get_runtime() - start_moment; } void runtime() { cout << fixed << setprecision(5) << get_ru...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int mod = 1e9 + 7; const int maxn = 1e5 + 5; int m, q; int val[maxn], sum1[maxn], sum2[maxn], las[maxn], pre[maxn], fl[maxn], res[maxn]; struct no { int le, ri, id; } qu[maxn]; bool cmp(no n1, no n2) { return...
#include <bits/stdc++.h> #define MOD 998244353 using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define rrep(i, a, b) for(int i = (a-1); i >= (b); --i) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typed...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { vector<long long int> v1; vector<long long int> v2; long long int n, mo = 0, x, y, f; scanf( %lld , &n); for (long long int i...
#include <bits/stdc++.h> using namespace std; int d, n, m; const int M = 2e5; pair<int, int> gas[M + 7]; bool possible = true; int pendingD, running; int currentGas; long long res = 0; struct cmp { bool operator()(int c1, int c2) { if (gas[c1].second != gas[c2].second) return gas[c1]...
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; int num[1000]; int x, y; cin >> n; for (int i = 1; i <= n; i++) { cin >> num[i]; sum += num[i]; } cin >> x >> y; int cur = 0; for (int i = 1; i <= n; i++) { if (cur >= x && cur <= y && (s...
#include <bits/stdc++.h> using namespace std; void solve() { int a, b; scanf( %d%d , &a, &b); int c[3] = {0, 0, 0}; for (int i = 1; i <= 6; ++i) { int d1 = abs(i - a), d2 = abs(i - b); if (d1 < d2) c[0]++; if (d1 == d2) c[1]++; if (d1 > d2) c[2]++; } for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int p[n]; for (int i = 0; i < n; i++) cin >> p[i]; sort(p, p + n); map<string, int> mm; string x; for (int i = 0; i < m; ++i) { cin >> x; if (mm.find(x) == mm.end()) mm.insert(make...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; vector<vector<int> > adj(maxn), adj2(maxn); vector<pair<int, int> > vs; bool vis[maxn]; void dfs(int pv, int v) { vis[v] = 1; for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i]; if (vis[u]) continue; vs...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long z[3000019], arr[3000019], pre[3000019]; void fnc(string s) { memset(z, 0, sizeof(z)); long long l = 0, r = 0; long long n = s.size(); for (long long i = 1; i <= n; i++) { if (i <= r) z[i] = min(r - i + 1, z...
#include <bits/stdc++.h> using namespace std; int main() { int tc, cs = 1, n, k, a, b, c, d; while (cin >> n >> k) { cin >> a >> b >> c >> d; if (k < n + 1 || n == 4) { printf( %d n , -1); } else { printf( %d %d , a, c); for (int i = 1; i < n + 1; i++) { ...
#include <bits/stdc++.h> using namespace std; void File() { freopen( output.txt , w , stdout); freopen( input.txt , r , stdin); } void fast() { ios::sync_with_stdio(NULL); cout.tie(NULL); cin.tie(NULL); } const double pi = 2 * acos(0.0); const int nn = 5e2 + 5; const int oo = 0x3f3...
#include <bits/stdc++.h> using namespace std; using ll=long long; using pii=pair<int,int>; int np[17][200000]; int pre[(1<<17)+1]; int main() { int n,k; cin >> n >> k; string s; cin >> s; int l=0,r=n/k; while (l<r) { int m=(l+r+1)/2; for (int j=0;j<k;...
#include <bits/stdc++.h> using namespace std; const int MAX = 1005; char ch[MAX]; int ans[MAX]; int main() { int n; scanf( %d%s , &n, ch); ans[0] = 1; for (int i = 1; i < n; i++) { if (ch[i - 1] == = ) ans[i] = ans[i - 1]; else if (ch[i - 1] == L ) { ans[i] = 1; ...
#include <bits/stdc++.h> using namespace std; void printAll(int n, ...) { if (1) { va_list ap; va_start(ap, n); for (int i = 1; i <= n; i++) cout << va_arg(ap, long long int) << ; cout << endl; va_end(ap); } } template <typename T> string toString(T n) { stringstre...
#include <bits/stdc++.h> using namespace std; int dp[100000]; int main() { int n, a, b, c; cin >> n >> a >> b >> c; dp[a] = dp[b] = dp[c] = 1; int x = min(a, min(b, c)); for (int i = x; i <= n; i++) { if (i - a >= 0 && dp[i - a] > 0) dp[i] = max(dp[i], dp[i - a] + 1); if (i - b >= ...
#include <bits/stdc++.h> using namespace std; int L[100007], R[100007]; int n; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d%d , L + i, R + i); } sort(L + 1, L + n + 1); sort(R + 1, R + n + 1); long long ans = 0; for (int i = 1; i <= n; i++) { ans...
#include <bits/stdc++.h> using namespace std; int ball[100005]; int main() { int n, m; cin >> n >> m; if (m % 2) { int basket = m / 2; while (n--) { cout << basket + 1 << n ; basket = m - basket - 1; if (basket <= m / 2) basket--; if (basket < 0) basket = ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int N = 1000 + 10; int n, l, k; double dp[202][202][404]; double pro[300]; int a[N]; double solve(int i, int sofar, int cap) { if (i == n + 1) { return sofar >= l && cap >= 0; } double &ret = dp[i][sofar][c...
#include <bits/stdc++.h> using namespace std; using namespace std; const int N = 3030; const int INF = (int)2e9; int n, m; int len[N]; int f[N][N]; vector<int> g[N]; vector<int> gr[N]; vector<pair<int, int> > have[N]; vector<pair<int, int> > gave[N]; queue<int> q; void bfs(int v) { for (in...
#include <bits/stdc++.h> using namespace std; template <typename T> void printvec(vector<T>& vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << ; } cout << n ; } vector<vector<int> > adj; vector<int> comp; vector<vector<int> > memb, arr; vector<vector<long long> > cum...
#include <bits/stdc++.h> using namespace std; int v[100009]; map<double, bool> mb; int main() { long long n, k, i, j, l, cnt = 0; cin >> n >> k; for (i = 0; i < n; i++) { cin >> v[i]; } sort(v, v + n); for (i = 0; i < n; i++) { double val = (double)(v[i] / (double)k); i...
#include <bits/stdc++.h> using namespace std; int const siz = 1e9, bound = 7e5, mod = siz + 9; long long const oo = 1e18; int aa[bound]; int main() { int n, k; scanf( %d , &n), scanf( %d , &k); for (int(i) = 0; (i) < (n); (i)++) scanf( %d , &aa[i]); int l = 0, r = n, mid, rob; while (l <= ...