solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b != 0) { a %= b; swap(a, b); } return a; } long long calc(long long n, long long k) { return n / gcd(n, k); } int main() { int n, k, a, b; scanf("%d%d%d%d", &n, &k, &a, &b); long long L = n * 1LL * k; l...
4
#include <bits/stdc++.h> using namespace std; const int N = 240000 + 20; char s[N]; int n, m; int z[N], g2[N]; int ans[3], now[3]; int M[220][220]; struct node { int l, r; node() {} node(int p, int q) : l(p), r(q) {} bool operator<(const node& a) const { return (l < a.l || (l == a.l && r > a.r)); } } a[10...
4
#include <bits/stdc++.h> using namespace std; int n; int a[10]; vector<string> res; vector<int> fields; int b[10]; void gao(const char* s, int len) { int depth = (int)fields.size(); if ((4 - depth) * 3 < len) { return; } if (depth == 4) { if (len == 0) { char buf[1024]; sprintf(buf, "%d.%d.%...
6
#include <bits/stdc++.h> using namespace std; using cd = complex<double>; const double pi = acos(-1); vector<long long> ft(1, 1LL); void solve() { long long x1, x2, y1, y2, a, b; cin >> x1 >> y1 >> x2 >> y2 >> a >> b; long long dx = abs(x1 - x2), dy = abs(y1 - y2); if (dx % a == 0 and dy % b == 0 and (abs(dx / ...
2
#include <bits/stdc++.h> using namespace std; int main() { string s; long long int k, len, m, arr[100], max = 0, i, sum = 0, c; cin >> s; cin >> k; len = s.length(); m = len + k; for (i = 0; i < 26; i++) { cin >> arr[i]; if (arr[i] > max) max = arr[i]; } for (i = 0; i < m; i++) { if (i >= ...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int inf = 1e9 + 7; constexpr ll longinf = 1LL << 60; constexpr ll mod = 1e9 + 7; vector<set<int>> g; void dfs(int u, vector<int>& trail) { while (!g[u].empty()) { int v = *g[u].begin(); g[u].erase(v); g[v].erase(u); dfs(v, t...
8
#include <bits/stdc++.h> long long int n, m; long long int row[50] = {0L}; long long int col[50] = {0L}; int main() { scanf("%I64d%I64d", &n, &m); long long int i, j; int t; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { scanf("%d", &t); if (t) { row[i]++; col[j]++; } ...
2
#include <bits/stdc++.h> const int N = 3e5 + 5, mod = 998244353; int n, nxt[N << 1], to[N << 1], head[N], f[N][3], cnt; int read() { int x = 0, f = 1; char s; while ((s = getchar()) > '9' || s < '0') if (s == '-') f = -1; while (s >= '0' && s <= '9') x = (x << 1) + (x << 3) + (s ^ 48), s = getchar(); ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n) { if (n % 2 == 0) { cout << "Mahmoud"; break; } else { cout << "Ehab"; break; } } }
0
#include <bits/stdc++.h> using namespace std; long long n, L, R, l[300005], r[300005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> l[i] >> r[i]; L += l[i]; R += r[i]; } int ans = abs(L - R), pm = 0; for (int i = 1; i <= n; i++) { L = L - l[i] + r[i]; R = R - r[i] + l[i]; ...
1
#include <bits/stdc++.h> using namespace std; long long f[60][120][2], n, L, R, now; long long dfs(long long ws, long long res, long long flag) { if (res < 0) return 0; if (~f[ws][res][flag]) return f[ws][res][flag]; long long& t = f[ws][res][flag]; t = 0; if ((1ll << ws) > now) { if (res == 0 && flag == ...
12
#include <bits/stdc++.h> using namespace std; int C[1005][1005], s[1005], mod = 1e9 + 7; int main() { int i, j, m; scanf("%d", &m); for (i = 1; i <= m; i++) { scanf("%d", &s[i]); s[i] += s[i - 1]; } for (i = 0; i <= s[m]; i++) for (j = C[i][0] = 1; j <= i; j++) { C[i][j] = C[i - 1][j] + C[i ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < (long long)(n); i++) { cin >> a[i]; } bool z = 0; long long prev; long long sum = 1; for (long long i = 0; i < (long long)(n); i++) { if (a[i]) { if (!z) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { pair<int, int> coo[3]; int miy = 1000, may = 0; for (int i = 0; i < 3; ++i) { cin >> coo[i].first >> coo[i].second; miy = min(miy, coo[i].second); may = max(may, coo[i].second); } sort(coo, coo + 3); cout << (may - miy) + (coo[2].first -...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int n; cin >> n; if (n % 2 == 0) cout << "NO"; else { cout << "YES" << endl; cout << 1 << " "; for (long long int i = 1, j = 2; i < n and j < n; i = i + 2, j...
2
#include <bits/stdc++.h> using namespace std; const int N = 25e2 + 1, NN = N * N; pair<int, int> D[NN]; int A[N][N], n, nn, t; bool cmp(const pair<int, int> &a, const pair<int, int> &b) { return (A[a.first][a.second] > A[b.first][b.second]); } bitset<N> B[N]; void SIK() { printf("NOT MAGIC"); exit(0); } int main(...
8
#include <bits/stdc++.h> using namespace std; int main() { long long t, a[105], sum = 1, sum1 = 0; cin >> t; for (int i = 0; i < t; i++) { cin >> a[i]; } for (int i = 0; i < t; i++) { sum = 1; sum1 = 0; if (a[i] % 2 != 0) { sum1 = ((a[i] - 1) / 2) * a[i] + a[i]; } else { sum1 =...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const long long inf = 1000000000000; int main() { int n; cin >> n; long long w[26] = {0}; bool is[26] = {0}; vector<string> vs; for (int i = 0; i < n; i++) { string s; cin >> s; vs.push_back(s); int cnt = 0; for (i...
4
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; char ans[100005] = {'\0'}; int curr = 0, len = 0; ans[0] = 'a'; len++; curr++; char ch = 'a'; while (k != 0) { if (k - curr >= 0) { k -= curr; ans[len++] = ch; curr++; } else { ch++; curr ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1 << 20; const int INF = 0x3f3f3f3f; int n; long long A[N]; multiset<int> s; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &A[i]); } long long ans = 0; for (int i = n; i >= 1; i--) { if (A[i] == -1) { break;...
8
#include <bits/stdc++.h> using namespace std; const int M = 200005; int w[M], n, m, ans, sum, bk[M]; bool vis[M]; int main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> w[i]; } for (int i = 1; i <= m; ++i) { cin >> bk[i]; for (int j ...
4
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 3; long long inf = 1e13 + 1; void solve() { int n; cin >> n; int a[n], b[n], c[n]; for (int &i : a) cin >> i; for (int &i : b) cin >> i; for (int &i : c) cin >> i; int pre = 1e9 + 1; for (int i = 0; i < n - 1; i++) { if (a[i] != pre) ...
0
#include <bits/stdc++.h> using namespace std; long long int powfi(long long int a, long long int b) { long long int c = 1LL; while (b > 0) { if (b % 2 == 1) c = ((c % 1000000007) * (a % 1000000007)) % 1000000007; a = ((a % 1000000007) * (a % 1000000007)) % 1000000007; b = b / 2; } return c; } int ma...
1
#include <bits/stdc++.h> int colors1[150], colors2[150]; int main() { int i, n1, n2, count = 0; char owns[1005], needs[1005]; scanf("%s", owns); scanf("%s", needs); n1 = strlen(owns); n2 = strlen(needs); for (i = 0; i < n1; i++) { colors1[owns[i]]++; } for (i = 0; i < n2; i++) { colors2[needs[...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int &i : a) cin >> i; long long int sum = 0; for (int i : a) sum += i; long long in...
2
#include <bits/stdc++.h> const double eps = 1e-8; const double pi = acos(-1.0); struct Segment { double l, r; bool operator<(Segment b) const { if (fabs(r - b.r) < eps) return l < b.l; else return r < b.r; } } seg[200100]; struct Point { double dis, arg; } point[200100]; int n, f[30][200100]...
11
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 1e2 + 10; long long a[N][N]; int flag[N][N]; long long dp[N][N]; int main() { int ncase; scanf("%d", &ncase); while (ncase--) { int n, m; scanf("%d%d", &n, &m); vector<long long> v; for (int i = 1; i <= n; i...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2010; int maps[maxn * 2][maxn * 2]; int vis[maxn * 2]; int pre[maxn * 2]; int n1, n2, k; int n; int deg[maxn * 2]; int s, t; vector<int> v[maxn * 2]; vector<int> num[maxn]; int bfs(int s, int t) { queue<int> q; memset(vis, 0, sizeof vis); memset(pre, ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int INF = 0x3f3f3f3f; const long long mod = 998244353; long long n, k, m; vector<pair<long long, long long> > a[maxn]; struct tree { long long l, r; long long cnt, sum; } tr[maxn << 2]; void build(long long id, long long l, long long r) {...
6
#include <bits/stdc++.h> using namespace std; int main() { int arr[20], num, ans; arr[1] = 7; arr[2] = 2; arr[3] = arr[4] = 3; arr[5] = 4; arr[6] = 2; arr[7] = 5; arr[8] = 1; arr[9] = arr[0] = 2; cin >> num; ans = arr[num % 10]; num /= 10; ans *= arr[num]; cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 4e3 + 10; const int INF = 1e9 + 9; const int B = 1e9 + 7; int di[] = {+1, 0, -1, 0, -1, -1, +1, +1}; int dj[] = {0, -1, 0, +1, -1, +1, -1, +1}; int u[N][N]; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); int n; cin >> n; pair<long long, long...
1
#include <bits/stdc++.h> using namespace std; int main() { int graph[6][6] = {0}; int m; int x, y; bool is_three_pair_wise = false; for (cin >> m; m; m--) { cin >> x >> y; graph[x][y] = 1; graph[y][x] = 1; } for (int i = 1; i <= 3; i++) { for (int j = i + 1; j <= 4; j++) { for (int k...
2
#include <bits/stdc++.h> using namespace std; int n, a[100 + 9]; int d, dist[100 + 9][100 + 9], x[100 + 9], y[100 + 9]; int main() { cin >> n >> d; for (int i = 1; i < n - 1; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ...
6
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, ctr = 1; long long a[N], bit[N]; map<long long, long long> m; void update(long long i, long long x) { while (i <= n) { bit[i] = max(bit[i], x); i += (i & (-i)); } } long long prefmax(long long i) { long long ans = 0; ...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using v = vector<T>; const ll INF = numeric_limits<ll>::max() / 10 * 9; const ll TREES = 1e5; const ll N = 2 * TREES; ll heights[TREES + 1]; ll dists[TREES + 1]; ll vals[N + 1][2]; struct State { ll bigsum, biglhs, bigrhs; }; St...
7
#include <bits/stdc++.h> using namespace std; const int Max = 2e5 + 5; const int Mod = 1e9 + 7; long long data[Max], ndata[2][Max]; int main() { std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin >> n; long long sum = 0, osum = 0; int cnt1 = 0, cnt2 = 0; for (int i =...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; const int mod = 1e9 + 7; const int inf = (1 << 30); int nex[maxn], a[maxn], b[maxn], ans[maxn], seg[4 * maxn]; vector<int> v[maxn]; int get(int id, int L, int R, int l, int r) { if (L == l and R == r) return seg[id]; int mid = (L + R) / 2; i...
8
#include <bits/stdc++.h> using namespace std; inline void rd(int &res) { res = 0; char c; while (c = getchar(), c < 48) ; do res = (res << 1) + (res << 3) + (c ^ 48); while (c = getchar(), c >= 48); } inline void print(int x) { if (!x) return; print(x / 10); putchar((x % 10) ^ 48); } inline void sc(...
12
#include <bits/stdc++.h> using namespace std; int n, k, a[100005]; char s[100005]; int main() { scanf("%d%d", &n, &k); cin >> s; for (int i = 1; i <= n; i++) a[i] = s[i - 1] - '0'; for (int i = 1; i <= n; i++) { if (a[i] == 4 && a[i + 1] == 7 && a[i + 2] == 7 && i % 2 == 1) k %= 2; if (k == 0) bre...
3
#include <bits/stdc++.h> using namespace std; int cnt1, cnt2; int main(int argc, char** argv) { string a, b; cin >> a >> b; cnt1 = cnt2 = 0; for (int i = 0; i < a.length(); i++) { if (a[i] == '1') cnt1++; } for (int i = 0; i < b.length(); i++) { if (b[i] == '1') cnt2++; } if (cnt1 + cnt1 % 2 >= ...
4
#include <bits/stdc++.h> using namespace std; int a[10000000], f[10000000]; int main() { long long int x, n, sum = 0; long long int i; cin >> n >> x; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { sum += f[a[i] ^ x]; f[a[i]]++; } cout << sum << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; struct o { int x; int y; int z; }; long a[1000][1000] = {0}, n, rt[7], f = 0, d[100000], e[100000]; o b[10000]; void dfs(int v) { for (int k = 0; k <= 6; ++k) if (a[v][k] > 0) { --a[v][k]; --a[k][v]; dfs(k); } ++f; d[f] = v; return; }...
6
#include <bits/stdc++.h> using namespace std; long long N, M; long long X[200000], T[200000]; long long P[200000], B[200000]; vector<long long> x; const int n = 1 << 19; struct SegTree { pair<long long, long long> dat[n * 2 - 1]; SegTree() { for (long long(i) = 0; (i) < (n * 2 - 1); (i)++) dat[i] = make_p...
8
#include <bits/stdc++.h> using namespace std; int Q, N, K; vector<pair<int, int> > G[5 << 17]; pair<long long, long long> dfs(int u, int p) { vector<long long> A; long long ret = 0; for (const pair<int, int>& q : G[u]) { if (q.first == p) continue; pair<long long, long long> r = dfs(q.first, u); ret +...
6
#include <bits/stdc++.h> using namespace std; const long double epsilon = 1e-9; const bool indebug = false; int main() { if (indebug) freopen("bobi.in", "r", stdin); int numTests = 1; if (indebug) cin >> numTests; for (int o = 0; o < numTests; o++) { long long n, m, a, d; cin >> n >> m >> a >> d; ve...
7
#include <bits/stdc++.h> using namespace std; struct Edge { int a, b, l, r; bool operator<(const Edge& other) const { return r > other.r; } }; Edge es[3100]; int fa[3100]; int Find(int x) { while (fa[x] != x) { x = fa[x]; } return x; } int main() { int n, m; scanf("%d%d", &n, &m); int i, j; for (i...
6
#include <bits/stdc++.h> using namespace std; vector<int> k; vector<vector<int> > g; vector<pair<long long, int> > f; void dfs(int v, int p = -1) { f[v] = pair<long long, int>(0, k[v]); if (v != p) f[v].second--; if (g[v].empty() || (g[v].size() == 1 && g[v][0] == p)) return; vector<pair<long long, int> > d; ...
6
#include <bits/stdc++.h> void choose(int x, int y) { printf("%d %d\n", x + 1, y + 1); } int main() { int w, h; scanf("%d %d", &w, &h); for (int x = 0; x < w / 2; x++) { for (int y = 0; y < h; y++) { choose(x, y); choose(w - x - 1, h - y - 1); } } if (w % 2 == 1) { for (int y = 0; y < h...
5
#include <bits/stdc++.h> using namespace std; int n, m; int daoskdoa[51], aodksao[51], dksaopdoa[51], dosakdosa[51]; vector<int> x, y; struct edge { int to, cap, rev; }; int V; vector<edge> G[2005]; int level[2005]; int iter[2005]; void add_edge(int from, int to, int cap) { G[from].push_back((edge){to, cap, (int)G[...
8
#include <bits/stdc++.h> const int fin = 0, maxn = 1000010; int n; char s[maxn]; int left[maxn], st[maxn]; struct rec { bool a[3]; rec() {} rec(bool x, bool y, bool z) { a[0] = x, a[1] = y, a[2] = z; } const bool& operator[](const int& x) { return a[x]; } }; inline rec sol(int l, int r) { if (l == r) if (...
9
#include <bits/stdc++.h> using namespace std; int n, m; int main() { scanf("%d%d", &n, &m); if (m != n) printf("No\n"); else printf("Yes\n"); return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { long int n, i, t; cin >> n; long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (a[0] == 0) a[0] = a[1]; if (n >= 2) { if (a[n - 2] - a[0] < a[n - 1] - a[1]) t = a[n - 2] - a[0]; else t = a[n - 1] - a[1]; ...
0
#include <bits/stdc++.h> using namespace std; string s, r; char p[1234567]; vector<string> v, ans; int main() { int n; cin >> n; cin >> s; for (int i = 0; i < n; i++) { int temp = s[i] - '0', temp1 = 0, temp2 = 0; if (temp > 0) { temp = 10 - temp; } r = s; for (int j = 0; j < n; j++) {...
3
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; int dp[2005][2005]; int main() { memset(dp, 0, sizeof(dp)); for (int i = 0; i < 1005; i++) dp[i][0] = 1; for (int i = 1; i < 1005; i++) for (int j = 1; j < 1005; j++) dp[i][j] = (dp[i - 1][j] + dp[i - 1]...
6
#include <bits/stdc++.h> constexpr int lc = 20; bool lines[lc][lc]; bool visited[lc]; bool dfs(int i) { if (visited[i]) return false; visited[i] = true; for (int j = 0; j < lc; ++j) if (lines[i][j] || lines[j][i]) dfs(j); return true; } int main() { using namespace std; ios::sync_with_stdio(false); ci...
11
#include <bits/stdc++.h> using namespace std; template <typename TYPE> inline TYPE sqr(const TYPE& a) { return (a) * (a); } const int INF = 1000 * 1000 * 1000; const long double EPS = 1e-9; const long double PI = 2 * acos(0.0); const int N = 2100; int to[N]; int main() { int n, k; scanf("%d%d", &n, &k); for (in...
2
#include <bits/stdc++.h> using namespace std; const int MAXINT = numeric_limits<int>::max(); const long long MAXLONGLONG = numeric_limits<long long>::max(); const double PI = 3.14159265; using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } string P; int b[110]; int n; void kmpPreprocess() {...
3
#include <bits/stdc++.h> using namespace std; int mat[110][110]; int n, m, q; void cr(int k) { int t = mat[k][m]; for (int i = m; i >= 2; i--) mat[k][i] = mat[k][i - 1]; mat[k][1] = t; } void cc(int k) { int t = mat[n][k]; for (int i = n; i >= 2; i--) mat[i][k] = mat[i - 1][k]; mat[1][k] = t; } void print()...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; n--; string s1, s2; cin >> s1 >> s2; reverse(s1.begin(), s1.end()); for (int i = 0; i < n; i++) if (s1[i] == 'E') s1[i] = 'W'; else if (s1[i] == 'W') s1[i] = 'E'; else if (s1[i] == 'N') s1[i] = 'S'; ...
8
#include <bits/stdc++.h> using namespace std; template <typename T> string tostr(const T& t) { ostringstream os; os << t; return os.str(); } const long long INF = 1000000000000000000LL; long long T[2002], C[2002]; int main(int argc, char* argv[]) { long long n, m, l, r, t, c, res = 0; cin >> n >> m; memset(...
2
#include <bits/stdc++.h> using namespace std; const int maxn = int(1e7) + 5; int A[maxn], p[maxn], mark[maxn]; void pre() { for (int i = 0; i < maxn; i++) p[i] = 1; for (int i = 2; i < maxn; i++) { if (p[i] == 1) { for (int j = i * 2; j < maxn; j += i) p[j] = max(p[j], i); } } } void factorise(int v...
5
#include <bits/stdc++.h> using namespace std; int n; int a[5010]; int L[5010]; int R[5010]; int Ok[5010]; int D[5010]; int M[5010]; int RDp[5010][5010]; int LDp[5010][5010]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (Ok[a[i]] == 0...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int p = 0; for (int i = 0; i < n; i++) { if (s[i] == '-') { if (p > 0) { p--; } } else { p++; } } cout << p; return 0; }
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline void ckmax(T& x, T y) { x = (y > x ? y : x); } template <typename T> inline void ckmin(T& x, T y) { x = (y < x ? y : x); } const int MAXN = 2e5; int n, m, q, inf; map<pair<int, int>, bool> mp; set<int> s0[MAXN + 5], s1[MAXN + 5]; struct Segm...
9
#include <bits/stdc++.h> int main() { int a[19000], b, c, n; a[1] = 1; int i = 2; while (i <= 18257) { a[i] = a[i - 1] + 12 * (i - 1); i++; } while (scanf("%d", &n) != EOF) { printf("%d\n", a[n]); } return 0; }
2
#include <bits/stdc++.h> using namespace std; const int mx2 = 505; const int mx3 = 1005; const int mx5 = 300005; const int mx6 = 800005; int _toggle(int N, int pos) { return N = N ^ (1 << pos); } int _set(int N, int pos) { return N = N | (1 << pos); } int _reset(int N, int pos) { return N = N & ~(1 << pos); } bool _che...
6
#include <bits/stdc++.h> using namespace std; int main() { long long x, n, i, s, m; long long a[1005] = {0}; cin >> n; for (i = 0; i < n; i++) { cin >> x; a[x]++; } s = 0; for (i = 1; i <= 1000; i++) if (a[i] > 0) s++; m = a[1]; for (i = 2; i <= 1000; i++) if (a[i] > m) m = a[i]; cou...
1
#include <bits/stdc++.h> #define inf 0x3f3f3f3f #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #define rep(i, a, n) for(int i = a; i <= n; ++ i) #define per(i, a, n) for(int i = n; i >= a; -- i) //#define ONLINE_JUDGE using namespace std; typedef long long ll; const int mod=1e9+7; template<typename T>void write(...
1
#include <bits/stdc++.h> using namespace std; int INF = 0x3f3f3f3f; long long MOD = 1000000007; long long binpow(long long a, long long b, long long c = 1e18) { long long res = 1; while (b > 0) { if (b & 1) { res *= a; res %= c; } a *= a; a %= c; b >>= 1; } return res; } int main...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; vector<long long> v(n + 1); for (int i = 1; i <= n; ++i) { cin >> v[i]; } string str; cin >> str; str = " " + str; vector<long long> prefixA(n + 2, 0), prefixB(n + 2, 0); ve...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, t...
7
#include <bits/stdc++.h> using namespace std; int x[110]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &x[i]); int ans = 1; for (int i = 1; i <= n; i++) { if (i > 1 && x[i - 1] && x[i]) ans += 5; else if...
0
#include <bits/stdc++.h> int main() { int n, a; while (~scanf("%d%d", &n, &a)) { if (a % 2 == 1) printf("%d\n", a / 2 + 1); else printf("%d\n", (n + 2 - a) / 2); } return 0; }
1
// Question Link: #include<bits/stdc++.h> #include<cmath> #include<algorithm> #include<string.h> # define mod 1000000007 using namespace std; typedef long long int lli; void solve() { //write your code here int n; cin >> n; vector<int>arr(n+1); for(int i=0;i<n;i++) { int x; cin ...
0
#include <bits/stdc++.h> using namespace std; bool isPrime(long long a) { if (a <= 1) return false; else if (a <= 3) return true; if (a % 2 == 0 || a % 3 == 0) return false; for (long long i = 5; i * i <= a; i += 6) { if (a % i == 0 || a % (i + 2) == 0) return false; } return true; } vector<unsi...
0
#include <bits/stdc++.h> using namespace std; int n, num[100], cnt[200010]; long long a[200010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) { long long temp = a[i]; while (temp && temp % 2 == 0) { cnt[i]++; temp /= 2; } ...
5
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, t; int main() { scanf("%lld%lld", &n, &m); if (m == 2 && n == 1) printf("Yes\n"); else if (m == 1) printf("Yes\n"); else if (n <= m) printf("No\n"); else { for (i = 2; i <= min(m, 1000000LL); i++) { if (n % i == i - 1) ...
4
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int q; cin >> q; while (q--) { int a, b, c, d, k; cin >> a >> b >> c >> d >> k; int x, y; if (a % c == 0) { x = a / c; } else { x = a / c + 1; } if (b % d == 0) {...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 300007; int n, a[maxn]; static pair<int, in...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; bool array[100]; memset(array, 1, 100); while (n--) { int r, ai; cin >> r; bool b[100]; memset(b, 0, 100); for (int i = 0; i < r; ++i) cin >> ai, b[ai - 1] = 1; for...
0
#include <bits/stdc++.h> using namespace std; const int N = 2050, inf = ~0u >> 2; struct tree { int l, r, v; tree *lc, *rc; tree(int _l, int _r) : l(_l), r(_r), v(0), lc(0), rc(0) {} void expand() { if (l == r) return; int m = (l + r) >> 1; (lc = new tree(l, m))->expand(); (rc = new tree(m + 1, ...
9
#include <bits/stdc++.h> #include <string.h> using namespace std; #define KP \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define rep(i, a, b) for (int i = a; i < b; i++) #define ll long long int #define MIN -1e9 #define MAX 1e9 #define endl "\n" #define vi vector<int> #define pb pu...
0
#include <bits/stdc++.h> using namespace std; const int N = 3e5; const int M = 405; const int oo = 1e9 + 777; vector<int> g[N]; int n, m; int d[N]; int r[M][M]; bool kiemtra; void enter() { kiemtra = false; cin >> n >> m; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; if ((u == 1 && v == n) |...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; template <class T> void read(T &x) { char c; bool op = 0; while (c = getchar(), c < '0' || c > '9') if (c == '-') op = 1; x = c - '0'; while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0'; if (op) x = -x; } template <clas...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 10; int mod = 1e9 + 7; long long dp[3000000]; int main() { int t, n; cin >> t; dp[1] = 0; dp[2] = 0; for (int i = 3; i < maxn; ++i) dp[i] = (dp[i - 1] + dp[i - 2] * 2 + (!(i % 3) ? 4 : 0)) % mod; while (t--) { scanf("%d", &n); ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = (1 << 18) + 5; long long a[maxn << 2], lz; void build(int rt, int l, int r) { if (l == r) { cin >> a[rt]; return; } int mid = (l + r) >> 1; build(rt << 1, l, mid); build(rt << 1 | 1, mid + 1, r); a[rt] = a[rt << 1] + a[rt << 1 | 1]; } vo...
8
#include <bits/stdc++.h> using namespace std; int main() { string s, ans = ""; cin >> s; int n = s.length(), flag = -1, cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == '0') { flag = i; break; } } if (flag >= 0) { for (int i = 0; i < n; i++) { if (i != flag) cout << s[i]; ...
1
#include <bits/stdc++.h> using namespace std; int n; string a; int main() { cin >> n >> a; for (int i = 0; i < n; i++) if (a[i] == 'R' && a[i + 1] == 'U' || a[i] == 'U' && a[i + 1] == 'R') a.replace(i, 2, "D"); cout << a.size(); }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 200 + 10; vector<int> adj[maxn], q; int c[maxn], n, m[maxn]; bool mark[maxn], mark2[maxn]; void dfs(int v) { mark[v] = true; for (int i = 0; i < adj[v].size(); i++) { int tmp = adj[v][i]; if (!mark[tmp]) dfs(tmp); } q.push_back(v); } int mai...
4
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { bool f = 0; char c = getchar(); x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void wr...
7
#include <bits/stdc++.h> using namespace std; const long long OO = (long long)1e18; const long long mod = (1e9) + 7; const double PI = acos(-1.0); const double EPS = 1e-8; int dx[]{-1, -1, -1, 0, 0, 1, 1, 1}; int dy[]{-1, 0, 1, -1, 1, -1, 0, 1}; void file() {} struct node { int x, y; }; bool operator<(node a, node b)...
3
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > v[1000007]; long long int mills[1000007]; long long int is_mill[1000007]; int main() { ios::sync_with_stdio(false); cin.tie(0); long long int s, d, val, i, j, mini = 1e18, n, m, k, lim = 1e18; cin >> n >> m >> k; for (i ...
2
#include <bits/stdc++.h> using namespace std; int pow(int x, int y) { int res = 1; while (y) { if (y & 1) res *= x; y >>= 1; x *= x; } return res; } struct Compare { constexpr bool operator()( pair<long long, pair<long long, long long> > const& a, pair<long long, pair<long long, long l...
4
#include <bits/stdc++.h> using namespace std; int n, a[2000], used[1000], ans[1000], l, x, r, b[10000]; set<int> a1, a2; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= 2 * n; i++) { cin >> b[i]; a[b[i]]++; } for (int i = 10; i <= 99; i++) if (a[i] >=...
5
#include <bits/stdc++.h> using namespace std; int MAX = 1000000; int MIN = -1000000; int INF = 1000000000; int x4[4] = {0, 1, 0, -1}; int y4[4] = {1, 0, -1, 0}; int x8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int y8[8] = {1, 1, 0, -1, -1, -1, 0, 1}; int i, j, k; int main() { string str, tabel = "", temp; vector<string> v;...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, len0, len1, vis[N], co; int res, ans = (1 << 30); bool flag; struct node { int to, w; node() {} node(const int To, const int W) { to = To; w = W; } }; vector<node> e[N]; vector<int> vec, v0, v1, v2; void dfs(const int u, cons...
7
#include <bits/stdc++.h> using namespace std; template <typename T> void gi(T &angka) { angka = 0; char input = getchar(); T kali = 1; while (!(48 <= input && input <= 57)) { if (input == '-') kali = -1; input = getchar(); } while (48 <= input && input <= 57) angka = (angka << 3) + (angka << 1) ...
6
#include <bits/stdc++.h> const int MAXN = 0; const int MAXM = 0; const int INF = 2000000000; const int MOD = 1000000007; using namespace std; int n; long long dp[2000]; long long k; int main() { dp[0] = 1; dp[1] = 1; scanf("%d", &n); for (int i = 2; i <= n + 2; i++) { dp[i] = dp[i - 1] + dp[i - 2]; } sc...
5
#include <bits/stdc++.h> using namespace std; int n, m, k, y = 1, x = 1, dir = 1; vector<pair<int, int>> path; int main() { cin >> n >> m >> k; while (x <= n) { path.push_back(make_pair(x, y)); y += dir; if (y == m + 1) dir = -1, y = m, x++; else if (y == 0) dir = 1, y = 1, x++; } fo...
3
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007, N = 200010; long long T, n, m, q[N], a[N], C, b[N], ms; bool v[N]; map<long long, int> mp; set<int> s[N]; int exgcd(long long a, long long b, long long &x, long long &y) { int z; return !b ? (x = 1, y = 0, a) : (z = exgcd(b, a % b...
10