func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ct[2][6] = {0}; for (int i = 0; i < n; i++) { int tmp; scanf( %d , &tmp); ct[0][tmp]++; } for (int i = 0; i < n; i++) { int tmp; scanf( %d , &tmp); ct[1][tmp]++; } int ...
#include <bits/stdc++.h> using namespace std; long long j, k, s, l, m, n, t, d; long long e[111][33333], a, b, i, p, c; map<string, long long> y; string q, r, w; int main() { cin >> n >> a >> b >> c; n *= 2; for (i = 0; i <= a; i++) { for (j = 0; j <= b; j++) { k = n - i - 2 * j; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, k, d, t1, t2, kol; bool f; f = false; cin >> n; cin >> t; cin >> k; cin >> d; t1 = 0; t2 = 0; kol = 0; while (kol < n) { t1++; if (t1 % t == 0) { kol = kol + k; } } kol ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int y, w; cin >> y >> w; int ans; ans; if (y >= w) { ans = 6 - y + 1; } else if (w >= y) { ans = 6 - w + 1; } if (ans == 6) { cout << 1 << / << 1 << endl; }...
#include <bits/stdc++.h> using namespace std; int n, m, a[111], ans = 1e9; set<int> s[111]; int main() { ios_base ::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 0, x, y; i < m; ++i) { cin >> x >> y; s[x].insert(y); ...
#include <bits/stdc++.h> using namespace std; int main() { int temp = 0; int n = 0; cin >> n; vector<int> city(n); for (int i = 0; i < n; ++i) { cin >> city[i]; } int max = 0; int min = 0; for (int j = 0; j < n; ++j) { if (j == n - 1) { min = abs(city[j] - cit...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return (b == 0) ? a : gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a * (b / gcd(a, b)); } template <typename T> T mod_exp(T b, T p, T m) { T x = 1; while (p) { if (p & 1) x = ...
#include <bits/stdc++.h> using namespace std; int A[105][105]; int main() { int n; int ans = 0; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < n; j++) { if (s[j] == C ) { A[i][j] = 1; } else { A[i][j] = 0; ...
#include <bits/stdc++.h> using namespace std; char name[110][3000], text[110][3000]; int name_len[110], text_len[110]; bool found[110][110], dp[110][110]; int pre[110][110]; int chosen[110]; void variable_init() { memset(found, 0, sizeof found); memset(dp, 0, sizeof dp); } int main() { int...
#include <bits/stdc++.h> using namespace std; void readi(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = v * 10 + c - 0 ; while (isdigit(c = getchar())) v = v * 10 + c - 0 ; x = v * f; } void ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 != 0) { n += 1; } cout << (n / 2) - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxN(1e5 + 10); typedef int i_N[maxN]; int N, Gx[maxN][2], Fx[maxN][2][2]; i_N A; string S; int main() { scanf( %d n , &N); getline(cin, S); for (int i = 0; i < (int)S.size(); i++) A[i + 1] = S[i] == 1 ; A[0] = A[N + 1] = -1; for...
#include <bits/stdc++.h> using namespace std; int n, d; string s, t; map<pair<char, char>, vector<int> > M; map<char, vector<int> > N; int main() { ios_base::sync_with_stdio(false); cin >> n >> s >> t; d = 0; for (int i = 0; i < n; ++i) { if (s[i] != t[i]) { M[make_pair(s[i], t...
#include <bits/stdc++.h> using namespace std; set<int> s; int ans[300005]; int main() { int n, m, l, r, x; cin >> n >> m; for (int i = 1; i < n + 1; i++) { s.insert(i); ans[i] = 0; } for (int i = 0; i < m; i++) { cin >> l >> r >> x; set<int>::iterator lb = s.lower_bou...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; char s[N]; int n, f[N], mk[N], cnt[N]; vector<int> p; void init() { for (int i = 2; i < N; i++) if (!mk[i]) { p.push_back(i); for (int j = i + i; j < N; j += i) mk[j] = true; } } int main() { scanf( ...
#include <bits/stdc++.h> using namespace std; vector<vector<long long int> > edge(100010); long long int vis[100010]; vector<long long int> color[2]; bool dfs(long long int a, long long int c = 2) { vis[a] = c; color[c - 1].push_back(a); for (auto x : edge[a]) { if (!vis[x] && dfs(x, 3ll - c...
#include <bits/stdc++.h> using namespace std; int p[110]; int find(int v) { if (p[v] == v) return v; return p[v] = find(p[v]); } bool merge(int u, int v) { int x = find(u); int y = find(v); if (x != y) { p[x] = y; return true; } return false; } int main() { int ...
#include <bits/stdc++.h> using namespace std; char local = O ; template <typename T> void read(T &p) { cin >> p; } template <typename T, typename T1> void read(pair<T, T1> &p) { read(p.first); read(p.second); } template <typename T> void read(T arr[], long long n) { for (long long i...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; bool match(string s1, string s2) { long long cnt = 0; for (long long i = 0; s1[i]; ++i) { if (s1[i] != s2[i]) ++cnt; if (cnt > 1) return 0; } return 1; } int32_t main() { ios_base::sync_with_stdio(0); ...
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { if (a < b) return a; else return b; } static 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 ...
#include <bits/stdc++.h> using namespace std; int static_init = []() { ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; return 0; }(); constexpr int N = 3e5; int32_t n, x[2], c[N + 1], p[N + 1]; int64_t t[N + 2]; bool run(bool sw) { for (int k1 = 1; k1 <= n; k1++) { int i1 = ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 1e3 + 10; const int M = 1e4; int a[N][N]; int main() { int n, k, d; cin >> n >> k >> d; int flag = 1; memset((a), (0), sizeof(a)); if (n == 1) { while (d--) cout << 1 << endl; return 0;...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)3e3 + 5; const long long INF = (long long)1e15; pair<int, long long> dp[MAXN][MAXN]; vector<int> adj[MAXN]; int arr[MAXN]; int sub[MAXN]; int n, m; void dfs(int v, int pr = -1) { fill(dp[v], dp[v] + n + 1, make_pair(-n, -INF)); ...
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf( %d , &n); if (n & 1) printf( %d n , (n - 1) / 2); else { int w = 1; while (w <= n) w *= 2; w /= 2; printf( %d n , (n - w) / 2); } return 0; }
#include <bits/stdc++.h> using namespace std; int solve(vector<int> a, int bit) { if (bit == 0) { return a.size(); } if (a.size() <= 1) { return a.size(); } vector<int> v0, v1; for (int x : a) { if (1 & (x >> bit)) { v0.push_back(x); } else { v1.push_b...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T x, T y) { if (x < y) swap(x, y); while (y > 0) { T f = x % y; x = y; y = f; } return x; } const int maxn = 100007; int BLOCKSIZE = 350; set<int> s[maxn]; int a[maxn]; int nxt[maxn]; int n, m...
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long int, long long int> &a, pair<long long int, long long int> &b) { if (a.first == b.first) return a.second < b.second; return a.first > b.first; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lo...
#include <bits/stdc++.h> using namespace std; int a, b, h, n, i; long long x, ans; pair<pair<int, int>, int> p[100005]; map<long long, long long> f; void update(int index, long long value) { while (index < 1e9) { f[index] = max(f[index], value); index += (-index & index); } } long lo...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n % k == 0) cout << n + k << endl; else cout << n + (k - n % k); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; const ld EPS = 1E-9; struct pt { ld x, y; }; struct seg { pt p, q; int id; ld get_y(ld x) const { if (abs(p...
#include <bits/stdc++.h> using namespace std; char str[200005]; int main() { int ts; scanf( %d , &ts); while (ts--) { int n; scanf( %d %s , &n, str); vector<int> vec; for (int i = 0; i < n; i++) { int j = i, c = 0; while (i < n && str[i] == str[j]) i++, c++; ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } int main() { int n; long long k; scanf( %d%I64d , &n, &k); long long ans = 1; bool ok = false; fo...
#include <bits/stdc++.h> using namespace std; int mr[] = {0, 1, 0, -1}; int mc[] = {1, 0, -1, 0}; char a[52][52]; int id[52][52]; int ar[2500], br[2500], ac[2500], bc[2500]; void flood(int r, int c, char color, int tag) { ar[tag] = min(ar[tag], r); br[tag] = max(br[tag], r); ac[tag] = min(ac[t...
#include <bits/stdc++.h> using namespace std; int hx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; int hy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int nx[] = {1, -1, 0, 0, -1, 1, 1, -1}; int ny[] = {0, 0, 1, -1, 1, -1, 1, -1}; class pt { public: int x, y; }; i...
#include <bits/stdc++.h> using namespace std; int N, K, T, to[25]; long double prob[25], dp[2000100], val[25], ans[25]; bool v[2000100]; long double calc(int mask) { if (v[mask]) return dp[mask]; v[mask] = 1; int i; long double tot = 0; for (i = 0; i < N; i++) if (mask & (1 << i)) to...
#include <bits/stdc++.h> using namespace std; vector<long long> graph[200010]; long long v[200010], new_visit[200010], MAX_node, mx, cnt; void dfs(long long node) { v[node] = 1; if ((long long)graph[node].size() > mx) { mx = (long long)graph[node].size(); MAX_node = node; } for (auto...
#include <bits/stdc++.h> using namespace std; vector<int> p; vector<pair<int, int> > v, ans; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) return a.second > b.second; else return a.first < b.first; } int main() { int n; cin >> n; int a, b; for (in...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const long long INF64 = 1000000000000000007; int n; int p[17]{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59}; int a[105]; int number[60]; int dp[105][1 << 17]; int pred[105][1 << 17]; void find_pred(int x, int...
#include <bits/stdc++.h> using namespace std; long long n, m, budget; long long price[100005], perMoney[100005]; bool can(int k) { long long curBudget = 0; int j = 0; for (int i = k - 1; i >= 0; i--, j++) { curBudget += max(0ll, price[j] - perMoney[i]); } return curBudget <= budget; ...
#include <bits/stdc++.h> using namespace std; struct Node { int loc; int s; int v; Node(int ll, int ss, int vv) : loc(ll), s(ss), v(vv) {} bool operator<(const Node& other) const { return v > other.v; } }; vector<pair<int, int> > adj[32]; int main() { priority_queue<Node> que; int ...
#include <bits/stdc++.h> using namespace std; long long t, n, i, j, k, b[200005], a[200005], x, m, l, r, mid, ans, s; vector<long long> u, v; int main() { ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); cin >> n; for (i = 0; i < n; i++) { cin >> x; if (x % 2) v.push_...
#include <bits/stdc++.h> using namespace std; int n, m; int visit[111111]; vector<int> v[111111], mark[111111]; int dfs(int t) { vector<int> v1; int i; for (i = 0; i < v[t].size(); i++) { int u = v[t][i]; if (visit[mark[t][i]] == 0) { visit[mark[t][i]] = 1; int w = dfs(...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> vi1, vi2; for (int i = 0; i < n; i++) { int x; cin >> x; vi1.push_back(x); } sort(vi1.begin(), vi1.end()); vi1.push_back(1e9); for (int i = 0; i < m; i++) { int a, ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int t, h, g; cin >> t; while (t--) { scanf( %d %d , &h, &g); int n = (1 << h) - 1, m = (1 << g) - 1; std::vector<pair<int, int> > a(1 << h); for (int i = 0; i < n; i++) { scanf( %d , &a[i]....
#include <bits/stdc++.h> using namespace std; void solve() { int n, cnt = 0; cin >> n; vector<vector<int>> adj(n); vector<int> deg(n); for (int i = 0; i < n - 1; i++) { int x, y; cin >> x >> y; x--, y--; adj[x].push_back(y); adj[y].push_back(x); deg[x]++, deg[...
#include <bits/stdc++.h> struct node { int x, l; } a[200005]; int skip[200005][25]; int mx[200005]; long long f[200005][25]; inline int read() { register int x = 0, f = 1; register char s = getchar(); while (s > 9 || s < 0 ) { if (s == - ) f = -1; s = getchar(); } whi...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n; cin >> n; vector<int> v(n); set<int> st; for (int i = 0; i < n; i++) { cin >> v[i]; st.insert(v[i]); } sort(v.begin(), v.end()); int mx = v.bac...
#include <bits/stdc++.h> using namespace std; int n, q, i, j, u, v, k; int a[300003]; int last[19]; int go[300003][19]; int main() { cin >> n >> q; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < 19; i++) { go[n][i] = n; last[i] = n; } for (i = n - 1; i >= 0; i--) { ...
#include <bits/stdc++.h> using namespace std; vector<int> arr(78498); vector<vector<int>> in(505, vector<int>(505)); vector<vector<int>> out(505, vector<int>(505)); void SieveOfEratosthenes(int n) { vector<bool> prime(n + 1, true); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { ...
#include <bits/stdc++.h> using namespace std; int main() { char a[103], c; int length, i, m; gets(a); length = strlen(a); for (i = length - 2; i >= 0; --i) { if (a[i] != ) { c = a[i]; break; } } if (c == a || c == e || c == i || c == o || c == u |...
#include <bits/stdc++.h> using namespace std; int main() { int vp, vd, t, f, c, ans; double cc, d; scanf( %d%d%d%d%d , &vp, &vd, &t, &f, &c); if (vd <= vp) { printf( 0 n ); return 0; } d = vp * t; cc = c; ans = 0; while (1) { if (d + d / (vd - vp) * vp >= cc - 1...
#include <bits/stdc++.h> using namespace std; vector<int> v; int n, x, now; long long ans; char a[3]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a; if (a[0] == a ) { cin >> x; v.insert(lower_bound(v.begin(), v.end(), x), x); } if (a[0] == d...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = v * 10 + c - 0 ; while (isdigit(c = getchar())) v = v * 10 + c - 0 ; x = v * f; } ...
#include <bits/stdc++.h> using namespace std; class Jora { public: int a; int b; }; int myfunc(Jora A, Jora B) { if (A.a < B.a) return 1; if (A.a > B.a) return 0; return A.b < B.b; } Jora jrr[200200]; int n; vector<int> ser; map<int, int> taken; map<int, vector<int> > mp; in...
#include <bits/stdc++.h> using namespace std; long long f(long long l) { if (l < 10ll) return l; long long L = l, t = 1ll, ans = 0ll; int x = 0, last; while (L) { x++; last = L % 10; L /= 10; } for (int i = 1; i < x; i++) { ans += 9ll * t; if (i >= 2) t *= 10ll;...
#include <bits/stdc++.h> int main() { long long k, l, c = 0; scanf( %I64d , &k); scanf( %I64d , &l); while (l % k == 0) { l /= k; c++; } if (c >= 0 && l == 1) printf( YES n%I64d , c - 1); else printf( NO ); }
#include <bits/stdc++.h> using namespace std; struct Node { int id, fail, next[26]; void init() { id = -1; fail = -1; memset(next, 0, sizeof(int) * 26); } } node[2000050]; int e; void insert(char *str, int id) { int len = strlen(str); int pos = 0; for (int i = 0; i < ...
#include <bits/stdc++.h> const int xn = 200001, xe = 399999; int head[xn], next[xe], to[xe], N, E, fa[xn], q[xn], ue[xn], O[xn * 5], L, col[xn], D; int main() { scanf( %d , &N); bool allblack = 1; for (int i = 1; i <= N; i++) { scanf( %d , col + i); if (col[i] == -1) allblack = 0; ...
#include <bits/stdc++.h> using namespace std; long long n, cntu[1000006], cntd[1000006], preu[1000006], pred[1000006]; string s; vector<long long> lisu, lisd; int main() { ios::sync_with_stdio(0); cin >> n >> s; lisd.push_back(0); lisu.push_back(0); for (int i = 1; i <= n; i++) { if ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long t; cin >> t; while (t--) { long long a; cin >> a; long long b; cin >> b; if (b >= a) { if (b % a == 0 && pow(2, (long long)log2(b / a)) == b / a...
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cin >> n; if (n == 1) { count = abs(2 - i) + abs(2 - j); cout << count << endl; return 0; } } } c...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, v; int sum = 0; int cnt[10]; memset(cnt, 0, sizeof cnt); cin >> n; while (n--) { cin >> v; cnt[v]++; sum += v; } if (cnt[0] == 0) { cout ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, string> > v[10020]; int main() { long long n, m; pair<long long, string> p; long long temp; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> p.second; cin >> temp; cin >> p.first; v[temp].push_back(...
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } const double EPS = 1e-9; const double PI = acos(-1.); const int INF = 1e8; const int MAXN = 505; const long long MOD = 1e9 + 7; int v[MAXN]; int dp[MAXN][MAXN]; void solve() { ...
#include <bits/stdc++.h> using namespace std; int n, a[110], suml[110], sumr[110], ans = 0; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) suml[i] = suml[i - 1] + (a[i] == 0); for (int i = n; i >= 1; i--) sumr[i] = sumr[i + 1] + (a[i] == 1); for (...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int n; cin >> n; vector<vector<long double> > dist(n + 1, vector<long double>(n + 1)); vector<long double> x(n + 1), y(n + 1), z(n + 1); vector<long l...
#include <bits/stdc++.h> using namespace std; inline int getint() { static char c; while ((c = getchar()) < 0 || c > 9 ) ; int res = c - 0 ; while ((c = getchar()) >= 0 && c <= 9 ) res = res * 10 + c - 0 ; return res; } const int MaxN = 200005; const int M = 1000000007; inl...
#include <bits/stdc++.h> using namespace std; int xx[4] = {0, 0, 1, -1}; int yy[4] = {1, -1, 0, 0}; int n, m, b, s; int x[int(1e5)], y[int(1e5)]; int main() { scanf( %d%d , &n, &m); scanf( %d , &b); for (int i = (1), _b = (b); i <= _b; i++) { scanf( %d , &s); x[s] = true; } s...
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 10; int ad[N][N]; long long n; pair<int, int> t[N]; bool ok; int c[N]; void connect(int k) { for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (abs(t[i].first - t[j].first) + abs(t[i].second - t[j].secon...
#include <bits/stdc++.h> using namespace std; long long ans = 0; int n, u, r; vector<int> b, k; vector<int> p; void exec(vector<int> a, int type, int count) { if (count < u) { if (type == 0) { for (int i = 0; i < n; ++i) a[i] = a[i] ^ b[i]; exec(a, 1, count + 1); } else { ...
#include <bits/stdc++.h> using namespace std; int book[100010]; vector<pair<int, int>> v; deque<int> high, low; int main() { int n, k, ans = 0, num = 0, r, l; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> book[i]; for (r = 1, l = 1; r <= n; r++) { while (!high.empty() && high.back()...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > Dates; int n, x, y, ans, cur; int main() { std::ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; Dates.push_back(make_pair(x, y)); } sort(Dates.begin(), Dates.end()); ...
#include <bits/stdc++.h> using namespace std; string a[] = { zero , one , two , three , four , five , six , seven , eight , nine }; string b[] = { ten , twenty , thirty , forty , fifty , sixty , seventy , eighty , ninety }; string c[] = { eleven , twelve ,...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long int INF = 3e16; const int N = 200010; int n; int ask(vector<int> v) { printf( ? ); for (int i = 0; i < n; i++) printf( %d , v[i]); printf( n ); fflush(stdout); int ans; scanf( %d , &ans); ret...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[300000 + 13]; int n; void erf() { for (int i = 1; i < n; i++) { if (a[i - 1].first + 1 >= a[i].first) a[i].first = a[i - 1].first + 1; } } int main() { int cur, ebte; cin >> n; for (int i = 0; i < n; i++) { cin >>...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e6; long long a[100000 + 5]; bool vis[100000 + 5]; char c[] = { 6 , 7 , 8 , 9 , T , J , Q , K , A }; int main() { long long n; string s, s1, s2; cin >> s >> s1 >> s2; if (s1[1] == s[0]) { if (s2[1] != s[0]) ...
#include <bits/stdc++.h> using namespace std; int getID(char nms[202][30], char s[30], int &len) { for (int i = 0; i < 30; ++i) { if (s[i] >= a && s[i] <= z ) s[i] += A - a ; } for (int i = 0; i < len; ++i) { if (strcmp(nms[i], s) == 0) return i; } strcpy(nms[len], s); len+...
#include <bits/stdc++.h> using namespace std; ; const long long N = 5e3 + 10; vector<bitset<N> > v; vector<pair<long long, pair<long long, long long> > > hor, ver; long long n, cnt, y11, y2, x1, x2; long long ans; bool check(long long x, pair<long long, long long> a) { return a.first <= x && x <= a....
#include <bits/stdc++.h> const double PI = 3.141592653589793238460; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n], i, sum = 0, maxi = -1000000000, mi...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1760777216 ) using namespace std; const double Pi = 3.14159265358979323846; int main() { int T; scanf( %d , &T); while (T--) { double R, r, k; scanf( %lf%lf%lf , &R, &r, &k); double x1 = 0.5 / R, x2 = 0.5 / r, rr = fabs(x1 - ...
#include <bits/stdc++.h> using namespace std; bool arr[100100]; int dp[100100]; int pref[100100]; int pref2[100100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n; cin >> n; char a; for (int i = 1; i <= n; i++) { cin >> a; if (a == G...
#include <bits/stdc++.h> using namespace std; ifstream f( test.in ); ofstream g( test.out ); int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, ans = 0; cin >> n; stack<int> s; int x; cin >> x; s.push(x); for (int...
#include <bits/stdc++.h> using namespace std; string a, b; int main() { cin >> a >> b; if (a == b) cout << a; else cout << 1; }
#include <bits/stdc++.h> using namespace std; vector<set<int> > newadj(212345); int visit[212345]; vector<vector<int> > adj(212345); vector<int> vec, vecans; set<int> seti; int cnt = 0; int pos[212345]; int dfs(int cur) { cnt++; visit[cur] = 1; set<int>::iterator it; for (it = newadj[c...
#include <bits/stdc++.h> using namespace std; int main() { int b = -1, n = 0, limit = 10; string pass, box = 0000000000 , zero, one, two, three, four, five, six, seven, eight, nine; cin >> pass; cin >> zero; cin >> one; cin >> two; cin >> three; cin >> four; cin...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 20; const int MAXS = (1 << 16) + 10; long long dp[MAXS]; int ans[MAXN], req[MAXN]; bool vis[MAXN]; int main() { long long n, y, m; cin >> n >> y >> m; y -= 2001; for (int i = 1; i <= m; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, q; const long long N = 2e5 + 100; vector<long long> v[N]; long long dfn[N], num[N], val[N], sz[N], hs[N], tp[N], dep[N], f[N]; inline void dfs(long long x, long long fa) { sz[x] = 1; long long num = 0; dep[x] = dep[fa] + 1; f[x] = fa; ...
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const long long linf = (1ll << 62) - 1; const int N = 200; const int M = 1e9 + 7; const long long M2 = 1ll * M * M; int n; long long a[N]; int mat[N][N]; int result[N][N]; void multiply(int a[N][N], int b[N][N]) { sta...
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; inline long long int max(long long int a, long long int b) { return a > b ? a : b; } inline long long int min(long long int a, long long int b) { return a > b ? b : a; } inline int read() { int x = 0; char c = getchar()...
#include <bits/stdc++.h> long long T, n, k; long long a, sum, num; int main() { scanf( %I64d%I64d , &n, &k); for (long long i = 1; i <= n; i++) { scanf( %I64d , &a); if (sum - (i - 1 - num) * (n - i) * a >= k) sum += a * (i - 1 - num); else { printf( %I64d n , i); ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9, MOD = 1e9 + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0}; const long long LINF = 1e18; const long double PI = abs(acos(-1)); int a, b, c; int main() { cin >> a >> b >> c; for (int x1 = (0); x1 < (3); x1++) { for ...
#include <bits/stdc++.h> using namespace std; int dp[3001]; int n; struct node { int pos, val; bool operator<(const node& a) const { return val < a.val; } } nodes[3001]; int main() { int t; scanf( %d , &t); while (t--) { int ans = 0; scanf( %d , &n); for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; const int inf = ~0u >> 1, MOD = 1e9 + 7; inline int rd() { int first = 0, c = 0, f = 1; for (; c < 0 || c > 9 ; c = getchar()) f = c != - ; for (; c >= 0 && c <= 9 ; c = getchar()) first = first * 10 + c - 0 ; return f ? first : -first; } c...
#include <bits/stdc++.h> using namespace std; int lsb(int val) { return val & ((val ^ (val - 1))); } pair<int, pair<int, int> > a[600666]; int Arb[600666], SEG[600666], result[600666]; bool comp(pair<int, pair<int, int> > i1, pair<int, pair<int, int> > i2) { return i1.second.second < i2.second.second; }...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (b != 0) { int r = a % b; a = b; b = r; } return a; } void FindMinimum(int a[], int &n) { int g = gcd(a[0], a[1]); for (int i = 2; i < n; ++i) g = gcd(a[i], g); cout << g * n; } int main() {...
#include <bits/stdc++.h> using namespace std; int expo(int base, int exponent, int mod) { int ans = 1; while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base) % mod; base = (1LL * base * base) % mod; exponent >>= 1; } return ans % mod; } int n, a[5005], ans[10005], p...
#include <bits/stdc++.h> using namespace std; const long long lim = 100000000000ll; long long qv[61], dis[100010], ma, nw, dep[100010]; int n, Q, ans[61], x, y, v, hd[100010], cnt, q[100010], l, r, maa, la[100010], rt[100010]; struct node { int to, next, val; } e[200010]; struct seg { int ls...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int nax = 2e5 + 10; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, f; cin >> n >> f; vector<int> k(n), l(n); vector<pair<int, int> > a; for (int i = 0; i < n; i++) { cin >>...
#include <bits/stdc++.h> using namespace std; const int INF = 987654321; bool adj[4010][4010]; int n, m, u, v, cnt[4010]; vector<vector<int> > node; int main() { scanf( %d%d , &n, &m); node.resize(n + 1); while (m--) { scanf( %d%d , &u, &v); node[u].push_back(v); node[v].push_b...
#include <bits/stdc++.h> using namespace std; struct wall { double x, y; wall() {} wall(double x, double y) : x(x), y(y) {} }; struct tx { double d; int v; tx() {} tx(double d, int v) : d(d), v(v) {} }; bool cmp2(const tx& p1, const tx& p2) { return p1.d < p2.d; } bool cmp(cons...