solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> inline void read(int &x) { scanf("%d", &x); } inline void read(long long &x) { scanf("%I64d", &x); } inline void read(double &x) { scanf("%lf", &x); } inline void read(long double &x) { double tmp; read(tmp); x = tmp; } template <class T> inline void read(T *a, int n) { for (int i = (0)...
5
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const int NN = 100000; long long res; int a, i, d, M, aktPos, fir, n, j; vector<int> vec[NN + 5]; int w[3 * NN]; void insert(int v, int b) { int s = M + v; while (s) { w[s] += b; s /= 2; } } int query(int a, int b) { int va = M + ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100009; const double eps = 1e-14; struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} } sp, ep, e[maxn], v[maxn], sp2, ep2; double l[maxn], r[maxn]; inline int dcmp(double x) { return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1); ...
15
#include <bits/stdc++.h> using namespace std; char s[1000005]; int main() { scanf("%s", s); int n = strlen(s); int mn = 28; for (int i = 0; i < n; i++) { if (s[i] - 'a' > mn) printf("Ann\n"); else printf("Mike\n"); mn = min(mn, s[i] - 'a'); } return 0; }
5
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> construct(int st, vector<int> d) { if (d.empty()) return vector<pair<int, int>>(); vector<pair<int, int>> res; for (int i = 0; i < d[0]; i++) { for (int j = st + i + 1; j <= st + d.back(); j++) { res.push_back({st + i, j}); } } ...
17
#include <bits/stdc++.h> using namespace std; int break_point() { char c; while ((c = getchar()) != '\n') ; return 0; } template <typename T> void read_integer(T &r) { bool sign = 0; r = 0; char c; while (1) { c = getchar(); if (c == '-') { sign = 1; break; } if (c != ' ' &...
13
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } const int maxn = 100010; char s[maxn]; set<int> S[2]; void solve() { sc...
19
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().cou...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; const int mod = 1e9 + 7; double eps = 1e-8; long long a[maxn], b[maxn]; long long quick_power(long long a, long long n) { long long sum = 1; while (n) { if (n & 1) sum = sum * a % mod; a = a * a % mod; n = n >> 1; } return sum; ...
11
#include <bits/stdc++.h> long double PI = acos(-1.0); const int maxn = 1e6 + 10; int t[maxn][2]; using namespace std; void solve() { int n; cin >> n; int count = 0; double temp; for (long long int i = 1; i < n; i++) { for (long long int j = i; i * i + j * j <= n * n; j++) { temp = i * i + j * j; ...
4
#include <bits/stdc++.h> const int mod = 1e9 + 7; const int inf = 1039074182; const long long llinf = 1LL * inf * inf; using namespace std; template <typename T1, typename T2> inline void chmin(T1 &x, T2 b) { if (b < x) x = b; } template <typename T1, typename T2> inline void chmax(T1 &x, T2 b) { if (b > x) x = b; ...
17
#include <bits/stdc++.h> int eight(int a) { for (;;) { if ((a % 10 == 8) || (a % 10 == -8) || (a == 8)) return 1; a = a / 10; if (a == 0) return 0; } return 0; } int main() { int a, b, t; scanf("%d", &a); t = a; if (a > -8 && a <= 1) b = 8 - a; else { for (;;) { if (eight(a++) ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, d, m, x, y; cin >> n >> d; cin >> m; for (int i = 0; i < m; ++i) { cin >> x >> y; if (x - y <= (d) && x - y >= (-d) && x + y <= n * 2 - d && x + y >= d) { cout << "YES\n"; } else { cout << "NO\n"; } } }
3
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int maxn = 50005; const int mod = 100000000; long long n; long long a[20]; void init() { a[0] = 1; for (int i = 1; i < 16; i++) a[i] = a[i - 1] * 10 + 1; } long long dfs(long long num, int d) { if (d == 0) return num; int p1 = num / a[d]; ...
10
#include <bits/stdc++.h> using namespace std; int n, m; int inf = 1e9 + 10; const int maxn = 5e5 + 10; vector<int> adj[maxn], in[maxn], out[maxn]; vector<int> top; vector<pair<int, int> > E; int a[maxn], b[maxn], c[maxn], t[maxn]; int cmp[maxn]; bool mark[maxn]; inline bool Cmp(int a, int b) { return c[a] < c[b]; } inl...
23
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long s; s = (12 + 6 * (n - 1)) * n / 2; cout << s + 1; }
3
#include <bits/stdc++.h> using namespace std; vector<int> v[100500]; int was[100500], r[100500]; void f(int x, int p) { r[x] = p; was[x] = 1; for (int i = 0; i < v[x].size(); i++) { if (was[v[x][i]] == 0) { if (p == 0) f(v[x][i], 1); else f(v[x][i], 0); } } } int main() { i...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; string a; cin >> a; int l = a.length(); int cnt = 0, ans = 0, i; for (i = l - 1; i >= 0; i--) { if (a[i] == '0') { if (cnt == 0) ans++; else { a...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 504; const int maxq = 300005; int t, n, m, q, r1, r2, c1, c2, sum; char board[maxn][maxn]; bool actv_board[maxn][maxn]; int sum_pref[maxn][maxn]; queue<pair<int, int> > actv_spts; int result[maxq]; int query[maxq][4]; bool ext(pair<int, int> pos, int tsz) {...
17
#include <bits/stdc++.h> #pragma GCC optimize("O3") const long long mod1 = 998244353; const long long mod2 = 1000000007; long long pow(int a, int b) { if (b == 0 || a == 1) return 1; if (b % 2 == 0) { long long k = pow(a, b / 2); return (k * k); } else { long long k = pow(a, b / 2); return k * k *...
10
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const long long INF = 0x3f3f3f3f; const long long modn = 1e9; const long long N = 1e5 + 5; void solve() { long long n; cin >> n; getchar(); string s; cin >> s; long long idx = -1; for (long long i = 0; i < s.length(); i++) { i...
7
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T a) { return a < 0 ? (-a) : a; } template <typename T> inline T sqr(T x) { return x * x; } int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); for (int i = 0; i < (n); ++i) { cin >> a[i]; } for (int i = 0; i < ...
10
#include <bits/stdc++.h> using namespace std; long long cnt[4]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; int a = -1, r = 1e9; for (int k = 1; k <= n; ++k) { int ans = k + (n + k - 1) / k; if (ans < r) { r = ans; a = k; } } int k = a, e = n, cnt = 0; for (in...
8
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f; int cnt; string s, s1, s2, s3, s4, s5; long double d1, d2, d3, d4, d5; int main() { ; ios_base::sync_with_stdio(0); cin >> a >> b >> c; cnt = (2 * (a + b) - 8 * (c - 1) - 4) * c; cout << cnt; }
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, a, b, c, pos; long long ans, ANS, sum, now; struct Node { long long h, d; bool operator<(const Node &cur) const { return h - d > cur.h - cur.d; } } x[N]; int main() { scanf("%d%d%d", &n, &a, &b); for (int i = 1; i <= n; i++) scanf("%ll...
13
#include <bits/stdc++.h> using namespace std; long long inf = 1e18 + 42; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; long long j = (n - 1) / 3 + 1; long long a = 1, t = 1, l = 0; while (j > t) { j -= t; ...
14
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MOD = 1e9 + 7; const int N = 0; int n; string s; char spe; vector<string> a[15]; int main() { cin >> n; int total = 0; for (auto i = 1; i <= n; i++) { cin >> s; int m = s.length(); a[m].push_back(s); total += m; } for...
12
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-6; const double PI = acos(-1); bool chkmax(long long& a, long long b) { return a < b ? a = b, true : false; } bool chkmax(int& a, int ...
16
#include <bits/stdc++.h> using namespace std; long long M; long long solve(long long A, long long B) { if (B >= M) return 0; long long S = A + B; if (S <= A) return -1; long long x = (B + B - A - 1) / B; if (A + x * B == B) x++; return solve(B, A + x * B) + x; } int main() { long long A, B; cin >> A >> ...
8
#include <bits/stdc++.h> using namespace std; long long a[31]; int b[1000000], ans, n, m, d; int main() { scanf("%d%d", &n, &m); while (n--) { scanf("%d", &d); for (int j = 29; j >= 0; j--) if (d >= (1 << j)) { a[j]++; d -= (1 << j); } } for (int i = 0; i < 30; i++) a[i] *= (...
11
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 200009; const long long int inf = 100000000000000ll; const long long int mod = 1e8 + 7; struct edge { int u, v, w; bool operator<(const edge& b) const { return w < b.w; } }; int n, m, s, t; vector<vector<pair<long long int, long long int> > > g, gt; vec...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 5010; const int INF = 1e9; int n, dp[MAXN][MAXN]; vector<int> A; int solve(int l, int r) { if (r <= l) return 0; if (dp[l][r] < INF) return dp[l][r]; if (A[l] == A[r]) return dp[l][r] = solve(l + 1, r - 1) + 1; else return dp[l][r] = min(sol...
11
#include <bits/stdc++.h> using namespace std; string s1; string s2; long long ans = 0; long long check(long long x, long long y, long long z) { if (x < 0 || x > s1.size() - 1 || y < 0 || y > s1.size() - 1 || z < 0 || z > s1.size() - 1) { return -1; } if (s2[y] == '0' && s2[z] == '0') { s2[y] = 'X'; ...
7
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3; long long sum, a[2000001], d[100], n, m, k, last[200]; string s; int main() { cin >> m >> k; cin >> s; n = s.length(); fill(last, last + k, -1); for (int i = 0; i < n; i++) { a[i] = s[i] - 'a'; las...
14
#include <bits/stdc++.h> using namespace std; int H[100000][5], V[100000][5]; long long dp[32]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i < m; ++i) for (int j = 0; j < n; ++j) cin >> H[i][j]; for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) c...
19
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, MOD = 1e9 + 7, EPS = 1e-6; const int N = 1e5 + 5; int a, b, n; vector<char> order; int main() { a++; while (1) { char c; scanf("%c ", &c); if (c == '+') a++; if (c == '-') b++; if (c == '=') break; if (c != '?') order....
10
#include <bits/stdc++.h> using namespace std; long long memo[40][80][80]; int n, k; struct cond { int a, b; string s; cond(int a, int b, string s) : a(a), b(b), s(s) {} }; vector<cond> v; bool check(int a, int b, string s) { if (s[0] == '=') return a == b; if (s[0] == '<') { if (s.length() == 2 && s[1] ==...
16
#include <bits/stdc++.h> using namespace std; int n, a[100005], b[100005], cnt; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) b[i] = a[i]; sort(b + 1, b + n + 1); cnt = 0; for (int i = 1; i <= n; ++i) cnt += (a[i] == b[i]) ? 0 : 1; if (cnt <= 2...
5
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 1; int n, q, from[N], to[N], T, seg[2][4 * N], lazy[2][4 * N]; vector<int> g[N]; void DFS(int v, int p) { from[v] = ++T; for (size_t i = 0; i < g[v].size(); ++i) if (g[v][i] != p) DFS(g[v][i], v); to[v] = T; } inline void pro(int p, int l, int ...
13
#include <bits/stdc++.h> using namespace std; double PI = (acos(-1)); long long md = 1000000007; long long pw(long long a, long long b) { long long c = 1, m = a; while (b) { if (b & 1) c = (c * m); m = (m * m); b /= 2; } return c; } long long pwmd(long long a, long long b) { long long c = 1, m = a...
16
#include <bits/stdc++.h> using namespace std; struct treap { int x, y, cnt; long long sum; treap *l, *r; }; long long getsum(treap *t) { return t ? t->sum : 0; } int getcnt(treap *t) { return t ? t->cnt : 0; } void recalc(treap *t) { if (t) { t->sum = t->x + getsum(t->l) + getsum(t->r); t->cnt = 1 + get...
21
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; const int M = 1e6; const int oo = 1e9; const int mod = 1e9 + 7; long long a[N], b[400][21], u[400], c[N]; int main() { int n; cin >> n; int Z = sqrt(n) + 1; for (int i = 0; i < n; i++) cin >> a[i]; int m; cin >> m; for (int i = 0; i < n...
12
#include <bits/stdc++.h> using namespace std; int main() { int num, i; cin >> num; for (i = 0; i < num; i++) { if (i % 2 == 0 && i != num - 1) cout << "I hate that "; else if (i % 2 == 0 && i == num - 1) cout << "I hate it"; if (i % 2 != 0 && i != num - 1) cout << "I love that "; ...
0
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(T x) { return x * x; } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, -b); return a * (b / __gcd(a, b)); } template <class T> T power(T N, T P) { return (P == 0) ? 1 : N * power(N,...
6
#include <bits/stdc++.h> using namespace std; int n; char seg[105]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> seg[i]; for (int i = 0; i < n - 4; i++) { if (seg[i] == '*') { for (int j = 1; i + 4 * j < n; j++) { if (seg[i + j] == '*' && seg[i + 2 * j] == '*' && seg[i +...
5
#include <bits/stdc++.h> using namespace std; int boss[100100], n, m, workers[100100], was[100100]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &boss[i]); boss[i]--; } int cnt = 0; while (cnt < n) { m++; for (int i = 0; i < n; i++) workers[i] = 0; for (int i = 0...
1
#include <bits/stdc++.h> using namespace std; namespace io { inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } template <class I> inline void fr(I &num) { num = 0; register ch...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; int main() { int n, n1, n2; priority_queue<int> q; scanf("%d%d%d", &n, &n1, &n2); while (n--) { int temp; scanf("%d", &temp); q.push(temp); } if (n1 < n2) { int temp = n1; n1 = n2; n2 = temp; } int tempn1 = n...
3
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5, inf = 1e9 + 7; long long n, k, i, j; long long A[N], l[N], r[N], len[N]; set<pair<long long, long long> > st; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long i, j, a, b, ans = 0, cur; cin >> n; for (i = 1; i < n...
12
#include <bits/stdc++.h> using namespace std; long long int dp1[200001], dp2[200001]; int main() { long long int r, g, h, i, j; cin >> r >> g; if (r > g) swap(r, g); h = (sqrt(1 + 8 * r + 8 * g) - 1.0) / 2; if (r == 0 || g == 0) { printf("1\n"); return 0; } dp1[0] = 1; dp1[1] = 1; long long in...
12
#include <bits/stdc++.h> using namespace std; int main() { string a; long long int i, count = 0, j; map<char, long long int> m; cin >> a; if (a.length() < 26) { cout << -1; return 0; } for (i = 0; i < 26; i++) { if (a[i] == '?') { count++; } else { m[a[i]]++; } } long l...
5
#include <bits/stdc++.h> using namespace std; int main() { long long y, k, n; cin >> y >> k >> n; long long a = (k - y % k); n -= y; if (a > n) { cout << -1 << endl; return 0; } for (; a <= n; a += k) { cout << a << ' '; } return 0; }
4
#include <bits/stdc++.h> using namespace std; const int N = (1 << 23) + 7; int n, m; vector<int> x; bool seen[N]; int v(int i, int f) { return (i << 1) | (1 & f); } int dfs(int i) { if (seen[i]) return 0; seen[i] = 1; if ((i & 1) == 0) { i >>= 1; for (int k = 0; k < n; k++) if ((i & (1 << k)) == 0) ...
17
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } long long bin_to_integer(string strin) { long long r = 1, sum = 0; for (long long i = strin.length() - 1; i >= 0; i--) { if ...
4
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; template <typename T, typename... Args> void debug(T t, Args... args) { return; } long long int power(long long int x, long long int y) { long long int ans = 1; while (y > 0) { if (y & 1) ans = (ans * x) % mod; y = y >> 1; x = ...
13
#include <bits/stdc++.h> using namespace std; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; template <typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; } template <int M...
23
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 1; const long long INF = 1e18; const long long mod = 1e9 + 7; char ch, ch1; long long n; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> ch >> ch1 >> n; if (n % 2 == 0) return cout << "undefined", 0; long ...
1
#include <bits/stdc++.h> using namespace std; int n, p[666666]; vector<int> v; void go(int x) { int dt = min(p[x], p[x + 1]); if (!dt) return; v.push_back(x); p[x] -= dt; p[x + 1] -= dt; } long long f[666666]; int g[666666]; int ss[666666], sn = 0; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i...
24
#include <bits/stdc++.h> std::vector<int> node[1024 * 2]; int ma[1024 * 2], ch[1024 * 2], tm; int l[1024 * 2], f[1024 * 2]; std::pair<int, int> poi[1024]; std::map<int, int> prer, prec; int *lr = l, *lc = l + 1024; int *fr = f, *fc = f + 1024; int dfs(int u) { f[u] = 1; for (auto v : node[u]) { if (ch[v] == tm)...
19
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point() {} Point(double _x, double _y) { x = _x; y = _y; } }; vector<double> getCf(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { double a = (x2 + x3 - x1 - x4) * (...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; n = abs(n); int ans = 0, sum = 0; while (sum < n or (sum - n) % 2 != 0) { ans++; sum += ans; } cout << ans << endl; return 0; }
8
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long tot = 1; while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') { tot = -1; c = getchar(); } long long sum = 0; while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = ...
21
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int fa[maxn][35]; long long minval[maxn][35]; long long sum[maxn][35]; void init(int n) { for (int k = 1; k < 34; k++) for (int i = 0; i < n; i++) { fa[i][k] = fa[fa[i][k - 1]][k - 1]; minval[i][k] = min(minval[i][k - 1], minval[f...
13
#include <bits/stdc++.h> using namespace std; const int M = (int)1e9 + 7; const int N = (int)1e5 + 10; const int L = 17; int sum0[N], sum1[N], sum2[N], psum0[N], psum1[N], psum2[N], par[L][N], in[N], out[N], curt, u, v, w, h[N], delta0[N], delta1[N], delta2[N], n, q; vector<pair<int, int> > adj[N]; int add(int a, i...
19
#include <bits/stdc++.h> using namespace std; char S[100010]; int N, L, R; unsigned int dp[100010 * 3]; int main() { scanf("%d%s", &N, S); dp[L = N + 2] = 1; R = L + 1; for (int i = 0; i < N; i++) { if (S[i] != '?') --L; else { dp[++R] = 0; dp[++R] = 0; for (int j = R - 1; j >= L...
21
#include <bits/stdc++.h> using namespace std; int main() { long int x, y; cin >> x >> y; x -= (y - 1); if (x % 2 == 0 && x >= 0 && !(x > 0 && y == 1) && y > 0) printf("Yes\n"); else printf("No\n"); return 0; }
5
#include <bits/stdc++.h> using namespace std; int read() { int x = 0; char c; do { c = getchar(); } while (!isdigit(c)); do { x = x * 10 + c - '0'; c = getchar(); } while (isdigit(c)); return x; } const int N = 200000 + 10; int n, m, fa[N]; vector<int> g[N]; struct E { int u, v; E(int a, i...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, m; ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; int a[1005], c[1005]; for (int i = 0; i < (n); ++i) cin >> c[i]; for (int i = 0; i < (m); ++i) cin >> a[i]; int cnt = 0, cur = 0; for (int i = 0; i < (n); ++i) { if (...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int r, c; cin >> r >> c; for (int i = 0; i < r; i++) { if (i & 1) { if (i % 4 == 1) { for (int j = 0; j < c - 1; j++) { cout << "."; } cout << "#\n"; } ...
0
#include <bits/stdc++.h> using namespace std; int tavan(int a, long long b, int md) { int ans = 1; while (b > 0) { if (b & 1) ans = (1ll * ans * a) % md; a = (1ll * a * a) % md; b /= 2; } return ans; } int main() { int q; scanf("%d", &q); while (q--) { long long k, l, r, p; scanf("%lld...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, k; int a[N]; int vis[300]; int main() { cin >> n >> k; memset(vis, -1, sizeof vis); for (int i = 0; i < n; i++) { cin >> a[i]; if (vis[a[i]] != -1) { cout << vis[a[i]] << ' '; continue; } for (int j = max(0, a[...
9
#include <bits/stdc++.h> using namespace std; int n, b, odd, even, ans; int arr[101]; void solve() { cin >> n >> b; for (int i = 0; i < n; i++) { cin >> arr[i]; } vector<int> v; ans = 0; if (arr[0] & 1) { odd = 1; even = 0; } else { odd = 0; even = 1; } n--; for (int i = 1; i < n...
4
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; const long long MOD2 = 998244353; const long long N = 5000 * 100 + 1; const long long N2 = 1000 * 1000 + 5; const long double PI = 3.14159265; const long l...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, m; string s; cin >> n >> m >> s; vector<int> a(m); for (int i = 0; i < (int)m; ++i) cin >> a[i]; vector<int> b(n + 1); int k = s.size(); for (int i = 0; i < (int)m; ++i) b[a[i] - 1]++; for (int i = 0; i < (int)m; ++i) b[a[i] - 1 + k]--;...
11
#include <bits/stdc++.h> using namespace std; struct way { int x, y; } e[200010]; struct node { int l, r, s, t, id; } q[200010]; int f[1010][1010], n, m, t; bool ans[200010]; bool cmp(node a, node b) { return a.l > b.l; } int main() { scanf("%d%d%d", &n, &m, &t); for (int i = 1; i <= m; i++) scanf("%d%d", &e[i]...
20
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int IT_MAX; const int MOD = 1000; const int INF = 1034567891; const long long LL_INF = 2234567890123456789ll; const double PI = 3.141592653589793238; bool isEqual(long double a, long double b) { return abs(a - b) <= 1E-10; } int main() { in...
17
#include <bits/stdc++.h> using namespace std; map<long long, long long> ls; long long vv[100010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, a, b; cin >> n >> a >> b; int sw = 0; if (b < a) { swap(a, b); sw = 1; } for (int i = 0; i < n; i++) { long long v; cin >>...
12
#include <bits/stdc++.h> using namespace std; struct ST { int n, h; vector<int> t, u, d; void build(int sz) { n = sz; h = sizeof(int) * 8 - __builtin_clz(n); t = vector<int>(2 * n); u = vector<int>(2 * n, 1); for (int i = n - 1; i > 0; i--) u[i] = u[i << 1] + u[i << 1 | 1]; d = vector<int>...
21
#include <bits/stdc++.h> using namespace std; int a, b; int main() { scanf("%d%d", &a, &b); for (int i = 1;; i++) { if (a < i) { printf("Vladik"); return 0; } a -= i; i++; if (b < i) { printf("Valera"); return 0; } b -= i; } return 0; }
0
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; using u64 = uint64_t; using pi64 = pair<i64, i64>; constexpr i64 MAXN = 3 * 100 * 1000 + 5LL; constexpr i64 MOD = 1000000007LL; constexpr i64 INF64 = MOD * MOD; inline i64 fix_tail(const i64 tail_len) { return (tail_len + 2) / 3; } inline i64 get_nbr(co...
9
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 5; const int mod = 1e9 + 7; int T, n, m, k, a[N]; char s[N]; vector<int> vec[N * 10]; int main() { scanf("%d", &n); scanf("%d", &k); scanf("%s", s + 1); int tot = 0, sum = 0; while (1) { bool flag = 0; tot++; for (int i = 1; i < n; ...
13
#include <bits/stdc++.h> using namespace std; int N, M, K; int i, j; void next() { cout << " " << i << " " << j; if (i % 2 == 1) { if (j == M) { i++; } else { j++; } } else { if (j == 1) { i++; } else { j--; } } } int main() { cin >> N >> M >> K; int k = 1; ...
7
#include <bits/stdc++.h> using namespace std; long long int pwr(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b & 1) { res = (res % 1000000007 * a % 1000000007) % 1000000007; } a = (a % 1000000007 * a % 1000000007) % 1000000007; b >>= 1; } return res; } int...
5
#include <bits/stdc++.h> using namespace std; void parseArray(long long* A, long long n) { for (long long K = 0; K < n; K++) { cin >> A[K]; } } long long modInverse(long long a, long long b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } long long gcd(long long a, long long b) { return b ? gcd(b, a ...
8
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 500; long long p[maxn]; vector<long long> ger[maxn]; bool vis[maxn]; bool gm[maxn]; bool dfs(long long a, bool s) { if (vis[a] && gm[a] != s) return 1; if (vis[a]) return 0; gm[a] = s; vis[a] = 1; long long v; for (long long i = 0; i...
13
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, m, t, a = 0, b = 0, d = 0; cin >> n >> m; for (i = 1; i <= 6; i++) { if (abs(n - i) < abs(m - i)) a++; else if (abs(n - i) == abs(m - i)) d++; else b++; } cout << a << " " << d << " " << b << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long a, b, c, n; cin >> a >> b >> c >> n; long long arr[3] = {a, b, c}; sort(arr, arr + 3); int d = (arr[2] - arr[1]) + (arr[2] - arr[0]); if ...
0
#include <bits/stdc++.h> using namespace std; int main() { int h1, a1, c1, h2, a2, counter = 0; cin >> h1 >> a1 >> c1 >> h2 >> a2; if (ceil((double)h2 / a1) > ceil((double)h1 / a2)) { counter = 1; while (counter * c1 <= (ceil((double)h2 / a1) + counter - 1) * a2 - h1) ++counter; } cout << counte...
4
#include <bits/stdc++.h> using namespace std; const int N = 2 * (int)1e5; vector<int> g[N]; long long n, ans; long long p[N]; long long d[N]; long long u[N]; void dfsD(int v, int prev) { d[v] = 0; p[v] = 1; for (int i = 0; i < g[v].size(); i++) { int m = g[v][i]; if (m == prev) { continue; } ...
13
#include <bits/stdc++.h> using namespace std; int n, k; int a[200009]; int main() { cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; vector<int> ans; long long now = 0; long long total = 0; int all = n; for (int i = 0; i < n; ++i) { if (total - now * (all - now - 1) * a[i] < k) { ans.push...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n, k1, k2; cin >> n >> k1 >> k2; int max1 = 0; int max2 = 0; int x; for (int j = 0; j < k1; j++) { cin >> x; if (x > max1) { max1 = x; } } for (in...
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double EPS = 1e-9; int n, s, m, k, a[1515], c[1515], cnt_m; struct Line { int l, r; void input() { scanf("%d%d", &l, &r); } bool operator<(const Line &h) const { return r < h.r; }...
17
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; vector<int> adj[MAXN]; bool vis[MAXN]; int cnt[2][20]; int arr[MAXN]; int sub[MAXN]; int pw[20]; int compSz; int n, k; long long ans; void pre() { pw[0] = 1; for (int i = 1; i < 20; ++i) { pw[i] = (pw[i - 1] << 1); } } bool bit(int x, int...
13
#include <bits/stdc++.h> using namespace std; long long int g[30] = {0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12}; long long int N; long long int usd[35000]; int main(void) { long long int i, j, k; cin >> N; long long int val = 1; long lon...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, d[N], z[N], q; vector<int> e[N]; long long a; long long C(int x) { return (long long)z[x] * (d[x] - z[x]); } int main() { scanf("%d%d", &n, &m); for (int i = 1, x, y; i <= m; i++) { scanf("%d%d", &x, &y); d[x]++; d[y]++; ...
16
#include <bits/stdc++.h> const long long T00B1G = 9223372036854775807LL; const int maskl = 5; bool mask[64][5]; template <class TEl> using TTable = std::vector<std::vector<TEl>>; template <class TEl> void spacecreator(long long first, long long second, TTable<TEl>& vec) { vec.resize(first); for (auto& sub : vec) { ...
19
#include <bits/stdc++.h> using namespace std; int q, n, k; int main() { scanf("%d\n", &q); while (q--) { scanf("\n"); int a, maxx, minn; maxx = 0; minn = 999999999; scanf("%d %d \n", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a); minn = min(a, minn); maxx = max(a,...
1
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int> > v; int main() { int n, i, j, k, a, x, y, m, p, b, ans = 0; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d%d%d%d%d", &k, &a, &x, &y, &m); p = b = 0; for (j = 1; j <= k; j++) { if (a < b) p++; if (v.size(...
8
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int szA = a.size(), szB = b.size(); string tmp = ""; if (szA < szB) { for (int i = 0; i < szB - szA; i++) { tmp += "0"; } tmp += a; a = tmp; szA = a.size(); } else if (szB < szA) { tmp += b; ...
4