func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long int a[1001]; map<long long int, int> used; int ans = 0; map<pair<long long int, long long int>, bool> us; void rec(long long int x, long long int y, int kol) { ans = max(ans, kol); long long int z = x + y; if (z > 1000000000 || z < -1000000...
#include <bits/stdc++.h> long long int M = 1000000007; using namespace std; vector<int> cnt(1e6 + 1); void SieveOfEratosthenes(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) ...
#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 = 1e6 + 107; const double pi = acos(-1.0); const double eps = 0.0000000001; long long gcd(long long a, long long b) { return b ? gcd(b,...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, m, n, boys[105], girls[105]; while (cin >> n >> m) { memset(boys, 0, sizeof(boys)); memset(girls, 0, sizeof(girls)); cin >> k; while (k--) { cin >> j; boys[j] = 1; } cin >> k; wh...
#include <bits/stdc++.h> using namespace std; const int MN = 1e5 + 5; int T, N, arr[MN]; void solve() { scanf( %d , &N); for (int i = 0; i < N; i++) scanf( %d , arr + i); sort(arr, arr + N); printf( %d n , min(min(arr[N - 1], arr[N - 2]) - 1, N - 2)); } int main() { scanf( %d , &T); ...
#include <bits/stdc++.h> using namespace std; const int N = 1210, inf = 0x3f3f3f3f; int n, m, k, x, y, rd[N], s, t, cnt = 1, head[N], stk[N], col[N], tot, sum, vis[N]; struct edge { int to, nxt, c; } e[N * 10]; void Adde(int x, int y, int c) { e[++cnt].to = y; e...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; vector<int> g[maxn + 1]; int father[maxn + 1], a[maxn + 1]; int f[maxn + 1], fup[maxn + 1]; int n, K; int result; int ge[maxn + 1], upge[maxn + 1]; int MIN; void init() { int i, x, y; scanf( %d%d , &n, &K); for (i = 1...
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383; struct Rcompare { bool operator()(pair<int, int> lhs, pair<int, int> rhs) { return lhs.first > rhs.first; } }; struct compare { bool operator()(pair<int, int> lhs, pair<int, int> rhs) { ...
#include <bits/stdc++.h> using namespace std; long long int arr[100005]; int main() { long long int n, a, b, x, val, pos; cin >> n >> a >> b; for (long long int i = 0; i < n; i++) { cin >> x; long long int val = x * a; long long int t = val / b; long long int tb = t * b; ...
#include <bits/stdc++.h> using namespace std; const int mod = 99999997; const int mmax = 200010; const double eps = 1e-8; const double pi = acos(-1.0); const int inf = 0x3fffffff; int a[200010], b[200010]; int main() { int n, m, sa, sb; int cnt1, cnt2, df; while (cin >> n) { for (int i...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int lo = 0, hi = m; while (lo < hi) { int mid...
#include <bits/stdc++.h> using namespace std; long long int sieve[1000003 + 5]; long long int num_primes[1000005] = {0}; void calc_sieve() { for (long long int i = 0; i <= 1000003; i++) sieve[i] = 0; sieve[0] = sieve[1] = 1; for (long long int i = 2; i <= 1000003; i++) { num_primes[i] = num_pr...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int n1 = n; int k1; int k[n + 1]; int pri[n + 1]; for (int i = 1; i <= n; i++) { k[i] ...
#include <bits/stdc++.h> using namespace std; char buf[25]; const int maxn = 1000010; int a[maxn * 2], b[maxn * 2]; int n, m, x, y, t, mx; int read() { int x = 0, f = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = 1; ch = getchar(); } while (ch >= ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[n], i, j, k, cnt = 1e9, tmp = 0; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < s.size() - 1; i++) { if (s[i] == R && s[i + 1] == L ) { tmp = (a[i + 1] - a[i]) / 2...
#include <bits/stdc++.h> using namespace std; int n, m, q; const int max_w = 100; vector<pair<int, int>> cnt_sort(vector<pair<int, int>>& a) { vector<int> cnt(n * max_w + 5); for (int i = 0; i < a.size(); ++i) { ++cnt[a[i].first + 1]; } for (int i = 1; i < cnt.size(); ++i) { cnt[i] +...
#include <bits/stdc++.h> using namespace std; int p[1000006], n, k; int main() { ios::sync_with_stdio(false); cin >> n >> k; iota(p + 1, p + n + 1, 1); for (int i = 2; i <= n; i++) { if (p[i] == i) { p[i]--; for (int j = i + i; j <= n; j += i) p[j] = p[j] / i * (i - 1); ...
#include <bits/stdc++.h> using namespace std; struct Query { int id, left, right, time, blockLeft, blockRight; Query() : id(-1), left(-1), right(-1), time(-1), blockLeft(-1), blockRight(-1) {} Query(int id, int left, int right, int time, int blockLeft, int blockRight) : id(id), ...
#include <bits/stdc++.h> const int N = 200005; const int M = 500005; using namespace std; pair<int, int> a[N]; int p[20][M]; int main() { int n, m; scanf( %d%d , &n, &m); int i, j; for (i = 0; i < n; i++) { scanf( %d%d , &a[i].first, &a[i].second); } sort(a, a + n); memset(...
#include <bits/stdc++.h> using namespace std; int n, m, t; int main() { cin >> t; while (t--) { int s = 0, a; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a; s += 2 * a; } if (m < n || n < 3) { cout << -1 << endl; continue; } ...
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(0); solve(); return 0; } list<pair<deque<int>, int> > basket; int N, bN; int p[100001]; void update(pair<deque<int>, int>& it) { it.second = it.first[0]; for (int i = 0; i < (int)((it.first)...
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; const int maxm = maxn * 2; const int maxe = 200005; const int mod = 1e9 + 7; int n, a, b; string str; int cc[26][maxn][26]; int exist[26]; int main() { cin >> str; n = str.length(); for (int i = 0; i < n; i++) { i...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; scanf( %lld%lld%lld , &n, &m, &k); if (n % 2 == 0) { printf( Marsel n ); return 0; } if (n % 2 == 1) { if (k == 1 && m > 1) { printf( Timur n ); return 0; } for (long long ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:33554432 ) int N, Q, cnt[3][100005]; char A[100005]; int main() { int i, j, k; scanf( %s , A + 1); N = strlen(A + 1); for (i = 1; i <= N; i++) { for (j = 0; j < 3; j++) cnt[j][i] += cnt[j][i - 1]; cnt[A[i...
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, k, it, t; long long r[101], rr[101], c[101], cc[101]; long long a[101][101]; long long R, C, x; vector<long long> ans, ans2; int main() { cin >> n >> m; int k = 1; x = 3; while (n != 0) { if (n % 2 == 1) { k ...
#include <bits/stdc++.h> using namespace std; double pi = 3.1415926536; int main() { int n; cin >> n; int r[n]; for (int i = 0; i < n; i++) cin >> r[i]; double area = 0; sort(r, r + n); for (int i = n - 1; i >= 0; i -= 2) { if (i > 0) area += (r[i] * r[i] - r[i - 1] * r[i...
#include <bits/stdc++.h> const bool DEBUG = false; using namespace std; const long long maxn = 1e5 + 2; const long long INF = 4e18; const long long M = 1e9 + 7; const int lg = 21; const int z = 256 * 256; int n, m, a[maxn], t[maxn], dp[maxn]; string s; vector<int> g[2], v[2]; bool f(vector<int>(&v...
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); } const long long inf = 0x7f7f7f7f; const long long mod = 1e9 + 7; double pi = acos(-1.0); long long a[120]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9, maxn = 5e5 + 5, mod = 1e9 + 7; long long x[maxn], y[maxn], sz[maxn], n, m; set<long long> S; unordered_map<long long, long long> cnt, id; vector<long long> son[maxn]; long long gc(long long x) { long long ret = 0, j = 0; whil...
#include <bits/stdc++.h> int main() { int n, a, b, c = 0; scanf( %d , &n); while (n--) { scanf( %d , &a); c += a != b; b = a; } printf( %d , c); }
#include <bits/stdc++.h> using namespace std; int main() { int x = 0; int n; string ch; cin >> n; for (int i = 0; i < n; i++) { cin >> ch; { if (ch[1] == + ) x++; if (ch[1] == - ) x--; } } cout << x << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 100; pair<int, int> khar[maxn]; bool mk[10 * maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; mk[a] = true; khar[i] = pair<int, int>(a, b); } sort(khar...
#include <bits/stdc++.h> using namespace std; int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; class SorT { public: bool operator()(pair<int, int>& p1, pair<int, int>& p2) { return p1.second < p2.second; ...
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; void solve() { long long int n; cin >> n; long long int a[n]; long long int hi = 0; for (long long int i = 0; i < n; ++i) { cin >> a[i]; hi += a[i]; } sort(a, a + n); long long int ans = hi - n; ...
#include <bits/stdc++.h> using namespace std; long long n, x, y; long long bs1(long long l, long long r, long long num) { long long mid = (l + r) / 2; if (r - l <= 0) { return -1; } long long time = mid * x; long long highnow = mid + ((mid * x + x - 1) / y); long long lownow = mid + ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; const int mod = 1e9 + 7; int v[200005]; int n, k; bool guess(int x) { ll spent = x - v[n / 2]; for (int i = n / 2 + 1; i < n; i++) { spent += max(0, x - v[i]); if (spent > (ll)k) return false...
#include <bits/stdc++.h> using namespace std; const int N = 500010; const int MOD = 1000000007; int n, m, q; char s[14]; int f[(1 << 12) + 10][(1 << 12) + 10], w[13], freq[(1 << 12) + 10]; int v[(1 << 12) + 10][100 * 14]; int main() { cin >> n >> m >> q; for (int i = 0; i < n; ++i) { scanf...
#include <bits/stdc++.h> using namespace std; const int maxn = 100001; vector<pair<long long, int>> g[maxn]; vector<pair<long long, int>> _g[maxn]; int n, m, s, t; int u[maxn], v[maxn]; long long c[maxn]; void enter() { cin >> n >> m >> s >> t; for (int i = (0), _b = (m); i < _b; ++i) { ci...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100, LEN = 21, M = 1 << LEN, inF = N * 30; int n, len, ps[N], dp0[N], dp1[N], mini[M][LEN]; string s[N]; void _min(int &a, int b) { a = min(a, b); } int same(string a, string b) { int A = 0, B = 0, res = 0; for (int i = 0; i < len; i+...
#include <bits/stdc++.h> using namespace std; vector<vector<int64_t>> board, vis, diag1, diag2; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int64_t n; cin >> n; for (int64_t i = 0; i < n; i++) { vector<int64_t> temp; vector<int64_t> zero; for (int64_t j = 0; j < n...
#include <bits/stdc++.h> using namespace std; void boost() { ios_base::sync_with_stdio(false); cin.tie(NULL); } void free() { freopen( A.in , r , stdin); freopen( A.out , w , stdout); } int a[100001]; int main() { boost(); int n; cin >> n; for (int i = 0; i < n; i++) cin ...
#include <bits/stdc++.h> using namespace std; inline void read(long long &num) { num = 0; long long f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { num = num * 10 + c - 48; c = getchar(); } num *= f;...
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int l = 1, h, i, n, x, t, q, y = -1, z = 0, a = 0, b = 0, c = 0, k, sum = 0, m, d = 0, r, w, j, ans, s, mini = INT...
#include <bits/stdc++.h> #include<stdlib.h> using namespace std; #define pb push_back #define ll long long #define ff first #define ss second #define ppb pop_back #define mp make_pair #define vl vector<ll> #define vi vector<int> #define endl n #define all(x) x.begin(), x.end() #define deb(x...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long N = 1e5 + 5; map<long long, long long> freq, freq2; void func1(long long a[], long long n) { int i = 0, j = 0; while (i < n) { if (a[i] == 0) { i++; continue; } j = i; w...
#include <bits/stdc++.h> using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, x, b, y; cin >> n >> a >> x >> b >> y; while (a != x && b != y) { if (a == b) break; a = (a % n) + 1; if (b == 1) b = n; else b--; } if (a == b) cout << YES ; else ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } const int mod = 1e9 + 7; long long binpow(long long a, long long b) { long long res = 1; while (b > 0) if (b & 1) { ...
#include <bits/stdc++.h> template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } using namespace std; bool B[100], G[100]; int main() { int n, m; cin >> n >> m;...
#include <bits/stdc++.h> using namespace std; int n, m, lim; struct node { int to; int val; }; stack<int> ans; vector<node> g[5500]; int f[5500][5500]; int fa[5500][5500]; void dfs(int u, int dep) { for (int i = 0; i != g[u].size(); i++) { int& co = g[u][i].val; int& v = g[u][i...
#include <bits/stdc++.h> using namespace std; const long long LINF = 334ll << 53; const int INF = 15 << 26; const long long MOD = 1E9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, q; cin >> n >> q; vector<int> t(n), s(n), d(n); priority_queue<pair<int, int>, vector<...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; using ll = long long; using ld = long double; template <typename T> using mat = vector<vector<T> >; template <int mod> struct modint { int x; modint() : x(0) {} modint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % ...
#include <bits/stdc++.h> const int mod = 998244353; using namespace std; inline int read() { int f = 1, x = 0; char s = getchar(); while (!isdigit(s)) { if (s == - ) f = -1; s = getchar(); } while (isdigit(s)) { x = (x << 1) + (x << 3) + (s ^ 48), s = getchar(); } re...
#include <bits/stdc++.h> using namespace std; struct node { string name; int version; }; int main(void) { int n; cin >> n; map<pair<string, int>, vector<pair<string, int> > > m; pair<string, int> init; for (int i = 0; i < n; i++) { pair<string, int> cur; cin >> cur.first ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, l = -1, j, p, m; long k; cin >> n >> k; long long a[k]; for (long i = 0; i < k; i++) { cin >> a[i]; j = n / a[i]; if ((j * a[i]) > l) { l = j * a[i]; p = i + 1; m = j; } } ...
#include <bits/stdc++.h> using namespace std; template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (T& x : v) is >> x; return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; int n, m, ans, flag; bool vis[10]; string fac[7] = { 1869 , 1968 , 1689 , 6198 , 8691 , 8916 , 1896 }; string s, ss, anss, xx = 0000 ; int main() { int i, j, t, pos, x, y, u, v, w; while (cin...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int MN = 1 << 8; int exp(int x, int n) { int ret = 1; while (n) { if (n & 1) ret = 1LL * ret * x % mod; x = 1LL * x * x % mod; n >>= 1; } return ret; } int inv(int x) { return exp(x, mod - 2); } ...
#include <bits/stdc++.h> using namespace std; int zero(int n) { if (n == 0) return 0; if (n % 10 == 0) return zero(n / 10); return 10 * zero(n / 10) + (n % 10); } int main() { int a, b; cin >> a >> b; if (zero(a) + zero(b) == zero(a + b)) { cout << YES ; } else { cout <<...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template <class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } struct MaxFlow { struct edge { int to, cap, rev; }; ve...
#include <bits/stdc++.h> using namespace std; int main() { char a[15], b[15]; while (cin >> a >> b) { int len_a = strlen(a); sort(a, a + len_a); int k = 0; for (int i = 0; i < len_a; i++) { if (a[i] != 0 ) { k = i; break; } } char tmp;...
#include <bits/stdc++.h> const int oo = 0x3f3f3f3f, mod = 1e9 + 7; using namespace std; int dx[]{1, -1, 0, 0, 1, 1, -1, -1}; int dy[]{0, 0, 1, -1, 1, -1, 1, -1}; long long OO = (1LL * oo * oo); void K_K() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { K_K(); long ...
#include <bits/stdc++.h> using namespace std; int a, b, c; unsigned long ans = 0; unordered_map<int, int> um; void eval(int x) { int t = 0; for (int i = 1; i <= sqrt(x); ++i) { if (i * i == x) t += 1; else if (x % i == 0) t += 2; } ans += t; um[x] = t; } int...
#include <bits/stdc++.h> using namespace std; const int64_t M = 1000000007; const int64_t MM = 998244353; template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } int6...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; string s; int x; cin >> n >> m >> k; int a[n][m]; int b[n][m]; int c[n][m]; for (int i = 0; i < n; i++) { cin >> s; for (int j = 0; j < m; j++) { cin >> x; a[i][j] = x; cin >> ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; const int M = N * 3; const int inf = 1e9 + 7; const int base = 1e9 + 9; const double pi = acos(-1); const double ep = 1e-11; pair<pair<int, int>, int> p[N]; int n; int vp, vs; int sqr(int x) { return x * x; } double sqr(double ...
#include <bits/stdc++.h> using namespace std; const int N = 300010; int sufp[N], freq[N][2]; int mi = 0, ma = 0, par = 0; void add(int x) { if (x >= mi and x <= ma) { if (x % 2 == par) mi = 0; else mi = 1; } else if (x > ma) { mi = x - ma; } else { mi = mi -...
#include <bits/stdc++.h> using namespace std; set<string> ans; string a; int dp[1000010][5]; int main() { cin >> a; int len = a.size(); reverse(a.begin(), a.end()); for (int i = 1; i < len - 5; ++i) { if (i == 1) { string s1 = ; s1 += a[i]; s1 += a[i - 1]; ...
#include <bits/stdc++.h> using namespace std; int n, k; string s; int main() { cin >> n >> k >> s; --k; if (k < n - 1 - k) { while (k) { cout << LEFT << endl; --k; } for (int i = 0; i < n; ++i) { if (i) cout << RIGHT << endl; cout << PRINT << ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long upper_limit = 1e9; long long lower_limit = -1e9; int n; cin >> n; for (int i = 0; i < n; i++) { int c, d; cin >> c >> d; if (d == 2) { upper_limit = min...
#include <bits/stdc++.h> using namespace std; const int pi = 3.14159265; const int INF = 1 << 30; const int maxn = 1e5; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; string s; cin >> n >> k; cin >> s; int t = s.find( T ); int g = s.find( G ); if (g > t) swap(t...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, x[5000 + 5], y[5000 + 5], tot; int color[5000 + 5]; bool flag; int ksm(int b, int k) { int s = 1; while (k > 0) { if (k & 1) s = (1ll * s * b) % mod; k >>= 1; b = (1ll * b * b) % mod; } return s %...
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, -1, 1}; void arquivo() { freopen( , r , stdin); freopen( , w , stdout); } const int N = 5000100; int n; long long a, b; int v[N]; bool memo[N][3]; long long pd[N][3]; int atPrime; long long fu...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; ...
#include <bits/stdc++.h> using namespace std; const int32_t M = 1e9 + 7; int32_t mod_inv(int32_t a, int32_t m) { int32_t g = m, r = a, x = 0, y = 1; while (r != 0) { int32_t q = g / r; g %= r; swap(g, r); x -= q * y; swap(x, y); } return x < 0 ? x + m : x; } int g...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1E5 + 5; long long m, n, k, alice[MAXN], bob[MAXN]; bool cmp(int x, int y) { return x > y; } int main() { cin >> n >> m >> k; for (int i = 0; i < n; i++) cin >> alice[i]; for (int i = 0; i < m; i++) cin >> bob[i]; if (n > m) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; scanf( %d , &n); long long int a[n]; set<long long int> x; map<long long int, set<int> > m; for (i = 0; i < n; i++) { scanf( %lld , &a[i]); x.insert(a[i]); m[a[i]].insert(i); } while (!x.empty()) {...
#include <bits/stdc++.h> using namespace std; template <typename T> using min_queue = priority_queue<T, vector<T>, greater<T>>; const long long MOD = 1e9 + 7; int N; int cnt[6]; int res[100100]; vector<int> v[6]; int main() { ios::sync_with_stdio(0); cin.tie(0); const vector<string> sizes ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; char a[n + 1][n + 1]; int ans[n + 1][n + 1]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { cin >> a[i][j]; ans[i][j] = 0; } for (int i = 1; i <= n; i++) { for (...
#include <bits/stdc++.h> using namespace std; long long ans, l; int n, m, N, i, j, k, s[3005], a[3005][3005], b[3005]; int main() { scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) { scanf( %d%d , &j, &k); a[j][++s[j]] = k; } for (i = 1; i <= m; i++) sort(a[i] + 1, a[i] + s[i] + 1, gr...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int n, m, a[maxn]; map<int, int> mp, rmp; int main() { scanf( %d%d , &n, &m); int id; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); if (a[i] == m) id = i; } int cnt = 0; for (int i = id; i >= 1; i-...
#include <bits/stdc++.h> using namespace std; const unsigned long long O = 2e9; const double E = 1e-9; const double pi = 3.1415926536; int DX[] = {1, -1, 0, 0}; int DY[] = {0, 0, 1, -1}; int main() { int n, m; cin >> n >> m; int out = n * 2 + 1, in = 1; if (m > n * 2) { for (int i = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; set<int> s; int x[maxn]; int n, k; int main() { while (~scanf( %d , &n)) { k = 0; if (!s.empty()) s.clear(); for (int i = 1; i <= n; i++) { int p; scanf( %d , &p); if (s.count(p) == 0) ...
#include <bits/stdc++.h> const int MAXN = 100005; int n, val[MAXN], ch[MAXN][2], fa[MAXN], maxv[MAXN], size[MAXN], root; inline int max(int a, int b) { return a > b ? a : b; } inline int min(int a, int b) { return a > b ? b : a; } inline void maintain(int x) { size[x] = size[ch[x][0]] + size[ch[x][1]] + 1...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { int t; cin >> t; while (t--) { int c, s, v = 0, m, d, k, y; cin >> c >> s; m = (s / 2); d = (c / s); k = (c % s); if (m == 0) { v = c; } else { if (k >= m) {...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; vector<long long> v[105]; map<long long, long long> mp; int vis[105]; long long cnt, cnt2; void dfs(int s) { vis[s] = 1; cnt += v[s].size(); cnt2++; for (int i = 0; i < v[s].size(); i++) { if (!vis[v[s][i]]) dfs(v[s][i]...
#include <bits/stdc++.h> using namespace std; int n; vector<int> V; int solve() { V.clear(); cin >> n; for (int i = 0; i < n; ++i) { int a; cin >> a; V.emplace_back(a); } sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end()); return V.size(); } ...
#include <bits/stdc++.h> using namespace std; vector<long long> v[201]; long long arr[201]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, i, j, c, max1, min1, temp, temp1, n1; cin >> n; for (i = 0; i < 2 * n; i++) { cin >> arr[i]; ...
#include <bits/stdc++.h> using namespace std; long long n; const long long maxn = 2e5 + 100; const long long mod = 1e9 + 7; vector<long long> G[maxn]; long long dp[maxn]; long long oth[maxn]; long long fs[maxn], ts[maxn]; long long ans[maxn]; void myinit() { cin >> n; for (long long i = 2; i...
#include <bits/stdc++.h> using namespace std; template <typename T> void print2dvector(vector<vector<T> > v) { cout << A 2d vector: << endl; int a = v.size(); int b = v[0].size(); if (a <= 15 && b <= 15) { for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { cout <...
#include <bits/stdc++.h> using namespace std; int a[200005], b[200005], vis[200005]; bool cmp(int a, int b) { return a > b; } int main() { int n; scanf( %d , &n); int numa = 0, numb = 0, flag = 0; for (int i = 0; i < n; i++) { int x; scanf( %d , &x); if (vis[x]) a[numa+...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = 1005; int cnt[N]; bitset<N> dp; int n, m; int idx[N]; int par[N]; int xx[N]; bool vis[N]; int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } int main() { for (int i = 0...
#include <bits/stdc++.h> using namespace std; const int MaxN = 33; template <class T> inline void relax(T &a, const T &b) { if (b > a) a = b; } int main() { int n; static int a[MaxN][MaxN]; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf( %d , &a[i][j]); ...
#include <bits/stdc++.h> using namespace std; inline void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); } inline long long Set(long long n, long long pos) { return n = n | (1LL << pos); ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1LL << 60; const long long N = 2e5 + 5; long long a[N]; void solve() { long long n; cin >> n; vector<long long> vect; for (long long i = 1; i < n + 1; i++) { cin >> a[i]; if (a[i] !...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, l, c, d, p, nl, np; cin >> n >> k >> l >> c >> d >> p >> nl >> np; int mls = k * l; int slices = c * d; int drinks = min(mls / nl, min(p / np, slices)) / n; cout << drinks << endl; }
#include <bits/stdc++.h> using namespace std; int a[500010]; char s[500010], temp[500010]; int n; long long Max = -1000, sum = 0; void init() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> s[i]; } } void work() { for (int...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_std...
#include <bits/stdc++.h> using namespace std; int main() { int r, g, b; cin >> r >> g >> b; if (r % 2 == 0) r = r / 2; else r = r / 2 + 1; if (g % 2 == 0) g = g / 2; else g = g / 2 + 1; if (b % 2 == 0) b = b / 2; else b = b / 2 + 1; int tmp1 = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 4e6 + 7; const int inf = INT_MAX; const long long inff = 1e18; const long long mod = 1e9 + 7; int d, s; pair<int, int> dp[maxn]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> d >> s; for (int i = 0; i <= (d + 1...