solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int n, long long int m); long long int power(long long int a, long long int n, long long int m) { if (n == 0) return 1; long long int x = power(a, n / 2, m); if (n % 2 != 0) return (((a * x) % m) * (x) % m) % m; els...
10
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; string a; cin >> a; long long int i = 0, j = 0, index = 0; for (j = 1; j < n; j++) { i = 0; long long int k = j; int flag = 0; while (k < n) { if (a[i] != a[k]) { flag = 1; bre...
5
#include <bits/stdc++.h> using namespace std; int N; string names[101]; int taxi[101]; int pizza[101]; int girl[101]; bool isTaxi(string& pn) { bool t = true; for (int i = 1; i < 8 && t; i++) { if (i == 2 || i == 5) continue; if (pn[i] != pn[0]) t = false; } return t; } bool isPizza(string& pn) { bool...
4
#include <bits/stdc++.h> using namespace std; int n, d, X, A[110000], B[110000], q[110000], to[110000]; int pu; int getNextX() { X = (X * 37LL + 10007) % 1000000007; return X; } int main() { scanf("%d%d%d", &n, &d, &X); for (int i = 0; i < n; i = i + 1) A[i] = i + 1; for (int i = 0; i < n; i = i + 1) swap(A[i...
15
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { bool flag = true; int n; scanf("%d", &n); vector<int> a(n), inc, dec; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a.begin(), a.end()); inc.push_back(a[0]); for (int i = 1; i < n; i++) { if (a[i] != a[i...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 2e4 + 24; long long a[N], dp[N][55], sm[N]; int main() { memset(dp, -0x3f, sizeof(dp)); dp[0][0] = 0; int n, k, p; scanf("%d%d%d", &n, &k, &p); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); sm[i] = sm[i - 1] +...
12
#include <bits/stdc++.h> using namespace std; int T, n, l, r; vector<pair<pair<int, int>, int>> seg; vector<int> ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> T; int mn; bool found; while (T--) { cin >> n; seg.clear(); for (int i = (0); i < (n); ++i) { cin >> l >> r; ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 20; long long n, k; long long dp[maxn], ans; bool vis[maxn]; vector<int> gr[maxn]; void dfs(int u) { vis[u] = true; for (int i : gr[u]) { if (!vis[i]) { dfs(i); dp[u] += dp[i]; } } ans += min(dp[u], 2 * k - dp[u]); } int ma...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 20; vector<int> pos['z' - 'a' + 5]; int vis[N]; vector<int> ero[2]['z' - 'a' + 5]; char str[N]; int main() { int k; scanf("%s%d", str, &k); int sz = strlen(str); if (k > (1ll * sz * (sz + 1)) / 2) return printf("No such line.\n"), 0; for (int i...
13
#include <bits/stdc++.h> using namespace std; int n, k, l[5010], r[5010], s[3000010], p[3000010]; char c[3000010], ans[3000010]; void updata(int x) { for (; x <= k; x += x & -x) s[x]--; } int ask(int x) { int tmp = 0; for (int i = (1 << 30); i; i >>= 1) if (tmp + i <= k && s[tmp + i] < x) tmp += i, x -= s[tmp...
20
#include <bits/stdc++.h> using namespace std; void read(int& x) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == '-') fu = 1, c = getchar(); for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0'; if (fu) x = -x; }; char getc() { char c; for (c = getchar(); c <= 32; c =...
11
#include <bits/stdc++.h> using namespace std; void always() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { always(); long long n; cin >> n; long long a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n; i++) { while (a[i] % 2 == 0) { a[...
5
#include <bits/stdc++.h> using namespace std; int main() { string s, s2; cin >> s >> s2; string ans = ""; ans += s[0]; int f = 0; for (int i = 1; i < s.length(); i++) { if (s[i] < s2[0]) ans += s[i]; else { ans += s2[0]; f = 1; break; } } if (f == 1) { cout << ans...
2
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 10, mod = 1e9 + 7, b = 313, b1 = 101; long long pb[maxn], a[maxn], pb1[maxn]; bool NP[maxn]; vector<long long> P; map<pair<long long, long long>, long long> cnt; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); for (long long i = ...
10
#include <bits/stdc++.h> const int N = 1e5 + 5; const long long mod = 1e9 + 7; long long f[N], dp[N], w[55][55]; int n, q, num[55]; char s[N]; long long qpow(long long x, long long y) { long long res = 1; for (; y; y >>= 1, x = x * x % mod) if (y & 1) res = res * x % mod; return res; } int id(char x) { if (...
18
#include <bits/stdc++.h> using namespace std; const unsigned mod = 998244353; const unsigned _mod = 1e9 + 7; const long long infi = 0x3f3f3f3f3f3f3f3fll; const int inf = 0x3f3f3f3f; long long ksm(long long x, long long y) { long long ret = 1; while (y) { if (y & 1ll) ret = ret * x % mod; y >>= 1ll; x = ...
21
#include <bits/stdc++.h> using namespace std; ifstream fin("date.in"); vector<int> adj[300003]; int dad[300003]; int diam[300003]; int last, maxd, maxd2; void dfs(int c, int p, int h) { if (h > maxd) last = c, maxd = h; for (auto next : adj[c]) if (next != p) dfs(next, c, h + 1); } inline int ld(int a) { return...
13
#include <bits/stdc++.h> using namespace std; long long dp[705][2], sum[705][2]; char str[705]; inline void upd(long long &x, long long y) { x += y; if (x >= 1000000007) x -= 1000000007; } int main() { scanf("%s", str); int n = strlen(str); long long ans = 0; for (int d = 1; d <= 9; d++) { memset(dp, 0,...
20
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n * n) + ((n - 1) * (n - 1)) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; inline long double min(long double a, long double b) { if (a < b) return a; return b; } inline long double max(long double a, long double b) { if (a < b) return b; return a; } int n; int a[100100]; int pref[100100]; int suff[100100]; int solve() { pref[0] = a[0]; ...
8
#include <bits/stdc++.h> using namespace std; void debug() { cout << endl; } template <class T, class... R> void debug(T f, R... r) { cout << "[" << f << "]"; debug(r...); } template <class T> T mmin(T a, T b) { return min(a, b); } template <class T, class... R> T mmin(T a, R... b) { return min(a, mmin(b...)); ...
15
#include <bits/stdc++.h> using namespace std; unordered_map<long long, long long> hm; int main() { long long t = 1; while (t--) { long long n; cin >> n; long long a[n], sm = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; sm += a[i]; } sort(a, a + n); long long x = 100; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int l, c = 1; char s[100]; cin >> s; l = strlen(s); sort(s, s + l); for (int i = 0; i < l - 1; i++) { if (s[i] != s[i + 1]) c++; } if (c % 2 == 1) cout << "IGNORE HIM!"; else cout << "CHAT WITH HER!"; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e3 + 5; const long long MOD = 1e9 + 7; int n, m, a[MAXN], x; int main() { scanf("%d%d", &m, &n); for (long long i = 1; i <= n; i++) { printf("1\n"); fflush(stdout); scanf("%d", &x); if (x == 0) exit(0); if (x == -1) a[i]...
10
#include <bits/stdc++.h> using namespace std; const int inf = numeric_limits<int>::max(); const double eps = 1.0e-12; const double pi = 3.141592653589793238462643383279; inline string readln() { string _s; getline(cin, _s); return _s; } int main() { int m, n; cin >> m >> n; readln(); string s = readln(); ...
13
#include <bits/stdc++.h> using namespace std; int ind[100001]; int main() { int n, m; cin >> n >> m; int c = 0; while (m % n == 0) { if (m == n) { cout << "YES\n" << c << "\n"; return 0; } m /= n; c++; } cout << "NO\n"; }
2
#include <bits/stdc++.h> using namespace std; template <class T> struct SegTree { int n; vector<T> t; T E = -1e9; T comb(T a, T b) { return max(a, b); } SegTree() {} SegTree(int _n) : n(_n) { t.assign(4 * n + 5, E); } SegTree(vector<T>& bld) : n(bld.size()) { t.assign(4 * n + 5, E); build(bld, 1, ...
13
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int G = 3; int n, bs[1 << 20], lim = 1, lg, m, invlim, rev[1 << 20], f[1 << 20], g[1 << 20], qaq[1 << 20], res; inline int pov(int x, int y) { int res = 1; for (; y; x = (1ll * x * x) % mod, y >>= 1) if (y & 1) re...
16
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; template <typename T> vector<T> compress(vector<T> v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); return v; } template <typename T> map<T, long long> dict(const vector<T> &v) { map<T, long long> res; for (long...
16
#include <bits/stdc++.h> using namespace std; int n; int num[200005]; int test[200005]; char key[200005]; int pre; int cnt = 0; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &num[i]); test[i] = num[i]; } scanf("%s", key); key[n - 1] = 0; if (key[0] == '1') pre = 0; el...
6
#include <bits/stdc++.h> using namespace std; int main() { int Na, Nb, k, m; vector<int> A, B; cin >> Na >> Nb >> k >> m; for (int i = 0; i < Na; i++) { int tmp; cin >> tmp; A.push_back(tmp); } for (int i = 0; i < Nb; i++) { int tmp; cin >> tmp; B.push_back(tmp); } if (A[k - 1] <...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const long long maxn = 555; long long dp[2][maxn][maxn]; char str[maxn][maxn]; const long long mod = 1e9 + 7; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1); memset(dp,...
15
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); long long int x, y, z; cin >> x >> y >> z; long long int n = (x + y) / z; if (x % z + y % z >= z) { cout << n << " " << min(z - x % z, z - y % z); } else { cout << n << " " << 0; } return 0; }
2
#include <bits/stdc++.h> using namespace std; string tostring(long long n) { ostringstream ss; ss << n; return ss.str(); } long long tonumber(string str) { stringstream ss; ss << str; long long n; ss >> n; return n; } string res; int a, b; vector<string> v; int main() { long long n, num, i, j; vecto...
6
#include <bits/stdc++.h> using namespace std; int main(void) { int n, i; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; bool inc = false, dec = false; bool gay = false; if (n == 1) { cout << "YES" << endl; } else { for (i = 1; i < n; i++) { if (arr[i] - arr[i - 1]...
2
#include <bits/stdc++.h> using namespace std; bool check(string s, vector<string> g) { long long n = g.size(), m = s.size(); map<string, long long> make_pair; for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) { if (s[j] != g[i][j]) { make_pair[g[i]]++; if (make_pair[g...
9
#include <bits/stdc++.h> using namespace std; int main() { int Data1, Data2; pair<int, int> Search[51]; cin >> Data1 >> Data2; for (int i = 1; i <= Data1; i++) cin >> Search[i].first >> Search[i].second, Search[i].first *= -1; sort(Search + 1, Search + Data1 + 1); cout << count(Search + 1, Search + Data...
3
#include <bits/stdc++.h> using namespace std; int c[401], n, ans = -1, p, cnt, w; int main(int argc, char **argv) { cin >> n; for (int i = 0; i < n; i++) cin >> c[i]; for (int i = 1; i < n; i++) { for (int j = i; j < n; j++) { p = c[i - 1] - 1, cnt = 1, w = c[j]; for (int k = i; k <= j; k++) { ...
18
#include <bits/stdc++.h> using namespace std; struct edge { int vertex, cost; }; vector<list<edge>> ADJLST; vector<int> heights, Number; int calHeight(int ind, int par = 0) { heights[ind] = 1; for (list<edge>::iterator itr = ADJLST[ind].begin(); itr != ADJLST[ind].end(); itr++) { if (itr->vertex != par...
8
#include <bits/stdc++.h> int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); if (a == c && b != d) { printf("%d %d %d %d\n", abs(b - d) + a, b, abs(b - d) + a, d); } if (a != c && b == d) { printf("%d %d %d %d\n", a, abs(a - c) + b, c, abs(a - c) + b); } if (a != c && b != d) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { string cad; cin >> cad; string res = ""; for (int i = 0; i < cad.size(); i++) { if (cad[i] != 'd' && cad[i] != 'a') res += cad[i]; else { if (cad[i] == 'd' && i + 2 < cad.size() && cad[i + 1] == 'o' && cad[i + 2] == 't') { ...
5
#include <bits/stdc++.h> using namespace std; using T = pair<long long, long long>; long long n, m; string s; T gpos(long long v) { long long x = 0, y = 0, u = 0, d = 0, l = 0, r = 0; for (long long i = 0; i <= v - 1; ++i) { auto &c = s[i]; if (c == 'U') u = min(u, --x); else if (c == 'D') d...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int ch; stack<int> operands; stack<char> ops; getchar(); while ((ch = getchar()) != EOF) { char c = char(ch); if (c == '\n') break; switch (c) { case '(': break; case '0': operands.pu...
18
#include <bits/stdc++.h> using namespace std; const long long N = 2e2 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7; const long long infll = 1e18 + 7; long long n, m, ans = inf; vector<pair<long long, long long>> a[N]; long long adj[N][N]; long long dist[N][N]; vector<pair<pair<lo...
16
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 10, M = 5010, MOD = 1e9 + 7, ML = 25; int a[M], b[M], h[M], vis[M], n, dis; int dfs(int v, int d) { vis[v] = 1; h[v] = d; int z = 1; for (int u = 1; u < n; u++) { if (abs(a[v] - a[u]) + abs(b[v] - b[u]) <= dis) continue; if (!vis...
18
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, a[N], ls[N << 2], rs[N << 2]; long long w[N << 2]; bool add[N << 2]; void build(int p, int l, int r) { ls[p] = l, rs[p] = r; if (l == r) { w[p] = a[l]; return; } int mid = l + r >> 1; build(p << 1, l, mid); build(p << 1 | 1,...
10
#include <bits/stdc++.h> using namespace std; const int Mod = (int)((int)1e9 + 7); struct Circle { int c, r, idx; bool operator<(const Circle &o) const { return c < o.c; } }; bool valid(int x, int y, Circle circle) { int c_x = circle.c; long long int dx = c_x - x; long long int dy = y; return dx * dx + dy *...
9
#include <bits/stdc++.h> using namespace std; const int N = 4e3 + 5; const int M = 65; int n, A[N]; int dp_l[N][M][M], dp_r[N][M][M]; int solve_r(int l, int sz, int k); int solve_l(int l, int sz, int k) { if (sz < k) return 0; if (~dp_l[l][sz][k]) return dp_l[l][sz][k]; int now = solve_r(l + k, sz - k, k) + A[l +...
17
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 10; long long pre[maxn][2]; long long dp[maxn][2]; long long sum[maxn][2]; long long dsum[maxn][2]; long long num[maxn]; int b[maxn]; int w[maxn]; int n, k; string s; int main() { cin >> n >> k; cin >> s; num[0] = 1; f...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; struct SegmentTree { long long seg[4 * maxn]; void init() { memset(seg, 0, sizeof(seg)); } long long query(int x, int st, int en, int l, int r) { if (r < st || en < l) { return 0; } if (l <= st && en <= r) { return seg...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, sol = 0; cin >> n; if (n % 2 != 0) ++n; sol = n / 2; cout << sol; return 0; }
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e3 + 10; ; long long vis[maxn][maxn]; struct Edge { long long v, w, next; } e[maxn << 1]; struct Ans { long long u, v, w; } ans[maxn << 2]; long long Cnt; long long head[maxn]; long long cnt; void add(long long u, long long v, long long w) { e[...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<char> v; unordered_map<char, int> m; string s; for (int i = 0; i < n; i++) { cin >> s; v.push_back(s[0]); m[s[0]]++; } int count = 0; for (auto i : m) { int k = i.second / 2; count += k * (k - 1) / 2...
1
#include <bits/stdc++.h> using namespace std; inline long long mod(long long n, long long m) { long long ret = n % m; if (ret < 0) ret += m; return ret; } long long M; long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long exp(long long a, long long b, long long m) { if (b ==...
13
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int t, n, d; cin >> t; while (t--) { cin >> n >> d; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { while (a[i] && i <= d) { a[0]++; a[i]--; d -= i; } ...
0
#include <bits/stdc++.h> #define LL long long #define SZ 200000 using namespace std; int main() { int t; LL xx, yy; scanf ("%d", &t); while (t--) { scanf ("%lld %lld", &xx, &yy); LL ans = 0; for (LL r = 1; r <= min((LL)100000, yy); r ++) { LL b1 = (xx/r) - 1; ...
9
#include <bits/stdc++.h> using namespace std; void init() {} const int N = 202; bitset<N> b[N * N], c; bool u[N * N][N]; int n, k, len, x; bool uu[N * N], uuu[N * N]; vector<vector<int> > ans; vector<int> cur; int main() { init(); cin >> n; if (n == 2) { cin >> len; cin >> x; cout << "1 " << x << "\n"...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0); int n; string s; cin >> n >> s; bool ok = true; for (int i = 1; i < n; i++) { if (s[i] == '1' && s[i - 1] == '1') { ok = false; } } for (int i = 0; i < n; i++) { if ((i - 1 < 0 || s[i - ...
4
#include <bits/stdc++.h> using namespace std; vector<long long int> v[1000011]; long long int intime[200011], outtime[200011]; long long int up[200011][25]; long long int tim, depth; pair<long long int, long long int> pp[200011]; long long int dist[200011]; void dfs(long long int s, long long int p) { intime[s] = ++t...
10
#include <bits/stdc++.h> using namespace std; const int N = 111111; vector<int> P[N]; const int MOD = 1000000007; long long d[N], e[N]; long long quick_pow(long long b, long long n) { long long ret = 1; while (n != 0) { if (n % 2 == 1) ret = ret * b % MOD; b = b * b % MOD; n /= 2; } return ret; } lo...
13
#include <bits/stdc++.h> using namespace std; struct t_v { float t, v; }; int mycomp(t_v a, t_v b) { return (a.t < b.t); } int main() { int n; float a, d; scanf("%d %f %f", &n, &a, &d); t_v tv[n]; for (int i = 0; i < n; i++) { scanf("%f %f", &tv[i].t, &tv[i].v); } sort(tv, tv + n, mycomp); for (in...
8
#include <bits/stdc++.h> int Recursively(int l1, int r1, int l2, int r2, int step) { if (r1 < l1 || r2 < l2) { return 0; } else if (r1 == r2) { return r1 - std::max(l1, l2) + 1; } else if (l1 == l2) { return std::min(r1, r2) - l1 + 1; } else if (step == 1) { return 1; } else { int mid = (1...
16
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c; cin >> a >> b >> c; int total = abs(a - b) * 2; if (total < max(a, b) || c > total) { cout << -1 << endl; } else { if (c > total / 2) { cout << c - (total / 2) << endl; ...
0
#include <bits/stdc++.h> using namespace std; struct Vote { int p, c; } v[3005]; bool cmp(const Vote &a, const Vote &b) { return a.c > b.c; } int main() { int n, m, vote[3005] = {0}; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d%d", &v[i].p, &v[i].c); int mx = 0; long long ans = 1e16; bool ...
9
#include <bits/stdc++.h> using namespace std; int n, m; int k[123123]; int cnt[123123]; int a[123123]; map<int, unordered_set<int> > fuck; int main() { ios_base::sync_with_stdio(0); cin >> n; int ans = 1; for (int i = 0; i < n; i++) { int x; cin >> x; int p = 2; while (p * p <= x) { if (x ...
6
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int n, k; string s; int BS[1000005], WS[1000005]; long long LM[1000005], BF[1000005], RM[1000005], WF[1000005]; long long ans, pw2; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; cin >> s; for (int i...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, m, ok = 1; cin >> m >> n; if (n == 1) { cout << -1; return 0; } if (n == 2 && m == 3) { cout << 11 << "\n"; return 0; } if (n == 3 && m == 5) { cout << 11 << "\n"; return 0; } int sol = 0; while (1) { if (n...
17
#include <bits/stdc++.h> using namespace std; using namespace chrono; template <class T> void Swap(T &a, T &b) { a ^= b; b ^= a; a ^= b; } template <class type> void show(type name) { for (auto &nm : name) cerr << nm << ' '; cerr << '\n'; } using lng = long long; using ivec = vector<int>; int main() { int n...
0
#include <bits/stdc++.h> using namespace std; struct _nl { } nl; bool _ns = 0; template <typename T> void _p(const T& _) { if constexpr (is_same<T, _nl>()) { cout << "\n"; _ns = 0; } else { if (_ns) cout << " "; cout << _; _ns = 1; } } template <typename... T> void out(const T&... _) { (_p(_...
14
#include <bits/stdc++.h> using namespace std; int N, X, res; int main() { cin >> N >> X; for (int i = 1; i * i <= X; i++) { if (X % i == 0 && X / i <= N) { res += 2; if (i * i == X) { res -= 1; } } } cout << res << '\n'; }
2
#include <bits/stdc++.h> using namespace std; const int md = 1000000007; int n, a[200009], b[200009], c[200009], used[100009], cnt[100009], s1[100009], s1c[100009], s2[100009], s2c[100009], par[19][100009]; int val[19][100009], q, dep[100009]; vector<int> adj[100009]; inline void Dfs1(int x) { used[x] = 1; cnt[...
19
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); int n; int main() { cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { int start = j * n - n, end = start + n; if (j % 2 == 0) { printf("%d ", end - i + 1); } else ...
2
#include <bits/stdc++.h> using namespace std; int fa[51], d[51]; int root(int a) { if (a == fa[a]) return a; return fa[a] = root(fa[a]); } int main() { int n, m, i, j, a, b; scanf("%d%d", &n, &m); if (m > n) { printf("NO\n"); return 0; } if (n == 1) { printf("YES\n"); if (m == 1) pri...
15
#include <bits/stdc++.h> using namespace std; const long long int INF = 9223372036854775807; const long long int mod = 1000000007; long long int MOD(long long int a, long long int b) { if (a > b) return a - b; else return b - a; } long long int max3(long long int a, long long int b, long long int c) { ret...
11
#include <bits/stdc++.h> using namespace std; double dp[55][5005]; bool vis[55][5005]; int n, r; double p[55]; int fast[55], slow[55], ispos[55]; double prv; double solve(int now, int tot) { if (tot > r) return 1e100; if (now == n) return 0.0; if (vis[now][tot]) return dp[now][tot]; vis[now][tot] = 1; double ...
16
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for (auto e : v) out << e << ' '; return out; } template <class T> ostream& operator<<(ostream& out, vector<T> v) { return prnt(out, v); } template <cla...
17
#include <bits/stdc++.h> using namespace std; const int N = 5001; int n, C[N][N], mod = 1e9 + 7; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); C[0][0] = 1; for (int i = 1; i < N; i++) { C[i][0] = 1; for (int j = 1; j < N; j++) { C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; ...
16
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long kuaisumi(long long x, long long y) { long long ans = 1; while (y) { if (y % 2) ans = ans * (x % MOD) % MOD; x = (x % MOD) * (x % MOD) % MOD; y /= 2; } return ans; } int main() { int n; long long t, ans2, ans = 2; ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; double arr[2 * n]; int count = 0; for (int i = 0; i < 2 * n; i++) { cin >> arr[i]; if (arr[i] - floor(arr[i]) == 0) count++; arr[i] = arr[i] - floor(arr[i]); } double sum = 0; for (int i = 0; i < 2 * n; i++) { su...
10
#include <bits/stdc++.h> using namespace std; int arr[100005]; int main() { int n; scanf("%d", &n); int i; for (i = 0; i < n; i++) scanf("%d", arr + i); sort(arr, arr + n); if (arr[n - 1] == 1) { arr[n - 1] = 2; for (i = 0; i < n; i++) printf("%d ", arr[i]); } else { arr[n - 1] = 1; printf...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int n, c = 0, k, m = 0; scanf("%lld", &n); scanf("%lld", &k); long long int a[n]; for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); } for (int i = 0; i < n; i++) { if (a[i] >= (k * 2)) { c = c + (a[i] / (k * 2)); a[...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; inline long long ksm(long long a, long long b) { long long ans = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) ans = ans * a % mod; return ans; } long long n, m; long long num_a[200000], num_b[400000], cost[500000]; signed main()...
13
#include <bits/stdc++.h> using LL = long long; const int MAXN = 10000031; LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } LL exp(LL a, LL b) { LL ans = 1; for (; b; b >>= 1) { if (b & 1) { ans *= a; } a *= a; } return ans; } LL n = 0, l = 0, r = 0; LL p[MAXN]; LL solve() { if (n == 1) {...
16
#include"bits/stdc++.h" using namespace std; // ********************************************************************************************************************************************* template <typename T> T inverse(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m...
15
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long p = 1; while (b) { if (b % 2) { p = p * a; } b >>= 1; a = a * a; } return p; } bool prime(long long n) { if (n <= 3) { return true; } for (long long i = 2; i <= sqrt(n); ++i) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { vector<int> l(6); for (int i = 0; i < 6; i++) cin >> l[i]; sort(l.begin(), l.end()); if (l[0] == l[3]) cout << (l[4] == l[5] ? "Elephant" : "Bear"); else if (l[1] == l[4]) cout << "Bear"; else if (l[2] == l[5]) cout << (l[0] == l[1] ? "E...
3
#include <bits/stdc++.h> using namespace std; const double eps = 1E-9; int main(int argc, char **argv) { ios::sync_with_stdio(false); int n; cin >> n; string name; int score; map<string, int> gamer; for (int i = 0; i < n; ++i) { cin >> name >> score; gamer[name] = max(score, gamer[name]); } ma...
6
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, c = getchar(), f = 0; for (; c > '9' || c < '0'; f = c == '-', c = getchar()) ; for (; c >= '0' && c <= '9'; x = (x << 1) + (x << 3) + c - '0', c = getchar()) ; return f ? -x : x; } inline void write(int x) { if (x < 0) putch...
26
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[100005]; int main() { int n, i, d; cin >> n >> d; for (i = 1; i <= n; i++) scanf("%d%d", &arr[i].first, &arr[i].second); sort(arr + 1, arr + n + 1); long long int ans = 0, cur = 0; int l = 1; for (i = 1; i <= n; i++) { while ((l < i) && ...
7
#include <bits/stdc++.h> using namespace std; template <typename X, typename Y> static inline void xmin(X &x, Y y) { if (y < x) x = y; } template <typename X, typename Y> static inline void xmax(X &x, Y y) { if (x < y) x = y; } long long pw(long long x, long long y, long long md) { if (!y) return 1; if (y & 1) ...
12
#include <bits/stdc++.h> using namespace std; int son[400005], Top[400005], dep[400005], siz[400005]; int q, h[400005], cnt = 1, num, tot, bl[400005]; int n, m, dfn[400005], low[400005], stk[400005], top; int fa[400005], cf1[400005], cf2[400005], cal[400005], prt[400005]; vector<int> p[400005]; struct node { int to, ...
20
#include <bits/stdc++.h> using namespace std; const int MAXM = 60; template <typename _T> void read(_T &x) { _T f = 1; x = 0; char s = getchar(); while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while ('0' <= s && s <= '9') { x = (x << 3) + (x << 1) + (s ^ 48); s = getchar...
24
#include <bits/stdc++.h> using namespace std; int u[100005], c[100005], x[100005], y[100005]; int main() { int n, i, j, ans = 0; scanf("%d", &n); for (i = 1; i < n; i++) { scanf("%d%d", &x[i], &y[i]); } for (i = 1; i <= n; i++) { scanf("%d", &c[i]); } for (i = 1; i <= n; i++) { if (c[x[i]] != ...
8
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int arr[105]; int t; cin >> t; while (t--) { int n, d; cin >> n >> d; for (int i = 0; i < n; i++) cin >> arr[i]; int ans = arr[0]; int nday = 0; int i = -1...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const int inf = (int)1e9 + 5; const long long INF = (long long)1e18 + 5; long long n, k; vector<vector<long long>> a, out; vector<bool> vis; vector<long long> out_ans; long long ans = 0; long long dfs(long long v) { vis[v] = true...
13
#include <bits/stdc++.h> using namespace std; const int maxn = int(2e5) + 100; struct astr_data { int start, num, nid, type; astr_data() { start = num = 0; } bool operator<(const astr_data b) const { if (type != b.type) return (type < b.type); if (nid != b.nid) return (nid < b.nid); return num < b.num...
21
#include <bits/stdc++.h> using namespace std; template <class T> bool up_max(T& a, const T& b) { return b > a ? a = b, 1 : 0; } template <class T> bool up_min(T& a, const T& b) { return b < a ? a = b, 1 : 0; } priority_queue<pair<string, int>, vector<pair<string, int> >, greater<pair<string, int> > >...
13
#include <bits/stdc++.h> using namespace std; int a[200010], t[200010], st[200010], sx[200010], eqlt[200010], eqlx[200010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; t[i] = -1; } int q; cin >> q; int cnt = 0; eqlt[0] = -1, eqlx[0] = 0; for (int i = 0; i < q; i++)...
8
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; long long x[N]; long long y[N]; long long b[N]; long long b_pref[N] = {}; long long ans[N] = {}; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; long long sum_y = 0; for (int i = 0; i < n; ++i) { c...
11
#include <bits/stdc++.h> using namespace std; int dp[20000], pp[20000]; int a[20000], b[20000], c[20000]; int n, k; int main() { while (~scanf("%d%d", &n, &k)) { memset(dp, -0x3f, sizeof(dp)); memset(pp, -0x3f, sizeof(pp)); dp[0] = pp[0] = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); ...
11