solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double PI = acos(-1.0); const int inf = 0x3f3f3f3f; template <class T> void read(T& num) { char CH; bool F = false; for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar()) ; for (num = 0; CH >= '0' && CH <= ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 26; int road[maxn][maxn]; int main() { string a, b; int n; cin >> a >> b >> n; if (a.size() != b.size()) { cout << -1; return 0; } for (int i = 0; i < maxn; i++) { fill(road[i], road[i] + maxn, 10010); } for (int i = 0; i < n; i+...
5
#include <bits/stdc++.h> using namespace std; int rem(const string& s, int mod) { long long res = 0; for (int i = 0; i < (int)(s).size(); ++i) { res *= 10; res += (s[i] - '0'); if (res >= mod) { res %= mod; } } return res; } int fi(int n) { int ans = n; for (int i = 2; i * i <= n; ++i)...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; cout << (n - 1) * n * (n + 1) / 3 << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; const double PI = acos(-1.0); int N, M; pair<int, int> tmp[500]; int x[500][2], x2[500][2]; double at2r[500][500]; double at2b[500][500]; int CID; bool ccw(int xx, int yy, int ia, int ib) { long long xa, ya, xb, yb; if...
9
#include <bits/stdc++.h> using namespace std; int l, b, f; int a[105], c[105]; int sum[101205 << 2], lsum[101205 << 2], rsum[101205 << 2], visit[101205 << 2]; void pushup(int l, int r, int node) { int len = r - l + 1; lsum[node] = lsum[node << 1]; rsum[node] = rsum[node << 1 | 1]; if (lsum[node] == len - (len >...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long int rvsr(long long int n) { string s = to_string(n); reverse(s.begin(), s.end()); stringstream obj(s); obj >> n; return n; } long long int power(long long int x, long long int y) { long long int res = 1; x = x; while (y > 0...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) { cin >> arr[i]; } long long i = 0, j = 0; vector<long long> vec; while (i < n) { long long ans = 1; j = i; while (j < n) { if (j != 0 && arr[j] == ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, i, a, b, j, k; cin >> n >> m; vector<int> v[n + 1]; for (i = 1; i <= m; i++) { cin >> a >> b; v[a].push_back(b); } for (i = 1; i <= n; i++) { long long ans = 0; for (j = ...
4
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 10; const double eps = 1e-9; const int inf = 1e9; map<pair<int, int>, int> link2; map<int, int> link; vector<int> adj[mx]; int n, len = 0; bool ok = 0, vis[mx]; map<int, int> XX; void dfs(int u) { len++; vis[u] = 1; if (len == n + 1) ok = 1; if ...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; using vvi = vector<vi>; using vii = vector<pii>; string s; bool read() { if (!(cin >> s)) { return 0; } return 1; } const int mod = (int)1e9 + 7; void add(int &a, int...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> v(n); long long i; for (i = 0; i < n; i++) cin >> v[i]; reverse(v.begin(), v.end()...
0
#include <bits/stdc++.h> using namespace std; long long pow2(long long base, long long p) { long long ans = 1; while (p > 0) { if (p & 1) ans = (((ans) % 1000000007) * ((base) % 1000000007)) % 1000000007; base = (((base) % 1000000007) * ((base) % 1000000007)) % 1000000007; p = p / 2; } return ...
5
#include <bits/stdc++.h> using namespace std; bitset<300000000> s; int l, r; int main() { ios::sync_with_stdio(false); cin >> l >> r; for (int i = 3; i * i <= r; i += 2) { if (!s[i]) for (long long j = (long long)i * i; j <= r; j += 2 * i) { s[j] = 1; } } int ans = (l <= 2) && (r >= 2)...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x; cin >> n; long long int s = 0; for (long long int i = 0; i < n; ++i) { cin >> x; if (x < 0) x *= -1; s += x; } cout << s << "\n"; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long INFL = 2e18; const int N = 1e6, M = N; int n, m, G = 0; vector<int> adj[N + 5]; int gr[N + 5], p[N + 5]; vector<int> pth[N + 5]; vector<int> PTH_myEndlessLove; int Pos[N + 5]; void dfs(int u) { gr[u] = G; PTH_myEndlessLove.push_back(...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> v(n); int arr[n + 1]; for (int i = 0; i < n; i++) { cin >> v[i]; arr[v[i]] = i; } vector<pair<int, int>> p; int l = 0, r = n - 1; for (int pp = 1; pp <= n; ...
4
#include <bits/stdc++.h> const int maxBufSize = (10000000); using namespace std; int n; string str[105]; int main() { int i, j, a, b, c; str[0] = "zero"; str[1] = "one"; str[2] = "two"; str[3] = "three"; str[4] = "four"; str[5] = "five"; str[6] = "six"; str[7] = "seven"; str[8] = "eight"; str[9] =...
1
#include <bits/stdc++.h> using namespace std; void boost() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } int main() { boost(); int n; cin >> n; long a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } vector<long> c(n); for (...
3
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 100; const long double eps = 1e-12; const long double pi = acos(-1.0L); int myrand() { return rand(); } unsigned rdtsc() { unsigned ans; asm("rdtsc" : "=a"(ans)); return ans; } int rnd(int x) { return myrand() % x; } void precalc() {} int n,...
7
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; int n, k, a[500005], dig[500005], p[50]; const int M = 1000033; struct HashMap { int cnt = 0, head[M], to[M], nxt[M]; long long v[M]; bool count(int f) { int x = f % M; for (int i = head[x]; i; i = nxt[i]) { if (to[i] == f) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { int x, y; scanf("%d%d", &x, &y); if (x < y) { printf("-1\n"); return 0; } double t1 = (x - y) * 1.0 / 2; double t2 = (x + y) * 1.0 / 2; int k1 = floor(t1 / y); int k2 = floor(t2 / y); t1 /= k1; t2 /= k2; if (t1 < t2) printf("%....
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5; int n, m, upd, c[MAXN + 5], t[MAXN + 5], has[MAXN + 5], cnt[MAXN + 5], ans[MAXN + 5]; vector<pair<int, int> > adj[MAXN + 5]; vector<pair<int, int> > q[MAXN + 5]; void dfsw(int v, int par) { for (int i = 0; i < ((int)((adj[v]).size())); i++) i...
8
#include <bits/stdc++.h> using namespace std; const int inf = 1e9, mod = 1e9 + 7; const int N = 1e5 + 5; int S = 1, t1, t2, n, m, k, x, y, z, size[N], root[N], h[N], sum[N]; long long res[N]; vector<pair<pair<int, int>, pair<int, int> > > edges; vector<pair<int, int> > v[N]; int findset(int x) { return root[x] = (roo...
7
#include <bits/stdc++.h> using namespace std; const long long Maxn3 = 1e3 + 10; const long long Maxn4 = 1e4 + 10; const long long Maxn5 = 1e5 + 10; const long long Maxn6 = 1e6 + 10; const long long Maxn7 = 1e7 + 10; const long long Maxn8 = 1e8 + 10; const long long Maxn9 = 1e9 + 10; const long long Maxn18 = 1e18 + 10; ...
1
#include <bits/stdc++.h> using namespace std; const long long M = 1005, X = 143, MOD = 12345; long long n, m, mul[M], t[32], cc, ansi, flag; bool mark[X], mm[32][X]; char c[M]; vector<long long> v, w[X], z; map<vector<long long>, long long> mapi; struct matrix { long long a[X][X]; matrix() { for (int i = 1; i <...
8
#include <bits/stdc++.h> using namespace std; int main() { int k, b, c; cin >> k >> b >> c; if (c > b) swap(b, c); if (c / k == 0 & b % k != 0) printf("%d\n", -1); else printf("%d\n", b / k + c / k); return 0; }
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; long long dp[maxn][1 << 7]; int s[maxn][7]; int a[maxn], id[maxn]; bool cmp(int x, int y) { return a[x] > a[y]; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, p, K; cin >> n >> p >> K; for (int i = 1; i <= n; i++) id[i] = ...
7
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e18 + 10; long long n, a, b; long long x[1000100], f[1000100], g[1000100]; vector<long long> prime; bool isprime[1000100]; set<long long> s; void getPrime() { int i, j; for (i = 0; i < 1000100; i++) isprime[i] = true; isprime[0] = isprime[1] = 0...
7
#include <bits/stdc++.h> const int MXN = 1e6 + 1; const int INF = 1e9 + 7; const int N = 1e3 + 1; using namespace std; long long int a, b, s, x, y; int main() { ios_base ::sync_with_stdio(0); cin >> a >> b >> s; if (abs(a) + abs(b) == s) { cout << "Yes"; return 0; } if (abs(a) + abs(b) > s) { cout...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, r; scanf("%d%d", &n, &r); vector<double> c(1 << n); double s = 0.0; for (int i = 0; i < (1 << n); i++) { scanf("%lf", &c[i]); s += c[i]; } double p = pow(2.0, n); printf("%.7lf\n", s / p); while (r--) { int x; double g; ...
8
#include <bits/stdc++.h> using namespace std; typedef struct point { int x, y; point(){}; point(int a, int b) { x = a; y = b; } } point; int X[] = {0, 1, -1, 0, -1, 1, -1, 1}; int Y[] = {1, 0, 0, -1, -1, 1, 1, -1}; string inttostr(int num) { string res; stringstream s; s << num; s >> res; retu...
2
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e6 + 5; long long n, m, i, j, k = 0, cou = 0, F, o, z; string s; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); char c; cin >> n; for (i = 0; i < n; i++) { cin >> c; if (c == '1') { o++; } else { z++...
0
#include <bits/stdc++.h> using namespace std; const int N = 10005; const int inf = 1e9; const int mod = 1e9; const int base = 1000 * 1000 * 1000; struct tp { pair<int, string> first, second, th; }; int n, m, a, b; string s; tp p[N]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> s >> a >> b...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n, stick[maxn], ans[4], tmp[maxn]; int main() { int t, i, j, k, cnt = 0, flag, a, b; double aans, tt; cin >> t; while (t--) { cin >> n; flag = cnt = 0; aans = 1e18; for (i = 1; i <= n; i++) scanf("%d", tmp + i); sor...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int c[n + 1], top[4] = {0}; memset(top, 0, sizeof top); bool avail[n + 1]; vector<pair<long long int, int> > a[4]; for (int i = (0); i < (int)n; i++) { cin >> c[i]; avail[i] = 1; } int g; for (int...
3
#include <bits/stdc++.h> const long long maxn = 1005; long long n, m, base, k, ansx, ansy, anss; long long a[maxn][maxn], line[maxn][maxn], sum1[maxn << 1][maxn], sum2[maxn << 1][maxn]; long long lft[maxn][maxn], rgt[maxn][maxn], ans[maxn][maxn]; inline long long max(long long a, long long b) { return a > b ? a : b...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; vector<long long> d(200010, 0); int main() { long long n; cin >> n; long long ans = n; for (long long i = 0; i < n - 1; i++) { long long u, v; cin >> u >> v; ans = (ans * (++d[u]) % mod * (++d[v]) % mod) % mod; } cout...
5
#include <bits/stdc++.h> using namespace std; char s[200000], t[200000]; int poz1[200000], poz2[200000], n1, n2, j; int main() { cin >> (s + 1); cin >> (t + 1); n1 = strlen(s + 1), n2 = strlen(t + 1); for (int i = 1, j = 1; i <= n2; ++j) if (s[j] == t[i]) poz1[i] = j, ++i; for (int i = n2, j = n1; i >= 1;...
4
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); long long int x, y; cin >> x >> y; vector<pair<char, long long int> > v; while (x > 1 or y > 1) { ...
8
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive...
11
#include <bits/stdc++.h> using namespace std; int num[101000]; int main() { int n; scanf("%d", &n); int sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &num[i]); sum += num[i]; } sort(num, num + n); int k = 0; for (int i = 0; i < n; i++) { k += num[i]; if (k > (sum + 1) / 2) { k...
1
#include <bits/stdc++.h> int main(void) { int n = 500; printf("%d\n", n); printf("0 500000\n"); int x = 300000; for (int r = n - 2; r >= 1; r--) { x += r; printf("%d %d\n", x, r); x += r; } printf("1000000 1000000\n"); return 0; }
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16000000") using namespace std; const int Maxn = 100005; const long long Inf = 1000000000000000000ll; int n, m, q; int c[Maxn]; vector<int> neigh[Maxn]; vector<int> inCity[Maxn]; int cur, lef[Maxn], rig[Maxn], cnt[Maxn]; int my[Maxn], L[Maxn], P[Maxn], ind[Maxn];...
11
#include <bits/stdc++.h> using namespace std; int dig(int m, int n) { set<int> a; while (m) { a.insert(m % 10); m = m / 10; } while (n) { int x = n % 10; if (a.find(x) != a.end()) return 1; n = n / 10; } return 0; } int main() { int n, ans = 0; cin >> n; for (int i = 1; i * i <= n;...
2
#include <bits/stdc++.h> using namespace std; int n, k, num, color = 1; vector<int> ans(5e3 + 3); map<int, vector<int> > m; int main(void) { ios ::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> num; m[num].emplace_back(i); } for (auto p : m) { if (p.second.s...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9; const int N = 1e5 + 5; inline long long pow_mod(long long x, long long n) { long long r = 1; while (n) { if (n & 1) r = (r * x) % MOD; x = (x * x) % MOD; n >>= 1; } return r; } inline long long pow_(long long...
3
#include <bits/stdc++.h> using namespace std; const long long N = 2e5; const long long M = 1e4; const long long inf = 2e18; inline long long read() { long long s = 0; register bool neg = 0; register char c = getchar(); for (; c < '0' || c > '9'; c = getchar()) neg |= (c == '-'); for (; c >= '0' && c <= '9'; s...
7
#include <bits/stdc++.h> using namespace std; long long n, s; bool check(long long x) { long long y = x; long long dem = 0; while (x != 0) { dem += x % 10; x /= 10; } return (y - dem >= s); } int main() { cin >> n >> s; long long l = 0, r = n + 1; while (r - l > 1) { long long mid = (r + l) ...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int ar[n]; for (int i = 0; i < n; i++) cin >> ar[i]; sort(ar, ar + n); for (int i = n - 1; i >= 0; i--) cout << ar[i] << " "; cout << "\n"; } }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int mn = 5e3 + 10; long long po(long long a, long long b = mod - 2) { long long ans = 1; for (; b; b >>= 1, a *= a, a %= mod) if (b & 1) ans *= a, ans %= mod; return ans; } long long fact[mn]; long long ch(long long a, long lon...
8
#include <bits/stdc++.h> const int maxn = 500100; const double eps = 0.0000000001; const double inf = 99999999999; double dis(double x1, double y1, double x2, double y2) { return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } using namespace std; int main() { double x1, y1, x2, y2, vmax, t, vx, vy, wx, wy; ...
6
#include <bits/stdc++.h> using namespace std; const int MaxN = int(2e6) + 256; const int INF = int(1e9); const int mod = (int)(1e9) + 7; const double pi = 3.1415926535897932384626433832795; long long n, m, ans, a[MaxN], d[MaxN][3]; int used[MaxN][3], timer; long long rec(int x, int q) { if (x > n || x <= 0) { ret...
4
#include <bits/stdc++.h> using namespace std; int n, k; long long s, t, g[200007], c, v; pair<long long, long long> car[200007]; int check(int x) { long long sum = 0, dis = 0, cur = 0, val = car[x].first; for (int i = 1; i <= k + 1; i++) { long long pl = g[i]; if (i == 1) dis = pl - 0; else ...
4
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 29; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return n & two(b); } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b) ...
6
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 3e5 + 10; long long mod; int n, m; int a[maxn]; int ans[maxn]; vector<int> v[maxn]; char s[maxn]; int main() { cin >> (s + 1); cout << "3" << endl; cout << "L" << " " << "2" << endl; cout << "R" << " ...
3
#include <bits/stdc++.h> using namespace std; int o[10], o2[10]; int main() { string a; cin >> a; for (int i = (0); i <= (((int)((a).size())) - 1); i++) o[a[i] - '0']++; int mx = -1, ii = 0; for (int i = (0); i <= (9); i++) o2[i] = o[i]; for (int i = (1); i <= (5); i++) if (o[i] && o2[10 - i]) { o...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 4; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ; cin >> s; long long n = s.size(); long long sub = 0; for (int k = 1; k <= 8; k++) { for (int i = 0; i + k <= n; i++) { bool fla...
5
#include <bits/stdc++.h> int palindrome(char checkstring1[11], int length); int main() { int i, flag = 0, j, k, r, l; char string[11]; char string1[12]; scanf("%s", string); for (i = 0; i <= strlen(string); i++) { for (j = 0; j <= 25; j++) { string1[i] = 'a' + j; l = 0; for (k = 0; k < s...
1
#include <bits/stdc++.h> using namespace std; char s1[100005], s2[100005]; int main() { int a = 0, b = 0; gets(s1); gets(s2); int l = strlen(s1); for (int i = 0; i < l; i++) { if (s1[i] == '4' && s2[i] == '7') a++; if (s1[i] == '7' && s2[i] == '4') b++; } printf("%d\n", a > b ? a : b); return 0;...
2
#include <bits/stdc++.h> using namespace std; template <class T> using v2d = vector<vector<T> >; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } mt19937 rng(chrono::system_clock::now().time_since_epoch(...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000; int n, m, tot, sum, big, a[MAXN][MAXN]; bool judge() { bool res = true; for (int i = 0; i < (n / 2); i++) for (int j = 0; j < (m); j++) if (a[i][j] != a[n - i - 1][j]) res = false; return res; } int main() { cin >> n >> m; for (int...
2
#include <bits/stdc++.h> using namespace std; int n, k, maxb, t; int f[101001]; int l; int a[101011]; void init() { cin >> k >> n >> maxb >> t; } void force() { for (int T = 1; T <= k; T++) { for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < t; i++) { for (int j = 1; j <= n; j++) a[i * n + j...
9
#include <bits/stdc++.h> using namespace std; struct data { int x, y, z; }; data num[500003]; int tree[4 * 500003], n, numy[500003]; bool cmp(data a, data b) { return a.x > b.x; } int query(int node, int l, int r, int ql, int qr) { if (ql == l && qr == r) return tree[node]; int mid = (l + r) >> 1; if (qr <= mid...
8
#include <bits/stdc++.h> using namespace std; long long dp[50][2]; long long second, X; void give(int n, long long c, long long x, long long s) { if (x > 1) x = 1; if (s > 1) s = 1; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { if ((i ^ j) == x and (c + i + j) % 2 == s) { dp[n + 1]...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; int stk[50005], top = 0; struct Point { long long x, y; Point() {} Point(long long _x, long long _y) { x = _x; y = _y; } Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); } Point operator+(const Point &b)...
9
#include <bits/stdc++.h> using namespace std; long long sum[500101]; long long ans = 0, last = 0; int main() { int a, b, c, d; cin >> a >> b >> c >> d; for (int i = 1; i <= d; ++i) sum[i] = sum[i - 1] + i; long long y; for (int z = c; z <= d; ++z) { if (b + c <= z) break; int g = z - b + 1; int x ...
5
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return (b == 0) ? abs(a) : gcd(b, a % b); } template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> inline T mod(T a, T b) { a %= b; if (a < 0) a += b; return a; } template <typename ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n; cin >> n; string s = "ROYGBIV"; long long x = n - 7; string st = "GBIV"; long long i = 0; while (i < x) { s += st[(i % 4)]; i++; } cout << s << end...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int n, k; cin >> n >> k; int max_h = -2e9; for (int i = 0; i < n; ++i) { int f, t; cin >> f >> t; max_h = max(max_h, f - max(0, t - k)); } cout << max_h << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int ans[200005 << 2], cnt, n, m, rt; vector<int> g[200005]; bool v[200005], c[200005]; void add(int x) { c[ans[++cnt] = x] ^= 1; } bool ok() { for (int i = 1; i <= n; ++i) if (c[i]) return 0; return 1; } void dfs(int u) { add(u), v[u] = 1; for (typeof(g[u].begin...
7
#include <bits/stdc++.h> using namespace std; const int N = 1010; bool st[N]; int a[N]; int n; vector<int> ans; int mex() { memset(st, false, sizeof st); for (int i = 0; i < n; i++) st[a[i]] = true; int cur = 0; while (st[cur]) cur++; return cur; } bool check() { for (int i = 0; i < n; i++) if (a[i] != ...
5
#include <bits/stdc++.h> using namespace std; int mask[2][60][60]; int dp[60][60]; int graph[30][30]; void func(int id, int N, string s) { int d, i, j, k, a, b; for (d = 1; d <= N; d++) for ((i) = 0; (i) < (int)(N - d + 1); (i)++) { j = i + d; if (d == 1) { mask[id][i][j] = (1 << (s[i] - 'a'...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >>t; while (t>0){ t--; int n; cin >> n; int nos[2*n]; for(int i =0;i<(2*n);i++){ cin >> nos[i]; } sort(nos,nos+2*n); for (int i =0;i<n;i++){ cout << nos[i] << " " << nos[2*n - i - 1] << " ...
0
#include <bits/stdc++.h> using namespace std; int n; char s[2020]; bool mp[8080][8080], mp1[8080][8080]; long long ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { char s = getchar(); int cur; for (int j = 1; j <= n / 4; ++j) { s = getchar(); cur = s >= '0' && s <= '9' ? s -...
13
#include <bits/stdc++.h> int n; long long s, f[30]; long long inv(long long x) { long long base = 1000000007 - 2, ans = 1; while (base) { if (base & 1) ans = ans * x % 1000000007; x = x * x % 1000000007; base >>= 1; } return ans; } long long C(long long x, long long k) { if (x < k) return 0; if ...
7
#include <bits/stdc++.h> using namespace std; void sep(string SS = "BLOCK") { cout << "-------------" << SS << "-----------------\n"; } template <typename T> void debugv(vector<T> arr) { for (auto t : arr) cout << t << " "; cout << "\n"; } template <typename T> void debugarr(T arr, int n) { for (int i = 0; i < ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; if (n < 4) cout << -1 << endl; else { int k = n / 4; for (int i = 0; i < k; i++) { cout << i *...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (i & 1) cout << -(abs(a[i])) << ' '; else cout << abs(a[i]) << ' ';...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9; const int N = 2e5 + 4; long long powmod(long long a, long long b, long long mod) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; } return res % MOD; } in...
4
#include <bits/stdc++.h> using namespace std; int main() { int a, b, r; int c; cin >> a >> b >> r; c = r * 2; if (b < c || a < c) cout << "Second" << endl; else cout << "First" << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int w = 0, b = 0, total; char buf; for (int i = 0; i < 64; i++) { total = 0; cin >> buf; if (!(buf == '.')) { if (isalpha(buf)) { if (buf == 'q' || buf == 'Q') total += 9; else if (buf == 'r' || buf == 'R') ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long i, k, j, l, n, m, t; t = 1; while (t--) { string s; cin >> s; cout << (s.size() + 1) * 25 + 1; } return 0; }
0
#include <bits/stdc++.h> using namespace std; long long infi = 1e18 + 10; long long MOD = 1e9 + 7; const long long N = 1e6 + 10; const long long M = 998244353; long long dx[] = {1, 0, -1, 0}; long long dy[] = {0, 1, 0, -1}; void init_code() {} long long binexp(long long a, long long b, long long p) { a %= p; long l...
0
#include <bits/stdc++.h> using namespace std; int read() { char ch = getchar(); int x = 0, flag = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; return x * flag; } void write(int x) { if (x < 0) putchar('-'), x = -x; if (x >...
11
#include <bits/stdc++.h> using namespace std; int last[100005]; int main() { int n, x[100005], y[100005]; cin >> n; for (int i = 1; i <= n; i++) { scanf("%d %d", &x[i], &y[i]); int cnt = 0; if (y[i] == 0) { for (int j = 1; j <= sqrt(x[i]); j++) { if (x[i] % j == 0) { last[j] = ...
5
#include <bits/stdc++.h> using namespace std; double p[200]; double s[200]; double ans[200][200]; int main() { int n, i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%lf", &p[i]); sort(p, p + n); memset(ans, 0, sizeof(ans)); double r = 0; for (i = 0; i < n; i++) { s[i] = 1; for (j = i - 1...
5
#include <bits/stdc++.h> using namespace std; const int M = 310; const int N = 2000 * 1000 + 13; int n, m, q; int a[M][M]; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; bool in(int first, int second) { return 0 <= first && first < n && 0 <= second && second < m; } int p[M * M], rk[M * M]; int getp(int v) { retu...
10
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k = 0, n; string a; cin >> n; for (int m = 0; m < n; m++) { cin >> a; cin >> i >> j; if (i >= 2400 && j > i) k++; } if (k >= 1) cout << "YES\n"; else cout << "NO\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, m; char grid[50][50]; int main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, c, d, n = 0, m = 0; cin >> a >> b >> c >> d; a--; b--; c--; d--; for (int i = 0; i < 25; i++) for (int j = 0; j < 25; j++) grid[i][j] = 'A'; for (int i = 0; ...
5
#include <bits/stdc++.h> using namespace std; vector<long long int> v; bool vi[1002][1002]; char te[100006]; map<pair<long long int, long long int>, long long int> ma; int main() { long long int n; cin >> te; long long int l = strlen(te); for (long long int i = 0; i < l; i++) v.push_back(te[i] - '0'); long lo...
2
#include <bits/stdc++.h> using namespace std; bool f(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; pair<int, int> a[n]; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y...
7
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") const int maxn = 100010; int n, m, a[maxn]; void print(int x) { if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i...
11
#include <bits/stdc++.h> int main() { char a[5][2]; char b[2], flag = 0; for (int i = 0; i < 2; i++) { scanf("%[^\n]c", &b[i]); } for (int i = 0; i < 5; i++) { for (int j = 0; j < 2; j++) { scanf(" %c", &a[i][j]); } } for (int i = 0; i < 5; i++) { if (a[i][0] == b[0] || a[i][1] == b[...
0
#include <bits/stdc++.h> const long long M = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; for (long long i = 0; i < t; i++) { string s; cin >> s; for (long long j = 0; j < 26; j++) { for (long long k = 0; k < s.length(); k...
1
#include <bits/stdc++.h> using namespace std; int n, m = 0, ans = 0; int a[30], A[1 << 20], B[1 << 20]; void deal(const int z, const int x, const int y) { if (z > m) return; int w = x ^ y; deal(z + 1, x, w); for (int i = 1; i <= a[z]; ++i) A[++ans] = x, B[ans] = y; deal(z + 1, w, y); } void Gans(const int z) ...
8
#include <bits/stdc++.h> using namespace std; int main() { int arr[10] = {0}; int k; cin >> k; k *= 2; char s; for (int i = 0; i < 16 && cin >> s; i++) if (s != '.') arr[s - '0']++; for (int i = 0; i < 10; i++) if (arr[i] > k) { cout << "NO"; return 0; } cout << "YES"; return 0...
0
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf("%d", &n); int ans = 0; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); int j = 1; while (x >= j) x -= j, j++; j--; ans ^= j; } if (ans == 0) printf("YES"); else printf("NO"); return 0; }
6
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int mod = 1e9 + 7; int n, m; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'...
8