func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma warning(disable : 4996) using namespace std; const long long INF = 2147483647; const double PI = acos(-1); const int mod = 1e9 + 7; char arr[121212]; int main() { long long t; cin >> t; for (int j = 1; j <= t; j++) { long long n;...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, seed = 131, MAXN = 0; struct Item { string s; int x; }; int main() { cin.tie(0); cin.sync_with_stdio(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<string> arr(n); for...
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, a[N], b[N], lst[N], pre[N], suf[N], pr[N], sf[N], cn[N], sta[N], top, ans; long long s[N][4], tag[N][4]; inline long long S2(const int x) { return (x + 1ll) * x >> 1; } inline long long S(const int l, const int r) { return S2(...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; void testCase() { int n, k, cnt = 0, ans = 1, s = 0; scanf( %d%d , &n, &k); vector<int> a(n), fr(101), z(101); for (int i = 0; i < n; ++i) { scanf( %d , &a[i]); if (fr[a[i]]++ == 0) ++cnt, ++s; if (cnt == k + 1)...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 1e5 + 10; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; int ans = 0; vector<int> b(n); for (i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, k, j, c; while (scanf( %d%d , &n, &m) != EOF) { c = 0; char a[990][101], x; for (i = 0; i < n; i++) scanf( %s , a[i]); for (i = 0; i < n; i++) { for (k = 0; k < m; k++) { x = a[i][k]; ...
#include <bits/stdc++.h> using namespace std; int s[100010]; int main() { long long n, x; cin >> n >> x; long long sum = 0, ans = 0; for (int i = 0; i < n; i++) { cin >> s[i]; } sort(s, s + n); int j = 0; while (j < n) { if (x < 1) x = 1; ans += s[j] * x; x-...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5; int n; pair<long long, long long> a[MAXN + 5]; priority_queue<long long, vector<long long>, greater<long long> > q; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { long long t...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } co...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { register T sum = 0; register char cc = getchar(); int sym = 1; while (cc != - && (cc > 9 || cc < 0 )) cc = getchar(); if (cc == - ) sym = -1, cc = getchar(); sum = sum * 10 + cc - 0 ; cc = getc...
#include <bits/stdc++.h> using ii = std::pair<int, int>; bool visited[50001]; int nexts[50001]; int value[50001]; int n, start, x; void input() { for (int i = 1; i <= n; i++) { scanf( %d %d , &value[i], &nexts[i]); } } ii query(int pos) { visited[pos] = true; printf( ? %d n , pos);...
#include <bits/stdc++.h> using namespace std; int main() { string s, s1, s2; cin >> s; s1 = s; sort(s1.begin(), s1.end()); s2 += s1[0]; for (int i = 1; i < s1.length(); i++) { if (s1[i] != s1[i - 1]) s2 += s1[i]; } int d = 0; for (int j = s2.length() - 1; j >= 0; j--) { ...
#include <bits/stdc++.h> #pragma GCC optimize(3, Ofast , inline ) using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const long long maxn = (long long)1e6 + 5; const long long mod = 998244353; const long long inf = 0x3f3f3f3f; long long T = 1; vector<lon...
#include <bits/stdc++.h> using namespace std; const int int_inf = 0x7fffffff; const long long ll_inf = ~(1ll << 63); const double eps = 1e-7; char *p1, *p2, buf[1 << 20]; inline int read() { int f = 1, x = 0; char ch; while (!isdigit( ch = (p1 == p2 && (p2 = (p1 = b...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 0 ), ch = getchar(); return x; } const int N = 1e7 + 5; const long long mod = 998244353; int ksm(int a, int...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; set<char> ss; map<string, bool> mp; long long l = 0; for (long long i = 0; i < s.size(); i++) { if (!mp[s]) l++; mp[s] = true; rotate(s.begin(), s.end() - 1, s.end()); } cout << l << endl...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1100000; int p[MAXN], f[MAXN], g[MAXN]; int main() { int n; scanf( %d , &n); f[1] = 1, g[1] = 0; for (int i = 2; i <= n + 1; i++) { scanf( %d , &p[i]); f[i] = 1, g[i] = 0; for (int v = i; v != 1; v = p[v]) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, x; cin >> n >> x; string s; cin >> s; for (int j = 0; j < x; j++) { for (int i = 0; i < n - 1; i++) { if (s[i] == B && s[i + 1] == G ) { s[i] = G ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define poly vector<ll> #define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++) #define Rep(i,r,l) for(int i=(int)(r);i>...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int x = 0, y = 0; for (int i = 0; i < s.size(); i++) { x = x % 4; y = y % 4; if (s[i] == 0 ) { cout << 3 << << y + 1 << endl; y++; } else { cout << 1 << << x + 1 <<...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); srand(time(NULL)); int t; cin >> t; while (t--) { int n; cin >> n; unordered_map<string, int> codes; vector<string> v(n); for (int i = 0; i < n; i++) { st...
#include <bits/stdc++.h> using namespace std; double x, y, R, r, eps = 0.000001; int a, b; int main() { scanf( %lf , &r); for (a = 1; a < 11; a++) for (b = 1; b < 11; b++) { x = (double)a / 2; y = (double)b; R = sqrt(x * x + y * y); if (abs((double)a / 2 * (double)b...
#include <bits/stdc++.h> using namespace std; int n, m, l, r, a[100100], L[100100], R[100100]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); for (int i = 1; i <= n; ++i) if (a[i] > a[i - 1]) L[i] = i; else L[i] = L[i - 1]; for (int...
#include <bits/stdc++.h> using namespace std; int read() { int ret = 0; char c = getchar(); while (c > 9 || c < 0 ) c = getchar(); while (c >= 0 && c <= 9 ) ret = (ret << 3) + (ret << 1) + (c ^ 48), c = getchar(); return ret; } const int maxn = 55; const int maxk = 6; const i...
#include <bits/stdc++.h> using namespace std; string a, b; int ans = 0; vector<int> A, B; string cp(string s, int n) { string ans = s; for (int i = 1; i < n; i++) ans += s; return ans; } int main() { cin >> a >> b; for (int i = 1; i <= a.size(); i++) if (a.size() % i == 0 && cp(a...
#include <bits/stdc++.h> static const int MAXN = 5004; static const int ALPHA = 26; static const int MODULUS = 1e9 + 7; int n; char s[MAXN]; int binom[MAXN][MAXN]; int f[MAXN][ALPHA] = {{0}}, f_rowsum[MAXN] = {0}; void preprocess_binomials() { binom[0][0] = 1; for (int i = 1; i < MAXN; ++i) { ...
#include <bits/stdc++.h> using namespace std; std::vector<long long> prime; unsigned long long int power(unsigned long long int x, unsigned long long int y, unsigned long long int mod) { unsigned long long int res = 1; while (y) { if (y & 1) res = res * x % mod; ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T qmin(const T &x, const T &y) { return x < y ? x : y; } template <typename T> inline T qmax(const T &x, const T &y) { return x > y ? x : y; } template <typename T> inline void getmin(T &x, const T &y) { if (y < x) ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> moves(2, vector<int>()); for (int i = 0; i < 2; ++i) { int k; cin >> k; for (int j = 0; j < k; ++j) { int m; cin >> m; moves[i].push_back(m); } } qu...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn], b[maxn]; int p[maxn]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } memset(p, 0, sizeof(p)); for (int i = 1; i <= n; i++) { scanf( %d , &b[i]); ...
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; struct point { int x, y, id; point operator-(const point &a) const { point res; res.x = x - a.x; res.y = y - a.y; return res; } int operator*(const point &a) const { return x * a.y - y * a.x; } } p[100010]...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:512000000 ) using namespace std; void solve(bool); void precalc(); clock_t start; int main() { start = clock(); int t = 1; cout.sync_with_stdio(0); cin.tie(0); precalc(); cout.precision(10); cout << fixed; int testNum =...
#include <bits/stdc++.h> using namespace std; long long int pi[1000], ai[1000]; long long int bsearch(long long int arr[], long long int x, long long int n) { long long int a = 0; long long int k; long long int b = n - 1; while (a <= b) { k = (a + b) / 2; if (arr[k] == x) { } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1200 + 10; char s[maxn]; int a[maxn]; int main() { while (~scanf( %s , s)) { memset(a, 0, sizeof(a)); int len = strlen(s); int cnt = 0; int m; scanf( %d , &m); if (len % m == 0) { int cur = len / m; ...
#include <bits/stdc++.h> using namespace std; int i, m; string a, s; int main() { cin >> a >> s; m = s.size(); sort(s.begin(), s.end()); for (m--; i < a.size(); i++) { if (a[i] < s[m]) a[i] = s[m--]; } cout << a; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string one, o, two; vector<int> a(2, 0); cin >> n; cin >> one; a[0] += 1; while (n-- > 1) { cin >> o; if (o == one) a[0] += 1; else { a[1] += 1; two = o; } } if (a[0]...
#include <bits/stdc++.h> #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) const long double eps = 1e-12; const long double Pi = acos(-1); const long long md = 1e9 + 7; using namespace std; long long n, m, p[10100], f[10100], x, y; pair<long long, long long> d[10100]; bool used[10100]; boo...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 50, M1 = 998244353, M2 = 1e9 + 7; struct ModInt { int x1, x2; ModInt(int a = 0, int b = 0) : x1(a), x2(b) {} }; ModInt operator+(ModInt a, ModInt b) { return ModInt((a.x1 + b.x1) % M1, (a.x2 + b.x2) % M2); } ModInt operator-(Mod...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; k--; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int res = 0; if (a[k] != 0) { res++; a[k] = 0; } for (int i = 0...
#include <bits/stdc++.h> using namespace std; template <class T> inline T checkmin(T &a, T b) { return (a < b) ? a : a = b; } template <class T> inline T checkmax(T &a, T b) { return (a > b) ? a : a = b; } template <class T> T GCD(T a, T b) { if (a < 0) return GCD(-a, b); if (b < 0) re...
// Problem: A. Dungeon // Contest: Codeforces - Educational Codeforces Round 100 (Rated for Div. 2) // URL: https://codeforces.com/problemset/problem/1463/A // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; ...
#include <bits/stdc++.h> using namespace std; char ar[] = 1689 , s[1000010]; int val[10], ct[10]; int main() { do { val[atoi(ar) % 7] = atoi(ar); } while (next_permutation(ar, ar + 4)); scanf( %s , s); int len = strlen(s); for (int i = 0; i < len; ++i) ct[s[i] - 0 ]++; for (int i...
#include <bits/stdc++.h> const long long mod = 2147483647LL; long long read() { long long r = 0; char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); while (c >= 0 && c <= 9 ) { r = 10LL * r + (long long)c - 0 ; c = getchar(); } return r; } long long fast(long lo...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:20000000 ) using namespace std; int ri() { int x; scanf( %d , &x); return x; } long long rll() { long long x; scanf( %lld , &x); return x; } int mas[200500]; int tmas[200500]; int d1[100500]; int d2[100500]; int cnt[2...
#include <bits/stdc++.h> using namespace std; const int N = 500010; const int INF = 0x3f3f3f3f; const int iinf = 1 << 30; const long long linf = 2e18; const int MOD = 1000000007; const double eps = 1e-7; void print(int x) { cout << x << endl; exit(0); } void PRINT(string x) { cout << x <...
#include <bits/stdc++.h> using namespace std; const int maxn = 500; int n, ret, cnt; char a[maxn][maxn]; int arr[maxn][maxn]; pair<int, int> par[maxn][maxn]; multiset<pair<int, int> > s; pair<int, int> root(pair<int, int> c) { if (par[c.first][c.second].first < 0) return c; return par[c.first][c...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } if (n == 1) { if (a[0] == k) ...
#include <bits/stdc++.h> using namespace std; int t, m; int a[128], id = 1; int main() { cin >> t >> m; for (int i = 0; i < t; ++i) { string q; cin >> q; switch (q[0]) { case a : { int k; bool ok = false; cin >> k; for (int i = 0; i + k ...
#include <bits/stdc++.h> using namespace std; void OUT_TST(string s, istream_iterator<string> it) { cerr << s; } template <typename T, typename... Args> void OUT_TST(string s, istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << ; OUT_TST(s, ++it, args...); } template <cla...
#include <bits/stdc++.h> using namespace std; #define N 200020 int cnt, last[N], n, ans; struct edge { int to, next; } e[N << 1]; inline void add(int u, int v) { e[++cnt] = {v, last[u]}, last[u] = cnt; e[++cnt] = {u, last[v]}, last[v] = cnt; } int dfs(int x, int fa) { ve...
#include <bits/stdc++.h> using namespace std; int hag(int p, int t) { int d; d = max(3 * p / 10, p - ((p / 250) * t)); return d; } int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (hag(a, c) > hag(b, d)) cout << Misha ; if (hag(a, c) == hag(b, d)) cout << Tie ; if (hag(...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, f, t, sum = -999999999, m, x, i; cin >> n >> k; for (i = 0; i < n; i++) { cin >> f >> t; if (k < t) { m = f - (t - k); } else { m = f; } x = max(sum, m); sum = x; } cout...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; unordered_map<string, int> ma; int T, n, tot; int a[1000010], b[1000010]; long long dp[1000010][2], ans; struct node { int per, to; } e[1000010]; int head[1000010]; long long sum; void addedge(int from, int to) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; bitset<N> b; int p[N]; int cnt[N]; bool was[N]; int main() { int n, k; scanf( %d %d , &n, &k); for (int i = 0; i < n; i++) { scanf( %d , p + i); p[i]--; was[i] = false; } for (int i = 1; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; int main() { string c; cin >> c; string ans = regex_replace(c, regex( (/)+ ), / ); if (ans[ans.size() - 1] == / and ans.size() > 1) { ans[ans.size() - 1] = ; } cout << ans << endl; ; }
#include <bits/stdc++.h> using namespace std; const long long OO = 1e18; vector<int> prs = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; long long solve(long long num, int in, int lst) { if (in == prs.size() || lst == 0) return num == 1 ? 1 : -1; long long res = -1; long long cur = 1; long long cp = num...
#include <bits/stdc++.h> uint16_t C[10][10 + 1]; void flow(int i, int j, uint16_t c) { if (i >= 10) { return; } if (C[i][j] == (1 << 10)) { flow(i + 1, j, c >> 1); flow(i + 1, j + 1, c >> 1); } else { C[i][j] += c; } } int main() { int n, t; std::cin >> n >> t...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, Q = 1e5 + 10; int n, q; struct edg { int x, y, t; bool operator==(edg a) { return x == a.x && y == a.y; } } e[Q]; bool cmp(edg a, edg b) { return a.x < b.x || (a.x == b.x && a.y < b.y) || (a.x == b.x && a.y == b.y &...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const long long mo = 1e9 + 7; const long long inf = 1e9; const long long Inf = 1e18; long long w[N], a[N]; int x[N], y[N]; int main() { int n, m, k; scanf( %d%d%d , &n, &k, &m); for (int i = (1); i <= (n); ++i) scanf( %lld...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll LINF = 1001002003004005006ll; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return...
#include <bits/stdc++.h> using namespace std; int solve(int x) { int sum = 0; while (x >= 5) { sum += x / 5; x /= 5; } return sum; } int main() { int m; cin >> m; int k = 0; vector<long long> vec; for (int i = 1; i <= 1000000; i++) { long long sum = solve(i)...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const int INF = (int)1E9; const long long INF64 = (long long)1E18; const long double EPS = 1E-8; const long double PI = 3.1415926535897932384626433832795; const int MAXN = 5200; const int MAXF = 1001000; long long...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 10; const int M = 20; vector<int> soln[M][M]; int compute(vector<int> sha) { vector<int> sz(sha.size(), 1); vector<int> out[sha.size()]; for (int i = sha.size() - 1; i > 0; i--) { sz[sha[i]] += sz[i]; out[sha[i]].pu...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string op; int x = 0; for (int k = 0; k < n; k++) { cin >> op; if (op == ++X || op == X++ ) { x++; } else if (op == --X || op == X-- ) { x--; } } cout << x << endl; ...
#include <bits/stdc++.h> using namespace std; bool isprime(long long k) { for (long long i = 2; i <= sqrt(k); i++) if (k % i == 0) return false; return true; } long long bm(long long a, long long b, long long mod) { if (b == 0) return 1; long long t = bm(a, b / 2, mod); t = t * t % mod...
#include <bits/stdc++.h> using namespace std; int n, k, i, a[1000021], j; int main() { scanf( %d%d , &n, &k); if (n / k <= 2) { cout << -1; exit(0); } for (i = 1; i <= k * ((n / k) - 1); i++) a[i] = (i - 1) / ((n / k) - 1) + 1; j = ((n / k) - 1) * k; while (j <= n) for (i...
#include <bits/stdc++.h> int aa[100005]; int main(void) { int n; while (~scanf( %d , &n)) { for (int i = 0; i < n; i++) { scanf( %d , &aa[i]); } for (int i = 0; i < n - 1; i++) { printf( %d , aa[i] + aa[i + 1]); } printf( %d n , aa[n - 1]); } }
#include <bits/stdc++.h> using namespace std; static const int maxn = 3e5 + 5; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; multiset<int> ms; for (int i = 0; i < n; i++) { int x; cin >> x; ms.insert(x); } ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; int vis[200005]; int comp_size; int cycle_length; void dfs(int cur, int prev, int t, vector<vector<int>> &edges) { vis[cur] = t; comp_size++; for (int e : edges[cur]) { if (vis[e] == -1) { dfs(e, cur, t...
#include <bits/stdc++.h> using namespace std; long long pw[16], t[20], na[30], ma[30], ta[30], per[30]; vector<long long> rem; void calc_pw() { long long i; pw[0] = 1; for (i = 1; i <= 11; i++) pw[i] = 7 * pw[i - 1]; } long long conv(long long num) { long long ret = 0, temp; temp = num; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { long long x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2) { cout << abs(y1 - y2) << endl; } else if (y1 == y2) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, s; cin >> n >> s; long long cnt = 0, x = n; while (x) { cnt += x % 10; x /= 10; } long long ans = 0, now = 1; while (1) { if (cnt...
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; cin >> n; for (int i = 0; i < n; i++) { int x; scanf( %1d , &x); if (x) { count++; continue; } break; } cout << min(count + 1, n); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, x, y; int work() { int ans = 0; int b = x % m; if (b == 0) b = m; int a = x / m + (b != m); int d = y % m; if (d == 0) d = m; int c = y / m + (d != m); if (a == c) return 1; if (b == 1 && (d == m || y == n)) return 1; ...
#include <bits/stdc++.h> using namespace std; int M[52][52]; int main() { int n; cin >> n; for (int i = 0; i < n * (n - 1) / 2 - 1; i++) { int a, b; cin >> a >> b; a--, b--; M[a][b]++; } int _x = -1, _y = -1, x, y; bool enc = 0; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 5010; int n, arr[N], ans[(N << 1)]; vector<int> a[N], b[N]; const int inv2 = 500000004; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &arr[i]); } for (int i = n - 2; i >= 0; i--) { a[i].resize((...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; map<long long, long long> mp; int main() { long long n, k, p, x, ans = 0; scanf( %lld%lld%lld , &n, &p, &k); for (long long i = 0; i < n; ++i) { scanf( %lld , &x); mp[((x * x % p * x % p * x % p - x * k % p) % p + p...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; int main() { int n, m; scanf( %d%d , &n, &m); int maxc = 0; for (int i = 0; i < n; i++) { int minc = INF; for (int j = 0; j < m; j++) { int cij; scanf( %d , &cij); if (minc > cij) minc = cij;...
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { a = ((a) < 0 ? -(a) : (a)); b = ((b) < 0 ? -(b) : (b)); while (b) { a = a % b; swap(a, b); } return a; } const long long inf = 2147383647; const long long mod = 1000000007; const do...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 9 || s[i] == H || s[i] == Q ) { cout << YES ; return 0; } } cout << NO ; }
#include <bits/stdc++.h> int Pos(int a) { if (a < 0) { return 0; } return a; } int main() { int n = 0, p1 = 0, t1 = 0, p2 = 0, t2 = 0, p3 = 0; int energy = 0; std::vector<int> timeDatal; std::vector<int> timeDatar; std::cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; for (int i =...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010, mod = 998244353; inline int read() { int x = 0, f = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) f |= ch == - , ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return f ? -x : ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void solve() { int n, k; cin >> n >> k; vector<int> a(n * k); for (auto &it : a) cin >> it; reverse(a.begin(), a.end()); long long ans = 0; int mid = n / 2, cnt = 0; for (int i = mid; i < (int)a.size() && cnt++ ...
#include <bits/stdc++.h> using namespace std; const int maxn = 101111, maxm = 5011, inf = 2147000000; struct orz { int d, num; } a[maxn]; int n, v, ans; bool cmp(orz x, orz y) { return (x.d < y.d); } int main() { scanf( %d%d , &n, &v); int i, j, x, y; for (i = 1; i <= n; i++) scanf( %d%d ,...
#include <bits/stdc++.h> using namespace std; const int MXN = 1e2 * 2; const int TMXN = 1048576; const long long INF = 1e9 + 7; const long long INFL = 1e18; struct query { int l, r, id; }; int n; int a[TMXN]; long long ans[TMXN]; long long res; int cnt[TMXN]; int m, k; query q[TMXN]; b...
#include <bits/stdc++.h> int main(void) { int a, s, d; long long x, y; scanf( %d%d%d , &a, &s, &d); x = a / d; y = s / d; if (x * d < a) x++; if (y * d < s) y++; printf( %lld , x * y); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, a, b, c, res = LONG_LONG_MAX; int main() { cin >> n >> a >> b >> c; if (n % 4 == 0) return puts( 0 ); if (n % 4 == 1) { res = min(res, a * 3); res = min(res, a + b); res = min(res, c); } else if (n % 4 == 2) { res =...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> v[N]; vector<pair<int, int> > ans; int deg[N], maxT; void dfs(int x, int T, int u) { ans.push_back({x, T}); int beginT = T; for (auto it : v[x]) if (it != u) { if (T == maxT) { T = maxT - deg...
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint linf = 1e18 + 7; const lint inf = 1e9 + 7; const int MOD = 1000000007; void press(vector<long long>& x) { map<int, int> memo; int n = x.size(); for (int i = 0; i < n; ++i) { memo[x[i]] += 1; } int cur ...
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 9; struct edge { int to, nxt; } e[N * 2]; int hd[N], tot; void add(int u, int v) { e[++tot] = (edge){v, hd[u]}; hd[u] = tot; } int n, sz[N], msz[N]; void pre(int u, int fa) { for (int i = hd[u], v; i; i = e[i].nxt) ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T range(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } inline void setin(string s) { freopen(s.c_str(), r , stdin); } inline void setout(string...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) return a; else return b; } long long min(long long a, long long b) { if (a < b) return a; else return b; } long long gcd(long long a, long long b) { return b ? gcd(b, a ...
#include <bits/stdc++.h> using namespace std; char n[1000 + 2]; char m[1000 + 2]; int color_n[30]; int color_m[30]; int main() { while (scanf( %s , n) != EOF) { scanf( %s , m); memset(color_n, 0, sizeof(color_n)); memset(color_m, 0, sizeof(color_m)); for (int i = 0; i < strlen(n)...
#include <bits/stdc++.h> int main() { int N, X, sum = 0; std::cin >> N >> X; for (int i = 0; i < N; i++) { int tmp; std::cin >> tmp; sum += tmp; } if (sum + N - 1 == X) std::cout << YES n ; else std::cout << NO n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 10; inline long long rd() { long long x = 0, w = 1; char ch = 0; while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 3) + (x << 1) + (ch ^ 48); ...
#include <bits/stdc++.h> using namespace std; int n; int a[1010]; int sum = 0; int cnt = 0; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); sum += a[i]; } for (int i = 0; i < n; i++) { if ((sum % 2) == (a[i] % 2)) { cnt++; } ...
#include <bits/stdc++.h> using namespace std; istream& in = cin; int n; int a[1000010]; void input() { in >> n; for (int i = 1; i <= n; ++i) in >> a[i]; } long long mod = (long long)1e9 + 7; long long fac[1000010], inv[1000010]; long long quick_mod(long long a, long long p) { long long ret...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) int mod = 1000000007; using namespace std; bool isp(long long x) { for (long long i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; } void pog() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; } bool...
#include <bits/stdc++.h> using namespace std; int t1, t2; int s1[100010], s2[100010]; pair<int, int> c1[100010], c2[100010]; bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; } int main() { int n, v; cin >> n >> v; for (int i = 0; i < n; i++) { int t, p; cin >>...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(...