solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int N, K; long long B; bool flag[100000 + 5]; struct Point { int x, y; Point(int _x = 0, int _y = 0) : x(_x), y(_y) {} }; vector<struct Point> a; bool cmp(const struct Point &a, const struct Point &b) { return a.x > b.x || (a.x == b.x && a.y < b.y); } int main() { s...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); ; int a, i, c = 1, k, max; cin >> a; int b[a], x[a]; for (i = 0; i < a; i++) { cin >> b[i]; } max = 1; for (i = 1; i < a; i++) { if (b[i] >= b[i - 1]) { c++; } else { if (max <= c)...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { int n, x; cin >> n >> x; set<int> st; for (int i = 1; i <= 300; i++) { st.insert(i); } for (int i = 1; i <= n;...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 5; const int mod = 1e9 + 7; int32_t main() { 4; ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { ll n, m; cin >> n >> m; long long a[m], b[m]; long long id, mx = 0; ...
6
#include <bits/stdc++.h> using namespace std; int n, m, h; int U[100001]; vector<int> V[100001]; int C[100001], L[100001], second[100001], R[100001], t = 0, top = 0; int SCC[100001], out[100001], nSCC = 1; void DFS(int v) { L[v] = C[v] = ++t; second[top++] = v; for (int e : V[v]) { if (!C[e]) DFS(e); if (...
5
#include <bits/stdc++.h> int main() { int n, i, x = 0; char a[4]; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%s", &a); if (a[1] == '+') { x++; } else if (a[1] == '-') { x--; } } printf("%d", x); return 0; }
0
#include <bits/stdc++.h> using namespace std; inline int read(int &i) { i = 0; char c = 0; bool flag = false; for (; (c < '0' || c > '9') && c != '-'; c = getchar()) ; while (c == '-') { flag = true; c = getchar(); } for (; c >= '0' && c <= '9'; c = getchar()) i = 10 * i + c - '0'; if (flag)...
4
#include <bits/stdc++.h> using namespace std; long long n, k, a[55]; int main() { a[0] = a[1] = 1; for (int i = 2; i <= 50; i++) a[i] = a[i - 1] + a[i - 2]; cin >> n >> k; long long c1 = 1, c2 = 2; while (n > 0) { if (k > a[n - 1]) { cout << c2 << " " << c1 << " "; k -= a[n - 1], n -= 2, c2 +=...
5
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (...
13
#include <bits/stdc++.h> using namespace std; const int inf = 10000000; const int MOD = 1000000007; int n, m, k, c = 1, q, d; set<char> se; vector<char> v, u, w; int a[100005]; int ind[100005]; map<int, int> mp; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; ...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long n, ans = 0, sum = 0; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < 31; i++) { sum = 0; for (long long j...
6
#include <bits/stdc++.h> const int S = 1 << 21; char ibuf[S], *iS, *iT, obuf[S], *oS = obuf, *oT = oS + S - 1; struct Flusher_ { ~Flusher_() { (fwrite(obuf, 1, oS - obuf, stdout), oS = obuf, void()); } } flusher_; template <class T> inline void read(T &x) { x = 0; register char c = (iS == iT ? (iT = (iS = ibuf) +...
12
#include <bits/stdc++.h> using namespace std; const int Maxn = 2e5 + 1000; int Init[Maxn], First[Maxn], Last[Maxn], Arr[Maxn], Depth[Maxn], cnt, n, m; bool Mark[Maxn]; pair<int, int> Num[5 * Maxn]; vector<int> V[Maxn]; void Dfs(int Vert) { Mark[Vert] = true; Arr[++cnt] = Vert; First[Vert] = cnt; for (int i = 0;...
6
#include <bits/stdc++.h> using namespace std; int x2, y2, n, d; int sg[603][603]; int dx[603], dy[603]; bool use[403]; int &SG(int first, int second) { return sg[first + 200][second + 200]; } int main() { scanf("%d%d%d%d", &x2, &y2, &n, &d); for (int i = (0); i < (int)(n); i++) scanf("%d%d", dx + i, dy + i); for ...
5
#include <bits/stdc++.h> using namespace std; int n, k, ar[1 << 20]; long long dp[5005][5005]; int C; int cnt[5050]; int c1, c2; int done; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> ar[i]; cnt[i % k]++; } sort(ar, ar + n); C = 1e9; for (int i = 0...
6
#include <bits/stdc++.h> using namespace std; int n, a; int main() { scanf("%d%d", &n, &a); if (a % 2 == 1) { cout << (a + 1) / 2 << endl; } else { cout << n / 2 + 1 - a / 2 << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int L, v, li, ri; cin >> L >> v >> li >> ri; cout << L / v - (ri / v - (li - 1) / v) << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const long long N = 2e5, MAX = 2e5 + 5; const long long MOD = 1e9 + 7, mod = 1e9 + 7; long long dp[N] = {-1}; long long a[N], n; long long solv(long long i) { if (dp[i] != -1) return dp[i]; long long &ans = dp[i]; ans = 0; for (long long j = i % a[i]; j < n; j += a[...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<long long> d(n); for (int i = 0; i < n; i++) { cin >> d[i]; } auto sum = a; partial_sum(a.begin(), a.end(), sum.begin()); auto get...
7
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m, c = 0, i, tc = 0; cin >> n >> m; long long x = m % 10; long long m1 = 10 * m; if (n >= m1) { for (i = 1; i < 10; i++) { c += ((i * x) % 10); } tc = (n / m1) * c; n = n % m1; } for (i = 1; i * m <= n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { long long int a, b; cin >> a >> b; vector<pair<long long int, long long int> > vec, vec2; for (int i = -1000; i <= 1000; i++) { for (int j = -1000; j <= 1000; j++) { if (i && j && i * i + j * j == a * a) { v...
4
#include <bits/stdc++.h> using namespace std; int main() { int a, b, s, n, x; cin >> a >> b; n = a / b; s = a % b; x = n + s; int j = x; while (j != 0) { s = x % b; x = x / b; j = x; n += x; x += s; } cout << a + n; }
0
#include <bits/stdc++.h> using namespace std; int b[20][20], a[20], ans, n, q, N, st[20], c[262144], wz[1075637], top; long long dp[262144][20], da[20][262144], ta[262144], v[60000]; void FWT(long long *a, int s) { for (int h = 1; h < N; h <<= 1) for (int i = 0; i < N; i += h + h) for (int j = 0; j < h; ++j...
12
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define inf 100000000000 #define mod 1000000007 ll power(ll x,ll n) { if(n==0) return 1; else if(n%2 == 0) //n is even return power((x*x),n/2); else ...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 1e5 + 5; const long long inf = 1e18; char s[N]; int i, j, aux[200]; int main() { scanf("%s", s); int len = strlen(s); int index = 123; for (i = 0; i < len; i++) aux[s[i]] = i; for (i = 122; i >= 97; i--) { for (j = aux[in...
1
#include <bits/stdc++.h> using namespace std; int n; int computer[201], check[3][201]; vector<int> vv[201]; int bk[201]; int bfs(int st, int num) { queue<int> q; int ans = n; for (int i = 1; i <= n; i++) { if (check[num][i] == 0) q.push(i); } while (!q.empty()) { memset(bk, 0, sizeof(bk)); while (...
4
#include <bits/stdc++.h> using namespace std; const int N = (int)5e5 + 7; const int inf = (int)1e9 + 7; int n; int a[303], f[303], cnt[303], sz; int c[303][303]; int d[303][303]; int ff[303]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); for (int j = 2; j * 1ll * j <= a[i]...
8
#include <bits/stdc++.h> using namespace std; bool uni[200010]; int sub[200010]; vector<int> adjList[200010]; int dfs(int node, int p = -1) { sub[node] = uni[node]; for (int nxt : adjList[node]) { if (nxt == p) continue; sub[node] += dfs(nxt, node); } return sub[node]; } int main(void) { int n, k; s...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int l = 1, r; char str[maxn]; int find(char ch) { for (int i = l; i <= r; i++) { if (str[i] == ch) { return i; } } return EOF; } int main() { gets(str + 1); r = strlen(str + 1); int point = find('.'); for (; str[l] == 4...
5
#include <bits/stdc++.h> using namespace std; long long int fast_expo(long long int x, long long int p) { if (p == 0) return 1; else if (p % 2 == 0) { long long int t = fast_expo(x, p / 2) % 998244353; return (t * t) % 998244353; } else return (x * (fast_expo(x, p - 1)) % 998244353) % 998244353; }...
3
#include <bits/stdc++.h> using namespace std; int N, M; vector<bool> arr[1000005]; vector<bool> brr[1000005]; pair<int, int> dq[4000005]; vector<int> dist[2][1000005]; void add(int n, bool b) { arr[n].push_back(b); brr[n].push_back(b); dist[0][n].push_back(INT_MAX >> 1); dist[1][n].push_back(INT_MAX >> 1); } vo...
7
#include <bits/stdc++.h> using namespace std; int main(void) { int a[8], i, g, j; string c[10]; string b, B, v; cin >> b; for (i = 0; i < 10; i++) cin >> c[i]; for (i = 0; i < 8; i++) { B.clear(); for (j = 0; j < 10; j++) B.push_back(b[i * 10 + j]); for (j = 0; j < 10; j++) if (B == c[j]) ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int cnt1 = 0, cnt0 = 0; if (n % 2 != 0) { cout << 1 << endl; cout << s << endl; } else { for (int i = 0; i < n; i++) { if (s[i] == '0') { cnt0++; } else { cnt1++; }...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 3e5 + 5; const int INF = 1e9 + 7; struct note { int a, pos; } a[maxn], b[maxn]; bool cmp1(note t1, note t2) { return t1.a < t2.a; } bool cmp2(note t1, note t2) { return t1.a > t2.a; } int main() { int n; scanf("%d", &n); int...
5
#include <bits/stdc++.h> using namespace std; long long mod_exp(long long x, long long y, long long mm) { if (y == 0) return (1); else if (y % 2 == 0) return (mod_exp((x * x) % mm, y / 2, mm)); else return ((x * mod_exp((x * x) % mm, (y - 1) / 2, mm)) % mm); } bool isPowerOfTwo(int n) { if (n == 0) ...
2
#include <bits/stdc++.h> using namespace std; long long a[100200]; pair<long long, long long> b[100200]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); reverse(a, a + n); int l = 0, r = 0; long long s = 0; while (r < n - 1) { if (a[r] > a[r + 1] + 1) r++...
4
#include <bits/stdc++.h> using namespace std; int f[4194304]; int n; int a[1000010]; int main() { int limit = (1 << 22) - 1; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); f[limit - a[i]] = a[i]; } for (int i = limit; i >= 0; i--) { if (!f[i]) continue; for (int j = 0; j <...
7
#include <bits/stdc++.h> using namespace std; int n, m, q, a, b, c, d, dp[50][50][50][50], A[50][50]; string s[50]; int main() { cin >> n >> m >> q; for (int i = 0; i <= n - 1; i++) cin >> s[i]; for (int i = 0; i <= n - 1; i++) for (int j = 0; j <= m - 1; j++) A[i + 1][j + 1] = (A[i + 1][j] + 1) * (s[i]...
5
#include <bits/stdc++.h> using namespace std; int n, k; string s; int cnt; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == '#') { cnt++; } else { if (cnt >= k) { cout << "NO" << endl; re...
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; inline long long CinLL() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } ...
4
#include <bits/stdc++.h> using namespace std; int main() { string S, S1, S2, S11, S21; getline(cin, S); int N = S.length(); int i, j, k; int t = 0, t3 = 0; for (i = 0; i < N; i++) { if (S[i] != S[N - i - 1] and t3 == 0) { t3 = 1; if (S[i + 1] == S[N - i - 1]) { t = 1; S1 = S;...
11
#include <bits/stdc++.h> using namespace std; long long prime(long long n) { for (long long i = 2; i * i <= n; i++) { if (n % i == 0) return i; } return n; } int main() { long long n, ok = 0; cin >> n; if (n % 2 != 0) { n -= prime(n); ok++; } cout << ok + n / 2 << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; void rec(int n) { if (n == 1) return; int x = n; x--; while (n % x != 0) x--; cout << x << " "; return rec(x); } int main() { int n; cin >> n; cout << n << " "; rec(n); return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, rsp, ans, taram; char first; int main() { cin >> n; cin >> first; if (first == 'U') { taram = 2; rsp++; } else taram = 1; for (int i = 2; i <= n; i++) { cin >> first; if (rsp * 2 == i - 1) { ans += (first == 'R' && taram == 2); ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5, MAXS = 1e7, mod = 998244353, G = 3, invG = (mod + 1) / 3; int n; long long m; int cnte, h[MAXN], to[MAXN << 1], nx[MAXN << 1]; inline void adde(int u, int v) { cnte++; nx[cnte] = h[u]; to[cnte] = v; h[u] = cnte; } int fa[MAXN], si...
13
#include <bits/stdc++.h> using namespace std; void solve() { const long long mxN = 1e5; int n, a, counter = 0; int ar[mxN] = {}; cin >> n; for (int i = 0; i < n; i++) { cin >> a; ar[i] = a; } for (int i = 0; i < n; i++) { if (ar[i] != ar[i + 1]) { counter++; } } cout << counter; ...
0
#include <bits/stdc++.h> using namespace std; int rev(int n) { int res = 0; while (n) { res *= 10; res += n % 10; n /= 10; } return res; } bool prime(int n) { for (int i = 2; i * i <= n; ++i) { if (n % i == 0) return false; } return true; } int main() { stack<int> st; st.push(0); int...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int n; int check[maxn]; int ver[maxn]; int f[maxn]; vector<int> e[maxn]; int ord; int in[maxn]; void dfs(int u) { check[u] = 1; for (int i = 0; i < e[u].size(); ++i) { int v = e[u][i]; if (!check[v]) dfs(v); } ver[ord--] = u; } int mai...
5
#include <bits/stdc++.h> using namespace std; int main() { string x = "qwertyuiopasdfghjkl;zxcvbnm,./", s; char a; cin >> a >> s; if (a == 'L') for (int i = 0; i < s.length(); i++) for (int j = 0; j < 30; j++) if (s[i] == x[j]) { s[i] = x[j + 1]; break; } if (a ==...
0
#include <bits/stdc++.h> using namespace std; int main() { long t; string input; cin >> t; while (t--) { cin >> input; cout << input.size() - count(input.begin(), input.end(), '0') << endl; for (int i = input.size() - 1; i >= 0; i--) { if (input[i] != '0') { cout << input[i] + string(i...
0
#include <bits/stdc++.h> using namespace std; const int MAX_SZ = 12; const int MAX_VAL = 10; map<vector<int>, bool> seenDP; map<vector<int>, bool> winDP; bool cannotMove(vector<int> v) { int zero = 0; for (int out : v) zero += out == 0; if (zero >= 2) return true; vector<int> forced; for (int i = 1; i < v.siz...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } return x * f; } inline ...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) { long long int m, j = 0, n, g, b, i, k, c = 0, x; cin >> n; for (i = n; i < 1200; i++) { c = 0; m = i; while (m != 0) { c +=...
0
#include <bits/stdc++.h> using namespace std; bool mark[2][105]; char s[2][105][20]; int n, num[2][26]; int get(int x, int y) { int ret = -1; for (int i = 0; i < n; i++) if (!mark[1][i]) { int k = s[1][i][0] - 'A'; if (y == k || x == -1 && num[1][k] > num[0][k]) if (ret == -1 || strcmp(s[1][...
6
#include <bits/stdc++.h> const int M = 1000000000 + 7; int n, l, a[2][100]; int dp[30001][100][2], res = 0; int main() { scanf("%d %d", &n, &l); for (int i = 0; i < n; ++i) scanf("%d %d", &a[0][i], &a[1][i]); for (int i = 1; i <= l; ++i) for (int k = 0; k < n; ++k) for (int p = 0; p < (a[0][k] == a[1][k...
5
#include <bits/stdc++.h> int main() { int a, b, c, d, min, e, f; long long int sum; scanf("%d%d%d%d", &a, &b, &c, &d); scanf("%d%d", &e, &f); if (f > e) { min = b; if (min > c) min = c; if (min > d) min = d; d = d - min; sum = min * f; if (a >= d) min = d; else min = a;...
0
#include <bits/stdc++.h> using namespace std; struct Trie { int mark; Trie* son[53]; }; Trie* nul; Trie node[100000]; char s[10001], s1[10001]; int pn; Trie* root; int n; Trie* newnode() { Trie* temp; temp = &node[++pn]; temp->mark = 0; for (int i = 0; i < 53; i++) temp->son[i] = nul; return temp; } int f...
9
#include <bits/stdc++.h> long long a, b, c, d, e, f, i = 4, r, z, x, y; int main() { std::cin >> a >> b >> c >> d >> e >> f; for (z = f * f + e * e; i--; x = c - a, y = d - (b = -b), r |= (!z && !x && !y) | (z && !((x * e + y * f) % z) && !((y * e - x * f) % z))) std::swap(a...
6
#include <bits/stdc++.h> using namespace std; constexpr static int MAXN = 1e5 + 10; constexpr static int MAXVAL = 200; constexpr static int MOD = 998244353; int n; int a[MAXN]; int64_t cnt0[2][MAXVAL + 1], cnt1[2][MAXVAL + 1]; int64_t cnt0sum[2][MAXVAL + 1], cnt1sum[2][MAXVAL + 1]; int main() { scanf("%d", &n); for...
5
#include <bits/stdc++.h> using namespace std; double eps = 1e-9; double pi = acos(-1); int fx[8] = {1, -1, 0, 0, 1, -1, -1, 1}; int fy[8] = {0, 0, 1, -1, 1, -1, 1, -1}; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define fast_io ios_base::sync_with_stdio(false); cin.tie(0); #define ll lo...
1
#include <bits/stdc++.h> using namespace std; const int module = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; vector<long long> p4(n, 1); for (int i = 1; i < n; ++i) p4[i] = p4[i - 1] * 4; cout << 4 * 2 * 3 * p4[n - 3] + 4 * (n - 3) * 3 * 3 * (n >= 4 ? p4[n - 4] :...
4
#include <bits/stdc++.h> using namespace std; template <class T> int len(const T &c) { return (int)c.size(); } template <class T> void cmin(T &a, T b) { if (b < a) a = b; } template <class T> void cmax(T &a, T b) { if (b > a) a = b; } map<long long, long long> m; long long z, n, t1; int main() { cin >> n; for...
2
#include <bits/stdc++.h> using namespace std; long long n, m, a[1000100], x, y, z, k, r, w, t; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; t = 0; k = 0; for (int i = 0; i < m; i++) { cin >> x; while (x > k + a[t]) { k += a[t]; t++; } cout << t + 1 << ' ' <<...
1
#include <bits/stdc++.h> int top = 0; std::vector<int> ask[500005]; int x[500005], y[500005], z[500005], fa[500005], size[500005], tmp[500005], res[500005]; struct edge { int x, y, val; } e[500005]; struct state { int x, y, fx, fy; } st[500005]; inline int read() { register int x = 0, f = 1; register char s...
7
#include <bits/stdc++.h> using namespace std; int v[100001]; vector<pair<int, int>> lefttt, rightttt; int main() { int n, d, b; int sumaLeft = 0; int sumaRight = 0; cin >> n >> d >> b; for (int i = 1; i <= n; ++i) { cin >> v[i]; } for (int i = 1; i <= n; ++i) { if (sumaLeft + v[i] >= ((n + 1) / 2)...
7
#include <bits/stdc++.h> using namespace std; int cnt[10005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k, a; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a; cnt[a]++; } long long ans = 0; for (int i = 0; i <= 1e4; i++) { for (int j = 0; j...
4
#include <bits/stdc++.h> using namespace std; int abs(int a, int b) { if (a < b) { return b - a; } else { return a - b; } } int main() { int t; int arr[100]; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; for (int j = 0; j < n; j++) { cin >> arr[j]; } int min_va...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int p[N], a[N], ll[N], lr[N], rr[N], f[N]; int ta, tp, n; char s[N]; void spe() { int t1 = 0, t2 = 0; for (int i = 1; i <= ta; ++i) if (a[i] < p[1]) ++t1; else ++t2; if (t1 > t2 || (t1 == t2 && p[1] - a[1] < a[ta] - p[1])) ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { char c[] = {'a', 'b', 'c', 'd'}; int i = 0; while (n--) { cout << c[i++]; if (i > 3) i = 0; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; using mii = map<int, int>; using pii = pair<int, int>; using ll = int64_t; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; const pair<int, int> DD[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const int mod = 1e9 + 7, mxN = 2e5 + 5, INF = 0x3f3f3f3f; const ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> a(n), b(n); for (size_t i = 0; i < n; i++) cin >> a[i]; for (size_t i = 0; i < n; i++) cin >> b[i]; vector<long long> dp_a(n), dp_b(n); dp_a[n - 1] = a[n - 1]; dp_b[n - 1] = b[n - 1]; for (int i = n - 2; i >=...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; const long long MOD = 1e9 + 7; const double PI = acos(-1.0); long long arr[MAX]; int fun(long long n) { int ans = 0; if (n == 0) return -1; while (1) { if (n & 1) return ans; else { ans++; n >>= 1; } } } int mai...
5
#include <bits/stdc++.h> using namespace std; int euc(int a, int b) { if (a < b) { int t = a; a = b; b = t; } while (b != 0) { int r = a % b; a = b; b = r; } return a; } int main() { int a, b; scanf("%d %d", &a, &b); int nsd = euc(a, b); long long int lcm = ((long long int)a) *...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; int solutions[40]; cin >> t; for (int i = 0; i < t; ++i) { int x; cin >> x; int num_bef; string a = std::to_string(x); int q = ((a[0] - '0') - 1) * 10; if (a.size() == 1) { q += 1; } if (a.size() == 2) { ...
0
#include <bits/stdc++.h> int main() { int n, i, t, s1 = 0, p = 1, s2 = 0, c = 0; scanf("%d", &n); while (n--) { scanf("%d", &t); int a[t]; for (i = 0; i < t; i++) { scanf("%d", &a[i]); s1 = s1 + a[i]; p = p * a[i]; if (a[i] == 0) { s2 = s2 + 1; c++; } else...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<int> s; for (; n--;) { int x; cin >> x; s.insert(x); } vector<int> v(s.begin(), s.end()); if (v.size() < 2) return cout << "NO\n", 0; cout << v[1] << "\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 110; int a[N]; int main() { int n, d; scanf("%d %d", &n, &d); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); int m; scanf("%d", &m); int index = 0, resp = 0; while (m--) { if (index < n) resp += a[index++]; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int x[4][4]; char c; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> c; x[i][j] = (c == '#' ? 1 : 0); } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int check = x[i][j] + x[i][j + 1] + ...
1
#include <bits/stdc++.h> using namespace std; int n; long long a[505]; long long mn = 0x3f3f3f3f; long long ans; int check(int k) { long long ret = 0; for (int i = 1; i <= n; i++) { int c = a[i] % k; int d = a[i] / k; if (c != 0 && (c + d) < (k - 1)) { return 0; } ret += d + (c != 0); } ...
8
#include <bits/stdc++.h> using namespace std; multimap<long long int, long long int> st; int main() { long long int n, m; cin >> n >> m; long long int arr[n]; set<long long int> s1, s2, res1, res2; for (long long int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] % 2 == 0) s1.insert(arr[i]); ...
5
#include <bits/stdc++.h> using namespace std; struct st { bool operator()(string a, string b) { return a + b < b + a; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); ; int n; string s; multiset<string, st> S; cin >> n; for (int i = 0; i < n; i++) { cin >> s; S.insert(s); } f...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int n, dp[4005][4005], t[4005][4005]; int main() { scanf("%d", &n); t[0][0] = 1; for (int i = 1; i <= n; i++) { t[i][0] = 1; for (int j = 1; j <= n; j++) t[i][j] = (t[i - 1][j - 1] + t[i - 1][j]) % MOD; } dp[1][1] = 1; for ...
5
#include <bits/stdc++.h> using namespace std; int x, y, n, m, a[100000], k; vector<long long> v; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> x >> y; if (v.size() != 0) { v.push_back(x * y + v[v.size() - 1]); } else { v.push_back(x * y); } } for (int i = 1; i <= ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long t, ans; for (cin >> t; t; t--) { string str; cin >> str; long long po = 0; long long num1 = 0, num2 = 0, len = str.length(); long long ans = len; for (int i = (0); i <= (len - 1); i++) { if (str[i] == 'A') num1++; ...
1
#include <bits/stdc++.h> using namespace std; const int N = 305; namespace geometry { struct Vector { long long x, y; Vector(long long x = 0, long long y = 0) : x(x), y(y) {} bool operator<(const Vector &tmp) const { return x != tmp.x ? x < tmp.x : y < tmp.y; } bool operator==(const Vector &tmp) const { r...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; void solve() { int n; cin >> n; char c, prev; cin >> c; prev = c; int cnt = 0; while (cin >> c) { if (c == prev) cnt++; prev = c; } cout << cnt; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005000; const int MD = 1000000007; vector<int> divs[MAXN]; int lp[MAXN]; vector<int> pr; int phi[MAXN]; int pil[MAXN]; int sum[MAXN][3]; int getPhi(int x) { int res = x; while (x != 1) { int div = lp[x]; res /= div; res *= (div - 1); wh...
10
#include <bits/stdc++.h> using namespace std; long long int m, n, c, d, j, k, l, r, x, t, y, u, b, z, i; vector<long long int> v, w; set<long long int> s1; string s, p, q; map<long long int, pair<long long int, long long int> > mp; map<char, long long int> mk; int main() { cin >> n; long long int a[n + 1]; for (i...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:94777216") using namespace std; string st; int din[100001][26]; int ls[26]; int main() { cin >> st; int n = st.length(); for (int i = 0; i < 26; i++) ls[i] = -1; for (int i = 1; i <= n; i++) { for (int j = 0; j < 26; j++) din[i][j] = din[i - 1][j]; ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, j, k, m, n, x, y; t = 1; while (t--) { long long int flag = 0; x = -1; string s; cin >> s; n = s.length(); string F = ":("; for (i = 0; i < n; i++) { if (s[i] == 'a') { x = i; } } ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 1; int k, s[maxn], t[maxn], res[maxn]; void Input() { cin >> k; char c; s[0] = t[0] = 0; for (int i = 1; i <= k; i++) { cin >> c; s[i] = int(c - 'a'); } for (int i = 1; i <= k; i++) { cin >> c; t[i] = int(c - 'a'); } } vo...
5
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } int n, e; const int MAXN = 2000005; vector<int> res; int arr[MAXN]; int pos[MAX...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:167772160000") using namespace std; vector<pair<int, int> > edges[310000]; bool ans[310000]; int ansCount; int num[310000]; int cnt[3]; bool vis[310000]; bool dfs(int a) { if (vis[a]) return false; vis[a] = true; bool ret = (num[a] == 2); for (int i = 0; ...
6
#include <bits/stdc++.h> using namespace std; void solve() { long long n, b, a, an = 0; cin >> n >> b >> a; long long x[n], cur = a; for (long long int i = 0; i < n; i++) cin >> x[i]; for (long long int i = 0; i < n; i++) { if (b == 0 && cur == 0) break; an++; if (x[i]) { if (cur == a) ...
3
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-10; const int INF = 1 << 30; const long long LLINF = 1ll << 60; const int MOD = 1e9 + 7; const int xx[8] = {1, 0, -1, 0, 1, -1, 1, -1}; const int yy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); c...
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 int maxn = 1e3 + 5; int ans[maxn * maxn], x[maxn * 5]; int main() { int n, m, k; int a, b; scanf("%d%d%d", &n, &m, &k); int num = 0; for (int i = 1; i <= k; i++) ans[num++] = 1; for (int i = 1; i <= n; i++) x[i] = k; int z; for (int i = n + 1; i <= m +...
5
#include <bits/stdc++.h> using namespace std; int a[33][33] = { 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, ...
3
#include <bits/stdc++.h> using namespace std; const int base = 1e6 + 3; long long f[20][20]; long long a[20]; long long FastPow(long long a, int n) { long long res = 1; for (; n; n >>= 1, a = a * a % base) if (n & 1) res = res * a % base; return res; } void Mul(int i, int x) { for (int j = (0), _b = (11); j...
7
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N]; int main() { ios::sync_with_stdio(0); int n, k; cin >> n >> k; for (int(i) = (0); i < (n); ++(i)) a[i] = i; k = min(k, n / 2); long long ans = 0; for (int(j) = (0); j < (n); ++(j)) { if (j < k) ans += (n - 1 - j); ...
2