solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void vrikodara(long long n = 12) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(n) << fixed; } long long lb = 100000; vector<string> fun(string s, long long k, l...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, m; cin >> n >> k; m = n / k; if (m % 2 != 0) cout << "yes"; else cout << "no"; }
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int maxn = 1e5 + 5; const int mod = 998244353; const int INF = 1e9; int K; struct S { int l, r, id; bool operator<(const S& rhs) const { return l / K < rhs.l / K || (l / K == rhs.l / K && r < rhs.r); } }; int gcd(int x, int y) { re...
17
#include <bits/stdc++.h> using namespace std; template <typename Tp> inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") { for (Tp current = _begin; current != _end; ++current) { std::cout << *current << _delim; } std::cout << '\n'; } using ll = long long; using pii = std::pair<int, int>; constex...
9
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, s; cin >> a >> b >> s; if (a < 0) a = -a; if (b < 0) b = -b; if (a == 0 && b == 0) { if (s % 2 == 0) cout << "Yes\n"; else cout << "No\n"; } else { if (a + b <= s && (s - a - b) % 2 == 0) cout << "Yes\n"...
2
#include <bits/stdc++.h> using namespace std; const int N = 200500; int read(int &n) { char ch = ' '; int q = 0, w = 1; for (; (ch != '-') && ((ch < '0') || (ch > '9')); ch = getchar()) ; if (ch == '-') w = -1, ch = getchar(); for (; ch >= '0' && ch <= '9'; ch = getchar()) q = q * 10 + ch - 48; n = q * ...
19
#include<bits/stdc++.h> using namespace std; const int N = 100; int quary1(int i,int j) { int x; cout << 1 << " " << i << " " << j << endl; fflush(stdout); cin >> x; return x; } int quary2(int i,int *jj,int k) { int h,x; cout << 2 << " " << i << " " << k; for(h = 0;h < k;++h) ...
19
#include <bits/stdc++.h> using namespace std; void SieveOfErat() { bool prime[1000001]; memset(prime, true, sizeof(prime)); for (long long vec = 2; vec * vec <= 1000000; vec++) { if (prime[vec] == true) { for (long long dd = vec * 2; dd <= 1000000; dd += vec) prime[dd] = false; } } } long long gcd...
14
#include <bits/stdc++.h> using namespace std; long long n, m, x, y; long long dis[1001], t[1001], c[1001]; vector<pair<long long, long long> > adj[1001], fadj[1001]; void dijkstra(int S) { fill(dis, dis + 1001, (1LL << 61)); priority_queue<pair<long long, long long> > q; q.push(make_pair(S, 0)); dis[S] = 0; w...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n * 3 <= k) { cout << 0 << endl; } else { cout << (n * 3) - k << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<int> v; int k[60 * 10000]; int main() { int n, d; scanf(" %d %d", &n, &d); for (int i = 0; i < n; i++) { int a; scanf(" %d", &a); v.push_back(a); } k[0] = 1; for (int i = 0; i < v.size(); i++) for (int j = 60 * 10000; j >= 0; j--) if...
14
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; double dist(pair<int, int> p1, pair<int, int> p2) { int p1x = p1.first, p2x = p2.first, p1y = p1.second, p2y = p2.second; return sqrt((p1x - p2x) * (p1x - p2x) + (p1y - p2y) * (p1y - p2y)); } double calc(vector<pair<int, int>> vp) { double ans...
10
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string f = s; int count = 0; do { char k = s[s.length() - 1]; for (int i = s.length() - 2; i >= 0; i--) { s[i + 1] = s[i]; } s[0] = k; count++; } while (f != s); cout << count; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long x1, y1; long long d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } int main() { ios_base::sync_with_stdio...
10
#include <bits/stdc++.h> using namespace std; struct node { int id; int num; int s; } arr[1000000]; queue<node> que; set<pair<int, int> > s; int main() { long long cnt = 0; int n, i; scanf("%d", &n); for (i = 0; i < n; i++) { arr[i].id = i; scanf("%d%d", &arr[i].num, &arr[i].s); cnt += (long l...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int req; cin >> req; int tm, cnt = 0, pc[8]; pc[0] = 0; for (int j = 0; j < 7; j++) { cin >> tm; cnt += tm; pc[j + 1] = pc[j] + tm; } int dp[2 * cnt + 1]; for...
7
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int answerh, answerm; int sh, sm, th, tm; sh = ((s[0] - '0') * 10) + (s[1] - '0'); sm = ((s[3] - '0') * 10) + (s[4] - '0'); th = ((t[0] - '0') * 10) + (t[1] - '0'); tm = ((t[3] - '0') * 10) + (t[4] - '0'); answerh =...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; int const nmax = 5000; int const modulo = 998244353; class Zring { private: void gcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; } else { gcd(b, a % b, x, y); int aux = x; x = y; y = aux - ...
18
#include <bits/stdc++.h> const long long mod = 1e9 + 7; const long long MAX = INT_MAX; const long long inf = 1e18 + 5; const double pi = 3.14159265358979323846; long long dirX[] = {1, -1, 0, 0}; long long dirY[] = {0, 0, 1, -1}; using namespace std; long long LCS(string a, string b) { a = '$' + a; b = '$' + b; lo...
6
#include <bits/stdc++.h> using namespace std; int in() { int x; scanf("%d", &x); return x; } const int maxn = 100 * 1000 + 5; int cnt[maxn], L[maxn], R[maxn]; int lis[maxn]; void LIS(int a[], int n, int L[]) { int len = 0; for (int i = 0; i < n; i++) { int it = upper_bound(lis, lis + len, a[i]) - lis; ...
11
#include <bits/stdc++.h> using namespace std; const int N = 100010; int lg[N], f[N][20], n, fa[N]; int calc(int x, int y) { int ll = lg[y - x + 1]; return f[x][ll] | f[y - (1 << ll) + 1][ll]; } int findprev(int x) { return fa[x] > 0 ? fa[x] = findprev(fa[x]) : x; } int main() { scanf("%d", &n); for (int i = 2; ...
8
#include <bits/stdc++.h> using namespace std; int n, i, j, k, a[222000]; int main() { cin >> n; for (i = 2; i <= n; i++) { if (a[i] == 0) { j++; for (k = i; k <= n; k += i) a[k] = j; } } for (i = 2; i <= n; i++) cout << a[i] << " "; }
5
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 1; const double eps = 1e-8; template <class T> bool chk_max(T& a, const T& b) { return b > a ? a = b, 1 : 0; } template <class T> bool chk_min(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> void _swap(T& a, T& b) { T t ...
9
#include <bits/stdc++.h> using namespace std; #define ld long double typedef long long ll; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) long double ans; long double v; const ld E=1e-7; void recur(long double c, long double m, long double p, long double len, long double cur){ ans+=(len...
11
#include <bits/stdc++.h> using namespace std; int n, a[100 + 9]; int d, dist[100 + 9][100 + 9], x[100 + 9], y[100 + 9]; int main() { cin >> n >> d; for (int i = 1; i < n - 1; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 1007; bool odw[MAXN]; int d[MAXN], low[MAXN], ojc[MAXN], spo[MAXN]; int tim = 0; unordered_set<int> G[MAXN]; vector<pair<int, int> > E = {{0, 0}}; const int INF = 1e9 + 7; const int MAXM = 30007; int waga[MAXM]; unordered_set<int> M; int drugi(int kr, int a...
18
#include <bits/stdc++.h> using namespace std; using ll = long long; enum seg_type { seg_not_lazy, seg_lazy, seg_beats }; template <class node, seg_type type> struct segment_tree { using node_container = typename node::node_container; using lazy_container = typename node::lazy_container; private: template <const...
20
#include <bits/stdc++.h> using namespace std; inline void Read(int &x) { int f = 1; char c = getchar(); x = 0; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + c - '0'; c = getchar(); } x *= f; } const int p = 10...
19
#include <bits/stdc++.h> using namespace std; int checkRight(int a, int b, int c, int d, int e, int f) { if ((a == c && c == e) || (b == d && d == f) || (a == c && b == d) || (c == e && d == f)) return 0; int x1, y1, z1; x1 = ((a - c) * (a - c) + (b - d) * (b - d)); y1 = ((c - e) * (c - e) + (d - f) *...
7
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, k, i, j, sum = 0, p; cin >> n >> k; vector<vector<long long int> > moves; vector<long long int> temp; string s, new_s; cin >> s; do { temp.clear(); new_s = s; fo...
13
#include <bits/stdc++.h> using namespace std; string convert(string s) { for (int i = 0; i < s.length(); i++) { s[i] = isupper(s[i]) ? tolower(s[i]) : toupper(s[i]); } return s; } int main() { string s; cin >> s; int upper = 0; bool firstCap = false; for (int i = 0; i < s.length(); i++) { if (i ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int rides, mrides, oneride_price, mridesprice; cin >> rides >> mrides >> oneride_price >> mridesprice; int oneRideTotals = oneride_price * rides; if (rides % mrides == 0) { if ((...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 2; int n, s, a[maxn]; int cnt, pri[maxn]; int pos[maxn]; bool not_pri[maxn]; long long ans, tmp; int main() { not_pri[1] = 1; for (int i = 2; i <= 1e5; ++i) { if (!not_pri[i]) pri[cnt++] = i; for (int j = 0; j < cnt && i * pri[j] <= 1e5; +...
10
#include <bits/stdc++.h> using namespace std; int main() { stack<pair<int, int>> stk; int N; cin >> N; int ans = -1; for (int i = 0; i < N; ++i) { int curr_psycho; int killed = 0; cin >> curr_psycho; while (!stk.empty() && stk.top().first < curr_psycho) { killed = stk.top().second + 1; ...
11
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; long long dp[1005][2005]; vector<int> a_s; string S; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> S; int cur = 0, cnt = 0; for (int k = 0; k < (S.length()); k++) { if (S[k] < '0' || S[k] > '9') cur+...
18
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long inf = 1e9 + 7; long long modexp(long long base, long long power) { if (power == 0) return 1; if (power & 1) ret...
7
#include <bits/stdc++.h> using namespace std; const int N = 300005; struct node { int id; long long num; bool operator<(const node &x) const { return num > x.num; } }; priority_queue<node> q1, q2, q3, q4, q5; int n, w, op1, op2 = 1, op3 = 1, op4, op5 = 2; long long sum, a[N], b[N], ans[N]; signed main() { scanf...
18
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int maxm = 15; const long long INF = 1e18; int n, m, k; int a[maxn]; long long dp[maxn][maxm]; void ReadInput() { cin >> n >> m >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; } void Solve() { fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0]...
11
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c; cin >> a >> b >> c; int a1 = a, b1 = b, c1 = c; int v = 0, h = 0; while (a1 > 0 && b1 > 1) { v += 3; --a1; b1 -= 2; } while (b1 > 0 && c1 > 1) { v += 3; ...
0
#include <bits/stdc++.h> using namespace std; template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>; template <typename T> void setmax(T& a, T b) { a = max(a, b); }; template <typename T> void setmin(T& a, T b) { a = min(a, b); }; template <typename T> bool in(T lo, T v, T hi) { return lo <=...
12
#include <bits/stdc++.h> using namespace std; long long int solve() { long long int n, u; cin >> n >> u; long long int a[n]; double ans = 0.0; for (long long int i = 0; i < n; ++i) cin >> a[i]; for (long long int i = 0; i < n - 2; ++i) { long long int hi = n - 1, lo = i; while (hi >= lo) { lon...
8
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10; int a[M], v[M], u[M]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int ans = -1; v[0] = 1; for (int i = 1; i < n; i++) { if (a[i] > a[i - 1]) v[i] = v[i - 1] + 1; else ...
8
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int sum = 0; long long int a[n]; string s; vector<long long int> v; map<long long int, long long int> mp; for (long long int i = 0; i < n; i+...
6
#include<algorithm> #include<ctime> #include<iostream> #include<random> #include<string> #include<vector> using namespace std; int cnt_bits(int a) { int res = 0; while (a > 0) { res += (a & 1); a >>= 1; } return res; } int main() { int n, m, p; cin >> n >> m >> p; mt19937 gen(time(0)); uniform_int_distr...
16
#include <bits/stdc++.h> using namespace std; const long long N = 2e5; const long long M = 25; const long long block = 8000; const long long big = 1e18; const long long mod = 998244353; mt19937_64 srnd(chrono::steady_clock::now().time_since_epoch().count()); long long n, k; long long a[N]; long long zanim[N]; int main(...
11
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math") const long long maxn = 5e3 + 10, maxm = 5e3 + 10, lg = 12, mod = 1e9 + 7, inf = 1e18; string s; long long G[maxn]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); fo...
15
#include <bits/stdc++.h> using namespace std; long long fact[1000001] = {0}; void preFact() { fact[0] = 1; fact[1] = 1; for (long long i = 2; i < 1000001; i++) { fact[i] = (fact[i - 1] * (i % 1000003)) % 1000003; } } bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 ==...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const double pi = 3.14159265358979323846264338327950288419716939937511; const double eps = 1e-10; char ch_ch_ch[1 << 20]; inline string gs() { scanf("%s", ch_ch_ch); return string(ch_ch_ch); } inline string gl() { gets(ch_ch_...
16
#include <bits/stdc++.h> using namespace std; const long long INF = 1e+16; const int SMALL_INF = 1998244353; const long long NSIZE = 2 * 1e+5 + 1000; const long long MOD = 998244353; const long double EPS = 1e-12; const int MAX = 1e+6 + 1000; const long double PI = atan(1) * 4; const long long HZ = 692281337; const lon...
18
#include <bits/stdc++.h> const int MOD = 998244353; using ll = long long; ll factorialNumInverse[100500 + 1]; ll naturalNumInverse[100500 + 1]; ll fact[100500 + 1]; void InverseofNumber(ll p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for (int i = 2; i <= 100500; i++) naturalNumInverse[i] = naturalNumIn...
16
#include <bits/stdc++.h> using namespace std; const int MOD = (1e9) + 7; const int N = 1 << 18; const int TO = 1 << 20; struct multiplication_tree { private: int n; int a[N]; int fpow(int n, int k) { if (n == 0) return 0; if (k == 0) return 1; int p = fpow(n, k >> 1); p = (p * 1ll * p) % MOD; ...
17
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long g, h, l; const long long N = 100005, inf = 1e9 + 5; long long add(long long a, long long b); long long mul(long long a, long long b); long long binpo(long long a, long long b); int main() { ios_base::sync_with_stdio(false); cin.tie(NUL...
8
#include <bits/stdc++.h> using namespace std; char maze[1500 + 5][1500 + 5]; bool visited[1500 + 5][1500 + 5] = {false}; int xy[1500 + 5][1500 + 5][2]; int cx[4] = {-1, 1, 0, 0}; int cy[4] = {0, 0, -1, 1}; int n = 0, m = 0; struct pos { int x, y; }; using namespace std; bool bfs(int tx, int ty) { pos curr; curr.x...
12
#include <bits/stdc++.h> using namespace std; char arr[4] = {'A', 'C', 'G', 'T'}; int ans = 1000000006LL; string s[300005]; int n, m; int isrow; vector<int> anslist; int ansa, ansb; void rowfixed(int a, int b) { vector<int> collist; int c, d; for (int i = 0; i < 4; i++) { if (i != a && i != b) { c = i; ...
13
#include <bits/stdc++.h> using namespace std; int i; int main() { int n, m; scanf("%d", &n); if (n % 2 == 0) { for (int i = 0; i < n / 2; i++) cout << 1; printf("\n"); } else { cout << 7; for (int i = 0; i < n / 2 - 1; i++) cout << 1; printf("\n"); } return 0; }
4
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> t(m), l(m), r(m); for (int i = 0; i < m; i++) cin >> t[i] >> l[i] >> r[i]; vector<int> ans(n); for (int i = 0; i < m; i++) { if (t[i] == 0) continue; for (...
10
#include <bits/stdc++.h> using namespace std; const int N = 110, P = 131, mod = 1e9 + 7; const double PI = 3.1415926535; struct Vector { double x, y; Vector operator-(const Vector& a) { return {x - a.x, y - a.y}; } Vector operator+(const Vector& a) { return {x + a.x, y + a.y}; } double operator*(const Vector& t...
11
#include <bits/stdc++.h> using namespace std; inline int abs(int a) { if (a < 0) { return -a; } else { return a; } } int main() { ios::sync_with_stdio(false); int n, h, a, b, k, ta, fa, tb, fb, ans; cin >> n >> h >> a >> b >> k; for (int i = 1; i <= k; i++) { cin >> ta >> fa >> tb >> fb; a...
2
#include <bits/stdc++.h> using namespace std; bool ers[100000]; int main() { string a; int i = 0; int pr[100000]; int nx[100000]; for (int i = 0; i < 100000; i++) { pr[i] = i - 1; nx[i] = i + 1; } cin >> a; while (i < a.length() - 1 && nx[i] < a.length()) { if (a[i] == '1' && a[nx[i]] == '0'...
12
#include <bits/stdc++.h> int main() { long int a[100000]; long int k; int i, p, n, m; a[0] = 1; p = 2; i = 0; scanf("%d", &k); while (a[i] < k) { i++; a[i] = a[i - 1] + p; p++; } n = i; int l = 0; for (i = 0; i <= n; i++) { for (int j = i; j <= n; j++) { if (a[i] + a[j] == ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, x0, y0, x, y, x1, y1, x2, y2; cin >> n >> x0 >> y0; set<double> lines; for (int i = 0; i < n; ++i) { cin >> x1 >> y1; double m = (y0 - y1); if ((x0 - x1) != 0.0) m = m / (x0 - x1); else m = 9999999.0; lines.insert(...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; while (~scanf("%d", &n)) { int a[n]; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); if (n % 2) { printf("%d\n", a[n / 2]); } else { printf("%d\n", a[n / 2 - 1]); } } return 0; }
6
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& n) { char ch; int sign = 1; while (!isdigit(ch = getchar())) if (ch == '-') sign = -1; n = ch - '0'; while (isdigit(ch = getchar())) n = n * 10 + ch - '0'; n *= sign; } const int INF = 1e9 + 7; const int N = 122222; int n, ...
6
#include <bits/stdc++.h> const int maxn = 1e5 + 10; using namespace std; int n, m; long long a[maxn], b[maxn]; long long min(long long a, long long b) { return a < b ? a : b; } int main() { cin >> n >> m; long long suma = 0, sumb = 0; for (int i = 1; i <= n; i++) cin >> a[i], suma += a[i]; for (int i = 1; i <= ...
11
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> m >> k; if (m >= n && k >= n) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 500030; const int mod = 1e9 + 7; struct SegmentTree { int T[N << 2]; int lazy[N << 3]; void toggle(int v, int l, int r) { if (lazy[v] == -1) return; T[v] = (1LL * lazy[v] * (r - l + 1) % mod); lazy[v + v] = lazy[v]; lazy[v + v + 1] = lazy...
21
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 25; return 0; }
0
#include <bits/stdc++.h> int a[220001], b[220001], t[220001], c[220001]; void add(int index, int n, int val) { for (; index <= n; index += ((index) & (-index))) c[index] += val; } int getSum(int index) { int sum = 0; for (; index > 0; index -= ((index) & (-index))) sum += c[index]; return sum; } template <class...
12
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 77; signed main() { ios_base::sync_with_stdio(0); long long n; cin >> n; vector<vector<long long>> in(n); vector<long long> uwu(72), ans, lul(n); for (long long i = 0; i < n; i++) { long long v; cin >> v; ans.push_back(v); ...
7
#include <bits/stdc++.h> using namespace std; int main() { int q, temp, a, p, n, r, t; cin >> q; for (int i = 0; i < q; i++) { temp = 0; cin >> n >> r; set<int> s; for (int j = 0; j < n; j++) { cin >> a; s.insert(a); } p = s.size() - 1; for (set<int>::iterator it = s.begin(...
5
#include <bits/stdc++.h> using namespace std; struct node { int t, next; } a[800010]; int head[400010], flag[400010], size[400010], us[400010], ms[400010], up[400010]; int mx1[400010], mx2[400010], son[400010], n, tot; inline int rd() { int x = 0; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getch...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 200; int hl, hr, n; int dat[maxn][4]; double cross(complex<double> base, complex<double> x, complex<double> y) { x -= base; y -= base; return (x * conj(y)).imag(); } bool intersect(complex<double> ax, complex<double> ay, complex<double> bx, ...
12
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; const int MAX = 1e5 + 10; int arr[MAX], arr2[MAX]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int second = 0, x = 0; for (int i = 0; i < n; ++i) { cin >> a...
5
#include <bits/stdc++.h> const int INF = 1e9 + 7; int as[200005]; std::pair<int, int> query(int l, int r) { printf("? %d %d\n", l + 1, r); fflush(stdout); int X, F; scanf("%d", &X); static std::map<int, int> times; times[X]++; assert(times[X] <= 3); if (X == -1) exit(0); scanf("%d", &F); return {X, ...
19
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long int MOD = 1e9 + 7; const int N = 1e6 + 6; long long int fact[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); read: long long int n; cin >> n; int cnt[10]; for (int i = 0; i < 10; i++) cnt[i] = 1; i...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); std::cout.precision(8); int n, x; cin >> n; int f = 0, o = 0; for (int i = 0; i < n; i++) { cin >> x; if (x == 5) f++; else o++; } if (o == 0) { cou...
2
#include <bits/stdc++.h> using namespace std; char c[300005]; int nrquiz; int main() { cin >> nrquiz; while (nrquiz--) { int n; cin >> n; vector<bool> ok(n, 0); bool all_same = 1; char x = 'a'; for (int i = 0; i < n; ++i) { cin >> c[i]; if (c[i] != '-') { if (x == 'a') { ...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> ...
24
#include <bits/stdc++.h> using namespace std; long long n, H; long long sum(long long L, long long R) { if (R < L) return 0; return (L + R) * (R - L + 1) / 2ll; } bool check(long long mx) { if (mx - 1 >= H) { if ((double)(H + mx - 1.0) * (mx - H) / 2.0 + mx * (mx - 1.0) / 2.0 >= (double)n) retur...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i, j, l, m; vector<int>::iterator ptr; cin >> n >> k; vector<int> v(n); v.reserve(n); for (i = 1; i <= n; i++) { cin >> j; v.at(i - 1) = j; } sort(v.begin(), v.end()); if (k < n) { if (k == 0) { ptr = v.begin(); ...
4
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[200010]; int check(int task) { int now = 0, qwq = 0; while (1) { now++; qwq = 0; if (now > m) { return 0; } while (qwq <= k) { if (task > n) { return 1; } qwq += a[task]; task++; if (qwq ...
10
#include <bits/stdc++.h> using namespace std; int M, N, K; map<string, int> msi; char cs[161][161]; int tsum[(31 * 24 * 60 + 100)]; int Tm[(31 * 24 * 60 + 100)]; int uset[161]; int edt[161]; int money[161]; int tid[161]; int dp[161][(31 * 24 * 60 + 100)]; int pre[161][(31 * 24 * 60 + 100)]; void outtime(int t) { int ...
18
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; class Mint { private: long long int x; inline static long long int mod = 1e9 + 9; long long int fastPow(long long int x, long long int p) const { if (p == ...
10
#include<bits/stdc++.h> using namespace std; const int mod= 1e9+7; #define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define what_is(x) cerr << #x << " = " << x << endl; typedef long long ll; char a[1009][1009],b[1009][1009]; int main() { fastIO int t; cin>>t; while(t--) { ...
11
#include <bits/stdc++.h> using namespace std; int T, m, d, w; int gcd(int x, int y) { if (x == 0) return y; if (y == 0) return x; return gcd(y, x % y); } void solve() { scanf("%d%d%d", &m, &d, &w); int tmp = gcd(d - 1, w); w /= tmp; tmp = min(m, d); long long ans; if (tmp % w == 0) ans = 1LL * w *...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)(1e5 + 100); const int MAXD = (int)(1e6 + 100); int n; vector<int> x; int a, b; int mods[MAXD]; int dist[MAXD]; int left[MAXD]; void place() { for (int i = 0, sz = x.size(); i < sz; ++i) { int start = (b + x[i] - 1) / x[i] * x[i]; for (int j ...
14
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; vector<int> x(a); vector<int> y(b); int k, m; cin >> k >> m; for (int i = 0; i < a; i++) cin >> x[i]; for (int i = 0; i < b; i++) cin >> y[i]; if (x[k - 1] < y[b - m]) cout << "YES"; else cout << "NO"; retu...
1
#include <bits/stdc++.h> using namespace std; #define int long long void read (int &x) { char ch = getchar(); int f = 0; x = 0; while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x; } const int N = 2e5 + 5, M = N << 1; int...
17
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct Info { int a, b; Info operator+(const Info& B) const { return (Info){a + B.a, max(b + B.a, B.b)}; } }; struct Segment_Tree { const static int NODE = N << 2; bool setv[NODE]; Info A[NODE]; void pushdown(int o, int L, int R) { ...
24
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") const int mods[10] = {1000000007, 999999937, 999999929, 999999893, 999999883, 999999797, 999999761, 999999757, 999999751, 999999739}; const int mod = 1000000007; int rand_mods[2]; const long double eps = 1e-10; const int siz...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q, l, r; cin >> n >> m >> q; string a, b; cin >> a >> b; bool p[n + 1]; for (int i = 0; i < n + 1; i++) { bool f = true; for (int j = 0; j < m; j++) if (a[i + j] != b[j]) { f = false; break; } p[i + ...
5
#include <bits/stdc++.h> using namespace std; int n; int cur; bool f[300010]; vector<int> ans; int main() { scanf("%d", &n); ans.push_back(1); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); f[x] = true; while (f[n - cur]) cur++; ans.push_back(i - cur + 1); } for (int i = 0; i <= n;...
7
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template <typename _T, typename... args> void _DBG(const char *s, _T x, args... a) { while (*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } str...
12
#include <bits/stdc++.h> using namespace std; inline int read() { int 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(); } return x * f; } const int Maxn = 1005; ...
18
#include <bits/stdc++.h> using namespace std; long long HASH1, HASH2, MOD1, MOD2, pw1[100005], pw2[100005], dp1[100005], dp2[100005], MODI1[100005], MODI2[100005], ps[100005], frq[100005]; long long expo(long long base, long long exponent, long long mod) { long long ans = 1; while (exponent != 0) { if ((exp...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a, b; vector<int> c; for (int i = 0; i < n * n; i++) { int ia, ib; cin >> ia >> ib; a.push_back(ia); b.push_back(ib); bool t = false; for (int j = 0; j < a.size() - 1; j++) { if (a[a.size() - ...
2
#include <bits/stdc++.h> using namespace std; void sorted(vector<long long int> &arr) { sort(arr.begin(), arr.end()); } void coutarr(vector<long long int> arr) { long long int n = arr.size(); for (long long int i = 0; i < n; i++) cout << arr[i] << " "; cout << '\n'; } void coutarr2(vector<vector<long long int>> a...
13
#include <bits/stdc++.h> using namespace std; void fileIO() {} bool sortbysecdesc(const pair<long long, long long> &a, const pair<long long, long long> &b) { return a.second > b.second; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); fileIO(); long long T; T = 1; ...
2
#include <bits/stdc++.h> using namespace std; int a; char st[4444]; int sum[4444]; map<int, int> p; long long ans = 0; int len, tot; int main() { cin >> a; scanf("%s", st); for (int i = 0, j = strlen(st); i < j; i++) { sum[i + 1] = sum[i] + st[i] - '0'; } for (int i = 1, len = strlen(st); i <= len; i++) ...
8
#include <bits/stdc++.h> using namespace std; int main() { char c; int len = 0; bool big = false, small = false, dig = false; while (cin >> c) { len++; if (c >= int('A') && c <= int('Z')) big = true; if (c >= int('a') && c <= int('z')) small = true; if (c >= int('0') && c <= int('9')) dig = true...
0