func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 3e3 + 555; struct node { long long x, y, v; bool operator<(const node& n) const { if (x != n.x) return x < n.x; else return y < n.y; } }; long long pre[maxn][maxn]; node ori[maxn...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; void self_max(long long& a, const long long& b) { a = max(a, b); } void self_min(long long& a, const long long& b) { a = min(a, b); } inline void preprocessing() {} inline void solve() { long long n; cin >> n; if (n == 1) ...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c; cin >> a >> b >> c; vector<long> v; for (int i = 1; i <= 81; i++) { long long sum = i; for (int j = 2; j <= a; j++) sum *= i; sum *= b; sum += c; if (sum > 0 && sum < 1000000000) { ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const int maxn = 100 + 10; int n; complex<double> p[maxn]; int sign(double x) { if (x < -eps) return -1; return x > eps; } double cross(complex<double> a, complex<double> b) { return (conj(a) * b).imag(); } double dot...
#include <bits/stdc++.h> using namespace std; struct node { int leftColors[10], rightColors[10]; int leftParent[10], rightParent[10]; int components; node() { components = 0; } }; int n; node merge(node l, node r) { node ans; ans.components = l.components + r.components; for (int e...
#include <bits/stdc++.h> using namespace std; long long DP[100005][25], arr[100005], freq[100005], l = 1, r, ans; void alter_range(long long l1, long long r1) { while (l1 < l) { l--; ans += freq[arr[l]]++; } while (r < r1) { r++; ans += freq[arr[r]]++; } while (l < l1) ...
#include <bits/stdc++.h> using namespace std; long long int fuckAbs(long long int a) { return a >= 0 ? a : -a; } int main(void) { long long int t, n, m, ans, dx, dy, sx, sy, x1, y1, x2, y2; cin >> t; while (t--) { cin >> n >> m >> x1 >> y1 >> x2 >> y2; ans = n * m; dx = n - max(x1, x...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int x; cin >> x; bool f1 = 0, f2 = 0; long long su = 0; for (int i = 0; i < n; i++) { int k; cin >> k; su += k; if (k == x) { f1 = 1; } else f2 = 1; } if (!...
#include <bits/stdc++.h> using namespace std; int i, j, m, s, ans; long long n, k, t; double sum; int main() { scanf( %lld%lld , &n, &k); sum = (1.0 + k) * k / 2; if (sum > n) { puts( -1 ); return 0; } t = sum; for (int i = 1; (long long)i * i <= n; i++) if (n % i == ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void pg() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { pg(); long long t; cin >> t; while (t--) { long long n, x; cin >> n >...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, x; cin >> n >> x; long long int a[n]; a[0] = 0; string s; cin >> s; for (int i = 0; i < n; i++) { char ch; ch = s[i]; if (i == 0) {...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e7 + 10, maxl = 20, mod = 1e9 + 7, base = 737, inf = 2e18 + 13; int a, n, res[maxn], t[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> a >> n; for (int i = 2; i < a + n; i++) if (!t[i]) ...
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <cstring> #include <list> #include <casser...
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n; cin >> n; vector<long long> l(n + 5), r(n + 5); for (long long i = 1; i < n + 1; ++i) cin >> l[i]; for (long long i = 1; i < n + 1; ++i) cin >> r[i];...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; constexpr int LOGMAX = 31 - __builtin_clz(MAX) + 5; int N; char T[MAX]; int sa[MAX], tsa[MAX], ra[MAX], tra[MAX]; int lcp[MAX], plcp[MAX], phi[MAX], c[MAX], st[LOGMAX][MAX]; long long pref[MAX]; void sort(int k) { memset(c, 0, ...
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e16; int a[2][111111]; int main(void) { int n; cin >> n; for (int e = 0; e < 2; e++) for (int p = 0; p < n; p++) cin >> a[e][p]; long long int tot = 0; for (int e = 0; e < n; e++) tot += a[0][e]; sort(a[1], a[...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1 << << 1 << endl << 1 << endl; return 0; } int value = n * 2 - 2; cout << value << << 2 << endl << 1 << << 2 << endl; }
#include <bits/stdc++.h> using namespace std; int dp[2][100010], bit, n; long long a[100010]; inline int comp(long long x, long long y) { return (x % (1ll << (bit + 1))) > (y % (1ll << (bit + 1))); } int main() { long long mx = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %...
#include <bits/stdc++.h> using namespace std; long long n, k, ar[1000005], br[1000005]; int main() { scanf( %lld %lld , &n, &k); long long min_ = 0, max_ = 0; for (int i = 1; i < n + 1; i++) { ar[i] = br[i] = i; min_ += i; max_ += max((long long)i, n - i + 1); } if (k < min_)...
#include <bits/stdc++.h> using namespace std; int read(); int n; char t[102]; int w[102][102], rnk[102][102], pos[102]; vector<int> p[102]; queue<int> q; void init(int t) { for (int i = 1; i <= n; ++i) { p[i].clear(), p[i + n].clear(); for (int j = 1; j <= n; ++j) p[i].push_back(j + n), ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, a, n2, m2; cin >> n >> m >> a; if ((a * (n / a)) == n) n2 = n / a; else n2 = (n / a) + 1; if ((a * (m / a)) == m) m2 = m / a; else m2 = (m / a) + 1; cout << n2 * m2 << endl; return ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); int out = n; int cur = n / 2; for (int i = 0; i < n / 2 && cur < n; i++) { while (true) { if (v[i] * 2 <= v[c...
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b) { long long res = 1; a %= 1000000007; for (; b; b >>= 1) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; } return res; } struct node { int x, y; } f[2203456], ans[22034...
#include <bits/stdc++.h> using namespace std; int main() { long long n, t; cin >> n >> t; long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); float mxdif = INT_MIN; for (int i = 1; i < n; i++) { if (arr[i] - arr[i - 1] > mxdif) { m...
#include <bits/stdc++.h> using namespace std; long long memo[4][1001][1001]; long long mp[1001][1001]; int n, m; long long REC(int x, int y, int st) { if (x >= n || y >= m || x < 0 || y < 0) return 0; if (st == 0 && x == n - 1 && y == m - 1) return mp[x][y]; if (st == 1 && x == 0 && y == 0) return...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const int NMAX = 5005; const int INF = 2e5; int n; vector<int> arr; vector<vector<int>> dp(NMAX, vector<int>(NMAX, INF)); int rec(int i, int j) { if (dp[i][j] != INF) return dp[i][j]; if (i == j) return dp[i][j] = 0;...
#include <bits/stdc++.h> using namespace std; int n, q; int x, y, z; int sum = 0; map<int, pair<char, int> > ans; map<int, pair<char, int> >::iterator t; int main() { scanf( %d%d , &n, &q); ans[0] = { U , 0}; ans[n + 1] = { L , 0}; for (int i = 1; i <= q; i++) { scanf( %d%d%c%c , &x,...
#include <bits/stdc++.h> using namespace std; inline long long qr() { register long long ret = 0, f = 0; register char c = getchar(); while (c < 48 || c > 57) f |= c == 45, c = getchar(); while (c >= 48 && c <= 57) ret = ret * 10 + c - 48, c = getchar(); return f ? -ret : ret; } const int ma...
#include <bits/stdc++.h> using namespace std; using LL = long long; namespace _buff { const size_t BUFF = 1 << 19; char ibuf[BUFF], *ib = ibuf, *ie = ibuf; char getc() { if (ib == ie) { ib = ibuf; ie = ibuf + fread(ibuf, 1, BUFF, stdin); } return ib == ie ? -1 : *ib++; } } // na...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int now; int n, m, c, a[MAX]; int main() { cin >> n >> m >> c; c /= 2; while (m--) { int x; scanf( %d , &x); if (x <= c) { for (int i = 1; i <= n; i++) { if (a[i] == 0 || a[i] > x) { ...
#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; int distance(char a, char b) { int d = abs(a - b); int d1 = 26 - d; return min(d, d1); } int main() { int n; string A; int cursor; cin >> n >> cursor >> A; cursor--; n--; cursor = min(cursor, n - cursor); int middle = n / ...
#include <bits/stdc++.h> int n, m, x, tab[11][1001][1001], mx[11][1001][1001], i = 1, j = 1, ij = 1; char a[1001], b[1001], q; inline int max(int a, int b) { if (a >= b) return a; return b; } int main() { scanf( %d %d %d , &n, &m, &x); q = getchar(); while (i <= n) { a[i] = getchar()...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; long long int arr[n]; set<long long int> s; for (int i = 0; i < n; i++) cin >> arr[i]; for...
#include <bits/stdc++.h> using namespace std; bool comp(long long x, long long y) { if (x >= y) return true; return false; } bool compare(const pair<long long, long long> &i, const pair<long long, long long> &j) { return i.first <= j.first; } bool compare1(const pair<long long, lo...
#include <bits/stdc++.h> using namespace std; vector<long long int> primes; void SOE(long long int n) { primes.erase(primes.begin(), primes.end()); bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (long long int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (long lo...
#include <bits/stdc++.h> using namespace std; string ans = ; set<int> s[26]; map<int, bool> vis; void solve(char a) { ans += a; vis[a - a ] = true; for (auto it : s[a - a ]) { if (!vis[it - a ]) { solve(it); } } } int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; string bin(long long n) { string ans = ; while (n > 0) { if (n % 2 == 0) ans = 0 + ans; else ans = 1 + ans; n /= 2; } return ans; } long long gcd(long long a, long long b) { ...
#include <bits/stdc++.h> using namespace std; const long long maxF = (long long)1e9 * 1e9; const int maxn = 100, maxm = 100, maxlen = maxn + maxm + 1; int n, m, len, map[maxn + 5][maxm + 5], pri[maxlen], cir[maxlen]; long long dp[maxlen][(maxlen >> 1) + 1], k; long long cal() { memset(dp, 0, sizeof(dp))...
#include <bits/stdc++.h> using namespace std; template <class T> inline T checkmin(T &a, T b) { return (a < b) ? a : a = b; } template <class T> inline T checkmax(T &a, T b) { return (a > b) ? a : a = b; } template <class T> T GCD(T a, T b) { if (a < 0) return GCD(-a, b); if (b < 0) re...
#include <bits/stdc++.h> using namespace std; long long seg[200005], h[100005], dp[100005]; int n, cnt, arr[100005], a[100005], b[100005]; map<int, int> mn; map<int, long long> tot; inline void modify(int pos, long long x) { for (seg[pos += cnt] += x; pos; pos >>= 1) seg[pos >> 1] = max(seg[pos], ...
#include <bits/stdc++.h> using namespace std; const int Direction[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; const int Nmax = 200010; int n, k; long long a[20000], pref[20000]; long long f[60][500][500]; long long diff[500][2]; int main() { ios::sync_with_stdio(0); cin >> n >> k; for (int i...
#include <bits/stdc++.h> using namespace std; inline long long add(long long a, long long b, long long p = 1000000007) { long long c = a + b; if (c >= p) c -= p; return c; } inline long long sub(long long a, long long b, long long p = 1000000007) { long long c = a - b; if (c < 0) c += p; ...
#include <bits/stdc++.h> using namespace std; const long long infll = powl(2, 63) - 1; struct cup { long long a, b, c; }; bool comp(cup x, cup y) { return x.c < y.c; } bool cmp1(cup x, cup y) { if (x.a == y.a) return x.c < y.c; return x.a > y.a; } int32_t main() { long long n, tea; c...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long x, y, m; cin >> x >> y >> m; long long sol = 0ll; if (x >= m || y >= m) { cout << 0 n ; return 0; } if (x <= 0ll && y <= 0ll) { cout << -1 n ; return 0;...
#include <bits/stdc++.h> using namespace std; using std::bitset; const double Pi = acos(-1); namespace fastIO { template <class T> inline void read(T &x) { x = 0; bool fu = 0; char ch = 0; while (ch > 9 || ch < 0 ) { ch = getchar(); if (ch == - ) fu = 1; } while (ch <...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int T, n; long long W; pair<long long, int> w[N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); for (cin >> T; T--;) { vector<int> id; cin >> n >> W; long long x = W; for (int i = 1; i <= n...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2004; const int INF = 0x3f3f3f3f; char s[MAXN][MAXN]; int u[MAXN][MAXN], d[MAXN][MAXN]; int l[MAXN][MAXN], r[MAXN][MAXN]; int dp[MAXN][MAXN]; int n, m; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; ++i) scanf( %s , s[i...
#include <bits/stdc++.h> using namespace std; const int N = 55; int n, siz[N]; vector<int> e[N]; double f[N][N], sav[N], C[N][N], fac[N]; void dfs(int x, int fa) { siz[x] = 0, f[x][0] = 1; for (const int &v : e[x]) if (v != fa) { dfs(v, x), ++siz[v]; double sum = 0, o; ...
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; void solve() { long long int n; cin >> n; vector<long long int> a(n); long long int sum = 0; long long int x = 0; for (long long int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; x = x ^ a[i]; } ...
#include <bits/stdc++.h> using namespace std; const int N = 305000; const int INF = 105000; int main() { long long n, k; cin >> n >> k; long long g = (n / 2) / (k + 1); long long d = g * k; long long ost = n - d - g; cout << g << << d << << ost; }
#include <bits/stdc++.h> using namespace std; map<string, vector<string> > graph; unsigned long long int countSetBits(long long int n) { unsigned long long int count = 0; while (n) { n &= (n - 1); count++; } return count; } bool valid(set<string>& t) { for (auto i = t.begin(); ...
#include <bits/stdc++.h> using namespace std; const long long LLINF = 1ll << 60; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(25); int T; cin >> T; while (T--) { int n; cin >> n; string s; cin >> s; int cnt = 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 8; bool vis[N][N]; int n, m, ans, a[8]; vector<pair<int, int> > edges; vector<int> v; int calc() { memset(vis, 0, sizeof vis); for (auto X : edges) { int x = X.first; int y = X.second; vis[a[x]][a[y]] = vis[a[y]][a[x]] =...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 3; int a[MAXN], b[MAXN], p[MAXN]; int read() { int x = 0, w = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) w = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << ...
#include <bits/stdc++.h> using namespace std; const int N = 501000; int n, a[N]; bool check(int p) { for (int i = p - 1; i >= 0; i--) { if (a[i] * 2 > a[n - p + i]) return false; } return true; } int work() { int l = 0, r = n >> 1; while (l <= r) { int mid = l + r >> 1; ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); template <class T = int> T __rand(T range = numeric_limits<T>::max()) { return (T)(rng() % range); } int debug = 0; int __db_level = 0; struct debug_block { string name; debug_b...
#include <bits/stdc++.h> using namespace std; char dat[1048576]; long long countSub(long long a, long long b, long long left, long long right, long long d) { long long low = b * d - a; if (low < 0) { if (a % b != 0) { low = b - a % b; } else { low = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, s[200005], d[200005], k; while (cin >> n >> t) { int maxx = 0x3f3f3f3f; for (int i = 1; i <= n; i++) { cin >> s[i] >> d[i]; int change = s[i]; while (change < t) { change += d[i]; } ...
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 5; const double eps = 1e-10; int n, m, cnt, v[N], tr[N << 1]; double a[N], b[N]; pair<double, int> e[N << 1]; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1;...
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { string s; string t; cin >> s >> t; string result(s); int carry = 1; for (int ii = s.length() - 1; ii >= 0; --ii) { result[ii] = (char)(s[ii] + carry); if (result[ii] > z ) { result[ii] = a ...
#include <bits/stdc++.h> using namespace std; long long s[100007]; long long l[100007]; int main() { long long n, k, r = 0; cin >> n >> k; map<int, int> m; map<int, int> e[10]; long long ki = 0; for (int i = 0; i < n; i++) { scanf( %I64d , &s[i]); r += s[i] / 10; if (s[...
#include <bits/stdc++.h> using namespace std; int n, m, k, a[110]; int main() { cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> k; for (int j = k; j <= n; ++j) if (a[j] == 0) a[j] = k; } for (int i = 1; i <= n; ++i) cout << a[i] << ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a[10000], b, c, d, e, f, i, j, k, l, t; cin >> t; while (t--) { d = 0; cin >> b >> c; for (i = 0; i < b; i++) { cin >> a[i]; d += a[i]; } if (d < c) { cout << d << endl; } else if (...
#include <bits/stdc++.h> using namespace std; int n; string a, b; void perform(int len) { for (int i = 0; i < len / 2; ++i) { if (a[i] == a[len - 1 - i]) { a[i] = 0 + 1 - a[i]; a[len - 1 - i] = 0 + 1 - a[len - 1 - i]; } } if (len & 1) a[len / 2] = 0 + 1 - a[le...
#include <bits/stdc++.h> #pragma GCC optimize( O3,unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; mt19937 rnd(time(nullptr)); const int N = 1e5 + 5; unordered_set<int> g[N]; bool check(int v) { for (auto i : g[v]) for (auto j : g[...
#include <bits/stdc++.h> using namespace std; int n, h, l, r, dp[2005][2005]; int main() { scanf( %d%d%d%d , &n, &h, &l, &r); memset(dp, 0xc0, sizeof(dp)); dp[0][0] = 0; for (int i = 1, x; i <= n; i++) { scanf( %d , &x); for (int j = 0; j < h; j++) { dp[i][j] = max(dp[i][j], dp...
#include <bits/stdc++.h> using namespace std; void File() { freopen( output.txt , w , stdout); freopen( input.txt , r , stdin); } int countDivisors(long long n) { int cnt = 0; for (long long i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) cnt++; el...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); if (n % 3 == 0 || n % 3 == 1) { cout << 1 << << 1 << << n - 2; } else { cout << 1 << << 2 << << n - 3; } return 0; }
#ifdef LOCAL #include <prettyprint.hpp> #endif #include<bits/stdc++.h> #define endl n #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define lg2(x) __lg(x) #define rem_dupl(x) sort(all(x)); x.erase(unique(all(x)), x.end()) using namespace std; typedef long long ll; ty...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; const int T = (1 << 21) + 123; long long a[T], b[T], s[T]; int p[N]; int n, m, d; int i, j, k, l; void upd(int i, int j, long long A, long long B, int l = 0, int r = d - 1, int q = 1) { if (!(i <= j && l <= r && l <= i &...
#include <bits/stdc++.h> using namespace std; int a, b, x, y, cnt; void RUL(int); void DLU(int); void LDR(int); void URD(int); void disp_res(int x, int y) { printf( %d %d n , x, y); exit(0); } void RUL(int n) { if (cnt == b) { disp_res(x, y); }; if (n <= 0) return; URD(n ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long int n; cin >> n; long long int a[n]; long long int mx = 0; long long int sum = 0; for (long long int i = 0; i < n; i++) { cin >> a[i]; mx = max(mx, a[i]); sum +...
#include <bits/stdc++.h> using namespace std; int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dx4[] = {1, 0, -1, 0}; int dy4[] = {0, 1, 0, -1}; template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << : << arg1 << n ; ; } te...
#include <bits/stdc++.h> using namespace std; int const MAX_N = 100001; int main() { int n, m; cin >> n >> m; vector<int> v; vector<int> u; int t = m; for (int i = 0; i < m; i++) { v.push_back((i + 1)); } for (int i = 0; i < m; i++) { u.push_back(v[(int)((v.size() + 1) ...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9 + 10; const int MOD = 1e9 + 7; const int N = 1e3 + 10; int n, k; int a[N]; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; if ((a[1] & 1) && (a[...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } long long gcd(long...
#include <bits/stdc++.h> using namespace std; int sum[64]; long long a[200200]; long long calc() { long long ans = 0; for (int i = 0; i < 64; i++) { ans += (1LL << i) * (sum[i] > 0); } return ans; } int main() { int n, k, x; cin >> n >> k >> x; for (int i = 1; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> v; long long s[100100]; void init() { scanf( %d , &n); scanf( %d , &k); v.resize(1 + n); for (int i = 1; i <= n; i++) scanf( %d , &v[i]); sort(v.begin() + 1, v.end()); v[0] = 0; s[0] = v[0]; for (int i = 1; i <...
#include <bits/stdc++.h> using namespace std; int main() { int n; ; scanf( %d , &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if ((j + i) % 2 == 0) printf( W ); else printf( B ); } printf( n ); } return 0; }
#include <bits/stdc++.h> using namespace std; long long a[60][60], b[60][60], n, m; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> b...
#include <bits/stdc++.h> using namespace std; const int MAX = 1000007; vector<int> edg[MAX]; int lvl[MAX]; multiset<int>* msets[MAX]; int k; void mergesets(int frm, int to, int height) { if (msets[frm]->size() > msets[to]->size()) { swap(msets[frm], msets[to]); } height *= 2; for (in...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, cnt1 = 0; cin >> n >> k; int y = k + 1; bool ab[y], a = false; for (int i = 0; i < y; i++) ab[i] = false; for (int i = 0; i < n; i++) { string x; cin >> x; for (int j = 0; j < x.length(); j++) { in...
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383279; const long double EPS = 1e-6; const int INF = 1e9 + 7; const long long MOD = INF; const long long maxn = 5e5 + 2; const long long HASH_MODS[] = {1000000007333, 1000000009367, 1000000075747, ...
#include <bits/stdc++.h> using namespace std; char inp[5]; void try_catch(long long int l, long long int r) { long long int mid = l + rand() % (r - l + 1); printf( %lld %lld n , mid, mid); fflush(stdout); scanf( %s , inp); if (inp[0] == Y ) exit(0); } int main() { srand(time(NULL)); ...
#include <bits/stdc++.h> using namespace std; const int M = 100000 + 10; int d[M]; long long int pred[M]; long long int a[M]; long long int dp[110][M]; long long int pres[M]; long long int dq[M]; long long int yk(int i, int k) { long long int val = dp[i][k] + pres[k]; return val; } int mai...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, t; int TM[maxn], wait, ans; priority_queue<int> in; int main() { scanf( %d%d , &n, &t); for (int i = 1; i <= n; ++i) scanf( %d , &TM[i]); for (int i = 1; i <= n + 1; ++i) { wait = t - i; if (wait < 0) bre...
#include <bits/stdc++.h> using namespace std; void run() { int n; scanf( %d , &n); if (n & 1) printf( %d %d n , 9, n - 9); else printf( %d %d n , 4, n - 4); } int main() { run(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int k; cin >> n >> k; string a; cin >> a; bool no = false; for (int i = 0; i < a.size(); i++) { if (a[i] == N && (i + k) <= a.size() && (i == 0 || a[i - 1] != N )) { int count = 0; int j; f...
#include <bits/stdc++.h> int a, n, m, k, p; int main() { std::cin >> n >> m, a = 0, p = 1; for (int i = 1; i <= n; ++i) { std::cin >> k; if (a + k <= m) a += k; else a = k, ++p; } std::cout << p; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c =...
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long a[(long long)1e5 + 10]; long long b[(long long)1e5 + 10]; long long c[(long long)1e5 + 10]; long long d[(long long)1e5 + 10]; int main() { cin >> n >> m >> k; for (long long i = 0; i < m; i++) { cin >> a[i] >> b[i] >>...
#include <bits/stdc++.h> using namespace std; int n; char s[711]; const int mod = 1e9 + 7; int kk[711][12], f[711][711][2]; int main() { scanf( %s , s + 1); n = strlen(s + 1); for (int j = 0; j <= 9; j++) { int num = s[n] - 0 ; if (j > num) { f[n][0][0] = num + 1; f[...
#include <bits/stdc++.h> using namespace std; const int MAXK = 1 << 12; const int P = 7340033; const int G = 3; const int MAXH = 30; int dp[MAXH + 7][MAXK + 7], buff[MAXK + 7]; int qpow(int a, int b) { if (b == 0) return 1; if (a == 0) return 0; int aux = qpow(1LL * a * a % P, b >> 1); if ...
#include <bits/stdc++.h> const int inf = 1e5 + 10; using namespace std; int main() { int to[5][5]; int a[5]; memset(a, 0, sizeof(a)); memset(to, 0, sizeof(to)); ios::sync_with_stdio(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == 0 ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0; string s; cin >> n; cin.ignore(); for (int i = 1; i <= n; i++) { getline(cin, s); if (s[1] == + ) { x++; continue; } if (s[1] == - ) { x--; continue; } } ...
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long POW(long long a, long long b, long long MMM = MOD) { long long ret = 1; for (; b; b >>= 1, a = (a * a) % MMM) if (b & 1) ret = (ret * a) % MMM; return ret; } long long gcd(long long a, long long b) { return b...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, n, day, ans, flag; cin >> n; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); day = 1; ans = 0; j = 0; while (1) { flag = 0; for (i = j; i < n; i++) { if ...
#include <bits/stdc++.h> using namespace std; long long bin_pow(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) { long long t = bin_pow(a, b / 2); return t * t % 1000000007; } else return a * bin_pow(a, b - 1) % 1000000007; } vector<long long> graph[500000]; boo...
#include <iostream> using namespace std; long long n,mod; long long cnt[55][2505]; long long cntS[55][2505]; long long per[55]; long long ans[55]; void calcCnt() { cnt[0][0]=1; for(int i=1;i<=n;i++) { for(int inv=0;inv<=i*i;inv++) for(int nval=1;nval...