solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int a[600][600]; int main(void) { int num = 1; int x = 1, y = 1, z = 1; a[1][1] = 1; while (num <= 250000) { a[x][++y] = ++num; for (int j = 0; j < z; j++) a[++x][y] = ++num; for (int j = 0; j < z; j++) a[x][--y] = ++num; ++z; a[++x][y] = ++num; ...
16
#include <bits/stdc++.h> using namespace std; long long a[1000000], k, temp, last, sum, temper, i, j, n; int main() { std::ios_base::sync_with_stdio(false); cin >> n >> k; for (i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } temper = a[1]; sort(a + 1, a + n + 1); last = a[1]; temp = k; for (...
12
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC optimize("unroll-loops") using namespace std; const int MAX = 2e5 + 5; const long long MAX2 = 11; const long long MOD = 1100000007; const long long MOD2 = 1000005329; const long long INF = 2e18; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; const int dc...
17
#include <bits/stdc++.h> constexpr int MAX = 1 << 22; std::vector<int> find_compatible(const std::vector<int>& vector) { std::vector<int> masks(MAX, -1); for (auto x : vector) { masks[x] = x; } for (int i = 0; i < masks.size(); ++i) { if (masks[i] == -1) { continue; } for (int j = 1; (i | ...
14
#include <bits/stdc++.h> using namespace std; int main() { int s, v1, t1, v2, t2; cin >> s >> v1 >> v2 >> t1 >> t2; int s1 = s * v1 + 2 * t1; int s2 = s * v2 + 2 * t2; if (s1 == s2) cout << "Friendship"; else if (s1 > s2) cout << "Second" << endl; else cout << "First" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int main() { int n, m, x; long long sum = 0; while (~scanf("%d %d", &n, &m)) { while (n--) { scanf("%d", &x); sum += x; if (n == 0) printf("%lld", sum / m); else printf("%lld ", sum / m); su...
1
#include <bits/stdc++.h> const int TETA = 26; std::vector<int> fix(std::vector<int> f) { std::vector<int> odd; for (int i = 0; i < TETA; i++) { if (f[i] % 2 == 1) { odd.push_back(i); } } for (int left = 0, right = odd.size() - 1; left <= right; left++, right--) { f[odd[left]] += 1; f[odd[r...
10
#include <bits/stdc++.h> using namespace std; vector<int> ans; map<int, int> check; int main() { int n; cin >> n; int pr = 1; for (int i = 1; i <= 31; i++) { check[pr] = i - 1; pr *= 2; } int q = 0; bool f = true; while (true) { if (((n + 1) & n) == 0) { cout << q << endl; for (a...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<pair<long long, long long>> a(n); for (long long i = 0; i < n; i++) cin >> a[i].first >> a[i].second; sort(a.begin(), a.end()); vector<pair<pair<long long, long long>, long long>> b; pair<long long, long long> cur = a...
6
#include <bits/stdc++.h> using namespace std; template <typename P, typename Q> ostream& operator<<(ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; } char g[2][13]; void show(void) { for (int i = 0; i < 2; ++i) { for (int j = 0; j < 13; ++j) { cout << g[i][j]; ...
8
#include <bits/stdc++.h> using namespace std; char a[1000005]; vector<int> D; int parse(char *s, char *e) { int val = 0; while (s != e) val = val * 10 + (*(s++)) - '0'; return val; } void parse() { int year = parse(a, a + 4); int month = parse(a + 5, a + 7); int day = parse(a + 8, a + 10); int hour = pars...
12
#include <bits/stdc++.h> using namespace std; const int N = 100050; long long t[N], a[N], sol[N]; multiset<long long> snow; int main() { int n, i; scanf("%i", &n); for (i = 1; i <= n; i++) scanf("%lld", &a[i]); for (i = 1; i <= n; i++) scanf("%lld", &t[i]), t[i] += t[i - 1]; long long sum = 0; for (i = 1; i...
8
#include <bits/stdc++.h> using namespace std; struct node { double x, r; int f, id; } a[100005]; bool cmp1(node a, node b) { return a.x < b.x; } bool cmp2(node a, node b) { return a.id < b.id; } int isin(int i, double x, double y) { double t = (x - a[i].x) * (x - a[i].x) + y * y; if (t <= a[i].r * a[i].r) retur...
9
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } long long int power(long long int x, long long int y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 9; const long long int MOD = 1e9 + 696969; mt19937_64 rng(time(0)); int random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } const long long INF = 1e18; const int maxn = 500100; namespace atcoder { namespace internal { int ceil_pow...
20
#include <bits/stdc++.h> using namespace std; int main() { long long j, t, k, l, sum, r, y, z, h, x, mini, maxi, kmax, d, i, g, n, m, q, v, kol, raz, viv, braz; cin >> x; cin >> y; l = 0; r = 1000000; while (l != r - 1) { z = (l + r) / 2; sum = z * (z + 1) / 2; if (sum > (x + y)) { r...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1]; for (int i = 0; i < n; ++i) cin >> a[i]; int dp[n][n]; for (int i = 0; i < n; ++i) dp[i][i] = 1; for (int i = 0; i < n - 1; ++i) { if (a[i] == a[i + 1]) dp[i][i + 1] = 1; else dp[i][i + 1] = 2; ...
11
#include <bits/stdc++.h> using namespace std; map<pair<long long, int>, pair<long long, int> > mp; pair<long long, int> dfs(long long n, int mx) { if (n == 0) return make_pair(0, 0); if (n < 10) { pair<long long, int> ret = make_pair(1, 0); if (mx > n) ret.second = mx - n; return ret; } pair<long lo...
3
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const double eps = 0.00000000001; int t, n, s[605]; double l, r, m; struct N { double x, y; N(double a = 0, double b = 0) { x = a, y = b; } } A[305]; struct L { N a, b; double f; } a[605], b[305], c[605]; N operator+(N a, N b) { return N(...
25
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 9; const int M = 1e3 + 9; const int INFINT = 1e9 + 9; const long long INFLL = 1e18 + 9; const long double EPS = 1e-16; int deg[N]; int main() { ios::sync_with_stdio(0); int n, v, u, ans = 0; cin >> n; for (int i = 0; i < (n - 1); i++) { cin >...
2
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5, M = 104206969, OO = 0x3f3f3f3f; const double Pii = 3.14159265359; long long t, n, m; long long a[N], b[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { cin >> n >> m; set<pair<int, int>> st; ...
6
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30); const long long INFLL = (1ll << 60); const long long MOD = (long long)(1e9 + 7); void mul_mod(long long& a, long long b) { a *= b; a %= MOD; } void add_mod(long long& a, long long b) { a = (a < MOD) ? a : (a - MOD); b = (b < MOD) ? b : (b ...
17
#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") #pragma GCC optimize("unroll-loops") using namespace std; string tostr(int n) { stringstream rr; rr << n; return rr.str(); } const int mo...
16
#include <bits/stdc++.h> using namespace std; using namespace std; template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, '...
6
#include <bits/stdc++.h> using namespace std; int getCost(vector<vector<int>> &a) { int n = a.size(), m = a[0].size(); int ans = 0; for (int i = 0; i < m; ++i) { ans += 1LL * (a[n / 2 - 1][i] - a[n / 2][i]) * (a[n / 2 - 1][i] - a[n / 2][i]); } return ans; } void change(vector<vector<int>> &a) { ...
10
#include <bits/stdc++.h> using namespace std; const int N = 4e6 + 1, M = 3e5 + 1; int Tree[N][2], A[M], B[M], n, cnt, s, H[N][2]; void Add(int x) { int cur = 0; for (int i = 30; i >= 0; i--) { if (1 << i & x) s = 1; else s = 0; H[cur][s]++; if (!Tree[cur][s]) Tree[cur][s] = ++cnt; cu...
10
#include <bits/stdc++.h> using namespace std; auto main() -> int { ios_base ::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int m; cin >> m; int ans = min(n, m); (ans % 2 == 1) ? cout << "Akshat\n" : cout << "Malvika\n"; return 0; }
1
#include <bits/stdc++.h> using namespace std; int abs(int x) { if (x < 0) return -x; return x; } int a[100010]; int main() { ios_base::sync_with_stdio(false); int n, k, x; cin >> n; memset(a, -1, sizeof(a)); bool flag = 1; while (n--) { cin >> x >> k; if (x <= a[k]) { continue; } else ...
6
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, int> > a[200020]; int d[200020]; map<pair<int, int>, int> mp; int k, x, y, z; set<pair<int, int> > q; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { scanf("%d%d%d", &x, &y, &z); a[x].push_back(make_pair(y, z)); a[y].pus...
9
#include <bits/stdc++.h> using namespace std; int root(vector<int> &Arr, int i) { while (Arr[i] != i) { Arr[i] = Arr[Arr[i]]; i = Arr[i]; } return i; } void weighted_union(vector<int> &Arr, vector<int> &size, int A, int B) { int root_A = root(Arr, A); int root_B = root(Arr, B); if (size[root_A] < si...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n, level; cin >> n; long long cur = 2; for (level = 1; level < n + 1; level++) { long long y = level * (level + 1) * (level + 1) - (cur / level); cout << y << "\n"; cur = level * (level + 1); }...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char a[N]; int main() { int n; ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); while (cin >> n) { cin >> a; sort(a, a + n); puts(a); } return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int ls[n], rs[n]; int mn = 1000000; for (int i = 0; i < n; i++) { ls[i] = min(mn, a[i]); mn = ls[i]; ...
1
#include <bits/stdc++.h> long long mpow(long long a, long long n, long long mod) { long long ret = 1; long long b = a; while (n) { if (n & 1) ret = (ret * b) % mod; b = (b * b) % mod; n >>= 1; } return (long long)ret; } using namespace std; double dp[205][205][410]; int prob[205], a[205], off = 20...
10
#include <bits/stdc++.h> long long mod = 1e9 + 7; using namespace std; char str[1005][1005]; int black[1005]; int white[1005]; int dp[1005][2]; int main() { int n, m, x, y; cin >> n >> m >> x >> y; int i, j; for (i = 0; i < n; i++) scanf("%s", str[i]); for (i = 0; i < 1006; i++) { black[i] = 0; white[...
9
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos((long double)-1.0); const double EPS = 1e-10; const int MOD = 1e9 + 7; template <typename T> void cmin(T &x, T y) { if (y < x) x = y; } template <typename T> void cmax(T &x, T ...
13
#include <bits/stdc++.h> using namespace std; long long int min(long long int a, long long int b) { if (a < b) return a; return b; } long long int max(long long int a, long long int b) { if (a > b) return a; return b; } int main() { int n, m; cin >> n; if (n % 2 == 0) m = (n + 2) / 2; else m = (...
3
#include <bits/stdc++.h> using namespace std; char str[10]; vector<int> V; class op { public: int type; int value; void input() { scanf("%s", str); if (strcmp(str, "add") == 0) { type = 0; } else if (strcmp(str, "del") == 0) { type = 1; } else { type = 2; return; } ...
15
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const int N = 1000 + 10; const int M = 5000 + 10; const double pi = 3.1415926535; int main(void) { int n; scanf("%d", &n); priority_queue<int, vector<int>, greater<int> > q; for (int i = 1; i <= n; i++) { int t; scanf("%d", &t); ...
3
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, node[N], parent[N], sum[N]; struct Edge { int u, v, w; Edge(int u = 0, int v = 0, int w = 0) { this->u = u; this->v = v; this->w = w; } } e[N]; bool cmp(Edge a, Edge b) { return a.w > b.w; } int find(int x) { if (x == pare...
11
#include <bits/stdc++.h> using namespace std; struct dat { long long scm, scl, tm, tl; long double pro; bool operator<(dat a) const { return tl * 1e6 * (1 - pro) * a.pro < a.tl * 1e6 * (1 - a.pro) * pro; } } plm[1005]; pair<long double, long double> dp[1005][1561]; int main() { int n, t; cin >> n >> t; ...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, changes; cin >> n; char input[n + 1]; scanf("%s", input); if (n > ('z' - 'a' + 1)) { cout << "-1" << endl; return 0; } changes = 0; for (int i = 0; i < n; i++) { if (input[i] == '*') continue; for (int j = i + 1; j < n; j+...
2
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1000005; const long long SQRTN = 1003; const long long LOGN = 22; const double PI = acos(-1); const long long INF = 1e16; const long long MOD = 1000000007; const long long FMOD = 998244353; const double eps = 1e-9; bool primes[100001]; long long spf[1...
7
#include <bits/stdc++.h> using namespace std; long long n; int dx[6] = {-1, -2, -1, 1, 2, 1}, dy[6] = {2, 0, -2, -2, 0, 2}; int main() { cin >> n; if (n == 0) { cout << "0 0\n"; return 0; } long long l = 0, r = 1000000000; while (l < r) { long long mid = (l + r + 1) >> 1; long long pp = mid * ...
13
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, K = 300; struct query { int l, r, ind; }; bool cmp(query a, query b) { if (a.l / K != b.l / K) return (a.l / K < b.l / K); else return (a.r < b.r); } int poj[N], sol[N], arr[N]; query qs[N]; int prijelaz(pair<int, int> a, pair<int, int>...
10
#include <bits/stdc++.h> using namespace std; void read(int &x) { char ch = getchar(); x = 0; while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); } const int N = 5e5 + 5; int n, res, a[N], lg[N], ma[N], na[N], b[N]; struct st { int c[20][N]; void work(int *a) { ...
25
#include <bits/stdc++.h> #define ll long long #define endl '\n' #define PI acos(-1) #define sz 10020 #define mod 10000007 #define RUN_FAST ios::sync_with_stdio(false); using namespace std; //int row[]={0, 0, -1, 1};///4 adjacent(Up, down, left, right) //int col[]={1, -1, 0, 0}; //int row[]={-2, -2, 2, 2, -1, -1, 1, 1...
0
#include <bits/stdc++.h> using namespace std; const int M = 100000 + 10; int d[M]; long long int pred[M]; long long int a[M]; long long int dp[110][M]; long long int pres[M]; long long int dq[M]; long long int yk(int i, int k) { long long int val = dp[i][k] + pres[k]; return val; } int main() { int n, m, p; cin...
16
#include <bits/stdc++.h> using namespace std; int main() { long long q; cin >> q; while (q--) { long long n, k; cin >> n >> k; string s; cin >> s; long long lz = -1, ocnt = 0; for (long long i = 0; i < s.size(); i++) { if (k == 0) break; if (s[i] == '1') ocnt++; if (s[i] ...
7
#include <bits/stdc++.h> using namespace std; int n, m, last; int nxt[300300 * 6][27], link[300300 * 6], dp[300300 * 6], cnt[300300 * 6], ord[300300 * 6], occur[3][300300 * 6]; char s[300300 * 6]; void extend(int c) { if (nxt[last][c] && dp[nxt[last][c]] == dp[last] + 1) { last = nxt[last][c]; return; }...
16
#include <bits/stdc++.h> using namespace std; struct node { node() { t.resize(3); } node(int a, int b, int c) { t.resize(3); t[0] = a; t[1] = b; t[2] = c; } vector<int> t; }; void actualiser(node &n) { sort(n.t.begin(), n.t.end()); } int main() { ios_base::sync_with_stdio(false); int n; ci...
13
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int s1 = max((3 * a / 10), (a - (a / 250) * c)); int s2 = max((3 * b / 10), (b - (b / 250) * d)); if (s1 > s2) cout << "Misha"; else if (s1 < s2) cout << "Vasya"; else cout << "Tie"; return 0;...
1
#include <bits/stdc++.h> using namespace std; struct pp { int x; int y; }; int a[100][100], n; vector<pp> v[5]; string s[51]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> s[i]; s[i] = '0' + s[i]; } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { pp p; p.x ...
10
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } void inout() {} int main() { fast(); inout(); int n, x, y; cin >> n >> x >> y; vector<int> v(n); int a = 0; for (long long int i = 0; i < n; i++) { cin >> v[i]; if (v[i] <= x) a++; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 10000005; bitset<N> isPrime; vector<int> primes; void sieve() { primes.push_back(0); isPrime.set(); isPrime[0] = isPrime[1] = 0; for (int i = 2; i < N; ++i) { if (isPrime[i]) { primes.push_back(i); for (long long int j = 1LL * i * i; j ...
4
#include <bits/stdc++.h> char a[4020][2010]; long b[2010]; int main() { int i, j, t, n, m; long k; while (scanf("%d%d%ld", &n, &m, &k) != EOF) { memset(b, 0, sizeof(b)); for (i = 0; i < n; i++) scanf("%s", a[i]); for (t = 0; t < n; t++) { for (j = 0; j < m; j++) { if (a[t + t][j] == 'U' ...
6
#include <bits/stdc++.h> using namespace std; struct S { long long sta; long long end; }; bool cmp(S a, S b) { if (a.end == b.end) { return a.sta < b.sta; } else { return a.end < b.end; } } int main() { struct S s[500100] = {}; long long n, i, j, cnt = 0; while (~scanf("%lld", &n)) { memset(...
8
#include<bits/stdc++.h> #include <limits> using namespace std; #define ll long long #define ld long double #define pb push_back #define ff first #define ss second #define mp make_pair #define ins insert #define sb substr #define con continue #define ub upper_bound #define lb lower_bound #define pll pair<ll,ll> #defin...
8
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 200000; int n; int a[MAXN]; int cnt[MAXN], freq[MAXN + 1], mxcnt; int solve() { int ret...
18
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> v, e, o, q; ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); long long t, a, b; cin >> t; while (t--) { long long a, b, c, n; cin >> a >> b >> c >> n; long long d = max(a, max(b, c)); d = d - a...
0
#include <bits/stdc++.h> using namespace std; const int N = 40; long long R() { long long ans = 0, f = 1; char c = getchar(); for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1; for (; c >= '0' && c <= '9'; c = getchar()) ans = ans * 10 + c - '0'; return ans * f; } long long dp[N][N], s[N], an...
9
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {1, -1, 0, 0, 1, -1, -1, 1}; template <class T> void cmin(T &a, T b) { if (b < a) a = b; } template <class T> void cmax(T &a, T b) { if (b > a) a = b; } template <class T> int len(const T &c) { return (int)c.size(); } tem...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 20; int n, m, ans; char c[MAXN][MAXN]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> c[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { bool k = false; for (int a = -...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; vector<int> G[100000 + 1]; deque<int> LAST; deque<int> newLAST; int cnt = 0; int main() { int N, K, zero = 0, lastzero = -1; cin >> N >> K; vector<std::pair<int, int> > D(N); for (long long i = 0; i < (int)N; i++) cin >...
10
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; } inline void YES() { cout << "YES\n"; } inline void NO() { cout << "NO\n"; } const long long mod = 1e9 + 7; const long long maxn = 300; long long rand_int(long long l, long long r) { sta...
15
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; vector<string> y; int n; int main() { cin >> n; y.resize(n); for (int i = 0; i < (int)(n); i++) cin >> y[i]; string tmp, tm; for (int i = 0; i < (int)(n); i++) { tm = "2012"; for (int j = 0; j < (int)(4); j++) ...
9
#include <bits/stdc++.h> #pragma GCC optimize(1) #pragma GCC optimize(2) #pragma GCC optimize(3, "Ofast", "inline") using namespace std; const int maxn = 2e6 + 7; const int INF = 1e9; const long long INFF = 1e18; int main() { int num0, num1, num2, num3; bool mark = true; scanf("%d%d%d%d", &num0, &num1, &num2, &nu...
11
#include <bits/stdc++.h> using namespace std; int solve() {} int main() { int n; cin >> n; std::vector<int> v(n); int x; for (int i = 0; i < n; i++) { cin >> x; x--; v[x] = i; } long long s = 0; for (int i = 1; i < n; i++) { s += fabs(v[i] - v[i - 1]); } cout << s; return 0; }
4
#include <bits/stdc++.h> using namespace std; struct point { int x, y, sx, sy; void zip_cords(int a, int b) { if (y - x < 0) sy = (y - x) / (2 * b) - 1; else sy = (y - x) / (2 * b); if (y + x < 0) sx = (y + x) / (2 * a) - 1; else sx = (y + x) / (2 * a); } void init(int a,...
10
#include <bits/stdc++.h> using namespace std; const int maxm = 1e5 + 10; int x[3000], y[3000]; int sumx[100], sumy[100]; int vis[300][3000]; int main() { int a1, a2, b1, b2, c1, c2; scanf("%d%d%d%d%d%d", &a1, &a2, &b1, &b2, &c1, &c2); printf("3\n"); printf("%d %d\n", b1 + c1 - a1, b2 + c2 - a2); printf("%d %d...
4
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long nax = 2e5 + 5; const long long inf = 1e18; using pii = pair<long long, long long>; bool check(string s1, string s2) { if (s1 == s2) { return true; } if (s1.length() == 1) return false; if (s1.length() % 2 || s2.length...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, *a, d = 1; cin >> n; a = new int[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { if (a[i] >= d) d++; } cout << d - 1; }
2
#include <bits/stdc++.h> using namespace std; long long bigmod(long long a, long long b) { if (b == 0) { return 1; } if (b % 2 == 0) { long long r = bigmod(a, b / 2); r = r * r; r = r % 1000000009; return r; } else { long long r = bigmod(a, b - 1); r = r * a; r = r % 1000000009; ...
8
#include <bits/stdc++.h> using namespace std; FILE *in, *out; int N, M, K; int ar[5100]; int arx[5100]; int p[5100]; int b[5100]; int q(int x, int y) { int i; cout << "? " << x << " " << y << "\n"; cout.flush(); cin >> i; return i; } int used1[5100]; int used2[5100]; int ANS[5100]; int check() { int i, j, k...
12
#include <bits/stdc++.h> using namespace std; int c[100006]; int main() { int m, n, i, j; while (~scanf("%d", &m)) { int b = 100000000; for (i = 0; i < m; i++) { int a; scanf("%d", &a); b = min(a, b); } scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &c[i]); sort(c, c ...
6
#include <bits/stdc++.h> using namespace std; int ans, n; int main() { cin >> n; int t = 0; for (int i = 1; n > 0; i++) { t += i; n -= t; ans++; if (n < 0) { ans--; } } cout << ans; }
0
#include <bits/stdc++.h> using namespace std; map<int, int> h, g; map<int, int>::reverse_iterator rit, rit2; int main() { int n, m, k; cin >> n >> m >> k; for (int(i) = 0; (i) < (int)(n); ++(i)) { int x; cin >> x; h[x]++; } for (int(i) = 0; (i) < (int)(m); ++(i)) { int x; cin >> x; g[x...
8
#include <bits/stdc++.h> using namespace std; char A[2020], B[2020]; int la, lb; int main() { while (scanf("%s%s", A, B) > 0) { la = strlen(A); lb = strlen(B); int m = lb; for (int b = -lb; b < la; ++b) { int c = 0; for (int i = 0, k = b; i < lb; ++i, ++k) c += (k < 0 || k >= la ||...
9
#include <bits/stdc++.h> using namespace std; using namespace chrono; template <class T, class V> void _print(pair<T, V> p); template <class T> void _print(vector<T> v); template <class T> void _print(set<T> v); template <class T, class V> void _print(map<T, V> v); template <class T> void _print(multiset<T> v); templat...
8
#include <bits/stdc++.h> using namespace std; const int MAX = 1200; long long row[MAX], col[MAX]; long long sol1[MAX][MAX]; long long soltt[MAX]; long long sol2[MAX]; long long n, m; char mm[MAX][MAX]; int main() { scanf("%lld %lld", &n, &m); long long cnt = 0; for (int i = 0; i < n; i++) scanf("%s", mm[i]); fo...
17
#include <bits/stdc++.h> using namespace std; int main() { int n, pos, l, r; cin >> n >> pos >> l >> r; int res = 0; if (l == 1 and r == n) { return cout << res, 0; } if (l == 1) { if (pos <= r) { res += (r - pos + 1); } else { res += (pos - r + 1); } return cout << res, 0; ...
5
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7, INF = 0x3f3f3f3f; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long qpow(long long a, long long n) { long long r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } long lo...
6
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, k = 1; cin >> n; unordered_map<string, long long> map; map["polycarp"] = 0; vector<long long> v; v.push_back(1); for (long long i = 0; i < n; i++) { string name1, s, name2; cin ...
4
#include <bits/stdc++.h> int main() { int i, j, k, l, flag, count, flagp, i1, c; char s[10000]; while (scanf("%d", &k) == 1) { scanf("%s", s); flag = 0; int flagc[30] = {0}; l = strlen(s); if (l < k) { printf("IMPOSSIBLE\n"); continue; } for (i = 0, j = l - 1; i <= j; i++, ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { if (i % 4 == 1) { cout << '.'; } else { cout << '#'; } for (int j = 1; j < m - 1; j++) { if (i % 2) {...
0
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, q, pa[N], F[N], mx[N], res[N]; vector<int> adj[N]; void dfs(int u) { int num = -1, tmp = -1; F[u] = 1; for (int i = 0; i < (int)adj[u].size(); ++i) { int v = adj[u][i]; dfs(v); F[u] += F[v]; if (F[v] > num) { num = F[...
11
#include <bits/stdc++.h> #pragma GCC optimize "03" using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; vector<pair<int, pair<int, int> > > ed; int par[N], we[N]; vector<pair<int, int> > g[N]; int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void ...
11
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 1; int a[MAX_N]; int f[MAX_N]; int l[MAX_N]; int n, m; set<int> num; int main() { cin >> n >> m; for (int x = 1; x <= n; x++) cin >> a[x]; for (int x = 1; x <= m; x++) cin >> l[x]; f[n] = 1; num.insert(a[n]); for (int x = n - 1; x >= 1; x...
3
#include <bits/stdc++.h> using namespace std; vector<int> vc; int main() { int n; int num = 1; cin >> n; if (n == 1) { printf("1 0\n"); return 0; } for (int i = 2; i <= n; i++) { int cnt = 0; while (n % i == 0) { cnt++; if (cnt == 1) num *= i; n /= i; } if (cnt) vc....
7
#include <bits/stdc++.h> using namespace std; namespace Tzh { const long long maxn = 2000010, p = 1e9 + 7; long long inv[maxn], fac[maxn], n, sum, ans, cnt, f[maxn], g[maxn]; long long c(long long n, long long m) { return fac[n] * inv[m] % p * inv[n - m] % p; } long long qpow(long long a, long long b) { long long s...
12
#include <bits/stdc++.h> using namespace std; const int iinf = 1 << 29; const long long inf = 1ll << 60; const long long mod = 1e9 + 7; void GG() { cout << "-1\n"; exit(0); } long long mpow(long long a, long long n, long long mo = mod) { long long re = 1; while (n > 0) { if (n & 1) re = re * a % mo; a =...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 10; int n, a[N]; inline void read() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; } inline void solve() { int ans = 0; int sum = 0; sort(a, a + n); for (int i = 0; i < n; ++i) sum += a[i]; if (sum >= 4.5 * n) cout << 0; else { ...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1000000000") using namespace std; const int maxn = (int)2e5 + 10; struct segm { long long l, r; int num; }; segm v[maxn]; bool operator<(segm a, segm b) { if (a.l != b.l) { return a.l < b.l; } return a.r < b.r; } int ans[maxn]; int main() { long l...
12
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return a / gcd(a, b) * b; } int main() { int a, b, c, d; cin >> a >> b >> c >> d; int l = lcm(a, c); int a1 = l, b1 = b * (a1 / a), c1 = l, d1 = d * (c1 / c); if (b1 > d1) { i...
6
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define ub upper_bound #define lb lower_bound #define sz(s) (int)s.size() #define pii pair<int,int> #define piii pair< int,pair<int,int> > #define ff first #define ss second #define all(a) a.begin(),a.end() #define rall(v) v.rbe...
6
#include <bits/stdc++.h> using namespace std; long long dp[2005][2005]; long long cal(int n, int m) { if (n == 1) return m; if (n == 0) return 1; if (n == m) return 1; if (dp[n][m]) return dp[n][m]; dp[n][m] = (cal(n - 1, m - 1) + cal(n, m - 1)) % 998244353; return dp[n][m]; } long long fpow(long long a, lo...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; const double pi = 3.1415926535897; void SuperFast() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); } void INOUT() {} void AcCePtEd() { int b, g, n; cin >> b >> g >> n; cout << min(b, n) + min(g, n) - n + 1 << "\n"; } int...
3
#include <bits/stdc++.h> int main() { int n, m, c = 0, h = 0, i = 0; scanf(" %d %d", &n, &m); while (c == 0 && h == 0) { int sum = 220; if (i % 2 == 0) { while (sum >= 100 && n > 0) { sum -= 100; n--; } while (sum >= 10 && m > 0) { sum -= 10; m--; } ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, min1, min2, min3, max1, max2, max3; cin >> n >> min1 >> max1 >> min2 >> max2 >> min3 >> max3; int a, b, c; a = max(n - min2 - min3 < max1 ? n - min2 - min3 : max1, min1); b = max(n - min3 - a < max2 ? n - min3 - a : max2, min2); c = min(n - a...
3
#include <bits/stdc++.h> using namespace std; long long gcd(long long n1, long long n2) { if (n1 % n2 == 0) return n2; return gcd(n2, n1 % n2); } long long powmod(long long base, long long exponent) { long long ans = 1; while (exponent) { if (exponent & 1) ans = (ans * base) % 1000000007; base = (base *...
10