func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; char a[1005], b[1005]; int main() { int s1 = 0, s2 = 0; scanf( %s %s , &a, &b); int len1 = strlen(a); int len2 = strlen(b); for (int i = 0; i < len1; i++) if (a[i] == 1 ) s1++; for (int i = 0; i < len2; i++) if (b[i] == 1 ) s2++; ...
#include <bits/stdc++.h> using namespace std; int n, Q, x, y, z, kk; int dis[500005], head[500005], father[500005], top[500005], q[500005]; bool vis[500005]; int far[500005], heavyson[500005], rak[500005], sum[500005], leaf[500005], ans, d[500005]; struct Tree { int nxt, to, step; } e[500005]; ...
#include<bits/stdc++.h> #define For(i, x, n) for(int i = x; i < n; i++) #define ROF(i,x,n) for(int i = n - 1; i >= x; i--) #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define F first #define S second #define pb push_back #define po pop_back #define mp make_pair #define En en...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int n, m, X, a[maxn], b[maxn], c[maxn], d[maxn], tr[maxn]; long long ans; vector<int> M[maxn]; vector<pair<int, int>> Q[maxn]; void add(int p) { for (; p <= X; p += p & -p) tr[p]++; } int sum(int p) { int s = 0; for (; ...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int a[n], b[n]; long int s = 0; for (int i = 0; i < n; i++) scanf( %d%d , &a[i], &b[i]); for (int i = 1; i < n; i++) { if (b[i] >= b[i - 1]) b[i] = b[i - 1]; s += (a[i] * b[i]); } printf( %ld n , s + (a[0] * b[0]...
#include <bits/stdc++.h> using namespace std; int main() { int a = 1023, b = 0, n, e; char op; cin >> n; while (n--) { cin >> op >> e; if (op == | ) { a |= e; b |= e; } else if (op == & ) { a &= e; b &= e; } else if (op == ^ ) { a ^=...
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); int a, b, c, d, k, x, y; while (t--) { scanf( %d %d %d %d %d , &a, &b, &c, &d, &k); if (a % c == 0) { x = a / c; } else { x = a / c + 1; } if (b % d == 0) { y = b / d; } else { ...
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e15 + 696969; long long n, k; long long a[1LL << 20], b[1LL << 20]; long long opt[20][1LL << 20]; signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); memset(opt, -1, sizeof opt); cin >...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long x1, y1, z1; long long x2, y2, z2; cin >> x1 >> y1 >> z1; cin >> x2 >> y2 >> z2; long long sum = 0; if (z2 > x1) { z2 -= x1; if (z2 > z1) { z2 ...
#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; const long long INFL = LLONG_MAX; int N, ans, P[100100], ord[100100]; int comp(int a, int b) { return P[a] > P[b]; } int main() { ios_base::sync_with_stdio(0); cout.precision(15); cin >> N; for (int(i) = 1; (i) <= (N); (i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int inv = 0; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (a[i] < a[j]) { inv++; } } ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 23; int parseInt() { int d; scanf( %d , &d); ; return d; } int n; int a[MAXN], b[MAXN]; vector<pair<int, int> > v; map<int, int> rang; int main() { cin >> n; for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7, INF = 0x3f3f3f3f; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long qpow(long long a, long long n) { long long r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; ret...
#include <bits/stdc++.h> using namespace std; int Length[1001], n, x, a[1001], Concern, Pos, Ppl; vector<int> Queues, adj[1001], Ans; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n >> x; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (a[i]) adj[...
#include <bits/stdc++.h> using namespace std; int Min = -10000000; int Max = -Min; int A[8] = {1, 1, 0, 0, 1, 1, 1, 1}; int B[8] = {0, 0, 1, 1, 1, 1, -1, -1}; int C[8]; struct Nodes { int x, y; } p[100010]; bool operator<(Nodes &p1, Nodes p2) { if (p1.x == p2.x) return p1.y < p2.y; return ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5e4 + 2; int head[N], grp_edge[N][30], max1[N][30], grp[N], level[N], okfine = 0, sum[N], dem = 0; char edge[N]; bool cac = true; vector<pair<int, char> > adj[N]; vector<int> ad...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf( %d , &n) == 1) { string s; cin >> s; s = # + s; bool used[n + 1]; memset(used, 0, sizeof used); int d[n + 1]; for (int i = 1; i <= n; i++) { scanf( %d , d + i); } i...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; template <typename T, typename U> inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { _out << _p.first ...
#include <bits/stdc++.h> using namespace std; char _; int num_rectangles; pair<pair<int, int>, pair<int, int> > rectangles[135000], pre[135000], suff[135000]; pair<pair<int, int>, pair<int, int> > intersection( pair<pair<int, int>, pair<int, int> > first, pair<pair<int, int>, pair<int, int> ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6, maxm = 1e6; unsigned int degree[maxn + 10], blk[maxn + 10]; namespace find { unsigned int fa[maxn + 10], siz[maxn + 10]; inline void Init(const unsigned int n) { iota(fa, fa + n + 1, 0); fill(siz, siz + n + 1, 1); } unsigned int...
#include <bits/stdc++.h> using namespace std; int main() { string s; int count = 0, count1 = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] >= 97 && s[i] <= 122) count++; else count1++; } if (count >= count1) { for (int i = 0; i < s.size(); i++) ...
#include <bits/stdc++.h> using namespace std; int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1}; vector<string> vec_splitter(string s) { s += , ; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find( , ))); s = s.substr(s.find( , ) +...
#include <bits/stdc++.h> using namespace std; int a[300005], p[300005], out[300005]; long long f[300005]; bool v[300005]; int n, m, cnt; void work(int p) { int t = min(a[p], a[p + 1]); if (t) out[++m] = p; a[p] -= t; a[p + 1] -= t; } int main() { scanf( %d , &n); for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; int a[4] = {1, 2, 3, 5}; int main(void) { int n, k; scanf( %d%d , &n, &k); printf( %d n , (5 + 6 * (n - 1)) * k); for (int i = 0; i < n; i++) { printf( %d %d %d %d n , (a[0] + 6 * i) * k, (a[1] + 6 * i) * k, (a[2] + 6 * i) * k, (a[3]...
#include <bits/stdc++.h> int main() { int n, mxpos = 0, mx = 0, temp, i; scanf( %d , &n); int p[n]; for (i = 0; i < n; i++) { scanf( %d , &p[i]); if (mx < p[i]) { mx = p[i]; mxpos = i; } } int loopno = 0, j; int notsorted = 1; while (notsorted) { ...
#include <bits/stdc++.h> using namespace std; const int N = 32000; const int mod = 1000000007; const int inf = 2 * mod; int dp[5001][5001]; pair<long long, long long> hashVal[5001]; pair<long long, long long> powVal[5001]; const long long base1 = 37; const long long base2 = 2017; const long long mod...
#include <bits/stdc++.h> using namespace std; const long long INF = LLONG_MAX; const long long mod = 1e9 + 7; inline long long power(long long n, long long k, long long mod = INF) { long long ans = 1; while (k > 0) { if (k & 1) ans = (ans * n) % mod; n = (n * n) % mod; k >>= 1; } ...
#include <bits/stdc++.h> int a[100005], s[100005]; int main() { int l, r, q1, q2, i, N, S; scanf( %d%d%d%d%d , &N, &l, &r, &q1, &q2); s[0] = 0; for (i = 1; i <= N; i++) { scanf( %d , &a[i]); s[i] = s[i - 1] + a[i]; } int mx = s[N] * l + q1 * (N - 1); for (i = 0; i <= N; i++) ...
#include <bits/stdc++.h> using namespace std; int arr[1000] = {0}; int main() { int n, m, i, j, k; cin >> n; for (i = 0; i < n; i++) cin >> arr[i]; if (n % 2 == 0) { cout << No << endl; return 0; } else { if (arr[0] % 2 == 1 && arr[n - 1] % 2 == 1) { cout << Yes <...
#include <bits/stdc++.h> int main() { int pages, readPages[7]; scanf( %d , &pages); for (int i = 0; i < 7; i++) scanf( %d , &readPages[i]); int day = 1, i = 0; while (pages > 0) { if (day == 8) day = 1; if (i == 7) i = 0; pages -= readPages[i]; day++, i++; } printf(...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3000 + 50; const int MAX_D = 15; struct DP { int d1; int d2; int d3; int v1; int v2; int v3; }; bool operator<(const DP& l, const DP& r) { return l.v1 < r.v1 || (l.v1 == r.v1 && l.v2 < r.v2) || (l.v1 == r....
#include <bits/stdc++.h> using namespace std; struct Node { long long l, r; mutable long long val; Node(long long l = 0, long long r = 0, long long v = 0) : l(l), r(r), val(v) {} bool operator<(const Node& rv) const { return l < rv.l; } }; long long n, m; set<Node> t; long long a[100...
#include <bits/stdc++.h> using namespace std; const int maxp = 22; const long double EPS = 1e-18; const long long INF = 1e18; const int MOD = 1e9 + 7; const int N = 2e5 + 1; void yesno(bool a) { if (a) { cout << YES << n ; } else { cout << NO << n ; } } long long power(...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; char c[n][n]; for (long long i = 0; i < n; i++) { for (long long j = 0; j < n; j++) { cin >> c[i][j]; } } bool re =...
#include <bits/stdc++.h> int main() { int n; std::string s; std::cin >> n >> s; int cnt = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 1 ) cnt++; else { std::cout << cnt; cnt = 0; } } std::cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; long long f[105][105][2]; struct seg { int a; long long len; bool operator<(const seg &p) const { return a < p.a; } } a[105]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d%lld , &a[i].a, &a[i].len); ...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; const int maxn = 1e5 + 10, lg = 18; int n, m, q, cid[maxn], csize = 0, H[maxn], low[maxn], ok[maxn], par[maxn][lg], comp[maxn], c1; bool dp[maxn][lg]; vector<int> G[maxn]; bool mark[maxn]; void dfs1(int a,...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; int count[5005] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; count[a[i]]++; } int c[n]; int d = 1; for (int i = 1; i <= 5000; i++) { if (count[i] > k) { co...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; const long long int LINF = 1LL * INF * INF; const int MAXN = 2e5 + 10; const int MAXM = 5e3 + 10; priority_queue<int> pq; vector<vector<int> > graph; queue<int> que; pair<int, int> A[20]; long long int dp[20][(1 << 20)]; long ...
#include <bits/stdc++.h> using namespace std; int q[1000005]; long long i, j, t, tot, C, cnt; long long loc[10005], op[10005]; long long n, m, k, H, x, y, ans, tmp; long long a[100005], w[100005], e[25], dis[10005], heap[10005]; bool used[100005], f[10005]; map<long long, long long> A; map<long long, ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int r = min(a / 3, min(b / 2, c / 2)); a -= 3 * r; b -= 2 * r; c -= 2 * r; int ans = 7 * r; int cnt1 = 0; for (int i = 0; i < 14; i++) { int a1 = a, b1 = b, c1 = c, cnt = 0; fo...
#include <bits/stdc++.h> using namespace std; int main() { long long arr[100000], arr1[100000], n, x, z, co = 0, co1 = 0, k, m, fin = 1000000; map<long long, long long> left; map<long long, long long> right; cin >> n; if (n % 2 == 0) k = n ...
#include <bits/stdc++.h> using namespace std; const int N6 = 1e6 + 6; using namespace std; long long n, m, x, y, sum1, sum2, ans1, ans2; int main() { cin >> n >> x >> y; if (n > y) { cout << -1; return 0; } sum1 = y - n + 1; sum1 *= sum1; sum1 += (n - 1); if (sum1 >= x)...
#include <bits/stdc++.h> using namespace std; const int maxn = 1050; int dp[maxn][9], nxt[maxn][9][maxn], a[maxn], n, cnt[9]; inline int ask(int k) { return (1 << (k - 1)); } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); for (int i = 1; i <= n; ++i) { for (in...
#include <bits/stdc++.h> using lint = long long; using ldouble = long double; void solve() { int n, d; std::cin >> n >> d; std::vector<int> vs(n, 1); int diff = n * (n - 1) / 2 - d; if (diff < 0) { std::cout << NO << std::endl; return; } int head = 1; for (int v = n -...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 1e18; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; k++; long long A[n]; ...
#include <bits/stdc++.h> using namespace std; void r(int b, int p, int f, int h, int c); int main() { int b, p, f, h, c, t; cin >> t; while (t--) { cin >> b >> p >> f >> h >> c; r(b, p, f, h, c); } } void r(int b, int p, int f, int h, int c) { int i, j, k, t = 0; i = b / 2;...
#include <bits/stdc++.h> using namespace std; ; clock_t start; mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const long long N = 501, lmx = 11; long long mx[N][N][lmx][lmx], n, m, q, col[4][N][N], logg[N]; long long sum(long long k, long long r1, long long c1, long long r2, ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } bool is_simple(int a) { for (int i = 2; i < a; ++i) { if (a % i == 0) return false; } return true; } int elems[200009] = {0}; int addings[200009] = {0}; int removes[200009] = {0}; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } long long sum[30]; char fir[210000], sec[210000]; int main() { int len, i; double ans, cnt; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, k, ans[5]; char s[N]; void solve(int l, int r) { while (l != r) { int mid = l + r >> 1; printf( 1 %d %d n , mid, mid + 1); fflush(stdout); scanf( %s , s); if (!strcmp(s, NIE )) l = mid + 1...
#include <bits/stdc++.h> const int N = 2e5 + 5; const int highestboolN = 1e9; const long long unsigned inf = 1234568901234567890; const long double pi = 3.141592653589793; const int md = 1e9 + 7; using namespace std; int here = 1; void force_break() { here++; if (here >= (N * 100)) { cout ...
#include <bits/stdc++.h> using namespace std; long long arr[1010], brr[1010]; int main() { long long n, i, j, x, y, ans; cin >> n; for (i = 1; i <= n; i++) cin >> arr[i]; for (i = 1; i <= n; i++) cin >> brr[i]; ans = 0; for (i = 1; i <= n; i++) { x = arr[i]; y = brr[i]; a...
#include <bits/stdc++.h> using namespace std; int n; long long dp[26][2][2]; long long need; bool hasone = 0; int ans[55]; inline void upd(long long &a, long long b) { a += b; } inline long long getval(int p, int v) { memset(dp, 0, sizeof(dp)); dp[0][0][0] = 1; for (int i = 0; i < (n + 1) / ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T& x) { int f = 0, c = getchar(); x = 0; while (!isdigit(c)) f |= c == - , c = getchar(); while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); if (f) x = -x; } template <typename T, typename... Args> ...
#include <bits/stdc++.h> using namespace std; const bool debug = 1; int xl = 1 << 30, xr = -(1 << 30), yl = 1 << 30, yr = -(1 << 30), zl = 1 << 30, zr = -(1 << 30); bool getpod(pair<int, int> p, int s) { int pzl = p.first - p.second - s; int pzr = p.first - p.second + s; int pxl = p.first - s;...
#include <bits/stdc++.h> using namespace std; int main() { int arr[3][3]; int cnt1, cnt2, cnt3; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) scanf( %d , &arr[i][j]); cnt1 = arr[0][1] + arr[0][2]; cnt2 = arr[1][0] + arr[1][2]; cnt3 = arr[2][0] + arr[2][1]; if (cnt1 >= cnt...
#include <bits/stdc++.h> using namespace std; long long n, x, a1, a2; int main() { scanf( %lld , &n); for (int i = 1; i <= n; ++i) { scanf( %lld , &x); if (i % 2 == 0) { a1 += (x + 1) / 2; a2 += x / 2; } else { a1 += x / 2; a2 += (x + 1) / 2; } }...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); int a, b, c; cin >> a >> b >> c; cout << ((a + c - 1) * (b + c - 1) - c * (c - 1)) << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, -1, 0, 1}; vector<long long> p(10000005, -1); void f(long long n = 10000005) { p[2] = 2; for (long long i = 4; i < n; i += 2) { p[i] = 2; } for (long long i...
#include <bits/stdc++.h> using namespace std; char str[100005]; int cnt[250]; int main() { scanf( %s , &str); int len = strlen(str); set<char> myset; for (int i = 0; i < len; i++) { myset.insert(str[i]); cnt[str[i]]++; } if (myset.size() == 1 || myset.size() > 4) { prin...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100005; int n, m; int t[MAX_N], x[MAX_N]; int nxt; int idx[MAX_N]; int res[MAX_N]; bool mycmp(const int a, const int b) { if (x[a] != x[b]) return x[a] < x[b]; return a < b; } int main() { scanf( %d%d , &n, &m); for (int...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; const int mod = 1e9 + 7; const long long INF = 1e18; string a[30], b[30], ans[407]; void rua() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; int cnt = 0,...
#include <bits/stdc++.h> int main(int argc, char *argv[]) { int n, i, a, b, c, d; long int s; scanf( %d , &n); s = 0; for (i = 1; i <= n; i++) { scanf( %d %d %d %d , &a, &b, &c, &d); s = s + (1 + abs(a - c)) * (1 + abs(b - d)); } printf( %ld , s); return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vect...
#include <bits/stdc++.h> #pragma GCC optimization( unroll-loops ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4 ) using namespace std; const int BASE = 1000000; char what[1 << 20]; pair<int, int> nxt[10][1 << 20]; pair<long long, int> to[10][10]; inline long long Calc(long...
#include <bits/stdc++.h> const int MAXN = 200000 + 10; const int INF = 0x7fffffff; using namespace std; struct EDGE { int u, v, w; bool operator<(const EDGE &b) const { return w > b.w; } }; int fa[MAXN + MAXN]; int n, m, vis[MAXN]; int Min[MAXN]; vector<EDGE> edge; int Find(int x) { return f...
#include <bits/stdc++.h> using namespace std; int intervalo[200010]; int aparicoes[200010]; int aceito[200010]; int main() { int n, k, q; cin >> n >> k >> q; int l, r; for (int i = 0; i < n; i++) { cin >> l >> r; intervalo[l] += 1; intervalo[r + 1] -= 1; } int x = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a; b = a; for (string::reverse_iterator itr = a.rbegin(); itr != a.rend(); itr++) b += *itr; cout << b << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long; const int inf = 1000000007; const int MOD = 1000000007; int f(int x) { int res = 0; while (x > 0) { res += x % 10; x /= 10; } return res; } bool calc(int n, int k) { int sm = 0; for (int i = 0; i < k;...
#include <bits/stdc++.h> #pragma GCC optimize( O3,no-stack-protector,unroll-loops,fast-math ) using namespace std; struct coor { long long x, y, x1, y1; }; vector<struct coor> v; struct coor ldp[200005], rdp[200005]; struct coor inter(struct coor l, struct coor r) { struct coor res = {INT_MIN, INT...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, a, b, c, d; cin >> t; while (t--) { cin >> n >> a >> b >> c >> d; int mi = (a - b) * n, ma = (a + b) * n; if ((mi > c + d) || (ma < c - d)) cout << NO << endl; else cout << YES << endl; }...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const long long mod = 1000000007; void solve() { int n, m, u, v; cin >> n >> m; vector<int> adj[n + 1]; for (int i = 0; i < m; i++) { cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } v...
#include <bits/stdc++.h> using namespace std; using namespace std; typedef long long int ll; typedef unsigned long long int ull; inline void smax(int &x, int y) { x = max(x, y); } inline void smin(int &x, int y) { x = min(x, y); } ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); } const doubl...
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 0; cin >> n; int last; for (int(i) = 0; (i) < (n); ++(i)) { cin >> last; m += last; } cout << ((n - m == 1 && n > 1) || (n == 1 && m == 1) ? YES n : NO n ); }
#include <bits/stdc++.h> using namespace std; int n, k, trie[100100][27], sz = 1, ok[2][100100]; char s[100100]; void add() { int v = 0; for (int i = 0; s[i] != 0 ; i++) { if (trie[v][s[i] - a ] == 0) trie[v][s[i] - a ] = sz++; v = trie[v][s[i] - a ]; } } void calc(int v, bool b...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int t, id, n, m, x, y, k, c, p, dif, ans, sum, pre, rem, cur, tmp, tot, r, l, u, d, xx, yy; int a[N], vis[N], f[N], b[N], cu[N]; vector<int> v, adj[N]; bool fl, ok; int dp[N]; int mem[N]; int sol(int i = n) { int &ret = mem...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; char maz[505][505]; int dp[10][505][505]; inline void cm(int& x) { if (x >= mod) x -= mod; } int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) scanf( %s , maz[i] + 1); int up = (n + m - 1) /...
#include <bits/stdc++.h> using namespace std; void task(); int main() { task(); return 0; } const int N = 2e5 + 10; const long long int MOD = (long long int)1e9 + 7; const int INF = 0x3f3f3f3f; const long long int LINF = (long long int)4e18 + 100; const int BUF_SIZE = (int)1e6 + 10; const do...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int f = 1; int s = 0; vector<int> A; for (int i = 0; i < n; i++) { int a; cin >> a; A.push_back(a); } if (A.size() == 1) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 500100; multiset<pair<long long, long long> > intervals; long long n, k; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 0; i < k; i++) intervals.insert(make_pair(0, i)); long long s, d; ...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; }; vector<node> q; int n, m, sum[2020][2020]; char g[2020][2020]; void init() { for (int i = 0; i < (n); i++) for (int j = 0; j < (m); j++) if (g[i][j] == w ) q.push_back((node){i, j}); for (int i = 0; i < (n)...
#include <bits/stdc++.h> using namespace std; template <class T, class U> void maximize(T &x, U y) { if (x < y) x = y; } template <class T, class U> void minimize(T &x, U y) { if (x > y) x = y; } template <class T> T Abs(T x) { return (x < (T)0 ? -x : x); } template <class T> T safe_...
#include <bits/stdc++.h> using namespace std; int n, a[1050]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int tens = a[0]; set<int> answer; for (int rem = 0; rem < 10000000; rem++) { double fuel = tens * 10 + static_cast<double>(rem) / 1000000; double addend = f...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)2e5 + 10; vector<pair<int, int> > a, b; vector<int> L; int n, m, q[MAXN], id[MAXN], Tohka[MAXN], l[MAXN], r[MAXN], t[MAXN], fa[MAXN], T[MAXN]; bool cmp(int first, int second) { return q[first] < q[second]; } bool cmp1(int first, int...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; scanf( %d %d %d , &n, &m, &q); int log_n = 0; while (1 << log_n <= n) { ++log_n; } int jump_small = pow(n, 1.0 / 3), jump_large = pow(n, 2.0 / 3); vector<vector<int>> rmq_min(log_n, vector<int>(n)), rmq...
#include <bits/stdc++.h> using namespace std; int main() { long int n, i; cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } if (n == 1) { cout << a[0]; return 0; } sort(a, a + n); long long int sum = 0; if (a[0] >= 0) { sum = -1 * ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; const long long M = 1e9 + 7; const double eps = 1e-7; int a[N]; int Int() { int x; scanf( %d , &x); return x; } long long Lnt() { long long x; scanf( %I64d , &x); return x; } long long Bigmod(long long A, lo...
#include <bits/stdc++.h> using namespace std; long long int a[2005]; long long int cnt[2005]; long long int b[2005]; long long int vis[2005]; vector<long long int> v; vector<long long int> vv; vector<long long int> ans; long long int prime[2005]; bool pr[2005]; set<char> st; priority_queue<long ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = (int)int(s.size()); int num = (s[n - 1] - 0 ) + 10 * (s[n - 2] - 0 ); if (num % 4 == 0) cout << 4; else cout << 0; return 0; }
#include <bits/stdc++.h> using namespace std; void dfs(long long a, long long b, char A, char B) { if (a == 1 && b == 1) return; if (a < b) swap(a, b), swap(A, B); printf( %I64d%c , (a - 1) / b, A); dfs(a - (a - 1) / b * b, b, A, B); } long long gcd(long long a, long long b) { if (b == 0) re...
#include <bits/stdc++.h> using namespace std; int q, ans; char s[300010]; set<int> len, hs[300010]; int p[300010], v[300010]; int main() { int i, l, op; for (i = 1, p[0] = 1; i <= 300000; ++i) p[i] = 1LL * p[i - 1] * 27 % 1000000007; scanf( %d , &q); while (q--) { scanf( %d%s , &...
#include <bits/stdc++.h> using namespace std; struct node; typedef node *Node; const int inf = 1000000; bool fl = 0; struct node { Node left, right, link, parent; int size, prior, sum, number; set<int> all; pair<int, int> mmin; node(int number) : number(number) { left = right = lin...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000000 ) using namespace std; const long long int INF = 2e18; int nex[20000][35]; int at[35]; int main() { string f, s; cin >> f >> s; memset(nex, -1, sizeof nex); memset(at, -1, sizeof at); for (int i = 0; i < f.size(); i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> dis(n + 1, n), cnt(n + 1, -1); while (m--) { int a, b; cin >> a >> b; ++cnt[a]; dis[a] = min(dis[a], a > b ? b - a + n : b - a); } for (int i = 1; i <= n; ++i) { int ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(); string s, mx; cin >> s; int len = s.length(); for (int i = 1; i < 1 << len; i++) { string foo; for (int j = 0; j < len; j++) if (i & (1 << j)) foo += s[j]; bool flag ...
#include <bits/stdc++.h> using namespace std; const int size = 300000001; bitset<size> gut; int main() { int l, r; cin >> l >> r; gut.set(); for (int i = 3; i * i <= r; i += 2) { if (gut[i]) for (int j = i * i; j <= r; j += (i << 1)) { gut[j] = false; } } ...
#include <bits/stdc++.h> using namespace std; const int N = 3010; struct edge { int v, next, flag; } e[N << 2]; int head[N], cnt; void addedge(int u, int v, int flag) { e[cnt].v = v; e[cnt].flag = flag; e[cnt].next = head[u]; head[u] = cnt++; } int sum[N], dp[N]; void dfs(int u, in...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 100; int N; int p[MAXN], rp[MAXN]; char ans[MAXN][MAXN]; bool v[MAXN]; int lvl, C; bool pd; bool id(int* a, int as) { for (int i = 1; i <= as; i++) if (a[i] != i) return false; return true; } char get_dir(bool d) { ...