func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int MAXN = 1000000005; long long meta; bool ok = 0; map<long long, long long> visite; void bfs(long long padre) { queue<long long> cola; cola.push(padre); while (!cola.empty()) { long long hijo = cola.front(); cola.pop(); long long ...
#include <bits/stdc++.h> int CH, NEG; template <typename TP> inline void read(TP& ret) { ret = NEG = 0; while (CH = getchar(), CH < ! ) ; if (CH == - ) NEG = true, CH = getchar(); while (ret = ret * 10 + CH - 0 , CH = getchar(), CH > ! ) ; if (NEG) ret = -ret; } using names...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; const int N = 5e5 + 10; const int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7, G = 3; const int base = 30000; int t; int n, m, k; int dp[35][35][55]; int dfs(int n, int m, int k) { if (k == 0 || n * m == k) return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { map<char, int> mapdown, mapup, mapleft, mapright; char keys[10] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 }; int n, count1 = 0, count2 = 0, count3 = 0, count4 = 0; char str[15]; mapdown.clear(); mapup.clear(); mapleft.cl...
#include <bits/stdc++.h> using namespace std; bool isSolveabe(int *a, int n, int m) { int i = m; int j = n - 1; int min = INT_MIN; while (i < j) { if (a[i] < a[j]) { if (a[i] < min) { return false; } min = a[i]; ++i; } else { if (a[j] < m...
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; } const long long N = 2e5 + 7; const long long inf = 1e6 + 1; const long long mod = 998244353; int t, n, m, a[N]; struct node { int def, s; bool operator<(const node& a) const { re...
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> ...
#include <bits/stdc++.h> using namespace std; template <typename Elem> int quick_power(int a, Elem b, int Mod) { int ans = 1; while (b) { if (b & 1) { ans = 1ll * ans * a % Mod; } b >>= 1; a = 1ll * a * a % Mod; } return ans; } const int Maxn = 100000; const i...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); bool p1 = (n >= 5); bool p2 = 0, p3 = 0, p4 = 0; for (int i = 0; i < n; i++) { p2 |= (s[i] >= a && s[i] <= z ); p3 |= (s[i] >= A && s[i] <= Z ); p4 |= (s[i] >= 0 && s[i]...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n; map<string, int> was; void read() { cin >> n; while (n--) { int c; string s; cin >> c >> s; sort(s.begin(), s.end()); if (was.count(s) == 0) { was[s] = c; } else { was[s] = min...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--){ string s; cin >> s; stack<char> a, b; int ans = 0; for (auto c: s){ if (c == ( || c == ) )...
#include <bits/stdc++.h> using namespace std; int q[123456]; vector<int> sq; int main() { int n, k; int a, b; scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) { scanf( %d%d , &a, &b); sq.push_back(min(2 * a, b) - min(a, b)); q[i] = min(a, b); 1; } sort(sq.begin...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s[n]; int a[n]; for (int x = 0; x < n; x++) { cin >> s[x]; a[x] = s[x].length(); } for (int x = 0; x < n; x++) { for (int y = 0; y < n - 1; y++) { if (a[y] > a[y + 1]) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, k, m, c1 = 0, count2 = 0, m3 = 0; cin >> n; long long int a[n]; map<long long int, long long int> m1; for (i = 0; i < n; i++) { cin >> a[i]; m1[i] = -1; } cin >> m; vector<long long int> v; ...
#include <bits/stdc++.h> using namespace std; double PI = 3.14159265358979323846; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long get(long long x, long long n) { long long l, r; if (x > n) return 0; long long acc = 0; if (x % 2 == 0) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1005; template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + c - 0 ; x *= f; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); int n, m; cin >> n >> m; if (n == m) { cout << n << endl; return 0; } cout << 2 << endl; }
#include<bits/stdc++.h> using namespace std; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen( input1.txt , r , stdin); freopen( error1.txt , w , stderr); freopen( output1.txt , w , stdout); #endif int t ; cin >> t; while (t-...
#include <bits/stdc++.h> using namespace std; char s[2005]; int n, c[2005][2005], ans = 0x3f3f3f3f, was, ot[2005]; bool chk() { static int ar[2005]; int sum = 0; for (int i = (1), LIM = (n); i <= LIM; i++) ar[i] = ot[i], sum += ot[i]; sort(ar + 1, ar + 1 + n); int sm = 0; for (int i = (1...
#include <bits/stdc++.h> using namespace std; int ans, a, b, c; int main() { cin >> a >> b >> c; ans = a; while (!(b >= ans + 1 && c >= ans + 2)) ans--; cout << 3 * ans + 3; return 0; }
#include <bits/stdc++.h> using namespace std; long long inv[500005]; void getinv() { inv[0] = inv[1] = 1; for (int i = 2; i < 500005; i++) inv[i] = ((-1000000007 / i * inv[1000000007 % i]) % 1000000007 + 1000000007) % 1000000007; } long long slove(int n, int m) { long lon...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 10, M = 20, mo = 1e9 + 7; vector<vector<long long> > f, sum; vector<long long> g; long long a[maxn], c[maxn]; long long n, l, k, K, B, ans, i, j, z, x, y, N, r; int main() { scanf( %lld%lld%lld , &n, &l, &k); g.push_back(0)...
#include <bits/stdc++.h> using namespace std; long long i, j, flag, c, k, x, z, n, m, a[300007]; int main() { cin >> n; long long lst0 = 0, lst1 = 1; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0) lst0 = i + 1; else lst1 = i + 1; } cout << min(lst0, lst...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; r...
#include <bits/stdc++.h> using namespace std; const int maxn = 400000 + 5; vector<int> G[maxn]; int n; int down[maxn], up[maxn], sz[maxn], par[maxn]; void dfs(int u, int fa) { int len = G[u].size(); par[u] = fa; sz[u] = 1; for (int i = 0; i < len; i++) { int v = G[u][i]; if (v ==...
#include <bits/stdc++.h> using namespace std; int main() { long long int mod, h1, a1, x1, y1, h2, a2, x2, y2, c1, c2, i, ans = 0, temp, j, m1, m2, h11, h12; cin >> mod; cin >> h1 >> a1; cin >> x1 >> y1; cin >> h2 >> a2; cin >> x2 >> y2; temp = h2; ans = 0; h11 = h1; h...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10, C = 30; int nex[N][C], p, n, par[N], dfa[N][C]; string s, t; vector<pair<int, char> > adj_matrix[N]; long long ans; void dfs(int v, int p, int state) { if (state == (int)t.size()) ans++; for (auto pa : adj_matrix[v]) { int...
#include <bits/stdc++.h> using namespace std; int bef[100050]; int main() { string s, s1; cin >> s; int len = s.size(); int last_a = -1; int now = 0; for (int i = 0; i < len; i++) { if (s[i] != a ) { s1 += s[i]; bef[now] = i; now++; } else { las...
#include <bits/stdc++.h> using namespace std; int const N = 3e5 + 10, oo = 1e9, M = 64; long long const OO = 1e18; int mod = oo + 7; double const eps = 1e-4, PI = acos(-1); int n, k, in[N]; int cc = 0, m = 0, cnt = 0; vector<int> dv[N]; bool brute(int i, int h) { if (h > k) return 0; if (i == ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; long long a[20][10][10], b[20][10][10], c[20]; int read_int() { int a = 0; int b = 1, c = getchar(); if (c == - ) b = -1; else a = c - 48; while ((c = getchar()) != && c != n ) a = a * 10 + c - 48; ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, ar[10]; cin >> a >> b >> c; ar[0] = a + b + c; ar[1] = a * b * c; ar[2] = a + b * c; ar[3] = a * b + c; ar[4] = (a + b) * c; ar[5] = a * (b + c); sort(ar, ar + 6); cout << ar[6 - 1]; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n; int a[maxn]; int nivel[maxn], in[maxn], out[maxn], tt; vector<int> grafo[maxn]; struct BinaryLifting { int tab[maxn][20]; void dfs(int u, int p) { in[u] = ++tt; for (auto v : grafo[u]) { if (v == p)...
#include <bits/stdc++.h> using namespace std; #define ll long long #define deb(x) cout << #x << = << x << endl #define deb2(x, y) cout << #x << = << x << , << #y << = << y << endl #define nl n void solve() { int n; cin >> n; int arr[n][n]; int x = 1; for(int i=0;i<...
#include <bits/stdc++.h> const int MOD = 1e9 + 7; int primes[100000]; using namespace std; bool cmp(const pair<int, int>& a, const pair<int, int>& b) { return a.first > b.first; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; int a[n]; f...
#include <bits/stdc++.h> using namespace std; bool isPrime(int num) { for (int i = 2; i <= sqrt(num) + 1; ++i) { if (num % i == 0) return false; } return true; } int main() { int n; cin >> n; if (n < 9) { cout << 1 << endl; cout << n << endl; } else if (n == 9) { ...
#include <bits/stdc++.h> using namespace std; bool yes(int x1, int x2, int x3, int x4) { int num1 = (x1 + x2 + x3 + x4) / 4, num2 = (x2 + x3) / 2, num3 = x4 - x1; if (((x1 + x2 + x3 + x4) % 4 != 0) || ((x2 + x3) % 2 != 0) || num1 != num2 || num1 != num3 || x1 == -1 || x2 == -1 || x3 == -1 || x4 == -...
#include <bits/stdc++.h> using namespace std; int n, k; int a[120000]; int main() { cin >> n >> k; for (int i = 0; i < n * 2; i++) a[i] = i; for (int i = 0; i < k; i++) { int now = i * 2; swap(a[now], a[now + 1]); } k = n - k; for (int i = 0; i < n * 2; i++) { printf( %...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; if (n % 2 == 0) { n = n / 2; if (n % 2 == 0) cout << 0; else cout << 1; } else { n = (n + 1) / 2; if (n % 2 == 0) cout << 0; else cout << 1; }...
#include <bits/stdc++.h> using namespace std; template <typename T> void _dbg(const char* _s, T _h) { cerr << _s << = << _h << n ; } template <typename T, typename... Ts> void _dbg(const char* _s, T _h, Ts... _t) { int _b = 0; while (((_b += *_s == ( ) -= *_s == ) ) != 0 || *_s != , ) c...
#include <bits/stdc++.h> using namespace std; int n, a[100005], top, s[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; top = -1; for (int i = n - 1; i >= 0; --i) { s[++top] = a[i]; while (top > 0 ...
#include <bits/stdc++.h> const int MaxN = 100111; const int mod = 1000000009; int f[MaxN]; int getFather(int x) { if (f[x] == x) return f[x]; return f[x] = getFather(f[x]); } int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) f[i] = i; int ans = 0; for (in...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-12; const int INF = (1 << 31) - 1; const long long LLINF = ((long long)1 << 62) - 1; const int maxn = 1000 * 100 + 10; int a[maxn], sum[maxn], sum2[maxn]; int main() { int n; scanf( %d , &n); fo...
#include <bits/stdc++.h> using namespace std; template <typename... T> inline void inp(T &...args) { ((cin >> args), ...); } template <typename T> inline istream &operator>>(istream &in, vector<T> &a) { for (auto &x : a) in >> x; return in; } template <typename T, typename U> inline istrea...
#include <bits/stdc++.h> using namespace std; bool debug = false; int n, m, k; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; long long ln, lk, lm; int a[10]; bool v[9], vv[9]; bool walk(int x) { v[x] = 1; if (a[x] == 1 || vv[a[x]]) return vv[x] = 1; if (v[a[x]]) return 0; return vv[x...
#include <bits/stdc++.h> const int MAXN = 1e5 + 5; long long ans[MAXN], b[MAXN]; int n, first[65], cnt_ans; bool selected[MAXN]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %lld , &b[i]); std::sort(b, b + n); memset(first, 0xff, sizeof(first)); for (int i = 0; i < n; i...
#include <bits/stdc++.h> using namespace std; int N, K; char c[10]; int vl(int x, int y) { printf( 1 %d %d n , x, y), fflush(stdout); return scanf( %s , c), c[0] == T ; } int ef(int L, int R) { for (; L < R;) vl((L + R >> 1), (L + R >> 1) + 1) ? R = (L + R >> 1) ...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int b, f, p, h, c, money = 0; scanf( %d %d %d %d %d , &b, &p, &f, &h, &c); b /= 2; if (h > c) { money = min(b, p) * h; b -= min(b, p); money += min(b, f) * c; ...
#include <bits/stdc++.h> using namespace std; int main() { { int n, m; cin >> n >> m; vector<int> a(n + 2); for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = 0, a[n + 1] = m; vector<int> light(n + 2, 0), dark(n + 2, 0); for (int i = 1; i <= n + 1; i++) { light[i]...
#include <bits/stdc++.h> using namespace std; const int maxn = 1 << 23; bool a[maxn]; bool vis[maxn]; int n, m, x; void dfs(int x) { if (vis[x]) return; vis[x] = true; for (int i = 0; i <= n; i++) if (x & (1 << i)) dfs(x ^ (1 << i)); if (a[x]) dfs((1 << n) - 1 - x); } int main() { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, pos, lpos; int q; cin >> n >> q; for (int i = 0; i < q; i++) { cin >> pos; while (pos % 2 == 0) { lpos = pos / 2 + 1; pos += n - lpos + 1; } ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9; const long long N = 1e5 + 10; const long long bits = 30; const long long mod = 1e9 + 7; const long double pi = 3.14159265358979323846; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; ...
#include <bits/stdc++.h> using namespace std; int nx[10000][26], al[26], l1, l2; string s1, s2; int main() { cin >> s1 >> s2; l1 = s1.size(); l2 = s2.size(); for (int i = 0; i < l1; i++) fill(nx[i], nx[i] + 26, -1); fill(al, al + 26, -1); for (int i = l1 - 1; i >= 0; i--) al[s1[i] - a ]...
#include <bits/stdc++.h> using namespace std; inline long long Getint() { char ch = getchar(); long long x = 0, fh = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) fh = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { (x *= 10) += ch ^ 48; ch = getchar(); } ...
#include <bits/stdc++.h> using namespace std; const int G = 2520; const int B = 41; const int MAXN = B * G; unsigned char S[G][B], ps[B + 1][G][4], mp[256]; string e; void Pre() { mp[ A ] = 0; mp[ G ] = 1; mp[ T ] = 2; mp[ C ] = 3; } void build(int g) { for (int i = 0; i < 4; i++) ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 9e4; const int INF = 1 << 30; const long long mod = 1e9 + 7; const double eps = 1e-8; int main() { long long a[100] = {0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292, 341, 390, 439}; long long n; wh...
#include <bits/stdc++.h> int main() { int tab[2000], i, max = 0, posmax = 0, index = -1, n; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &tab[i]); if (tab[i] > max) { max = tab[i]; posmax = i + 1; } } while (max-- && index == -1) for (i = 0; i < n;...
#include <bits/stdc++.h> char bar[1000002]; int main() { scanf( %s , bar); int n = strlen(bar); long long int left = 0, mid = 0, right = 0; for (int i = 0; bar[i] != ^ ; i++) mid = i + 1; for (int i = 0; bar[i] != ^ ; i++) if (bar[i] != = ) left += (mid - i) * (bar[i] - 0 ); for (i...
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int, char> > > adj(201); int dp[101][101][26][2]; bool solve(int i, int j, char round, bool turn) { if (dp[i][j][(int)(round - a )][turn] != -1) return dp[i][j][(int)(round - a )][turn]; int ret = 0; if (!turn) { for (int...
#include <bits/stdc++.h> using namespace std; int a[100001], b[100001], part1[100001], part2[100001]; int main() { int n, m, c; cin >> n >> m >> c; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i], part1[i] = part1[i - 1] + b[i]; for (int i = 1; i <= m; i++) p...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; unsigned long long dp[1000000]; unsigned long long ans = 0; for (long long i = 1; i <= 500000; i += 2) { long long val = (i * i - (i - 2) * (i - 2)) * (i / 2...
#include <bits/stdc++.h> using namespace std; pair<int, int> w[200000 + 20]; int a[200000 + 20][3]; vector<pair<int, pair<int, int> > > to_compress; int n; void maximize(int &a, int b) { if (a < b) a = b; } struct Fenwick_tree { int bit[1000000 + 50]; void update(int x, int v) { for (;...
#include <bits/stdc++.h> using namespace std; int n, k, a, b, q, d, ai, p, t, zb[200001], suma[800005], sumb[800005], za[200001], res; void build1(int a[], int v, int tl, int tr) { if (tl == tr) suma[v] = a[tl]; else { int tm = (tl + tr) / 2; build1(a, v * 2, tl, tm); build1(...
#include <bits/stdc++.h> using namespace std; long long t; long long n; int x; int main() { ios::sync_with_stdio(0); cin.tie(), cout.tie(); cin >> t; while (t--) { cin >> n; set<int> s; int count = 0; for (int i = 0; i < n; i++) { cin >> x; if (s.find(x)...
#include <bits/stdc++.h> using namespace std; const long long N = 100005; long long n, k, fd, gcd, sum = 0; int main() { cin >> n >> k; if (k > sqrt(2 * n)) { cout << -1 n ; } else { if ((k * (k + 1)) / 2 > n) { cout << -1; } else { fd = -1; for (long long ...
#include <bits/stdc++.h> using namespace std; string rotate(string s) { for (int i = 1; i <= 3; i++) { swap(s[i - 1], s[i]); } return s; } string rotate2(string s) { swap(s[0], s[4]); swap(s[2], s[4]); swap(s[2], s[5]); return s; } string solve(string s) { string ans = ...
#include <bits/stdc++.h> using namespace std; long long n, k; void In() { cin >> n >> k; } void Solve() { k--; while (k--) { int largest = INT_MIN, smallest = INT_MAX; for (long long copy = n; copy; copy /= 10) { int r = copy % 10; largest = max(r, largest); smallest ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m1 = 0, m2 = 0, mn1 = INT_MAX, mn2 = INT_MAX, s1 = 0, s2 = 0; cin >> n; vector<pair<int, int> > vt; long long tmp1, tmp2; for (int i = 0; i < n; i++) { cin >> tmp1 >> ...
#include <bits/stdc++.h> using namespace std; long long func(long long x, long long y, long long z) { return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x); } void solve() { long long na, nb, nc; cin >> na >> nb >> nc; vector<long long> a(na), b(nb), c(nc); long long i, j, k; ...
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void...
#include <bits/stdc++.h> using namespace std; long long int const mod = 1e9 + 7; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return re...
#include <bits/stdc++.h> int check_matrix(int** arr, int n, int m) { int itN = 0, itJ = n - 1; if (n % 2) return n; while (itN < itJ) { for (int i = 0; i < m; ++i) if (arr[itN][i] != arr[itJ][i]) return n; itN++; itJ--; } return check_matrix(arr, n / 2, m); } int main...
#include <bits/stdc++.h> using namespace std; const int N = 201000; struct str { long long nr; char c; }; int n, m; str a[2 * N], b[N], l[N]; vector<int> poz; bool cmp(str a, str b) { return (a.nr == b.nr && a.c == b.c); } int z[2 * N]; void calcpot() { int i, j; for (i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; vector<int> v; void dfs(int depth, bool state) { if (depth == 0) return; dfs(depth - 1, !state); v.push_back(state); dfs(depth - 1, state); } int main() { int N; cin >> N; int D = 1; while (1 << D <= N) D++; dfs(D - 1, 1); i...
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); const long long inf = 1LL << 30; const double eps = 1e-9; const long long mod = 1e9 + 7; const int N = 100100; pair<int, pair<int, int>> a[N]; int seg[N << 2], lazy[N << 2]; ; int ans[N]; int dp[N]; void push(int nd, ...
#include <bits/stdc++.h> using namespace std; const int maxN = 2005; int n, h, l, r, a[maxN]; int dp[maxN][maxN]; inline int getint() { int num = 0, bj = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == EOF) return EOF; bj = (c == - || bj == -1) ? -1 : 1, c = getchar(); ...
#include <bits/stdc++.h> using namespace std; pair<int, int> cnt(string s) { int bal = 0, minBal = 0; for (char c : s) { if (c == ( ) bal++; else bal--; minBal = min(minBal, bal); } return {bal, minBal}; } int k[400400]; int main() { ios_base::sync_with_s...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int INF = 0x3f3f3f3f; const int mo = 1e9 + 7; inline int ksm(int a, int b) { int ret = 1; for (; b; b >>= 1, a = 1ll * a * a % mo) if (b & 1) ret = 1ll * ret * a % mo; return ret; } inline int read() { char ch...
#include <bits/stdc++.h> using namespace std; vector<int> a[200001]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int x, y; scanf( %d %d , &x, &y); a[x].push_back(y); } set<pair<int, int> > S; for (int i = 1; i <= n; i++) { sort(a[i].begin(), a[i].en...
#include <bits/stdc++.h> using namespace std; map<string, int> c; int main() { int l1, l2, f, ans = 0; string s1, s2; cin >> s1 >> s2; l1 = s1.length(); l2 = s2.length(); for (int i = 1; i <= min(l1, l2); i++) if (l1 % i == 0 && l2 % i == 0) { f = 0; c.clear(); ...
#include <bits/stdc++.h> using namespace std; int const MAX = 1e5 + 41; int n; int q; int s[MAX]; int m[MAX]; int r[MAX]; int const BLOCK = 441; bool sp[MAX]; int lt[MAX]; int ltb[MAX]; vector<pair<int, int> > a[MAX]; vector<long long> prefsum[MAX]; vector<long long> prefspeed[MAX]; int co...
#include <bits/stdc++.h> using namespace std; int n, m, a[100005], pn = 11, sumid[500005], lazy2[500005]; long long sum[500005], sum2[500005], pw[15], lazy[500005]; set<int> st; void getsum(int x) { sum2[x] = sum[x] - *lower_bound(pw + 1, pw + pn + 1, sum[x]); } void pushup(int x) { sum2[x] = max(...
#include <bits/stdc++.h> using namespace std; const int N = 1005; double a[N][N], f[N]; int n, m, sx, sy; inline void solve(int x) { memset(a, 0, sizeof(a)); for (int i = 1; i <= m; ++i) { if (i == 1) { a[1][1] = 2; a[1][2] = -1; a[1][m + 1] = 3 + f[1]; } else if (i...
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { if (x < 0) return -x; return x; } template <class T> T sqr(T a) { return a * a; } const double pi = acos(-1.0); const double eps = 1e-8; int i, n, cnt; char s1[110], s2[110]; void fun1() { if (s1[i + 1]...
#include <bits/stdc++.h> using namespace std; int check(string s) { int d = 0; for (int i = 0; i < s.length(); i++) if (s[i] == a || s[i] == e || s[i] == o || s[i] == u || s[i] == i ) d++; return d; } int main() { string s1, s2, s3; getline(cin, s1); getline(cin, s...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 55; string s[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) cin >> s[i]; int sx, sy, ex, ey; for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; char str1[200002], str2[200002]; const int K = 1024; int aw[200002]; int bw[200002]; char bit[1 << 16]; short cnt[200002 / K + 1][200002]; int main() { gets(str1); gets(str2); int l1 = strlen(str1), l2 = strlen(str2); for (int i = 0; i < l1; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10086; struct Node { string name; vector<Node *> son; }; char str[MAXN]; int ans; void build(Node *&root, int &pos) { if (str[pos] == 0) { root = NULL; return; } string name = ; for (; str[pos] != . && s...
#include <bits/stdc++.h> using namespace std; const int N = 100008; int n, a[N]; vector<pair<int, int> > ans; int main(void) { int i, j, k; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , a + i); for (i = 1; i + 2 <= n; i++) if (a[i]) { k = 1; for (j = 2; i + j <= n...
#include<bits/stdc++.h> typedef long long ll; using namespace std; const int MAXN = 5005; int tag[MAXN],s[MAXN]; ll dp[MAXN]; int main(){ ios::sync_with_stdio(false); int t;cin>>t; while(t--){ int n;cin>>n; for(int i=1;i<=n;i++){ cin>>tag[i]; } ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; template <typename T> inline T Bigmod(T base, T power, T MOD) { T ret = 1; while (power) { if (power & 1) ret = (ret * base) % MOD; base = (base * base) % MOD; power >>= 1; } return ret; } bool ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; const long long int P = 1000000007; const double eps = 1e-6; int val[N]; int deg[N]; vector<int> gr[N]; vector<long long int> mx(N); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000005; struct node { int l, r, sum, id; } tr[200010 * 4]; void build(int l, int r, int x) { tr[x].l = l, tr[x].r = r; if (l == r) { tr[x].sum = 0; tr[x].id = l; return; } int mid = (l + r) >> 1; build(...
#include <bits/stdc++.h> int main() { char A[100]; int M, N = 0, i = 0; scanf( %d , &M); scanf( %s , A); for (i = 0; i < M; i++) { if (A[i] == x && A[i + 1] == x && A[i + 2] == x ) { N++; } } printf( %d n , N); }
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k; long long int n, m, t; long long int a, b; scanf( %I64d%I64d%I64d , &n, &a, &b); t = n / a + 1; for (i = 0; i <= t; i++) { m = i * a; if ((n - m) % b == 0 && n - m >= 0) { printf( YES n%I64d...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 9; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long n, m; cin >> n >> m; vector<vector<long long>> v(n); vector<vector<long long>> vr(n); long long a, b; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 2e5 + 4; int main() { int n; scanf( %d , &n); long long b[n], c[n], sum = 0; for (int i = 0; i < n; i++) scanf( %lld , &b[i]), sum += b[i]; for (int i = 0; i < n; i++) scanf( %lld , &c[i]), sum += c[i]...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations ) #pragma GCC target( avx ) inline int read_char() { static char buf[1 << 16], *ptr = buf, *end_ptr = buf; if (ptr == end_ptr) { int len = fread(buf, 1, sizeof(buf), stdin); i...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; unsigned long long x[N], y[N], f[N]; int a[N], cnt[N]; queue<int> g[N]; mt19937_64 rng(time(0)); char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf; inline int rd() { int x = 0, f = 1; char ch = (p1 == p...
#include <bits/stdc++.h> void bubbleSort(long long int arr[], int n) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { int swap = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = swap; } } } } int main() ...
#include <bits/stdc++.h> using namespace std; const int maxN = 1000 * 1000; const int mod = 1000 * 1000 + 3; string com = ><+-.,[] ; int main() { string s; cin >> s; int res = 0; for (int i = 0; i < s.size(); i++) res = (res << 4) % mod, res = (res + 8 + com.find(s[i])) % mod; cout ...