func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const long long inf = LLONG_MAX / 2; const long long MX = 1e5 + 10; int a[MX]; set<int> s; vector<int> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (long long(i) = (0); (i) <= (n - 1); ++(i))...
#include <bits/stdc++.h> using namespace std; inline long long tr(long long d) { return d * (d + 1) / 2; } inline long long tr2(long long d) { return 2 * tr(d) - d; } int n; long long solve(int y, int x, long long c) { long long res = 4 * (tr(c + 1) - c - 1) + 1; if (c - (y + 1) >= 0) res -= tr2(c - (...
#include <bits/stdc++.h> using namespace std; void setIO(string name = ) { ios_base::sync_with_stdio(0); cin.tie(0); if (int((name).size())) { freopen((name + .in ).c_str(), r , stdin); freopen((name + .out ).c_str(), w , stdout); } } long long gcd(long long a, long long b) { r...
#include <bits/stdc++.h> #define int long long using namespace std; const int maxm=5e5+5; int stk[maxm],head; int d[maxm]; int a[maxm]; int n; // int rt[maxm],tot; int lc[maxm*40],rc[maxm*40],ma[maxm*40]; inline void pp(int k){ ma[k]=max(ma[lc[k]],ma[rc[k]]); } void update(int x,int val,...
#include <bits/stdc++.h> using namespace std; vector<long long int> fact(2000006); vector<long long int> prime_check(1e7 + 2); vector<long long int> primes; long long powmod(long long x, long long y, long long m) { long long res = 1LL; while (y) { if (y & 1) res = (res * x) % m; x = (x * x...
#include <bits/stdc++.h> using namespace std; void solve() { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if ((x1 <= x2 && y1 <= y2) || x1 + y1 <= max(x2, y2)) { cout << Polycarp ; } else { cout << Vasiliy ; } } int main() { ios_base::sync_with_stdio(false); cin.tie...
#include <bits/stdc++.h> using namespace std; char a[105], b[105]; int main() { int n, q, l, r; for (scanf( %d%d %s , &n, &q, a); q--;) { memcpy(b, a, sizeof(a)); scanf( %d%d , &l, &r); l--, r--; int s[10] = {0}, i = l, p = n, d = 1; for (; i >= l && i <= r; i += d) { ...
#include <bits/stdc++.h> using namespace std; int n, a[6], t; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &t), a[t]++; } if (a[0] == 0) { printf( -1 n ); return 0; } int k = a[5] / 9; for (int i = 0; i < k; i++) { printf( 555555555 );...
#include <bits/stdc++.h> const int MAXN = 210; const int mod = 1e9 + 7; void reduce(int& x) { x += x >> 31 & mod; } int mul(int x, int y) { return (long long)x * y % mod; } void fma(int& x, int y, int z) { x = ((long long)y * z + x) % mod; } struct vec { int x, y; vec() { x = y = 0; } vec(int a,...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; template <int mod = mod> struct Modular { int val; Modular() { val = 0; } Modular(long long _val) { val = Normalize(_val); } Modular(int _val) { val = Normalize(_val); } inline int Normalize(long long& _val) { if ...
#include <bits/stdc++.h> using namespace std; const int N = 505; long long dp_hor[2][N][N], dp_vert[2][N][N]; vector<pair<int, int>> cost_hor[N][N], cost_vert[N][N]; long long inf = 1e18; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ...
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX; int n; struct node { long double x, y; } a[100010]; bool check(long double xx) { long double l, r; l = -1e19, r = 1e19; for (int i = 0; i < n; ++i) { if (a[i].y >= xx * 2 || l > r) return false; l = max(l, a[i...
#include <bits/stdc++.h> #include <algorithm> #include <unordered_map> using namespace std; typedef long long ll; typedef vector<long long int> vll; typedef vector<int> vi; typedef unordered_map<int, int> umap; typedef vector<bool> vb; typedef pair<int, int> pii; typedef vector<pii> vpii; typed...
#include<bits/stdc++.h> using namespace std; int read() { char c=getchar(); int x=0,f=1; while (c< 0 || c> 9 ) { if (c== - ) f=-1; c=getchar(); } while (c>= 0 && c<= 9 ) { x=x*10+c- 0 ; c=getchar(); } return x*f; } const int p=998244353; int a[1200005],b[1200005],c[1200005]...
#include <bits/stdc++.h> using namespace std; const unsigned long long N = 1e10; int getLen(unsigned long long a) { int len = 0; while (a) { len++; a /= 10; } return len; } unsigned long long gcd(unsigned long long a, unsigned long long b) { return b == 0 ? a : gcd(b, (a % b));...
#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> using namespace std; const long long N = 300; inline long long read() { long long s = 0, ww = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) ww = -1; ch = getchar(); } while ( 0 <= ch && ch <= 9 ) { s = 10 * s + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int S; cin >> S; if (S == 1) { cout << 1 << << 1 << n ; cout << 1 << n ; return 0; } cout << (S - 1) * 2 << << 2 << n ; cout << 1 << << 2; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2000 + 10; bool mrk[MAX_N][MAX_N]; bool Ver[MAX_N][MAX_N]; bool Hor[MAX_N][MAX_N]; int N; int Total; void Solve(int x, int y) { bool flag = false; if ((mrk[x][y] ^ Ver[x][y] ^ Hor[x][y]) == 1) flag = true; int dx = -1, dy = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int m, n, i, j, l, r, u, d, sum; char s[209]; while (scanf( %d , &n) != EOF) { getchar(); scanf( %s , s); sum = 0; for (i = 0; i < n; i++) { l = r = u = d = 0; for (j = i + 1; j < n; j++) { int x...
#include <bits/stdc++.h> using namespace std; int p, numb, hh, i, j, l, n, m, a; char k; bool flag; int h[200000], check[500000], check1[500000], prime[500000], dp[500000]; int main() { for (i = 2; i <= 100000; i++) if (check[i] == 0) { for (j = 2 * i; j <= 100000; j += i) check[j] = 1; ...
#include <bits/stdc++.h> using namespace std; int n, a, b, k[100100]; const int du = 0.000001; bool cmp(int x, int y) { return x > y; } int main() { scanf( %d%d%d , &n, &a, &b); long long sum = 0; for (int i = 1; i <= n; ++i) { scanf( %d , &k[i]); sum += k[i]; } if (a == b) { ...
#include <bits/stdc++.h> using namespace std; inline long long int c(long long int n, long long int i) { if (i == 0) return 1; else if (i == 1) return n; else if (i == 2) return (n * (n - 1)) / 2; else if (i == 3) return (n * (n - 1) * (n - 2)) / 6; else if (i == 4) ...
#include <bits/stdc++.h> using namespace std; int f(int n) { if (n < 10) { return n; } int ans = 1; while (n) { if (n % 10 != 0) { ans *= n % 10; } n /= 10; } return ans; } int g[1000005]; int cnt[10][1000005]; int main() { ios::sync_with_stdio(fal...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int N = 100200; struct Node { int to, cost; }; vector<Node> g[N]; int dist[105][N] = {}, arr[N] = {}, n, m, type[N] = {}, k, s, vis[N] = {}; void addedge(int u, int v, int cost) { g[u].push_back((Node){v, cost}); g[v].p...
#include <bits/stdc++.h> using namespace std; long n, l, x, y, a[1 << 20]; set<long> has; long hx, hy; long ans; long thx, thy; void check(long ps) { if (ps < 0 || ps > l) return; hx = thx; hy = thy; if (has.find(ps + x) != has.end()) hx = 1; if (has.find(ps + y) != has.end()) hy = 1; ...
#include <bits/stdc++.h> using namespace std; int n, m; int k; bool debug = false; int a[105]; int main() { cin >> n; for (int i = 0, x; i < n; i++) { scanf( %d , &x); a[x]++; } for (int i = 0; i < 105; i++) k += a[i] / 2; printf( %d n , k / 2); return 0; }
#include <bits/stdc++.h> using namespace std; int t, n, m, a[1005], b[1005], ans; bool c[1005], lol; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { lol = false; fill(c, c + 1005, false); cin >> n >> m; for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> adj[200003]; vector<pair<int, pair<int, int>>> edges; vector<long long> len; set<int> vertices; void dijkstra(int start) { set<int> vis; priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<...
#include <bits/stdc++.h> using namespace std; signed main() { long long int t; cin >> t; while (t--) { long long int n, x, i; cin >> n >> x; long long int second = 0; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long n, k, l, a[1000010], m, p, q, b[1000010], d, c[1000010], f[1000010], g[1000010], ans; struct BIT { long long a[1000010]; void clear() { memset(a, 0, sizeof(a)); } void add(int x, long long v) { for ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 5; int n, q, m; const int N = 105; const int L = 1505; char s[maxn]; int tr[maxn][30], tot = 0; int fail[maxn], w[maxn]; vector<int> g[maxn]; void add(char *s, int id) { int u = 0; int n = strlen(...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 7; int n, m; vector<int> d[MAXN]; int r[MAXN]; vector<pair<int, int> > g[MAXN]; inline void add_edge(int u, int v, int c) { g[u].push_back(make_pair(c, v)); g[v].push_back(make_pair(c, u)); } int col[MAXN]; inline bool dfs(...
#include <bits/stdc++.h> using namespace std; const long long inf = 1ll << 60; int n; long long a[100100][4], f[100100][4], mx[4], sum[100100]; int main() { scanf( %d , &n); for (int j = 1; j <= 3; j++) { for (int i = 1; i <= n; i++) scanf( %I64d , &a[i][j]); } for (int i = 1; i <= n; i+...
#include <bits/stdc++.h> using namespace std; long long int arr[1000000]; int main() { int n; cin >> n; long long int count = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; } long long int Min = arr[0]; long long int Max = arr[0]; for (int i = 1; i < n; i++) { if (arr[...
#include <bits/stdc++.h> using namespace std; int main() { int a, k = 0, nod; cin >> a; for (int i = 2; i < a; i++) { int b = a; while (b != 0) { k += b % i; b /= i; } } int b = a - 2; for (int i = k; i > 0; i--) if (k % i == 0 && b % i == 0) { ...
#include <bits/stdc++.h> using namespace std; long long a[(20ll + (long long)2e5)], b[(20ll + (long long)2e5)], c[(20ll + (long long)2e5)], *d[(20ll + (long long)2e5)], e[(20ll + (long long)2e5)]; int main() { long long n; scanf( %lld , &n); for (long long i = 1; i <= n; i++) { scanf...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; struct Tree { int n; vector<long long> t; vector<int> mx; vector<int> val; vector<int> weights; void add_val(int v, int l, int r, int now) { t[v] = weights[v] * (long long)now; mx[v] = now; val[v] = no...
#include <bits/stdc++.h> using namespace std; int const N = 1e3 + 10, K = 10 + 2, E = -(1e8 + 10); long long dp[N][N][K][2]; int n, m, kk; string s, t; void read_input() { cin >> n >> m >> kk; cin >> s >> t; } void solve() { s = * + s, t = * + t; for (int i = 1; i <= n; i++) fo...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); ...
#include <bits/stdc++.h> using namespace std; const long long inf = 5e9; long long w[20], s[20], m; bool solve(int bm) { long long l = 0, r = m; for (int i = 0; i < 14; ++i) { if (bm % 3 == 0) l += w[i]; else if (bm % 3 == 1) r += w[i]; bm /= 3; } return l == r;...
#include <bits/stdc++.h> using namespace std; int main() { int n, b; cin >> n >> b; int a[n], maxx = b; for (int x = 0; x < n; x++) cin >> a[x]; for (int x = 0; x < n; x++) { for (int y = x + 1; y < n; y++) maxx = max(maxx, (b / a[x]) * a[y] + (b % a[x])); } cout << maxx; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int n, k; vector<vector<long long>> adj, leaf; vector<long long> level, par, out; vector<long long> counti; void dfs(int src, int lvl, int p = -1) { int child = 0; level[src] = lvl; for (auto it : adj[src]) { if (it =...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 77, L = 17; int n, q, tim = 1, root = 1; int b[N], d[N], Par[N][L], St[N], En[N]; long long S[N << 2], lz[N << 2]; inline void Shift(int l, int r, int id) { long long x = lz[id]; lz[id] = 0; S[id] += (r - l) * x; if (r - l ...
#include <bits/stdc++.h> using namespace std; long long int Pow(long long int a, long long int b, long long int md, long long int ans = 1) { for (; b; b >>= 1, a = a * a % md) if (b & 1) ans = ans * a % md; return ans % md; } const long long int MAXK = 1e6 + 10; const long lo...
#include <bits/stdc++.h> #define pb push_back #define speed ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef long double ld; typedef vector <ll> vll; typedef pair<ll,ll> pll; typedef vector <pair<ll,ll>> vpll; typedef vector <vll> vvll; ...
#include <bits/stdc++.h> using namespace std; long long a[200010]; long long vis[200100]; long long x, n, k, sum, y; string s; long long dfs(long long x, long long k, long long y) { if (x == y) return k; return dfs(a[x], k + 1, y); } long long poww(long long ba) { if (ba == 0) return 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; string s[maxn]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> s[i]; int ans = 6, cnt; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { cnt = 0; for (int k = 0; k < ...
#include <bits/stdc++.h> using namespace std; int main(void) { int t; long long s, a, b, c; scanf( %d , &t); while (t--) { scanf( %I64d %I64d %I64d %I64d , &s, &a, &b, &c); printf( %I64d n , s / c + s / c / a * b); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, j; cin >> s; for (i = 0; i < s.size(); i++) if (s[i] == . ) break; if (s[i - 1] == 9 ) { cout << GOTO Vasilisa. ; return 0; } if (s[i + 1] >= 5 ) s[i - 1]++; for (j = 0; j < i; j++) cout...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, n2; long long dip, cert, losers; cin >> n >> k; dip = n / (2 * (k + 1)); cert = k * dip; losers = n - dip - cert; cout << dip << << cert << << losers; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int a[25], b[25]; int dp[1 << 24]; int main() { int n, k; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); scanf( %d , &k); for (int i = 1; i <= k; i++) scanf( %d , &b[i]); dp[0] = 1; for (int i ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { if (x == 0) return y; return gcd(y % x, x); } int main() { int t; long long r, b, k; scanf( %d , &t); while (t--) { scanf( %I64d%I64d%I64d , &r, &b, &k); long long Gcd = gcd(r, b); r...
#include <bits/stdc++.h> using namespace std; long long a[1000000], prime[1000000]; vector<long long> v[3000000]; int main() { ios::sync_with_stdio(false); cin.tie(), cout.tie(); long long e; for (long long i = 3; i * i <= 1000000; i += 2) if (a[i] == 0) for (long long j = i * i; j...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) { long long n, k, s; cin >> n >> k >> s; if (s >= k && s <= k * (n - 1)) { long long step = s / k; long long x = s - k * ...
#include <bits/stdc++.h> using namespace std; const int N = 5023; int grundy[N], canCut[N], mex[N]; void init() { memset(grundy, 0, sizeof(grundy)); memset(canCut, 0, sizeof(canCut)); for (int i = 1; i < N; i++) { for (int j = 0; j < i; j++) { mex[grundy[max(0, j - 1)] ^ grundy[max(0, ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; map<int, int> mp; vector<int> ans; int a; for (int i = 0; i < n; i++) { scanf( %d , &a); mp[a] = 1; } n = m; for (int i = 1; i <= n; i++) { if (i > m) break; if (mp[i] == 0...
#include <bits/stdc++.h> using namespace std; int n, cnt, T; vector<int> g[128]; void input(int x) { if (g[x].size()) return; if (cnt == 16) { g[x].push_back(1), g[x].push_back(1); return; } cnt++; printf( ? %d n , x); fflush(stdout); int nw, y; scanf( %d , &nw); ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1000000000; const ll LINF = 1001002003004005006ll; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > h; vector<vector<long long> > g; long long p[500001][21]; long long volume[500001]; long long n, dt, ans, s, f; void dfs(long long v, long long m) { p[v][0] = m; for (long long i = 0; i < g[v].size(); i++) { lo...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; char s[5005], t[5005]; long long DP[5005][5005]; int main(int argc, char** argv) { scanf( %s%s , s, t); int lens = strlen(s); int lent = strlen(t); long long ans = 0; for (int i = 1; i <= lens; i++) { for...
#include <bits/stdc++.h> using ::std::cin; using ::std::cout; using ::std::endl; using ::std::multiset; using ::std::pair; using ::std::vector; int main() { ::std::ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; const int N = 500010; int ans[N]; void solve() { int n; cin >> n; int d = 0; for (int i = 0; i <= 30; i++) { ans[i] = (1 << i); } int sum = 0; for (int i = 0; i <= 30; i++) { sum += ans[i]; if (sum >= n) { d = i;...
#include <bits/stdc++.h> const double PI = 3.1415926535897932384626; const int KL = 1e6; const long long MOD = 1e9 + 7; using namespace std; void show(complex<double> a) { cout << fixed << setprecision(10) << a.real() << + << a.imag() << i << endl; } complex<double> rot(complex<double> ...
#include <bits/stdc++.h> struct SFountain { size_t beauty; size_t price; SFountain() = default; SFountain(size_t b, size_t p) : beauty(b), price(p) {} static bool less_price(const SFountain &lhs, const SFountain &rhs) { return lhs.price < rhs.price; } static bool less_beauty(const SF...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, -1, 1, -1, -1, 1, 1}; int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1}; bool mark[100007]; long long int n, in = -1, prime[100007]; void seive() { prime[++in] = 2; for (long long int i = 3; i * i < 100007; i += 2) { if (mark[i] == 0) ...
#include <bits/stdc++.h> using namespace std; int n; int a[200001]; vector<int> G[200001]; int res[200001]; vector<int> divisor; vector<int> now; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } void dfs(int v, int p) { for (int i = 0; i < G[v].size(); i++) { i...
#include <bits/stdc++.h> using namespace std; #define int long long void solve() { int n, m, k; cin >> n >> m >> k; vector<tuple<int, int, int>> edges(m + 2), edges_large, edges_small; vector<int> values; for (int i = 1; i <= m; i++) { int a, b, c; c...
#include <bits/stdc++.h> using namespace std; long long int visited[100001]; vector<long long int> adj[100001]; long long int sum = 0; void dfs(long long int s) { if (visited[s] == 1) { return; } sum++; visited[s] = 1; for (auto u : adj[s]) { dfs(u); } } long long int b...
#include <bits/stdc++.h> using namespace std; long long dp[10010], leftx[10010], rightx[10010], l[5010], r[5010]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, x; cin >> n >> x; vector<int> ry; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; l[i] ...
#include <bits/stdc++.h> bool chCount[26]; int main() { int n, m; std::cin >> n >> m; int max = -1; for (; n >= 1; --n) { int min = 1000000000 + 10; for (int i = 0; i < m; ++i) { int x; std::cin >> x; min = std::min(x, min); } max = std::max(min, max);...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a, m; cin >> a >> m; a %= m; map<int, bool> vis; while (!vis[a]) { vis[a] = true; if (!a) { cout << Yes n ; return 0; } a *= 2; a %= m; ...
#include <bits/stdc++.h> using namespace std; const int nMax = 100007; int parent[nMax]; vector<int> g[nMax]; bool used[nMax]; void dfs(int root, int parent, int& cnt, int b, bool& bad) { if (root == b) { bad = true; } used[root] = true; ++cnt; for (int i = 0; i < g[root].size(); +...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; const int size = 1 << 8, M = 1e6 + 10; int n, q, w[N], head[N], ne[N], cnt; void add(int f, int t) { w[++cnt] = t; ne[cnt] = head[f]; head[f] = cnt; } int fa[N], a[N], h[N]; void dfs(int x) { for (int i = head[x]; i; i ...
#include <bits/stdc++.h> using namespace std; const int n = 10000; long long qm[6][n + 2]; void ask(int i, long long b) { int j = min(b, (long long)n); vector<long long> v; long long r = qm[i - 1][j]; for (int s = 1; s <= j; ++s) { v.push_back(r + b); ++r; r += qm[i - 1][min(r ...
#include <bits/stdc++.h> using namespace std; void swap(int &a, int &b) { int temp; temp = a; a = b; b = temp; } void printarr(int a[], int n) { for (int i = 0; i < 2 * n; i++) cout << a[i] << ; cout << endl; } int main() { long long int n, k, v; cin >> n; int a[2 * n]...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int add(int a, int b) { return a + b - (a + b >= MOD) * MOD; } int mult(int a, int b) { return ((long long)a * b) % MOD; } int n, h, w; char s[500013]; int dX[200], dY[200]; int diffx, diffy; int maxx, minx; int maxy, miny; int...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } inline void R(int &xx) { xx = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) ch = getchar(); while (ch >= 0 && ch <= 9 ) xx = xx + xx + (xx << 3) + ch - 48, ch = g...
#include <bits/stdc++.h> using namespace std; vector<long long> b, c; long long s[1000000]; long long d[1000000]; int F(long long x) { vector<long long> a = b; a.push_back(x); sort(a.rbegin(), a.rend()); long long n = a.size(); s[0] = 0; for (int i = 1; i <= n; ++i) { s[i] = s[i ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; const int MN = 1e5 + 10; int n, a[MN << 1], b[MN << 1]; struct cmp { bool operator()(const int &x, const int &y) { if (a[x] + b[x] != a[y] + b[y]) return a[x] + b[x] > a[y] + b[y]; return x > y; } }; set<int, cmp> ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char c = getchar(), f = 0; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) f = 1; for (; c >= 0 && c <= 9 ; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -...
#include <bits/stdc++.h> using namespace std; const int SIZE = 20 + 5; const int Mod = 1e9 + 7; int inv[SIZE], n; long long a[SIZE], m, ans; inline long long read() { char ch = getchar(); long long f = 1, x = 0; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; const int MX = 1e5 + 5; int n; int M[9][2] = {{0, 0}, {-1, -1}, {1, 1}, {0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, -1}, {-1, 1}}; int compute(vector<int> Arr, int A0, int A1, int val) { Arr[0] = A0; Arr[1] = A1; int d = Arr[1] - Arr[0]; ...
#include <bits/stdc++.h> const int N = 200100; char a[N], b[N]; int cnt[330]; int main() { int la, lb, i; long long ans = 0; scanf( %s%s , a, b); la = strlen(a), lb = strlen(b); for (i = 0; i < lb - la; i++) cnt[b[i]]++; for (i = 0; i < la; i++) { cnt[b[lb - la + i]]++; if (a...
#include <bits/stdc++.h> using namespace std; int f[1100000], p[1100000], n, m, a[110], b[30], c[30]; char cc; bool cmp(int a, int b) { return a > b; } void init() { scanf( %d , &n); for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]); sort(a + 1, a + 1 + n, cmp); scanf( %d n , &n); for (i...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> arr(n); vector<pair<int, int>> sorted_arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; sorted_arr[i] = {arr[i], i}; } sort(sorted_arr.begin(), sorted_arr.end()); vector<int> pos(...
#include <bits/stdc++.h> using namespace std; long long n; long long s(long long x) { long long ans = 0; while (x) ans += x % 10, x /= 10; return ans; } long long solve(long long x) { return x * x + s(x) * x - n; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> ...
#include <bits/stdc++.h> using namespace std; double y111, y222, yw, xb, yb, r; double ASIN(double w) { if (w < -1.0) w = -1.0; if (w > 1.0) w = 1.0; return asin(w); } int main() { cin >> y111 >> y222 >> yw >> xb >> yb >> r; y111 += 1E-9; y222 -= 1E-9; double st = yw - r; doubl...
#include <bits/stdc++.h> using namespace std; const double sn = 1e-6; int n, k; char arr[55][10]; string s[55]; string res[55]; int main() { scanf( %d%d , &n, &k); for (int i = 0; i < n - k + 1; i++) { scanf( %s , arr[i]); string st(arr[i]); s[i] = st; } string val = Aa ...
#include <bits/stdc++.h> using namespace std; int main() { string x; cin >> x; int y; if (x.size() == 1) { y = x[0] - 0 ; if (!(y % 4)) cout << 4; else cout << 0; return 0; } y = x[x.size() - 1] - 0 + ((x[x.size() - 2] - 0 ) * 10); if (!(y % 4)...
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { if (a < b) return a; else return b; } int main() { int n, a, b, c, j; bool t = false; cin >> n; for (int i = 0; i < (4); ++i) { cin >> a >> b; if (a < 1 || b < 1) c = n + 1; else ...
#include <bits/stdc++.h> using namespace std; const int N = 102; double dp[N][N][N][3]; int vis[N][N][N][3]; double call(int r, int s, int p, int id) { if (id == 0) { if (r == 0) return 0; if (s + p == 0) return 1; } else if (id == 1) { if (s == 0) return 0; if (r + p == 0) ret...
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238; 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; } long long f...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int ti = 0; ti < t; ti++) { int n, k; cin >> n >> k; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); vector<int> weights(k); for (int i ...
#include <bits/stdc++.h> long long ago; using namespace std; template <class T = long long int> T nxt() { T x; cin >> x; return x; } long long int pw(long long int a, long long int b, long long int mod) { if (!b) return 1; if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod; retu...
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; cin >> n >> s; vector<int> vec; for (int i = 0; i < s.length(); ++i) { if (s[i] == B ) { int res = 0; while (i < s.length() && s[i] == B ) { ++res; ++i; } vec.p...
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5; struct NOOD { int flag; int l; int r; int v; } num[MaxN + 5]; int ans[MaxN + 5], p[MaxN + 5]; bool ok[MaxN + 5], flag; int Max; int n, m; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { ...
#include <bits/stdc++.h> using namespace std; long long solve() { long long n, i, j, k; cin >> n >> k; long long arr[n]; for (i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); j = 0; for (i = 0; i < n && arr[i] < 0; i += k) j += 2 * abs(arr[i]); for (i = n - 1; i >= 0 && arr[i] >...
#include <bits/stdc++.h> using namespace std; int main() { int n; string a, b, tem; scanf( %d , &n); a = <3 ; for (int i = 0, j = 0; i < n; ++i) { cin >> tem; a += tem; a += <3 ; } cin >> b; int len1 = a.length(), po1 = 0, po2 = 0; int len2 = b.length(); w...