solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct Node { long long M[210]; } dp; struct node { long long M[210][210]; } a; long long n, m; long long b[110]; node operator*(node a, node b) { node ans; for (long long i = 1; i <= 101; i++) { for (long long j = 1; j <= 101; j++...
14
#include <bits/stdc++.h> using namespace std; struct Droite { long long origine, coef; }; struct point { long long vitesse, prix; }; bool compV(point a, point b) { return a.vitesse < b.vitesse || (a.vitesse == b.vitesse && a.prix < b.prix); } deque<Droite> hull; void ajouter(Droite nouvelle) { hull.push_back(no...
20
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; long long a[n], b[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; long long min1 = 1000000000000000000; for (int i = 0; i < n; i++) { long long maxm = -1000000000000000000; f...
6
#include <bits/stdc++.h> using namespace std; struct Node { int id, fail, next[26]; void init() { id = -1; fail = -1; memset(next, 0, sizeof(int) * 26); } } node[2000050]; int e; void insert(char *str, int id) { int len = strlen(str); int pos = 0; for (int i = 0; i < len; i++) { int tmp = st...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, c, m = 1e8, p = 0; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; s[i] += s[i]; } for (int i = 0; i < n; i++) { c = 0; string a = s[i].substr(0, s[i].size() / 2); for (int j = 0; j < n; j++) { ...
5
#include <bits/stdc++.h> using namespace std; const int max_n = 200005; const int inf = 0x3f3f3f3f; string s; int a[max_n]; int n; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> s; for (int i = 0; i < n - 1; i++) { if (s[i] == '0') continue; int j = i; while (j < n - 1 && s[j...
6
#include <bits/stdc++.h> using namespace std; int n, A[2100005]; int Tmp[2100005], Vis[2100005]; int main() { int T; scanf("%d", &T); while (T--) { int Ans = 0, Now = 1, Sum = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &A[i]); Vis[i] = 0; } sort(A + 1, A + n + 1...
5
#include <bits/stdc++.h> using namespace std; int a[100010]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; int v = -1, k = 0; for (int j = 0; j < 32; ++j) { int t = -1, c = 0; for (int i = 0; i < n; ++i) if (a[i] & (1 << j)) { t &=...
10
#include<bits/stdc++.h> typedef int LL; typedef double dl; #define opt operator #define pb push_back #define pii std::pair<LL,LL> const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f; LL Read(){ LL x(0),f(1); char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0' && c<='9'){ x=(x<<3ll...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 100001; int N; long long int val[MAXN], incr[MAXN], decr[MAXN]; vector<int> way[MAXN]; void dfs(int nd, int dad) { for (vector<int>::iterator it = way[nd].begin(); it != way[nd].end(); it++) if (*it != dad) { dfs(*it, nd); incr[nd] = max(i...
10
#include <bits/stdc++.h> using namespace std; using ll = long long; using pi = pair<int, int>; using vi = vector<int>; using vl = vector<ll>; void solve() { ll n; cin >> n; vl num(n); for (long long int i = (0); i <= (n - 1); i++) { cin >> num[i]; } sort(num.begin(), num.end()); for (long long int i =...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int a0 = 0; a0 < n; ++a0) { string s; cin >> s; s.erase(s.begin(), s.begin() + 4); int l = s.size(); int x = stoi(s); int start = 1989, ten = 10, f = 0; for (int i = l - 1; i > 0; --i) { f += ten; ...
12
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> deg; signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, s; cin >> n >> s; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; deg[a]++; deg[b]++; } int l = 0; for (int i = 1; i ...
9
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T0> void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } bool isPowerOfTwo(int x) { return x &...
7
#include <bits/stdc++.h> using namespace std; const int mxn = 2e5 + 5; int n, mxd, s[mxn]; int main() { scanf("%d", &n); for (int(i) = (int)(1); (i) <= (int)(n); (i)++) { scanf("%d", &s[i]); s[i] += s[i - 1]; } mxd = s[n]; for (int(i) = (int)(n - 1); (i) >= (int)(2); (i)--) mxd = max(mxd, s[i] - m...
14
#include <bits/stdc++.h> using namespace std; int b[205][205], c[205][205], a[205][205], xy[12][2], n, m, q, cnt, t, boo[2000]; char s[2000000]; void add(int bo) { if (boo[bo]) return; boo[bo] = 1; for (int i = 0; i <= 9; i++) if ((bo | (1 << i)) == bo) add(bo - (1 << i)); } void dfs(int x, int y, int bo)...
17
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 314; const int INF = 1e9; const double PI = acos(-1); const int MOD = 1e9 + 7; const double eps = 1e-9; int d[N]; pair<int, int> p[N]; int ans[N]; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first < b.first) return 1; if (b.first < a.first) ...
7
#include <bits/stdc++.h> using namespace std; int ans[128]; int main() { for (int i = 1; i <= 100; i++) { ans[i] = 10000; if (i % 4 == 0) { for (int n = 4;; n += 2) { int hn = n / 2 - 1; int maxval = 0; if (hn % 2) { maxval = 4 * ((hn * hn + 1) / 2); } else { ...
9
#include <bits/stdc++.h> const long long maxn = 1e5 + 10; inline long long Max(long long a, long long b) { return a > b ? a : b; } inline long long Min(long long a, long long b) { return a > b ? b : a; } inline long long read() { long long f = 1, r = 0; char c = getchar(); while (!isdigit(c)) { if (c == '-') ...
15
#include <bits/stdc++.h> using namespace std; int e[100 + 1]; int main() { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int cnt = 0; for (int i = 1; i <= n; i++) { if (e[i] == 1) continue; int dem = 1; for (int j = i + 1; j <= n; j++) i...
6
#include <bits/stdc++.h> using namespace std; long long n, x, y, v[200005], d[200005], pos[200005], f[200005]; vector<int> grafo[200005]; void dfs(int nodo, int last) { f[nodo] = last; for (int i = 0; i < grafo[nodo].size(); i++) { if (grafo[nodo][i] != last) { d[grafo[nodo][i]] = d[nodo] + 1; dfs(g...
9
#include <bits/stdc++.h> using namespace std; long long int mod = 998244353; int main() { string s; cin >> s; int n = s.size(); vector<long long int> power_2(n + 1, 1); for (int i = 1; i < n + 1; i++) { power_2[i] = (2 * power_2[i - 1]) % mod; } vector<long long int> cnt(n + 1, 0); for (int i = 0; i...
18
#include <bits/stdc++.h> using namespace std; int a[35][35]; int main() { int n, x; scanf("%d", &n); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) scanf("%d", a[i] + j); x = (n + 1) / 2; int ans = -999999999; for (int i = 0; i < 1 << x; ++i) { int sum = 0; long long j = i & 1; for ...
21
#include <bits/stdc++.h> using namespace std; int n, m, k; int main() { cin >> k, n = 1 << k; vector<vector<long long>> a(n, vector<long long>(n)); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) scanf("%lld", &a[i][j]); cin >> m; vector<pair<int, int>> V; for (int i = 1, k1, k2; i <= m; ++i) ci...
27
#include <bits/stdc++.h> using namespace std; int main() { int i, N, t = 0, x; cin >> N; for (i = 1; i <= N; i++) { cin >> x; t += x * i; } cout << t << endl; return 0; }
12
#include <bits/stdc++.h> int main() { int n; char s[105]; scanf("%d", &n); scanf("%s", s + 1); int tot = 0; for (int i = 1; i <= n; i++) { if (s[i] == '1') tot++; } if (tot) printf("1"); for (int i = 1; i <= n - tot; i++) { printf("0"); } }
0
#include <bits/stdc++.h> template <typename T> inline T gcd(T a, T b) { T c; while (b) { c = b; b = a % b; a = c; } return a; } template <typename T> T lcm(T a, T b) { return b * (a / gcd(a, b)); } template <typename T> inline T pow2(T base, T n) { T ansp = 1; while (n) { if (n & 1) ansp *...
0
#include <bits/stdc++.h> using namespace std; struct MSTree { vector<vector<int>> tree; int n; MSTree(){}; MSTree(int n_) { n = log2(n_) + 1; n = 1 << n; tree.resize(2 * n); } void build(vector<int>& a) { for (int i = n; i < a.size() + n; i++) { tree[i].push_back(a[i - n]); } f...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 30; int num[maxn], n; int main() { scanf("%d", &n); map<int, int> maps; for (int i = 1; i <= n; i++) { scanf("%d", &num[i]); maps[num[i]] = i; } sort(num + 1, num + 1 + n); int ans[maxn]; for (int i = 2; i <= n; i++) ans[maps[num[i - 1...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; char c[] = {'G', 'B', 'I', 'V'}; int rem = n - 7; string ans = "ROYGBIV"; for (int i = 0; i < rem; ++i) { ans += c[i % 4]; } cout << ans << endl; }
4
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive...
18
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using mti = vector<vector<int>>; using vl = vector<ll>; using mtl = vector<vector<ll>>; using pi = pair<int, int>; using pl = pair<ll, ll>; template <typename T> using heap = priority_queue<T, vector<T>, ...
8
#include <bits/stdc++.h> using namespace std; long long w[305][305], a[305], b[305]; inline long long MOD(long long a, long long b) { a = a % b; a += b; return a % b; } inline long long ABS(long long x) { return x < 0 ? x * -1 : x; } inline long long Min(long long a, long long b) { return a < b ? a : b; } inline ...
14
#include <bits/stdc++.h> using namespace std; int lpf[10001000], mob[10001000], lgt[10001000]; int prm[10001000], pcnt; int main() { int n; long long ans = 0; scanf("%d", &n); for (int i = 2; i <= n; i++) { int tmp = n / i; if (!lpf[i]) { prm[pcnt++] = i; lpf[i] = i; mob[i] = 1; ...
19
#include <bits/stdc++.h> using namespace std; long long n; vector<long long> a, parent, curr, cap; long long find(long long n) { if (parent[n] == n) return n; return parent[n] = find(parent[n]); } long long add(long long p, long long x) { long long par = find(p); while (x) { long long rem = cap[par] - curr[...
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int main() { int n, k; cin >> n >> k; char s[MAXN]; cin >> s; stack<char> c; int cnt = 0; char ans[MAXN] = {0}; int len = n; for (int i = 0; i < n; i++) { if (!c.empty() && s[i] == ')' && c.top() == '(' && len > k) { an...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); printf("%d", n); for (int i = 1; i < n; i++) printf(" %d", i); puts(""); }
9
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; long long ans = 0, sum = 0, mn = 1e18, mx = 0, cnt = 0; const long long M = 1000000007; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } lo...
6
#include <bits/stdc++.h> using namespace std; int n, d, m; int a[105]; int main() { cin >> n >> d >> m; for (int i = 1; i <= n; ++i) a[i] = 1; int tmp = n & 1; for (int i = 1; i <= n; ++i) { while (i & 1 and a[i] < m and tmp < d) a[i]++, tmp++; while (!(i & 1) and a[i] < m and tmp > d) a[i]++, tmp--; ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long n, m; cin >> n >> m; vector<int> v(n); vector<long long> pref(n + 1); pref[0] = 0; for (int i = 0; i < n; i++) { cin >> v[i]; pref[i + 1] = pref[i] + v[i]; } vector<int> ans; for (int i = 0; i ...
16
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long l, r, x, y, k; cin >> l >> r >> x >> y >> k; for (int cost = x; cost <= y; cost++) { long long experience = cost * k; if (experience >= l && experience <= r) { cout << "YES"; return 0;...
4
#include <bits/stdc++.h> using namespace std; int n, q, t[4000005], a[1000005], qwq = 0; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } void build(int x, int l, int r) { int md; if (l == r) return (void)(scanf("%d", &t[x])); else md = (l + r) >> 1; build(x << 1, l, md), build(x << 1 | 1, md + 1...
11
#include <bits/stdc++.h> using namespace std; int main() { int t, x1, y1, x2, y2; cin >> t >> x1 >> y1 >> x2 >> y2; char a, b; int x = 0, y = 0; if (x1 - x2 <= 0) a = 'E'; else a = 'W'; if (y1 - y2 <= 0) b = 'N'; else b = 'S'; string s; cin >> s; x = abs(x1 - x2); y = abs(y1 - y2...
4
#include <bits/stdc++.h> using namespace std; int n, c[210], deg[4][210], mark[210]; vector<int> vet[210]; queue<int> q; int cal(int now, int i) { if (now == i) return 0; if (now == 1) { if (i == 2) return 1; return 2; } else if (now == 2) { if (i == 3) return 1; return 2; } else if (i == 1) ...
9
#include <bits/stdc++.h> using namespace std; const int Maxn = 110; const int INF = 0x7f7f7f7f; const double eps = 1e-8; const double pi = 3.1415926535897932384626433832795; bool used[Maxn]; int cnt1[300], cnt2[300]; string s1[Maxn], s2[Maxn]; int main() { int n; bool first = true; ios::sync_with_stdio(0); cin ...
12
#include <bits/stdc++.h> using namespace std; int main() { int f, l, n; cin >> n; n--; if (n == 0) { cin >> f; if (f == 0) { cout << "UP"; return 0; } if (f == 15) { cout << "DOWN"; return 0; } cout << "-1"; return 0; } while (n--) { cin >> f; } ci...
3
#include <bits/stdc++.h> using namespace std; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &o, vector<T> &vec) { for (auto &v : vec) o << v << ' '; return o; } const long long mod = 1e9 + 7; c...
0
#include <bits/stdc++.h> int main() { int i, l; char s[1000]; scanf("%s", s); for (i = 0; i < strlen(s); i++) { if (s[0] >= 97 && s[0] <= 122) s[0] = 65 + s[0] - 97; } printf("%s\n", s); return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<char> v; vector<int> pos; int main() { char ch; int n, i, k, t, j; cin >> n >> k; for (i = 0; i < n; i++) { cin >> ch; v.push_back(ch); if (ch == ')') pos.push_back(i); } for (j = 1; j <= (n - k) / 2; j++) { t = pos[0] - 2 * (j - 1); p...
4
#include <bits/stdc++.h> using namespace std; struct Event { int pos; int type; Event(int _pos, int _type) : pos(_pos), type(_type) {} }; bool operator<(const Event& lhs, const Event& rhs) { if (lhs.pos != rhs.pos) { return lhs.pos < rhs.pos; } return lhs.type < rhs.type; } int main() { int n, m, t; ...
13
#include <bits/stdc++.h> using namespace std; const double tl = 2.9; const int iters = 100; const int dx[4][5] = { {0, 0, 0, 1, 2}, {0, 1, 1, 1, 2}, {0, 1, 2, 2, 2}, {0, 1, 1, 1, 2}}; const int dy[4][5] = { {0, 1, 2, 1, 1}, {2, 0, 1, 2, 2}, {1, 1, 0, 1, 2}, {0, 0, 1, 2, 0}}; double start; int n, m, ans, it; boo...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, i, j, k, ans = 0, x = 0; cin >> n >> m; int edge[8][8]; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) edge[i][j] = 0; } for (i = 0; i < m; i++) { cin >> a >> b; edge[a][b] = 1; edge[b][a] = 1; } for (i = 1; i ...
9
#include <bits/stdc++.h> using namespace std; const int INF = 1e8; int n, a[55][55], dp[51][51][51][51]; char s[55][55]; inline int get(int x1, int y1, int x2, int y2) { return a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1]; } inline int DP(int x1, int y1, int x2, int y2) { if (dp[x1][y1][x2][y2] != ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n = 100000; int m; cin >> m; while (m--) { if (n < 200000) { if (m) cout << n++ << " "; else cout << n << endl; } else cout << 200001 << endl; } return 0; }
4
#include <bits/stdc++.h> int main() { int n; char seats[1000][4]; char dummy; scanf("%d", &n); scanf("%c", &dummy); for (int i = 0; i < n; i++) { scanf("%c%c|%c%c", &seats[i][0], &seats[i][1], &seats[i][2], &seats[i][3]); scanf("%c", &dummy); } int row = -1, col = -1; for (int i = 0; i < n; i+...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, A, B, C; cin >> a >> b >> c >> d; vector<int> v = {a, b, c}; sort(v.begin(), v.end()); A = v[0]; B = v[1]; C = v[2]; int mi = INT_MAX; if (B - d > A) { if (B + d < C) mi = 0; else mi = B + d - C; } else { ...
0
#include <bits/stdc++.h> using namespace std; char bus[5][12]; int main() { int N; cin >> N; for (int i = 1; i < 12; ++i) { for (int j = 1; j < 5; ++j) { if (j == 3 && i != 1) bus[j][i] = '.'; else { if (N) { bus[j][i] = 'O'; N--; } else bus[j]...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int n; int ans; int u[maxn]; int v[maxn]; int w[maxn]; int O[maxn]; int par[maxn]; int num[maxn]; void in(); void solve(); int dsu(int, int); bool cmp(int, int); int root(int); void out(); int main() { ios::sync_with_stdio(false); cout.tie(0);...
19
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long vpow(long long a, long long b, long long p) { if (b == 0) return 1; if (b == 1) return a; long long temp = vpow(a, b / 2, p); temp *= temp; temp %= p; if (b % 2...
6
#include <bits/stdc++.h> using namespace std; long long nCr(long long n, long long r) { vector<vector<long long> > ans(n + 1); ans[0].push_back(1); ans[1].push_back(1); ans[1].push_back(1); for (int i = 2; i <= n; i++) { ans[i].push_back(1); for (int j = 1; j < ans[i - 1].size(); j++) { ans[i].p...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 25005; const int p = 998244353; const int inf = 2147483647; const double eps = 1e-6; const double pi = 3.1415926576; const long long INF = 9223372036854775807ll; int n, x[maxn], y[maxn], dx[maxn], dy[maxn], v[maxn]; double k[maxn], b[maxn], t1, t2, _x, _y; ...
21
#include <bits/stdc++.h> using namespace std; int main() { string a, entrada, subString = "\0", inteiros = "\"", resto = "\""; bool ehInteiro = true; cin >> entrada; for (int i = 0; i <= entrada.size(); i++) { if (i == entrada.size() || entrada[i] == ',' || entrada[i] == ';') { if (ehInteiro && !subSt...
8
#include <bits/stdc++.h> using namespace std; const int OO = (int)2e9; const int MOD = (int)1e9 + 7; const long double Pi = 3.1415926535897932384626433832795; const int N = (int)1e5 + 5; int n, m, a, b, mVVUJ = 0; bool nRJ[7]; int len(int x) { int mVVUJ = 0; while (x > 0) mVVUJ++, x /= 7; return max(1, mVVUJ); } ...
9
#include <bits/stdc++.h> using namespace std; int x, y, p, n; long long r; struct gripper { int dis, m, p; long long r; double disori; bool del = false; } gp[250020]; int lshcnt, lshmcnt, lshm[500050]; double lsh[500050]; priority_queue<pair<int, int> > c[500050]; queue<int> availgp; inline int lowbit(int x) { ...
16
#include <bits/stdc++.h> using namespace std; int n = 0, k = 0; long long a[200003]; int main() { int T = 0; scanf("%d", &T); while (T--) { scanf("%d %d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%lld", a + i); sort(a + 1, a + n + 1); for (int i = n - k + 1; i <= n; ++i) a[i] += a[i - 1]; ...
0
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX / 2; int main() { int n, m; scanf("%d %d", &n, &m); vector<int> a(m + 1); for (int i = 1; i <= m; i++) scanf("%d", &a[i]); vector<int> result(n); result[0] = 1; a[1]--; for (int i = 1; i < n; i++) { int pos = 0; for (int j = 1...
13
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; mt19937 rnd(time(nullptr)); const long long INF = 1e18; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; vector<vector<long long>> a(n, vector<long long...
7
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-9; int FLAGS[1000]; int main(void) { int n; int nums; cin >> n; nums = n * (n - 1) / 2; int vindex = 0; vector<int> A[nums]; vector<int> retA[n]; memset(FLAGS, 0, sizeof(FLAGS)); for (int i = 0; i < (int)(nums); i++) { A[i]...
9
#include <bits/stdc++.h> using namespace std; vector<long long int> adj[100005]; vector<bool> vis; long long int sz; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; ...
7
#include <bits/stdc++.h> using namespace std; int n, x[5], y[5]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]); sort(x + 1, x + n + 1); sort(y + 1, y + n + 1); if (x[1] == x[n] || y[1] == y[n] || n == 1) printf("-1"); else printf("%d", (x[n] - x[1]) * (y[n] -...
3
#include <bits/stdc++.h> using namespace std; int n; int a[100001]; long long m1, m2, m3; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { if (a[i] == a[0]) m1++; if (a[i] == a[1]) m2++; if (a[i] == a[2]) m3++; } if (a[0] == a[1] && a[...
7
#include <bits/stdc++.h> using namespace std; const int N = (int)3e5 + 5; int n, T; int task[N], tim[N], a[2], x[2], cnt[2]; int get_greedy(int T, int c0, int c1) { int get0 = min(c0, T / a[0]); T -= a[0] * get0; int get1 = min(c1, T / a[1]); T -= a[1] * get1; return get0 + get1; } void solve() { int ans = ...
10
#include <bits/stdc++.h> using namespace std; char a[2][2]; string ss[1005][4]; int num = 0; void check(char x[2][2]) { string s; int flag = 0; s += a[0][0]; s += a[0][1]; s += a[1][0]; s += a[1][1]; for (int i = 0; i < num; i++) { for (int j = 0; j < 4; j++) { if (ss[i][j] == s) { flag ...
5
#include <bits/stdc++.h> using namespace std; long long n; long long calc(long long a, long long b, long long c) { if ((a + b + c) % 2) return 0; if (a == c) return 1; if (a == b || b == c) return 3; return 6; } int main() { while (cin >> n) { if (n % 3) puts("0"); else { long long sum = 0...
16
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n; cin >> n; vector<long long> v(n); vector<long long> ans(n); vector<long long> sz(n); for (long long i = 0; i < n; i++) { cin >> v[i]; } long long gnow = -1; for (long long i = 0; i < n; i++) { gnow++; ans[gnow] = v...
13
#include <bits/stdc++.h> const long long oo = 1000000000LL; using namespace std; long long l[5000000], r[5000000], n, m, ans[2000000], ss; long long sum[5000000], tot[5000000], L, R, mid, a[200000], cnt[5000000]; void ask(long long s, long long L, long long R, long long lx, long long rx) { if (!cnt[s]) return; if (...
17
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; long long int dp[200010], prob[200010]; long long int fastPow(long long int a, long long int n, long long int mod) { long long int ret = 1; a %= mod; while (n > 0) { if (n & 1) ret = ret * a % mod; a = a * a % mod; n >>= 1; } ...
13
#include <bits/stdc++.h> using namespace std; int tab[1000100] = {0}; int a[1000100], n, m; vector<int> primes; int vis[1000100] = {0}; int res[1000100] = {0}; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); for (int i = 0; i < n; ++i) if (a[i] <= m) tab[a[i]]++; int maxi...
13
#include <bits/stdc++.h> using namespace std; char n[100005]; int mod() { int len = strlen(n), ret = 0, i, val; for (i = 0; i < len; i++) { val = n[i] - '0'; ret = (val + ret * 10) % 4; } return ret; } int main() { int ans, ret; while (scanf("%s", n) != EOF) { ans = 1; ret = mod(); if (!...
4
#include <bits/stdc++.h> using namespace std; #define Mod 1000000007 #define PI 3.14159265358979323846 #define ll long long #define lld long double #define ld double #define Vi vector<int> #define Vll vector<long long> #d...
8
#include <bits/stdc++.h> using namespace std; inline int read() { int X = 0, w = 1; char ch = 0; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') X = (X << 3) + (X << 1) + ch - '0', ch = getchar(); return X * w; } int n, ans, bt[507], son[507...
24
#include <bits/stdc++.h> using namespace std; vector<long long> v; int main() { int cnt = 0, ans = 0; string s; getline(cin, s); set<char> st; for (int i = 0; i < s.size(); i++) { if (s[i] >= 'a' && s[i] <= 'z') { st.insert(s[i]); } } cout << st.size(); }
0
#include <bits/stdc++.h> using namespace std; const int N = 510; const long long inf = 1e18; int n, m, now; long long ans, pow2[1000]; bitset<N> f[2][70][N], g, tmp; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; const int oo = 1000 * 1000 * 1000; int n, x, Minus, sum, minimum = oo; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < 2 * n - 1; ++i) { cin >> x; sum += abs(x); minimum = min(minimum, abs(x)); if (x <...
10
#include <bits/stdc++.h> using namespace std; struct point { long long x, y; } p[1005]; long long n, r[1005], components, who[1005], num[1005]; vector<long long> pox, poy, vec[4]; bool sx(long long a, long long b) { if (p[a].x == p[b].x) return p[a].y < p[b].y; return p[a].x < p[b].x; } bool sy(long long a, long ...
20
#include <bits/stdc++.h> using namespace std; void solve() { string s; int ind1, ind2, ind3, ind4, colons[550000] = {0}, stlines[550000] = {0}, f1 = 0, f2 = 0; cin >> s; if (s[0] == ':') colons[0] = 1; if (s[0] == '|') stlines[0] = 1; for (int i = 0; i < s.size(); i++) { if...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; int a[maxn]; int c[maxn]; int ans[maxn]; int nxt[maxn]; vector<int> r[maxn]; int pos[maxn]; int lowbit(int x) { return x & (-x); } void add(int x, int k) { while (x <= n + 1) { c[x] += k; x += lowbit(x); } } int query(int x) { ...
16
#include <bits/stdc++.h> using namespace std; const int MAX = 100010; int prm[MAX], a[MAX]; static int c2[MAX], p[MAX]; int main(void) { int n, m, j, k, l, flag = 0; cin >> n >> m; char ch; for (int i = 2; i <= n; i++) if (!prm[i]) for (j = i, prm[i] = i; j <= n; j = j + i) prm[j] = i; for (int i = ...
8
#include <bits/stdc++.h> using namespace std; struct event { int time; int type; int group; }; int n, l, r; event p; int cnt; vector<event> cab; vector<int> answ; bool cmp(event a, event b) { return a.time == b.time ? a.type < b.type : a.time < b.time; } int main() { scanf("%d", &n); for (int i = 0; i < n; ...
9
#include <bits/stdc++.h> using namespace std; struct line { long long int m, c; line() {} line(long long int _m, long long int _c) { m = _m; c = _c; } } ara[200010]; long long int n, a[200010], cst, cost[200010], cum[200010], sz; bool chknthSeg(bool tp, long long int m1, long long int c1, long long int ...
18
#include <bits/stdc++.h> using namespace std; int n, ans, arr[200001], m, mx; map<int, int> ma; int main() { ios::sync_with_stdio(false); cin >> n; arr[1] = 1; ma[1]++; for (int i = 2; i <= n; i++) { cin >> m; arr[i] = arr[m] + 1; ma[arr[i]]++; mx = max(arr[i], mx); } for (int i = 1; i <= ...
7
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, bool> m; map<pair<int, int>, int> dist; map<pair<int, int>, bool> visited; int main() { pair<int, int> init; pair<int, int> final; cin >> init.first >> init.second >> final.first >> final.second; m[init] = true; m[final] = true; int n; cin ...
10
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<doub...
13
#include <bits/stdc++.h> using namespace std; int mn = 3000, mx = 0; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; mx = max(mx, x); mn = min(mn, x); } assert((mx + mn) % 2 == 0); cout << (mx + mn) / 2 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; long long int exp(long long int n, long long int m, long long int md) { long long int a = 1; while (m > 0) { if (m & 1) a = (a * n % md) % md; m /= 2; n = (n * n) % md; } return a % md; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0...
8
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, e, f, q, r, i, j, k, l; vector<long long> v; map<long long, long long> m; cin >> a; for (i = 1; i <= a; i++) { cin >> b; v.push_back(b); } sort(v.begin(), v.end()); l = 0; for (i = 0; i < a; i++) { for (j = i ...
4
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 9, maxn = 100010; long long _pow(long long x, long long n) { long long ret = 1; for (; n; n >>= 1, x = x * x % mod) if (n & 1) ret = ret * x % mod; return ret; } long long n, a, b, K; char s[maxn]; int main() { scanf("%I64d%I64d%I64d%I64d%s...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int inf = 0x3f3f3f3f; struct Node { int a, b, c, ab, bc, abc; int tag; } t[N << 2]; char s[N]; int n, q, y[N]; void push_up(int rt) { t[rt].a = max(t[rt << 1].a, t[rt << 1 | 1].a); t[rt].b = max(t[rt << 1].b, t[rt << 1 | 1].b); t[rt].c...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i, sum = 0, count, c = 0; cin >> n >> k; int p = k; while (k--) { int t; cin >> t; int a[t]; for (i = 0; i < t; i++) cin >> a[i]; if (a[0] == 1) { count = 1; for (i = 0; i < t - 1; i++) { if (a[i + 1] ==...
7
#include <bits/stdc++.h> using namespace std; int rd() { int sum = 0, flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { sum = sum * 10 + ch - '0'; ch = getchar(); } return flag * sum; } int main() { ...
3