solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<pair<int, int>> arr; pair<int, int> x, y; int xmax = INT_MIN, xmin = INT_MAX, ymax = INT_MIN, ymin = INT_MAX; for (int i = 0; i < n; i++) { cin >> x.first >> x.second; xmax = max(xmax, x...
13
#include <bits/stdc++.h> using namespace std; template <typename T> void Minimize(T& x, T y) { x = min(x, y); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, firstPosition, lastPosition; cin >> n >> firstPosition >> lastPosition; vector<int> x(n + 1); for (int i = 1; i <= n; ++i) { ...
17
#include <bits/stdc++.h> using namespace std; int a[5050]; set<int> S; void solution() { int n, k; cin >> n >> k; S.clear(); for (int i = (1); i <= (n); i++) { scanf("%d", &a[i]); S.insert(a[i]); } set<int>::iterator itend = S.end(); int q; cin >> q; int need; for (int QQQ = (1); QQQ <= (q);...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int n, m, i, j, flag = 1; cin >> n >> m; long long int a[n][m]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) cin >> a[i][j]; } ...
4
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:36777216") template <class T> void chmax(T& l, const T r) { l = max(l, r); } template <class T> void chmin(T& l, const T r) { l = min(l, r); } void reader(int& x) { int k, m = 0; x = 0; for (;;) { (k) = getchar_unlocked(); i...
13
#include <bits/stdc++.h> int main() { int k, n, s, p, b, c; scanf("%d %d %d %d", &k, &n, &s, &p); for (int i = 1; i <= 100000; i++) { b = s * i; if (b / n >= 1) { c = i; break; } } if (c * k % p == 0) printf("%d\n", c * k / p); else printf("%d\n", c * k / p + 1); return 0; ...
0
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int n) { long long int r; if (n == 0) return 1; else if (n == 1) return a; else r = power(a, n / 2); if (n % 2 == 0) return ((r) % 1000000007) * ((r) % 1000000007) % 1000000007; else return ((r) ...
0
#include <bits/stdc++.h> int main() { long long int p = 0, l, r, k, i = 0, n = 0, res = 1, fuck = 0; scanf("%I64d %I64d %I64d", &l, &r, &k); if (l == 1) { printf("1 "); fuck = 1; } while (res <= r / k && res * k <= r) { res *= k; if (res >= l && res <= r) { printf("%I64d ", res); f...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 25; const double EPS = 1e-9; bool graph[MAXN][MAXN]; int degree[MAXN]; double p[MAXN]; double a[MAXN * MAXN][MAXN * MAXN]; double x[MAXN * MAXN]; int equ, var; void BuildEquation(int n, int target) { int i, j, k, h, cur; double t1, t2; equ = var = n *...
19
#include <bits/stdc++.h> using namespace std; long long s[300005]; int n; long long cal(int k) { long long ans = 1, x = 2; while (k) { if (k & 1) ans *= x; x *= x; x %= 1000000007; ans %= 1000000007; k /= 2; } return ans; } int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("...
7
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); template <class T = int> T __rand(T range = numeric_limits<T>::max()) { return (T)(rng() % range); } template <class T> ostream& operator,(ostream& out, const T& thing) { return out << ", " << thing; }...
20
#include <bits/stdc++.h> using namespace std; int main(void) { long long n, ok = 0; cin >> n; for (long long i = 0; i < 1000; i++) { if (i * 1234567 > n) break; for (long long j = 0; j < 10000; j++) { double k = (n - j * 123456 - i * 1234567) * 1.0 / 1234; if (k < 0) break; if (k == floo...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, sum = 0; cin >> n; long long a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } sort(a, a + n); for (int i = a[n - 1];; i++) { if (n * i - sum > sum) { cout << i; break; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; int T, n, m, a[100005]; signed main(void) { cin >> T; while (T--) { int ans = 0; cin >> n >> m; vector<int> cnt(m, 0); for (int i = 1; i <= n; i++) cin >> a[i], a[i] %= m, cnt[a[i]]++; for (int i = 1; i <= m / 2; i++) { int x = i, y = m - i; if (cnt[x] ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int coffee[n]; for (int i = 0; i < n; i++) cin >> coffee[i]; sort(coffee, coffee + n, greater<int>()); int L = 1, R = n, mid, ans = -1; while (L <= R) { mid = (L + R) / 2; ...
9
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class T> inline void amin(T &x, const T &y) { if (y < x) x = y; } template <class T> inline void amax(T &x, const T &y) { if (x < y) x = y; } template <class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp ...
18
#include <bits/stdc++.h> using namespace std; long long int pwr(long long int base, long long int p, long long int mod) { long long int ans = 1; while (p) { if (p & 1) ans = (ans * base) % mod; base = (base * base) % mod; p /= 2; } return ans; } long long int gcd(long long int a, long long int b) { ...
7
#include <bits/stdc++.h> using namespace std; typedef struct point { long long x, y; point() {} point(long long x, long long y) : x(x), y(y) {} } point; point u(0, 1); long long operator*(point &a, point &b) { return a.x * b.x + a.y * b.y; } long long operator%(point &a, point &b) { return a.x * b.y - a.y * b.x; ...
19
#include <bits/stdc++.h> using namespace std; const long long int M = 1000000007; const long long int N = 1e5 + 1; double PI = 2 * acos(0.0); vector<long long int> isprime(N, true); vector<long long int> prime; vector<long long int> spf(N); void seive() { isprime[0] = isprime[1] = false; for (long long int i = 2; i...
0
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class ...
17
#include <bits/stdc++.h> using namespace std; void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } pair<int, int> operator*(const pair<int, int> &p, const pair<int, int> &x) { pair<int, int> np = make_pair(p.first * x.firs...
17
#include <bits/stdc++.h> using namespace std; void amn(long long &x, long long y) { x = min(x, y); } void amx(long long &x, long long y) { x = max(x, y); } const long long INF = 1e18; const long long N = 2e5 + 5; pair<long long, long long> seg[4 * N]; pair<long long, long long> combine(pair<long long, long long> a, ...
15
#include <bits/stdc++.h> using namespace std; long long getint() { long long summ = 0, f = 1; char ch; for (ch = getchar(); !isdigit(ch) && ch != '-'; ch = getchar()) ; if (ch == '-') { f = -1; ch = getchar(); } for (; isdigit(ch); ch = getchar()) summ = (summ << 3) + (summ << 1) + ch - 48; ...
14
#include <bits/stdc++.h> using namespace std; const int N = 105; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; char ans[N][N]; bool cc[7]; int n, m, k; void draw_right(int x, int y) { for (int i = 0; i < 7; i++) cc[i] = 0; for (int i = 0; i < 4; i++) { int xx = dx[i] + x, yy = dy[i] + y; ...
13
#include <bits/stdc++.h> namespace Myns { namespace iostream_ { using std::cerr; using std::cin; using std::cout; using std::endl; using std::ios; } // namespace iostream_ namespace iomanip_ { using std::fixed; using std::setprecision; } // namespace iomanip_ namespace string_ { using std::getline; using std::string;...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k, a; cin >> n >> k; vector<long long int> dp; for (int i = 0; i < n; i++) { cin >> a; dp.push_back(a); } for (int i = 1; i < n; i++) { dp[i] = (dp[i...
3
#include <bits/stdc++.h> using namespace std; long long n, m, p[100005], x, y, ans = 1; int par(int x) { if (x == p[x]) return x; return p[x] = par(p[x]); } void uni(int x, int y) { p[par(y)] = par(x); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) p[i] = i; ...
15
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; vector<int> a(n); for (int &x : a) cin >> x; vector<int> smaller_left(n, 0), smaller_right(n, n - 1); priority_queue<pair<int, int> > pq; for (int i = 0; i < n; ++i) { while ...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int t, n; int check(int mid, pair<int, int> *s) { for (int i = 1; i <= n; i++) { mid += s[i - 1].second; if (mid <= s[i].first) return 0; } return 1; } int main() { cin >> t; while (t--) { cin >> n; pair<int, int> s[n + 1]; ...
5
#include <bits/stdc++.h> using namespace std; const int max_n = 1e5 + 100; const int max_d = 1e6 + 100; int a, b; int x[max_n], n; int d[max_d], e[max_d]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) cin >> x[i]; sort(x, x + n); cin >> a >> b; for (int i = 0; i <= a -...
14
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll N = 1e6 + 100; ll n; ll m; ll **arr() { ll **res = new ll *[n + 2]; for (ll i = 0; i < n + 2; ++i) { res[i] = new ll[m + 2]; fill_n(res[i], m + 2, 0); } return res; } ll **inp; ll **ans; void pref(ll **a) { for (ll i = 1; i <...
14
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { for (; b; a %= b, swap(a, b)) ; return a; } int n, m; vector<string> color; vector<string> dir; vector<int> loopSize; vector<vector<pair<int, int> > > loops; vector<vector<int> > loopNo; vector<vector<int> > loopNum; vector<...
14
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; const int maxn = 111; int occ[maxn], en[maxn]; int main() { int b, d; scanf("%d %d", &b, &d); string a, c; cin >> a >> c; for (int e = 0; e < c.size(); e++) { int cur_c = e; int qtd = 0; for (int cu...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, a, b, c, d; cin >> n >> a >> b >> c >> d; if (((n * (a - b)) >= (c - d) || (n * (a + b)) >= (c - d)) && ((n * (a - b)) <= (c + d) || (n * (a + b)) <= (c + d))) { cout << "Yes" << endl; } ...
1
#include <bits/stdc++.h> using namespace std; vector<int> G[405]; vector<int> R[405]; int a[405][405]; int bfs(int n, int src) { int val; queue<int> q; int taken[405] = {0}, distance[405] = {0}; q.push(src); taken[src] = 1; distance[src] = 0; while (!q.empty()) { int u = q.front(); for (int i = 0;...
8
#include <bits/stdc++.h> using namespace std; template <typename T> inline void printV(vector<T>& a) { for (int i = 0; i < ((int)((a).size())); i++) { cout << a[i] << " "; } cout << "\n"; } template <typename T> inline void printV(vector<T>& a, int n) { for (int i = 0; i < n; i++) { cout << a[i] << " ";...
7
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007LL; long long int fastpow(long long int base, long long int exp) { long long int res = 1; while (exp > 0) { if (exp % 2 == 1) res = (res * base) % MOD; base = (base * base) % MOD; exp /= 2; } return res % MOD; } bool isprime...
6
#include <bits/stdc++.h> using namespace std; long long t, n, r, a[100100], d, ans; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> t; while (t--) { cin >> n >> r; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); long long poz = n; ans = 0; d = 0...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 5020; int n, a[MAX]; int main(void) { int T; scanf("%d", &T); while (T--) { scanf("%d", &n); for (register int i = (0); i < (n); ++i) scanf("%d", &a[i]); bool ok = 0; for (register int i = (0); i < (n); ++i) for (register int j = ...
3
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b; cin >> t; vector<string> s(t); for (int i = 0; i < t; i++) { cin >> a >> b; if ((a + b) % 3 != 0 || 2 * min(a, b) < max(a, b)) { s[i] = "NO"; } else { s[i] = "YES"; } } for (int i = 0; i < t; i++) { cout ...
5
#include <bits/stdc++.h> using namespace std; map<int, int> sg; int SG(int x, int k) { int i; if (sg.count(x) == 1) return sg[x]; int vis[500] = {0}; for (i = 1; i * i <= x; i++) if (x % i == 0) { if (i > 1 && x / i >= k) { if (i & 1) vis[SG(x / i, k)] = 1; else vis...
12
#include <bits/stdc++.h> using namespace std; long long n, t, k; vector<int> a(500005); void solve() { cin >> n; int s = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } sort((a).begin(), (a).begin() + n); bool first = true; if (2 * a[n - 1] > s) first = true; else if (s % 2 ...
10
#include <bits/stdc++.h> using namespace std; int solve(int n) {} int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; if (n < 31) cout << "NO" << '\n'; else { cout << "YES" << '\n'; int x = n - 30; int arr[4] = {6, 10, 14, 1...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int head[222222], to[222222], cap[222222], dist[222222], nxt[222222], cur[222222]; int n, m, s, t, cnt, x, y, z, h, ans, l, r, c; void addedge(int s, int t, int cp) { cnt++; nxt[cnt] = head[s]; head[s] = cnt; to[cnt] = t; cap[cnt] = cp; } ...
19
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005LL; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; inline string IntToString(long long a) { char x[100]; sprintf(x, "%lld", a); st...
5
#include <bits/stdc++.h> #pragma GCC optimize("-O3") using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; bool sortbysec(const pair<long long, long long>& a, const pair<long long, long long>& b) { if (a.sec...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } long long int m; cin >> m; long long int q[m][2]; for (int i = 0; i < m; ++i) { cin >> q[i][0] >> q[i][1]; } long long int inv = 0; for (...
10
#include <bits/stdc++.h> using namespace std; const int N = 1000006; int cnt[N], m; int dp[N][5][5]; int f(int i, int a, int b) { if (i == m) return 0; int &ans = dp[i][a][b]; if (~ans) return ans; ans = 0; int mx = 2; mx = min(mx, cnt[i] - a); mx = min(mx, cnt[i + 1] - b); mx = min(mx, cnt[i + 2]); f...
14
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; int a[MAX], pos[MAX]; int visit[MAX]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; pos[a[i]] = i; } int big = 1; for (int i = 0; i < n; i++) { if (visit[i]) continue; v...
8
#include <bits/stdc++.h> const int oo = 2139063143; const int N = 65; const int mod = 1000000007; using namespace std; inline void sc(int &x) { x = 0; static int p; p = 1; static char c; c = getchar(); while (!isdigit(c)) { if (c == '-') p = -1; c = getchar(); } while (isdigit(c)) { x = (x <...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 10 + 100000; const int INF = int(1e9); int n, m; int l[MAXN], r[MAXN], q[MAXN]; void input() { ({ int neg = 0; n = 0; char ch; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') neg = 1; n = ch - 48; fo...
10
#include <bits/stdc++.h> using namespace std; int n; vector<int> a, b, c, d, e; int main() { cin >> n; a.resize(n); b.resize(n); c.resize(n); d.resize(n); e.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; b[0] = 0; c[0] = 0; d[n - 1] = n - 1; e[n - 1] = n - 1; for (int i = 1; i < n; i++) { ...
11
#include <bits/stdc++.h> using namespace std; int fa[100005][20], dep[100005]; vector<int> st; pair<long long, long long> p[100005]; long long cross(pair<long long, long long> o, pair<long long, long long> a, pair<long long, long long> b) { long long ax = a.first - o.first, ay = a.second - o.second; ...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int a[maxn]; int main() { int n, k, l; scanf("%d %d %d", &n, &k, &l); for (int i = 1; i <= n * k; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n * k); int idx = upper_bound(a + 1, a + 1 + n * k, a[1] + l) - a; int num = idx - 1; if (nu...
7
#include <bits/stdc++.h> using namespace std; long long h[3003][3003]; long long hh[3003][3003]; deque<pair<long long, long long> > de; signed main() { long long n, m, a, b; long long g, x, y, z; cin >> n >> m >> a >> b; cin >> g >> x >> y >> z; for (long long i = 1; i <= n; i++) { for (long long j = 1; j...
13
#include <bits/stdc++.h> using namespace std; const int N = 55, mod = 1e9 + 7; void add(int &x, int y) { x += y; x = (x >= mod ? x - mod : x); } int cnt[N << 1][N][N][2][2], f[N << 1][N][2]; int n, q[N << 1], head, tail; bool e[N][N]; vector<int> vec[N][N]; void solve0(int x, int y) { head = 1; tail = 0; for ...
23
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; const int maxn = 1e5 + 5; const long long int inf = 1e18 + 9; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; if (n % 2) { for (int i = 0; i < n; i++) { cout << i << ' ';...
5
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e5 + 10; int ed, g[N], nxt[N << 1], v[N << 1], w[N << 1]; void add(int x, int y, int z) { v[++ed] = y, nxt[ed] = g[x], g[x] = ed, w[ed] = z; } int fa[N], siz[N]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } vo...
20
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int mod = 1e9 + 7; int nex[N]; char a[N]; bool v[N]; inline int re() { int x = 0; char c = getchar(); bool p = 0; for (; c < '0' || c > '9'; c = getchar()) p |= c == '-'; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0...
9
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int maxn = 1 << 20; char buf[maxn]; int d[maxn]; int z[maxn]; int where[maxn]; int finish[maxn]; int can[maxn]; void go(const string& s) { int l = 0, r = -1; int n = s.size(); for (int i = 0; i < n; ++i) { ...
20
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, q, dfn[N], low[N], dfs_clock, sta1[N * 2], top1, scc_num, scc_id[N * 2], edgenum; int fa[N][21], vet[N * 2], head[N], Next[N * 2], dep[N], beg[N * 2], sta2[N * 4], top2, w[N][21]; bool flag[N * 2], vis[N]; bool used[N]; void addedge(...
14
#include <bits/stdc++.h> using namespace std; int a[11]; vector<int> ans; int n, m; int d[1001]; void go(int v, int cur1, int cur2, int last) { if (v > m) { cout << "YES" << endl; for (int i = 1; i <= m; i++) { cout << d[i] << ' '; } exit(0); } for (int i = 1; i <= n; i++) { if (a[i] == ...
9
#include <bits/stdc++.h> using namespace std; int i, j, k, n, l, ans, temp; char c; int pos[2000000], st[2000000]; char expr[2000000]; int gettype(int p, int q) { int x, left, right; if (p == q) { if (expr[p] == '0') return 0; if (expr[p] == '1') return 1; if (expr[p] == '?') return 4; } x = pos[p];...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); int S = 0; for (int i = 0; i < n; i++) { cin >> a[i]; S += a[i]; } sort(a.begin(), a.end()); int best = 0; for (int i = 0; i < n; i++) for (int j = a[i]; j >= 1; j--) if (a[i] % j == 0) { ...
5
#include <bits/stdc++.h> using namespace std; int i, N, M, A[100005], q[100005]; bool cmp(int X, int Y) { return X < Y; } bool cmp1(int X, int Y) { return X > Y; } int main() { scanf("%d", &M); for (i = 0; i < M; ++i) { scanf("%d", &q[i]); } scanf("%d", &N); for (i = 0; i < N; ++i) { scanf("%d", &A[i]...
6
#include <bits/stdc++.h> using namespace std; void setInOut() {} vector<int> adj[1000005]; int temp[1000005], root; bool visited[1000005]; int dfs(int u, int T, vector<int>& cuts) { int tmp = temp[u]; visited[u] = true; for (int i = 0; i < adj[u].size(); ++i) { int v = adj[u][i]; if (!visited[v]) tmp += d...
12
#include <bits/stdc++.h> using namespace std; struct edge { int u, v; long long w; int rev; }; int MOD = 1000000007; vector<int> G[100000]; int parent[20][100000]; int depth[100000]; void dfs(int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (int i = 0; i < G[v].size(); i++) if (G[v][i] != p) d...
14
#include <bits/stdc++.h> using namespace std; const int N = 100000, M = 100000; int oo[1 + M * 2], oj[1 + M * 2]; int link(int o, int j) { static int _ = 1; oo[_] = o, oj[_] = j; return _++; } int ae[N], af[N]; char ff[N], used[N]; void dfs1(int i) { if (used[i]) return; used[i] = 1; for (int o = ae[i]; o; ...
9
#include <bits/stdc++.h> using namespace std; int dat[3220000]; int N; int main() { scanf("%d", &N); for (int(i) = 0; (i) < (N); (i)++) dat[i] = i; int mv = 0; for (int(i) = (2); (i) < (N + 1); (i)++) { int pp = 0; vector<int> tmp; dat[mv + N] = dat[mv + N / i * i]; for (int(_) = 0; (_) < ((N + ...
14
#include <bits/stdc++.h> using namespace std; int main() { long long n, ev, od, k; cin >> n; if (n <= 2) cout << "No" << endl; else { ev = n / 2; od = (n + 1) / 2; if (od % 2 == 0) { cout << "Yes" << endl; cout << ev; for (int i = 2; i <= n; i += 2) cout << " " << i; cout...
3
#include <bits/stdc++.h> using namespace std; inline int ni() { int a; scanf("%d", &a); return a; } inline double nf() { double a; scanf("%lf", &a); return a; } template <class T> void out(T a, T b) { bool first = true; for (T i = a; i != b; i++) { if (!first) printf(" "); first = false; cou...
6
#include <bits/stdc++.h> using namespace std; char c; int a[101001], n, p, l, r; const long long mod = 1e9 + 7; long long num[101010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> p; num[0] = 1; for (int i = 1; i < 100001; i++) num[i] = num[i - 1] * 2 % mod; for (int i = ...
8
#include <bits/stdc++.h> using namespace std; const int maxx = 2000010; const double pi = acos(-1.0); const double eps = 1e-15; long long t, n, m; long long ans = 0, total = 0, sum = 0, cnt = 0, l = 0, r = 0; long long a[maxx], c[maxx]; long long ksm(long long x, long long p) { long long res = 1; while (p) { if...
10
#include <bits/stdc++.h> using namespace std; void set(int& n, int first) { n = n | (1 << first); } void reset(int& n, int first) { n = n & ~(1 << first); } bool check(int n, int first) { return (bool)(n & (1 << first)); } const int mx = 100005; int a[mx], k; bool f[mx]; bool fun(int s, int e, int v1, int v2) { if (v...
14
#include <bits/stdc++.h> struct { int* elem; int len; } SqList; int main() { int n; while (~scanf("%d", &n)) { int ar[n], round[n]; memset(round, 0, n * sizeof(int)); SqList.elem = new int[n]; SqList.len = 0; for (int i = 0; i < n; ++i) scanf("%d", ar + i); for (int i = n - 1; i >= 0; --...
11
#include <bits/stdc++.h> int main() { char str[201]; char def[201]; int def_cnt = 0; size_t i; scanf("%s", str); for (i = 0; i < strlen(str); ++i) { while (str[i] == 'W' && str[i + 1] == 'U' && str[i + 2] == 'B') i += 3; if (i >= strlen(str)) break; do { def[def_cnt] = str[i]; ++def_...
1
#include <bits/stdc++.h> using namespace std; vector<int> razliciti[100005]; int a[100005]; int b[100005]; bool mark[100005]; int n, m; int p, q; int indeks; int pronadji(int x) { for (int i = 1; i <= n; i++) { if (i != x) { if (!mark[i]) return i; } } } int main() { ios_base::sync_with_stdio(false)...
10
#include <bits/stdc++.h> const int MOD = 1e9 + 7; using namespace std; long long n, k, sol; long long power(long long b, long long e) { if (e == 0) return 1; if (e % 2 == 1) return ((b % MOD) * (power(b, e - 1) % MOD)) % MOD; return ((power(b, e / 2) % MOD) * (power(b, e / 2) % MOD)) % MOD; } double p; long long ...
8
#include <bits/stdc++.h> bool comp(const int& a, const int& b) { return a < b ? false : true; } using namespace std; long long int a[200009]; int tim[200009]; vector<long long int> a1; vector<int> a2; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { ...
8
#include <bits/stdc++.h> using namespace std; int k; long long a[256]; int cnt[256]; char ans[120000]; char str[120000]; int p[2][120000]; int plen[2]; int main() { ios_base::sync_with_stdio(false); cin >> str; cin >> k; int n = strlen(str); if (k > (long long)n * (n + 1) / 2) { cout << "No such line." <<...
13
#include <bits/stdc++.h> using namespace std; bool ok; int n, x; string s; bool w[300000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { cin >> s >> x; n = s.size(); ok = true; for (int i = 0; i < n; i++) w[i] = 1; for (int i = 0; i < n; i++) { ...
7
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } const int maxn = 400001; int a[maxn], b[maxn]; int n, m; unordered_map<long long, int> tree; long long ansx = -1, ansd; inline long long calc(long long x, long long k) { long long ret = 1; for (; k; x = (x * x) % m, k >>...
18
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5; bool visited[MAX]; int p[MAX]; vector<int> adj[MAX]; void dfs(int s) { visited[s] = true; for (int i = 0; i < adj[s].size(); ++i) { if (visited[adj[s][i]] == false) dfs(adj[s][i]); } } int main() { int n, m; cin >> n; memset(visited, 0, ...
5
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int MAXN = 1010; int h[MAXN]; bool sign[MAXN]; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } bool ok(int a, int b) { int x = gcd(a, b); if (x == 1) return true; else return false; } int main() { int n; scan...
4
#include <bits/stdc++.h> using namespace std; int main() { int x, y, m; cin >> x >> y; if (x > y) m = x; else m = y; m += 1 - fabs(x - y); cout << m << endl; x = 0; while (m--) { cout << x << " " << y << endl; x++; y--; } return 0; }
7
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 10; int a[N], dp[N][N], ind[N]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { int tmp = i; while...
4
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const long long LINF = INF * (long long)INF; const int MAX = 1000100; int A[MAX]; int B[MAX]; int main() { int n, p; cin >> n >> p; for (int i = (0); i < (n); i++) { cin >> A[i] >> B[i]; } l...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int size = 1; while (size * size < n) size++; int cnt = (n + size - 1) / size; vector<int> minb(cnt), maxb(cnt), bal(cnt); vector<int> l(cnt), r(cnt); for (int i = 0; i < (int)(cnt); i++) { l[i] = i * size; r[i] = min(n,...
14
#include <bits/stdc++.h> using namespace std; int scale(char c) { if (c <= '9' && c >= '0') return c - '0'; if (c <= 'Z' && c >= 'A') return c - 'A' + 1; return c - 'a' + 1; } const int inf = 1e8 + 5; int main() { int n; cin >> n; vector<int> v(2 * n); for (int i = 0; i < 2 * n; ++i) cin >> v[i]; sort(v...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int a[maxn]; int g[maxn]; int d[maxn]; int n; struct SegTree { int maxv[maxn * 3]; int ql, qr; int query(int o, int L, int R) { if (ql > qr) return 0; int M = L + (R - L) / 2, ans = 0; if (ql <= L && R <= qr) return maxv[o]; if...
7
#include <bits/stdc++.h> using namespace std; int binc(long long n) { int ans = 0; while (n) { ans += n & 1; n >>= 1; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, p; cin >> n >> p; int i, k = -1; for (i = 0; i < 32; i++) { i...
8
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); ; string x, y, s; cin >> x >> y; int a = 0, b = 0; bool is = 0; for (int i = 0; i < x....
3
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long c = 0; for (long long i = 0; i < n; i++) if (a[i] == 1) c++; long long m = INT32_MIN, mhere = INT32_MIN; for (long long i = 0; i < n; i++) { ...
4
#include <bits/stdc++.h> int main() { int i, t1 = 0, t2 = 0; char s[101]; scanf("%s", s); for (i = 0; i < strlen(s); i++) { if (s[i] == '0') { t2 = 0; t1++; if (t1 == 7) { printf("YES"); break; } } else { t1 = 0; t2++; if (t2 == 7) { prin...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1000030; int cnt[maxn + 2]; int main() { int n, in; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &in); cnt[in]++; } int ans = 0; for (int i = 0; i < maxn; i++) { if (cnt[i] & 1) ans++; cnt[i + 1] += cnt[i] / 2; } ...
7
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& o, const vector<T>& v); const int N = 340; bool color[N]; vector<int> adj[N]; int n; int cap; int parent[N]; int has[N]; int desired[N]; int deg[N]; bool solved[N]; long long dfs(int v) { if (!color[v]) return 0; color[...
17
// Problem: C. Nastia and a Hidden Permutation // Contest: Codeforces - Codeforces Round #720 (Div. 2) // URL: https://codeforces.com/contest/1521/problem/C // Memory Limit: 256 MB // Time Limit: 3000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; #define int long ...
12
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; int vis[101]; int main() { int n, w; cin >> n >> w; vector<pair<int, int> > v(n); vector<int> ans(n); for (int i = 0; i < n; i++) { cin >> v[i].first; v[i].second = i; ans[i] = (v[i].first + 1) / 2; w -= ans[i]; } if ...
6
#include <bits/stdc++.h> using namespace std; int main(void) { long long a, b; long long sx, sy; long long gx, gy; cin >> a >> b >> sx >> sy >> gx >> gy; long long sr = (sx + sy) / 2 / a; if (sx + sy < 0) sr--; long long sl = (sx - sy) / 2 / b; if (sx - sy < 0) sl--; long long gr = (gx + gy) / 2 / a; ...
10
#include <bits/stdc++.h> using namespace std; const int N = 5010; const int MOD = int(1e9) + 7; int n, m; int s[N]; vector<int> spos[N]; int f[N], h[N]; int l[N], r[N]; int cows_at[N]; int inv[N]; int ans[N]; int cows_got[N]; int ways_got[N]; void update(int l, int r, int c_got, int w_got, int inv_w_got) { if (l > r)...
17