func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int ntest = 0, test = 0; inline void init(); inline void run(); inline void stop() { ntest = test - 1; } int main() { init(); while (++test <= ntest) { run(); } return 0; } const int INF = (int)1E9 + 5; const double EPS = 1E-11; con...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const long long LL_INF = (long long)9.22e18; string s; int main() { cin >> s; bool isFirst = true; int cnt = 0; for (char ch : s) { if (ch == 1 && isFirst) { isFirst = false; continue; } ...
#include <bits/stdc++.h> using namespace std; string s; int ans, pre, cnt; int main() { cin >> s; for (int i = 0; i < s.size(); i++) { pre += s[i] - 0 ; cnt++; if (cnt == 3 || (s[i] - 0 ) % 3 == 0 || pre % 3 == 0) ans++, pre = 0, cnt = 0; } cout << ans << endl; re...
#include <bits/stdc++.h> using namespace std; using LL = long long; using pii = pair<int, int>; using UI = unsigned int; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double EPS = 1e-8; const double PI = acos(-1.0); const int N = 5e5 + 10; const int M = N + (1 << 20); int n, a[N][2]; ...
#include <bits/stdc++.h> using namespace std; const int tinf = (int)1e9 + 7; const long long inf = (long long)1e18 + 7; const int N = 1e5 + 5; long long n, x[10000], y[10000], ans; int main() { { ios ::sync_with_stdio(false); cin.tie(0); } cin >> n; for (int i = 0; i < n; i++) ci...
#include <bits/stdc++.h> using namespace std; int main() { long long second = 0; int r, m; cin >> m >> r; long long koef = 0, koef2 = 0; for (int i = 1; i <= m; ++i) { long long lef = i - 2, rig = m - i - 1; if (lef < 0) lef = 0; if (rig < 0) rig = 0; koef2 += i != 1; ...
#include <bits/stdc++.h> using namespace std; long long spf[100001]; long long fac[100001]; void sieve() { spf[1] = 1; for (long long i = 2; i < 100001; i++) spf[i] = i; for (long long i = 4; i < 100001; i += 2) spf[i] = 2; for (long long i = 3; i * i < 100001; i++) { if (spf[i] == i) { ...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 100; const long long INF = 9 * (long long)(1e18); const long double PI = 3.14159265358979323846; long long int modexp(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; if (y == 0) retu...
#include <bits/stdc++.h> using namespace std; const int N = 50 + 10, dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; int main() { int n, m, x, y; while (~scanf( %d%d , &n, &m)) { getchar(); char a[N][N]; for (int i = 0; i < n; i++) { scanf( %s , a[i]); for (int j = 0; j < m; ...
#include <bits/stdc++.h> using namespace std; struct MyStruct { long long val; long long under; long long scorev; long long scoreu; MyStruct(long long v, long long u, long long sv, long long su) : val(v), under(u), scorev(sv), scoreu(su) {} bool operator<(const MyStruct& m) const { r...
#include <bits/stdc++.h> using namespace std; const long long INF = 9e18; const int mod = 4e4 + 7; vector<int> prime; bool p[100005]; void init() { p[1] = true; for (int i = 2; i <= 100005; i++) { if (!p[i]) { prime.push_back(i); for (int j = i + i; j < 100005; j += i) p[j] = t...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); int sum = 0; for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } int req = sum / 2 - v[0] + 1; vector<pair<int, int> > v1; for (int i = 1; i < n; i++) { if (v[i] ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int t, n, i, j, k, sum = 0, res = 0, maxi = -1, mini = 1000000100; cin >> n; long long int a[n + 1]; for (i = 0; i < n; i++) cin >> a[i]; long long int idx = 0; for (i = 31;...
#include <bits/stdc++.h> const int MOD = 1E9 + 7; const int N = 150000 + 5; const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1}; using namespace std; struct Edge { int nex, to; int w; Edge() {} Edge(int nex, int to, int w) : nex(nex), to(to), w(w) {} ...
#include <bits/stdc++.h> using namespace std; const int max_n = 100011, log_n = 32, max_m = 111, mod = 1000000007, inf = 1011111111, p = 997; long long n, pp[22], dp[max_n][22][2]; bool a[max_n][22]; long long ans; vector<int> v[max_n]; void dfs(int x, int p) { for (int i = 0; i < v[x].siz...
#include <bits/stdc++.h> using namespace std; const int maxn = 105; const int INF = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-9; int a[maxn]; int n; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); int now = 10; int ans = 0; in...
#include <bits/stdc++.h> using namespace std; int main() { long long x, r, r1, s, s1, pos, pos1, nx = 0; int digits[19], index = 0; cin >> x; pos = 1; do { pos1 = pos; pos *= 10; r = x % pos; s = (x - r) / pos; r1 = r % pos1; s1 = (r - r1) / pos1; digits...
#include <bits/stdc++.h> int main() { int val[105]; memset(val, 0, sizeof val); char arr[105]; scanf( %s , arr); int n = strlen(arr); for (int i = 0; i < n; i++) { if (arr[i] == A ) { if (i > 0) { val[i - 1] |= 1; } val[i] |= 1; if (i < n - 1) {...
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } long lo...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <typename T> inline bool smin(T &a, const T &b) { r...
#include <bits/stdc++.h> using namespace std; const int N = 25; int main() { int n, m, l, r, t, c; cin >> n >> m; pair<int, int> s[n + 1]; for (int i = (1), _b = (n + 1); i < (_b); ++i) s[i] = make_pair(0, 0); for (int i = (0), _b = (m); i < (_b); ++i) { cin >> l >> r >> t >> c; fo...
#include <bits/stdc++.h> using namespace std; int n, m, A, B, scc[75], tot[75], fa[75], ans[75], f[75][1 << 16]; int c, To[405], nxt[405], cst[405], Head[75]; bool vis[75][1 << 16]; inline int Read() { int x = 0, f = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == - ) f = -1;...
#include <bits/stdc++.h> const long long INF = (1 << 30) - 1; const int MAXN = 100001; struct Node { int l, r; long long num; long long num2; long long delta; }; int n, m; long long t[MAXN]; int l[MAXN], r[MAXN]; long long q[MAXN]; Node tree[MAXN << 2]; void build(int cur, int l, int...
#include <bits/stdc++.h> struct Node { Node(int v = 1, int pos = 1e9) { min = (v == 1 ? int(1e9) : pos); } Node(Node l, Node r) { min = std::min(l.min, r.min); } int min; }; template <class i_t, class e_t> class SegmentTree { public: void init(std::vector<e_t> base) { n = base.size(); ...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; vector<long long> fact(10005); long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long power(long long x, long long y) { long long temp; if (y == 0) return 1; temp = power(x, ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; vector<int> gr[(ll)(1e5 + 4)]; set<int> g[(ll)(1e5 + 4)]; bool vis[(ll)(1e5 + 4)]; int par[(ll)(1e5 + 4)], si[(ll)(1e5 + 4)]; int find(int no) { if (par[no] != no) { par[no] = find(par[no]); } r...
#include <bits/stdc++.h> using namespace std; int n, fwt[262144]; vector<int> a1, b1, c1, d1, e1, ans; void add(int x, int k) { for (; x < 262144; x += x & -x) { fwt[x] += k; } } int sum(int x) { int res = 0; for (; x; x -= x & -x) { res += fwt[x]; } return res; } int...
#include <bits/stdc++.h> using namespace std; int main() { int n, temp, i, x = 0, arr[100] = {0}; map<long long, long long> inx; cin >> n; for (i = 0; i < n; i++) { cin >> temp; inx[temp] = i; } for (map<long long int, long long int>::iterator it = inx.begin(); it != inx...
#include <bits/stdc++.h> using namespace std; long long n, ans; string str; long long solve() { cin >> n; long long v[1001]; for (long long i = 0; i <= n - 1; ++i) { long long t; cin >> t; v[i + 1] = t; } for (long long i = 1; i <= n; ++i) { long long a[n + 1]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, i; scanf( %d %d , &n, &t); if (n == 1 && t == 10) { printf( -1 n ); } else { if (t == 10) { t = 1; } printf( %d , t); for (i = 0; i < n - 1; i++) { printf( 0 ); } printf( n...
#include <bits/stdc++.h> using namespace std; int n1, n2; int k1, k2; int main() { cin >> n1 >> n2 >> k1 >> k2; if (n1 > n2) cout << First << endl; else cout << Second << endl; return 0; }
#include <bits/stdc++.h> using namespace std; char s[500001], t[500001]; long long nt[10000001], n, k, m; long long c[2]; void kmp(long long x, char a[]) { int i, j; for (nt[0] = j = -1, i = 1; i < x; nt[i++] = j) { while (~j && a[j + 1] != a[i]) j = nt[j]; if (a[j + 1] == a[i]) j++; }...
#include <bits/stdc++.h> using namespace std; int n, k, x, m, s; vector<int> f, t, f1; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x >> m; f.push_back(x); t.push_back(m); } for (int i = 0; i < n; i++) { if ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k, a[205], b[205]; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j = 1; j <= k; j++) cin >> b[j]; if (k >= 2) {...
#include <bits/stdc++.h> using namespace std; template <typename T> void dbg(T a) {} template <typename T, typename... Arg> void dbg(T a, Arg... arg) {} const int maxn = (1e6) + 7; const int inf = (1e9) + 7; const long long LLinf = (1e18) + 7; const long double eps = 1e-9; const long long mod = 1e9 ...
#include <bits/stdc++.h> using namespace std; long long i, j, k, l, r, m, s, t, n, a[11236], b[123456], z, c[168456], zam[17456], za[1234]; bool p[40000000]; long long xx, yy, x, y; int main() { cin >> n >> k; if (n == 2) { if (k == 1) cout << 01 ; else cout << -1; ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e6 + 5, inf = 1e9 + 7; long long n, k, cumm[N], m[26]; set<pair<long long, long long> > st; string s; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long i, j, a, b, ans = 1; cin >> n >> k >> s; s = #...
#include <bits/stdc++.h> using namespace std; const int N = 3007; const int M = 998244353; int n, m, dp[N][N]; string s, t; bool matches(int i, char c) { if (i > m) return true; else return t[i - 1] == c; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> s >...
#include <bits/stdc++.h> char ans[100]; int n; int main() { scanf( %s%d , ans, &n); for (int i = 0; i < strlen(ans); i++) { if (ans[i] < a ) ans[i] += a - A ; if (ans[i] < 97 + n) ans[i] += A - a ; } printf( %s n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { int a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if (a[0] + a[1] >= a[2] - 1) { cout << Yes n ; } else cout << No n ; } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> void sf(T &res) { int f = 1; char c; res = 0; while (c = getchar(), !isdigit(c)) ; if (c == - ) f = -1, c = getchar(); do res = (res << 1) + (res << 3) + (c ^ 48); while (c = getchar(), isdigit(c)); res *= f; ...
#include <bits/stdc++.h> using namespace std; set<pair<char, char> > V; char R[18][18], S[18][18]; int main(void) { int n, m; cin >> n >> m; bool test1 = (n >= 6 && m >= 3) || (n >= 3 && m >= 6); if (test1 == false) { cout << No solution. << endl; return 0; } for (int i = 0...
#include <bits/stdc++.h> char buf[1 << 21], *p1 = buf, *p2 = buf; using namespace std; template <class T> void rd(T &k) { char c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++); int f = 1; k = 0; while (c < 0 || c > 9...
#include <bits/stdc++.h> using namespace std; string a, b; int main() { cin >> a >> b; if (a == b) { cout << a << endl; return 0; } else { cout << 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> bool gmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> bool gmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const long long N = 110; const long long K = 100010; const long long INF = 1e12; lon...
#include <bits/stdc++.h> using namespace std; bool check(string a) { bool flag = true; for (int i = 1; i <= a.size(); i++) if (abs(a[i] - a[i - 1]) == 1) flag = false; return flag; } int main() { int T; cin >> T; while (T--) { string s, one, two; cin >> s; for (in...
#include <bits/stdc++.h> using namespace std; int n, t, k, x; string s; int main() { cin >> s; n = s.size(); for (int k = 0;; k++) { if (s[k] == . ) { t = k; break; } } if (s[t - 1] == 9 + 0 ) cout << GOTO Vasilisa. ; else if (s[t + 1] < 5 + 0 ) { ...
#include <bits/stdc++.h> using namespace std; const int adj[8][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}, {-1, -1}, {-1, 1}, {1, 1}, {1, -1}}; const long long int LLINF = 9e18; const int INF = 2e9; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = acos(-1); cons...
#include <bits/stdc++.h> using namespace std; long long n, a, b, da, db; vector<long long> v[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { cin >> n >> a >> b >> da >> db; for (long long i = 0; i < n + 2...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int const nmax = 1010; int k, n; vector<pair<...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 9; int n, q, c[N]; void modify(int x, int v) { if (x == 0) return; for (int i = x; i <= n; i += i & -i) c[i] += v; } int query(int x) { int s = 0; for (int i = x; i >= 1; i -= i & -i) s += c[i]; return s; } void work(i...
#include <bits/stdc++.h> using namespace std; int main() { string s; string aux = CODEFORCES ; int i = 0; cin >> s; if (s.length() < aux.length()) cout << NO << endl; else { while (aux[i] == s[i] && i < aux.length()) i++; if (i == aux.length()) cout << YES << e...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; if (n < k) cout << k - n << endl; else { if ((n & 1) == (k & 1)) cout << 0 << endl; else cout << 1 << endl; } }...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, m; int a[maxn], b[maxn]; int main() { cin >> n >> m; m--; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } if (a[0] == 0) { cout << NO ; ...
#include <bits/stdc++.h> int main() { char a[110], b[110]; scanf( %s%s , a, b); if (strcmp(a, b) == 0) printf( %s n , a); else printf( 1 n ); }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int dir[8][2] = {{0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}}; const int dir8x[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; const int dir8y[8] = {-1, 0, 1, 1, -1, -1, 0, 1}; const long lo...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { unsigned long long int mino = LONG_MAX; unsigned long long int minc = LONG_MAX; unsigned long long int ans = 0; unsigned long long int n; cin >> n; unsigned long long int o[n], c...
#include <bits/stdc++.h> using namespace std; vector<int> split(string s) { vector<int> xs; stringstream ss(s); string item; while (getline(ss, item, , )) { xs.push_back(stoi(item)); } return xs; } int main() { string s; getline(cin, s); vector<int> xxs = split(s); ...
#include <bits/stdc++.h> const int kMaxN = 5000; std::vector<int> way[kMaxN], cost[kMaxN]; int f[kMaxN], c[kMaxN]; short hash[kMaxN][kMaxN], father[kMaxN][2 * kMaxN]; int a[kMaxN], id[kMaxN], t[kMaxN]; inline bool cmp(int x, int y) { return a[x] < a[y]; } void BuildTree(int u, int ff) { f[u] = ff; ...
#include <bits/stdc++.h> using namespace std; bool isthere(string s1, string s2); int main() { int t; cin >> t; for (int i = 0; i < t; i++) { string s1, s2; cin >> s1 >> s2; if (s2.size() == s1.size()) { if (isthere(s1, s2)) { cout << YES << endl; } else {...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0); char lowestChar = z + 1; string s; cin >> s; vector<int> ans(s.size(), 0); for (int i = 0; i < s.size(); ++i) { char c = s[i]; if (c < lowestChar) { ans[i] = 1; ...
#include <bits/stdc++.h> using namespace std; vector<int> bomb[5005]; int n, m, st_time[5005], sol[5005], dist_min[5005]; int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) dist_min[i] = 2 * 5005; int pos, val; for (int i = 1; i <= m; ++i) { cin >> pos >> val; bomb[pos].push_ba...
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; string s; for (int i = 0; i < t; i++) { cin >> n; cin >> s; int k = 0; if (n % 2 == 0) { for (int i = 1; i < n; i += 2) if ((int(s[i]) - 48) % 2 == 0) { k = 1; ...
#include <bits/stdc++.h> using namespace std; long long n, x, y, num[100005], res, a[100005], b[100005]; bool vis[100005]; vector<int> v[100005]; void dfs(long long now, long long pre) { for (long long i = 0; i < v[now].size(); i++) { int j = v[now][i]; if (j != pre) { dfs(j, now); ...
#include <bits/stdc++.h> #pragma GCC target( sse4,avx ) const int p = 1000000007; int mul32(int x, int y) { return int(int64_t(x) * y % p); } int add32(int x, int y) { int res = x + y; if (res >= p) res -= p; return res; } int sub32(int x, int y) { int res = x - y; if (res < 0) res += p;...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; long long n, d, b, a[N], f[N]; int main() { long long i, j, k, t = 0, ans; scanf( %I64d%I64d%I64d , &n, &d, &b); for (i = 1; i <= n; i++) scanf( %I64d , &a[i]), f[i] = f[i - 1] + a[i]; for (i = 1; i <= n / 2; i++) ...
#include <bits/stdc++.h> using namespace std; int Get() { char c; while (c = getchar(), c < 0 || c > 9 ) ; int X = 0; while (c >= 0 && c <= 9 ) { X = X * 10 + c - 48; c = getchar(); } return X; } const int inf = 1000000000; int GCD(int a, int b) { return b ? GCD...
#include <bits/stdc++.h> using namespace std; long long grundy[1234]; int main() { long long idx = 1, i, j; for (i = 1; i <= 15; i++) { for (j = 1; j <= (i + 1); j++) { grundy[idx] = i; idx++; } } long long n; cin >> n; long long ans = 0; while (n--) { ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e; scanf( %d%d%d%d%d , &a, &b, &c, &d, &e); if ((a + b + c + d + e) % 5 == 0 && a + b + c + d + e >= 5) printf( %d n , (a + b + c + d + e) / 5); else printf( -1 n ); }
#include <bits/stdc++.h> using namespace std; long long n, a[100005], b[100005], fa[100005], s[100005], q[100005], l, p = -2147483647; inline long long find(long long x) { if (x == fa[x]) return x; return fa[x] = find(fa[x]); } inline long long M(long long u, long long v) { return u > v ? u : v;...
#include <bits/stdc++.h> using namespace std; int h, w, i, j, mod = 1e9 + 7, r, c, ans = 1, a[1001][1001]; int main() { cin.tie(NULL); ios_base::sync_with_stdio(0); cin >> h >> w; for (i = 0; i < h; i++) { cin >> r; for (j = 0; j < r; j++) a[i][j] = 2; a[i][r] = 1; } for ...
#include <bits/stdc++.h> using namespace std; vector<int> v[200010], circle; int fa[200010], dep[200010], a[200010], b[200010], n, rt, vs, vt, h1, h2; bool vis[200010], bo[200010]; inline int rd() { int x = 0; char ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) ; for (; ch ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; using i64 = long long; using i32 = int; using f64 = long double; template <class Key> using vec = vector<Key>; template <class Key> using heap = priority_queue<Key>; template <class Key> using hash_set = unordered_set<Key>...
#include <bits/stdc++.h> using std::max; int n, m, c, x[150000 + 1], a, b, i; long long p[150000 + 1], ans = 0; struct node { long long sum, mmax, lmax, rmax; void update(const node &l, const node &r) { sum = l.sum + r.sum; lmax = max(l.lmax, l.sum + r.lmax); rmax = max(l.rmax + r.sum,...
#include <bits/stdc++.h> using namespace std; template <class T> bool isPrime(T x) { if (x <= 1) return false; T i; for (i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } template <class T> class Prime { public: vector<T> z; Prime() { z.resize(1e5 + ...
#include <bits/stdc++.h> using namespace std; template <class T> T sq(T x) { return x * x; } const long long inf = 2147383647; const double pi = 2 * acos(0.0); const double eps = 1e-9; const long long maxint = 2147483647; const long long minint = -2147483648; char grid[450][450]; int row, col,...
#include <bits/stdc++.h> using namespace std; #define ll long long #define pi pair<int, int> #define pll pair<long long, long long> #define vi vector<int> #define vll vector<long long> #define vpi vector<pair<int, int>> #define vvi vector<vector<int>> #define mii map<int, int> #define mmii multim...
#include <bits/stdc++.h> int pn, pr[2000050]; bool np[2000050] = {0}; int n; int ln, ls[2000050]; inline void gen() { pn = 0; for (int i = 2; i < 2000050; i++) { if (np[i]) continue; pr[pn++] = i; if (i > 2000) continue; for (int j = i * i; j < 2000050; j += i) np[j] = 1; }...
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; if (b % 2 == 1) return (power(a, b - 1) * a); long long q = power(a, b / 2); return (q * q); } void solve() { long long n; cin >> n; for (long lon...
#include <bits/stdc++.h> using namespace std; int rev(int a) { int ans = 0; int shift = 0; while (shift <= 7) { ans |= (a & 1 << shift ? 1 : 0) << (7 - shift); shift++; } return ans; } int main() { string a; int prev = 0; getline(cin, a); for (int i = 0; i < a.len...
#include<cstdio> #include<iostream> #include<algorithm> int main() { int n; char a[100000]; bool x = 1; while (~scanf( %d , &n)) { while (n--) { x = 1; scanf( %s , a); for (int i = 0; a[i] != 0 ; i++) { if (x) { if (a[i] != a ) a[i] = a ; else ...
#include <bits/stdc++.h> using namespace std; typedef struct trie { char c; bool win, lose; struct trie *alphabet[26]; } trie; void addString(trie *T, char *s); trie *initTrie(char c); void dfs(trie *T); int main() { int i, n, k; char s[100005]; trie *T = initTrie( 0 ); scanf(...
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; if (str[0] > 4 && str[0] != 9 ) str[0] = (char)( 9 - str[0] + 0 ); for (int x = 1; x < (int)str.length(); x++) if (str[x] > 4 ) str[x] = (char)( 9 - str[x] + 0 ); cout << str << endl; return 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int dp[N][3][2]; string a; int n; int solve(int x, int state, int start) { if (x >= n) return 0; if (dp[x][state][start] != -1) return dp[x][state][start]; int res = 0; if (state == 0) { if (start == a[x]) re...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int *a = new int[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (i > 0 && i < n - 1) { if (abs(a[i] - a[i + 1]) < abs(a[i] - a[i - 1])) cout << abs(a[i...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e4 + 5; int main() { int k, n, s, p; cin >> k >> n >> s >> p; int ans = k * (n % s == 0 ? n / s : n / s + 1); if (ans % p == 0) cout << ans / p << endl; else cout << ans / p + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int inf = ~0u >> 2; int numa[N], numb[N], pos[N]; struct node { int val, id; node(int _val, int _id) { val = _val, id = _id; } bool operator<(const node& A) const { return val > A.val; } }; int now[N], unuse[N]; priori...
#pragma GCC optimize( Ofast ) #include<bits/stdc++.h> using namespace std; #define int long long int #define double long double #define all(x) begin(x), end(x) #define Done(x) cout<<x<<endl; return; #define endl n void solve(){ int q; cin>>q; for(int i=0;i<q;i++){ int u; cin>>u; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 400003, INF = 0x3f3f3f3f; int n, Q, sz[maxn], fa[maxn], son[maxn], dfn[maxn], cntdfn, rig[maxn], top[maxn], dep[maxn], z[maxn]; vector<int> g[maxn]; struct T { int mx, sum; T operator+(T x) const { return (T){max(x.mx, x.sum + mx), s...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, fail; int G[305][305], v[305], u[305], l[305], z[305]; long long int A, B, C, a[305], b[305], d[305]; int rx[305 * 305 * 2], ry[305 * 305 * 2], rc[305 * 305 * 2], cnt; void dfs(int x) { v[x] = 1; A += a[x]; B += b[x]; for (int i =...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long int N = 1e5 + 5; long long int a[N], b[N], n, d, x; long long int getNextX() { x = (x * 37 + 10007) % 1000000007; return x; } void...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n % 2 << endl; }
#include <bits/stdc++.h> char b[20]; using namespace std; int main() { char a[14]; for (int i = 1; i <= 2; i++) { scanf( %s , a); if (strcmp(a, monday ) == 0) b[i] = 1; if (strcmp(a, tuesday ) == 0) b[i] = 2; if (strcmp(a, wednesday ) == 0) b[i] = 3; if (strcmp(a, thursda...
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a % 2; a = a * a % 2; b >>= 1; } return res; } int main() { ios_base::sync_with_stdio(false); long long b, k, sum = 0; ...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { char ch; bool flag = false; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == - ) flag = true; for (x = 0; isdigit(ch); x = x * 10 + ch - 0 , ch = getchar()) ; x = flag ? -x : x; } inline void w...
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, n, cnt = 0, flag = 0, k = 0; string str; cin >> n >> str; for (i = 0; i < n; i++) { if (str[i] == ( ) { cnt++; if (cnt == 2) j = i; } else cnt--; if ((cnt == -2) && (!k)) k = i; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; pair<int, int> p[n]; int t = 0; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } sort(p, p + n); int start = 0, l = 0, r = 0, s = 0; for (int i = 0; i < 2 * n; i++) { if (i < ...
#include <bits/stdc++.h> using namespace std; int n; int a[100100]; int dig[11]; int ans[11]; int main() { int sum = 0; bool pos = false; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; dig[a[i]]++; sum += a[i]; } if (dig[0] == 0) { cout << -1; retu...
#include <bits/stdc++.h> using namespace std; int getInt() { int ret; scanf( %d , &ret); return ret; } int main() { int n = getInt(); vector<pair<int, int> > pr(n); for (int i = 0; i < (int)(n); i++) { pr[i].first = getInt(); pr[i].second = getInt(); } sort(pr.begin()...
#include <bits/stdc++.h> using namespace std; int f[105][45], head[105], la[45]; int n, k, i, j, ans, u, v, cnt; struct ff { int to, nxt; } e[2 * 105]; void add(int u, int v) { e[++cnt] = (ff){v, head[u]}; head[u] = cnt; } void dfs(int now, int fa) { if (e[head[now]].nxt == 0 && fa) { ...