solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int xa, ya, xb, yb, xf, yf, t; int main() { scanf("%d", &t); while (t--) { scanf("%d %d", &xa, &ya); scanf("%d %d", &xb, &yb); scanf("%d %d", &xf, &yf); bool lineX = xf == xa && xa == xb && yf > min(ya, yb) && yf < max(ya, yb); bool li...
0
#include <bits/stdc++.h> using namespace std; template <typename T> void re(T &x) { x = 0; int f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - 48; c = getchar(); } x *= f; } templa...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; char ch; long long int x, y; long long int initialmaxh = 0; long long int initialmaxw = 0; while (t--) { cin >> ch >> x >> y; if (ch == '+') { if (x >= y...
7
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; string input; cin >> input; pair<int, int> start_point = make_pair(0, 0); int idx_start = 0; pair<int, int> curr_loc = make_pair(0, 0); vector<pair<int, int> > points; points.push_back(start_point); for (int i = 0; i < n...
6
#include <bits/stdc++.h> using namespace std; int main() { int i, n, l, r, f = 0; cin >> n; int a[n + 1]; char s[n + 1], ss[n + 1]; vector<pair<int, int> > v; v.push_back(make_pair(-1, -1)); for (i = 1; i <= n; i++) { cin >> a[i]; v.push_back(make_pair(a[i], i)); } sort(v.begin(), v.end()); ...
8
#include <bits/stdc++.h> using namespace std; struct chill { long long r; long long c; long long x; }; vector<long long> cm, c12; vector<chill> c3; long long ara[105][105]; int main() { long long n, m, q, t, x; cin >> n >> m >> q; chill cl; for (int i = 0; i < q; i++) { cin >> t; cm.push_back(t); ...
6
#include <bits/stdc++.h> using namespace std; const int MAXSIZE = 1e6 + 10; const int MOD = 1e9 + 7; long long int mod(long long int a) { a %= MOD; if (a < 0) a += MOD; return a; } const double PI = 2 * acos(0.0); long long int digit(long long int x) { return floor(log10(x)) + 1; } long long int digit_sum(long lo...
0
#include <bits/stdc++.h> using namespace std; void floy(vector<vector<long long> > &matr, vector<long long> &ans, vector<long long> &arr, int n) { for (int k = n - 1; k >= 0; --k) { for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) matr[i][j] = min(matr[i][j], matr[i][arr[k]] + matr[...
9
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); int main() { int n; string s; cin >> n; cin >> s; int cnt = 0; int ans = 0; for (int i = 0; i < (int)s.size(); i++) { if (s[i] == '8') { cnt++; } int local = min(cnt, ((int)s.size() - cnt) / 10); ans = max(an...
0
#include <bits/stdc++.h> using namespace std; int s; int a, b, c; long double fun(long double x, long double y, long double z) { return a * log(x) + b * log(y) + c * log(z); } long double calc(long double x) { long double lo = 0, hi = s - x, ans = 0; int loop = 0; while (loop++ < 400) { auto m1 = lo + (hi -...
10
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for (int _t=0; _t<t;++_t) { int arr[4]; for (int i=0; i<4;++i) {cin >> arr[i];} sort(arr,arr+4); cout << arr[0]*arr[2] << '\n'; ...
0
#include <bits/stdc++.h> using namespace std; long long int extgcd(long long int a, long long int b, long long int& x, long long int& y) { if (b == 0) { x = 1; y = 0; return a; } else { int g = extgcd(b, a % b, y, x); y -= a / b * x; return g; } } long long int hcf(lon...
2
#include <bits/stdc++.h> using namespace std; int n, d, K, second[300005]; vector<pair<int, int> > G[300005]; long long ad[300005 << 2], mn[300005 << 2]; void dtp1(int u, int v) { ad[u] += v, mn[u] += v; } void dt(int u) { if (ad[u]) dtp1(u << 1, ad[u]), dtp1(u << 1 | 1, ad[u]), ad[u] = 0; } void add(int u, int l, in...
23
#include <bits/stdc++.h> using std::cin; using std::cout; using std::deque; using std::endl; using std::map; using std::max; using std::min; using std::set; using std::string; using std::swap; using std::vector; const int MOD = 998244353; const int inf = 1000000000; const int N = 100005; long long power(const long long...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1e9 + 7; const ll INF = 1e18 + 9; ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1) ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; } return ans; } ll gcd(ll a, ll b) {...
7
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") long long mod = 1e9 + 7; const long long INF = 1e18; const double eps = 1e-6; const int maxn = 5e2 + 5; template <class T> inline bool scan_d(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; wh...
15
#include <bits/stdc++.h> using namespace std; void init() {} int main() { init(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, m; cin >> n >> m; long long int a[n + 1]; for (long long int i = 1; i < n + 1; i++) cin >> a[i]; while (m--) { long long int l, r, x; cin >> l >>...
4
#include <bits/stdc++.h> using namespace std; const long long int mod = (1e9) + 7; const long long int N = 2 * (1e5); const long long int maxo = 1e14; const long long int inf = 1e6; long long int fastpow(long long int a, long long int b) { if (b == 0) return 1; long long int ans = fastpow(a, b / 2); return b & 1 ...
6
#include <bits/stdc++.h> using namespace std; int n, m; int a[100010]; pair<int, int> ps[100010]; priority_queue<int, vector<int>, greater<int> > q; int main() { a[0] = 1000000001; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= m; i++) scanf("%d", &ps[i].first); f...
16
#include <bits/stdc++.h> using namespace std; bool TG[410][410]; bool BG[410][410]; int visited[410]; int n, m, timer = 0; void printGraph() { for (int i = 0; i < n; i++) { cout << i + 1 << " : "; for (int j = 0; j < n; j++) { if (TG[i][j]) cout << j + 1 << " "; } cout << endl; } cout << "==...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int odd = 0, even = 0; int x; for (int i = 0; i < n; i++) { cin >> x; if (x & 1) odd++; else even++; } if (odd == 0 or even == 0) cout << "...
1
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> l[100007], d[100007], t[100007]; int ds[100007]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &l[i].first); l[i].second = i; t[i].first = l[i].first; } for (int i = 0; i < n; ++i) { scanf("%d", &d[i].f...
11
#include <iostream> #include <fstream> #include <set> #include <unordered_set> #include <string> #include <queue> #include <algorithm> #include <vector> #include <array> #include <cmath> #include <map> #include <limits.h> #include <numeric> #include <valarray> #include <stdio.h> #include <iomanip> #include <stack> #inc...
17
#include <bits/stdc++.h> using namespace std; mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); long long inf = 1e18, MOD = 1e9 + 7; long long n, m, k, ar[1000005], grundy[500][3], x, y, z, period, start; string s, s1; map<vector<vector<long long> >, long long> ma; long long mex(vector<long long> v...
17
#include <bits/stdc++.h> int main() { char word[1001]; scanf("%s", word); char rek[6] = "heidi"; int j = 0; int total = 0; for (int i = 0; word[i] != '\0'; i++) { if (word[i] == rek[j] && j <= 4) { total++; j++; } } if (total == 5) { printf("YES\n"); } else { printf("NO\n")...
0
#include <bits/stdc++.h> using namespace std; int n, m, x, y, c; char arr[55][55]; bool check[55][55]; bool eih = false; void fun(int i, int j) { if (i == x && j == y && c == -1 && check[i][j + 1] && check[i + 1][j]) { eih = true; return; } if (j + 1 <= m && arr[i][j + 1] == arr[i][j] && !check[i][j + 1] ...
7
#include <bits/stdc++.h> int x[4], y[4]; bool derecho() { int a = (x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]); int b = (x[2] - x[0]) * (x[2] - x[0]) + (y[2] - y[0]) * (y[2] - y[0]); int c = (x[2] - x[1]) * (x[2] - x[1]) + (y[2] - y[1]) * (y[2] - y[1]); if ((a && b && c) == 0) { return fals...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1000000007; const int MOD2 = 998244353; const int INF = 1 << 30; const ll INF2 = (ll)1 << 60; void scan(int& a) { scanf("%d", &a); } void scan(long long& a) { scanf("%lld", &a); } template <class T, class L> void scan(pair<T, L>& p) { ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; const long long N = 500 * 1000 + 10, MOD = 1e9 + 7; long long a[N], s[N]; bool dp[N]; long long d, k, n; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); ; cin >>...
13
#include <bits/stdc++.h> using namespace std; const int MX = 256; const int AL = 26; int dp[MX][MX][MX]; int nxt[AL][100001]; string s[3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; string t; cin >> n >> q >> t; for (int i = n; i >= 0; --i) { for (int j = 0; j < AL; ++j) { if...
14
#include <bits/stdc++.h> using namespace std; void adskiy_razgon() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int mxN = 1e+9 + 7; const long long INF = 1e+18 + 7; int nod(int a, int b) { if (a == 0 || b == 0) { return 0; } else if (a == b) { return a; } else if (a > b) { re...
4
#include <bits/stdc++.h> const long long maxn = 3e3 + 9, mod = 998244353, inf = 1e18; long long Read() { long long 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) + (x << 1ll) + c - '0'; c = getch...
17
#include <bits/stdc++.h> using namespace std; bool notPower(long long k) { if (k - (k & (-k)) != 0) return true; return false; } int main() { long long n, k; cin >> n >> k; while (notPower(k)) { long long i = 0; while (1ll << i <= k) i++; i--; k -= 1ll << i; } long long i = 0; while (1ll...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = static_cast<ll>(1e9) + 7; const int MAXN = static_cast<int>(5e3) + 17; struct query { int l, r, i; query() {} }; struct segtree { int n; vector<ll> T; segtree() {} segtree(int n) : n(n) { T.resize(4 * n, 0); } void upd(int ...
10
#include <bits/stdc++.h> using namespace std; template <class T> void print(vector<T> a) { int n = a.size(); for (long long i = 0; i < n; ++i) { cout << a[i] << (i == n - 1 ? "\n" : " "); } } int sum_vector(vector<int> v) { return accumulate(v.begin(), v.end(), 0); } void sort_vector(vector<int> &v) { sort(v....
15
#include <bits/stdc++.h> int main() { int t; std::cin >> t; while (t--) { int n; std::cin >> n; if ((n / 2) % 2 == 0) { std::cout << "YES" << std::endl; for (int i = 1; i <= n / 2; i++) { std::cout << 2 * i << ' '; } for (int i = 1; i < n / 2; i++) { std::cout <...
0
#include <bits/stdc++.h> using namespace std; vector<int> v(200005), a(200005); int ng, ns, in; long long ans; map<int, int> mp; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> v[i]; if (v[i] == m) in = i; if (v[i...
10
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr)...
12
#include<bits/stdc++.h> using namespace std; int num[105]; bool vis[200005]; int n,sum; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>num[i]; sum+=num[i]; } if(sum%2==1){ cout<<"0"<<endl; return 0; } sum/=2; vis[0]=1; for(int i=1;i<=n;i++){ for(i...
9
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC target("avx") using namespace std; const int inf = ~0u >> 1, mod = 1e9 + 7; struct Frw { char *TT, *m...
18
#include <bits/stdc++.h> using namespace std; int main() { size_t n{}, t{}, sumY{}, sumA{}, sumB{}, sumX{}; size_t count{}; int arr[2][2]{}; cin >> n; while (count++ < n) { cin >> t; if (t == 1) { cin >> arr[0][0]; cin >> arr[0][1]; sumX += arr[0][0]; sumA += arr[0][0] + arr[0]...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 10; vector<pair<int, int> > a[MAXN]; int ptr[MAXN], b[MAXN], e_v[MAXN], sz[MAXN], total; bool markv[MAXN], mark[MAXN], mark2[MAXN]; pair<int, int> e[MAXN]; void dfs(int v, int u, int id) { while (ptr[v] < a[v].size()) { pair<int, int> u2 = a[v][...
18
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int flag = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] == 'a' && flag) { break; } if (s[i] != 'a') { flag = 1; s[i] -= 1; } } if (!flag) { s[s.size() - 1] = 'z'; } cout << s; retur...
4
#include <bits/stdc++.h> #pragma GCC optimize("-O2") using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\t"; err(++it, args...); } template <typename T1, typenam...
10
#include <bits/stdc++.h> using namespace std; inline int getint() { int f = 1, x = 0; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x * f; } inline long long getll() { long long f = 1, x...
2
#include <bits/stdc++.h> using namespace std; int n, m; int a[510][510], b[510][510], da[510 << 1][510], db[510 << 1][510]; vector<int> va[510 << 1], vb[510 << 1]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { scanf("%d", &a[i][j]); va[i + j - 1].pus...
7
#include <bits/stdc++.h> using namespace std; const int N = 100000, geps = 10; int n, k[N + geps], f[N + geps], ans = 0; void Init() { scanf("%d", &n); for (int i = (1); i <= (n); ++i) scanf("%d", &k[i]); } void Solve() { Init(); k[0] = -10000; k[n + 1] = 2147483647; for (int i = (1); i <= (n); ++i) if ...
8
#include <bits/stdc++.h> using namespace std; int n, t; vector<int> v[100001]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) if (i * (i + 1) / 2 > n) { int k = 0; for (int ii = 1; ii <= i - 1; ii++) for (int jj = ii + 1; jj <= i; jj++) { k++; v[ii].push_back(...
8
#include <bits/stdc++.h> using namespace std; int n, m, k; int ran[2005]; int par[2005]; long long modexp(long long a, long long b) { long long res = 1; while (b > 0) { if (b % 2 == 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return res; } int find_set(int x) { if (par[x]...
8
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 500; long long g, r, n, q, l[N], ad[N]; set<pair<long long, pair<long long, long long> > > s; vector<pair<long long, long long> > v; vector<long long> rrr; map<long long, long long> mp; bool llerval(long long l, long long rr, long long x) { if (r...
20
#include <bits/stdc++.h> using namespace std; int ar[1000009]; int check(int a) { int s, d, f, g, h, j, k; if (ar[a] == ar[a - 1] && ar[a] == ar[a - 2] && ar[a] == ar[a - 3]) return 1; return 0; } int check1(int a) { int s, d, f, g, h, j, k; s = !ar[a]; if (s == ar[a - 1] && s == ar[a - 2] && s == ar[a - 3]...
5
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; void boost() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { boost(); 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 >>...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, i, t1[5000], t2[5000], t3[5000], x = 0, y = 0, z = 0, w, s; scanf("%d", &n); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { if (a[i] == 1) { t1[x] = i + 1; x++; } else if (a[i] == 2...
0
#include <bits/stdc++.h> using namespace std; const int N = 10004; vector<pair<int, int> > G[N]; long long int inf = 1LL << 60, d[N]; int w[2 * N], R[N], n, m, k, f, s1, s2, jak[N], skad[N]; set<pair<long long int, int> > kol; bool uzyte[N]; void Dijkstra() { int a; for (int i = 1; i <= n; i++) d[i] = inf; d[f] =...
20
#include <bits/stdc++.h> using namespace std; int n, m; bool check(int len, vector<int> &jedi, vector<int> k) { int pass = 0; for (int c = 1; c < (int)k.size(); c++) { if (k[c] == 0) { pass += 1; } } for (int i = 0; i < len; i++) { int c = jedi[i]; k[c] -= 1; if (k[c] == 0) { pas...
7
#include <bits/stdc++.h> using namespace std; const long double pi = acosl(-1); const long double radian = 180 / pi; const long double eps = 1e-12; const int inf = 0x7f7f7f7f; const long long infll = 0x7f7f7f7f7f7f7f7fll; const long double infl = 1e20; inline int sgn(const long double &x) { return (x > eps) - (x < -eps...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; int len[110] = {0}; cin >> n >> k; string str[n]; string pass; for (int i = 0; i < n; i++) { cin >> str[i]; len[str[i].length()]++; } cin >> pass; int passlen = pas...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000005; int last[MAXN], ver[MAXN], nxt[MAXN], cnt; int flag[MAXN], dg[MAXN], odd[MAXN], bln[MAXN], ans, num, sum; inline int read() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') { ...
16
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 30, Mod = 1e9 + 7; const long long SQ = 330; long long x[N << 2], y[N << 2], z[N << 2], xy[N << 2], yz[N << 2], xyz[N << 2], lazy[N << 2], a[N], n, q; void Ass(int id, int val) { lazy[id] += val; x[id] += val; y[id] += val; z[id] += val...
19
#include <bits/stdc++.h> const int MaxN = 1e5; using namespace std; int n, step[MaxN + 5], cnt[MaxN + 5]; int main() { while (~scanf("%d", &n)) { memset(step, 0, sizeof(step)); memset(cnt, 0, sizeof(cnt)); for (int i = 1; i <= n; i++) { int x; int pre = 0, c = 0; scanf("%d", &x); i...
11
#include <bits/stdc++.h> using namespace std; const int c=200005; int w, n, ert[c], ans[c], mini, mindb, maxi, dif; int kerd(int a, int b, int c) { cout.flush() << "? " << a << " " << b << " " << c << "\n"; int x; cin >> x; return x; } int main() { ios_base::sync_with_stdio(false); cin >> w; ...
22
#include <bits/stdc++.h> using namespace std; using lli = long long; void solve() { lli n, k; cin >> n >> k; string s; cin >> s; lli dp[n + 1]; for (int i = 0; i < n; i++) { if (s[i] == '0') dp[i + 1] = 1; else dp[i + 1] = 0; } dp[0] = 0; for (int i = 1; i <= n; i++) dp[i] += dp[i ...
8
#include <bits/stdc++.h> using namespace std; const int MX = 3000; stack<int> k; string s, t; int n = 0; int main() { cin >> s; n = s.size(); t.assign(n, '0'); for (int i = int(0); i < int(n); i++) { if (s[i] == '1') k.push(i); else { if (k.empty()) continue; t[k.top()] = '1'; k....
12
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; template <typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); } template <typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); } const int MAX = 110; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int k = ceil(n / 2.0); if (n % 2) { cout << k * k + (k - 1) * (k - 1); } else { cout << k * n; } cout << endl; for (int i = int(0); i < n; i++) { for (int j = int(0); j < n; j++) { if (i % 2 == 0) { if ...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; double seg[N * 4], m[N * 4], ad[N * 4]; int a[N]; void init(int pos, int l, int r) { m[pos] = 1, ad[pos] = 0; if (l == r) { seg[pos] = a[l]; return; } int mid = (l + r) >> 1; init(pos * 2, l, mid), init(pos * 2 + 1, mid + 1, r); se...
15
#include <bits/stdc++.h> typedef long long LL; LL cal(int x) { return 1ll * x * (x + 1) / 2; } int main() { int T; scanf("%d", &T); while(T--) { int x; scanf("%d", &x); int l = 1, r = x; while(l < r) { int mid = (l + r) >> 1; if(cal(mid) >= x) ...
4
#include <bits/stdc++.h> using namespace std; long long BIT[111111]; int n = 0; int BIT_Modify(int r, long long delta) { for (int i = r; i > 0; i -= (i & (-i))) BIT[i] += delta; return 0; } long long BIT_Query(int x) { if (x <= 0) return 0; long long sum = 0; for (int i = x; i <= n; i += (i & (-i))) sum += BI...
6
#include <bits/stdc++.h> int min(int a, int b) { return a < b ? a : b; } void append(int **ej, int *eo, int i, int j) { int o = eo[i]++; if (o >= 2 && (o & o - 1) == 0) ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]); ej[i][o] = j; } int main() { static int *ej[2][200000], eo[2][200000], dd[200000 * 2]...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, t; cin >> n >> t; long long int a[n], b[n]; long long int i; for (i = 0; i <= n - 1; i++) { cin >> a[i] >> b[i]; } long long int l = 0, r = n; vector<long long...
10
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long a, b, s = 0, i; cin >> a >> b; long long ar[a]; for (i = 0; i < a; i++) cin >> ar[i]; for (i = 1; i < a; i++) s += ar[i]; if (b > (ar[0] + s)) cout << ar[0] + s << endl; else...
0
#include <bits/stdc++.h> using namespace std; long long n, m; long long a[1007], f[1007]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (long long i = 0; i < n; ++i) { cin >> a[i]; if (f[a[i] % m]) { cout << 0 << endl; return 0; } f[a[i] % m]++;...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, k; while (cin >> n >> a >> b) { if (b < 0) { b = -b; for (int i = 0; i < b; i++) { a--; if (a == 0) a = n; } } else if (b >= 0) { for (int i = 0; i < b; i++) { a++; if (a == n + 1)...
2
#include <bits/stdc++.h> using namespace std; long long p, l, r, k; struct Matrix { long long d[2][2]; Matrix() { d[0][1] = d[1][0] = d[0][0] = d[1][1] = 0; } }; Matrix operator*(const Matrix& a, const Matrix& b) { Matrix ans; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k <...
16
#include <bits/stdc++.h> int main() { int a, b, t, n, B; scanf("%d%d%d", &n, &a, &B); int cnt = 0, num = 0, flag = 1, temp = 0, cnt1 = 0; while (n--) { scanf("%d", &t); if (t == 1) { if (b <= 0 && flag) { temp = cnt; flag = 0; } if (a > 0) a--; else { ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, c; cin >> n >> m >> k >> c; long long a[n + 1], b[m + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; long long d = (m + 1) - c; if (b[d] > a[k]) cout << "YES" << endl; else cout...
1
#include <bits/stdc++.h> using namespace std; long long int a[100005]; long long int dp[100005]; int main() { int i, j, k, t, go; long long int an; cin >> t >> go; a[0] = 1; dp[0] = 1; long long int mod = 1e9 + 7; for (i = 1; i <= 100000; i++) { a[i] = a[i - 1]; if (i - go >= 0) a[i] += a[i - go];...
9
#include <bits/stdc++.h> using namespace std; pair<double, double> toOrigin(pair<double, double> a, pair<double, double> b) { return {b.first - a.first, b.second - a.second}; } double cross(pair<double, double> a, pair<double, double> b) { return (a.first * b.second) - (a.second * b.first); } bool pointInPoly(pair<...
8
#include <bits/stdc++.h> using namespace std; int n; string s; vector<int> len; int main() { int l = 0, i, sum = 1; cin >> n; while (cin >> s) { l += s.length(); if (s.substr(s.length() - 1, 1) == "." || s.substr(s.length() - 1, 1) == "?" || s.substr(s.length() - 1, 1) == "!") { len....
8
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007LL; const double PI = 2 * acos(0); int main(void) { std::ios_base::sync_with_stdio(false); int n, i, j; set<int> row, col; map<int, int> row2, col2; char ch; cin >> n; for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) { ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string a, b; cin >> a >> b; reverse(b.begin(), b.end()); if (b.length() > a.length()) swap(a, b); int x = a.length() - b.length(); for (int k = 1; k <= x; k++) b = '0' + b; long long int ans = 0...
4
#include <bits/stdc++.h> using namespace std; long long int powr(long long a, long long b) { if (b == 0) { return 1; } if (b % 2 == 0) { return powr(((a % 1000000007) * (a % 1000000007)) % 1000000007, (b / 2) % 1000000007); } else { if (b == 1) { return a; } else { re...
8
#include <bits/stdc++.h> using namespace std; int c, m, x; bool valid(int team) { int baki = (c - team) + (m - team) + x; if (baki >= team) return 1; else return 0; } int Bin() { int lo = 0, hi = min(c, m), mid, res = 0; while (lo <= hi) { mid = (lo + hi) / 2; if (valid(mid)) { res = mid...
4
#include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for(int i=0;i<t;i++) { int n; cin >> n; int a[n]; for(int j=0;j<n;j++) { cin >> a[j]; } int ans=0; a[n-1]++; int c[2*n+2]; for(int j=0;j<...
0
#include <bits/stdc++.h> int main() { std::cout.precision(14); const long double EPS = 1e-12; long double a, b, m, vx, vy, vz, result_x, result_z, pos_x, pos_y, pos_z; std::cin >> a >> b >> m >> vx >> vy >> vz; pos_z = 0; pos_x = a / 2; pos_y = m; while (true) { long double d_to_door, d_to_floor_cei...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 500100; int n; char s[MAXN]; long long ans, tmp; long long hist[MAXN]; int main() { scanf("%d", &n); scanf("%s", s); memset(hist, -1, sizeof hist); for (int i = (0); i < int(n); i++) { if (s[i] == '0') { ans += tmp; continue; } ...
16
#include<bits/stdc++.h> #define ll long long #define ld long double #define F first #define S second #define ii pair<int,int> using namespace std; const ll MOD=1e9+7; const ld eps=1e-9; const int N=2e5+10; int a[N]; void solve(){ int n,k=0,m; scanf("%d%d",&n,&k); char ch[n]; scanf("%s",ch); string s=ch; for(i...
0
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; #define all(x) x.begin(),x.end() #define point pair<ll, ll> #define X first #define Y second void solve() { int n, m; cin>>n>>m; vector<int> v[n][2]; char grid[n][n]; for(int i = 0; i < n; i++) for...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int Array[n + 1]; int sum = 0; for (int i = 1; i <= n; i++) { cin >> Array[i]; if (Array[i] == 1) { sum++; Array[i] = -1; } else Array[i] = 1; } int solution[n + 1]; solution[0] = 0; for (int j = ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; double q[n]; for (int i = 0; i < n; i++) { cin >> q[i]; q[i] /= 100.0; q[i] = 1.0 - q[i]; } double ans = n; double t[n]; for (int i = 0; i < n; i++) t[i] = q[i]; for (int qz = 0; qz < 1000000; qz++) { double pr...
19
#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; inline int nxt() { int x; scanf("%d", &x); return x; } const int L = 21; const int N = 1 << L; struct Max2 { int x, y; Max2() : x(-1), y(-1) {} void refresh(int z) { if (z > x) { y = x; x = z; } else if (z > y) { y = z; } } void...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; const int S = 18; vector<pair<int, int> > Edges[N]; int JumperPoint[N][S + 2]; int VertexDepth[N]; int EdgePrefixSum[N]; int Edge_FoolsTravelingThrough[N]; void WczytajDane(int &n, int &m) {} void LiczWartosci(int v) { for (int i = 0; i < (int)Edge...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 10000; char a[110], c[110]; int s, b, d, n1, n2, l1, l2; int f[110], g[110]; long long ans = 0; int main() { cin >> b >> d; scanf("%s%s", a, c); l1 = strlen(a); l2 = strlen(c); for (int i = 0; i < l2; i++) { int n2 = i; for (int j = 0; j <...
12
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int min1 = -2000000000; long long int max1 = 2000000000; while (n--) { string str; cin >> str; if (str.length() == 1 && str[0] == '<') { long long int num; cin >> num; char ch; c...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; int b = 0; cin >> n; string s; cin >> s; for (int i = 0; i < s.size(); i++) if (s[i] == s[i + 1]) ++b; cout << b; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int a[maxn]; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int main() { int i, j; long long a, b, x, y; cin >> a >> b >> x >> y; long long g = gcd(x, y); x = x / g; y = y / g; long long k1 = a / x; long long...
2
#include <bits/stdc++.h> using namespace std; int main() { long long x, y; cin >> x; y = x / 2520; cout << y << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int maxn = 1e6 + 10; const int K = 1e6; int sum[maxn << 2]; void push_up(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; } void update(int x, int z, int l, int r, int rt) { if (l == r) { sum[rt] += z; return; } int mid = (l +...
16
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; inline int max(int a, int b) { return a < b ? b : a; } inline int min(int a, int b) { return a > b ? b : a; } inline long long max(long long a, long long b) { return a < b ? b : a; } inline long long min(long long a, long long b) { return a > b ? b ...
1