func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, m, ans, dp[8][8]; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { int l, r; cin >> l >> r; dp[l][r] = dp[r][l] = 1; } if (n <= 6) cout << m; else { for (int i = 1; i <= n; i++) for (int j = i ...
#include <bits/stdc++.h> using std::cin; using std::cout; using std::vector; using std::swap; int main() { int t; cin >> t; while (t--) { int n, x; cin >> n >> x; vector<int> a(n); for (auto& it : a) cin >> it; int cnt = 0; for (int i = 0; i < n && !is_sorted(a.begin...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 303; int n, m, d; int a[maxn], b[maxn], t[maxn]; int dt[maxn]; long long que[150001]; int id[150001]; long long dp[150001][2]; int main() { scanf( %d%d%d , &n, &m, &d); for (int i = 1; i <= m; ++i) { ...
#include <bits/stdc++.h> long long p; int k; namespace solver1 { void main() { std::vector<int> ans; int i; for (i = 0; p; i++) { if (i & 1) ans.push_back(((p - 1) / k + 1) * k - p), p = (p - 1) / k + 1; else ans.push_back(p % k), p /= k; } printf( %d n , (int)ans...
#include <bits/stdc++.h> using namespace std; int *a; int *b; int n; long long int what(long long x) { long long int s = 0; for (int i = 0; i < n; i++) { s += (x * a[i]) / b[i]; } return s; } int main() { int i, j; int c; cin >> n >> c; a = new int[n]; b = new int...
#include <bits/stdc++.h> using namespace std; long long M = 1000000007; long long power(long long a, long long b) { long long res = 1; for (long long i = 0; i < b; i++) res = (res * a) % M; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t, n, m, k...
#include <bits/stdc++.h> using namespace std; long long vet[9], used[9], available[9]; int dp[100][32]; int dp2[100][32]; vector<int> itens, itens2; void comp() { for (int i = 1; i <= 8; i++) { long long j = 1; used[i] = min(used[i], (long long)32 / i); while (used[i]) { itens....
#include <bits/stdc++.h> using namespace std; long long n, k, A, B; vector<long long> a(100000 + 5); long long rec(int l, int r) { long long m = (l + r) / 2, i, j, col = 0, lng = r - l + 1; i = lower_bound(a.begin(), a.end(), l) - a.begin(); j = upper_bound(a.begin(), a.end(), r) - a.begin(); j-...
#include <bits/stdc++.h> using namespace std; int a[500100]; int n; vector<int> g[200100]; int d[200100]; int cnt = 1; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { int ind = lower_bound(d...
#include <bits/stdc++.h> using namespace std; double x[(int)2e3 + 5], y[(int)2e3 + 5]; int fio() { int val = 0; char ch = getchar(); while (ch == || ch == n ) ch = getchar(); while (ch >= 0 && ch <= 9 ) { val = val * 10 + ch - 0 ; ch = getchar(); } return val; } i...
#include <bits/stdc++.h> using namespace std; int main() { int n, b, p; cin >> n >> b >> p; int m = n; long long int nb = 0; while (n > 1) { for (int i = 8; i >= 0; i--) { if (pow(2, i) <= n) { nb += b * pow(2, i) + pow(2, i) / 2; n = n - (pow(2, i)) + pow(2, i)...
#include <bits/stdc++.h> using namespace std; int gcd(int v, int vv) { return vv == 0 ? v : gcd(vv, v % vv); } int main() { int powV1, powV2, v[101], v2[101], vv, vv2, x; cin >> powV1 >> powV2; for (int i = 0; i <= powV1; i++) { cin >> v[i]; } for (int i = 0; i <= powV2; i++) { cin...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, p; cin >> t; while (t--) { cin >> n; p = (n + 3) / 4; for (i = 1; i <= n - p; i++) { cout << 9 ; } for (i = 1; i <= p; i++) { cout << 8 ; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 2002; int a[N][N] = {0}, b[N][N] = {0}; int c[N] = {0}, d[N] = {0}, e[N] = {0}, f[N] = {0}; int main() { int n, m, ans = 0; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> c[N]; vector<int> s[20][N]; int dp[20][N]; int h[N]; vector<int> v[N]; int sh(int x, int y) { for (int i = 17; i + 1; --i) if (y & (1 << i)) x = dp[i][x]; return x; } int ac(int x, int y) { if (h[x] > ...
#include <bits/stdc++.h> using namespace std; const int maxt = 300001; typedef int mang[maxt + 10]; struct mystr { int val[4]; }; mang bit1, bit2; mystr a[100010]; int n, dem, vt = 1; long long d, m; vector<pair<long long, pair<int, int>>> b; int kq[100010]; vector<int> s; int getbit(int x...
#include <bits/stdc++.h> using namespace std; bool used[2011]; int b[2011]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> b[i]; int cand; for (int i = 0; i < n; i++) { int cnt = 0; for (int j = n; j; j--) { if (used[j + k]) cnt++; if (!...
#include <bits/stdc++.h> using namespace std; const int MAX_VALUE = 32768; struct Tokenizer { string input; int at; void tokenize(const string& s) { input = s + @ ; at = 0; token = ; } char nextChar() { return input[at]; } char nextNoneSpace() { while (nextChar()...
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); const long long INF = 1e14; long long gcd(long long a, long long b) { while (b) { a = a % b; swap(a, b); } return a; } int main() { long long n, m, k; cin >> n >> m >> k; if ((n * m * 2) % k !=...
#include <bits/stdc++.h> using namespace std; const int MAX_NUMBER = 105; int flower[MAX_NUMBER], odd[MAX_NUMBER], even[MAX_NUMBER]; int number; int main() { scanf( %d , &number); int sums = 0; int odd_number = 0, even_number = 0; for (int i = 1; i <= number; i++) { scanf( %d , &flower[i...
#include <bits/stdc++.h> using namespace std; long long a[2005], b[2005]; vector<pair<long long, pair<int, int> > > bb; long long diff = 0L; bool good(long long x, int place) { if (place >= bb.size()) return false; else return diff + 2 * (bb[place].first - x) <= 0; } int find_(long lon...
#include <bits/stdc++.h> using namespace std; int main() { int l, r; cin >> l >> r; for (int i = l; i <= r; ++i) { int d[10] = {}; int c = i; bool ok = true; while (c) { if (d[c % 10]) { ok = false; break; } d[c % 10] += 1; c /=...
#include <bits/stdc++.h> using namespace std; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, 1, 0, -1}; long long spf[1]; void sieve() { long long i, j; for (i = 0; i < 1; i++) spf[i] = i; for (i = 4; i < 1; i += 2) spf[i] = 2; for (i = 3; i * i < 1; i++) { if (spf[i] == i) { ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int inf = 1e9; const long double eps = 1e-7; const long double pi = acos(-1); const int dx[8] = {0, 2, 1, 0, -2, -1, 1, 2}; const int dy[8] = {2, 0, 1, -2, 0, -1, 2, 1}; const int N = 23; const int MAXN = 1e5; const int ...
#include <bits/stdc++.h> using namespace std; string slv(string s) { int sz = s.size(); if (sz % 2 == 1) return s; else { string a = slv(s.substr(0, sz / 2)); string b = slv(s.substr(sz / 2, sz)); return a < b ? a + b : b + a; } } int main() { string a, b; cin >> ...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, n, ans; while (cin >> n >> a) { ans = (a / 2) + 1; if (a % 2 == 0) { ans = ans - 1; ans = (n / 2) - ans; ans = ans + 1; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, b; cin >> n >> m; vector<int> ct(0); if (m == 1) { for (int j = 0; j < n; j++) cout << 1 << endl; return 0; } if (m == 2) { ct.push_back(1); ct.push_back(2); for (int i = 0; i < n; i++) cout <<...
#include <bits/stdc++.h> using namespace std; vector<int> v[10003], v1[10003]; int cnt[10003]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, i, j; cin >> m >> n; for (i = 0; i < m; i++) { int x, y; cin >> x; memset(cnt, 0, sizeof(cnt)); for (j = 0; j...
#include <bits/stdc++.h> using namespace std; int a[505]; int sorted_a[505]; void rot(int i) { i--; int temp = a[i + 2]; a[i + 2] = a[i + 1]; a[i + 1] = a[i]; a[i] = temp; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int cases; cin >> cases; while...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int maxim = 0, sum = 0, a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; maxim = max(maxim, a[i]); ...
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) if (n % i == 0) return false; return true; } int odd(int arr[], int n) { for (int i = 0; i < n; i++) { if (arr[i] % 2 != 0) { return i; } } } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; string s1 = ; if (n % 2 == 0) { for (int i = 0; i < n; i++) { cout << s[i] << s[i + 1]; i++; if (i < n - 2) { cout << - ; } } } else { ...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; long long int fastPow(long long int x, long long int y) { long long int p = mod; long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } retur...
#include <bits/stdc++.h> using namespace std; long long p[10005]; long long s[10005]; long long dp[2][10005]; int n; long long m; int main() { scanf( %d%I64d , &n, &m); for (int i = 1; i <= n; i++) scanf( %I64d , &p[i]); for (int i = 1; i <= n; i++) scanf( %I64d , &s[i]); int now = 0, next...
#include <bits/stdc++.h> using namespace std; int a1, a2, b1, b2, c1, c2; int main() { scanf( %d%d%d , &a1, &b1, &c1); scanf( %d%d%d , &a2, &b2, &c2); if (a1 == 0 && b1 == 0) { if (c1 != 0) { puts( 0 ); return 0; } if (a2 == 0 && b2 == 0 && c2 != 0) puts( 0 );...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, p; cin >> a >> b >> p; string s; cin >> s; int len = s.size(); int pos = 0; char ss = C ; for (int i = len - 2; i >= 0; i--) { if (ss != s[i]) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int col[n + 2], k[m + 2]; for (int i = 1; i <= n; i++) cin >> col[i]; for (int i = 1; i <= m; i++) cin >> k[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { vector<int> v[105]; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); return x * f; } int n, m; vector<int> G[20], G2...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void chkmin(T &x, T y) { x = min(x, y); } template <typename T> inline void chkmax(T &x, T y) { x = max(x, y); } template <typename T> inline void read(T &x) { T f = 1; x = 0; char c = getchar(); for (; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) template <class T> inline void gmax(T &a, T b) { if (b > a) a = b; } template <class T> inline void gmin(T &a, T b) { if (b < a) a = b; } using namespace std; const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxin...
#include <bits/stdc++.h> using namespace std; const int c = 3002; int w, n, m, dif[c], rf[c]; long long sok = 1e15; pair<long long, long long> op[c][c], cl[c][c]; vector<int> sz[c]; bool v[c]; pair<long long, long long> add(pair<long long, long long> a, pair<long long, l...
#include <bits/stdc++.h> using namespace std; long long n, c; vector<vector<long long> > a; long long dp[200000 + 5][2][2]; long long fun(long long idx, bool state, bool prev) { if (idx == 0) return 0; if (dp[idx][state][prev]) return dp[idx][state][prev]; if (prev || !state) return dp[idx][...
#include <bits/stdc++.h> using namespace std; const int M = 6; const int MSK = 1 << M; const int N = 45; int D[45][MSK][MSK]; int col(int x) { int ans = 0; while (x) ans += x % 2, x /= 2; return ans; } int n, m; bool BIT(int x, int i) { if (i < 0) return 0; return (x >> i) & 1; }...
#include <bits/stdc++.h> using namespace std; int main() { int n; set<int> keyboards; scanf( %d , &n); for (int i = 0; i < n; i++) { int a; scanf( %d , &a); keyboards.insert(a); } int prev = 0; int result = 0; for (auto keyboard : keyboards) { if (prev != 0) r...
#include <bits/stdc++.h> using namespace std; int n, m, a[300010], f[300010], p; vector<int> x[300010], w; int main() { srand(time(0)); int i, j, k, l; scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) { a[i] = i + 1; for (j = i + i; j <= n; j += i) x[j].push_back(i); } p = n -...
#include <bits/stdc++.h> using namespace std; const int L = 1000000 + 10; int main() { int n; scanf( %d , &n); char s[n + 10]; scanf( %s , s); int next[n + 10]; next[0] = -1; int j = 0, k = -1; int maxn = 1; while (j < n) { if (k == -1 || s[j] == s[k]) { next[++j]...
#include <bits/stdc++.h> using namespace std; string char_to_str(char c) { string tem(1, c); return tem; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class T> T rand() { return uniform_int_distribution<T>()(rng); } signed main() { ios_base::sync_with_s...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int n; while (t--) { scanf( %d , &n); int k = sqrt(n); if (n == 1) cout << 0 << endl; else if (k * k == n) { cout << 2 * k - 2 << endl; } else cout << k - 1 + (n + k - 1)...
#include <bits/stdc++.h> using namespace std; const int N = 3e5; int n, fa[N], p[N], cnt, mk, la[N], size[N]; int getfa(int x) { if (fa[x] == x) return x; return fa[x] = getfa(fa[x]); } void merge(int x, int y) { int fx = getfa(x), fy = getfa(y); if (fx == fy) return; fa[fx] = fy; si...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, mod, a[N], b[N], ans[N]; int main() { cin >> n >> m >> mod; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= m; i++) { cin >> b[i]; } for (int i = 1; i <= m; i++) { ans[i] +...
#include <bits/stdc++.h> using namespace std; const long double epsilon = 1e-9; int main() { long long n, m, v; cin >> n >> m >> v; long long p = ((n - 1) * (n - 2)) / 2LL + 1; if (m > p || m < n - 1) { cout << -1 << endl; return 0; } int other = 1; if (v == 1) other = 2; ...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-7; const double PI = acos(-1.0); const double ZERO = 0; const double DOUBLE_MAX = 1 / ZERO; int main() { long double t, s, q; cin >> t >> s >> q; long double speed = (q - 1) / q; long double x = 0, d; int res = 0; wh...
#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; char str1[2000010]; char str2[2000010]; int main() { int cross, c...
#include <bits/stdc++.h> using namespace std; using ii = int; int main() { ii n, i; cin >> n; ii* ar = (ii*)malloc(sizeof(ii) * n); for (i = 0; i < n; i++) { cin >> ar[i]; } ii max = *max_element(ar, ar + n); if (n == 1) cout << max - max << endl; else { ii count ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> balance(n, 0); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; balance[a - 1] -= c; balance[b - 1] += c; } int total = 0; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int x = 0, f = 1; while (ch < 0 || ch > 9 ) f = ch == - ? -1 : 1, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x * f; } inline int sqr(int x) { return x...
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const double eps = 1e-12; const int maxn = 1e5 + 5; const int INF = 1e9; long long n, m; long long ma = 0, mi = 0; void pre() { for (int i = 0; i < n; i++) ma += i; if (n & 1) { mi = n / 2 * (n / 2 + 1); } else ...
#include <bits/stdc++.h> using namespace std; const int K = 30; const int MOD = 1e9 + 7; long long n, power[K + 1]; int k; __inline void add(int &a, int b) { if ((a += b) >= MOD) { a -= MOD; } } struct Matrix { int trans[K][K]; int go[K]; Matrix() { memset(trans, 0, sizeo...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n; int a[N], sum[N], b[65][N], cnt[65]; long long ans; int t[2]; long long find(int l, int r, int lim) { int i, j; long long ret = 0; if (l > r) return 0; j = l - 1; t[0] = t[1] = 0; for (i = l; i <= r; ++i) ...
#include <bits/stdc++.h> int main() { int T; int n, x, i, j; scanf( %d , &T); while (T--) { scanf( %d%d , &n, &x); printf( %d n , 2 * x); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int test; cin >> test; while (test--) { int bun, beef, chicks, hp, cp, count1 = 0, count2 = 0; cin >> bun >> beef >> chicks >> hp >> cp; bun /= 2; if (hp >= cp) { count1 = min(bun, beef); bun -= count1; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long mod = 998244353; long long p[N]; int main() { int n; long long ans; scanf( %d , &n); p[0] = 1; for (int i = 1; i <= n; i++) p[i] = p[i - 1] * (n - i + 1) % mod; ans = p[1]; for (int i = 2; i <= n;...
#include <bits/stdc++.h> using namespace std; int main() { int n, in, ans = 0, asum = 0, bsum = 0; vector<int> a, b; vector<int>::iterator minit, it2; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &in); a.push_back(in); } b = a; sort(b.begin(), b.end()); ...
#include <bits/stdc++.h> using namespace std; struct state { state(int a, int b, int c, int d) : num(a), ind1(b), ind2(c), oper(d){}; int num; int ind1, ind2; int oper; }; vector<state> ansState; int n, ans = 100000; map<set<int>, int> m; vector<state> v; void dfs() { if (v[v.size() ...
#include <bits/stdc++.h> using namespace std; const int inf = 2 * 1e9; const int mod = 1e9 + 7; const int maxn = 200005; int n, m; int arr[maxn], ob[maxn], fact[maxn], obr[maxn]; int main() { ios_base::sync_with_stdio(false); cin >> n >> arr[1]; ob[1] = fact[1] = obr[1] = 1; for (int i = 2...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; T f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; x *= f; } int max(int x, int y) { return x > ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, ch; while (!isdigit(ch = getchar())) ; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return x; } template <typename T> inline T gcd(T a, T b) { return !b ? a : gcd(b, a % b); } ...
#include <bits/stdc++.h> using namespace std; const long long int N = 2e5 + 5; void solve() { long long int n, x; cin >> n >> x; vector<long long int> v(n); for (auto &it : v) cin >> it; ; sort(v.begin(), v.end()); long long int ans = 0; vector<long long int> a; for (long long ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> c[2]; int main() { int n, k, p, x, m1 = 0, m2 = 0; scanf( %d%d%d , &n, &k, &p); for (int i = 0; i < n; ++i) { scanf( %d , &x); if (x & 1) { c[0].push_back(x); m1++; } else { c[1]...
#include <bits/stdc++.h> using namespace std; int x; char s[100005]; bool flag[500]; int cnt[500]; vector<char> f; int main() { scanf( %d , &x); scanf( %s , s); int len = strlen(s); for (int i = 0; i < len; i++) cnt[s[i]]++; for (int i = a ; i <= z ; i++) { if (cnt[i] == 0) con...
#include <bits/stdc++.h> using namespace std; long long a[200005], b[200005]; int x[200005]; int main() { int n; long long t; scanf( %d%I64d , &n, &t); for (int i = 1; i <= n; i++) scanf( %I64d , a + i); for (int i = 1; i <= n; i++) { scanf( %d , x + i); if (x[i] < x[i - 1] || x[...
#include <bits/stdc++.h> using namespace std; int main() { int tests; scanf( %d , &tests); while (tests--) { int item; cin >> item; vector<int> v; set<int> s; int temp; for (int i = 0; i < item; i++) { scanf( %d , &temp); v.push_back(temp); s.i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 16; int from[MAXN], to[MAXN], p[MAXN], q[MAXN]; bool w[MAXN][MAXN]; long long dp[1 << MAXN]; int main() { int n, m, a, b; long long y; cin >> n >> y >> m; fill(from, from + n, 0); fill(to, to + n, 0); fill(w[0], w[m], fal...
#include <bits/stdc++.h> using namespace std; const int N = 50005; int n, m; int p[N], a[N]; struct LCT { int fa[N], ch[N][2], siz[N], sv[N]; long long sv2[N], sav[N], san[N], sa[N]; int nroot(int u) { return ch[fa[u]][0] == u || ch[fa[u]][1] == u; } void pushup(int u) { siz[u] = siz[ch[...
#include <bits/stdc++.h> using namespace std; int a[6]; int sum = 0; int x, y, z; int x1, adjf, z1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); scanf( %d%d%d , &x, &y, &z); scanf( %d%d%d , &x1, &adjf, &z1); for (auto i = 0; i != 6; i++) scanf( %d , &a[i]); if (y < 0) {...
#include <bits/stdc++.h> using namespace std; long long n, k; long long mx, p1, p2, val, sum, res, res1; long long m[200007][27]; int main() { ios_base::sync_with_stdio(); cin.tie(); cout.tie(); ; cin >> n >> k; res = 1000000007.0; for (int i = 1; i <= n; i++) { cin >> val; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { long long a, b, c; scanf( %lld %lld %lld , &a, &b, &c); printf( %lld n , a + b + c - 1); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100003; int n, L, R, phi; long long mod; long long fac[N], inv[N]; int d[N][33]; int tot, p[N]; long long fpow(long long x, int y) { long long res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod; y >>=...
#include <bits/stdc++.h> using namespace std; long long mapa[35]; int main() { int n, q; scanf( %d %d , &n, &q); for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); for (int j = 30; j >= 0; j--) if ((1 << j) & x) { mapa[j]++; break; } } ...
#include <bits/stdc++.h> using namespace std; const int mn = 2010; long long a[mn], b[mn]; int main() { int n, k; long long p; scanf( %d %d %lld , &n, &k, &p); for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); for (int i = 1; i <= k; i++) scanf( %lld , &b[i]); sort(a + 1, a + n + 1); ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, b, r; cin >> n >> m; b = 3; r = 1; while (n > 0) { if (n % 2 != 0) r = (r * b) % m; b = (b * b) % m; n = n / 2; } cout << (r - 1 + m) % m; return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 30, Mod = 1e9 + 7; const long long SQ = 330; unordered_map<int, int> Par[N]; map<pair<int, int>, int> ans; vector<int> G[N]; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int find(int x, int c) { ...
#include <bits/stdc++.h> using namespace std; long long maxi = LLONG_MAX; long long mini = LLONG_MIN; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long a[] = {1, 1, 3}; void fn(long long n, long long x) { if (n <= 1) { for (long long i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using v...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5 * 105000; int n; int a[MAXN]; bool can(int x) { if (x == 0) return true; if (n - x < x) return false; int r = n; for (int i = x; i >= 1; i--) { if (r <= x) return false; while (a[r] < 2 * a[i]) { r--; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100020; const int logn = 18; const int MOd = 1e9 + 7; int a, b; int ar[maxn]; int main() { scanf( %d %d , &a, &b); for (int i = 1; i <= a; i++) scanf( %d , &ar[i]); double ans = 0.0; for (int i = 1, j, k, t; i <= b; i++) { ...
#include <bits/stdc++.h> using namespace std; mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); char mat[105][105]; void solve() { int n, m, horizontal; cin >> n >> m >> horizontal; int vertical = n * m / 2 - horizontal; int oxe = 0, nte = 0; char cc = e ; if (n ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; int main() { int N, ele = -1; cin >> N; vector<int> A(N); int i; for (i = 0; i < N; ++i) cin >> A[i]; sort(A.begin(), A.end()); int ans = 0, ctr = 0, x; for (i = 0; i < N; i += x) { x = upper_bound(A.begi...
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, c; cin >> a >> b >> c; if (b >= a && c >= a) cout << YES n ; else cout << NO n ; return 0; }
#include <bits/stdc++.h> using namespace std; int n, q; inline int clamp(int v) { if (v > n) return v - n; else if (v < 1) { if (v == 0) return n; else return n + v; } else return v; } void validate() { n = 6; assert(clamp(0) == 6); assert(clamp(...
#include <bits/stdc++.h> using namespace std; int n, i, j, k, l, mx; int a[100001]; int p[100001], miu[100001], len; vector<int> b[100001]; vector<int> c[100001]; bool bz[100001]; int f[100001]; long long ans, s; bool cmp(int a, int b) { return a > b; } int gcd(int x, int y) { int r = x % y; ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> using pr = pair<T, U>; template <typename T> using vt = vector<T>; template <class T> bool cmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> bool cmax(T& a, const T& b) { return a < b ? a...
#include <bits/stdc++.h> using namespace std; char ch[1005]; int dp[1005][3 * 1005]; int n, k; int func(int idx, int diff) { if (idx == n) { return (abs(diff) == k); } if (abs(diff) == k) { return 0; } int &re = dp[idx][diff + 1005]; if (re != -1) return re; re = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int pos[4] = {0}; int n = s.size(), ans = s.size() + 1; for (int i = 0; i < n; i++) { pos[s[i] - 0 ] = i + 1; int x = min(pos[1], min(pos[2], pos[3...
#include <bits/stdc++.h> using namespace std; const long long p = 998244353; const long long maxn = (1 << 16) + 5; long long cnt[maxn]; vector<vector<long long> > dp; long long k; long long c; long long c1[20][20]; long long maxbit(long long x) { for (long long i = 16; i >= 0; i--) { if (x &...
#include <bits/stdc++.h> using namespace std; const int M = 150; int ej[M][M]; const int inf = 1e9; int n; int bfs(int src, int sink) { vector<int> vis(n, 0); vector<int> dis(n, 0); queue<int> que; vis[src] = 1; que.push(src); while (que.size() > 0) { int u = que.front(); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; long long arr[n + 5]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); long long mn = arr[0]; long long mx = arr[n - 1]; ...
#include <bits/stdc++.h> using namespace std; int vis[50005]; long long int dp[50005][505]; int k; vector<int> v[50005]; long long ans; void dfs(int i) { vis[i] = 1; dp[i][0] = 1; for (auto j : v[i]) { if (!vis[j]) { vis[j] = 1; dfs(j); for (int w = 0; w <= k; w++...
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, a[N], b[N], p[N]; int main() { if (fopen( 180F.in , r )) freopen( 180F.in , r , stdin); scanf( %d n , &n); for (int i = 1; i <= n; i++) { scanf( %d , a + i); } for (int i = 1; i <= n; i++) { scanf( %d , ...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int n, i, k, ans = -1, x, l, sum; cin >> n; long long int a[n + 2]; a[0] = 0; long long int ca[n + 2]; ca[0] = 0; l = (n + 1) / 2; for (i = 1; i <= n; i++) { if (i <= l) { cin >> a[i]; } else...