solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; inline long long power(long long a, long long b) { long long x = 1; a = a % 1000000007ULL; while (b) { if (b & 1) x = (x * a) % 1000000007ULL; a = (a * a) % 1000000007ULL; b >>= 1; } return x; } inline long long inv(long long a) { return power(a, 10000...
10
#include <bits/stdc++.h> using namespace std; const int N = 200005, M = 998244353; set<pair<int, int> > S[N]; int n, m, l, r, x, opt; struct Tree { int l, r, num, flag1, flag2; } T[N * 4]; void split(int id, int x) { set<pair<int, int> >::iterator iter = S[id].lower_bound(make_pair(x, 1e9)); if (iter == S[id].beg...
17
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double EPS = 1e-6; const int MOD = (int)1e9 + 7; bool Reverse(long long a, long long b) { return a > b; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, mx = 0, mn = 999999999999999999; cin >> n; v...
8
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, M = 12e5 + 5; vector<int> adj[N]; void add(int a, int b) { adj[a].push_back(b); adj[b].push_back(a); } bitset<N> B; char C[N]; int SZ[N], IND[N], CNT[M], n, a, b, TV[21]; long long ans[N], ANS[N]; int get(int x) { return (TV[x]); } int getsize(int...
16
#include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t ; while(t--) { int x ; cin>>x ; int sum = 0 ; int k = 1 ; while(sum<x) { sum += k ; k++ ; } k-- ; if(sum == x || sum-x >=2) { cout<<k<<endl; continue ; } cout<<k+1<<endl; } return 0; }
4
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int main() { long long t;...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k, i; cin >> k; int a[k]; for (i = 0; i < k; i++) cin >> a[i]; sort(a, a + k); int le = a[k - 1]; int ans = max(0, (le - 25)); cout << ans; }
0
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, m; struct point { long long x, y; int id; }; point a[N], b[N]; int cmp1(point a, point b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } int cmp2(point a, point b) { return a.y < b.y || (a.y == b.y && a.x < b.x); } int mark[N]; long long...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 50; int n, k, m; int A[maxn]; int main() { while (scanf("%d %d %d", &n, &k, &m) == 3) { for (int i = 0; i < k; ++i) scanf("%d", A + i); sort(A, A + k); int sum = 0; for (int i = 0; i < k; ++i) sum += A[i]; int res = 0; for (int i =...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, t = "<3", st; for (int i = 0; i < n; i++) { cin >> st; t += st + "<3"; } cin >> s; int ptr = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == t[ptr]) { ptr++; if (ptr == t.length()) { ...
7
#include <bits/stdc++.h> using namespace std; int main() { int d; string s; cin >> d >> s; if (d == 1) { cout << "Impossible" << endl; exit(0); } vector<int> v; v.push_back(-1); for (int i = 0; i < int(s.size()); i++) { v.push_back(int(s[i]) - 'a'); v.push_back(-1); } int cotapos, co...
20
#include <bits/stdc++.h> using namespace std; const int MAX_ELEMENT = 100000; int main() { int i, j; int N, M; int s, e; cin >> N >> M >> s >> e; vector<int> a(N), b(M); vector<int> indexes[MAX_ELEMENT + 2]; for (i = 0; i < N; i++) cin >> a[i]; for (i = 0; i < M; i++) { cin >> b[i]; indexes[b[i]...
15
#include <bits/stdc++.h> using namespace std; using ll = long long; int max_digit(ll n) { int max = 0; do { int a = n % 10; if (a > max) max = a; n /= 10; } while (n != 0); return max; } int main() { ll n; cin >> n; int steps = 0; while (n != 0) { n -= max_digit(n); steps++; } co...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &num) { T x = 0, f = 1; char ch = getchar(); for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1; for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ '0'); num = x * f; } in...
27
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 4; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ; cin >> s; long long n = s.size(); long long sub = 0; for (int k = 1; k <= 8; k++) { for (int i = 0; i + k <= n; i++) { bool fla...
11
#include <bits/stdc++.h> int main() { long long n, x, y, o, overplus, numb; int I; scanf("%lld", &n); if (n == 0) { printf("0 0\n"); return 0; } o = (1 + (int)sqrtl((long double)(1 + (n - 1) * 4 / 3))) / 2; overplus = n - ((6 + 6 * (o - 1)) * (o - 1) / 2 + 1); I = overplus / o; numb = overplus...
13
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; long double EPS = 1e-9; template <class second, class T> ostream& operator<<(ostream& os, const pair<second, T>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream& operator<<(ostream& os, const vector...
12
#include <bits/stdc++.h> using namespace std; const int64_t mod = 1e9 + 7; const int N = 2e5 + 1; int ar[N], n, per, av[N]; int main() { int a, b, day = 0; cin >> n >> per; for (int i = 0; i < n; i++) { cin >> a >> b; day = max(day, a); av[a] += b; } int x = 0, mn, rem; for (int i = 1; i <= day ...
6
#include <bits/stdc++.h> using namespace std; vector<int> g[200005]; int vis[200005]; long long int v; void dfs(int s, int t) { v++; vis[s]++; for (auto x : g[s]) { if (vis[x] == 0 and x != t) dfs(x, t); } } int main() { int t; cin >> t; while (t--) { int n, m, a, b; cin >> n >> m; cin >> ...
11
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, d; cin >> n >> d; int a[n], b[n], mx[n]; int temp = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; temp += a[i]; b[i] = temp; } mx[n - 1] ...
11
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5, mod = 1e9 + 7, mod1 = 998242353, mod2 = 1e9 + 9, inf = 1e9 + 7; const long long infll = 1e18 + 7; long long n; pair<long long, long long> a[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >>...
0
#include <bits/stdc++.h> using namespace std; const int base = 100003; const int maxn = 300005; struct data { int u, v; long long w; } edge[maxn]; int n, m; vector<pair<int, int> > ke[maxn]; int useless[maxn], par[maxn]; long long d[maxn], weight[maxn]; void DIJK(int s) { for (int i = 1; i <= n; ++i) d[i] = weigh...
12
#include <bits/stdc++.h> using namespace std; struct elem { int l, p, t, ind; elem() {} elem(int inl, int inp, int intt, int inind) { l = inl; p = inp; t = intt; ind = inind; } }; int base = 315; int n; elem v[1000000]; int btmax[1000000]; int bttope[1000000]; int cuantos[1000000]; int bdesp[100...
23
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; char s[maxn], t[maxn]; int dp[maxn][maxn], pa[maxn][26], pb[maxn][26]; int main() { int T; cin >> T; while (T--) { int n; cin >> n; scanf("%s%s", s + 1, t + 1); for (int i = 1; i <= n; ++i) s[i] -= 'a', t[i] -= 'a'; for (int ...
18
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n, x; cin >> n >> x; string a; cin >> a; long long s[n]; long long mx = 0, mn = 0; for (long long i...
9
#include <bits/stdc++.h> using namespace std; long long stoll(string target) { stringstream s; s << target; long long w; s >> w; return w; } int stoi(string target) { stringstream s; s << target; int w; s >> w; return w; } string itos(int i) { stringstream s; s << i; return s.str(); } string l...
6
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n; const int bign = 200033; int a[bign]; int main() { long long minsize = 1e18; scanf("%d", &n); for (int i = 0; i < 2 * n; i++) scanf("%d", a + i); sort(a, a + 2 * n); minsize = 1ll * (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]); ...
7
#include <bits/stdc++.h> using namespace std; int inf = 1000000000; int data[100005]; int ada[2005]; int n, k, x; map<long long, int> dah; long long mod = 999999999989LL; void urut() { memset(ada, 0, sizeof(ada)); for (int(i) = (0); (i) <= (n - 1); ++(i)) ++ada[data[i]]; int now = 0; for (int(i) = (0); (i) <= (...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0, t, count = 1, max = 1; cin >> n; cin >> x; t = x; for (int i = 1; i < n; i++) { cin >> x; if (x >= t) count++; else { if (count > max) max = count; count = 1; } t = x; } if (count > max) max = co...
1
#include <bits/stdc++.h> using namespace std; map<char, int> ct; set<char> torem; struct c { char x; int ct; }; c alpha[100]; bool cmp(c c1, c c2) { return c1.ct < c2.ct; } char s[1000000]; int main() { gets(s); char s1[100]; gets(s1); int k; sscanf(s1, "%d", &k); int l = strlen(s); for (int i = 0; i ...
4
#include <bits/stdc++.h> using namespace std; const int Nmax = 4e5 + 5; deque<int> dq; int i, k, n, x; long long sum[Nmax], best[Nmax], dp[Nmax], C; int main() { cin.sync_with_stdio(false); cin >> n >> C; for (i = 1; i < 2 * n; ++i) { cin >> x; sum[i] = x + sum[i - 1]; } k = 0; for (i = 1; i <= n; +...
20
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1500 + 10; const long long INF = 9e18; const long double DINF = 1.79769e+308; int n, m; pair<int, int> pos, walk[MAXN][MAXN]; string s; bool a[MAXN][MAXN], visited[MAXN][MAXN], b; bool check(pair<int, int> v, pair<int, int> p, pair<int, int> u, ...
12
#include <bits/stdc++.h> using namespace std; const long long int INF = (long long)1e15; void solve() { long long n, w; cin >> n >> w; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long sum = 0; int flag = 0; vector<int> v; for (int i = 0; i < n; i++) { if (a[i] < (w + 1) / 2 && sum ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m, ans = -1; scanf("%i %i", &n, &m); int counts[n], arr[n]; memset(counts, 0, sizeof(counts)); for (int i = 0; i < m; i++) { int x = -1, i1 = -1; for (int j = 0; j < n; j++) { scanf("%i", &arr[j]); if (arr[j] > x) { ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; string p[MAXN][2]; int pos[MAXN]; int N; void get(int i) { getline(cin, p[i][0]); p[i][1] = ""; int l = p[i][0].length(); while (p[i][0][l - 1] != ' ') { p[i][1] = p[i][0][l - 1] + p[i][1]; p[i][0].erase(l - 1); l--; } p[i][0...
6
#include <bits/stdc++.h> using namespace std; template <typename T> int sgn(T val) { return (T(0) < val) - (val < T(0)); } int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int ncr(int n, int k) { int r = 1; if (k > n - k) k = n - k; for (int i = 0; i < k; i++) { r *= n - i; r /=...
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double PI = acos(-1.0); const long long int mod = 1e9 + 7; const int MAXN = 1e6 + 5; bool get(long long int l, long long int r) { cout << l << " " << r << '\n'; cout.flush(); string res; cin >> res; if (l == r && res == "Yes") exit(0...
13
#include <bits/stdc++.h> using namespace std; int c1, c2, c3, c4, c5, s; int main() { cin >> c1 >> c2 >> c3 >> c4 >> c5; s = c1 + c2 + c3 + c4 + c5; if (s == 0) cout << -1; else if (s % 5 == 0) cout << s / 5; else cout << -1; }
3
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int N = 1e5 + 7; const int M = 5e2 + 7; int n, l, r; vector<vector<int> > vec(N); int d[N], sub[N]; char ra[N]; struct build { inline void dfs(int v, int par) { sub[v] = 1; for (int i : vec[v]) { if (d[i] || par == i) { ...
13
#include <bits/stdc++.h> using namespace std; static inline void canhazfast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T extgcd(T a, T b, T &x, T &y) { T x0 = 1, y0 = 0, x1 = 0,...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; for (int i = 0; i < n; i++) { int val; cin >> val; long long low, mid, high; low = 0, high = 1e15; long long ans = high; while (low <= high) { mid = (low + high) / 2; long long dmg1, dmg...
10
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { long long x1, y1, x2, y2; scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2); long long vm, t; scanf("%lld %lld", &vm, &t); long long vx, vy, wx, wy; scanf("%lld %lld %lld %lld", &vx, &vy, &wx, &wy); long long tx = x2 - v...
13
#include <bits/stdc++.h> using namespace std; int check(string s) { int n = s.size(); if (n < 5) return 0; int c1 = 0, c2 = 0, c3 = 0; for (int i = 0; i < n; i++) { c1 += isupper(s[i]); c2 += islower(s[i]); c3 += isdigit(s[i]); } return (c1 > 0 && c2 > 0 && c3 > 0); } int main() { ios_base::sy...
0
#include <bits/stdc++.h> using namespace std; const long long inf = 1e14; class min_cost_flow { private: int N; struct edge { int to; long long cap, cost; int rev; }; vector<vector<edge>> G; vector<long long> h, dist, prevv, preve; public: min_cost_flow(int n) { N = n; G = vector<vect...
17
#include <bits/stdc++.h> using namespace std; struct PMA { PMA *next[0x100]; vector<int> accept; PMA() { fill(next, next + 0x100, (PMA *)0); } }; PMA *buildPMA(char p[10][11], int size) { PMA *root = new PMA; for (int i = 0; i < size; ++i) { PMA *t = root; for (int j = 0; p[i][j]; ++j) { char c ...
17
#include <bits/stdc++.h> using namespace std; void fin(int a) { if (a) cout << "Yes"; else cout << "No"; exit(0); } struct point { long long x = 0, y = 0; point() { x = 0; y = 0; } point(long long xx, long long yy) { x = xx; y = yy; } point operator+(point b) { return point(x +...
8
#include <bits/stdc++.h> using namespace std; const int maxn = int(1e5) + 100; const int mod = int(1e6); struct command { int type, ti, num, nid; }; struct hashs { int num, next; }; int n; int now; command a[maxn]; int ha[mod]; hashs t[maxn]; int ans[maxn], sum[maxn]; bool cmp(command x, command y) { return x.ti < ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; cout << 9 * n << " " << 8 * n << endl; return 0; }
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = 1000001000; const long long INFLL = INF * 1LL * INF; const int mod = 1000 * 1000 * 1000 + 7; const int mod9 = 1000 * 1000 * 1000 + 9; const int modr = 99990001; const long double PI = 3.1415926535897932385; templat...
6
#include <bits/stdc++.h> using namespace std; void solve() { int n, cur; scanf("%d", &n); scanf("%d", &cur); int mxVal = INT_MIN, mxDiff = INT_MIN; for (int i = 0; i < n; i++) { int x, y; scanf("%d", &x); scanf("%d", &y); mxVal = max(mxVal, x); mxDiff = max(mxDiff, x - y); } if (cur > ...
8
#include <bits/stdc++.h> using namespace std; int n; vector<int> brks; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int calc(vector<int> bead, bool sure); int split(vector<int> bead, int div, bool sure) { for (int i = (0); i <= (n - 1); i++) bead[i] /= div; return div * calc(bead, sure)...
17
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1e+9 + 7ll; const long long linf = (long long)1e+18 + 7ll; const long double eps = (long double)1e-10; const long double pi = acosl((long double)-1.0); const int alph = 26; static char buff[(int)2e6 + 17]; const int maxn = (int)1e6 + 17; int...
22
#include <bits/stdc++.h> using namespace std; const int MaxN = 3e5 + 6.66; const int MaxLog = 20; int up_ed[MaxN]; long long dp[MaxN]; long long dp_up[MaxN]; long long ret_dp[MaxN]; long long lca_sum[MaxLog][MaxN]; long long lca_rem[MaxLog][MaxN]; int lca[MaxLog][MaxN]; int arr[MaxN]; int h[MaxN]; vector<pair<int, int>...
19
#include <bits/stdc++.h> using namespace std; int main() { int a[1000] = {0}; int b = 0, maxi = 0; int n; cin >> n; string s[n]; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) if (s[i] == s[j]) b++; maxi = max(maxi, b); b = 0; } for...
2
#include <bits/stdc++.h> using namespace std; const int p = 1000000007; int f[600][600], g[600][600], h[600][600]; int i, j, k, n; int main() { cin >> n; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) cin >> g[i][j]; for (i = 1; i <= n; i++) f[i][i] = 1; for (i = 1; i < n; i++) for (j = 1; i + j <= n...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int L[maxn << 2], R[maxn << 2]; double sum[maxn << 2], add[maxn << 2], mul[maxn << 2]; void pushup(int i) { sum[i] = sum[i * 2] + sum[i * 2 + 1]; } void pushdown(int i) { sum[i * 2] = sum[i * 2] * mul[i] + add[i] * (R[i * 2] - L[i * 2] + 1); sum...
15
#include <bits/stdc++.h> using namespace std; long long int dp[100010]; long long int v[100010]; long long int c[100010]; bool vis[100010]; long long int maxPC[100010]; pair<long long, long long int> m1, m2; long long int solve(int N, long long int A, long long int B) { for (int i = 0; i < 100010; i++) vis[i] = false...
12
#include <bits/stdc++.h> using namespace std; int dp[1003][2003]; int main() { int i, j, k, l, n, m, a[2003], b[2003], p; for (i = 0; i < 1003; i++) for (j = 0; j < 2003; j++) dp[i][j] = 2e9; cin >> n >> k >> p; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < k; i++) cin >> b[i]; sort(a, a + n); ...
10
#include <bits/stdc++.h> using namespace std; int _arr[51]; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; int arr[n * 2]; for (int j = 0; j < n * 2; j++) cin >> arr[j]; _arr[0] = arr[0]; int flag = 1; for (int j = 1; j < n * 2; j++) { bool check = t...
0
#include <bits/stdc++.h> using namespace std; namespace IO { const int BUFFER_SIZE = 1 << 15; char input_buffer[BUFFER_SIZE]; int input_pos = 0, input_len = 0; char output_buffer[BUFFER_SIZE]; int output_pos = 0; char number_buffer[100]; uint8_t lookup[100]; void _update_input_buffer() { input_len = fread(input_buffe...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 510; int g[maxn][maxn] = {0}; int main() { ios_base ::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) cin >> g[i][j]; int row[maxn] = {0}; int col[maxn] = {0}; int cnt = 0; if (n...
9
#include <bits/stdc++.h> using namespace std; template <class T> int popcount(T n); template <> int popcount(unsigned int n) { return __builtin_popcount(n); } template <> int popcount(int n) { return __builtin_popcount(n); } template <> int popcount(unsigned long long n) { return __builtin_popcountll(n); } templa...
13
#include <bits/stdc++.h> using namespace std; long long read() { long long a = 0; char c = getchar(); while (c > '9' || c < '0') c = getchar(); while ('0' <= c && c <= '9') { a = a * 10 + c - 48; c = getchar(); } return a; } long long N; long long mu[200005], phi[200005], p[200005 / 10], cnt; bool v...
23
#include <bits/stdc++.h> using namespace std; struct Node { int pre, val, suf; bool full; Node(int a = 0, int b = 0, int c = 0, bool d = false) : pre(a), val(b), suf(c), full(d) {} }; Node combine(Node n1, Node n2) { Node ret = Node(n1.pre, max(max(n1.val, n2.val), n1.suf + n2.pre), n2.suf, false); ...
17
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, maxn = 4005; int n, a[maxn][2], h[maxn], id[maxn][maxn], dp[maxn][maxn], vis[maxn][maxn]; vector<int> g[maxn]; int dfs(int l, int r) { if (l >= r) return dp[l][r] = 0; if (~dp[l][r]) return dp[l][r]; dp[l][r] = dfs(l + 1, r); for (int i =...
13
#include <bits/stdc++.h> using namespace std; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; bool prime[10000001]; long long P = 1000000007 - 2; long long ...
11
#include <bits/stdc++.h> int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector<int> x(n), y(n); for (int i = 0; i < n; ++i) std::cin >> x[i] >> y[i]; long long eee = 0, eoo = 0; for (int i = 0; i < ...
25
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a == 0 && b == 0) { cout << "NO" << endl; return 0; } int x = abs(a - b); if (x <= 1) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; template <class T> T bigmod(T b, T p, T m) { if (p == 0) return 1; T res = bigmod(b, p / 2, m); res = (res * res) % m; if (p % 2 == 1) res = (res * b) % m; return res; } template <class T> T gcd(T x, T y) { if (y == 0) return x; return gcd(y, x % y); } templat...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int maxval = -1; int x; while (n--) { scanf("%d", &x); maxval = max(maxval, x); } printf("%d\n", x ^ maxval); return 0; }
10
#include <bits/stdc++.h> using namespace std; int main() { int n, k, sum = 0, c = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { sum = sum + 5 * i; } while (sum + k > 240) { sum = sum - 5 * n; n--; } cout << n << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; char s1[1000005], s2[1000005]; long long f[1000005], rf[1000005]; int num[2][30], tmp[2][30]; long long poww(long long a, long long b) { long long ans = 1; while (b) { if (b % 2) ans = (ans * a) % mod; a = (a * a) % mod; b /= 2; } ...
13
#include <bits/stdc++.h> using namespace std; string a; int x; int b; int c; int d; int e; int main() { cin >> a; x = a.length(); if (x >= 5) { b = true; } for (int i = 0; i < x; i++) { if ((a[i] >= 65) && (a[i] <= 90)) { c++; } else if ((a[i] >= 97) && (a[i] <= 122)) { d++; } else...
0
#include <bits/stdc++.h> using namespace std; int s, a, b, c; int main() { scanf("%d%d%d%d", &s, &a, &b, &c); if (a == 0) { if (b == 0) { if (c != 0) printf("%.14lf %.14lf %.14lf\n", 0.0, 0.0, s * 1.); else printf("%.14lf %.14lf %.14lf\n", 0.0, 0.0, 0.0); } else if (c == 0) ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; int n, m, a[maxn]; double p[maxn][maxn]; int main() { int u, v; while (scanf("%d%d", &n, &m) != EOF) { for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) p[i][j] = (a[i] > ...
18
#include <bits/stdc++.h> using namespace std; int p[300000]; int a[300000]; int pos[300000]; int n; long long seg[1500000]; long long lazy[1500000]; void propagate(int id, int l, int r) { seg[id] += lazy[id]; if (l != r) { lazy[id * 2 + 1] += lazy[id]; lazy[id * 2 + 2] += lazy[id]; } lazy[id] = 0; } lon...
14
#include <bits/stdc++.h> using namespace std; inline int read() { int re = 0, flag = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') re = (re << 1) + (re << 3) + ch - '0', ch = getchar(); return re * flag; } int n,...
26
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; int l, w, a[N]; int sum[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> w >> l; for (int i = 1; i < w; i++) cin >> a[i]; for (int i = 1; i < w; i++) sum[i] = sum[i - 1] + a[i]; int ans = 1000000000; for (int i =...
11
#include <bits/stdc++.h> using namespace std; int n, p, a[100010]; int judge(int x) { int now = 1, i; for (i = 1; i <= n; i++) { while (now <= n && a[now] <= x) now++; if ((now - i) % p == 0) return 1; x++; } return 0; } int main() { int i, maxi, l, r, mid; cin >> n >> p; for (i = 1; i <= n; i...
15
#include <bits/stdc++.h> const double eps = 1e-11; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; using namespace std; const int maxn = 100005; int n, m, arr[maxn]; pair<int, int> q[maxn]; int rtop[maxn], ltop[maxn]; void solve() { rtop[n - 1] = n - 1; for (int i = n - 2; i >= 0; i--) { if (arr[i] <= arr[i...
9
#include <bits/stdc++.h> struct drift { int x, y; bool v; drift(int a, int b) : x(a), y(b), v(0){}; }; std::vector<drift> array; void search(int start, int L) { if (array[start].v == 1) { return; } array[start].v = 1; for (int p = 0; p < L; p++) { if (array[p].x == array[start].x || array[p].y == ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5; struct node { int ls, rs, sum; }; node tr[maxn * 10]; int mar[maxn], a[maxn], nxt[maxn]; int root[maxn]; int v, n; void nw(int x) { tr[x] = (node){0, 0, 0}; } void build(int x, int l, int r) { if (l == r) { tr[x].sum = 0; if (mar[a[l]] == l...
16
#include <bits/stdc++.h> using namespace std; namespace IO { inline char ch() { static char s[1 << 16], *S, *T; return (S == T) && (T = (S = s) + fread(s, 1, 1 << 16, stdin), S == T) ? EOF : *S++; } template <typename T> void read(T &x) { x ...
15
#include <bits/stdc++.h> using namespace std; struct DSU { int n; int* p; DSU(int n) : n(n), p(new int[n]) { for (int i = 0; i < n; i++) p[i] = i; } ~DSU() { delete[] p; } int get(int x) { if (p[x] == x) return x; return p[x] = get(p[x]); } void unite(int a, int b) { a = get(a); b = ...
13
#include <bits/stdc++.h> using namespace std; vector<long long> moves; long long k; long long a; long long s; bool cheat(int n) { vector<long long> mv; for (int i = 0; i < n; i++) mv.push_back(moves[i]); sort(mv.begin(), mv.end()); long long l = 1; long long sh = k; for (int i = 0; i < n; i++) { int cs ...
9
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") const long long mod = 1e9 + 7; const long long ulim = 2e6 + 5; long long coeff[ulim], powers[ulim], answers[ulim], sub[ulim]; long long fastexpo(long long n, long long p) { n %= mod; return (p == 0 ? 1 : fastexpo(n * n, p / 2) * (p & 1 ? n : 1...
15
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pli = pair<ll, int>; using pil = pair<int, ll>; using pll = pair<ll, ll>; template <typename T> using vec = vector<T>; using vi = vec<int>; using vl = vec<ll>;...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n]; int c = 0; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (b[i] - a[i] >= 2) c++; } cout << c; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int len = s.length(), size = 0; for (char c : s) { if (c == '(') { size++; } else { if (size == 0) { len--; } else { size--; } } } if (size > 0) { cout << len - size; } el...
6
#include <bits/stdc++.h> using namespace std; template <class A> void pr(A a) { cout << a; cout << '\n'; } template <class A, class B> void pr(A a, B b) { cout << a << ' '; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << ' '; pr(b, c); } template <class A, class B, class ...
8
#include <bits/stdc++.h> using namespace std; template <class T> inline T euclide(T a, T b, T& x, T& y) { if (a < 0) { T d = euclide(-a, b, x, y); x = -x; return d; } if (b < 0) { T d = euclide(a, -b, x, y); y = -y; return d; } if (b == 0) { x = 1; y = 0; return a; } else...
10
#include <bits/stdc++.h> using namespace std; const int N = 200001; int d[N]; int n; long long sum, A; int main() { scanf("%d%I64d", &n, &A); sum = 0; for (int i = 0; i < n; ++i) { scanf("%d", &d[i]); sum += d[i]; } for (int i = 0; i < n; ++i) cout << max(d[i] - A + n - 1, 0ll) + max(A - sum + d[i...
8
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; cout << 25 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int read() { char c = getchar(); long long x = 1, s = 0; while (c < '0' || c > '9') { if (c == '-') x = -1; c = getchar(); } while (c >= '0' && c <= '9') { s = s * 10 + c - '0'; c = getchar(); } return s * x; } const int N = 3e5 + 5; int n, m, ...
23
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816; struct compare { bool operator()(pair<int, int> a, pair<int, int> b) const { return abs(a.second) < abs(b.second); } }; int main() { long long ans = 0; int n; s...
2
#include <bits/stdc++.h> #pragma GCC optimize("-O3") using namespace std; long long const N = 2 * 1e5 + 5; long long x1, r, x2, c, ibibibibbibibibiibigbabypanfewewf, y2, d, q, mx, mx1, ans, pos, a[N], aa[N], b, y3, k, pref[5005][4]; long long m, n; string second; char ch; vector<long long> v; vector<long long> v1; ...
6
#include <bits/stdc++.h> int n, f[100010], g[100010], h[100010], w[100010], cnt, p[100010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", f + i); for (int i = 1; i <= n; i++) if (f[i] != f[f[i]]) { puts("-1"); return 0; } for (int i = 1; i <= n; i++) if (!w[f[i]]...
9
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <class T> ostream &prnt(ostream &out, T v) { out << v.size() << '\n'; for (auto e : v) out << e << ' '; return out; } template <class T> ostream &operator<<(ostream &out, vector<T> v) { return prnt(out, v); } template <cla...
17
#include <bits/stdc++.h> using namespace std; int a[310]; int b[310], c[310]; int to[310]; bool root[310]; bool used[310]; vector<int> v; int dp[100010]; int main(void) { int N, Q, T, i, j; cin >> N >> Q >> T; for ((i) = 0; (i) < (int)(N); (i)++) cin >> a[i]; for ((i) = 0; (i) < (int)(Q); (i)++) cin >> b[i] >> ...
13
#include <bits/stdc++.h> using namespace std; vector<long long> v[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; for (long long int i = 0; i < n - 1; i++) { long long x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } for...
8