solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; long long n, m, a[100], b[100], x, xx, ans1, ans2, ans; map<double, pair<long long, long long> > mp; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i < n; i++) for (int j = 0; j < m; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; arr[i] = arr[i] % 2; } stack<int> s; for (int i = 0; i < n; i++) { if (s.empty()) s.push(arr[i]); else { if (s.top() == arr[i]) s.pop(); ...
7
#include <bits/stdc++.h> using namespace std; int fx[] = {1, -1, 0, 0}; int fy[] = {0, 0, 1, -1}; int n, m, id; vector<int> G[205], RG[205], assignment; stack<int> st; int vis[205]; void dfs1(int s) { vis[s] = 1; for (int i = 0; i < G[s].size(); i++) { int u = G[s][i]; if (!vis[u]) dfs1(u); } st.push(s)...
5
#include <bits/stdc++.h> using namespace std; int n, pai[200010], ans[200010], T[200010], res; vector<int> adj[200010], tipo[200010], dp[200010]; int go(int u) { T[u] = 0; for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i]; if (v == pai[u]) continue; pai[v] = u; dp[u][i] = (go(v) + tipo[u][...
4
#include <bits/stdc++.h> using namespace std; long long get(long long x) { return (1ll << (x - 1)); } vector<long long> v, q; int main() { ios_base::sync_with_stdio(false); long long n, m; cin >> n >> m; for (long long i = 1; i <= n; i++) { if (m > get(n - i)) { q.push_back(i); m -= get(n - i); ...
3
#include <bits/stdc++.h> using namespace std; set<long long> L; void recurse(long long num) { L.insert(num); if (num > 1000000000) return; long long L1 = num * 10 + 4; long long L2 = num * 10 + 7; recurse(L1); recurse(L2); } int main() { recurse(0LL); set<long long>::iterator it = L.begin(); long long...
1
#include <bits/stdc++.h> using namespace std; int n; const int MAX = 2e5+10; int a[MAX]; int lp[MAX<<2],rp[MAX<<2],mi[MAX<<2]; int lMax[MAX],rMax[MAX]; void pushup(int i){ mi[i] = min(mi[i<<1],mi[i<<1|1]); } void build(int l,int r,int i){ lp[i] = l; rp[i] = r; if(l == r){ mi[i] = a[l]; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int c, c2; map<int, int> mp; int n, m, k; scanf("%d%d%d", &n, &m, &k); for (c = 0; c < n; c++) { int v; scanf("%d", &v); mp[v]++; } for (c = 0; c < m; c++) { int v; scanf("%d", &v); mp[v]--; } vector<int> vals; for (m...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int> A(n + 1); for (int i = 1; i <= n; ++i) { A[i] = i; } vector<long long> S(n + 1); for (int i = 1; i <= n; ++i) { S[i] = S[i - 1] + A[i]; } while (q--...
8
#include <bits/stdc++.h> using namespace std; long long int r, j, l, m, c, n, s, f, q, i, p, y, k, d, t, u, e, g, val, w, x, z; string s1, s2, s3, s4; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int a, b, c; cin >> n >> a >> b >> c >> t; vector<long long int> ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const long long K = 1e17, D = 1e16; int n, a[N]; long long t, s[N]; map<long long, int> ma; void upd(long long i) { for (; i < K; i += i & -i) ma[i]++; } int get(long long i) { int s = 0; for (; i; i -= i & -i) s += ma[i]; return s; } int main...
5
#include <bits/stdc++.h> using namespace std; using INT = long long; const int mod = 1000000007; int flag[2001000], cnt[2001000], ans[2001000], pp[2001000], len, vst[2001000]; int power(int a, int b, int m, int ans = 1) { for (; b; b >>= 1, a = 1LL * a * a % m) if (b & 1) ans = 1LL * ans * a % m; return ans; } ...
10
#include<bits/stdc++.h> using namespace std; #define Vector Point #define Pi acos(-1.0) #define eps 1e-8 #define maxn 200005 #define ll long long #define inf 1000000005 ll k,l,r,t,x,y; map < ll,ll > mp; int main() { ios::sync_with_stdio(false); cin>>k>>l>>r>>t>>x>>y; if(x==y) { if(k+y<=r||k-y>=l) cout<<"Yes...
7
#include <bits/stdc++.h> 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 { ~debug() { cerr << '\n'; } template <class c>...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 100; int a[maxn]; int n; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); for (int i = 2; i <= n / 2 + 1; i++) { if (a[i] != a[i - 1]) { cout << "Alice" << endl; return 0; ...
6
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T a) { return a < 0 ? (-a) : a; } template <typename T> inline T sqr(T x) { return x * x; } int main() { int n; cin >> n; int m = (1 << (n + 1)); vector<long long> v(m, 0); for (int i = 0; i < (m - 2); ++i) { cin >> v[i +...
3
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 1000010; int n, cnt[N], ans, val[N]; long long a[N]; template <typename T> void gi(T &x) { x = 0; register char c = getchar(), pre = 0; for (; c < '0' || c > '9'; pre = c, c = getchar()) ; for (; c >= '0' && c <= '9'; c =...
5
#include <bits/stdc++.h> using namespace std; const int NN = 1e5 + 5, Mod = 1e9 + 7; int Ad(int x, int y) { return ((x + y) >= Mod) ? (x + y - Mod) : (x + y); } int Dc(int x, int y) { return ((x - y) < 0) ? (x - y + Mod) : (x - y); } int Ml(int x, int y) { return (long long)x * y % Mod; } int ksm(int x, int y) { int ...
10
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; int f[1001001][3][3], N; string s; int main() { ios_base::sync_with_stdio(0); cout.precision(15); cin >> s; N = s.size(); s = " " + s; f[0][0][0] = 1; for (int(n) = 1; (n) <= (N); (n)++) for (int(b...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; int Mat[1003][1003]; int main() { int n; while (scanf("%d", &n) != EOF) { int sum = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { cin >> Mat[i][j]; if (i == j) sum = s...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; int v[1000000]; for (int i = 0; i < n; i++) cin >> v[i]; int l = 1, r = 10000000; int best = -1; while (l <= r) { long long tot = 0; int m = l + (r - l) / 2; for (int i = 0; ...
6
#include <bits/stdc++.h> using namespace std; long long func(long long M, long long K, long long x) { if (K * x >= M) return M; return M + (M - K * x - 1) / (K - 1); } long long power(long long x, long long n) { if (n == 0) return 1; long long y = power(x, n / 2); y = y * y % 1000000009ll; if (n % 2 == 1) y...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 10; long long mod[4] = {19260817, 19260817, 19260817, 19260817}; long long o = 1e9 + 7; char s[maxn]; int T, n, k, kk; long long pre[maxn][4], suf[maxn][4], p[maxn][4]; long long h1(int l, int r, int x) { return (pre[r][x] - pre[l - 1][x] * p[r - l ...
3
#include <bits/stdc++.h> using namespace std; namespace { using uint = unsigned int; using uint_col = vector<uint>; int solve(const uint_col &counts, const uint_col &colors, uint pos, uint tgt) { using pos_count_map = map<uint, uint_col>; using count_map = unordered_map<uint, uint>; using pos_color_col = vector<v...
6
#include <bits/stdc++.h> using namespace std; char rev(char s) { return '0' + (1 - (s - '0')); } int main() { string s, s2; cin >> s; int n = s.size(); s = "#" + s; s2 = s; int x = (n - 2) / 2 + (n - 2) % 2, y = n - 2 - x, emp = 0; int ones = 0, zeros = 0; for (int i = 1; i <= n; i++) { if (s[i] == ...
5
#include <bits/stdc++.h> using namespace std; template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v); template <typename A, typename B> ostream &operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.first << ", " << p.second << ")"; } template <typename A> ostream &operator<<(...
9
#include <bits/stdc++.h> using namespace std; const long long MX = 5 * 1000 + 10, INF = 1e12, INF2 = -1e12, D = 1e9 + 7; long long n, m; vector<long long> gr[MX], bgr[MX], out, output, cop[MX]; vector<long long> bfs; vector<pair<long long, long long> > ed; long long mark[MX], mn; long long dis[MX]; bool cmark[MX], bmar...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, m, a[maxn], b[maxn]; string s; void solve() { cin >> n >> s; m = n; for (int i = 0; i < n; i++) { int len = 1; while (i < s.size() && s[i] == '<') { len++; i++; } for (int j = i; j > i - len; j--) { a...
5
#include <bits/stdc++.h> using namespace std; struct zero { int nxt, to; } edge[200000 << 1]; int head[200000], tot = 0; void add_edge(int a, int b) { edge[++tot] = (zero){head[a], b}; head[a] = tot; } int n, m, plk, poi, d1, d2, dep[200000], kl[200000], d[200000], op[200000], h[200000]; bool flag; void aux(i...
8
#include <bits/stdc++.h> using namespace std; vector<int> nxt[53]; int N, sz[53]; long double dp[53][53]; void DP(int x, int p) { sz[x] = 1; for (int l = 0; l <= N; ++l) dp[x][0] = 1; for (auto t : nxt[x]) if (t != p) { DP(t, x); static long double tmp[53]; memset(tmp, 0, sizeof(tmp)); ...
10
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; using ll = long long; using db = long double; const int N = 2e3 + 5; int n, x[N], y[N]; bool vis[N]; string s; inline void pr(int i) { cout << i + 1 << ' '; vis[i] = true; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >>...
9
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (auto i : v) os << i << " "; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for (auto i : v) os << i << " "; return os; } const int N = 233; cons...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 205 * 2; int dp[maxn][maxn][4][2]; struct point { int x, y; point(int x = 0, int y = 0) { this->x = x; this->y = y; } } a[maxn]; double dis(point a) { return sqrt((a.x - 200) * (a.x - 200) + (a.y - 200) * (a.y - 200)); } int n, d; int dfs(po...
5
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 1e5 + 5; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; vector<int> v{6, 10, 14, 15}; while (t--) { int n; cin >> n; if (n < 31) { cout << "NO\n"; } else { cout << ...
0
#include <bits/stdc++.h> #pragma warning(disable : 4244 4267 4018 4996 4800) using namespace std; istream& in = cin; ostream& out = cout; pair<char, char> pos(-1, -1); int n, m; vector<vector<int>> p, q, pback, allowed; vector<pair<char, char>> moves; int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int dy[] = {-1, -1, -1, 0, 0...
10
#include <bits/stdc++.h> using namespace std; const int DIM = 200010; const long long INF = 1e15; int n, m, q, vis[DIM], vis1[DIM], cc; int comp[DIM]; long long d[DIM]; int k[DIM]; long long mi = 0; long long c[DIM], a[DIM]; vector<int> g[DIM], gt[DIM]; vector<int> top; void dfs(int v) { vis[v] = 1; for (int v1 : g...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, min, max; scanf("%d %d %d %d", &n, &m, &min, &max); int ok = 1, cnt = 0, num[110]; for (int i = 0; i < m; i++) { int tmp; scanf("%d", &tmp); if (tmp < min || tmp > max) ok = 0; else num[cnt++] = tmp; } if (!ok) ...
2
#include <bits/stdc++.h> using namespace std; struct order { long long hairs; long long annoyance; size_t index; order(long long hairs, long long annoyance, size_t index) : hairs(hairs), annoyance(annoyance), index(index) {} order() : hairs(-1), annoyance(-1), index(999999) {} }; bool compare1(const ord...
7
#include <bits/stdc++.h> using namespace std; using namespace std; int toInt(char ch) { string str(1, ch); int num; istringstream iss(str); iss >> num; return num; } int main() { vector<char> a_vect; vector<char> s_vect; string a, s; cin >> a >> s; if (a.length() != s.length()) { cout << "NO" <<...
1
#include <bits/stdc++.h> int GetSize(char a[]) { int i; for (i = 0; a[i] != '\0'; i++) ; return i; } void CopyArr(char a[], char b[], int l, int r) { int i, j; for (i = l, j = 0; i <= r; i++, j++) { a[j] = b[i]; } } long long int Max(long long int f, long long int s) { if (f > s) return f; e...
3
#include <bits/stdc++.h> using namespace std; int const N = 5e5, oo = 1e9; int mod = oo + 7; double const eps = 5e-6; int n, s, an, aa[N]; map<int, int> cnt; int main() { cin >> n >> s; for (int i = 0; i < n; i++) { cin >> aa[i]; if (i == s - 1) { if (aa[i]) an++; cnt[0]++; } else cnt[...
5
#include <bits/stdc++.h> using namespace std; clock_t start; void Time(bool timeIt) { if (!timeIt) return; clock_t end = clock(); double elapsed_time = ((double)end - (double)start) / (double)CLOCKS_PER_SEC; printf("Time elapsed = %0.4lf\n", elapsed_time); } int main() { start = clock(); long long p, k, m =...
6
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 0, l = 0; string s = ""; cin >> n; while (cin >> s) { n = s.size(); for (int i = 0; i < n; i++) { if (s[i] < 'a') { m++; } } if (m > l) { l = m; } m = 0; } cout << l; }
0
#include <bits/stdc++.h> using namespace std; bool check(int N) { if (N == 1) return false; for (int i = 2; i * i <= N; i++) { if (N % i == 0) return false; } return true; } int main() { int n; cin >> n; int i; if (check(n)) { cout << 1 << endl; printf("%d\n", n); } else if (n % 2 == 0) { ...
5
#include <bits/stdc++.h> template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; string to_string(const string &s) { return '"' + s + '"'; ...
2
#include <bits/stdc++.h> using namespace std; long long n, k; int a[55]; long long c[55][55][2][2]; bool visited[55][55][2][2]; long long solve(int l, int r, int can10, int can11) { if (l > r) { return 1; } if (visited[l][r][can10][can11]) { return c[l][r][can10][can11]; } visited[l][r][can10][can11] ...
9
#include <bits/stdc++.h> using namespace std; int n, m, k; const int N = (int)1e5; const int K = 8; pair<int, int> a[N]; struct Event { int time; bool type; int id; Event() {} Event(int time, bool type, int id) : time(time), type(type), id(id) {} bool operator<(const Event& other) const { if (time != ot...
8
#include <bits/stdc++.h> using namespace std; int a[200]; vector<int> v; int main() { int i, n, Min, f; bool ff; while (cin >> n) { v.clear(); for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] > 0) v.push_back(a[i]); } sort(a, a + n); for (i = 0; i < n; i += 2) { if (a[i] < 0 &...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll t; cin >> t; while (t--) { ll n, p, k; cin >> n >> p >> k; vector<ll> a(n); for (ll i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); ll price = 0; ll ans = 0; for (ll i = 0; i < n; i++) { ...
3
#include <bits/stdc++.h> using namespace std; int f(int n) { if (n % 2 == 1) return 0; else if (n == 2) return 2; else return 2 * f(n - 2); } int main() { int n; cin >> n; cout << f(n); return 0; }
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; bool vis[501][5001]; int a, b; void solve() { cin >> a >> b; queue<pair<pair<int, int>, string>> q; q.push({{0, 0}, ""}); vis[0][0] = true; string res = "-1"; while (!q.empty()) { int x, y; string s; pair<pair<int, int>...
7
#include "bits/stdc++.h" using namespace std; #define all(v) v.begin(), v.end() #define rep(i, a, n) for (auto i = a; i <= n; i++) #define f(i, n) for (auto i = 0; i < n; i++) #define frev(i, n) for (auto i = n; i >= 0; i--) #define fr first #define sc second #define pb emplace_back #define pf push_front #define mp ma...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; int N; long long modPower(long long a, long long x, long long m) { long long ret = 1; while (x) { if (x % 2) ret = (ret * a) % m; a = (a * a) % m; x >>= 1; } return ret; } int main() { ios::sync_with_stdio(0); cin >>...
6
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; int ans = 0; for (int i = 0; i < 100000000 && x >= 0; i++) { if (x % 2 == 0) x /= 2; else { x--; ans++; } } cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int spid[5][2] = {{0, 0}, {1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int a[50][50]; int n, m, best; void search(int x) { vector<pair<int, int> > tmp; int i, j, xx, yy, x2, y2, x1, y1, flag1 = 0; for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) { if (a[i][j] =...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string c; cin >> c; int n = c.size(); vector<char> intg, frac, ans; for (int i = 0; i < n; i++) { if (c[i] == '.') { int j = i + 1; while (j < min(i + 3, n)) { frac.p...
2
#include <bits/stdc++.h> const double Pi = acos(-1.0); using namespace std; int n, m; int par[1 << 15 + 5], bit[1 << 14 + 5]; int findpar(int x) { if (par[x] != x) par[x] = findpar(par[x]); return par[x]; } int cntm; void merge(int x, int y) { int p1 = findpar(x), p2 = findpar(y); if (p1 == p2) return; if (p1...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int x, n, m; cin >> x >> n >> m; bool ok = false; for (int i = 0; i <= n; i++) { int v = x; for (int j = 0; j < i; j++) v = v / 2 + 10; for (int...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; vector<int> v; bool l[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> l[i]; if (l[i] == 0) { v.push_b...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int N, K; int to[10]; int ok[10]; bool chk_dfs(int v) { ok[v] = 0; bool res = false; if (to[v] == 1) { ok[v] = 1; return true; } if (ok[to[v]] == -1) { res = chk_dfs(to[v]); ok[v] = (res ? 1 : 0); } else if (ok[to[v]] ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int MOD = 1e9 + 7; int v[N], cnt[2], pres[2]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, i, j, k; cin >> n; vector<int> dig; while (n > 0) { dig.push_back(n % 10); n /= 10; }...
2
#include <bits/stdc++.h> using namespace std; int Read() { char c; while (c = getchar(), (c != '-') && (c < '0' || c > '9')) ; bool neg = (c == '-'); int ret = (neg ? 0 : c - 48); while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48; return neg ? -ret : ret; } const int MAXN = 500005; cha...
7
#include <bits/stdc++.h> using namespace std; const int MaxN = 2010; int n; int a[MaxN][MaxN], s[MaxN][MaxN], v[MaxN][MaxN]; void init() { cin >> n; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) scanf("%d", &a[i][j]); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { for (int x...
7
#include <bits/stdc++.h> using namespace std; const int mx = 1e6 + 5; int n, m; int fa[mx]; int a[mx], siz[mx]; vector<int> fat[mx]; inline int f(int x) { return fa[x] == x ? x : fa[x] = f(fa[x]); } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); fa[i] = i; } for (i...
4
#include <bits/stdc++.h> using namespace std; int n; int x11, x22, x12, x21, y11, y22, y12, y21; void solve1() { int lo = 1, hi = n; while (lo < hi) { int mid = (lo + hi) / 2; cout << "? " << 1 << " " << 1 << " " << mid << " " << n << endl; int x; cin >> x; if (x == 0) lo = mid + 1; el...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long p(long long a, long long b) { if (b == 0) return 1; long long tmp = p(a, b / 2); if (b % 2 == 0) return (tmp * tmp) % mod; return ((tmp * tmp) % mod * a) % mod; } long long inv(long long x) { return p(x, mod - 2); } long long...
8
#include <bits/stdc++.h> using namespace std; const int N = 100000; int n, a, b; int p[N]; map<int, int> m; int deg[N]; int ans[N]; int main() { scanf("%d%d%d", &n, &a, &b); for (int i = 0; i < n; i++) { scanf("%d", &p[i]); m[p[i]] = i; } if (n == 1 && (p[0] == a - p[0] || p[0] == b - p[0])) { print...
6
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void c_p_c() {} void solve() { long long n, k = 0; cin >> n; long long i = 0; char res[1000005]; while (n--) { long long x, y; cin >> x >> y; if (x + k <= 500) { k += x; r...
3
#include <bits/stdc++.h> using namespace std; int n; bool ison[100010]; char temp[100]; int q, t; int isprime[100010]; int prime[100010]; vector<int> pr[100010]; void preprocess() { fill(isprime, isprime + 100010, 0); fill(ison, ison + 100010, false); fill(prime, prime + 100010, -1); for (int i = 2; i < 100010;...
4
#include <bits/stdc++.h> using namespace std; int notprime[1005]; void sieve() { for (int i = 2; i * i < 1002; i++) { if (!notprime[i]) { for (int j = 2 * i; j < 1002; j += i) notprime[j] = 1; } } } int main() { sieve(); int n, k, count = 0, sum; cin >> n >> k; int last = 2; for (int i = 3; ...
1
#include <bits/stdc++.h> using namespace std; struct node { int l, r, num; } a[100000]; int main() { int n, p; while (scanf("%d %d", &n, &p) != EOF) { for (int i = 0; i < n; i++) { scanf("%d %d", &a[i].l, &a[i].r); a[i].num = a[i].r / p - (a[i].l - 1) / p; } double ans = 0.0; for (int ...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 998244353; void add(ll &x, ll y){ x = (x + y) % mod; } const ll maxn = 500 + 10; int n; struct Node{ string op; ll num; }no[maxn]; ll ans; queue<int> s, t; ll dp[maxn][maxn]; void work(int pos){ for(int i = 1; i < pos; i++){ if(no[...
7
#include <bits/stdc++.h> using namespace std; char str[5005]; long long sum[5005], c[5005]; int main() { int n; scanf("%s", str + 1); n = strlen(str + 1); for (int i = 1; i <= n; i++) c[i] = c[i - 1] + (str[i] == '+'); long long tot = 0, mul = 1; for (int i = 1; i <= n; i += 2) { if (str[i - 1] == '+') ...
6
#include <bits/stdc++.h> using namespace std; long long b[100]; int main() { long long n, k, t = 0; cin >> n >> k; int a[n + 2]; for (long long i = 0; i < n; i++) { cin >> a[i]; b[a[i] % k]++; } for (long long i = 1; i <= k / 2; i++) { if (i == k - i) t += b[i] / 2; else t += min...
2
#include <bits/stdc++.h> using namespace std; int n, Q; string s[200200]; int ep[200200]; int len[200200]; struct data { int to, nxt; } mp[400400]; int head[200200], cnt; void link(int x, int y) { mp[++cnt].to = y; mp[cnt].nxt = head[x]; head[x] = cnt; } int id[200200], clk; int siz[200200]; void dfs(int x) { ...
10
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; string s; int len; int dp[300000 + 10]; void calc() { int cnt = 0; for (int i = 0; i < len; ++i) { if (s[i] == '(') { cnt++; } else { cnt--; } dp[i + 1] = cnt; } } int main() { cin >> len >> s; int cnt1, cnt2...
8
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 2e6 + 20; const double eps = 1e-8; int pri[N], mip[N], pos[N], c; bool vis[N]; long long n, m, s; long long fac[N], mcnt, pcnt[1000], p[1000]; void prime() { c = 0; memset((vis), 0, sizeof(vis)); for (int i = 2; i <= N; i++) {...
10
#include <bits/stdc++.h> using namespace std; int main() { float a, b, c, d, e, q, w, g, r, t, h, l, tt = 0; cin >> a >> b >> c >> d >> g; cin >> q >> w >> e >> r >> t; cin >> h >> l; if ((0.3) * 500 >= (1 - a / 250) * 500 - 50 * q) tt = (0.3) * 500; else tt = (1 - a / 250) * 500 - 50 * q; if ((0....
1
#include <bits/stdc++.h> using namespace std; const long long OO = (long long)(4e18) + 9; const long long MOD = (long long)(1e9) + 7; const int oo = 2147483647; const double EPS = 1e-8; const double PI = acos(-1.0); int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int dX[] = {1, 0, -1, 0, 1, -1, 1, -1}; int dY[] = {...
3
#include <bits/stdc++.h> using namespace std; int main() { long long t1; t1 = 1; while (t1--) { long long m, n; cin >> m >> n; long long a[m], b[n]; long long k1 = 0, k2 = 0; for (long long i = 0; i < m; i++) cin >> a[i], k1 ^= a[i]; for (long long i = 0; i < n; i++) cin >> b[i], k2 ^= b[i...
5
#include <bits/stdc++.h> using namespace std; string gl = "aeiou "; bool sogl(char c) { return find(gl.begin(), gl.end(), c) == gl.end(); } int main() { string s; cin >> s; for (int i = 2; i < s.size(); i++) { if (sogl(s[i]) and sogl(s[i - 1]) and sogl(s[i - 2]) and (s[i - 2] != s[i - 1] or s[i - 2] !...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; n *= 2; vector<int> arr(n); vector<int> odd(n); vector<int> even(n); int cnt_odd = 0, cnt_even = 0; for (int i = 0; i < n;...
1
#include<bits/stdc++.h> using namespace std; #define lli long long int #define lld long double #define ul unsigned long int #define pii pair<int,int> #define pll pair<lli, lli> #define vi vector<int> #define vii vector<pair<int,int>> #define vll vector<lli> #define pb push_back #define mpr make_pair #define ss sec...
8
#include <bits/stdc++.h> using namespace std; long long int modpow(long long int base, long long int exp, long long int mod) { long long int result = 1; for (base %= mod; exp; exp >>= 1) { if (exp & 1) result = (result * base) % mod; base = (base * base) % mod; } return result; } int main() { ios::syn...
3
#include <bits/stdc++.h> using namespace std; template <typename T> using vc = vector<T>; using pii = pair<long long, long long>; void xmax(long long& a, long long b) { a = max(a, b); } void xmin(long long& a, long long b) { a = min(a, b); } void print(vc<long long>& a, string second) { cerr << second << " : "; for...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; const int N = 300000 + 10, M = 20 + 2, max_val = 1000000000; int n; struct segme { int l, r; }; vector<segme> a, b, c; segme find_intersection(vector<segme> v) { segme tmp; tmp.l = 0; tmp.r = max_val; if (((int)((v).size(...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, a, b, d; cin >> n; a = n / 7; b = n % 7; if (b == 4) { cout << 4; for (i = 1; i <= a; i++) cout << 7; return 0; } else if (b == 5) { a = a - 1; b = 7 + 5; b = b / 4; if (a < 0) { cout << -1 <<...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; char alp = 'a'; int c = 0; int i = 0; int check = 1; while (i < s.size()) { if (s[i] <= alp) { s[i] = alp; if (alp == 'z') { break; } alp++; c++; } if (26 - c > s.size() - i - 1...
2
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 5; int n, a[N], b[N], c[N], x, y; int main() { cin.tie(0); cout.tie(0); ios_base ::sync_with_stdio(); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n + 1; j++) b[j] = 0; x = y = 0...
3
#include <bits/stdc++.h> using namespace std; const int MN = 2e6 + 100; int last[MN]; int cnt[MN]; int main() { ios::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; i++) { int t; cin >> t; cnt[t]++; } int ls = -1; for (int i = 0; i < MN; i++) { last[i] = ls; if (cnt[i]) { ...
6
#include <bits/stdc++.h> using namespace std; void main0(); int main() { clock_t start, end; ios::sync_with_stdio(false); cin.tie(0); main0(); return 0; } const int dx[8] = {0, 1, -1, 0, 1, 1, -1, -1}; const int dy[8] = {1, 0, 0, -1, 1, -1, -1, 1}; const int N = 2e5 + 5; const int M = 1e5; const int INF = 0x3...
0
#include <bits/stdc++.h> using namespace std; int main() { int num, j; cin >> num; vector<int> arr(num); int maxi = arr[0], index; for (j = 0; j < num; j++) { cin >> arr[j]; if (arr[j] >= maxi) { maxi = arr[j]; index = j; } } int ans1 = index + 1; arr[index] = -1; maxi = arr[0]...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); if (n + m == 2) return puts("1") & 0; if (n + m <= 4) return puts("-1") & 0; if (n == 1 || m == 1) { for (int i = 2; i <= n * m; i += 2) printf("%d%c", i, n < m ? ' ' : '\n'); for (int i = 1; i <= n * m; i += 2...
5
#include <bits/stdc++.h> using namespace std; int a[200000]; double f[200000]; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } f[0] = a[0]; for (int i = 1; i < n; i++) { f[i] = f[i - 1] + a[i]; } double sum = f[k - 1]; for (int i = 1, j = i + ...
2
#include <bits/stdc++.h> using namespace std; int main(void) { int n; int a[1000]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; a[n] = 0; int last = 0; int sum = 0; bool home = true; for (int i = 0; i < n; i++) { if (home) { if (a[i] == 1) { sum++; home = false; }...
0
#include <bits/stdc++.h> using namespace std; vector<int> v; int ar[1004]; int main() { int m, n, c = 0; string s, t; cin >> m >> n; cin >> s >> t; int lns = s.size(), lnt = t.size(); int j = 0, a = 0, k = 1, b = 0, p = 0, mn = INT_MAX, arln = 0, i = 0; while (i <= lnt - lns) { if (s[a++] != t[b++]) {...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; if (n == k) { cout << "YES" << endl; return 0; } n = n / k; if (n % 2 != 0) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double pi = acos(-1); int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; const int N = 1004; string t, s; int memo[N][N]; int solve(int i = 0, int j = 0) { if (j == (int)s.size()) { return (int)t.size() - i; ...
6
#include <bits/stdc++.h> using namespace std; char grid[1005][1005]; char obj[1005][1005]; int main() { int n, m; int i, j; int mtch = 1; scanf("%d", &n); scanf("%d", &m); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { grid[i][j] = '.'; } } for (i = 0; i < n; i++) { scanf("%s", ob...
2