solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const long long N = 10005; const long long INF = 1e15; const int MOD = 1e9 + 7; const double EPS = 1e-7; const double PI = acos(-1.0); string s; int main() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); cin >> s; int n = s.size(); if (s[0] == '-') {...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int n; int prime[maxn]; int cnt = 0; bool flag[maxn * 2]; int ans[maxn]; void p() { for (int i = 2; i <= n * 2; i++) { if (!flag[i]) prime[cnt++] = i; for (int j = 0; j < cnt; j++) { if (i * prime[j] > maxn * 2) break; flag[i ...
4
#include <bits/stdc++.h> namespace IO { static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23; inline char myGetchar() { static char buf[IN_BUF], *ps = buf, *pt = buf; if (ps == pt) { ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin); } return ps == pt ? EOF : *ps++; } template <typename T> inline bool read(...
16
#include <bits/stdc++.h> using namespace std; bool cmp(int i, int j) { return i < j; } int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int min1 = 10000000000; long long int *pole = new long long int[n]; for (long long int i = 0; i < n; i++) { ci...
0
#include <bits/stdc++.h> using namespace std; const int N = 500001; char s[N], t[N]; long long len, k, ans, r; int main() { scanf("%lld%lld", &len, &k); scanf("%s%s", s, t); if (s[0] < t[0]) r = 2; else r = 1; if (r >= k) { ans += len * k; printf("%lld", ans); return 0; } ans += r; f...
12
#include <bits/stdc++.h> using namespace std; void File() { freopen("output.txt", "w", stdout); freopen("input.txt", "r", stdin); } void fast() { ios::sync_with_stdio(NULL); cout.tie(NULL); cin.tie(NULL); } const double pi = 2 * acos(0.0); const int nn = 1e5 + 4; const int oo = 0x3f3f3f3f; long long nCr(long ...
8
#include <bits/stdc++.h> using namespace std; const long long int OO = 2e7; const double EPS = (1e-7); bool sort_p(pair<int, int> a, pair<int, bool> b) { return a.second < b.second; } long long int mod = 998244353; int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); int k, n; cin >> n >> k; ve...
5
#include <bits/stdc++.h> using namespace std; long long t = 1, n, xx, x = 0, y = 0, cc, f, m, k, base = 397; long long hsh[2000005], ans; long long pb[2000000 + 5]; string s, ss = ""; long long get_hash(string str, int sz) { long long ans = 0; for (int i = 0; i < sz; i++) { ans += ((str[sz - i - 1] - 'a' + 1) *...
9
#include <bits/stdc++.h> using namespace std; const int Maxn = 100 + 19; int A[Maxn], n, Max, Gcd = 0; int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &A[i]); if (A[i] > Max) Max = A[i]; Gcd = gcd(Gcd, A[i]); } printf("...
8
#include <bits/stdc++.h> using namespace std; void func(void) { freopen("input.c", "r", stdin); freopen("output.c", "w", stdout); } void print(vector<long long> &v) { cout << v.size() << endl; for (int i = 0; i < v.size(); i++) { printf("%lld ", v[i]); } printf("\n"); } void print(vector<pair<long long,...
16
#include <bits/stdc++.h> using namespace std; char s[2000005]; int ans; int main() { scanf("%s", s + 1); int n = strlen(s + 1); if (n == 1) { puts("1"); return 0; } int l = 0; for (int i = 1; i <= n; i++) s[n + i] = s[i]; s[0] = s[n], s[n + n + 1] = s[1]; for (int i = n + 1; i; i--) { if (s[...
14
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e17 + 10; const int INF = 1e9 + 7; void add(int& a, int b) { a += b; if (a >= mod) { a -= mod; } } string s; string t; int n, m; int cache[401][401][401]; int dp(int i, int j, int...
14
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:200000000") using namespace std; const int MAXN = 5000000; const long long MOD = (long long)1e9 + 7; const int INF = 0x3f3f3f3f; const long long INF_64 = (1LL << 62); const double eps = 1e-9; int main() { int n, m; cin >> n >> m; if (m < n - 1 || m > 2 * n ...
6
#include <bits/stdc++.h> using namespace std; map<int, int> H; int n, bit[200010 << 1], d[200010 << 1], dt, cnt; int f[200010], ans; struct point { int x, w; void in() { scanf("%d %d", &x, &w); } } a[200010]; bool cmp(point i, point j) { return i.x < j.x; } int query(int x) { int s(0); for (; x; x -= x & -x) s ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0; int arr[200004]; cin >> n; for (int i = 0; i < n; i++) arr[i] = i; cnt += n * (n - 1) / 2; for (int j = n - 1; j > 0; j--) { for (int i = 0; i < j; i++) cnt += arr[i]; cnt++; } cnt++; cout << cnt << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { char s[105]; gets(s); int j, i, n = strlen(s), res = 0; vector<int> a; for (i = 0; i < n; ++i) { a.clear(); int x = (int)s[i], w = 2; while (x > 0) { a.push_back(x % w); x /= w; } int z = a.size(); for (j = z; j < 8...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); string s; vector<long long> neg, pos, z; long long i, n; cin >> n; for (i = 0; i < n; i++) { cin >> s; long long t = 0, mi = LLONG_MAX; bool wasneg = false; for (lon...
6
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100; const int M = 3; const char ccs[M + 1] = "CMY"; int cmap[128], dp[MAX_N][M]; char s[MAX_N + 4]; int main() { for (int i = 0; i < M; i++) cmap[ccs[i]] = i; int n; scanf("%d%s", &n, s); if (s[0] == '?') for (int j = 0; j < M; j++) dp[0][j] =...
5
#include <bits/stdc++.h> using namespace std; struct interval { int l, r, idx; bool operator<(const interval& a) const { return l != a.l ? l < a.l : idx > a.idx; } } arr[300005]; vector<pair<int, int> > L[300005]; int uni[300005]; void build(int n) { set<interval> s; for (int i = 1; i <= n; i++) { uni...
27
#include <bits/stdc++.h> long long int power(long long int a, long long int b) { long long int ans = 1; long long int k = a; while (b) { if (b % 2 == 1) ans *= k, ans %= 1000000007; k *= k, k %= 1000000007; b /= 2; } return ans; } long long int check[110][110]; long long int comb(int a, int b) { ...
19
#include <bits/stdc++.h> using namespace std; long long int fact[400005]; int open[200005]; int clo[200005]; long long int power(long long int n, long long int x) { if (x == 0) return 1; long long int temp = power(n, x / 2); if (x & 1) return (n * ((temp * temp) % 1000000007)) % 1000000007; else return ...
15
#include <bits/stdc++.h> using namespace std; long long p(long long l) { if (l < 10) return l; long long f, t, ret; t = l % 10; f = l; while (f >= 10) f /= 10; ret = l / 10 + 9; if (t < f) ret--; return ret; } int main() { long long l, r; cin >> l >> r; cout << p(r) - p(l - 1) << endl; return 0;...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; char s[maxn]; int b[maxn]; int c[2][maxn]; pair<int, int> f[maxn]; int main() { int n, m; cin >> n >> s + 1 >> m; for (int i = 1; i <= n; i++) { b[i] = b[i - 1] + (s[i] == '?'); if (s[i] != 'a') c[0][i] = c[1][i - 1] + 1; if (s[i] ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long n, T; cin >> n >> T; map<long long, vector<vector<long long>>> data; for (int i = 1; i <= n; ++i) { long long a, t; cin >> a >> t; data[a].push_back({t, i, a}); } set<vector<long ...
10
#include <bits/stdc++.h> using namespace std; long n, k, bad[1 << 20]; vector<long> vec[1 << 20]; long cnt; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; for (int i = 1; i <= n; i++) { vec[i].push_back(6 * i - 4); vec[i].push_back(6 * i - 5); vec[i].push_back(6 * i - 3); vec[i].push_ba...
11
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } bool hasOddFactor(long long n) { for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { if (i % 2 == 1 || (n / i) % 2 ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k; cin >> n; int l = n % 10; if (l <= 5 && l != 0) { cout << n - l; return 0; } else if (l > 5) { int y = 10 - l; cout << n + y; } else if (n % 10 == 0) cout << n; return 0; }
0
#include <bits/stdc++.h> using namespace std; string M[55]; vector<int> R[55], C[55]; bool vr[55], vc[55]; vector<int> cr, cc; void dfs(int u, bool d) { if (!d) { cr.push_back(u); vr[u] = 1; for (int c : R[u]) { if (!vc[c]) dfs(c, 1); } } else { cc.push_back(u); vc[u] = 1; for (int...
5
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } const char lf = '\n'; namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *t ...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j; string str; cin >> n >> m; for (i = 1; i <= n; i++) { if (i % 2) { str = ""; for (j = 1; j <= m; j++) str += '#'; } else if ((i % 2 == 0) && (i % 4 == 0)) { str = "#"; for (j = 2; j <= m; j++) str += '.'; ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1000000000") #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") using namespace std; const int maxn = (int)1e5 + 10; struct vt { long double x, y; }; vt operator-(vt a, vt b) { a.x -= b.x; a.y -= b.y; return a; } vt operator+(vt a, vt b) { a....
24
#include <bits/stdc++.h> using namespace std; char st[105][105]; int n, m, ans, sx[10005], sy[10005], sz[10005]; bool fl[105][105]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", st[i] + 1); if (st[1][m] == '*' || st[1][1] == '*' || st[n][1] == '*' || st[n][m] == '*') { pri...
9
#include <bits/stdc++.h> using namespace std; int main() { int x; char c; double y; cin >> x >> c >> y; cout << ((x % 12) * 30 + (y / 2)) << " " << y * 6; return 0; }
4
#include <bits/stdc++.h> using namespace std; const int iinf = 1e9 + 10; const long long inf = 1ll << 60; const long long mod = 1e9 + 7; void GG() { cout << "0\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) re = re * a % mo; a =...
17
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int n, m, k, deg[N], ans[N], s[N], t[N]; map<int, bool> adj[N]; vector<int> g[N]; bool alive[N]; void solve() { priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q; memset(alive, 1, sizeof(al...
14
#include <bits/stdc++.h> using namespace std; int n, a[1200][1200]; int q, ans = 0; int x, num; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]); for (int i = 1; i <= n; i++) if (a[i][i]) ans++; ans %= 2; scanf("%d", &q); while (q--) { ...
8
#include <bits/stdc++.h> using namespace std; int n; int f[200005], a[200005]; int ans[200005]; int find(int x) { if (x == f[x]) return x; else return f[x] = find(f[x]); } void Union(int x, int y) { int fx = find(x); int fy = find(y); if (fx != fy) f[fx] = fy; } int main() { cin >> n; for (int i =...
9
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const int M = 1e5 + 5; const int N = 300; char s[M]; int f[26][M]; int dp[N][N][N]; int ch[4][N]; int main() { int n, m; scanf("%d%d%s", &n, &m, s + 1); for (int k = 25; k >= 0; k--) { f[k][n + 1] = n + 1; for (int i = n; i >= 0; i--) ...
14
#include <bits/stdc++.h> using namespace std; int main() { long long N, L, K; map<int, int> mp, mpe; scanf("%lld%lld%lld", &N, &L, &K); long long rem = L % N, rc = L / N; for (int n = 0; n < int(N); n++) { int x; scanf("%d", &x); mp[x]++; if (n < rem) mpe[x]++; } long long ans = 0; vecto...
13
#include <bits/stdc++.h> using namespace std; bool isSubSequence(string str1, string str2, int m, int n) { if (m == 0) return true; if (n == 0) return false; if (str1[m - 1] == str2[n - 1]) return isSubSequence(str1, str2, m - 1, n - 1); return isSubSequence(str1, str2, m, n - 1); } int main() { string st...
6
#include <bits/stdc++.h> using namespace std; int in() { int x; return cin >> x, x; } template <class T, class L> T& smax(T& x, L y) { return x < y ? x = y : x; } template <class T, class L> T& smin(T& x, L y) { return x > y ? x = y : x; } const int maxn = 1e2 + 17; int n; char c[maxn][maxn]; int d[maxn * maxn ...
13
#include <bits/stdc++.h> using namespace std; const int MAX_SIZE = 100 + 8; long long a[MAX_SIZE], bb[MAX_SIZE]; int c[MAX_SIZE]; const long long MOD = 1e9 + 7; const long long M_SIZE = 16; long long mod(long long &x) { x -= x / MOD * MOD; } struct Matrix { long long m[M_SIZE][M_SIZE]; long long N; void init() { ...
13
#include <bits/stdc++.h> int main() { int q, a, j; scanf("%d", &q); for (j = 0; j < q; j++) { scanf("%d", &a); if (a == 2) printf("2\n"); else if (a % 2 == 0) printf("0\n"); else printf("1\n"); } }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 * 100 + 10, SQ = 300; vector<int> graph[MAXN], t[MAXN]; vector<pair<int, int> > vec[MAXN]; int c[MAXN], ans[MAXN]; set<pair<int, int> > st[2][MAXN]; bool mark[MAXN]; void dfs(int v) { mark[v] = true; for (int i = 0; i < SQ; i++) t[v].push_back(0); ...
16
#include <bits/stdc++.h> using namespace std; int n; long long k, p, ans; map<long long, long long> mp; int main() { scanf("%d%lld%lld", &n, &p, &k); for (int i = 1; i <= n; i++) { long long x; scanf("%lld", &x); x = ((x % p * x % p * x % p * x % p - (k * x) % p) % p + p) % p; ans += mp[x], mp[x]++;...
15
#include <bits/stdc++.h> using namespace std; using i64 = long long; int n, a[423456], cnt[423456]; int s[423456], pos[423456], answer; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); cnt[a[i]]++; } int cntmode = 0; for (int i = 1; i <= n; i++) cntmode = max(cntmode, c...
18
#include <bits/stdc++.h> using namespace std; char s[20]; int main() { scanf("%s", s); int len = strlen(s); while (len && s[len - 1] == '0') --len; int mid = len / 2; bool ans = true; for (int i = 0; i <= mid; ++i) { if (s[i] != s[len - 1 - i]) { ans = false; break; } } printf("%s\n"...
1
#include <bits/stdc++.h> using namespace std; int main() { long long bulls = 0, cows = 0, bullsm, l1 = 0, l2 = 0, l3 = 0, l4 = 0; for (long long i = 0; i < 10; i++) { cout << "000" << i << endl; fflush(stdout); cin >> bulls >> cows; if (i == 0) bullsm = bulls; if (bullsm < bulls) l4 = i; } b...
8
#include <bits/stdc++.h> using namespace std; struct { bool operator()(const string what, const string what1) const { return what.length() < what1.length(); } } LenCompare; struct { void str(vector<string> VecStr) { for (int i = 0; i < VecStr.size(); i++) { cout << VecStr[i] << ' '; } } void...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 200; int qianzhui[maxn]; int n, k; char a[maxn]; bool check(int x) { int L, R; for (int i = 1; i <= n; i++) { if (a[i] == '1') continue; L = max(i - x, 1); R = min(i + x, n); if (qianzhui[R] - qianzhui[L - 1] >= k + 1) { retu...
8
#include <bits/stdc++.h> using namespace std; const int N = 100 * 1000 + 20; int main() { int cnt = 0; string heidi = "heidiA", str; cin >> str; for (int i = 0; i < str.size(); i++) if (heidi[cnt] == str[i]) cnt++; if (cnt == 5) cout << "YES"; else cout << "NO"; }
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 1010; int dp[N][N][2]; int bits[N]; int t, k; long long dfs(int len, int pos, int num, bool mark) { int maxx; long long sum; if (!len) { if (num == 1) { return true; } else { return false; } } if (!mar...
17
#include <bits/stdc++.h> using namespace std; long long int P = 1000000007; long long int a[100001], parent[100001], value[100001], flag = 0, ans = 0; vector<long long int> adj[100001]; long long int visited[100001]; void dfs(long long int src, long long int val) { visited[src] = 1; for (long long int i = 0; i < ad...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; int arr1[n], arr2[n]; for (int i = 0; i < n; i++) { cin >> arr1[i]; } for (int i = 0; i < n; i++) { cin >> arr2[i]; } ...
2
#include <bits/stdc++.h> using namespace std; int n, a, b, k; int dp[5001][5001] = {0}; int sum[5001][5001] = {0}; int solve1() { for (int i = 0; i <= k; i++) { for (int j = 1; j <= n; j++) { if (!i) { dp[i][j] = 1; } else { int diff = abs(j - b); dp[i][j] = (dp[i][j] + (sum[i ...
11
#include <bits/stdc++.h> using namespace std; bool prime[1000001 + 3]; void SieveOfEratosthenes() { memset(prime, true, sizeof(prime)); for (long long p = 2; p * p <= 1000001; p++) { if (prime[p] == true) { for (long long i = p * p; i <= 1000001; i += p) prime[i] = false; } } } long long gcd(long lo...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i = 0; i = i + n / 5; n = n % 5; i = i + n / 4; n = n % 4; i = i + n / 3; n = n % 3; i = i + n / 2; n = n % 2; i = i + n / 1; n = n % 1; cout << i; }
0
#include <bits/stdc++.h> using namespace std; const int maxd = 1000000007, N = 501000; const double pi = acos(-1.0); struct node { int id, l, r; } q[N]; int n, m, p[22], a[N], pos[22], ans[N]; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < '0') || (ch > '9')) { if (ch == '-') f = -1; c...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, c, d; cin >> a >> b >> c >> d; if (a != c && b != d) cout << 2 * (abs(a - c) + abs(b - d) + 2); else cout << 2 * (abs(a - c) + abs(b - d) + 3); return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; cout << n - 1 << " " << 1 << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<long long> vec; const long long MOD = 1e9 + 7; long long sel[1000003], cnt[1000003]; bool isprime[1000003]; void sieve() { memset(isprime, 1, sizeof isprime); isprime[1] = 0; for (int i = 2; i <= 1000000; i++) { if (isprime[i]) { vec.push_back(i); ...
14
#include <bits/stdc++.h> using namespace std; using pi = pair<int, int>; using lint = long long; const int mod = 1e9 + 7; const int inv2 = (mod + 1) / 2; const int MAXN = 100005; char s[MAXN]; int main() { scanf("%s", s); int n = strlen(s); lint r = 0, k = 0, p = 1; for (int i = 1; i <= n; ++i) { lint l = n...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const int mod = 1e9 + 7; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int n, m, arr[maxn], nxt = 1; vector<int> adj[maxn]; void no() { cout << "NO\n"; exit(0); } int main() { ios_base::sync_with_stdio(false)...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; int n; long long area, cnt; double fac[200], calc, ans; struct Point { long long x, y; Point() {} Point(long long x, long long y) : x(x), y(y) {} Point operator-(const Point& tmp) const { return Point(x - tmp.x, y - tmp.y); } } p[...
20
#include <bits/stdc++.h> using namespace std; int prime[1000005]; bool vis[1000005]; int n, tot; void getprime() { for (int i = 2; i <= n; i++) { if (vis[i] == 0) prime[tot++] = i; for (int j = 0; j < tot && i * prime[j] <= n; j++) { vis[i * prime[j]] = 1; if (i % prime[j] == 0) break; } } }...
5
#include <bits/stdc++.h> using namespace std; int T; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s1, s2, s3; getline(cin, s1); getline(cin, s2); getline(cin, s3); unsigned long long n1, n2, n3; n1 = ((int)(s1.size())); n2 = ((int)(s2.size())); n3 = ((int)(s3.size())); string ans ...
0
#include <bits/stdc++.h> using namespace std; const int nax = 3e5 + 69; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t, n, a[nax]; cin >> t; while (t--) { cin >> n; map<int, vector<int> > m; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (!m[a[i]]...
7
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; while (T--) { long long a, m; cin >> a >> m; long long g = gcd(a, m); ...
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = 1e18 * 4; const long double pai = acos(-1); int n, m; vector<pair<char, pair<int, int> > > v; string s[509]; int done[509][509]; int X[] = {-1, 0, 1, 0}; int Y[] = {0, 1, 0, -1}; void dfs(int x, int y, int last) { do...
11
#include <bits/stdc++.h> using namespace std; int dp[2000 + 1]; int v[2000 + 1]; int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } int main() { int i, j, N, t = -1, res = 0; scanf("%d", &N); for (i = 1; i <= N; ++i) scanf("%d", &v[i]); for (i = 1; i <= N; ++i) if (v[i] != 1) ++res; for (i = 1...
7
#include <bits/stdc++.h> using namespace std; int fx[] = {-1, 1, 0, 0}, fy[] = {0, 0, -1, 1}; int main() { int a, b, c, d, e, f, g; char p[100][100]; cin >> a; for (int i = 0; i < a; i++) { cin >> p[i]; } for (int i = 0; i < a; i++) { for (int j = 0; j < a; j++) { b = 0; for (int k = 0; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, k; long long ips[maxn]; long long fmt(int a[4]) { return ((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]); } string outfmt(long long a) { string res = ""; for (int i = 3; i >= 0; i--) { int r = 0; for (int j = 0; j < 8; j++) {...
8
#include <bits/stdc++.h> using namespace std; int inf = 1000000001; long long int llinf = 1000000000000000001LL; long long int mod = 1000000007; double eps = 1e-15; int dx[] = {1, 1, -1, -1}; int dy[] = {1, -1, 1, -1}; vector<bool> isprime; vector<int> primes; void seive(int n, bool wantlist = true) { isprime.resize(...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int64_t> w(n), m(n); vector<vector<pair<int, int64_t>>> e(n); vector<int64_t> p(n), r(n); for (int i = 0; i < n; ++i) { cin >> w[i]; } for (int i = 1; i < n; ++i) { int u, v; int64_t c; cin >> u >> v >> c;...
10
#include <bits/stdc++.h> using namespace std; int f[4], n, m, ans, xs, ys; char c[100][100]; string s; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int go(int x, int y, int ind) { if (x < 0 || x >= n || y < 0 || y >= m || c[x][y] == '#') return 0; if (c[x][y] == 'E') return 1; if (ind >= s.size()) return...
4
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long md) { long long res = 1; x %= md; while (y > 0) { if (y & 1) res = (res * x) % md; x = (x * x) % md; y = y >> 1; } return res % md; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout....
4
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; for (int i = 0; i < 1000; i++) cout << "5"; cout << endl; for (int i = 0; i < 999; i++) cout << "4"; cout << "5"; }
4
#include <bits/stdc++.h> using namespace std; int n, ans; pair<int, int> coord[200025]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> coord[i].first >> coord[i].second; for (int i = 1; i <= n; ++i) { int vecst = 0, vecs = 0, vecj = 0, vecd = 0; for...
2
#include <bits/stdc++.h> using namespace std; int x[200005], n, c, j; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i]; } sort(x, x + n); for (int i = 0; i < n; i++) { while (j < n && x[j] - x[i] <= 5) { j++; c = max(c, j - i); } } cout << c << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; inline int read() { register int x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ '0'); ch = getchar(); } return f ? x : -x; } const int N = 1e2 ...
18
#include <bits/stdc++.h> using namespace std; long long t; long long n, m, k; long long x, y, a, b; long long sad, sol; long long maxx, minn; vector<long long> v; int main() { cin >> t; while (t--) { cin >> n >> a >> b; for (int i = 0; i < n; i++) { cout << char('a' + (i % b)); } cout << "\n";...
1
#include <bits/stdc++.h> using namespace std; int dx4[] = {-1, 0, 1, 0}; int dy4[] = {0, 1, 0, -1}; int dx8[] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; void Duxar(int _this_line) {} bool AreEqual(double a, double b) { return (fabs(a - b) < 1e-10); } template <class T> bool GetNr(T &_value)...
16
#include <bits/stdc++.h> using namespace std; const int INF = 2000000000; const double PI = acos(-1.0); const int MAXN = 100000 + 7; int a[MAXN]; int n; long long solve(int l, int r) { vector<int> v(r - l); for (int i = l + 1; i <= r; i++) { v[i - l - 1] = abs(a[i] - a[i - 1]); } int n = v.size(); vector<...
13
#include <bits/stdc++.h> using namespace std; int main() { long long u, v; cin >> u >> v; if (u % 2 != v % 2 || u > v) { cout << -1; return 0; } if (u == v) { if (u == 0) cout << 0; else cout << 1 << endl << u; return 0; } long long ans = (v - u) / 2; if (u & ans) cou...
9
#include <bits/stdc++.h> int main() { char A[101], B[101]; int t; scanf("%d", &t); while (t--) { scanf("%s%s", A, B); int a[26] = {0}, b[26] = {0}; for (int i = 0; A[i] != '\0'; i++) { a[A[i] - 'a']++; b[B[i] - 'a']++; } for (int i = 0; i < 26; i++) { if (a[i] > 0 && b[i] >...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string pat = "aeiouy"; int n; cin >> n; char p, c; cin >> p; cout << p; while (cin >> c) { if (pat.find(c) != string::npos && pat.find(p) != string::npos) continue; p = c; cout << p; } ...
0
#include <bits/stdc++.h> using namespace std; int n, q, x, y; pair<int, int> a[30005], b[30005]; int posa[30005], posb[30005], match[30005]; long long dp[30005]; void updp(int bas) { for (int i = bas; i <= n; i++) { dp[i] = -200000000000000000; if (match[i] != i) dp[i] = max(dp[i], dp[i - 1] + 1ll * a[i...
22
#include <bits/stdc++.h> using namespace std; int main() { int n, m, v; cin >> n >> m >> v; --v; long long sum = ((n - 1) * (n - 2)) / 2; if (m < n - 1 || m > sum + 1) { cout << -1; return 0; } vector<pair<int, int>> vec; vec.push_back({0, 1}); m--; for (int i = 1; m && i < n; i++) { for...
9
#include <bits/stdc++.h> using namespace std; mt19937_64 rnd(503984); unordered_map<unsigned long long, int> mp; int n, cnt = 0; vector<int> v[100010]; unsigned long long val[300010], S[300010]; int a[100010], b[100010]; bool vis[300010]; void dfs1(int np, int fath) { unsigned long long sum = 0; for (int &x : v[np]...
21
#include <bits/stdc++.h> using namespace std; const double EPS = 5e-5; map<string, int> M; int main() { int n, m; double k; cin >> n >> m >> k; string s; int v; for (int i = 0; i < n; i++) { cin >> s >> v; double b = v * k; if (b + EPS < 100) { b = 0; continue; } M[s] = (int)...
9
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; mt19937 rng(time(NULL)); using ll = long long; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using ld = long double; using vb = vector<bool>; const ll MOD = 1000000007; ll sqr(ll a) { return a...
9
#include <bits/stdc++.h> int n; double x[100000]; double y[100005]; double dist(double x1, double y1, double x2, double y2) { double d1 = (x1 - x2) * (x1 - x2); double d2 = (y1 - y2) * (y1 - y2); return sqrt(d1 + d2); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lf %lf", &x[i], &...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; map<int, int> mp; for (int i = 0; i < n; i++) { int a; scanf("%d", &a); mp[a] = 1; } int ans = 0; if (mp.find(m) != mp.end()) ans++; for (int i = 0; i < m; i++) { if (mp.find(i) == mp.end()) { ans++...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10, MOD = 1e9 + 7; int n; void solve(int i, int j, int k, int l, int m) { printf("%d %d\n", i, j); printf("%d %d\n", i, k); printf("%d %d\n", l, m); printf("%d %d\n", k, m); printf("%d %d\n", i, l); printf("%d %d\n", j, m); printf("%d %d\n"...
23
#include <bits/stdc++.h> using namespace std; template <typename T> void print_vector(vector<T> path) { copy(path.begin(), path.end(), ostream_iterator<T>(cout, " ")); cout << endl; } template <typename T> void print_array(T a, long long n) { for (long long i = 0; i < n; i++) cout << a[i] << " "; cout << endl; ...
3
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1000005; int b[maxn]; vector<pair<int, int>> h[maxn], v[maxn]; int query(int x) { int ret = 0; while (x) { ret += b[x]; x -= x & (-x); } return ret; } void update(int x, int d) { while (x < maxn) { b[x] += d; ...
16
#include <bits/stdc++.h> using namespace std; const int mo = 1000000007 * 2; int a[17][17], ans[17][17], b[17][17], l, r; int P(int x, int y) { return y + x * 4; } void pret() { int j, k, l; for (j = 0; j < 4; ++j) for (k = 0; k < 4; ++k) { for (l = 0; l < 4; ++l) { if (k == l) continue; i...
17
#include <bits/stdc++.h> using namespace std; const int N = ((1 << 18) + 100); const int M = N << 2; long long sum[M], L[M], R[M]; int n, q, Rev[30], Swap[30]; inline void up(int x) { sum[x] = sum[(x << 1)] + sum[(x << 1 | 1)]; return; } inline void build(int x, int l, int r) { L[x] = l; R[x] = r; if (l == r)...
16
#include <bits/stdc++.h> using namespace std; int A[1000005]; int B[1000005]; int LD[2000005]; int LI[2000005]; int main() { int n, l, t; cin >> n >> l >> t; for (int i = (0); i < (n); i++) scanf("%d", &A[i]); for (int i = (0); i < (n); i++) B[i] = l - A[i]; for (int i = (0); i < (n); i++) LD[i] = A[i]; for...
12
#include <bits/stdc++.h> using namespace std; struct node { int u, d; } cards[100010]; int main() { map<int, int> totnum; map<int, int> upside; map<int, int> downside; int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &cards[i].u, &cards[i].d); if (cards[i].u != cards[i].d) { ...
7