func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string a[1000], b[1000]; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } for (int i = 0; i < m; i++) { string cmd, ip, tip; cin >> cmd >> ip; for (int i = 0; i < ip.size() - 1; i+...
#include <bits/stdc++.h> using namespace std; int n, k, ans = 1 << 30; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= k - 1; i++) if (n % i == 0) ans = min(ans, k * n / i + i); printf( %d n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, i, j; const double eps = 1e-9; struct nd { double x, y; }; nd operator-(nd x, nd y) { return (nd){x.x - y.x, x.y - y.y}; } bool cmp(nd x, nd y) { if (x.x == y.x) return x.y < y.y; return x.x < y.x; } double dis(nd x, nd y) { return ab...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > ps, is, psum(100001), isum(100001); long long m, n, d; class cmp { public: bool operator()(pair<long long, long long> &a, pair<long long, long long> &b) { return a.first > b.first || (a.first == b....
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; long long arr[n], ans[n]; for (long long i = 0; i < n; i++) arr[i] = 1; ans[n - 1] = 1; for (long long i = 2; i <= n; i++) { arr[n - 1] = i; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const long double pi = acos(-1.0); const int N = 2e5 + 100; int tr[4 * N]; int inicial[N]; int v[4 * N]; int n; void build(int node, int b, int e) { if (b == e) tr[node] = b...
#include <bits/stdc++.h> using namespace std; int n, m, q, w[15]; char s[15]; int cnt[5005]; int sum[5000][105]; int tot2[15]; int main() { scanf( %d%d%d , &n, &m, &q); tot2[0] = 1; for (int i = 1; i <= 14; i++) tot2[i] = tot2[i - 1] * 2; for (int i = 1; i <= n; i++) scanf( %d , &w[i]); ...
#include <bits/stdc++.h> using namespace std; inline void rd(int &x) { x = 0; char o, f = 1; while (o = getchar(), o < 48) if (o == 45) f = -f; do x = (x << 3) + (x << 1) + (o ^ 48); while (o = getchar(), o > 47); x *= f; } int head[100005], to[100005 << 1], nxt[100005 << 1], tot; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9; const int SIZE = 1e6 + 5; const long long INF = 1LL << 55; const double eps = 1e-10; int d[1000009]; int main() { int(n); scanf( %d , &n); if (n % 2) { int h = n / 2; for (int i = 0; i < (h); ++i) { d[...
#include <bits/stdc++.h> using namespace std; const int NMAX = 1000000; vector<int> graf[1 + NMAX]; int minim[1 + NMAX]; int minimLant = INT_MAX; bool vizitat[1 + NMAX]; void dfs(int z) { for (int i = 0; i < graf[z].size(); i++) { if (!vizitat[graf[z][i]]) { vizitat[graf[z][i]] = true; ...
#include <bits/stdc++.h> using namespace std; int n, q, A[1005], B[1005], x, y; int main() { scanf( %d %d , &n, &q); for (int i = 1; i <= q; i++) { scanf( %d %d , &x, &y); A[x] = 1; B[y] = 1; } int cev = 0; for (int i = 2; i < n; i++) { cev += !A[i] + !B[i]; } i...
#include <bits/stdc++.h> using namespace std; long long int n, m, p; long long int a[2105][2105]; long long int sz[2105 * 2105]; long long int fa[2105 * 2105]; pair<long long int, pair<long long int, long long int> > arr[2105 * 2105]; const int mv[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; long long in...
#include <bits/stdc++.h> using namespace std; vector<long long int> ans; vector<long long int> allD; unordered_map<long long int, int> comp; const int MM = 1e4; const int LIM = 1e5; vector<long long int> gr[MM]; void solve(long long int N, long long int K) { if (K == 0 || N == 0) { ans.push_ba...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5; const int MAXM = 5e6; int N; pii A[MAXN+10]; pii B[MAXM+10], C[MAXM+10]; int main() { scanf( %d , &N); for(int i=1; i<=N; i++) scanf(...
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n; n += 1; int h[n]; for (int i = 1; i < n; i++) cin >> h[i]; h[0] = 0; int energy = 0; int max_energy = 0; for (int i = 0; i < (n); ++i) { if (i == 0) continue; energy += h[i - 1] - h[i]; ...
#include <bits/stdc++.h> using namespace std; template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T min(T a, T b, T c, T d) { return min(a, min(b, min(c, d))); } template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 41; const int MASK = 1 << 21; long long sz[MAX_N], par[MAX_N], po2[MAX_N], vis[MAX_N]; long long dp[MASK]; vector<int> adj[MAX_N]; int rt(int v) { return v ^ par[v] ? par[v] = rt(par[v]) : v; } void join(int u, int v) { if ((u = rt(u)) ...
#include <bits/stdc++.h> using namespace std; set<pair<long long int, long long int> > s; pair<long long int, long long int> p; long long int d[300000], x, n, k, l = 0, di = 0; vector<long long int> v[300000]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; for ...
#include <bits/stdc++.h> using namespace std; int n, m, s, tot; int a[5005], b[5005], c[5005], last[5005]; vector<int> edge[5005]; int cmp(int i, int j) { return c[i] > c[j]; } long long dp[5005][5005]; int main() { scanf( %d%d%d , &n, &m, &s); int temp = s; for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const double eps = 1e-9; double mi[N], ma[N]; double pre1[N], pre2[N]; double ans1[N], ans2[N]; int main() { int n; scanf( %d , &n); for (int i = (1); i <= (n); i++) cin >> ma[i]; for (int i = (1); i <= (n); i++) cin >> m...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; n = n / 2; if ((n == x || n == x - 1) && (n == y || n == y - 1)) cout << NO << endl; else cout << YES << endl; }
#include <bits/stdc++.h> int n; int main() { scanf( %d , &n); printf( %d n , n % 5 % 3 + 1); }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; void solve() { long long n; cin >> n; if (n < 6) cout << -1 << endl; else { cout << 1 2 n2 3 n2 4 n1 5 n1 6 n ; for (long long i = 7; i <= n; i++) { cout << 2 << << i << endl; } ...
#include <bits/stdc++.h> using namespace std; long long pot[35]; int numbits(long long n) { int conta = 0; for (int i = 0; i <= 33; i++) { if (n & pot[i]) conta++; } return conta; } int main() { pot[0] = 1; for (int i = 1; i <= 33; i++) pot[i] = 2 * pot[i - 1]; long long n, p...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int a[6]; for (int i = 0; i < 6; i++) { a[i] = s[i] - 48; } int sum1 = a[0] + a[1] + a[2]; int sum2 = a[3] + a[4] + a[5]; int difference = abs(sum1 - sum2); int flag = 0; if (sum1 > sum2) fla...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int low = 0, up = 0; for (int i = 0; i < s.size(); i++) { if (s[i] < 93) { up++; } else { low++; } } if (low >= up) { for (int i = 0; i < s.size(); i++) { s[i] = tol...
#include <bits/stdc++.h> using namespace std; int p[500005], q[500005], c[500005], f[500005], siz[500005], fx[500005], sizx[500005], cln[500005 * 2], ans[500005], qu[500005], id[500005]; struct edge { int u, v, w, nxt, id; } e[500005]; vector<int> a[500005]; inline int find(int); void swap(int& ...
#include <bits/stdc++.h> using namespace std; const int desll[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const long long mod = 1e9 + 7; const int maxn = 1e6 + 7; const int maxm = 1e8 + 7; const double eps = 1e-4; int m, n, ar[maxn]; char ch[maxn]; int armid[maxn]; struct node { int val, num; ...
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); int c, m, t, r, i, W[301], tot, j; map<int, bool> used; map<int, bool> ends; map<int, bool> G; cin >> m >> t >> r; for (i = 0; i < m; i++) { c...
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n >> k; if (k >= (n * (n - 1)) / 2) cout << no solution ; else { for (int i = 0; i < n; ++i) cout << 0 << << i << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; cout << 0 0 << endl; int l = 1, r = (int)1e9, mid = l + (r - l) / 2; string s; cin >> s; int first; if (s[0] == b ) { first = 0; } else { fi...
#include <bits/stdc++.h> using namespace std; const int MAX = 3e5 + 5; pair<long double, int> x[MAX]; int main() { ios::sync_with_stdio(false); int n, id, k; cin >> n; for (int i = 0; i < (int)(n); i++) { cin >> x[i].first; x[i].second = i + 1; } cin >> k; sort(x, x + n);...
#include <bits/stdc++.h> using namespace std; inline long long getnum() { char c = getchar(); long long num, sign = 1; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) sign = -1; for (num = 0; c >= 0 && c <= 9 ;) { c -= 0 ; num = num * 10 + c; c = getchar(); } ...
#include <bits/stdc++.h> using namespace std; void FREOPEN() {} inline double Time() { return (clock() * 1.0) / CLOCKS_PER_SEC; } const int N = (int)200500, inf = (int)2e9, MOD = (int)1e9 + 7, alph = 26, C = 9; char CH[N]; const long long INF = (long long)1e18; const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1}...
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<vector<int> > Dist, Alist; vector<int> Distance, GivenPath; int mi, ma; bool isThere(int u, vector<int>& alist) { for (auto e : alist) { if (e == u) return true; } return false; } int main() { cin >> n >> m; vect...
#include <bits/stdc++.h> using namespace std; inline long long bip(long long x, long long n, long long mod) { long long res = 1; while (n) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; } const int maxn = 1e9; const long long i...
#include <bits/stdc++.h> const int Inf = (int)(1e9); const int K = 1000 + 1; const int N = 60 + 1; int w[N][N][N]; int n, m, r; int ans[K][N][N]; void prepare() { for (int i = 0; i < K; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k) ans[i][j][k] = Inf; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long mod = 998244353; int LIMIT; long long modpow(long long b, long long e) { long long ans = 1; for (; e; b = b * b % mod, e /= 2) if (e & 1) ans = ans * b % mod; re...
#include <bits/stdc++.h> using namespace std; const int N = 2e5; bool vis[N]; int n, m, ans; vector<int> top; vector<pair<int, int> > adj[N]; void dfs(int u) { vis[u] = 1; for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i].first; if (!vis[v]) dfs(v); } top.push_back(u)...
#include <bits/stdc++.h> using namespace std; int main() { long long num, length, devisor = 1, rest; long long i; string str; cin >> str; length = str.length(); num = atoi(str.c_str()); for (i = 1; i <= length - 1; i++) { devisor *= 10; } rest = num % devisor; cout << d...
#include <bits/stdc++.h> using namespace std; struct st { long long kici, san; long long kici2, san2; }; long long v[200010]; st T[200010 * 4]; long long t, x, y, q; long long n, k, S, O; void upd(long long pos, long long x, long long l, long long r, long long node) { if (l == r) { v[p...
#include <bits/stdc++.h> using namespace std; vector<int> p; vector<int> cor; int total; void dfs_visit(vector<vector<int>>& adj, int i) { cor[i] = 1; for (int j : adj[i]) { if (cor[j] == 1) { total++; } if (cor[j] == 0) { p[j] = i; dfs_visit(adj, j); } ...
#include <bits/stdc++.h> using namespace std; int sy, a, b, n, l[200010], r[200010], sum[200010], m, x, y; double xl, xr, ans; int getmid(double xi) { int L = 1, R = n + 1, ret, mid; while (L < R) { mid = (L + R) >> 1; if (l[mid] <= xi) ret = mid, L = mid + 1; else R = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; bool flag[maxn]; int phi[maxn]; vector<int> prime; vector<int> fin[6][maxn]; int a[10][10], num; void get_prime_phi() { phi[1] = 1; for (int i = 2; i < 1e5; i++) { if (!flag[i]) { prime.push_back(i); p...
#include <bits/stdc++.h> using namespace std; template <typename T> void dbg_vector(const T& v) { for (size_t i = 0; i < v.size(); ++i) cout << v[i] << ; cout << endl; } void dbg() { cerr << endl; } template <typename Head, typename... Tail> void dbg(Head H, Tail... T) { cerr << H << ; ...
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 1e5 + 5; int n; int in[N]; void solve(int x, int y) { int res = 0; while (x <= y) { res++; for (int i = 1; i <= n; i++) { if (in[i] == x) x++; } } cout << res << n ; } int ma...
#include <bits/stdc++.h> using namespace std; const long long N = 2 * 1e5 + 100; long long t, n; struct node { long long m, p; } sh[N]; bool cmp(node a, node b) { return a.m > b.m; } signed main() { scanf( %lld , &t); while (t--) { scanf( %lld , &n); for (long long i = 1; i <= n; i...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int inf = INT_MAX; const int N = 100004; const int modn = 1000000007; complex<long long> v[N]; int p[N]; long long x(complex<long long> a) { return a.real(); } long long y(complex<long long> a) { return a.imag(); } long lon...
#include <bits/stdc++.h> using namespace std; const int maxn = 2100; int n, al; double P; int main() { ios_base::sync_with_stdio(false); cin >> n >> P; al = n * (n - 1) * (n - 2) / 6; int ans = n; for (int i = 0; i <= n; i++) { double temp = 0; if (i >= 1 && n - i - 1 >= 0) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; cout << (abs((b % n) + a + n) % n > 0 ? abs((b % n) + a + n) % n : n); }
#include <bits/stdc++.h> using namespace std; int main() { int n, normg, bekg, uykg, beksur, uyksur; int i, j, x, y, t = 0, A[1000][2], fark; cin >> n >> normg >> bekg >> uykg >> beksur >> uyksur; for (i = 1; i <= n; i++) cin >> A[i][0] >> A[i][1]; for (i = 1; i <= n; i++) { t += abs(A[i][...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans[n]; int a, b, c; cout << ? 1 2 << endl; cin >> a; cout << ? 1 3 << endl; cin >> b; cout << ? 2 3 << endl; cin >> c; ans[0] = ((a + b + c) / 2) - c; ans[1] = ((a + b + c) / 2) - b...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, w = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) w = -1; c = getchar(); } while (c <= 9 && c >= 0 ) { x = (x << 1) + (x << 3) + c - 0 ; c = getchar(); } return w ...
#include <bits/stdc++.h> using namespace std; long long GI(long long &a) { return scanf( %I64d , &a); } long long n, i, j, k, tmp, m; long long arr[100100]; string s, s1; int32_t main() { getline(cin, s1); getline(std::cin, s); k = 0; for (long long i = 0; i < s1.length(); i++) k = k * 10 + ...
#include <bits/stdc++.h> using namespace std; int a[360360 + 1], k; int func(int from, int to) { int i, j; for (i = 0; i <= 360360; i++) a[i] = 100000000; if (from == 0) from = 360360; a[from] = 0; for (i = 360360; i > 0; i--) { if (a[i] == 100000000) continue; if (a[i - 1] > 1 + a...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n == 5) { cout << 2 << << 4 << n ; } else cout << 2 << << n / 2 << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m; long long ans, c[N], a[N]; vector<pair<int, int> > v[N], store; int main() { scanf( %d%d , &n, &m); long long k = n / m, x = 0, res = 0; for (int i = 0; i < n; ++i) { scanf( %lld , a + i); v[a[i] % m].push...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; string s = <3 ; for (int i = 0; i < n; i++) { string a; cin >> a; s += a; s += <3 ; } string b; cin >> b; long long int j = 0; for (int i = 0; i < b.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<long long> a(n); vector<long long> v; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) { v.push_back(abs(a[i] - a[i + 1])); } long long ans = a[n - 1] - a[0]; ...
#include <bits/stdc++.h> int a[51][51]; int p[51]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]); for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { if (p[i] != 0) continue; int sum = 0; ...
#include <bits/stdc++.h> int main() { int n, i, sum = 0, last = -1e8, c, k; scanf( %d%d , &n, &c); for (i = 1; i <= n; i++) { scanf( %d , &k); if (k - last > c) { sum = 1; last = k; } else { sum++; last = k; } } printf( %d , sum); }
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, prnt[N]; long long k; long long sum = 0; vector<int> g[N]; int sz[N]; void DFS(int node, int prnt) { sz[node] = 1; for (int i = 0; i < (int)g[node].size(); i++) { if (g[node][i] == prnt) continue; DFS(g[node][...
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265359; int main() { int n; long long p; cin >> n >> p; p /= 2; vector<int> a; for (int i = 0; i < n; i++) { string s; cin >> s; if (s == half ) a.push_back(0); else a.push_back(...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 30, Mod = 1e9 + 7; const long long SQ = 330; const long long INF = 1e17; long long a[N], n, q; long long sum[N << 2], mx[N << 2]; void Change(int x, int val, int id = 1, int b = 0, int e = n) { if (e - b == 1) { mx[id] = a[x...
#include <bits/stdc++.h> using namespace std; int Fac[1000010], IFac[1000010]; void gcd2(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return; } gcd2(b, a % b, x, y); long long t = x; x = y, y = t - a / b * y; } int Inv(int n) { long lo...
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::pair; using std::string; using std::vector; using vi = vector<int>; using pii = pair<int, int>; using vii = vector<pii>; using ll = long long; int solve(); int main(int argc, char* argv[]) { ::std::ios::syn...
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 5; map<long long int, long long int> m; long long int n, ans; void init() { m[-1] = -1; m[2e9] = 2e9; m[1] = n; ans = n; } void add(long long int l, long long int r) { m[l] = r; ans += r - l + 1; } void...
#include <bits/stdc++.h> using namespace std; const int N = 201110, M = 501110; int n, m, numeven, numodd; int a[N]; stack<int> odd, even; map<int, int> mp; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); mp[a[i]]++; if (a[i] % 2 == 0) ...
#include <bits/stdc++.h> using namespace std; struct edge { int v, c, i, d; edge(int v, int c, int i, int d) : v(v), c(c), i(i), d(d) {} }; vector<vector<edge> > g(200005); int n, m, d[200005], f[200005]; int main() { cin >> n >> m; for (int _n = m, i = 0; i < _n; ++i) { int a, b, c; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e8; const int MX = 2e5 + 5; vector<int> vorder; int dup[MX], lc[MX], rc[MX], good[MX], seek[MX]; string labels, corder; void ino(int curr) { if (curr == -1) return; ino(lc[curr]); vorder.push_back(curr); corder += labels[curr];...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; if (n % 3) { cout << 0; return 0; } n /= 3; vector<long long> d; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { d.push_...
#include <bits/stdc++.h> using namespace std; int main() { int64_t a, b, x, y, z; scanf( %I64d%I64d%I64d%I64d%I64d , &a, &b, &x, &y, &z); int64_t addA, addB; if (2LL * x + y - a > 0) addA = 2LL * x + y - a; else int64_t addA = 0; if (3LL * z + y - b > 0) addB = 3LL * z + y ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, k, l; cin >> n >> m; string s, t; cin >> s >> t; if (s == t) { cout << Yes << endl; return 0; } long long int present = 0; long long int flag = 0; for (i = 0; i < s.length(); i++) {...
#include <bits/stdc++.h> using namespace std; bool eq(long double l1, long double l2) { return abs(l1 - l2) < 1e-15; } int main() { const string names[] = { Vanya , Vova , Both }; vector<pair<long double, char>> v; int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= x; i++) { v.push_...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long inf = 1e17; long long v[N]; long long c[N]; long long dp[N]; bool mark[N]; long long n, q; long long a, b; void solver() { cin >> a >> b; long long max1 = 0; long long color1 = 0; long long max...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; int n, neg = 0; cin >> n; vector<int> a(2 * n - 1); bool zero = false; long long sum = 0; for (int i = 0; i < 2 * n - 1; ++i) { cin >> ...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3 ) int t, h[2000010], v[2000010 * 2], nxt[2000010 * 2], ec, in[2000010], n, a, b; char s[2000010]; void add(int x, int y) { v[++ec] = y; in[y]++; nxt[ec] = h[x]; h[x] = ec; } void adj(int x, int y) { add(x, y); a...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void prn(Arg1&& arg1) { cout << arg1 << n ; } template <typename Arg1, typename... Args> void prn(Arg1&& arg1, Args&&... args) { cout << arg1 << ; prn(args...); } template <typename Arg1> void prs(Arg1&& arg1) { ...
#include <bits/stdc++.h> const int V = 1e6, M = 1e9 + 7; struct edge { int v, c, nxt; } g[V]; int n, m, k, t, dep[V], q[V], l, r, d[7], head[V], dis[V], a1[V], a2[V], a3[V]; std::vector<int> h[V]; inline void Insert(int u, int v, int c) { g[++k] = (edge){v, c, head[u]}; head[u] = k; } bool C...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n + 1]; for (int i = 0; i < n; i++) scanf( %d , &arr[i]); int sums = 0; int sumd = 0; bool turns = true; int l = 0, r = n - 1; while (l <= r) { if (turns) { sums += max(arr[l], arr[r...
#include <bits/stdc++.h> using namespace std; const int big = 1e9; int dp[83][83][83][83], d[100][100]; int s[100][100][100], s1[100][100][100]; int n, kt, m, u, v, c; int main() { cin >> n >> kt >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) d[i][j] = -1; for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; int A[100005]; map<int, int> mymap; int main() { int n; map<int, int>::iterator it; int d; cin >> n; for (int i = 0; i < n; i++) { cin >> A[i]; mymap[A[i]]++; d = A[i]; while (mymap[d] % 2 == 0) { mymap[d + 1]++; ...
#include <bits/stdc++.h> using namespace std; int n; string col[1000]; int main() { cin >> n >> col[0]; for (int i = 1; i < 1000; ++i) col[i] = col[0]; for (int i = 0, a, b; i < n; ++i) { scanf( %d%d , &a, &b); char now = col[0][i]; for (int j = b; j < 1000; j += a) { now =...
#include <bits/stdc++.h> using namespace std; const int MAXN = 900; vector<int> neighbours[MAXN + 1]; vector<int> neighboursNoBridge[MAXN + 1]; vector<pair<int, int> > bridges; bool used[MAXN + 1]; int timer, tin[MAXN + 1], fup[MAXN + 1]; void dfs(int node, int parent = -1) { used[node] = true; ...
#include <bits/stdc++.h> using namespace std; int a[1000000 + 5]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } bool can = false; ...
#include <bits/stdc++.h> using namespace std; long long int r, c; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> r >> c; while (r--) cin >> s; long long int ans = 0; for (long long int i = 0; i <= c - 1; ++i) { if (s[i] != B ) continue; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n; cin >> n; cout << (n - 1) / 2; return 0; }
#include <bits/stdc++.h> long long p[2750131 + 5]; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } long long left = 0, right = n - 1, pas...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; char s[5010]; long long dp[5010][5010]; bool vis[5010][5010]; long long f(int i, int ind, int n) { if (vis[i][ind]) return dp[i][ind]; if (i > n) { if (ind == 0) return 1; return 0; } long long ans = 0; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int l[maxn], r[maxn], a[maxn], pos[40]; map<int, int> m; int main() { int n; scanf( %d , &n); long long ans = (long long)n * (n + 1) / 2; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; double ans = 0.0000; void bfs(); list<int> arr[100005]; int visited[100005], dep[100005]; int main() { int n, i, start, end; cin >> n; n--; while (n--) { cin >> start; cin >> end; arr[start].push_back(end); arr[end].push_b...
#include <bits/stdc++.h> using namespace std; vector<int> vv; int main() { int t, n, x, c1, c2; scanf( %d , &t); vv.clear(); c1 = c2 = 0; for (int i = 0; i < t; i++) { scanf( %d , &n); for (int j = 0; j < n / 2; j++) { scanf( %d , &x); c1 += x; } if (n %...
#include <bits/stdc++.h> using namespace std; int CNT[7002]; struct seg { seg(int _l, int _r, int _val) : l(_l), r(_r), val(_val){}; int l, r, val; }; vector<seg> q[7002]; int pw2[200002]; int up(int lev, int pos) { int l = 0, r = 200000; while (r - l > 1) { int m = (l + r) >> 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10, mod = 1e9 + 9; const int maxn = 500010; const long double eps = 1e-5; const int EPS = 500 * 500; template <typename T> void read(T &x) { x = 0; char ch = getchar(); long long first = 1; while (!isdigit(ch)) { if (c...
#include <bits/stdc++.h> using namespace std; map<int, int> Dn; int L[310]; int C[310]; int N; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { scanf( %d , &N); for (int i = 1; i <= N; i++) scanf( %d , L + i); for (int i = 1; i <= N; i++) scanf( %d ,...
#include <bits/stdc++.h> using namespace std; const long double EPS = (long double)1e-9; const long double PI = acos(0) * 2; bool isZero(const long double& x) { return abs(x) <= EPS; } int sign(const long double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); } long long gcd(long long a, long long b) { f...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 6; long long int arr[2000005], brr[2000005], crr[2000005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, k, ans; cin >> n >> k; vector<pair<int, int> > v; for (int i = 1; i <= n...
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == L ) { if (i - 1 >= 0 && s[i - 1] != * ) { for (int j = i - 1; j >= 0; j--) { if (s[j] == R ) { int...
#include <bits/stdc++.h> using namespace std; vector<int> edge[1005]; int vis[2][1005]; int d[2][1005]; int adj[1005][1005]; void djikstra(int s, int id) { priority_queue<pair<int, int> > PQ; PQ.push(make_pair(0, s)); d[id][s] = 0; while (!PQ.empty()) { pair<int, int> p = PQ.top(); ...
#include <bits/stdc++.h> using namespace std; int nx[1000514 * 2][26], spt; int fl[1000514 * 2], ll[1000514 * 2], lp[1000514 * 2]; int newnode() { memset(nx[spt], 0, sizeof(nx[spt])); fl[spt] = ll[spt] = lp[spt] = 0; return spt++; } void add(int root, int& last, char A) { int a = A - a ; ...