func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int base = 13331; const int MOD = 1e9 + 7; const int MOD1 = 998244353; const int mod = 65536; const long long INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int N = 1e6 + 10, M = 20000010; const int NN = 3e5 + 10; inline long lo...
#include <bits/stdc++.h> using namespace std; int t, sx, sy, ex, ey; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> t >> sx >> sy >> ex >> ey >> s; for (int i = 0; i < t; i++) { if (s[i] == S && sy > ey) { sy--; } else if (s[i] == N && sy < ey...
#include <bits/stdc++.h> using namespace std; ifstream fin( input.txt ); ofstream fout( output.txt ); int gcd(int a, int b) { while (a && b) a > b ? a %= b : b %= a; return a + b; } int val(char c) { if (c >= 0 && c <= 9 ) return (int)c - 0 ; else return (int)c - A + 10; ...
#include <bits/stdc++.h> using namespace std; const int N = 200005, P = 1e9 + 7; int dp[N][3], val[3], n; int add(int a, int b) { return (a += b) >= P ? a - P : a; } int qpow(int a, int b) { int res = 1; while (b) { if (b & 1) res = 1ll * res * a % P; a = 1ll * a * a % P; b >>= 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; int N, A[maxn]; unordered_map<int, int> cnt; unordered_map<int, int> cnt_popped; int main() { bool on[26] = {}; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> N; string S; getline(cin, S)...
#include <bits/stdc++.h> using namespace std; inline long long getnum() { char c = getchar(); long long num, sign = 1; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) sign = -1; for (num = 0; c >= 0 && c <= 9 ;) { c -= 0 ; num = num * 10 + c; c = getchar(); } ...
#include <bits/stdc++.h> int main() { int n, y[27] = {}, i, c = 0; char x[100001]; scanf( %d %s , &n, x); for (i = 0; i < n; i++) if (!y[x[i] - 97]) { y[x[i] - 97]++; c++; } if (n <= 26) printf( %d , n - c); else printf( -1 ); }
#include<bits/stdc++.h> using namespace std; bool possible(int *arr, int n) { int s=0; s = accumulate(arr,arr+n,s); if(s%2) return false; bitset<2000000> b; b[0] = 1; for(int i=0;i<n;i++) b = b|(b<<arr[i]); return b[s/2]; } int main() { int n; cin>>n; int arr[n]...
#include <bits/stdc++.h> using namespace std; string s, v; bool g(char k) { return (k == a || k == e || k == i || k == o || k == u ); } int main() { ios_base::sync_with_stdio(0); cin >> s; long long tek = 0; char t1 = - , t2 = - ; for (long long i = 0; i < s.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; const int M = 100500; vector<int> a, b, diff, c; int cnt[220000]; int cnt1[220000]; int cnt3[220000]; int cntt[220000]; int cntt2[220000]; int cntt3[220000]; int cnt2[220000]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout....
#include <bits/stdc++.h> using namespace std; struct UnionFind { int n; vector<int> p, rank; int findSet(int i) { return (p[i] == i ? i : (p[i] = findSet(p[i]))); } bool isSameSet(int i, int j) { return (findSet(i) == findSet(j)); } void unionSet(int i, int j) { if (!isSameSet(i, j)) { ...
#include <bits/stdc++.h> using namespace std; long long f1[120000], f2[120000], f3[120000], f4[120000], ans; vector<int> E[120000]; int n, a[120000]; void dfs1(int x, int fa) { f1[x] = f2[x] = a[x]; for (int i : E[x]) if (i != fa) { dfs1(i, x); f1[x] = max(f1[i], f1[x]); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int MOD = 1000000007; int N; int a[MAXN]; vector<int> ch[MAXN]; int dp[MAXN][2]; inline int add(int x, int y) { x += y; if (x >= MOD) x -= MOD; return x; } inline int mul(int x, int y) { return (long long)x * y ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int n, m; cin >> n >> m; string a; cin >> a; int arr[n + 5]; set<int> st; int mark[n + 5]; memset(...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; vector<int> v; vector<bool> b; vector<int> u; vector<int> s; vector<int> t(m, 0); for (int i = 0; i < n + m; i++) { l...
#include <bits/stdc++.h> using namespace std; int dcmp(double a, double b) { return ((fabs(a - b) < (1e-9)) ? 0 : (a < b) ? -1 : +1); } double crossP(const complex<double> &v1, const complex<double> &v2) { return (conj(v1) * v2).imag(); } double dotP(const complex<double> &v1, const complex<double> ...
#include <bits/stdc++.h> using namespace std; map<int, int> xMap; map<int, int> yMap; vector<pair<int, int> > row[200005], col[200005]; int x[200005], y[200005], tmr[200005], parent[200005]; int findrep(int u) { if (parent[u] != u) parent[u] = findrep(parent[u]); return parent[u]; } void Union(i...
#include <bits/stdc++.h> using namespace std; int main() { int i, j; int n; cin >> n; long long int a[n + 1]; map<long long, long long> m; for (i = 1; i <= n; i++) { cin >> a[i]; m[a[i]]++; } long long ans = 0; multiset<long long> s; for (auto it = m.begin(); it !...
#include <bits/stdc++.h> #pragma GCC optimization( unroll-loops ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4 ) using namespace std; const int BASE = 1000000; char what[1 << 20]; pair<int, int> nxt[10][1 << 20]; inline long long Calc(long long x) { long long suff = x /...
#include <bits/stdc++.h> using namespace std; const int maxn = 200, mo = 1000000000 + 7; int n, b, k, x, s[10]; long long d[maxn]; struct node { long long s[maxn][maxn]; void init() { memset(s, 0, sizeof(s)); } void give(node zjz) { for (int i = 0; i < x; i++) for (int j = 0; j < x; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, t, z = 0; cin >> n >> t; if (n == 1 && t == 10) cout << -1 << endl; else if (t == 10) { for (int i = 0; i < n - 1; i++) { cout << 1; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 10; const int mod = 1e9 + 7; const int AL = 9; const int N = 5000; const int INF = 1e9; struct Trie { int net[10000][12], fail[10000]; bool end[10000]; int root, L; int newnode() { for (int i = 0; i < AL; ++i) net[L...
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); } inline int qpow(int a, int n) { int ans = 1; while (n) { if (n & 1) ...
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T a) { return a < 0 ? -a : a; } template <typename T> T sqr(T a) { return a * a; } const int INF = (int)1e9; const long double EPS = 1e-9; const long double PI = 3.1415926535897932384626433832795; long double a, b, h...
#include <bits/stdc++.h> using namespace std; unordered_set<string> was; int n, i, j, pos, k = 13, t; string codes[1001]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (; i < n; ++i) cin >> codes[i]; for (i = 0; i < n; ++i) for (j = i + 1; j < n; ++j) { t = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int maxi = -1000000050; int f, t; int loli = -1000000050; for (int i = 0; i < n; i++) { cin >> f >> t; if (t > k) { loli = f - (t - k); } else loli = f; if (loli > maxi...
#include <bits/stdc++.h> using namespace std; int n, q, s, cntlog2[2050] = {0}; int main() { scanf( %d , &q); while (q--) { memset(cntlog2, 0, sizeof(cntlog2)); scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &s); if (s <= 2048) cntlog2[s]++; } for ...
#include <bits/stdc++.h> using namespace std; struct FenwickTree { vector<long long int> bit; int n; FenwickTree(int n) { this->n = n; bit.assign(n, 0); } FenwickTree(vector<long long int> a) : FenwickTree(a.size()) { for (size_t i = 0; i < a.size(); i++) add(i, a[i]); } ...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int n; cin >> n; long long int ar[n + 1]; for (long long int i = 0; i < n; i++) cin >> ar[i]; sort(ar, ar + n, greater<long long int>()); vector<long long int> v, ans; for (long long int i = 0; i < n; i++) { v...
#include <bits/stdc++.h> using namespace std; int n, ans[100], len, a, cur; int main() { cur = 1; cin >> n; for (int i = 0; i < (n); ++i) { cin >> a; if (a == cur) { ans[len++] = 2001 + i; cur++; } } cout << len << endl; for (int i = 0; i < (len); ++i) cou...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } cout << (*max_element(v.begin(), v.end()) ^ v.back()) << endl; return 0; }
#include <bits/stdc++.h> const int mod = 1000000007; const int inf = 1000000009; const long long INF = 1000000000000000009; const long long big = 1000000000000000; const long double eps = 0.000000000000000000001; using namespace std; vector<pair<int, int> > W; int T[200005]; int s, l, last = -1; boo...
#include <bits/stdc++.h> using namespace std; map<pair<string, int>, vector<pair<string, int> > > edg; queue<string> que; map<string, int> num, por; set<string> sett; int main() { int n, i, k, l, r, a, b, j; cin >> n; string s, t, S; for (i = 0; i < n; i++) { cin >> s >> a; if (!...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int q = 1; q <= t; q++) { int n; int k; cin >> n >> k; long long a[n * k + 10]; long long ans = 0; for (int i = 1; i <= n * k; i++) cin >> a[i]; int ind = n * k - n / 2; int c...
#include <bits/stdc++.h> using namespace std; int a[100005], vis[100005], b[100005], h[100005], g[100005]; int main() { int n, m = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == i) { g[a[i]] = ++m; h[m] = i; } } for (int i = 1; i <= n; i+...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long powmod(long long a, long long l, long long md) { long long res = 1; while (l) { if (l & 1) res = res * a % md; l /= 2; a = a * a % md; } return res; } long long binpow(long long a, long long l) {...
#include <bits/stdc++.h> using namespace std; int n, m, ya, yb, a[100003], b[100003], l[100003], dp[2][100003], ans; int main() { cin >> n >> m >> ya >> yb; ans = n; for (int i = 0; i < n; i++) scanf( %d , a + i); for (int i = 1; i <= m; i++) scanf( %d , b + i); b[0] = -998244353; m++; ...
#include <bits/stdc++.h> using namespace std; long long a[100010], b[100010]; int main() { long long n, i, res1 = 0, res2 = 0, l1, l2, r1, r2, turn; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= n; i++) { cin >> b[i]; } sort(a + 1, a + n + 1); sor...
#include <bits/stdc++.h> using namespace std; int n, m; int main() { scanf( %d%d , &n, &m); if (n > m) swap(n, m); if (n == 1) printf( %d n , m / 6 * 6 + 2 * max(m % 6 - 3, 0)); else if (n == 2) { if (m == 2) printf( 0 n ); else if (m == 3) printf( 4 n ); el...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; long long sumb, sumc; int n, a[N], b[N], c[N], cnt[30]; bool check() { for (int i = 0; i < n; i++) { for (int j = 0; j < 30; j++) { if (a[i] & 1 << j) cnt[j]++; } } for (int i = 0; i < n; i++) { long lon...
#include <bits/stdc++.h> using namespace std; int fx[] = {1, -1, 0, 0}; int fy[] = {0, 0, 1, -1}; const unsigned long long hs = 3797; unsigned long long F[100005], H[100005], H2[15]; int H2_size[15]; unsigned long long seg(int x, int y) { return H[y] - F[y - x + 1] * H[x - 1]; } int main() { F[0] = ...
#include <bits/stdc++.h> const int MAXN = 200 + 5; char str[MAXN][MAXN]; int n, m; namespace Flow { const int MAXM = 2e5 + 5; struct Edge { int to, w, nxt; } e[MAXM << 3]; int head[MAXM], cur[MAXM], cnt = 1; int dep[MAXM]; int S, T, N; inline void add(int u, int v, int w) { e[++cnt] = (Edg...
#include <bits/stdc++.h> namespace io { template <typename T> inline void read(T& a) { int c = getchar(), sign = 0; a = 0; while (c < 0 || c > 9 ) sign += (c == - ), c = getchar(); while (c >= 0 && c <= 9 ) a = (a << 1) + (a << 3) + c - 48, c = getchar(); if (sign & 1) a = -a; } tem...
#include <bits/stdc++.h> using namespace std; int main() { long long i = 1, n; string s[] = { Sheldon , Leonard , Penny , Rajesh , Howard }; cin >> n; if (n <= 5) { cout << s[n - 1]; return 0; } while (((1 << i) - 1) * 5 <= n) i++; i--; i = (1 << i); n -= (i - 1) ...
#include <bits/stdc++.h> using namespace std; long long n, k; struct ff { int value, order; } a[100010]; bool cmp(ff a, ff b) { return a.value < b.value; } long long sum1[100010], sum2[100010]; void add(long long s[], int i, int x) { while (i <= n) { s[i] += x; i += i & -i; } } ...
#include<bits/stdc++.h> using namespace std; #define ll long long int #define v vector<ll> #define pb push_back #define fr(i,a,n) for(ll i=a;i<n;i++) #define Fast ios::sync_with_stdio(false);cin.tie(NULL); #define in(a) ll a;cin>>a #define ip(a) string a;cin>>a #define R(a,n) for(int i=0;i<n;i++)cin>>...
#include <bits/stdc++.h> using namespace std; int a[8]; int main() { int n, m; cin >> n >> m; int xx = n; int kk = m; int ans = 0; int len1 = 1, len2 = 1; for (int b = 7; b < n; b *= 7) len1++; for (int b = 7; b < m; b *= 7) len2++; if (len2 + len1 > 7) { cout << 0; ...
#include <bits/stdc++.h> using namespace std; struct node { int x, y, time; }; char str[120][120]; int vis[102][102][102], n, m, ck = 0; void train(int p, int q, int cnt) { int time = 0, d = 0; for (int j = q; (j + cnt - 1) >= 0; j -= 2) { d = 0; int lim = cnt; if (j < 0) lim =...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, n, tx, ty, m; scanf( %d %d , &n, &m); double res = 0; for (int i = 0; i < n; i++) { scanf( %d %d , &x, &y); if (i == 0) { tx = x, ty = y; continue; } res = res + sqrt(((x - tx) * (x - tx)) + ...
#include <bits/stdc++.h> using namespace std; int a[100][100]; int main() { string x; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> x; for (int j = 0; j < n; j++) { if (x[j] == E ) a[i][j] = 1; } } int k = 0; int s; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; long long int cons; long long int check(long long int a) { if (a >= cons) a %= cons; return a; } long long int check2(long long int a) { a %= cons; if (a < 0) a += cons; return a; } long long int GCD(long long int a, long long int b) { ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, a[N], place[N], BIT[N]; long long inverse, res[N]; set<int> firstHalf, secondHalf; long long sumFirst = 0, sumSecond = 0; long long fenwickGet(int x) { long long res = 0; for (; x <= n; x += x & -x) res += BIT[x]; retur...
#include <bits/stdc++.h> using namespace std; string to_string(bool b) { return (b ? true : false ); } template <size_t N> string to_string(bitset<N> v) { string res = ; for (size_t i = 0; i < N; i++) { res += static_cast<char>( 0 + v[i]); } return res; } template <typename A> ...
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int r = 1; x = x % p; while (y) { if (y & 1) r = r * x % p; y = y >> 1; x = x * x % p; } return r; } const long long int N = 5005; long long in...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, p; string s, x, y; cin >> n; cin.ignore(); while (n--) { getline(cin, s); a = 0; b = 0; p = s.length(); if (s[0] == m && s[1] == i && s[2] == a && s[3] == o && s[4] == . ) { ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, ok = 1, i = 0, cnt; cin >> n; cnt = n; vector<int> v(n), ans(n, -1), temp; vector<pair<in...
#include <bits/stdc++.h> using namespace std; const int INIT_SIZE_MAX = (1 << 29) + 10; const int INIT_SIZE_MIN = -(1 << 29) - 10; const int INIT_SIZE = 0; const int MAX = 8; const int DIR_SIZE = 12; const double PI = 3.1415926535897932384; template <class T, class U> void convert(T &t, U &u) { st...
#include <bits/stdc++.h> using namespace std; const int iinf = 1 << 29; const long long inf = 1ll << 60; const long long mod = 1e9 + 7; void GG() { cout << -1 n ; exit(0); } long long mpow(long long a, long long n, long long mo = mod) { long long re = 1; while (n > 0) { if (n & 1) r...
#include <bits/stdc++.h> using namespace std; int main() { bool check = 1; vector<pair<int, int>> v; int a, b, c; cin >> a; for (int i = 0; i < a; i++) { cin >> b >> c; v.push_back({b, c}); } for (int i = 0; i < a; i++) { if (v[i].second != v[i].first) { cout <<...
#include <bits/stdc++.h> using namespace std; const int N = 110; int a[N], c[N][N]; int main() { int n, k; scanf( %d %d , &n, &k); for (int i = 0; i < n; ++i) { scanf( %d , a + i); } int mn = a[0], mx = a[0]; for (int i = 0; i < n; ++i) { if (a[i] < mn) mn = a[i]; if (a...
#include <bits/stdc++.h> using namespace std; char board[500][500]; int n, m, k; int w = 0, e = 0; int t; bool used[500][500]; bool inBound(int a, int b) { return (a >= 0 && a < n && b >= 0 && b < m); } bool dfs(int a, int b) { if (t == 0) return false; bool check = true; used[a][b] = true; ...
#include <bits/stdc++.h> using namespace std; long long sum[100010 << 2], tag[100010 << 2]; int num[100010 << 2], n, m; bool is[100010 << 2], Tag[100010 << 2]; void build(int p, int l, int r) { if (l == r) { is[p] = true, num[p] = l; return; } build(p << 1, l, (l + r) >> 1), build(p <<...
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; int n, f[405][405]; int main() { scanf( %d , &n); f[1][0] = f[1][1] = 1; for (int i = 2; i <= n; i++) { for (int j = 0; j <= n; j++) for (int k = 0; k <= n; k++) { int t = 1ll * f[i - 1][j] * f[i - 1][k] ...
#include <bits/stdc++.h> using namespace std; constexpr int MAXN = 1 << 30; struct tournament { struct Node { Node* parent; set<int, greater<int>> blocked; Node* left = nullptr; Node* right = nullptr; Node(Node* parent) : parent(parent) {} }* root = new Node(nullptr); set...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; int a, b, p, pos; int i, cost, j, k, l; string s; while (t--) { cin >> a >> b >> p; cost = 0; cin >> s; pos = s.length() - 2; i =...
#include <bits/stdc++.h> using namespace std; int const MOD = 1e9 + 7; double const PI = acos(-1); long long const oo = 8e18; int const N = 3e5 + 100; int const M = 1e6 + 100; int n; pair<int, int> a[N], p1[N], p2[N]; pair<int, int> intersection(pair<int, int> x, pair<int, int> y) { if (x.second <...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x; cin >> n >> x; int ar[n], i, cnt = 0; for (i = 0; i < n; i++) { cin >> ar[i]; cnt += ar[i]; } cnt += n - 1; if (cnt == x) cout << YES ; else cout << NO ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, s1, s2; cin >> a1 >> a2 >> s1 >> s2; if (a1 <= a2) cout << Second ; else cout << First ; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; bool isprime[32000]; vector<int> prime; int a[maxn + 50], num[maxn + 50], factor[maxn + 50], now[maxn + 50]; int k, n, len = 0; long long ans = 0; bool check() { for (int i = 1; i <= len; ++i) if (now[i] < num[i]) return false...
#include <bits/stdc++.h> using namespace std; const int N = 1000500; const int INF = 1000000000, mod = 1000000007; const long long LLINF = 1000000000000000000ll; char s[N]; int z[N]; int cnt[N]; int n; void calcZ() { int l = 0, r = 0; for (int i = 1; i < n; ++i) { if (i <= r) { z...
#include <bits/stdc++.h> using namespace std; bool vis[10010][51]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int m, n; cin >> m >> n; for (int i = 0; i < m; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int temp; cin >> temp; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int dp[4][N]; string str2[N], str3[N]; set<string> ans; int n; int cal(int len, int idx) { if (dp[len][idx] != -1) return dp[len][idx]; if (idx == n - 1) return dp[len][idx] = 1; ; int x = 0; if (idx + 2 < n) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const long long INF = 4e18 + 42; long long l[N]; char type[N]; void get_stam(long long need, long long &stam, long long &have, long long &ans, long long cost); int main() { ios_base::sync_with_stdio(false); cin.t...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; int a[1005][1005]; int main() { int N, K, D, i, j; loop: while (~scanf( %d%d%d , &N, &K, &D)) { memset(a, 0, sizeof(a)); for (j = 0; j < N; ++j) { a[D - 1][j] = j; } for ...
#include <bits/stdc++.h> using namespace std; void setIO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const long double PI = 4 * atan((long double)1); const int INF = 1e9 + 7; const long long _INF = 1e18; int main() { setIO(); int t; cin >> t; while (t--) { int...
#include <bits/stdc++.h> using namespace std; using dd = long double; struct Tree { struct Node { dd mul; dd add; dd sum; Node() : mul(1), add(0), sum(0) {} }; int S; vector<Node> drz; void update(int v) { drz[v].sum = drz[2 * v].sum + drz[2 * v + 1].sum; } Tree(con...
#include <bits/stdc++.h> using namespace std; int day[100005]; int cnt[100005]; int vis[100005]; int n, m; int jud(int x) { memset(vis, 0, sizeof(vis)); int i, j; int sum = 0, cntt = 0; ; for (i = x; i >= 1; i--) { if (day[i] && vis[day[i]] == 0) { cntt++; vis[day[i...
#include <bits/stdc++.h> using namespace std; int main() { int n, j, t, k, x, y; scanf( %d , &t); int a[10] = {0}, b[10] = {0}; for (j = 0; j < t; j++) { scanf( %d%d%d , &k, &x, &y); if (k == 1) { a[0] = a[0] + x; a[1] = a[1] + y; } else { b[0] = b[0] + x; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; vector<string> a; vector<string> ra; cin >> n >> m; for (int i = 0; i < n; ++i) { string s; cin >> s; a.push_back(s); reverse(s.begin(), s.end()); ra.push_back(s); } vector<int> selected; ...
#include <bits/stdc++.h> using namespace std; struct comp { bool operator()(long long int a, long long int b) { return a > b; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k; cin >> n >> k; vector<pair<long long int, long long int> > po...
#include <bits/stdc++.h> using namespace std; long long n; char str[1000010]; long long cntu[1000010]; long long cntd[1000010]; long long sumu[1000010]; long long sumd[1000010]; long long CNTU; long long CNTD; int main() { scanf( %I64d%s , &n, str + 1); for (long long i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int M = 7002; const int N = 100010; int n, q; bitset<M> num[M]; bitset<M> sq[M]; bitset<M> a[N]; vector<int> squareFree; int main() { cin >> n >> q; for (int i = 1; i < M; ++i) { int good = 1; for (int j = 2; j * j <= i; ++j) { ...
#include <bits/stdc++.h> using namespace std; long double EPS = 1e-9; long long cel(long long a, long long b) { return ((a - 1) / b + 1); } long long gcd(long long a, long long b) { if (a < b) swap(a, b); return (b == 0) ? a : gcd(b, a % b); } long long MIN(long long a, int b) { long long ans; ...
#include <bits/stdc++.h> using namespace std; int count_on(int mask) { int ans = 0; while (mask) { if (mask & 1) { ans++; } mask >>= 1; } return ans; } int dp[1 << 20]; string bin(int mask) { string str = ; while (mask) { if (mask & 1) { str +=...
#include <bits/stdc++.h> using namespace std; int M; int next_losing_index(int A, int losing_index) { return A == 0 || losing_index < M ? min(losing_index + 1, M) : 0; } struct segment_change { bool flip; segment_change(bool _flip = false) : flip(_flip) {} void reset() { flip = false; } se...
#include <bits/stdc++.h> using namespace std; vector<int> tree[100005]; int cat[100005]; bool vis[100005]; int n, m, ans = 0; void dfs(int root, int num) { vis[root] = true; if (cat[root]) num++; else num = 0; if (num > m) return; if (tree[root].size() == 1 && vis[tree[root][...
#include <bits/stdc++.h> using namespace std; int main() { string s; string t; cin >> s >> t; long j = 0; long ans = 0; for (long i = 0; i < t.size(); i++) { if (t[i] == s[j]) ++j; if (j == s.size()) { long rj = s.size() - 1; for (long k = t.size() - 1; k >= 0; k-...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char ch[n]; ch[n] = 0 ; int a[n][2]; for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } int suma = 0; int sumg = 0; for (int i = 0; i < n; i++) { if (((a[i][0] + suma) - sumg) <=...
#include <bits/stdc++.h> using namespace std; template <class T> inline void rread(T& num) { num = 0; T f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) num = num * 10 + ch - 0 , ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; map<int, int> mx, my; vector<int> v; long long cal() { long long ans = 0; int sz = v.size(); sort(v.begin(), v.end()); int l = 0, r; while (l < sz) { r = l; while (r < sz - 1 && v[r + 1] == v[l]) r++; a...
#include <bits/stdc++.h> using namespace std; int n, excluidos = 0; vector<priority_queue<int, vector<int>, greater<int>>> Vpq; bool umVazio() { for (auto u : Vpq) { if (u.size() == 0) return true; } return false; } int procura(int indAnterior, int i) { int num = -1; while (Vpq[i]....
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } const double eps = 1e-10; int n; int m; double ax, ay, az, vx, vy, vz, R, r, ox, oy, oz, px, py, pz; double scal(double x1, double y8687969, double z1, double x2, double y2, double ...
#include <bits/stdc++.h> using namespace std; class trio { public: long long first, second, third; }; class quad { public: long long first, second, third, fourth; }; class DSU { public: long long *par, *size; DSU(long long n) { par = new long long[n + 1]; size = new long...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { x = 0; char c; int sign = 1; do { c = getchar(); if (c == - ) sign = -1; } while (c < 0 || c > 9 ); do { x = x * 10 + c - 0 ; c = getchar(); } while (c <= 9 && c >= 0 )...
#include <bits/stdc++.h> using namespace std; long long binPow(long long a, long long b) { a = a % 1000000007; if (a == 0) return 0; long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return res; } int main()...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n], brr[n]; for (int i = 0; i < n; ++i) { cin >> arr[i] >> brr[i]; } for (int i = 0; i < n; ++i) { if (arr[i] != brr[i]) { cout << rated ; return 0; } } for (int 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, x, mx, mn, f, j, s, r, y, c, m, k, c1; cin >> t; while (t--) { cin >> n; vector<long long int> v; f = 0; for (i = 0; i < n; i++) { cin >> x;...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T0> void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } bool isPo...
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; std::vector<int> data(n); for (int i = 0; i < n; i++) { std::cin >> data[i]; } int s; int t; std::cin >> s; std::cin >> t; --s; --t; if (s > t) { std::swap(s, t...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int f[N], ff[N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; f[x]++; } multiset<int> ms; for (int i = 1; i < N; i+...