solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #pragma GCC diagnostic ignored "-Wmissing-declarations" vector<string> a; vector<string> rr; void solve(string& s, int n, int cur = 0) { if (cur == n) { rr.push_back(s); return; } if (s[cur] == '?') { for (char c = 'a'; c <= '...
9
#include <bits/stdc++.h> using namespace std; const int N = 100010; long long n, c[N], ans[N], pw[64]; queue<long long> q[64]; int main() { cin >> n; pw[0] = 1; for (int i = 1; i <= 60; i++) pw[i] = pw[i - 1] << 1; for (int i = 1; i <= n; i++) { cin >> c[i]; for (int j = 60; j >= 0; j--) if (c[i] ...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 300002; int edge[maxn][5], d[maxn], res[maxn]; int m, n; void read() { memset(d, 0, sizeof(d)); memset(res, 0, sizeof(res)); int u, v; while (m--) { scanf("%d %d", &u, &v); edge[u][d[u]++] = v; edge[v][d[v]++] = u; } return; } void d...
14
#include <bits/stdc++.h> using namespace std; template <typename... As> struct tpl : public std::tuple<As...> { using std::tuple<As...>::tuple; tpl() {} tpl(std::tuple<As...> const& b) { std::tuple<As...>::operator=(b); } template <typename T = tuple<As...> > typename tuple_element<0, T>::type const& x() cons...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, sx, sy, k, p[4] = {0, 0, 0, 0}, a, b, i, j = 0; cin >> n >> sx >> sy; for (i = 0; i < n; i++) { cin >> a >> b; if (a > sx) p[0]++; else if (a < sx) p[1]++; if (b > sy) p[2]++; else if (b < sy) p[3]++; }...
5
#include <bits/stdc++.h> using namespace std; int i, j, ind[2000005], lf[2000005], rg[2000005]; vector<long long> a; vector<pair<int, int> > pr, npr, st, nst; vector<pair<int, long long> > g[2000005]; long long ans, n, k; void dfs(int v, long long x = 0, int p = -1) { a.push_back(x); for (int i = 0; i < g[v].size()...
21
#include <bits/stdc++.h> using namespace std; int A[10010], last[10010], ans[10010]; int n; string s; int main() { memset(A, 0, sizeof(A)); int T, i, j, m; cin >> n; m = n * (n + 1) / 2; int sr = sqrt(m); int ok = 0; for (i = 2; i <= sr; i++) { if (m % i == 0) { ok = 1; cout << "Yes" << en...
3
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N], cnt = 1, k; int val; void go(int l, int r) { int mid = (l + r) >> 1; if (r == l) return; if (r == l + 1) { a[l] = val--; return; } if (cnt == k) { for (int i = r - 1; i >= l; i--) a[i] = val--; return; } cnt += 2...
10
#include <bits/stdc++.h> int n, m, tot[4]; std::vector<long long> vec[4]; struct node { long long val; int cnt1, cnt2; bool operator<(const struct node &rhs) const { return val < rhs.val; } } dp[(300010)]; long long pre_dp[(300010)]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { long ...
15
#include <bits/stdc++.h> using namespace std; template <class T> inline T checkmin(T &a, T b) { return (a < b) ? a : a = b; } template <class T> inline T checkmax(T &a, T b) { return (a > b) ? a : a = b; } template <class T> T GCD(T a, T b) { if (a < 0) return GCD(-a, b); if (b < 0) return GCD(a, -b); return ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i; string s[30]; cin >> n; for (i = 0; i < n; i++) { cin >> s[i]; } for (i = 0; i < n; i++) { if (s[i].substr(s[i].length() - 2) == "po") { cout << "FILIPINO" << endl; } else if (s[i].substr(s[i].length() - 4) == "desu" || ...
0
#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 n; pair<int32_t, int32_t> tree[400001][20]; long long power[...
12
#include <bits/stdc++.h> template <typename T> inline void rd(T& x) { int si = 1; char c = getchar(); x = 0; while (!isdigit(c)) si = c == '-' ? -1 : si, c = getchar(); while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); x *= si; } template <typename T, typename... Args> inline void rd(T& x, Args&... arg...
20
#include <bits/stdc++.h> using namespace std; int a, b, n, l, h; set<int> st; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); string f, l; cin >> f >> l; cout << f[0]; for (int i = 1; i < f.length(); ++i) { if (f[i] >= l[0]) break; else cout << f[i]; } cout << l[0];...
2
#include <bits/stdc++.h> const int fin = 0, maxn = 6001, maxm = maxn * (maxn - 1) / 2 + 10; int n; bool flag[maxm]; int p[maxm / 3], c[maxn]; void pre(int n) { int i, j; for (i = 2; i <= n; ++i) { if (!flag[i]) p[++p[0]] = i; for (j = 1; j <= p[0] && i * p[j] <= n; ++j) if (flag[i * p[j]] = 1, i % p[j...
14
#include <bits/stdc++.h> using namespace std; bool dp[110][350][60][2]; string second; int n, ans = -(1 << 29); char opp(char ch) { if (ch == 'F') return 'T'; return 'F'; } void Calc(int cur, int pos, int nn, int dir) { if (cur == second.size()) { if (n == nn) { ans = max(ans, abs(pos - 150)); ret...
10
#include <bits/stdc++.h> using namespace std; int n, t1, t2; long long a[200005], b[200005], c[200005], s1, s2; bool fst() { if (s1 != s2) return s1 > s2; for (int i = 0; i < min(t1, t2); i++) { if (a[i] > b[i]) return 1; if (a[i] < b[i]) return 0; } if (t1 != t2) return t1 > t2; return c[n - 1] > 0; ...
6
#include <bits/stdc++.h> using namespace std; long long a[100001], b[100001]; long long n, m; long long f(long long x) { long long result = 0; for (long long i = 0; i < n; i++) { if (x > a[i]) result += x - a[i]; } for (long long i = 0; i < m; i++) if (x < b[i]) result += b[i] - x; return result; } vo...
9
#include <bits/stdc++.h> using namespace std; unsigned int n, a, b, c, d; inline unsigned int f(unsigned int x) { return ((a * x + b) * x + c) * x + d; } inline unsigned int geta(unsigned int x) { unsigned int ans = 0, p = x; const unsigned int lim = n / p; while (p <= n) { ans += n / p; if (p > lim) brea...
17
#include <bits/stdc++.h> using namespace std; using ll = long long int; using dl = double; const int N = 2e5 + 10; ll aarray[200000 + 10]; ll magic[101][101]; vector<ll> primes; bool prime[1000001]; int main() { ios_base::sync_with_stdio(false); string str; ll i, j, n, m, k, t, l, r, p1, p2, p3; cin >> str; c...
5
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { fast(); long long n, m; cin >> n >> m; long long sum = 0; for (long long i = 0; i < m; i++) { long long x, d; cin >> x >> d; sum += x * n; if (d >= 0) { ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, h, m; cin >> n >> h >> m; int l, r, x; vector<int> v; v.assign(n, h * h); while (m--) { cin >> l >> r >> x; for (int i = l - 1; i < r; ++i) { v[i] = min(v[i], x * x); } } int ...
0
#include <bits/stdc++.h> using namespace std; const int INF = (int)1.01e9; const int N = 1 << 18; int main() { int n; while (scanf("%d", &n) == 1) { vector<int> a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a.begin(), a.end()); printf("%d\n", max(0, a[n - 1] - 25)); } return 0; }
0
#include <bits/stdc++.h> inline int read() { char c = getchar(); int x = 0; bool sgn = false; while (c < '0' || c > '9') { if (c == '-') { sgn = true; } c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c & 15); c = getchar(); } return sgn ? -x : x; } c...
17
#include <bits/stdc++.h> using namespace std; const int MAX_N = 519; int a[MAX_N], b[MAX_N], last[2 * MAX_N], d[MAX_N][MAX_N]; pair<int, int> pr[MAX_N][MAX_N]; set<int> s; map<int, int> ma; vector<int> numbers; int main() { int n, m; scanf("%d", &n); for (int i = 0; (i) < (n); ++i) scanf("%d", &a[i]), s.insert(a[...
20
#include <bits/stdc++.h> using namespace std; namespace RenaMoe { template <typename T> inline void read(T &x) { x = 0; bool f = false; char ch = getchar(); while (!isdigit(ch)) f |= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); if (f) x = -x; } const int N = 1e6 + 9;...
23
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; int cur = m; for (int i = 0; i < n; i++) { int x; cin >> x; if (x < cur) { cur -= x; cout << "0 "; } else { int ans = 1; x -= cur; ans += x / m; ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); ; double nr1; cin >> nr1; double r1, fr1 = 0; for (double i = 0; i < nr1; i++) { cin >> r1; fr1 = (max(fr1, r1)); } double nden1; cin >> nden1; double den1, fden1 = 0; for (double i = 0; i < nden1;...
5
#include <bits/stdc++.h> using namespace std; namespace suffix_automaton_array { std::vector<int> len, link, pos; std::vector<std::vector<int> > child; const int alpha = 26, start_char = 'A'; int init() { len.clear(); link.clear(); child.clear(); pos.clear(); len.push_back(0); pos.push_back(-1); link.push...
15
#include <bits/stdc++.h> using namespace std; int main() { long long x; cin >> x; cout << 1 + x * (x + 1) * 3 << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; vector<int> ansx, ansy; int n, er; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; if (n % 4 == 1 || n % 4 == 0) { cout << "YES" << "\n"; er = n % 4; if (n % 4) n--; for (int i = 1; i <= n; i += 4) { int a = i; in...
23
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __pri...
12
#include <bits/stdc++.h> using namespace std; int m = 0, mask[11], cnt[6][6], N; vector<pair<int, int> > cards; int next_mask() { m++; for (int i = int(0); i <= int(9); i++) mask[i + 1] = (m >> i) & 1; return m != (1 << 10); } int okay() { pair<int, int> a[N]; for (int i = int(0); i <= int(N - 1); i++) { ...
9
#include <bits/stdc++.h> using namespace std; int n, m, a[200100], is[200100]; int main() { int i, j, k, Ans = 0; scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); j = n / 2 + 1; for (i = 1; i <= n / 2; i++) { while (j < n && a[j] - a[i] < m) j++; if (a[j] -...
12
#include <bits/stdc++.h> using namespace std; long long int powe(long long int a, long long int b) { long long int ans = 1; for (; b; b >>= 1) { if (b & 1) ans = ans * a; a = a * a; } return ans; } class Comp { public: bool operator()(pair<long long int, long long int> a, pair<long ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0; cin >> n; string s[n]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { char ch; cin >> ch; s[i].push_back(ch); } } for (int i = 0; i < n; ++i) { int c = 0; for (int j = 0; j < n; ++j) { ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:268435456") using namespace std; template <class T> T abs(T &x) { return (x >= 0) ? (x) : (-x); } template <class T> T sqr(T &x) { return (x) * (x); } template <class T> T min(T &a, T &b) { return (a < b) ? (a) : (b); } template <class T> T max(T &a, T &b) ...
5
#include <bits/stdc++.h> using namespace std; double coo[70000], v[70000]; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> coo[i]; } for (int i = 0; i < n; i++) { cin >> v[i]; } int bb = 60; double lo = 0, mid = 0.0, hi = 1000...
8
#include <bits/stdc++.h> using namespace std; int fact[1000050]; int main() { ios::sync_with_stdio(false); fact[0] = 1; for (int i = 1; i < 1000050; i++) fact[i] = (fact[i - 1] * 1ll * i) % 1000000007; int n, m; cin >> n >> m; vector<vector<int> > pokemonIin(m); for (int i = 0; i < n; i++) { int c...
11
#include <bits/stdc++.h> using namespace std; string a, b; int v[200010]; bool subsir(int k) { string ac = a; for (int i = 0; i < k; ++i) { ac[v[i] - 1] = '*'; } int r, poz = 0; for (int i = 0; i < b.length(); ++i) { r = ac.find(b[i], poz); if (r == -1) { return false; } poz = r + 1;...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> girls; vector<int> pizza; vector<int> taxi; vector<string> v; while (n--) { int k; string s, t; cin >> k >> s; int p = 0, ta = 0, g = 0; for (int f = 0; f < k; f++) { cin >> t; if (t[0] ...
4
#include <bits/stdc++.h> using namespace std; int main() { int x, y, a, b; scanf("%d %d %d %d", &x, &y, &a, &b); if (x <= a && y <= b || x + y <= max(a, b)) { printf("Polycarp\n"); } else { printf("Vasiliy\n"); } return 0; }
9
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); printf("%d\n", n * (n + 1ll) % 4 == 0 ? 0 : 1); }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; long long f[MAXN][2], dat[MAXN]; inline int read() { int x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x; } int main() { ios::sync_with_s...
15
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (; t--;) { int n, x, k, c, y = 0; cin >> n >> x; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); vector<int> v1; for (int i = 0; i < n; i++) { int j;...
1
#include <bits/stdc++.h> int main() { long long a, b, c, d; scanf("%lld%lld", &a, &b); for (c = 1; c <= b; c++) { if (a % c != c - 1) { printf("No\n"); return 0; } } printf("Yes\n"); return 0; }
8
#include <bits/stdc++.h> using namespace std; long long n, a[505000], ans; multiset<long long> s; signed main() { cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; } for (long long i = 1; i <= n; i++) { if (!s.empty() && *s.begin() < a[i]) { ans += a[i] - *s.begin(); s.erase(s.begi...
16
#include <bits/stdc++.h> using namespace std; long long n, cnt = 1, ans, a[200005], b[200005]; signed main() { cin >> n; while (n--) { long long c, x, y; cin >> c; if (c == 1) { cin >> x >> y; a[x] += y; ans += x * y; } if (c == 2) { cin >> x; b[++cnt] = x; an...
8
#include <bits/stdc++.h> using namespace std; const int N = 400; int n, v, e; long long sum = 0; int a[N + 1], s[N + 1], fa[N + 1], b[N + 1]; vector<int> nei[N + 1]; int getFather(int i) { if (fa[i] == -1) return i; return fa[i] = getFather(fa[i]); } bool vis[N + 1]; bool mark[N + 1]; int currentVo; vector<pair<int...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; int cnt = 0; cin >> n; string s; char c; while (n != 0) { s = to_string(n); c = s[0]; for (int i = 0; i < s.size(); i++) { if (s[i] > c) c = s[i]; } n -= stoi(to_string(c)) - 48; cnt++; } cout << cnt; }
3
#include <bits/stdc++.h> int INF = 99999; int main() { std::string a, b; int n; std::cin >> a >> b >> n; if (a.size() != b.size()) { std::cout << -1 << std::endl; return 0; } std::vector<std::vector<int> > g(26, std::vector<int>(26, INF)); for (int i = 0; i < n; ++i) { char x, y; int w; ...
10
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } ...
2
#include <bits/stdc++.h> using namespace std; int n; int main() { int a; while (cin >> n) { map<int, int> G; while (n--) { scanf("%d", &a); if (G.find(a) != G.end()) G[a]++; else G[a] = 1; } map<int, int>::iterator iter = G.begin(); while (iter != G.end() && ite...
4
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1e9 + 7; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; int c = 0; for (int i = 2 * n; i <= 4 * n; i += 2) { c++; cout << i << " "; if (c == n) break; } cout << "\n"; ...
0
#include <bits/stdc++.h> using namespace std; int all[500], n, m; int main() { scanf("%d%d", &n, &m); memset(all, 0, sizeof(all)); for (int i = 0; i < n; i++) scanf("%d", &all[i + 1]); for (int i = 1; i <= n; i++) all[i] += all[i - 1]; int ans = 0; for (int i = 0; i < m; i++) { int l, r; scanf("%d%d...
4
#include <bits/stdc++.h> using namespace std; const long double epsilon = 1e-9; bool is_valid(vector<int> v) { if (v[1] > 12) return false; int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (v[0] % 4 == 0) m[1]++; return v[2] <= m[v[1] - 1]; } int main() { vector<int> y(3), v(3); scanf("%d.%d...
9
#include <bits/stdc++.h> using namespace std; inline void Swap(long long &x, long long &y) { long long Temp = x; x = y; y = Temp; } inline long long Min(long long x, long long y) { return x < y ? x : y; } inline long long Max(long long x, long long y) { return x > y ? x : y; } inline void read(long long &x) { x...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[205]; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int t1[205], t2[205], ans = -999999999; for (int i = 0; i < n; ++i) { for (int j = i; j < n; ++j) { int n1 = 0, n2 = 0, tp = 0; for (int k = 0; k ...
7
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(0); long long n, k, l, r, res, r1, l1; cin >> n >> k; vector<int> a(n, 1); vector<int> lin(n); for (int i = 0; i < n; i++) { cin >> lin[i]; lin[i]--; } for (int i = 0; i < n; i++) { ...
6
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; long long mod = 1000000007LL; long long mod2 = 998244353LL; int n; int p[200005]; int pmax[200005][20]; int pos[200005]; long long ans; void dfs(int l, int r) { if (l >= r) return; int pw = 0; while ((1 << pw) <= (r - l + 1)) { pw++; ...
14
#include <bits/stdc++.h> using namespace std; long long a, b, d[1001], y[100001], dp[1001][1001]; int main() { scanf("%lld%lld", &a, &b); for (int i = 1; i <= a; i++) { scanf("%lld", &d[i]); } sort(d + 1, d + a + 1); long long pp = 1; for (int i = d[1]; i <= d[a]; i++) { while (pp < a && i >= d[pp +...
17
#include <bits/stdc++.h> using namespace std; string a; vector<int> pod; int n, m, u; bool func(int k) { m = 0; for (int i = 0; i < k - 1; i++) { pod[a[i]]++; if (pod[a[i]] == 1) { m++; } } for (int l = 0, r = k - 1; r < n; l++, r++) { pod[a[r]]++; if (pod[a[r]] == 1) { m++; ...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; typedef long long ll; void my_return(ll code) { exit(code); } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll my_exp(ll a, ll b, ll MOD = numeric_limits<ll>::max()) { a %= MOD; if (b == 0) { return 1; } else { ...
11
#include <bits/stdc++.h> using ll = long long; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; using p = std::pair<int, int>; int n, m; std::vector<std::string> stage; std::vector<std::vector<int>> color; int num = 0; void dfs(p u, p pre = p(-1, -1)) { color[u.first][u.second] = num; for (int i = 0; i < 4; i++)...
12
#include <bits/stdc++.h> using namespace std; int n, m, x, y; vector<int> v[3005]; long long cal(int k) { vector<int> bk; long long res = 0; long long cnt = v[1].size(); for (int i = 2; i <= m; i++) { int num = v[i].size(); for (int j = 0; j < num; j++) { if (num - j >= k) { res += v[i][j]...
9
#include <bits/stdc++.h> using namespace std; bool busy[8][8], safe[8][8]; char r1[8], r2[8], wk[8], b[8]; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1}; void kill(char *str, bool rook) { int x = str[0] - 'a', y = str[1] - '1'; if (rook) { for (int d = 0; d < 4; ++d) { f...
9
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; void read(long long &x) { char ch = getchar(); x = 0; while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); } const long long N = 1e5 + 10; long long n, q, mx, sum, k, c[N], dis[N]; long long cnt...
25
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; long long prod; for (int i = 3;; i++) { prod = (i * (i + 1)) / 2; if (n < prod) { n = (i * (i - 1)) / 2; break; } } int a = (sqrt((8 * n) + 1) - 1...
8
#include <bits/stdc++.h> using namespace std; int w[1005], h[1005], v[1005]; int n, ans = 0x3f3f3f3f; void solve(int H) { int sum = 0, cnt = 0, cc = 0; for (int i = 0; i < n; ++i) { if (h[i] > H && w[i] > H) return; if (h[i] > H) { ++cnt; sum += h[i]; continue; } if (w[i] > H) { ...
11
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2, typename T3> class triple { public: T1 first; T2 second; T3 third; triple() { first = 0; second = 0; third = 0; } }; const int maxn = 2e5 + 9; const int INF = 1e9 + 9; const int LOG = 2e1 + 2; int n, m, q; int h[max...
8
#include <bits/stdc++.h> using namespace std; int a[1007][1007]; int b[1000007]; map<int, int> mp; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = a[i][0]; j <= a[i][1]; j++) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { int m, n, sum; while (~scanf("%d%d", &m, &n)) { int hx; sum = 0; int ans = 1; for (int i = 0; i < m; i++) { scanf("%d", &hx); sum += hx; if (sum > n) { ans++; sum = hx; } } printf("%d\n", ans);...
2
#include <bits/stdc++.h> using namespace std; int cost[200][200]; int x[200], y[200]; int a[200]; int dis[200]; bool vis[200]; int main(int argc, char *argv[]) { ios_base::sync_with_stdio(false); int n, d; cin >> n >> d; for (int i = 2; i < n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin...
13
#include <bits/stdc++.h> using namespace std; char c[1001]; vector<int> v; int main() { int n; cin >> n; if (n == 1) { cin >> c[1]; cout << c[1]; return 0; } for (int i = 1; i <= n; i++) { cin >> c[i]; } for (int i = 2; i <= n; i++) { if (n % i == 0) v.push_back(i); } sort(v.begin(...
1
#include <bits/stdc++.h> using namespace std; const int N = 1001000; int nx[N], vis[N], d[N], cnt[N], all[N]; vector<int> g; int main() { int p, k; cin >> p >> k; if (k == 0) { long long res = 1; for (int i = 0; i < p - 1; i++) { (res *= p) %= (int)(1e9 + 7); } cout << res << endl; retur...
10
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const long long mod = (long long)1e9 + 7; const double pi = acos(-1.0); const double eps = (double)1e-9; const int dx[] = {0, 0, 1, 0, -1}; const int dy[] = {0, 1, 0, -1, 0}; const int N = 100500; int n, m; pair<int, pair<int, int> > p[N]; struct e...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 123; int siz[N], son[N], fa[N], top[N], dep[N], dfn[N], tot; struct Edge { int to, pre; } e[N * 2]; int ecnt = 0, h[N]; void addedge(int u, int v) { e[ecnt] = (Edge){v, h[u]}; h[u] = ecnt++; } void dfs1(int u, int t) { top[u...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 50; int main() { std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { long long x, y, k; cin >> x >> y >> k; long long cnt = y * k + k - 1; long long ans = cnt / (x - 1) + k; if (cnt % (x - 1)) ans++; cout <...
2
#include <bits/stdc++.h> using std::endl; using std::map; using std::priority_queue; using std::string; using std::vector; int main(void) { using std::cin; using std::cout; std::ios_base::sync_with_stdio(false); cin.tie(0); string S; cin >> S; const int N = S.size(); int lastInd = -1; priority_queue<i...
8
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 7; long long arr[MAXN]; pair<long long, long long> A[MAXN]; long long n, m; long long dx[5] = {1, -1, 0, 0}; long long dy[5] = {0, 0, 1, -1}; char maps[100][100]; bool found; bool visited[200][200]; long long power(long long x, long long y) { ...
7
#include <bits/stdc++.h> using namespace std; vector<int> out; vector<int> used(50); vector<vector<int> > arr(1000); int t = 0; bool dfs(char v) { used[v] = 1; for (int i = 0; i < arr[v].size(); i++) if (used[arr[v][i]] == 0) { if (dfs(arr[v][i])) return 1; } else if (used[arr[v][i]] == 1) { ret...
8
#include <bits/stdc++.h> using namespace std; template <typename... T> void read(T&... args) { ((cin >> args), ...); } template <typename... T> void write(T&&... args) { ((cout << args << " "), ...); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, drink, drinkNeed(0); long long...
7
#include <bits/stdc++.h> using namespace std; long long dp[100001][2]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long n, a[100000]; cin >> n; vector<int> v(100001); for (int i = 0; i < n; i++) { cin >> a[i]; v[a[i]]++; } dp[1][1] = v[1]; dp[1][0] = 0; for (long long i = 2...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, k, ans, s[5005][5005]; inline int read() { int num = 0; char cc = getchar(); while (cc < 48 || cc > 57) cc = getchar(); while (cc > 47 && cc < 58) num = (num << 1) + (num << 3) + (cc ^ 48), cc = getchar(); return num; } inline i...
16
#include <bits/stdc++.h> using namespace std; int n; const long double ep = 1e-10; inline char nc() { static char buf[100000], *l = buf, *r = buf; return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r) ? EOF : *l++; } template <class T> void read(T &x) { x = 0; int f =...
20
#include <bits/stdc++.h> using namespace std; vector<long long int> a, b; long long int fep(long long int x, long long int y, long long int mod) { long long int res = 1; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res % mod; } int main() { ios_base::sy...
1
#include <bits/stdc++.h> using namespace std; long long power(long long x, unsigned long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long modInverse(long long n, long long p) { return power(n...
8
#include <bits/stdc++.h> using namespace std; double PI = acos(-1.0); long long mod = 1e9 + 7; long long GCD(long long a, long long b) { if (b == 0) return a; return GCD(b, a % b); } long long prod(long long a, long long b) { long long res = 0; a %= mod; while (b) { if (b & 1ll) res = (res + a) % mod; ...
5
#include <bits/stdc++.h> int n, r, c, len[1000086], next[20][1000086]; char buf[6000086], *pos[1000086]; int main() { gets(buf); sscanf(buf, "%d%d%d", &n, &r, &c); memset(buf, ' ', sizeof(buf)); gets(buf); buf[strlen(buf)] = ' '; char *cp = pos[1] = buf; for (int i = (2), asdf = (n + 1); i <= asdf; ++i) {...
13
#include <bits/stdc++.h> using namespace std; const int kN = 2e5 + 10; int N, M; long long L[kN], R[kN]; struct Event { long long x; long long l, r; int type, id; bool operator<(const Event& e) const { if (x != e.x) return x < e.x; else return type > e.type; } } es[2 * kN]; int e_cnt; int ...
12
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long mint = 0x7fffffff; const long long linf = 1000000000000000000LL; const long long mod = 998244353LL; const double eps = 1e-3; const int N = 1000020; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while...
18
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long int sum = 0; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int i = 0, j = 0; int m = INT_MIN; while (i < n && j < n) { if (a[i] > 0 && a[j] > 0) { ...
4
#include <bits/stdc++.h> using namespace std; istream& in = cin; ostream& out = cout; template <class T> void outputArray(const vector<T>& ar, ostream& out) { for (size_t i = 0; i < ar.size(); ++i) out << ar[i] << " "; out << endl; } typedef struct Item* PItem; struct Item { Item(int val, int prior) : value...
10
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int arr[3], a, b, c, sum = 0; cin >> arr[0] >> arr[1] >> arr[2]; sort(arr, arr + 3); c = arr[2]; b = arr[1]; a = arr[0]; if (c <= (a + b)) { sum = (a + b + c) / 2; cout...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
11
#include <bits/stdc++.h> using namespace std; int N; int min1, max1, min2, max2, min3, max3; int res1, res2, res3; int main() { scanf("%d", &N); scanf("%d%d", &min1, &max1); scanf("%d%d", &min2, &max2); scanf("%d%d", &min3, &max3); res3 = min(max(N - max1 - max2, min3), max3); N -= res3; res2 = min(max(N ...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 50; const long long M = 1e9 + 7; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } void solve() { int n; scanf("%d", &n); if (n == 3) { puts("5"); ...
9
#include <bits/stdc++.h> using namespace std; int baseres(const vector<int> &base, int v) { for (auto x : base) v = min(v, v ^ x); return v; } int baseres(const vector<int> &base, int len, int v) { for (int i = 0; i < len; ++i) v = min(v, v ^ base[i]); return v; } vector<int> baseof(const vector<int> &sum) { ...
16
#include <bits/stdc++.h> using namespace std; void solve() { int n; scanf("%d", &n); int maxi = 0; int arr[n]; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } int i; for (i = n - 1; i > 0 && arr[i - 1] >= arr[i]; i--) ; for (; i > 0 && arr[i - 1] <= arr[i]; i--) ; printf("%d\n", i)...
4
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 5; const long long mod = 1e9 + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(0)); long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; n *= 3; bool used[n]; ...
12