solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; void solve(); int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } bool isPrime(long long int a) { for (int i = 2; i <= sqrt(a); i++) { if (a % i == 0) return false; } return true; } int main() { int t = 1; cin >> t; while (...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; t = 1; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int b[26] = {0}; for (int i = 0; i < n; i++) { b[s[i] - 'A']++; } int mn = INT_MAX; for (int i = 0; i < k; i++) { mn = min(mn, (b[i]))...
0
#include <bits/stdc++.h> using namespace std; int n; int w[300010]; vector<int> G[300010]; struct edge { int from, to, dist; }; vector<edge> edges; long long res[300010]; vector<long long> tmp[300010]; void addedge(int from, int to, int dist) { edges.push_back(edge{from, to, dist}); G[from].emplace_back(edges.siz...
5
#include <bits/stdc++.h> #define int long long using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; void solveQuestion(){ int n1,n2,n3; cin >> n1 >> n2 >> n3; int n = n1+n2+n3; vector<int> arr(n); int sum = 0; for(int i=0;i<n;i++){ cin >> arr[i]; sum += arr[i]; } int mini1 = 1e9,mini2 = 1...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 10; int n, m, f[MAXN], l[MAXN], r[MAXN], opp[MAXN], t, T, N, bel[MAXN], vis[MAXN]; vector<pair<int, pair<int, int> > > L; int getf(int first) { if (f[first] == first) return first; f[first] = getf(f[first]); return f[first]; } void fail() {...
12
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int a, b, i; cin >> a >> b; if ((abs(a - b) + 1) % 2 == 0) { long long int temp = (abs(a - b) + 1) / 2; cout << temp * temp << endl; } else { long long int temp = (a...
0
#include <bits/stdc++.h> using namespace std; vector<int> c[300000], c2[300000]; pair<int, int> order[300000]; vector<pair<int, int> > occ[300000]; int last[300000], last2[300000], pos[300000]; int main() { int i, j; int t, n, q, k; scanf("%d", &t); while (t--) { scanf("%d %d", &n, &q); for (i = 0; i < ...
12
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long power(long long x, long long n) { if (n == 0) return 1; if (n == 1) return x % mod; if (n % 2 == 0) { long long y = power(x, n / 2) % mod; return (y * y) % mod; } if (n & 1) { long long y = power(x, n - 1); return...
5
#include <bits/stdc++.h> using namespace std; int ans[2050][15][50]; int data[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool judge(int d, int m, int y) { if (y <= 2015 && y >= 2013) { if (m >= 1 && m <= 12) { if (d >= 1 && d <= data[m - 1]) return true; } } return false; } const int N = ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 * 1000 + 10; int ans[MAXN][MAXN]; int main() { int n, d, k; scanf("%d%d%d", &n, &k, &d); long long is = 1; for (int i = 1; i <= d && is < n; ++i) is *= k; if (is < n) { puts("-1"); return 0; } for (int i = 1; i < n; i++) { for (i...
5
#include <bits/stdc++.h> int main() { using std::cin; using std::cout; std::string number; cin >> number; if (number.find("0") != std::string::npos) number.erase((unsigned)number.find("0"), 1); else number.erase(1, 1); cout << number; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, i, l = 0, r, tmp; string rs; cin >> n; r = n - 1; long long a[n]; for (i = 0; i < n; i++) cin >> a[i]; tmp = 0; while (l != r) { if (a[r] > tmp && (a[r] < a[l] || a[l] ...
2
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = acos(-1); const int oo = 1e9, bpr = 1e9 + 7, N = 2e5 + 100; int n, m, q, x[N], y[N], l[N], r[N], s[N], t[N]; vector<int> g[N]; int d[1001][1001]; int ans[N]; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); scanf("%d%d...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; long long int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] = a[i] % 3; } int c0 = 0, c1 = 0, c2 = 0; for (int i = 0; i < n; i++) { if (a[i] == 0) c0++; else if (a[i] == 1) c1++; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 305; int A[N], f[3], n, s; inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { scanf("%d%d", &n, &s); for (int i = 1; i <= n; ++i) scanf("%d", A + i), ++f[A[i] - 3]; int res(~0u >> 2), ri, rk, rj; for (int i = s / n; i >= 0; --i...
8
#include <bits/stdc++.h> using namespace std; bool sortcoll(vector<long long int> &v1, vector<long long int> &v2) { return v1[1] < v2[1]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, m; cin >> n >> m; long long int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; ...
3
#include <bits/stdc++.h> int N, K, f[2005][2005], g[2005][2005]; char S[2005]; void doit() { scanf("%d%d%s", &N, &K, S + 1), f[0][0] = g[0][0] = 1; for (int i = 1; i <= N; i++) for (int j = 0; j <= K; j++) { f[i][j] = 1ll * g[i - 1][j] * (S[i] - 97) % 1000000007; for (int k = 0, t; k < i && (t = (k ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 210; int ch[maxn][26], End[maxn], fail[maxn]; int num[maxn], q[maxn], head, tail, cnt; char c[maxn]; void insert(int opt) { int Now = 0; for (int i = 1; c[i]; i++) { if (!ch[Now][c[i] - 'a']) ch[Now][c[i] - 'a'] = ++cnt; Now = ch[Now][c[i] - 'a'...
8
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } int main() { double m, n; cin >> m >> n; long double ans = 0; for (double i = 1; i <= m; i+...
4
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; void solve() { int alph[26], alph1[26]; for (int i = 0; i < 26; i++) alph[i] = alph1[i] = 0; int a, b, l, r, dif, ans1 = INF; string s, s1; cin >> a >> b >> l >> r; --l; --r; char d; for (char c = 'a'; c - 'a' < a; c++) { if (...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int d[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; struct node { long long val, last; } dp[maxn][3]; long long h1[maxn], h2[maxn]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) scanf("%I64d", &(h1[i])); for (int i = 1; i <= n; i++) s...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using iii = tuple<int, int, int>; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N; bool f = false; string A, B; cin >> N >> A >> B; int C[26...
6
#include <bits/stdc++.h> int main() { int n, i, j; scanf("%d", &n); for (i = 0; i < n / 2 + 1; i++) { for (j = 0; j < n / 2 - i; j++) { printf("*"); } for (j = 0; j < (i * 2 + 1); j++) { printf("D"); } for (j = 0; j < n / 2 - i; j++) { printf("*"); } printf("\n"); }...
0
#include <bits/stdc++.h> using namespace std; long long int mod = 998244353; long long int INF = 1e18; long long int po(long long int a, long long int b) { long long int re = 1; while (b) { if (b % 2 == 1) { re = (re * a); } a = (a * a); b >>= 1; } return re; } vector<long long int> pri; b...
9
#include <bits/stdc++.h> namespace FastRead { char __buff[5000]; int __lg = 0, __p = 0; char nc() { if (__lg == __p) { __lg = fread(__buff, 1, 5000, stdin); __p = 0; if (!__lg) return EOF; } return __buff[__p++]; } template <class T> void read(T& __x) { T __sgn = 1; char __c; while (!isdigit(__c...
7
#include <bits/stdc++.h> using namespace std; set<long long int> s; void sieve() { std::vector<bool> arr(1000001, true); for (long long int i = 3; i * i < 1000001; i += 2) { if (arr[i] == true) { for (long long int j = i * i; j <= 1000001; j += i) arr[j] = false; } } s.insert(2); for (long long ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[1005], x, i; cin >> n; for (i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); x = arr[n - 1] - arr[0]; x = x + 1; x = x - n; cout << x << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; void ri(int &a) { a = 0; register int x = getchar_unlocked(); bool neg = false; while (x < '0' || x > '9') { if (x == '-') neg = true; x = getchar_unlocked(); } while (x >= '0' && x <= '9') { a = (a << 3) + (a << 1) + (x - '0'); x = getchar_unloc...
6
#include <bits/stdc++.h> #pragma GCC optimize(3, "inline", "Ofast") using namespace std; const int N = 5e5 + 100; int n, c0 = 0, c1 = 0, nxt[N]; char s[N], t[N]; void cal_fail() { int k = -1; nxt[1] = 0; for (int i = 2; i <= n; i++) { while (t[k + 1] != t[i] && k) k = nxt[k]; if (t[k + 1] == t[i]) ++k; ...
4
#include <bits/stdc++.h> using namespace std; void _IOS() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); } const long long mod = 1e9 + 7; long long n, m, k, w; long long a[100009]; bool ch(char s) { return s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u'; } bool palid(stri...
1
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k, c = 0; cin >> n >> k; long long int a[2 * n + 2]; for (long long int i = 1; i <= 2 * n + 1; ++i) { cin >> a[i]; } for (long long int i = 1; i <= 2 * n + 1; ++i) {...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const double eps = 1e-8; const double PI = acos(-1.0); const int maxn = 1e5 + 10; long double a[20]; string s[] = {"x^y^z", "x^z^y", "(x^y)^z", "(x^z)^y", "y^x^z", "y^z^x", "(y^x)^z", "(y^z)^x", "z^x^y", "z^y^x", "(z^x)^y", "...
8
#include <bits/stdc++.h> using namespace std; int n; int a[100009]; int b[100009], c[100009]; int used[100009]; int main() { cin >> n; if (n == 1) { cout << 0 << endl << 0 << endl << 0 << endl; return 0; } if (n % 2 == 0) { cout << -1 << endl; return 0; } for (int i = 1; i <= n - 2; i++) a[i...
2
#include <bits/stdc++.h> using namespace std; vector<vector<int>> v, dp; vector<int> vis, dep; int dfs(int x) { vis[x] = 1; for (int i = 0; i < v[x].size(); i++) { int y = v[x][i]; if (vis[y] == 0) { dp[y][0] = x; dep[y] = dep[x] + 1; dfs(y); } } return 0; } int lift(int x, int val...
6
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &a) { return out << "(" << a.first << "," << a.second << ")"; } template <class A> ostream &operator<<(ostream &out, const vector<A> &a) { for (const A &it : a) out << it << " "; return out...
4
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> &p) { out << p.first << " " << p.second; return out; } ...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int main() { long long n, k; cin >> n >> k; if (n < k) { if (k % n != 0) cout << k / n + 1; else cout << k / n; } else cout << 1; return 0; }
1
#include<algorithm> #include<iostream> #include<sstream> #include<cstring> #include<iomanip> #include<cstdio> #include<string> #include<vector> #include<queue> #include<deque> #include<cmath> #include<map> #include<set> #define AC 0 #define endl '\n' #define PI acos(-1) #define Please return #define int long long using...
4
#include <bits/stdc++.h> using namespace std; int n; int m; ; int vis[100005]; int c[100005]; vector<int> v[100005]; int dfs(int i) { vis[i] = 1; int p = c[i]; for (int j = 0; j < v[i].size(); j++) { if (vis[v[i][j]] == 0) p = min(p, dfs(v[i][j])); } return (p); } int main() { ios_base::sync_with_stdio(...
2
#include <bits/stdc++.h> using namespace std; vector<long long> tab; int n, k; bitset<60> dp[60]; bool check(long long val) { for (int i = 0; i <= n; ++i) dp[i].reset(); dp[0][0] = 1; for (int i = 1; i <= k; ++i) { for (int s = 1; s <= n; ++s) { if (!dp[s - 1][i - 1]) continue; for (int j = s; j <...
5
#include <bits/stdc++.h> using namespace std; const int oo = 1234567890; pair<int, int> g[1010][1010], h[1010][1010]; int f[1010][1010], a[1010], n; vector<string> vv; string toStr(int first) { string ret = ""; while (first > 0) { char t = (first % 10) + '0'; ret = t + ret; first /= 10; } return ret...
6
#include <bits/stdc++.h> using namespace std; bool isPalindrom(string s) { if (equal(s.begin(), s.begin() + s.size() / 2, s.rbegin())) return true; return false; } int main() { string s; cin >> s; while (s[0] == '0') { s.erase(0, 1); } while (s[s.size() - 1] == '0') { s.erase(s.size() - 1, 1); }...
0
#include <bits/stdc++.h> using namespace std; int type[200005]; int tim[200005]; map<int, pair<int, int>> mapp; void solve() { mapp.clear(); int n; long long t, a, b; int e = 0, h = 0; scanf("%d %lld %lld %lld", &n, &t, &a, &b); for (int i = 0; i < n; i++) scanf("%d", &type[i]); for (int i = 0; i < n; i++...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n][n]; int cur = n * n, ans = 0; for (int i = n - 1; i >= 0; i--) { for (int j = n - 1; j >= k - 1; j--) { a[i][j] = cur; cur--; } ans += (cur + 1); } for (int i = n - 1; i >= 0; i--) { fo...
2
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const long long inf = 1e15; int n; long long a[N]; bool was[N]; long long f[N]; long long maxf; vector<int> g[N]; void dfs(int u, int p) { f[u] = a[u]; for (int v : g[u]) { if (v == p) continue; dfs(v, u); if (f[v] > 0) { f[u] +...
8
#include <bits/stdc++.h> using namespace std; int main() { long long int i, n, nd, a[100005], sum; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); sum = a[0]; nd = 1; for (i = 1; i < n; i++) { if (a[i] >= sum) { sum += a[i]; nd++; } } cout << nd; return 0...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; struct info { long long v1, v2, v3; } tree[maxn << 2]; long long sum; int n, m; long long d[maxn], h[maxn]; info operator+(const info &a, const info &b) { info ret; ret.v1 = max(a.v1, b.v1); ret.v2 = max(a.v2, b.v2); ret.v3 = max(a.v3, b.v...
7
#include <bits/stdc++.h> using namespace std; ifstream in("input.txt"); ofstream out("output.txt"); int main() { int mas1[105]; int mas2[105][105]; int n; scanf("%i", &n); for (int i = 0; i < n; i++) { scanf("%i", &mas1[i]); for (int j = 0; j < mas1[i]; j++) { scanf("%i", &mas2[i][j]); } }...
2
#include <bits/stdc++.h> int main() { int N, K; scanf("%d%d", &N, &K); int ret = N - 1; int max = 0; int part = 0; for (int i = 0; i < K; i++) { int M; scanf("%d", &M); int a[100001]; if (M == 1) { scanf("%d", &a[0]); continue; } part += M - 1; for (int j = 0; j < M; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 200010; int n; long long w[N], h[N], c[N]; map<long long, map<long long, long long> > cnt; bool flag = 0; vector<pair<long long, long long> > vc; long long Gcd(long long a, long long b) { if (!a) return b; if (!b) return a; return Gcd(b, a % b); } bool I...
9
#include <bits/stdc++.h> using namespace std; void taskA1() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int q = sqrt(n), x = n; for (int i = (2); i <= (q); i++) if (n % i == 0) { x = i; break; } n = n + x + (k - 1) * 2; cout << n << "\n"; } ret...
0
#include <bits/stdc++.h> using namespace std; double p[100]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%lf", p + i); sort(p, p + n); double best = 0.0; for (int i = 0; i < n; ++i) { double x = 0.0, y = 1.0; for (int j = i; j < n; ++j) x = x * (1.0 - p[j]) + y * p[...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int t; cin >> t; while (t--) { long long int n, i, c = 0, x, p = 0; cin >> n; long long int a[n]; for (i = 0; i < n; ++i) a[i] = 0; for (i = 0; i < n; ++i) { cin >> x; ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, i, j, ans = 0, product = 1; ; cin >> n >> k; if (k >= n / 2) { cout << n * (n - 1) / 2; return 0; } for (i = 0; i < k; i++) { ans = ans + n - 1 - i; } ans = ans + (n - 2 * k) * (k); product = k * (k - 1) / 2; ans ...
2
#include <bits/stdc++.h> using namespace std; const long long int maxN = 1e5 + 10; long long int n, i, a[maxN], mx, cnt, nxt; stack<pair<long long int, long long int> > st; int main() { cin >> n; for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = n - 1; i >= 0; i--) { while (!st.empty()...
5
#include <bits/stdc++.h> using namespace std; int main() { vector<string> s1, s2, s; int n; string k; cin >> n; s1.push_back("purple"); s2.push_back("Power"); s1.push_back("green"); s2.push_back("Time"); s1.push_back("blue"); s2.push_back("Space"); s1.push_back("orange"); s2.push_back("Soul"); ...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 500010; int ara[MAX]; vector<pair<int, int> > V; vector<int> P; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) return a.second < b.second; return a.first > b.first; } int main() { int n, k; scanf("%d %d", &n, &k); for (int i...
3
#include <bits/stdc++.h> using namespace std; const int N = 1005, mod = 1000 * 1000 * 1000 + 7; long long dp[N][N]; int main() { int n, m, x; cin >> n >> m >> x; if (n > m) { cout << 0; return 0; } dp[0][0] = 1; for (int i = 1; i <= m; i++) { for (int j = n; j >= 0; j--) { for (int k = j; ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 501; vector<int> g[maxn]; int was[maxn], st = -1, p[maxn]; vector<int> cycle; int dfs(int v, int s, int f, int par) { p[v] = par; was[v] = 1; int ans = 0; for (int x : g[v]) { if (v != s or x != f) { if (was[x] == 1) ans++, p[x] = ...
7
#include <bits/stdc++.h> int main() { int r; int p; int i, j; scanf("%d", &r); scanf("%d", &p); i = 1; j = ((4 * r) / 2) + 1; while (i <= ((4 * r) / 2) || j <= p) { if (j <= p) { printf("%d ", j); j++; } if (i <= 2 * r) { if (i <= p) { printf("%d ", i); } ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, t = 0, p = 0; cin >> n; int a[n]; for (int k = 0; k < n; k++) { cin >> a[k]; if (a[k] > 0) { p = p + a[k]; } if ((a[k] == -1)) { if (p <= 0) { t = t + 1; } else p = p - 1; } } cout << t; ...
0
#include <bits/stdc++.h> using namespace std; const long long cg = 1e9; const int maxn = 2e5 + 100; struct Node { int x, f; int op; }; vector<Node> nodes; map<long long, int> dp; bool cmp(Node a, Node b) { return a.x < b.x; } int main() { int n, x, w, pre = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { ...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; const int md = (2 << 30); const long long oo = 1e14; const double pi = acos(-1); int dy[] = {0, 1, 0, -1}; int dx[] = {1, 0, -1, 0}; const int N = 1e9 + 5; bool Is_Prime(int x) { if (!(x & 1) && x != 2) retur...
3
#include <bits/stdc++.h> using namespace std; const int LIMIT = 1e2 + 7; const int INF = 1e9 + 7; long long n, dp[2][LIMIT][LIMIT], a[LIMIT]; int main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) { scanf("%lld", a + i); } for (int i = 0; i < LIMIT; i++) { for (int j = 0; j < LIMIT; j++) { d...
5
#include <bits/stdc++.h> using namespace std; const int maxL = 1024 + 5; bool adj[20][20]; bool bit[maxL][20]; int n, e, k; int cont[maxL], BIT[20]; long long dp[maxL][maxL]; inline void init() { for (int i = 0; i < (1 << n); i++) { int tmp = i; for (int j = 1; j <= n; j++) { bit[i][j] = tmp & 1; ...
8
#include <bits/stdc++.h> using namespace std; long long minbranch(long long n, long long b) { long long score = 0; long long p = 0; while (n > 0) { long long a = pow(b, p); long long k = min(n, a); n -= k; score += (p + 1) * k; p++; } return score; } int32_t main() { ios::sync_with_stdio...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int mxN = 100010; vector<int> g[mxN]; int vis[mxN]; int h[mxN]; int mn[mxN], mnI[mxN]; int nodeInCycle[mxN]; bool f = false; vector<int> res; vector<int> at; vector<int> st; void dfs(int v) { assert(!vis[v]); vis[v] = 1; mn[v] =...
9
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") const long long maxn = 70 + 10, N = 2e6 + 90, SQ = 300, base = 1999, mod = 1e9 + 7, INF = 1e9 + 1, lg = 25; const long double eps = 1e-4; long long n, dp[maxn][maxn][maxn][2], sz1, sz2, sz3; string s; inline void pre() { for (...
8
#include <bits/stdc++.h> using namespace std; struct node { int l, r, ind; } a[400001]; int arr[300005]; bool check(node a, node b) { if (a.l == b.l) return a.r < b.r; return a.l < b.l; } priority_queue<int, vector<int>, greater<int> > pq; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i,...
6
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; long long a[n], b[m]; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } long long sumn = 0; for (int i = 0; i < m; i++) { cin >> b[i]; sumn += b[i]; } long lo...
4
#include <bits/stdc++.h> using namespace std; const int N = 5010; const int M = 300100; const int INF = 0x3f3f3f3f; const int mod = 1000000007; void MOD(long long &a) { if (a >= mod) a -= mod; } void MOD(long long &a, long long c) { if (a >= c) a -= c; } void ADD(long long &a, long long b) { a += b; MOD(a); } v...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, t, c, d = 0, j, e = 0; cin >> n >> t >> c; int i = 0, a[n]; while (i < n) { cin >> a[i]; i++; } for (i = 0; i < n; i++) { if (a[i] <= t) { e++; } else { if (a[i - 1] <= t && e >= c) d = d + e - c + 1; e = 0; ...
1
#include <bits/stdc++.h> const int P = 1e9 + 7; const int N = 2e5 + 5; const int M = 1e6 + 5; int cnt[M], p[M]; int n, A[N], X[M]; long long ans = 0; int max(int a, int b) { return a > b ? a : b; } int MAX = 0; void Init() { p[0] = 1; for (int i = 1; i <= MAX; i++) p[i] = p[i - 1] * 2 % P, X[i] = i; for (int i = ...
7
#include <bits/stdc++.h> using namespace std; string ara[105]; bool vis[100][100], cycle; string str, str2; long long n, m; long long dx[] = {0, 0, 1, -1}; long long dy[] = {1, -1, 0, 0}; void dfs(char ch, long long r, long long c, long long sr, long long sc) { if (r >= n || c >= m || r < 0 || c < 0) return; if (ar...
3
#include <bits/stdc++.h> int main() { long long unsigned int days, a, b; scanf("%llu", &days); scanf("%llu", &a); scanf("%llu", &b); int w; long long unsigned int aux; for (int i = 0; i < days; i++) { scanf("%i", &w); aux = ((w * a) % b) / a; printf("%llu ", aux); } return 0; }
3
#include <bits/stdc++.h> using namespace std; vector<int> diff; vector<int> idOfDiff[2005]; int main() { ios::sync_with_stdio(0); int n, x; cin >> n; for (int i = 0; i < n; i++) { cin >> x; diff.push_back(x); idOfDiff[x].push_back(i + 1); } sort(diff.begin(), diff.end()); diff.resize(unique(di...
2
#include <bits/stdc++.h> using namespace std; int prime[33000]; int cntPr = 0; void init() { for (int i = (2), ei = (33000); i < ei; i++) { bool ok = 1; for (int j = 0; j < cntPr && prime[j] * prime[j] <= i; j++) if (i % prime[j] == 0) { ok = 0; break; } if (ok) prime[cntPr++] ...
8
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, flag = 0, sum = 0; cin >> a >> b; int A[a][b]; for (c = 0; c < a; c++) { for (d = 0; d < b; d++) { cin >> A[c][d]; } } for (c = a - 1; c >= 0; c--) { for (d = b - 1; d >= 0; d--) { if (A[c][d] == 0) { ...
1
#include <bits/stdc++.h> using namespace std; bitset<101> b; int n; pair<int, int> A[100]; void dfs(int i) { if (b[i]) return; b[i] = 1; for (int j = 0; j < n; j++) { if (i == j) continue; if ((A[j].first == A[i].first || A[j].second == A[i].second) && !b[j]) dfs(j); } } int main() { ios_base::s...
2
#include <bits/stdc++.h> using namespace std; int32_t MOD(int32_t x, int32_t y) { return x % y < 0 ? x % y + y : x % y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int32_t T; string s; for (cin >> T >> s; T--; cin >> s) { if (s[0] == 'R' && ('0' <= s[1] && s[1] <= '9') && s.find('...
4
#include <bits/stdc++.h> using namespace std; char *p1, *p2, buf[100000]; int read() { int x = 0, f = 1; char ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 10000, stdin), p1 == p2) ? EOF : *p1++); while (ch<48 | ch> 57) { if (ch == '-') f = -1; ch = (p1 == p2 && (p2 = (p1 ...
7
#include <bits/stdc++.h> using namespace std; long double PI = 3.14159265358979323846; const long long modo = 998244353; const long long inf = 1e16; const long long ms = (1e6) + 5; char ar[ms]; int tt[ms] = {0}; int ss[ms] = {0}; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); st...
4
#include <bits/stdc++.h> using namespace std; signed main() { long long n, sm = 0; cin >> n; vector<long long> v(n); vector<long long> s(n); for (long long i = 0; i < n; i++) { cin >> v[i]; sm += v[i]; s[i] = v[i]; } sort(s.begin(), s.end()); vector<long long> res; for (long long i = 0; i ...
2
#include <bits/stdc++.h> int num, tot, hd, top = 0; std::vector<int> vec; int p[35], cnt[35], st[100005]; inline int read() { register int x = 0, f = 1; register char s = getchar(); while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = x * 10 + s - ...
6
#include <bits/stdc++.h> using namespace std; int k[105]; int main() { int n, a, b, x, i; cin >> n >> a >> b; for (i = 1; i <= a; i++) { cin >> x; k[x] = 1; } for (i = 1; i <= b; i++) { cin >> x; if (k[x]) continue; k[x] = 2; } for (i = 1; i <= n; i++) cout << k[i] << ' '; return 0; ...
0
#include <bits/stdc++.h> using namespace std; const long long inf = (1ll << 62) - 1; const long long MOD = 998244353; const int MAX = 2e9 + 10; const long long int N = 3e5 + 10; using namespace std; int bPow(int a, int b) { int res = 1; while (b) { if (b & 1ll) { res = 1ll * res * a % MOD; } b >>=...
4
#include <bits/stdc++.h> using namespace std; int n, i, j, t, res, a[1001]; int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { t = 0; for (j = i; j >= 1; j--) if (a[j] >= a[j - 1]) t++; else break; for (j = i + 1; j < n; j++) if (a[j...
1
#include <bits/stdc++.h> using namespace std; ifstream fin("test.in"); ofstream fout("test.out"); int core[102]; int cell[102][102]; bool cellB[102]; int n, k, m; int instr[102][102]; int main() { int i, j, l, celula; cin >> n >> m >> k; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cin >> instr...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 7; struct Node { int l, r, minn, lazy; int mid() { return (l + r) >> 1; } } tree[MAXN << 2]; void PushUp(int rt) { tree[rt].minn = min(tree[rt << 1].minn, tree[rt << 1 | 1].minn); } void PushDown(int rt) { if (tree[rt].lazy) { tree[rt << 1...
4
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0; int i = 0; int n; scanf("%d", &n); char s[n]; cin >> s; for (i = 0; i < n; i++) { if (s[i] == s[i + 1]) { sum++; } } printf("%d", sum); return 0; }
0
#include <bits/stdc++.h> using namespace std; inline float minOf(float x, float y) { return (x < y ? x : y); } inline float maxOf(float x, float y) { return (x > y ? x : y); } float mabs(float x) { if (x < 0.0) return -x; return x; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; int a[4005...
5
#include <bits/stdc++.h> const int N = 5e3, Q = 7e4; int n, q, a[N], ans[Q]; std::vector<std::pair<int, int>> move; struct data { std::vector<int> v; std::map<std::pair<int, int>, int> map; } node[N * 4]; void build(int l, int r, int id = 1) { std::vector<int> &v = node[id].v; if (l == r) { v.push_back(a[l]...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int a[maxn][maxn], n, m; int levo[maxn][maxn]; int desno[maxn][maxn]; int gore[maxn][maxn]; int dole[maxn][maxn]; void fix(int r, int c) { a[r][c] = !a[r][c]; for (int i = 1; i < m; ++i) { if (a[r][i - 1]) levo[r][i] = levo[r][i - 1] + 1...
6
#include <bits/stdc++.h> using namespace std; int n, c[3010]; struct info { int x, y; }; struct as { int a, b, c; } ans; struct node { int x, id; } a[3010]; inline bool cmp(node a, node b) { return a.x > b.x; } inline info max(info a, info b) { if (a.x < b.x) return b; return a; } struct seg { int lt[12010]...
7
#include <bits/stdc++.h> using namespace std; long long mulMod(long long a, long long b, long long mod) { long long res = 0; while (b > 0) { if (b % 2 == 1) res = (res + a) % mod; a = (a + a) % mod; b /= 2; } return res; } long long powMod(long long base, long long exp, long long mod) { long long ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; cin >> a; cin >> b; vector<long long int> a1; vector<long long int> b1; for (int i = 1; i <= b; i++) { a1.push_back(i * a); } for (int i = 1; i <= a; i++) { b1.push_back(i * b); } long long int actr = 0; long lo...
3
#include <bits/stdc++.h> using namespace std; int test, n, i, l, r, m, cnt[3]; string s; bool check(int x) { cnt[0] = cnt[1] = cnt[2] = 0; for (i = 0; i < x; i++) cnt[s[i] - '1']++; if (cnt[0] && cnt[1] && cnt[2]) return 1; while (i < n) { cnt[s[i] - '1']++; cnt[s[i - x] - '1']--; if (cnt[0] && cnt[...
2
#include <bits/stdc++.h> using namespace std; int len, n, m, i, j, id[100010], xlh, cnt[100010], f[100010], a[100010], ans; int main() { scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); id[i] = 1; cnt[a[i]]++; } len = min(n * n, n * m); for (i = n + 1; i <= len; i++) a[i] = a[...
5
#include <bits/stdc++.h> using namespace std; void func(void) { freopen("input.c", "r", stdin); freopen("output.c", "w", stdout); } void print(vector<long long> &v) { cout << v.size() << endl; for (int i = 0; i < v.size(); i++) { printf("%lld ", v[i]); } cout << "----------------------------------------...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pi; ll mod=1000000007; ll bpow(ll a, ll b) { ll res=1; while(b>0) { if(b&1) { res=res*a; res%=mod; } a*=a; a%=mod; b>>=1; ...
4