func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int x[20005]; int y[20005]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { int xx, yy; scanf( %d %d , &xx, &yy); x[xx + 10000]++; y[yy + 10000]++; } long long ret = 0, sumx = 0, sumy = 0, tx = 0, ty = 0...
#include <bits/stdc++.h> using namespace std; bool maze[3][100001]; int judge(int r, int c) { if (r == 1) { if (c == 100000) return maze[2][99999] + maze[2][100000]; return maze[2][c - 1] + maze[2][c] + maze[2][c + 1]; } else { if (c == 1) return maze[1][1] + maze[1][2]; if (c == 1...
#include <bits/stdc++.h> using namespace std; long long int ESP = 1e18; long long int FCB = 1e9 + 7; long long int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const long long int N = 5005; long long int l[N], r[N]; vector<pair<long long int, long long int>> vv; bool fly(long long int x, long long int...
#include <bits/stdc++.h> using namespace std; int n, m, k, a[111111]; int main() { cin >> n >> m >> k; if (n % 2 == 0) { cout << 0 << endl; return 0; } for (int i = 0; i < n; i++) cin >> a[i]; int maxans = (int)2e9; for (int i = 0; i < n; i += 2) if (a[i] < maxans) maxans...
#include <bits/stdc++.h> using namespace std; int a[222], b[222]; int main() { int n, ans = 0; cin >> n; int p, q, r, s; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; for (int i = 0; i < n; i++) { p = q = r = s = 0; for (int j = 0; j < n; j++) { if (j == i) continue; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int i, temp, temp2, a[n + 1]; for (int i = 0; i < n + 1; i++) a[i] = 0; for (int i = 0; i < n - 1; i++) { cin >> temp >> temp2; a[temp]++; a[temp...
#include <bits/stdc++.h> using namespace std; int t, num[30], ans; char s[100005]; int main() { cin >> t; while (t--) { ans = 0; memset(num, 0, sizeof(num)); scanf( %s , s + 1); int len = strlen(s + 1); for (int i = 1; i <= len; i++) { num[s[i] - A + 1]++; }...
#include <bits/stdc++.h> using namespace std; using namespace std; const long long mod = 1e9 + 7; const int inf = 1e9; string s; long long expMod(long long base, long long ex, long long mod) { if (ex == 0) return 1; long long temp = expMod(base, ex / 2, mod); temp = (temp * temp) % mod; if (...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int64_t sum1 = 0; int64_t sum2 = 0; int to_double = 0; int zero = 0; std::set<std::pair<int, int>> doubled; std::set<std::pair<int, int>> pend; for (int i = 1; i <= n; i++) { int x, y; scanf( %d%d , &x, &y); ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; if (k % (n - 1) == 0) { cout << (k / (n - 1) * n) - 1 << endl; } else { cout << k / (n - 1) * n + k % (n - 1) << endl; } } }
#include <bits/stdc++.h> using namespace std; bool isSeparator(char ch) { return (ch == , || ch == || ch == ; ); } int main() { int i, j; bool isNumber; string s, ss; vector<string> words[2]; cin >> s; s += ; ss = , isNumber = true; for (i = 0; i < s.length(); i++) { ...
#include <bits/stdc++.h> using namespace std; const int mN = 222222; int n; int a[mN], outa[mN], outb[mN], ge[mN]; vector<int> ans; struct Bit { int c[mN]; void clear() { memset(c, 0, sizeof(c)); } int lob(int x) { return x & (-x); } void add(int x, int dt) { while (x <= n) { c...
#include <bits/stdc++.h> using namespace std; const int N = 4e6 + 7, M = 2e6; const long long mod = 1e9 + 7; inline int read() { int ret = 0; char ch = getchar(); bool f = 1; for (; !isdigit(ch); ch = getchar()) f ^= !(ch ^ - ); for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret <<...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, W, i, j, k; cin >> n >> m >> W; long long w[n], b[n]; for (i = 0; i < n; i++) cin >> w[i]; for (i = 0; i < n; i++) cin >> b[i]; vector<long long> G[n]; for (i = 0; i < m; i++) { cin >> j >> k; j--; ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); long long power(long long b, long long e, long long m) { if (e == 0) return 1; if (e & 1) return b * power(b * b % m, e / 2, m) % m; return power(b * b % m, e / 2, m); } long...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; ++i) cin >> arr[i]; sort(arr.begin(), arr.end()); int i = 0, j = n - 1; vector<int> left; vector<int> right; while (i <= j) { right.push_back(arr[j--]); ...
#include <bits/stdc++.h> using namespace std; int main() { int p, x, ans = 0; bool b; cin >> p; for (int i = 1; i < p; i++) { b = 1; x = 1; for (int j = 1; j < p - 1; j++) { x = (x * i) % p; if ((x - 1) % p == 0) b = 0; } if (((x * i) - 1) % p != 0) b = ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, i, j, A[200005], s = 1; cin >> n; for (long long(i) = 0; (i) < (n); (i) = (i + 1)) { cin >> A[i]; if (A[i] == n) { k = i; } } for (j = k; j < n - 1; j++) { if (A[j] < A[j + 1]) { s ...
#include <bits/stdc++.h> using namespace std; int n; const int maxN = 2005; int a[maxN][maxN]; int b[maxN][maxN]; vector<pair<int, int>> by[maxN]; const int dx[3] = {-1, 0, 0}; const int dy[3] = {0, -1, 1}; int his_val[maxN]; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr)...
#include <bits/stdc++.h> using namespace std; constexpr int N = 1e6 + 10; constexpr int M = 30; long long a1 = 2, a2 = 4, n, ans = 2, t = 4, dis[N], dp[N][M], v, dist1, dist2; int get_lca(int a, int b) { if (dis[a] < dis[b]) swap(a, b); while (dis[a] != dis[b]) a = dp[a][(int)log2(dis[a] - dis[b])]; ...
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> v, z; long long n, i, j, k; cin >> n; while (n != 0) { v.push_back(n % 10); n = n / 10; } long long p = 1; for (i = 0; i < v.size(); i++) { p = p * v[i]; } z.push_back(p); for (i = ...
#include <bits/stdc++.h> using namespace std; vector<int> road_wt[2 * 100000 + 5]; vector<int> rail_wt[2 * 100000 + 5]; vector<int> road[2 * 100000 + 5]; vector<int> rail[2 * 100000 + 5]; int visited[2 * 100000 + 5]; struct r { int city; signed long long int cost; int type; r() {} r(in...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int qtn; cin >> qtn; vector<long long int> resp(qtn + 1); resp[qtn] = 1000000000000000010; for (int i = 0; i < qtn >> 1; i++) { long long int n; cin >> n; resp[qtn - i -...
#include <bits/stdc++.h> using namespace std; int a[26], l[26], n, k, x, se, t; char b; string s; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> b >> s; if (x == 1) { if (i == n - 1) break; if (b != . ) se++; continue; } if (b != ? ) ...
#include <bits/stdc++.h> using namespace std; int xs[8] = {1, 1, 1, 0, 0, -1, -1, -1}; int ys[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int x1, y1, x2, y2; cin >> x1 >> y1; cin >> x2 >> y2; int nx, ny; int mV = INT_MAX; for (int ...
#include <bits/stdc++.h> using namespace std; int main() { long long m, h1, a1, x1, y1, h2, a2, x2, y2; long long p1, p2, q1, q2; while (cin >> m >> h1 >> a1 >> x1 >> y1 >> h2 >> a2 >> x2 >> y2) { p1 = p2 = q1 = q2 = 0; for (long long i = 1; i <= 2 * m; i++) { h1 = (h1 * x1 + y1) % m...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; if (n > 2) cout << n - 2 << endl; else if (n <= 2) cout << n + 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, i, flag; cin >> t; while (t--) { string s1, s2; cin >> s1 >> s2; flag = 0; for (i = 0; i < s1.length(); i++) { if (find(s2.begin(), s2.end(), s1[i]) == s2.end()) flag++; } if (flag == s1.length(...
#include <bits/stdc++.h> using namespace std; string s; int a[30]; int main() { int n; cin >> n; cin >> s; for (int i = 0; i < n; i++) { a[s[i] - a ]++; } for (int i = 0; i < 26; i++) { int temp = i; for (int j = 0; j < a[temp]; j++) { cout << char( a + temp);...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1e3 + 5; const int INF = 0x3f3f3f3f; const double eps = 1e-9; short int mp[MAXN][MAXN]; int d[MAXN][2]; bool vis[MAXN]; int n, m, s, t, u, v; void dijkstra(int s, int idx) { memset(vis, false, sizeof(vis)); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[101] = {0}, s = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> m; a[m]++; s = max(a[m], s); } cout << s; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; void solve() { int n, ans = 0; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; ans = max(ans, a[i] - i - 1); } cout << ans << n ; } int main() { int t; cin >> t; ...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( -O3 ) struct vertex { bool vis = false; vector<pair<long long int, long long int> > adj; long long int low = 1000000007; long long int dp = 0; long long int parent = -1; }; long long int tim = 0, n, m; vector<pair<long l...
#include <bits/stdc++.h> int mod = 1000000000 + 7; long long int inf = 1000000000000000000; using namespace std; mt19937 unlucko(chrono::steady_clock::now().time_since_epoch().count()); vector<int> tree[200000], way(200000), dp(200000), ans(200000); void dfs(int node, int pnode) { dp[node] = way[node]; ...
#include <bits/stdc++.h> constexpr int maxn = 2e5 + 5; constexpr int inf = 1e9; constexpr int mod = 1e9 + 7; using namespace std; using lint = long long; using pii = pair<int, int>; int t, n, a[maxn], b[maxn]; lint ans; map<int, int> ma, mb; signed main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; vector<long long> ad[200009]; long long vis[200009]; long long cnt, ans; void dfs(int u) { vis[u] = 1; cnt++; for (auto x : ad[u]) { if (!vis[x]) dfs(x); } } int main() { long long i, j, k, l, m, n, u, v; cin >> n >> k; for (i...
#include <bits/stdc++.h> int query(int aa[][150 + 1], int l0, int l1, int r0, int r1) { return l0 > l1 || r0 > r1 ? 0 : ((long long)aa[l1][r1] - aa[l0 - 1][r1] - aa[l1][r0 - 1] + aa[l0 - 1][r0 - 1]) % 1000000007; ...
#include <bits/stdc++.h> int a, b, i, j, x, y, ch, P[202], Q[202], X[202], Y[202]; bool ran(int A, int B, int C) { if (A <= B && B <= C) return true; else return false; } int main() { for (i = 0; i <= 23; i++) X[i] = 25, Y[i] = i; for (i = 24; i < 200; i++) { X[i] = i + 2; ...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5; const long long P = 1e9 + 7; long long n; long long col[N], f[N], g[N]; vector<long long> a[N]; long long read(void) { long long s = 0, w = 0; char c = getchar(); while (!isdigit(c)) w |= c == - , c = getchar(); while ...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n; cin >> n; int a[n], i, j, k, l, m; string s, temp; for (i = 0; i < n; i++) cin >> a[i]; char c = a , d; for (i = 0; i <= 50; i++) { s += a ; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int k1, k2, k3; cin >> k1 >> k2 >> k3; int n = k1 + k2 + k3; int maps[n]; for (int i = 0; i < n; i++) { int inp; cin >> inp; inp--; if (i < k1) ...
#include <bits/stdc++.h> using namespace std; void yala_bena() { cin.tie(0); std::ios::sync_with_stdio(0); } const int m_r = 999999; int k = -1; int bestsum, limit; vector<long long> ans; int binary(int number) { while (number) { k++; if (number % 2) return k; number /= 2; ...
#include <bits/stdc++.h> using namespace std; const int INF = (1u << 31) - 1; const int MAXN = 100086; int mice[MAXN], arr[MAXN], chese[MAXN]; int main() { for (int n, m; ~scanf( %d%d%*d%*d , &n, &m);) { for (int i = 0; i < n; i++) { scanf( %d , &mice[i]); } for (int i = 0; i < m...
#include <bits/stdc++.h> using namespace std; long long int a[101][101], f[101], ans[101]; int main() { int n, m; cin >> n >> m; memset(a, 0, sizeof(a)); memset(f, 0, sizeof(f)); memset(ans, 0, sizeof(ans)); for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { cin >>...
#include <bits/stdc++.h> using namespace std; const int mod = 7 + (int)1e9; long long process(string s) { for (int i = 0; i < s.size(); i++) s[i] = (s[i] - 0 ) % 2 + 0 ; return stoll(s); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; char c; map<long long, int> m...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int n, a, b; int max(int a, int b) { if (a > b) return a; return b; } bool checkNorm(pair<int, int> f, pair<int, int> s) { int x1, y1; x1 = max(f.first, s.first), y1 = f.second + s.second; if (x1 <= a && y1 <= b) re...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cnt[100005]; int cmax[10]; memset(cnt, 0, sizeof(cnt)); memset(cmax, 0, sizeof(cmax)); for (int i = 1; i <= n; i++) { int a; cin >> a; cnt[a]++; if (cnt[a] < 10) cmax[cnt[a]]++; } ...
#include <bits/stdc++.h> using namespace std; list<char> lanc; using It = list<char>::iterator; bool torolni_kell(It mit) { if (*mit == - ) return false; char akt = *mit, el = *prev(mit), kov = *next(mit); return (el != - && el != akt) || (kov != - && kov != akt); } int main() { ios_bas...
#include <bits/stdc++.h> using namespace std; long long ten[20], a, b, l, ans = (long long)1 << 40; long long lp, rp, mp, mt; int ls, rs, ms; int calc(long long x) { int y = 0; for (; x; x /= 10) if (x % 10 == 4 || x % 10 == 7) ++y; return y; } void askl() { lp = a; ls = -1; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { bool f = false; set<int> v1; int n, ans = -1; cin >> n; int a[n]; for (long long i = 0; i < n; i++) {...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int cnt[32][N + 10]; int main() { for (int i = 1; i <= N; i++) { int n = i, t = 0; while (n > 0) { cnt[t][i] = cnt[t][i - 1] + n % 2; t++; n /= 2; } } int t; cin >> t; while (t--) ...
#include <bits/stdc++.h> using namespace std; int n, q; int sz, nxt[(1 << 20)][2], son[(1 << 20)], val[(1 << 20)]; bool vis[(1 << 20)]; void insert(int v, int add) { int x = 0; for (int i = 18; i >= 0; i--) { int c = (v >> i) & 1; if (!nxt[x][c]) nxt[x][c] = sz++; x = nxt[x][c]; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const int MAX = 100005; bool check(int x, int y) { int cnt1[11] = {0}; int cnt2[11] = {0}; while (x > 0) { cnt1[x % 10]++; x /= 10; } while (y > 0) { cnt2[y % 10]++; y /= 10; } for...
#include <bits/stdc++.h> using namespace std; const int N = 3e6 + 7; long long int a[N], b[N], c[N], tree[N], lazy[N], cnt, sum, s2, mx; vector<long long int> v, u; vector<pair<long long int, long long int>> vp; map<long long int, long long int> mp; bool vis[111111]; pair<long long int, long long int> p...
#include <bits/stdc++.h> using namespace std; int n; int A[1000]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; int G = 0, C = 0; for (int i = 0; i < n; i++) { if (A[i] == 0) { G = min(C, G) + 1; C = G; } else if (A[i] == 1) { int temp = G; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> angles(n); for (int i = 0; i < n; i++) { int angle; cin >> angle; angles[i] = angle; } int difference = 360; for (int i = 0; i < n; i++) { int current_angle = angles[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<pair<long long, long long> > v(n); for (long long i = 0; i < n; i++) { cin >> v[i].first ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; int P, n, m, s[maxn]; long long K; struct que { long long x; int prey, y; bool operator<(const que &a) const { return x < a.x; } } q[maxn]; struct Matrix { int a[2][2]; Matrix() { memset(a, 0, sizeof a); } Matri...
#include <bits/stdc++.h> using namespace std; long long n, MOD, f[(long long)4e6 + 5], sum[(long long)4e6 + 5], d[(long long)4e6 + 5]; signed main() { cin >> n >> MOD; long long Sum = 0; for (long long i = 1; i <= n; i++) { if (i == 1) f[1] = 1; else f[i] = (Sum + d[i...
#include <bits/stdc++.h> using ll = long long int; using namespace std; int main() { int n; cin >> n; string s; cin >> s; int cnt = 0; int negative = -1; int ans = 0; for (int i = 0; i < n; ++i) { if (s[i] == ) ) --cnt; else if (s[i] == ( ) ++cnt; ...
#include <bits/stdc++.h> using namespace std; const long long N = 5056, M = 1e9 + 7; long long n, a[N], pr[N], ans[N * 2], h[N * 2]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; pr[0] = 1; for (int i = 1; i <= n - 1; ++i) { cin >> a[i]; pr[i] = a[i] * pr[i - 1] % M...
#include <bits/stdc++.h> using namespace std; int transition; int dp[10][2][1 << 9]; int solve(int idx, int tight, int mask, string &s) { if (idx == s.size()) { return __builtin_popcount(mask) == s.size(); } if (dp[idx][tight][mask] != -1) return dp[idx][tight][mask]; int &ans = dp[idx][ti...
#include <bits/stdc++.h> using namespace std; const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; int gcD(int a, int b) { while (a && b) a > b ? a %= b : b %= a; return a + b; }...
#include <bits/stdc++.h> using namespace std; const int N = 310000; int n, m, cs[N], cd[N], nr, rez[N], aint[4 * N], full[4 * N]; vector<int> v[N]; vector<pair<int, int> > x[N]; bool ver[N]; void df(int nod) { ver[nod] = 1; cs[nod] = ++nr; for (vector<int>::iterator it = v[nod].begin(); it != ...
#include <bits/stdc++.h> using namespace std; long long int func1(long long int i) { return i * (i + 1) * (2 * i + 1) / 6 - (i + i + 2) * i * (i + 1) / 2 + (i + i + 1 + i * i) * i; } long long int func2(long long int i) { return i + i * i - i * (i + 1) / 2; } int main() { long long int inp;...
#include <bits/stdc++.h> using namespace std; double dp[200]; int next1[200]; int cnt(int i, int j) { if ((11 - i) % 2 == 1) { return (10 - i) * 10 + j; } else { return (10 - i) * 10 + (11 - j); } } int main() { for (int i = (1); i < (11); i++) { for (int j = (1); j < (11);...
#include <bits/stdc++.h> using namespace std; int f[1005][1005]; int main() { int k; scanf( %d , &k); int w[39], cnt = 0; while (k) { w[cnt++] = k % 2; k /= 2; } f[1][3] = f[3][1] = 1; int now = 3; for (int i = 1; i < cnt; i++) { f[now][now + 1] = f[now + 1][now] ...
#include <bits/stdc++.h> using namespace std; char string_in_buffer[(int)2e5]; void fast_scan(int &first) { scanf( %d , &first); } void fast_scan(long long &first) { scanf( %lld , &first); } void fast_scan(unsigned long long &first) { scanf( %llu , &first); } void fast_scan(double &first) { scanf( %lf , &fi...
#include <bits/stdc++.h> using namespace std; int heap(int a, int t) { int tmp; if (a > t) swap(a, t); if (t % a == 0) return a; return heap(a, t % a); } int main() { string x, y; cin >> x >> y; bool f = true; for (int i = 0; i < x.size(); i++) { if (x[i] != y[x.size() - 1 ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, q, l; int A[N], sum[N]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , A + i); sum[i] = sum[i - 1] + A[i]; } scanf( %d , &q); while (q--) { scanf( %d , &l); printf(...
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 5; long long a[maxn], ps[maxn], mark[maxn]; set<pair<long long, long long> > st; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n >> k; for (long long i = 1; i <= n; i++) cin >...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200010; char A[MAXN]; char B[MAXN]; int n; void open() { freopen( B.in , r , stdin); freopen( B.out , w , stdout); } void close() { fclose(stdin); fclose(stdout); } void init() { scanf( %s , A + 1); scanf( %s , ...
#include <bits/stdc++.h> using namespace std; struct point { int x, y; int num; int mark; }; point p[100010]; int ans[100010]; point pt; int sum1, sum2; bool cmp(point a, point b) { return (a.x - pt.x) * (b.y - pt.y) - (a.y - pt.y) * (b.x - pt.x) < 0; } bool cmp2(point a, point b) { ...
#include <bits/stdc++.h> using namespace std; int n; vector<vector<pair<int, int>>> g; vector<int> p; vector<bool> was; vector<int> sz; long long res; void calcSz(int v, int par = -1) { sz[v] = 1; for (int i = 0; i < (int)g[v].size(); ++i) { int to = g[v][i].first; if (to != par && !...
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[100]; int res[100]; int main() { int N, W; scanf( %d%d , &N, &W); for (int i = 0; i < N; i++) { scanf( %d , &arr[i].first); arr[i].second = i; } sort(arr, arr + N); for (int i = 0; i < N; i++) { if (W < (a...
#include <bits/stdc++.h> using namespace std; const int INF = 10000000; const int MAX = 150; string s; int found(string aux) { int ans = 0; int cnt = 0; for (int i = 0; i < s.size(); i++) { for (int j = 0, k = i; j < aux.size(); j++, k++) { if (k == s.size()) break; if (aux[j...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> a[1000005]; bool fl1, fl2, fl3, fl4; long long dist(pair<long long, long long> a, pair<long long, long long> b) { return abs(a.first - b.first) + abs(a.second - b.second); } signed main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; int n, m; char arr[1503][1503]; int inix, iniy; bool visit[4503][4504]; int X[] = {0, 0, 1, -1}; int Y[] = {1, -1, 0, 0}; int nn, mm; int colax[4503 * 4503]; int colay[4503 * 4503]; bool dentro(int a, int b) { if (a < 0 || b < 0 || a >= nn || b >= ...
#include <bits/stdc++.h> using namespace std; int main() { int n, w, a[105], cnt1 = 0, cnt = 0, b[105], c[105], e[105], colour[105]; memset(colour, 0, sizeof colour); scanf( %d%d , &n, &w); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); c[i] = a[i]; cnt1 = a[i] / 2; if (a...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; const int MAXINT = 1073741823; int main() { ios::sync_with_stdio(false); cin.tie(0); int t, n, a, b, x; bool win; cin >> t; for (int q = 0; q < t; q++) { cin >> n >> a >> b; win = false; for (int i = 0; i < a; i++) { c...
#include <bits/stdc++.h> using namespace std; const char elem[][4] = { H , He , Li , Be , B , C , N , O , F , Ne , Na , Mg , Al , Si , P , S , Cl , Ar , K , Ca , Sc , Ti , V , Cr , Mn , Fe , Co , Ni , Cu , Zn , Ga , Ge , As , Se , Br , Kr ,...
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; int N; bool vis[MAX]; vector<pair<int, bool> > neigh[MAX]; bool islucky(int a) { while (a > 0) { if (a % 10 != 4 and a % 10 != 7) return false; a /= 10; } return true; } long long p3(long long N) { return (N) *...
#include <bits/stdc++.h> using namespace std; int n, l, r, ql, qr; int w[100010]; int main() { cin >> n >> l >> r >> ql >> qr; for (int i = 1; i <= n; ++i) cin >> w[i]; int f[100010]; f[0] = 0; for (int i = 1; i <= n; ++i) f[i] = f[i - 1] + w[i]; int ans = INT_MAX; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int m, k = 1, i; for (i = 0; i < s.size(); i++) { m = int(s[i]) - 96; if (m == k) k++; else if (m > k) { cout << NO ; return 0; } } cout << YES ; }
#include <bits/stdc++.h> using namespace std; int n, i, j, x, y, a[179000]; int main() { for (cin >> n >> x >> y, i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) { for (j = max(1, i - x); j <= min(n, i + y); j++) if (i != j && a[j] <= a[i]) break; if (j > min(n, i + y)) break...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; double arr[n]; double temp = 0; for (int i = 0; i < n; i++) { cin >> temp; arr[i] = temp; } long long sum = 0; double fractpart, intpart; int arr2[n]; for (int i = 0; i < n; i++) { a...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; string A, B; int a[N], b[N]; int main() { while (cin >> A >> B) { int len1 = A.size(), len2 = B.size(); for (int i = 0; i <= len1 - 1; i++) a[i] = A[i] - 0 ; for (int i = 0; i <= len2 - 1; i++) b[i] = B[i] - 0 ; ...
#include <bits/stdc++.h> using namespace std; ifstream fin( test.in ); struct intr { int l, r, id; }; intr q[200005]; int p, n, qq; long long sol; int a[200005]; long long rez[200005]; int mp[5 * 200005]; bool cmp(intr &q1, intr &q2) { return (q1.r / p < q2.r / p || (q1.r / p == q2.r / p &...
#include <bits/stdc++.h> using namespace std; long long int vis1[1000000]; long long int ara1[100005], ara2[100005]; map<long long int, long long int> vis; map<long long int, long long int> str2; priority_queue<long long int> pq; vector<long long int> vec; int main() { long long int a, b, c = 0, sum...
#include <bits/stdc++.h> using namespace std; long long int const inf = 1e18; long long int const maxn = 2e5 + 5; long long int const mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<long long int> arr(26); for (auto &u : arr) cin >> u; ...
#include <bits/stdc++.h> using namespace std; const long long N = 20; long long n, m, dp[N][1 << N], B, res, cb[1 << N]; bool used[N][1 << N], w[N][N]; long long cbit(long long x) { long long c = 0; while (x) { c += x & 1; x /= 2; } return c; } signed main() { ios_base::syn...
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 100; vector<int> vec[maxn]; int n, m, k; int d[maxn], cnt; bool vis[maxn]; void dfs(int x) { vis[x] = 1; d[++cnt] = x; for (int i = 0; i < vec[x].size(); i++) { if (vis[vec[x][i]]) continue; dfs(vec[x][i]); ...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d; cin >> a >> b >> c >> d; if (abs(c - d) > 1) { cout << -1 ; return 0; } if (max(c, d) > min(a, b)) { cout << -1 ; return 0; } if (a + b <= c + d) { cout << -1 ; return ...
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) #define pre(i,a,b) for(int i=a;i>=b;i--) #define N 505 using namespace std; int f[52][95][905][2],n,mx=450,cc=45; char s[N]; int calc(int x,int cur,int res,int op){ if(x==n+1&&!cur)return 0; if(abs(cur)>cc||abs(res)>mx||x==n+1)return 0...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; long long int dp1[N], dp2[N], Sa[N], Sw[N], dp[20][N], A[N]; int P[20][N], H[N], n, q; vector<pair<int, int> > adj[N]; void preDFS(int v, int p = -1) { if (!~p) P[0][v] = v; for (int i = 1; i < 20; i++) P[i][v] = P[i - 1][P[i - 1]...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 10, mod = 1e9 + 7, inf = 2e9, lg = 22, maskm = (1 << lg) - 1, maxm = (1 << lg) + 7; long long a[maxn], dp[maxm]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; ...
#include <bits/stdc++.h> using namespace std; bool vis[100010]; vector<int> dp[5][100010]; int k, l; int a[6][6]; int dfs(int now) { int i, j, x = 0, sum = 0; for (i = 0; i < now; i++) x = x * 10 + a[now][i]; if (i == l - 1) return dp[1][x].size(); for (i = 0; i < dp[l - now][x].size(); i++)...
#include <bits/stdc++.h> const int maxn = 5e5 + 10; using namespace std; int main() { string s; long long n; cin >> n; while (n--) { cin >> s; int b = 0, e = s.size() - 1; while (b < e && s[b] == s[e]) b++, e--; if (b >= e) cout << s << n ; else { st...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; int f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } x ...