func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, ans; int x[1100000], pw[1100000]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &x[i]); sort(x + 1, x + n + 1); pw[0] = 1; for (int i = 1; i <= n; i++) pw[i] = pw[i - 1] * 2 % 1000000007; for (int i = 1; i < n;...
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n, i, j, alp[27] = {0}, flg = 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 10000 + 10; int a[maxn]; int main() { int i, j, k, m, n; cin >> n; int sum = 0; while (n > 0) { if (n % 8 == 1) sum++; n /= 8; } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); int n; cin >> n; if (n == 5) return 0 * puts( 1 ); cout << n % 3 + 1 << n ; return 0; }
#include <bits/stdc++.h> using namespace std; int n; vector<int> edge[200010]; int dp[200010][2][2]; int leaf[200010]; void dfsLeaf(int u) { if (edge[u].size() == 0) { leaf[u] = 1; return; } for (int i = 0; i < edge[u].size(); ++i) { int v = edge[u][i]; dfsLeaf(v); ...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int x = 0, y = 0; int n = b.length(); while (x < n && a[x] == b[x]) x++; while (y < n && a[n - y] == b[n - 1 - y]) y++; int res = x + y + 2 - (n + 1); res = max(0, min(res, n + 1)); cout << res...
#include <bits/stdc++.h> #pragma optimize( Ofast ) using namespace std; using ll = long long; const int N = 2e5 + 5; vector<int> g[N]; bool vis[N]; int cnt; void dfs(int s) { ++cnt; vis[s] = true; for (auto it : g[s]) { if (!vis[it]) { dfs(it); } } } int main() { ...
#include <bits/stdc++.h> using namespace std; long long i, j, n, t, sum = 0, k, c1 = 1; int main() { cin >> n; vector<string> c(n); vector<string> s(n); for (i = 0; i < n; i++) { cin >> c[i] >> s[i]; } for (i = 1; i < n; i++) { k = 0; for (j = i - 1; j >= 0; j--) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int testCases = 1; cin >> testCases; while (testCases--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (n %...
#include <bits/stdc++.h> using namespace std; int n, k; long long mul[1005], c[1005][1005], f[1005][1005][2][3], chose[1005]; long long ans; int main() { scanf( %d%d , &n, &k); mul[0] = 1; for (int i = 1; i <= n; ++i) mul[i] = mul[i - 1] * (long long)i % 1000000007; for (int i = 0; i <= 1000; ...
#include <bits/stdc++.h> using namespace std; long long inf = 1e9; int main() { std::ios::sync_with_stdio(false); int n; cin >> n; long long noemer = 0; for (long long i = 1; i <= n; i++) { noemer += (n + 1 - i) * (n + 1 - i); } string s1, s2; cin >> s1; cin >> s2; do...
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, c, arr[5], count = 0; cin >> t; for (int i = 0; i < t; i++) { cin >> arr[0] >> arr[1] >> arr[2]; sort(arr, arr + 3); c = arr[0]; b = arr[1]; a = arr[2]; if (a > 0) { a--; count++; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const double PI = 3.141592653589793238463; const int N = 1e5 + 100; vector<int> v[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int x; cin >> x; int r, l; for...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; struct edge { int u, v, st, nt; } e[MAXN * 2]; vector<int> lis; int hd[MAXN], etot, used[MAXN], in[MAXN], u[MAXN], v[MAXN]; void addedge(int u, int v, int st) { e[etot].u = u; e[etot].v = v; e[etot].st = st; e[eto...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 9; int a[N], n; double ans(double x) { double arr[N]; for (int i = 0; i < n; i++) arr[i] = a[i] - x; double neg = 0; double pos = 0; double ans = 0; for (int i = 0; i < n; i++) { if (neg > 0) neg = 0; if (pos <...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int n, a, b, c, d, e, f, g, h, i, j, x, y, count = 0; cin >> n >> x >> y; n = n / 2; if ((x == n || x == n + 1) && (y == n || y == n + 1)) cout << NO ; else cout << YES ; ...
#include <bits/stdc++.h> using namespace std; struct Pt { long long int x, y; friend ostream& operator<<(ostream& os, const Pt& a) { os << a.x << << a.y; return os; } }; struct R { long long int a, b, c; }; int main() { ios::sync_with_stdio(false); long long int N, K;...
#include <bits/stdc++.h> using namespace std; template <typename T> void pr(vector<T> &v) { for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << ; cout << n ; ; } template <typename T> void pr(vector<vector<T>> &v) { for (int i = 0; i < (int)(v).size(); i++) { pr(v[i]); }...
#include <bits/stdc++.h> using namespace std; int main() { int length; cin >> length; int query; cin >> query; string result; cin >> result; for (int i = 0; i < query; ++i) { int left; int right; cin >> left >> right; char which; char what; cin >> whic...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long int n, x, y, cn = 0, ans = 0; string s; cin >> n >> x >> y >> s; for (int i = 0; i < n; i++) { if (s[i] == 0 ) cn++; else { if (cn) ans++; cn = 0; ...
#include <bits/stdc++.h> long long MOD = 1000000007; using namespace std; bool sortbysec(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.second < b.second); } long long POW(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a...
#include <bits/stdc++.h> using namespace std; template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x < 0 ? -x : x; } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } const int MAXN = 1e5 + 10; int n; int sum = 0; pair...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; struct Node { int is, id, x; bool operator<(const Node &a) const { if (x != a.x) return x < a.x; else return is < a.is; } }; int a[maxn * 4], s[maxn], p[maxn], inc[maxn], b[maxn], treea[maxn * 4], ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int p, q, l, r; cin >> p >> q >> l >> r; vector<pair<int, int> > z_timing, x_timing; int start, stop; for (int i = 0; i < p; i++) { cin >> start >> stop; z_ti...
// vaziat meshki-ghermeze ! #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << : << x << n using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pai...
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - 0 + c, c = getchar(); x *= f; } template <class T...
#include <bits/stdc++.h> using namespace std; const int SZ = 1e6 + 10; const int INF = 1e9 + 10; const int mod = 998244353; const long double eps = 1e-8; long long read() { long long n = 0; char a = getchar(); bool flag = 0; while (a > 9 || a < 0 ) { if (a == - ) flag = 1; a ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> poss; for (int i = 0; i < n; ++i) { int x = a[i]; while (x > 0) { poss.push_back(x); x /= 2; ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); int l = v[n - 1], q = v[n - 2]; int d = 0; for (int i = 0; i < n - 2; i++) { if (q > i + 1) d = i + 1; } co...
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int main() { ...
#include <bits/stdc++.h> using namespace std; bool b[4000000]; int main() { int n, cnt, x[2007], y[2007]; cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i]; b[x[i]] = 1; } for (int i = 1; i <= n; i++) { cin >> y[i]; b[y[i]] = 1; } cnt = 0; for (int i = 1;...
#include <bits/stdc++.h> using namespace std; const int N = 5000 + 5, mod = 1000 * 1000 * 1000 + 7; long long dp[N][N], ps[N]; int main() { long long n, a, b, k; cin >> n >> a >> b >> k; a--, b--; for (int i = 0; i < n; i++) { dp[0][i] = 1; } dp[0][b] = 0; for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; long long f[maxn], a[maxn]; int n; map<long long, long long> pre, sum; vector<long long> ans; void fir() { int st = 1; while (st <= n) { sum.clear(); pre.clear(); stack<long long> s; for (int& i = st; ...
#include <bits/stdc++.h> using namespace std; int gi() { int f = 1, x = 0; 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(); } return f == 1 ? x : -x...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int p1 = max((3 * a) / 10, a - ((a / 250) * c)); int p2 = max((3 * b) / 10, b - ((b / 250) * d)); if (p1 == p2) cout << Tie << endl; else if (p1 > p2) cout << Misha << endl; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void umax(T &a, T b) { if (a < b) a = b; } template <class T> inline void umin(T &a, T b) { if (a > b) a = b; } template <class T> inline T abs(T a) { return a > 0 ? a : -a; } template <class T> inline T gcd(T a,...
#include <bits/stdc++.h> using namespace std; const int MAX = 3005; int a[MAX], b[MAX], c[MAX], dp[MAX][2]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) cin >> c[i]; dp[1][0] = a[1]; dp[...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long flg = 0; for (long long i = 0; i < n - 1; i++) ...
#include <bits/stdc++.h> using namespace std; const int inf = 1012345678; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, Q; cin >> N >> Q; vector<vector<int> > g(N); int limit = 0; for (int i = 0; i < N; ++i) { int x, rad = 1; cin >> x; for (int j =...
#include <bits/stdc++.h> using namespace std; int n, m; const int maxn = 1e5 + 3; int terminal[maxn]; struct spe { int next, to; }; spe edge[maxn << 1]; int head[maxn]; int visit[maxn][3]; int cnt = 1, tpoint = -1; int nxt[maxn][2]; bool dp[maxn][3]; int cir = 0; bool dfs(int s, int val)...
#include <bits/stdc++.h> using namespace std; const int maxn = 100; const int maxm = 100; const int maxlen = maxn + maxm - 1; struct point { int ind, p; bool operator<(const point& b) const { return p < b.p; } } cell[maxlen]; char state[maxlen]; int n, m; long long k; int p; long long dp[m...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z, a, b; cin >> x >> y >> z; a = max(x, y); b = min(x, y); if (b + z < a || z == 0) { if (x > y) cout << + ; else if (x < y) cout << - ; else cout << 0 ; } else if (b + z >= a) ...
#include <bits/stdc++.h> const int mod = 1000000007, hmod = 10000019; int n, a[1000010], p[1000010], f[1000010]; long long sz[1000010]; int g[1000010]; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , a +...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &val) { val = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { val = (val << 3) + (val << 1) + (c ^ 48); c = get...
#include <bits/stdc++.h> using namespace std; stack<int> a[27]; stack<int> b[27]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n; cin >> n; string f, s; cin >> f >> s; for (int i = 0; i < f.size(); ++i) { if (f[i] == ? ) { a[26].pus...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f == 1 ? x : -x; ...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); long long ans = (6 * (1LL * n * (n + 1)) / 2); printf( %I64d n , ans + 1); }
#include <bits/stdc++.h> using namespace std; int main() { int n, num, sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> num; sum += num; } num = 0; for (int i = sum + 1; i < sum + 6; i++) { if (i % (n + 1) != 1) num++; } cout << num; return 0; }
#include <bits/stdc++.h> using namespace std; int t, n, m, cnt, xmin, xmax, ymin, ymax, head, tail, g[250 + 2][250 + 2], f[250 + 2][250 + 2], qx[250 * 250], qy[250 * 250]; bool checkType1() { if (tail != 4 * (xmax - xmin)) return false; for (int i = xmin; i <= xmax; ++i) { if (f[i][ymin] != cn...
#include <bits/stdc++.h> using namespace std; set<pair<long long, long long> > st; map<long long, long long> tp; long long ans[100013]; int main() { long long n, k; cin >> n >> k; vector<pair<long long, long long> > v(n); for (int i = 0; i < n; i++) { cin >> v[i].first; v[i].first ...
#include<bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including */ using namespace std; //using namespace __gnu_pbds; //typedefs typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typ...
#include <bits/stdc++.h> using namespace std; int a[4], b[4]; int get(int *a) { int ans; cout << ? << a[0] << << a[1] << << a[2] << << a[3] << endl; cin >> ans; return ans; } int get1(int a, int b, int c, int d) { int ans; cout << ? << a << << b << << c << ...
#include <bits/stdc++.h> using namespace std; int n, x, a, ans, r[2001], t[2001][2001]; bool f[2001][2001]; int main() { scanf( %d , &n); for (int _ = 1; _ <= n; _++) while (scanf( %d: , &x)) { r[_]++; for (int i = 1; i < x; i++) scanf( %d, , &a), t[_][a] = x; scanf( %d , &...
#include <bits/stdc++.h> using namespace std; const int maxN = 5e5 + 10, mod = 1e9 + 7; int n, q, cnt; int nxt[maxN + 1], res[maxN + 1], ans[maxN + 1]; int pw[maxN + 1], id[maxN + 1], tp[maxN + 1]; int L[maxN + 1], R[maxN + 1], S[maxN + 1]; int stk[maxN + 1], top; int sum[maxN + 1], mn[maxN + 1][21], lg...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int count = 0; while (s.size() != 1) { int sum = 0; for (int i = 0; i < s.size(); i++) sum += s[i] - 48; string res = ; while (sum) { ...
#include <bits/stdc++.h> #pragma GCC optimize(3, Ofast , inline ) #pragma GCC target( avx,avx2 ) using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == - , c = getchar(); while (isdigit(c)) x = (x << 1) + (x << ...
#include <bits/stdc++.h> using namespace std; long long mul(long long a, long long b) { if (!b) return 1; long long k = mul(a, b / 2); if (b & 1) return k * k % 998244353 * a % 998244353; return k * k % 998244353; } int n, k, N; long long A[200010], B[200010], C[200010], a, b, c, sum; long l...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { string n; int s; cin >> n >> s; reverse(n.begin(), n.end()); char temp[] = 0 ; n.insert(n.size(), temp); int sum = 0; ...
#include <bits/stdc++.h> using namespace std; long long sqr(long long x) { return x * x; } int mysqrt(long long x) { int l = 0, r = 1e9 + 1; while (r - l > 1) { int m = (l + r) / 2; if (m * (long long)m <= x) l = m; else r = m; } return l; } mt19937 rnd(1227);...
#include <bits/stdc++.h> using namespace std; const int MAXN = int(1e5 + 5); int n, A, cf, cm; int a[MAXN], tmp1[MAXN], tmp2[MAXN]; long long s[MAXN], m; int _max = 0, _min = int(1e9); bool cmp(int x, int y) { return a[x] < a[y]; } int main() { cin >> n >> A >> cf >> cm >> m; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; int n, k; double v1, v2, l; int main() { scanf( %d%lf%lf%lf%d , &n, &l, &v1, &v2, &k); int T = n / k; if (n % k) T++; printf( %.7lf n , (2 * T - 2 + (v1 + v2) / v1 - v2 / v1 + v1 / v2) * l / ((2 * T - 2) * v1 + v1 + v2)); ...
#include <bits/stdc++.h> using namespace std; bool ans[310000]; struct Query { int x1, y1, x2, y2, id; } querys[310000]; bool operator<(Query a, Query b) { return a.x2 < b.x2; } struct Point { int x, y; } points[310000]; bool operator<(Point a, Point b) { return a.x < b.x; } int minv[310000 <<...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x = n / 2, y = (n / 2) + 1, prime1 = 0, prime2 = 0; if (n % 2 == 0) { x = (n / 2); y = n / 2; } for (int i = 1; i <= n; i++) { for (int j = 2; j < x; j++) { if (x % j == 0) { p...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5, inf = 1e9 + 7; long long n, k, f[30]; string s, t, r; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long i, j, a, b, ans = 0; cin >> s >> t; r = s; sort(r.begin(), r.end(), greater<long long...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, k; cin >> n; int a[n], b[n]; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= n; i++) { k = a[i]; b[k] = i; } for (i = 1; i <= n; i++) { cout << b[i] << ; } }
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); const int INF = 1 << 29; const int MAXN = 505; int n; int M[MAXN][MAXN]; int R[MAXN]; long long A[MAXN]; int main(int argc, char** argv) { scanf( %d , &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const long long INF = 2000000000LL; long long res[MAXN], xx[MAXN << 1], cnt[MAXN << 1], la[MAXN << 1]; struct Event { long long l, r, y, v; Event() {} Event(long long _l, long long _r, long long _y, long long _v) : l(_l...
#include <bits/stdc++.h> using namespace std; long long n; long long l, val[205], cst[205]; char s[205]; long long ch[205][26], fail[205], cnt = 1; void Insert(char *s, long long w) { long long len = strlen(s), r = 0; for (long long i = 0; i < len; i++) { long long val = s[i] - a ; if (...
#include <bits/stdc++.h> int main() { int t, n, a, b, c, x, z = 0, e = 0, r = 0, o = 0, n1 = 0; char s[100000]; scanf( %d , &n); scanf( %s , &s); for (x = 0; x < n; x++) { if (s[x] == z ) z++; else if (s[x] == e ) e++; else if (s[x] == r ) r++; el...
#include <bits/stdc++.h> using namespace std; int a[20002][11] = {0}; int b[20002] = {0}; int c[11] = {0}; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf( %d , &a[i][j]); for (int i = 0; i < k; i++) { int x, y; cin ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5, mod = 1e9 + 7; vector<char> s; long long X; void paste(long long p, long long l, long long cnt) { if (s.size() > X + 3 || l == 0) return; for (long long i = 0; i < cnt; ++i) for (long long j = 0; j < l; ++j) if (s....
#include <bits/stdc++.h> using namespace std; using seg = pair<int, int>; using ll = long long; seg intersect(seg a, seg b) { seg ret = {max(a.first, b.first), min(a.second, b.second)}; if (ret.first > ret.second) return {-1, -1}; return ret; } inline int len(const seg& a) { return a.second - a....
#include <bits/stdc++.h> using namespace std; int a[3000]; int n, k; int ans = 0; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d , a + i); sort(a + 1, a + 1 + n); for (int i = 1; i <= k; i++) ans += a[i]; printf( %d n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; struct segment_tree { int val[200005 << 2]; inline void update(int l, int r, int k, int x, int w) { if (l == r) { val[k] = w; return; } int mid = l + r >> 1; if (x <= mid) update(l, mid, k << 1, x, w); else ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); const int N = 1e5 + 5; int n; map<string, set<string> > m; map<string, set<string> > m2; set<string> host; vector<set<string> > res; int main(void) { ios_base::sync_with_stdio(false); cin ...
#include <bits/stdc++.h> using namespace std; using ll = long long; struct Block { vector<array<int, 3>> events; int pop_before; vector<int> stack_after; void add_event(array<int, 3> v) { events.insert(upper_bound(events.begin(), events.end(), v), v); sort(events.begin(), events.end())...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int N = 700, COLOR = 3; int n; char s[N + 1]; int mch[N + 1]; int dp[N + 2][N + 1][COLOR][COLOR]; int main() { scanf( %s , s + 1); n = strlen(s + 1); stack<int> stk; for (int i = 1; i <= n; i++) if (s[i...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int64_t n, i; cin >> n; string s; cin >> s; string ans = ; ans = ans + s[0]; bool st = true; if ((n - 1) & 1) { st = false; } for (i = 1; i < n; i++...
#include <bits/stdc++.h> int main() { int req_amount; std::cin >> req_amount; while (req_amount--) { std::string s; std::cin >> s; int counter = 0; for (const auto c : s) { counter -= ((c == B ) ? -1 : 1); } std::cout << ((counter == 0) ? YES : NO ) << std::...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T > 0) { T--; string a, b; int d; cin >> a >> b; for (int i = 0; i < b.length(); i++) if (b[b.size() - i - 1] == 1 ) { d = i; break; } for (int i = ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1005; int n, s; struct Parcel { int l, r, w, s, v, id; } a[N]; vector<Parcel> p[N]; ll dp[N][N]; ll dfs(int pos, int r) { if (dp[pos][r] != -1) return dp[pos][r]; ll &ret = dp[pos][r]; ret = 0; vector...
#include <bits/stdc++.h> const int N = 50; std::vector<int> *graph[N][N], *igraph[N][N]; std::vector<int> expand(std::vector<int> *graph[N][N], std::vector<int> queue, int max) { for (int t = 0; t + 1 < (int)queue.size() && (int)queue.size() <= max; ++t) { int u = queue[t]; ...
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535897; int m, n, dp[5005][5005], ans; char yy[5005], sy[5005]; signed main() { std::ios::sync_with_stdio(0); std::cin.tie(0); cin >> m >> n >> yy >> sy; for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) { ...
#include <bits/stdc++.h> int main() { int x, y, z, a, b, c; scanf( %d %d %d , &x, &y, &z); scanf( %d %d %d , &a, &b, &c); if (x == a || y == b || z == c) printf( YES n ); else printf( NO n ); }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; unordered_set<char> st; for (int i = 0; i < s.length(); i++) { if (s[i] != s[i + 1]) { st.insert(s[i]); } else { i++; } ...
#include <bits/stdc++.h> using namespace std; const int N = 61; const int K = 22222; const int M = K + K + 5; int n, m; int a[N], b[N]; long long m1[M], m2[M]; int main() { scanf( %d %d , &n, &m); for (int i = 0; i < n; i++) scanf( %d , &a[i]); for (int i = 0; i < m; i++) scanf( %d , &b[i]);...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int n, ans[100001][4], cnt = 0; pair<int, int> t[4]; priority_queue<pair<int, int> > q; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x...
#include <bits/stdc++.h> using namespace std; void qmax(int &x, int y) { if (x < y) x = y; } void qmin(int &x, int y) { if (x > y) x = y; } inline long long read() { char s; long long k = 0, base = 1; while ((s = getchar()) != - && s != EOF && !(isdigit(s))) ; if (s == EOF) e...
#include <bits/stdc++.h> using namespace std; long long n, m, sx, sy, ex, ey, a, b; vector<pair<int, long long>> node[100001]; vector<pair<long long, int>> X, Y; vector<long long> dist; vector<bool> done; int mulMod(long long, long long); int addMod(int, int); void readArray(int *, int); void printA...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; long long int x[maxn]; long long int sum, ans; map<long long int, long long int> table[27]; string s; int main() { for (int i = 1; i <= 26; i++) cin >> x[i]; cin >> s; for (int i = 0; i < s.size(); i++) { ans += table[s[...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; signed main() { long long n; cin >> n; vector<long long> a(n); vector<long long> ruio(n + 1, 0); vector<long long> ruit(n + 1, 0); long long ro = 0; long long rt = 0; for (long long i = 0; i < n; i++) { ci...
#include <bits/stdc++.h> using namespace std; int main() { double r, x1, y1, x2, y2; cin >> r >> x1 >> y1 >> x2 >> y2; double distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); if (distance == 0) { cout << 0; return 0; } if (distance <= 2 * r) { cout << 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int T, n, m, a[N], b[N], cnt, res[N << 1], v[N << 1], t, c[N << 1], pr[N], sf[N], p[N]; long long ans; void add(int x, int y) { for (int i = x; i; i -= i & (-i)) c[i] += y; } int query(int x) { int ans = 0; for (int i =...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; long long fact[200005]; long long factinv[200005]; long long lgput(long long a, long long exp) { long long rz = 1; while (exp) { if (exp & 1LL) { --exp; rz = (rz * 1LL * a) % mod; } else { exp ...
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1000 * 100 + 10; int to[N], nxt[N], idx[N], tot; int rnk[N], sz[N]; bool visited[N]; int minsz, center; void add_edge(int u, int v) { ++tot; to[tot] = v; nxt[tot] = idx[u]; idx[u] = tot; } int compute_size(int node, int pa...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; long long int a[n + 1][m + 1], i, j, p = 0; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cin >> a[i][j]; } } for (i = ...
#include <bits/stdc++.h> using namespace std; struct data { int a, b, c, d; data() {} data(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {} }; const int MAX = 100500; data info[MAX]; int main() { std::ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; info[0] = dat...
#include <bits/stdc++.h> using namespace std; long long a[500005]; long long add[500005]; int main() { int i, j, n, x, y, z, m; long long sum; scanf( %d , &n); sum = 0; a[0] = 0; m = 1; for (i = 0; i < n; i++) { scanf( %d , &x); if (x == 1) { scanf( %d%d , &y, &z)...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1100; int n; vector<int> g[N]; int ed[N][3]; int ans[10 * N][3]; int ansSz; void addAns(int v, int u, int x) { ans[ansSz][0] = v + 1; ans[ansSz][1] = u + 1; ans[...
#include <bits/stdc++.h> constexpr int MAXN = 1e5 + 5; using namespace std; int tot, n, cnt; unordered_map<int, int> Map; vector<int> vec; vector<pair<string, int>> opt; string s; inline void discretization() { sort(vec.begin(), vec.end()); cnt = unique(vec.begin(), vec.end()) - vec.begin(); ...