func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10; vector<pair<string, int> > ch[MAXN]; int nxt[MAXN][27], n, gp, ans; string t; void adds(string &tmp) { for (int i = 0; i < tmp.size(); i++) { gp = nxt[gp][tmp[i] - a ]; if (gp == t.size()) ans++; } } void dfs(i...
#include <bits/stdc++.h> using namespace std; template <typename T> void gmin(T &a, T b) { a = a < b ? a : b; } template <typename T> void gmax(T &a, T b) { a = a > b ? a : b; } const int MAXV = 410; const int MAXE = 1650; const int INF = 0x3f3f3f3f; struct Edge { int to, cap, nxt, cos...
#include <bits/stdc++.h> const int N = 810; const int M = 10; int mod[N][M]; int ans[N], inv[N], a[N]; int n; void print() { if (ans[1] > n / 2) { for (int i = 1; i <= n; ++i) { ans[i] = n + 1 - ans[i]; } } printf( ! ); for (int i = 1; i <= n; ++i) { printf( %d , a...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { string s; cin >> s; long long int x = 0, y = 0, p, q, sum = 0; set<pair<int, int> > ma; for (long long int i = 0; i < s.size(); i++) { p = x; q = y; i...
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e6 + 100; const long long maxM = 1e3 + 100; const long long mod = 1e9 + 7; const long long hmod = 1e16 + 7; const long double PI = 3.141592653; const long double eps = 1e-8; const long long D = 1379; const long long INF = 1e18 + 20;...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, x; cin >> t; for (int i = 0; i < t; i++) { cin >> n >> x; cout << 2 * x << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; double prb[(1 << 21)], p[25], ans[25]; int vis[(1 << 21)]; bool eq(double a, double b) { return (abs(a - b) < 1e-12); } int main() { int i, n, k, tmp; scanf( %d , &n); scanf( %d , &k); tmp = n; for (i = 0; i < n; i++) { scanf( %lf , &p[i]...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 100; vector<int> v[MAX_N]; int dp[MAX_N], ans, deep[MAX_N]; void dfs(int x, int fa, int dep) { int i; deep[x] = dep; for (i = 0; i < v[x].size(); i++) { int y = v[x][i]; if (y == fa) continue; dfs(y, x, dep + 1...
#include <bits/stdc++.h> using namespace std; int Count(int ar[], int m, int n) { int count = 0, i; for (i = 0; i < n; i++) { if (ar[i] == m) { count++; } } return count; } void change(int br[], int ar[], int n, int clr, int d, int m) { int count = 0, i; for (i = 0; i...
#include <bits/stdc++.h> using namespace std; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; string ans = ; int flag = 0; int res...
#include <bits/stdc++.h> int main() { int i, y, ans, z, b, x[2]; for (i = 0; i < 2; i++) { scanf( %d , &x[i]); } y = x[0] * x[1]; ans = y / 2; { printf( %d , ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const int NUM = 2e5 + 10; struct node { int index, q; bool operator<(const node &a) const { return index + q < a.index + a.q; } } no[NUM]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d%d , &no[i].index, &no[i].q); ...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; const long double PI = acos(-1.0); const int MX = 1e5 + 5; long long mod = 1e9 + 7; pair<long long, int> tr[5 * MX]; long long lz[5 * MX]; vector<int> ids[MX]; int rnum[MX]; inline void prop(int n, int l, int r) { if (lz...
#include <bits/stdc++.h> using namespace std; long long arr[105], k; int n; bool check(long long x) { long long sum = 0; for (int i = 0; i < n; i++) { sum += (arr[i] + x - 1LL) / x; } return x * sum <= k; } int main(int argc, char const *argv[]) { cin >> n >> k; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; int main() { int cnt, n; cin >> n; cnt = 0; cnt += n / 100; n %= 100; cnt += n / 20; n %= 20; cnt += n / 10; n %= 10; cnt += n / 5; n %= 5; cnt += n; cout << cnt << endl; return 0; }
#include <bits/stdc++.h> int Cmp(const void *a, const void *b); int main(void) { int i, n, x, w, gpos = -2 * 1000000000, ans = 0, grange[200000][2]; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d%d , &x, &w); grange[i][0] = x - w; grange[i][1] = x + w; } qsort(grange, n, ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); map<int, int> cur; set<pair<int, int>> st; for (int i = 0; i < n; i++) { cin >> a...
#include <bits/stdc++.h> using namespace std; bool a[1000010]; int main() { memset(a, 0, sizeof(a)); int n, ans = 0; cin >> n; int f = 2; for (;;) { if (a[f] == 0) { for (int i = 2 * f; i <= 1000000; i = i + f) a[i] = 1; } f++; if (f == 1000000) break; } ...
#include <bits/stdc++.h> using namespace std; int Max = INT_MIN, Min = INT_MAX; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n, m, mx = 0; cin >> n >> m; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) { ...
#include <bits/stdc++.h> using namespace std; int a, b, c, n, i, j, z, mx; string s, s2; int main() { cin >> a >> b >> c; mx = max(max(a, b), c); for (i = 1; i <= mx; i++) { for (j = 1; j <= mx; j++) { z = c / j; if (i * j == a && i * z == b && j * z == c) { cout << i...
#include <bits/stdc++.h> using namespace std; int n, ways[5050][5050], last[27], fat[5050], ifat[5050]; char s[5050]; int expo(int b, int e) { if (!e) return 1; if (e & 1) return 1LL * b * expo(1LL * b * b % 1000000007, e >> 1) % 1000000007; return expo(1LL * b * b % 1000000007, e >> 1); } ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, t; cin >> t; while (t--) { cin >> n; if (n % 2 == 0) cout << n / 2 << n ; else cout << (n / 2) + 1 << n ; } }
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e6; long long seg_t[MAXN * 4]; long long n, k, cur, ans = 1; void add(long long u, long long curl, long long curr, long long l, long long r, long long delta) { long long curm = (curl + curr) / 2; if (l == curl && r == cur...
#include <bits/stdc++.h> using namespace std; const int N = 100; int ara[N]; int main() { int n = 0; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d , ara + i); } if (n == 1) puts( -1 ); else if (n == 2 && ara[0] == ara[1]) puts( -1 ); else { int mn =...
#include <bits/stdc++.h> using namespace std; #define int long long struct node{ int x, y, id; bool operator <(const node& W) const{ if (W.x != x) return x < W.x; else return y < W.y; } }; void work() { int n; cin >> n; vector<node> v(n); for (int i = 0; i < n; i++) { int x...
#include <bits/stdc++.h> using namespace std; vector<long long int> sieve; vector<long long int> *Sieve(int N) { const long long int maxn = N; sieve.resize(maxn); for (long long int(i) = 0; (i) < (maxn); ++(i)) sieve[i] = 1; sieve[1] = 0; sieve[0] = 0; for (long long int(i) = 2; (i) <= (ma...
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { int t; cin>>t; while(t--) { ll n; cin>>n; vector<ll>a(n); for(ll i=0;i<n;i++) { cin>>a[i]; } ll maxi=INT_MIN; ...
#include <bits/stdc++.h> using namespace std; class subtractions { private: int _a, _b; int _operations; bool even_divide(int& a, int& b) { if (b > a && !(b % a)) { _operations += (b / a); return true; } else if (a >= b && !(a % b)) { _operations += (a / b); ...
#include <bits/stdc++.h> using namespace std; int n; string s; long long w[3][300500]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0, qwerty = n; i < qwerty; i++) { cin >> s; stack<char> st; st.push(s[0]); for (int j = ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, t; cin >> t; while (t--) { cin >> a >> b; int num = abs(a - b); if (a > b && num % 2 != 0) cout << 2 << endl; else if (a < b && num % 2 != 0) cout << 1 << endl; else if (a > b && num % 2 ==...
#include <bits/stdc++.h> using namespace std; struct DSU { struct Node { int pr; long long max_sum; long long max_pref; long long sum; long long max_suff; }; vector<Node> t; multiset<long long> mx; DSU(int n, vector<int>& c) { t.resize(n); for (int i = 0...
#include <bits/stdc++.h> int main(int argc, char *argv[]) { int n; scanf( %d , &n); int i; if (n % 2 != 0) { printf( -1 n ); } else { if (n > 2) { for (i = 1; i <= n - 2; i++) { printf( %d , i + 1); printf( %d , i); i++; } } p...
#include <bits/stdc++.h> using namespace std; long long n, x, a[200005], b[200005]; int main() { cin >> n; for (int i = 1; i <= n / 2; i++) cin >> b[i]; a[1] = 0; a[n] = b[1]; for (int i = 2; i <= n / 2; i++) { a[i] = a[i - 1]; a[n - i + 1] = b[i] - a[i]; if (a[n - i + 1] > a...
#include <bits/stdc++.h> using namespace std; long long int i, j, ft; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int n; cin >> n; vector<long long int> v[n]; for (i = 0; i < (n - 1); i++) { long long int b, c; cin >> b >> c; v[b - 1].push_back(c - 1)...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2) cout << contest ; else cout << home ; return 0; }
#include <bits/stdc++.h> using namespace std; #define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define TEST ll Test ; cin >> Test; while #define TEST2 int Test = 1; while #define READ freopen( input.txt , r , stdin); freopen( output.txt , w ,...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long fac[300011], inv[300011]; int F, W, H; long long fastpower(long long v, long long p) { long long ret = 1; while (p > 0) { if (p % 2 == 1) { ret = ret * v; ret %= mod; p--; } el...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int m, p, l, q = 0, r, t = 0; long long int n, k = 0, i, j = 0; string s; getline(cin, s); j = 0; for (i = 0; i < s.size(); i++) { if (s[i] == a || s[i] == e...
#include <bits/stdc++.h> using namespace std; set<int> smax, smin; int ox[100000], oy[100000]; map<pair<int, int>, int> pnts; inline int eval(int x, int y) { if (pnts.count({x, y})) { return pnts.count({x, y - 1}) + pnts.count({x - 1, y - 1}) + pnts.count({x + 1, y - 1}); } retu...
#include <bits/stdc++.h> using LL = int64_t; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector<int> a(n); for (int &i : a) std::cin >> i; std::sort(a.begin(), a.end()); int maxa = a.back(); std::vector<std::vector<int>> mx(max...
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<int>; using PII = pair<int, int>; const int N = 1005, INF = 1e9; vector<PII> adj[N]; int dis[N][N]; int main() { int n, m, k; cin >> n >> m >> k; vector<tuple<int, int, int>> edges; for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; inline int read() { register int x = 0, f = 1, ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x * f; } int n; int a[1010]; int b[10...
#include <bits/stdc++.h> using namespace std; int main() { string x; cin >> x; int xx = 0; int ans = 0; for (int i = 0; i < x.size(); i++) { if (x[i] == ( ) xx++; else if (xx) xx--, ans++; } cout << ans * 2; }
#include <bits/stdc++.h> using namespace std; int f[201000], l[201000], r[201000]; int n; int a[201000], s[201000]; int top; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; top = 0; s[top] = 0; a[0] = 0; for (int i = 1; i <= n; i++) { while (a[s[top]] >= a[i]) ...
#include <bits/stdc++.h> using namespace std; int64_t dfs(int64_t idx, int64_t p, vector<vector<int64_t>>& g, vector<int64_t>& parents, int64_t& c1, int64_t& c2) { int64_t n = g.size() - 1; parents[idx] = p; int64_t res = 1; int64_t mx = 0; for (auto& x : g[idx]) { if (x != p...
#include <bits/stdc++.h> #define int long long #define INF (1e15 + 7) #define pii pair<int, int> using namespace std; struct Node { int x, y; Node(int _x = 0, int _y = 0) : x(_x), y(_y) {} bool operator<(const Node &u)const { if (x < u.x) return true; if (x > u.x) r...
#include <bits/stdc++.h> using namespace std; double dp[2][605]; int main() { int n, k; scanf( %d%d , &n, &k); int pre = 0, cur = 1; for (int i = 0; i < n; ++i) { memset(dp[cur], 0, sizeof dp[cur]); for (int j = 1; j < 600; ++j) dp[cur][j] += (1. * j / k / (j + 1) + (k - 1.) / ...
#include <bits/stdc++.h> using namespace std; long long tree[1000001]; int n; void update(int x, long long val) { for (int i = x; i <= n; i += i & (-i)) { tree[i] += val; } } long long query(int x) { long long sum = 0; while (x > 0) { sum += tree[x]; x -= x & (-x); } ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long my_pow(long long a, long long n) { long long res = 1; while (n) { if (n & 1) res *= a; a *= a; n >>= 1; } return res; } const int mn = 10010; vector<int> v[mn]; vector<int> s(mn, 0); voi...
#include <bits/stdc++.h> const int N = 100010; const int M = 30; std::map<std::string, int> Hash; int fa[N << 1], n, m, q; char s[M]; int find(int u) { return fa[u] == u ? u : fa[u] = find(fa[u]); } void unite(int u, int v) { int _u = find(u), _v = find(v); fa[_u] = _v; find(u); } int main...
#include <bits/stdc++.h> using namespace std; int bst(int a[], int lw, int hi, int n) { int mid = (lw + hi) / 2; if (lw > hi) return -1; if (a[mid] > n) bst(a, lw, mid - 1, n); else if (a[mid] < n) bst(a, mid + 1, hi, n); else return mid; } long long pw(long long a, long lo...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e6; long long n, K, d, a[200010]; map<long long, long long> mp; struct trnode { long long lc, rc, c, u; } tr[400010]; long long tot = 0; void pushdown(long long x) { long long lc = tr[x].lc, rc = tr[x].rc, c = tr[x].u; tr[x...
#include <bits/stdc++.h> using namespace std; template <class T> void read(T& x) { x = 0; T f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) f = (ch == - ? -1 : 1), ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 48, ch = getchar(); x *= f; } template <class ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; constexpr int MAXN = 1003; constexpr int MAXC = 10004; int n; ll w, b, x; int c[MAXN]; ll cost[MAXN]; ll dp[MAXN][MAXC]; int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k; int nums[1005]; cin >> t; while (t--) { cin >> n >> k; for (int i = 0; i < n; i++) cin >> nums[i]; sort(nums, nums + n); int sum = 0; for (int i = 1; i < n; i++) sum += (k - nums[i]) / nums[0]; ...
#include <bits/stdc++.h> using namespace std; int n, m, u, v, num_col = 1; vector<int> adjList[5001]; vector<int> edges[5001]; bitset<5001> vis; bitset<5001> act; bitset<5001> col; void dfs(int nd) { vis[nd] = 1; act[nd] = 1; for (int k = 0; k < adjList[nd].size(); k++) { int nd_b = ad...
#include <bits/stdc++.h> using namespace std; char s[100005]; int main() { int n; while (cin >> n) { scanf( %s , s); int ct = 1, n = strlen(s); bool ok = false; int cant = 0, ans = 0; for (int i = 1; i < n; i++) { if (s[i] == s[i - 1]) ct++; else { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int width; int height; cin >> height; cin >> width; char art[height][width]; for (int i = 0; i < height; i++) { for (int k = 0; k < width; k++) { cin >> art[i][k]; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m = 0; cin >> n; while (n--) { int x, y; cin >> x >> y; m = max(m, x + y); } cout << m; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = signed long long int; const int MX = 7000 + 10, INF = 3e5, A = 100; ll res; pair<ll, ll> ab[MX]; int n; map<ll, pair<int, ll>> m; vector<ll> v; bool ad; int main() { ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(null...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, x, res = 0, c = 0; cin >> n >> a >> b; for (int i = 0; i < n; i++) { cin >> x; if (x == 1) { if (a > 0) a--; else if (b > 0) { c++; b--; } else if (c > 0) c...
#include <bits/stdc++.h> using namespace std; int T[27], A[27][27], P[27], use; long long Q[1 << 22]; int main() { int n, k, t; cin >> n >> k >> t; string S; cin >> S; S = + S; for (int i = 1; i <= k; ++i) cin >> T[i]; for (int i = 1; i <= k; ++i) for (int j = 1; j <= k; ++...
#include <bits/stdc++.h> using namespace std; long long h[100000]; long long x[100000]; int g[31] = {0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12}; bool mark[100000]; map<int, int> gg; int grundy(int mask) { int nmask; int used[40]; ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; const long long inf = 199999999999999999; const long long mod = 1e9 + 7; void read() { freopen( lifeguards.in , r , stdin); freopen( lifeguards.out , w , stdout); } void solve() { int coloured[N] = {}, pp[N] = {}, mx ...
#include <bits/stdc++.h> using namespace std; int A[10], B[10]; bool Check(int j) { memset(B, 0, sizeof(B)); while (j) { B[j % 10]++; j /= 10; } for (int i = 0; i <= 9; i++) if (A[i] && B[i]) return true; return false; } int main() { int res = 0, x, _x; cin >> x; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 5, NMAX = 2e5 + 5, MOD = 998244353, N = 1e9 + 5, LOG = 25; const long double EPS = 1e-8, pi = 3.14159265358979323846; vector<long long> res; bool first(long long k, vector<long long> &v) { long long index = k; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, s, a, b, c, d, sum, ss; cin >> n >> m >> s; sum = 0; for (a = 1; a <= n && a <= s; a += 2) for (b = 1; b <= m && a * b <= s; b += 2) { if (a * b == s) { sum += (n - a + 1) * (m - b + 1) *...
#include <bits/stdc++.h> using namespace std; int n; string s; vector<int> v; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> s; s = * + s; for (int i = 1; i * i <= n; i++) if (n % i == 0) { v.push_back(i); if (i != n / i) v.p...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; bool used[123456]; bool cmp(const vector<int>& a, const vector<int>& b) { return a.size() < b.size(); } int main() { int n; cin >> n; vector<int> p(n + 1); for (int i = 1; i <= n; ++i) cin >> p[i]; vector...
#include <bits/stdc++.h> using namespace std; using Vi = vector<int>; using i64 = long long; using ll = long long; using Pi = pair<int, int>; mt19937 mrand(time(0)); int rnd(int x) { return mrand() % x; } const int N = 500005; const int M = 40005; int main() { ios::sync_with_stdio(false); ci...
#include <bits/stdc++.h> using namespace std; const int maxN = 100 * 1000 + 5; struct Node { int s, e, maxx; }; struct Segment { Node node[4 * maxN]; void build(int s, int e, int v = 1) { node[v].s = s; node[v].e = e; node[v].maxx = -1; if (e - s <= 1) return; int mid...
#include <bits/stdc++.h> static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; static const long double epsilon = 1e-15; static const long double pi = acos((long double)-1); using namespace std; inline void init_io() { ios_base::sync_with_stdio(false); cin.tie(NULL);...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; pair<long long, long long> p[maxn]; long long ans[maxn]; int main() { int n, num = 0, cnt = 0; long long l, r; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %lld%lld , &l, &r); p[++num].first = l; ...
#include <bits/stdc++.h> using namespace std; int n, m, f, vis[101][101][101]; char a[1001][1001]; int valid(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m); } int occupies(int x, int y, int turn) { y = y + (turn - 1) * 2; if (valid(x, y) && a[x][y] >= A && a[x][y] <= Z ) return 1; ...
#include <bits/stdc++.h> using namespace std; int n, k, a, b, q; int Size; int getMid(int s, int e) { return s + (e - s) / 2; } int getSumUtil(int *st, int ss, int se, int qs, int qe, int si) { if (qs <= ss && qe >= se) return st[si]; if (se < qs || ss > qe) return 0; int mid = getMid(ss, se); ...
#include <bits/stdc++.h> using namespace std; int n; double p[3005][305], f[305][3005], d[305]; inline int read() { int re = 0; char ch = getchar(); while (ch < 48 || ch > 57) ch = getchar(); while (ch > 47 && ch < 58) { re = (re << 3) + (re << 1) + (ch ^ 48); ch = getchar(); } ...
#include <bits/stdc++.h> using namespace std; const int N = 15000000, M = 5005; int dp[N], n, k, a[M]; set<int> s[23]; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d , a + i); s[0].insert(0); for (int i = 1; i <= k; i++) for (int j = 1; j <= n; j++) s[i].inser...
#include <bits/stdc++.h> using namespace std; int main() { int a[60], i, x, n, k; cin >> n >> k; for (i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); if ((n + 1 - k) >= 1) cout << a[n + 1 - k] << << a[n + 1 - k]; else cout << -1 ; }
#include <bits/stdc++.h> using namespace std; int main() { float n, k, y, s, per; cin >> n >> k >> y; per = (n * y) / 100; s = per - (int)per; if (s != 0) per = (int)per + 1; if ((per - k) > 0) { cout << per - k; } else { cout << 0 ; } }
#include <bits/stdc++.h> using namespace std; string s; int a[10005], f[10005][4], q[28000], h2[10005], h3[10005], n; int main() { ios::sync_with_stdio(0); cin >> s; n = s.size(); for (int i = 1; i <= n; i++) a[i] = s[i - 1] - a + 1; for (int i = 6; i <= n; i++) h2[i] = a[i] * 900 + ...
#include <bits/stdc++.h> using namespace std; long long a[200000 + 1]; int main() { long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); sort(a + 1, a + n + 1); long long mpos = 0, ppos = 0; for (int ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; struct node { int x, y; } f[2 * N]; int n, pos, vt[N], a[N], b[N], dd[N]; vector<pair<int, int> > vec; bool check(int x) { if (x == 0) return 0; while (x) { if (x % 10 != 7 && x % 10 != 4) return 0; x /= 10; ...
#include <bits/stdc++.h> using namespace std; int A[100010], D[100010], n; set<int> edge[100010]; vector<int> ans; void bfs() { int i, u; memset(A, 0, sizeof(A)); queue<int> que; ans.clear(); for (i = 1; i <= n; i++) { if (D[i] == A[i]) { que.push(i); } } set<in...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int INF = 1e9; using ll = long long; using ull = unsigned long long; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using vc = vector<char>; using vii = vector<vi>; using vll = vector<vl>; using...
#include <bits/stdc++.h> using namespace std; template <class A, class B> inline bool mina(A &first, B second) { return (first > second) ? (first = second, 1) : 0; } template <class A, class B> inline bool maxa(A &first, B second) { return (first < second) ? (first = second, 1) : 0; } int mod_co...
#include <bits/stdc++.h> using namespace std; int N, M, P[100005], R = 1, a, b; int findSet(int x) { if (P[x] == x) return x; else return (P[x] = findSet(P[x])); } void merge(int a, int b) { P[findSet(a)] = findSet(b); } int main() { scanf( %d%d , &N, &M); for (int i = 1; i <= N;...
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; }; const int N = 1000010; int n; long long a[N]; Point st[N]; int tp; bool cmp(long long x1, long long y1, long long x2, long long y2) { return x2 * y1 <= x1 * y2; } int main() { scanf( %d , &n); for (int ...
#include <bits/stdc++.h> using namespace std; int path[26][26]; char s[100001], t[100001]; void Floyd_Warshall(int n) { int i, j, k; for (k = 0; k < n; k++) { for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (path[i][k] + path[k][j] < path[i][j]) { path[i][j] = ...
#include <bits/stdc++.h> using namespace std; int n, a[1005][1005], q, opr, xi; int row_sum[1005], col_sum[1005], total_row_add, total_col_add; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf( %d , &a[i][j]); for (int i = 0; i < n; i++) for (in...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); map<int, vector<int>> indices; for (int i = 0; i < n; i++) cin >> a[i], indices[a[i]].push_back(i); map<int, int> dp; int mxn = 0, ans = -1; for (int i = n - 1; i >= 0; i--) { dp[a[i]]...
#include <bits/stdc++.h> using namespace std; const int MAXN = 610; int n; int anc[MAXN], depth[MAXN]; bool mark[MAXN]; vector<int> adj[MAXN]; vector<int> partitions[2]; map<vector<int>, int> ans; queue<int> q; int qtdEdges(vector<int> a) { if (a.empty()) return 0; sort(a.begin(), a.end()); ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { int a, b, n, krok = 0; cin >> a >> b >> n; bool podm = false; int g; while (n > 0) { if (krok % 2 == 0) { g = gcd(a, n); ...
#include <bits/stdc++.h> using namespace std; int main() { int cnt = 0; int a; string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == 4 || s[i] == 7 ) { cnt++; } } if (cnt == 4 || cnt == 7) { cout << YES ; } else { cout << NO ; ...
#include <bits/stdc++.h> using namespace std; int minFact[1000000 + 5]; vector<int> prime; int rec(int N, int K) { int ans = 0; if (N / K <= 10000) { ans = 0; for (int i = 1; i <= N / K; ++i) { ans += (minFact[i] >= K); } } else { ans = N / K; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; inline long long sum(long long x) { x %= 1000000007; return (1LL * x * (x + 1) / 2) % 1000000007; } int main() { long long n, m; ios::sync_with_stdio(false); cin >> n >> m; long long ans = ((n % 1000000007) * (m % 1000000007)) % 1000000007; ...
#include <bits/stdc++.h> using namespace std; int n, m; char grid[55][55]; char vis[55][55]; int di[] = {0, 1, -1, 0}; int dj[] = {1, 0, 0, -1}; bool dfs(int pi, int pj, char c, int li = -1, int lj = -1) { if (vis[pi][pj]) return true; vis[pi][pj] = true; for (int d = 0; d < 4; d++) { in...
#include <bits/stdc++.h> using namespace std; bool gt(long double a, long double b) { return a > b + 1e-12; } long long a, b, x; int main() { int n; cin >> n; while (n--) { string s; cin >> s; if (s == UR || s == DL ) a++; else if (s == UL || s == DR ) b...
#include <bits/stdc++.h> using namespace std; int main() { long a, b; cin >> a >> b; long i = 1; while (a >= 0 && b >= 0) { a -= i; if (a < 0) { cout << Vladik n ; return 0; } b -= i + 1; if (b < 0) { cout << Valera n ; return 0; ...
#include <bits/stdc++.h> using namespace std; int n, a, b, c; char str[2000000 + 5]; vector<int> G[10000 + 5]; vector<int> per[10000 + 5]; int siz[10000 + 5], dfn[10000 + 5], low[10000 + 5], dcnt; int blo[10000 + 5], bgcd[10000 + 5], blocnt; int stk[10000 + 5], t; int num[10000 + 5], mx[10000 + 5], mn...
#include <bits/stdc++.h> using namespace std; int a[200000 + 5], b[10][200000 + 5]; int main() { int n, i; cin >> n; char c; c = getchar(); for (i = 1; i <= n; i++) { c = getchar(); if (c == R ) a[i] = 1; if (c == G ) a[i] = 2; if (c == B ) a[i] = 3; } b[1][1...