solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int MX = 2e5 + 5; const long long INF = 1e18; const long double PI = 4 * atan((long double)1); template <class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T& b) { return a < ...
10
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t > 0) { int n, k, count = 0; cin >> n >> k; string s, c; vector<int> lab; cin >> s; for (int i = 0; i < k - 1; i++) { c.push_back('('); c.push_back(')'); } for (int i = 0; i < (n - 2 * k...
4
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n, s, a[200009], c[200009]; int main() { scanf("%d %d", &n, &s); s--; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (i != s) c[a[i]]++; } int ret = n - 1, sc = 0, sb = 0; for (int i = 1; i < n; i++) { sc += ...
5
#include <bits/stdc++.h> using namespace std; vector<int> g[23]; int n, m, a, b; int d[23]; double p[23]; double A[23 * 23][23 * 23], X[23 * 23][23], B[23 * 23][23]; int mp[23][23]; int tot; int f(int a, int b) { if (a > b) swap(a, b); return mp[a][b]; } void get_A() { for (int i = 1; i <= n; ++i) { for (int ...
9
#include <bits/stdc++.h> int main(void) { long long p, k; std::cin >> p >> k; std::vector<long long> vec; while (p != 0) { auto x = p % -k; p /= -k; if (x < 0) { x += k; ++p; } vec.emplace_back(x); } std::cout << vec.size() << std::endl; for (auto i : vec) std::cout << i <<...
6
#include <bits/stdc++.h> using namespace std; const int N = 2005; const int BASE = (int)1e9; int parse(char s[]) { int n = strlen(s); int val = 0; for (int i = 0; i < n; i++) val = 10 * val + (s[i] - '0'); return val; } struct BigInt { vector<int> a; void scan() { static char s[N]; scanf("%s", s); ...
9
#include <bits/stdc++.h> using namespace std; const int kMaxN = 1010; const int kMaxM = 32; const int kMo = 1000000009; int f[2][2][kMaxM][kMaxM][kMaxM]; int n, h; void solve() { int w = 0; f[w][1][0][0][0] = 4; for (int k = 2; k <= n; ++k) { memset(f[w ^ 1], 0, sizeof(f[w ^ 1])); for (int ii, i = 0; i < ...
7
#include <bits/stdc++.h> using namespace std; struct e { int a, b; }; e p[100005]; int n, k; bool use[100005]; priority_queue<int, vector<int>, std::greater<int> > Q; bool criteriu(e a, e b) { return a.b > b.b; } long long af; int main() { scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &p[...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, maxbit = 21; long long h[maxn], dt[maxn], p[maxn][maxbit], ans, tim, n, q, dis[maxn]; vector<pair<int, int>> adj[maxn]; set<pair<int, int>> s; void dfs(int v, int par) { h[v] = h[par] + 1; dt[v] = tim++; p[v][0] = par; for (int i = 1; i < ...
11
#include <bits/stdc++.h> using namespace std; const int m = 1e6 + 3; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { int n; cin >> n; vector<int> a(n), c; for (int i = 0; i < n; i++) cin ...
2
#include <bits/stdc++.h> using namespace std; int main() { string a, b; int n; cin >> a >> b >> n; cout << a << " " << b << endl; string k, r; for (int i = 0; i < n; i++) { cin >> k >> r; if (a == k) a = r; else b = r; cout << a << " " << b << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int sgN = 1048576; const int mxQ = 3e5; struct node { ll sum, mx; }; node segT[sgN << 1]; int join[mxQ]; inline int fst(int i) { int d = 31 - __builtin_clz(i); return (sgN >> d) * (i ^ 1 << d); } void update(int i, int d) { i += sgN; se...
8
#include <bits/stdc++.h> using namespace std; long long int mod_pow(long long int a, long long int n, long long int b) { long long int res = 1; while (n) { if (n & 1) res = (res * a) % b; a = (a * a) % b; n /= 2; } return res % b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
3
#include <bits/stdc++.h> using namespace std; const int N = 100005; const long long p = 239017; const long long md = 1e9 + 7; long long a[12][N]; long long aa[12][N]; long long d[12][N]; long long deg[N]; long long h[12][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); deg[0] = 1; for (in...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = (int)(1e9 + 1e6); const long long LINF = (long long)(4e18); const double EPS = 1e-9; const long long mod = 1e9 + 7; mt19937 ggen; int main(int argc, char* argv[]) { int a[] = {4, 8, 15, 16, 23, 42}; map<int, pa...
3
#include <bits/stdc++.h> int main(void) { int n, m; scanf("%d %d", &n, &m); puts((((n) < (m)) ? (n) : (m)) & 1 ? "Akshat" : "Malvika"); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; vector<int> st[maxn]; int n, m; int a, b; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", &a, &b); int x; if (b >= a) x = b - a; else x = n - a + b; st[a].push_back(x); } for (i...
5
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
5
#include <bits/stdc++.h> using namespace std; const int maxN = 10000 + 10; map<string, int> m; vector<int> a[maxN]; string name[maxN]; int main() { ios::sync_with_stdio(false); int e; cin >> e; for (int i = 0; i < e; i++) { int tmp; string x, y; cin >> x >> y; if (m.count(x) == 0) tmp = m.size()...
7
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int mod = 998244353; const double eps = 5e-13; const int N = 2e5 + 5; long long sum1[N], sum2[N]; long long X(int id) { return id - 1; } long long Y(int id) { return (id - 1) * sum1[id - 1] - sum2[id - 1]; } long double K(int i, int j) { ...
8
#include <bits/stdc++.h> using namespace std; string s; bool Check(const string& s) { int cnt = 0; for (int i = 0; i < (int)s.length(); i++) cnt += (s[i] != s[0]); if (cnt > 1) return true; return false; } bool Palin(const string& s) { for (int i = 0; i < (int)s.length(); i++) if (s[i] != s[(int)s.length(...
5
#include <bits/stdc++.h> using namespace std; int main() { long long m, n; cin >> m >> n; long long p[n]; long long x; int flag = 0; for (int i = 0; i < n; i++) { cout << 1 << endl; fflush(stdout); cin >> x; if (x == 0 || x == -2) { flag = 1; break; } if (x == 1) p[...
5
#include <bits/stdc++.h> using namespace std; void rd(int &num) { char c; while (!isdigit(c = getchar()) && c != '-') ; bool ne = 0; if (c == '-') { ne = 1; c = getchar(); } num = c - '0'; while (isdigit(c = getchar())) num = num * 10 + c - '0'; if (ne) num = -num; } int n, m; int f[100005];...
5
#include <bits/stdc++.h> using namespace std; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); ...
6
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; vector<std::vector<int> > List(100000); vector<std::vector<int> > id(100000); int parent[18][100000]; int level[100000]; int m[18][100000][10]; int ans[20]; void merge(int v, int l, int u) { int i = 0, j = 0; assert(l > 0); for (int k = 0; ...
7
#include <bits/stdc++.h> using namespace std; string a[100]; int id[30]; vector<int> cn[30]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { char l1 = '-'; char l2 = '-'; int j = -1; int s = a[i - 1].size(); if (a[i - 1].size() > a[...
4
#include <bits/stdc++.h> using namespace std; template <class T> inline T pow2(T a) { return a * a; } const int MOD = (int)1e6 + 3; ; const int maxn = (int)5e5 + 10; ; long long n, m, p[maxn]; vector<vector<long long> > num, t; void resize(vector<vector<long long> >& a, long long x, long long y) { a.resize(x); fo...
7
#include <bits/stdc++.h> using namespace std; int n, T; double dp[5001][5001]; int p[5001], t[5001]; double quickpow(double x, int y) { double res = 1; while (y) { if (y & 1) res *= x; x *= x; y >>= 1; } return res; } int main() { cin >> n >> T; dp[0][0] = 1; for (int i = 0; i < n; i++) scanf(...
8
#include <bits/stdc++.h> using namespace std; long long n, m, a[51][51], rw[51], rb[51], cw[51], cb[51], f[51]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; if (a[i][j] == 0) { rw[i]++; cw[j]++; } else { rb[i]...
2
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int x = 0, f = 1; while ((c < '0' || c > '9') && c - '-') c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + c - 48; c = getchar(); } return x * f; } cons...
8
#include <bits/stdc++.h> const int INF = 500000001; const double EPS = 1e-9; const double PI = acos(-1.0); using namespace std; int main() { srand(time(NULL)); char ch[101][105]; int n, m; int bl[105][105], cnt = 0; while (~scanf("%d %d", &n, &m)) { cnt++; for (int i = 0; i < n; i++) { scanf("%s...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 0, q = 0; cin >> n; string k; cin >> k; for (int i = 0; i < n; i++) { if (k[i] == '-') { if (m != 0) m--; } else m++; } cout << m; return 0; }
0
#include <bits/stdc++.h> using namespace std; long long n, m, p[105], a, l, r, ans; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a; p[i] = a + p[i - 1]; } while (m--) { cin >> l >> r; a = p[r] - p[l - 1]; if (a > 0) ans += a; } cout << ans; }
2
#include <bits/stdc++.h> using namespace std; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; long long gcd(long long a, long long b) { if (b == 0) return...
3
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; template <class T, class U> inline void add_self(T &a, U b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } template <class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void ma...
6
#include <bits/stdc++.h> using namespace std; long long int INF = 1000000000000000000; long long int mod = 1000000007; void fun() { long long int n; cin >> n; vector<long long int> v(n); long long int i, j; long long int sum = 0; map<long long int, long long int> m; set<long long int> s; for (i = 0; i <...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; char ss[N], ans[N]; int minn[N * 3], add[N * 3]; void addMin(int a, int c) { minn[a] += c; add[a] += c; } void pushDown(int a) { addMin(a << 1, add[a]), addMin(a << 1 | 1, add[a]); add[a] = 0; } void update(int a) { minn[a] = min(minn[...
6
#include <bits/stdc++.h> using namespace std; char mp[6005][6005]; bool isPrime[6005]; int prime[6005]; int tot; void get_prime() { for (int i = 2; i < 6005; i++) { if (!isPrime[i]) prime[tot++] = i; for (int j = 0; j < tot && i * prime[j] < 6005; j++) { isPrime[i * prime[j]] = 1; if (i % prime[j]...
3
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int gcd(int xx, int yy) { while (yy != 0) { xx = xx % yy; swap(xx, yy); } return xx; } int lcm(int xx, int yy) { return (xx / gcd(xx, yy)) * yy; } int Power(int a, int x, int base = -1) { if (base == -1) { if (x == 1) ...
1
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(false); cin >> n; if (n == 1) { cout << 1 << endl; return 0; } cout << n; for (int i = 1; i < n; ++i) cout << " " << i; cout << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; struct node { int val; int cnt; int i; inline long long cal(const long long& x, const long long& cnt) const { long long num = x / cnt; long long res = x % cnt; return 1ll * (cnt - res) * num * num + 1ll * res * (num + 1) * (num ...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { long long n, m, i, j, k; double ans = 0.0; cin >> n >> m; for (i = 1; i <= n; ++i) { ans += i * (pow(i * 1.0 / n, m) - pow((i - 1) * 1.0 / n, m)); } printf("%.12f\n", ans); return 0; }
4
#include <bits/stdc++.h> using namespace std; int ans[100005]; map<int, int> num; int main() { long long n, k, cnt = 0; cin >> n >> k; for (int j = 0; n; n >>= 1, j++) if (n & 1) num[j] = 1, cnt++; if (cnt > k) return cout << "No" << endl, 0; for (int i = 63; i >= -63; i--) { if (k - cnt >= num[i]) { ...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; string g = ""; for (int i = 0; i < s.size(); i += 2) { g = g + s[i]; } cout << g << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; using LL = long long; template <class T> int size(T &&x) { return int(x.size()); } template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &p) { return out << '(' << p.first << ", " << p.second << ')'; } template <class T> auto operator<<(ostream ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int r = 2 * 3 * 2 * 5 * 7 * 2 * 3; cout << n / r; }
1
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, flag = 1; char ch = 0; while (!isdigit(ch)) { ch = getchar(); if (ch == '-') flag = -1; } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return x * flag; } const int inf = 1e9 + 7; int...
7
#include <bits/stdc++.h> using namespace std; long long k[10] = {9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 9999999999}; int main() { int T; cin >> T; while (T--) { long long A, B; cin >> A >> B; long long w = upper_bound(k, k + 10, B) - k; ...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int MAXN = 3e5 + 100; bool used[MAXN]; int dist[MAXN]; int pr[MAXN]; vector<int> e[MAXN]; vector<int> comp, ans; void bfs(int v) { queue<int> q; q.push(v); used[v] = true; dist[v] = 0; pr[v] = -1; comp.push_back(v); while (!q.empty()...
9
#include <bits/stdc++.h> using namespace std; void __print(int x) { cout << x; } void __print(long x) { cout << x; } void __print(long long x) { cout << x; } void __print(unsigned x) { cout << x; } void __print(unsigned long x) { cout << x; } void __print(unsigned long long x) { cout << x; } void __print(float x) { cou...
1
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, m, i, j, a[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { cin >> n; string s, ans = ""; cin >> s; long long y = 0; for (i = 0; i < n; i++) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k, maxm = INT_MIN, e = 0, s = 0; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) e++; else s++; } for (int i = 0; i < k; i++) { int p = e, q = s; for (int j = i; j < n; j += k...
1
#include <bits/stdc++.h> using namespace std; const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, 1, 0, -1}; const long long MOD = 1e9 + 7; const long long INF = 1e14; const double EPS = 1e-6; int n; double T; vector<double> p(5005); vector<int> t(5005); vector<vector<double>> dp(5005, vector<double>(5005, 0)); double...
8
#include <bits/stdc++.h> using namespace std; int a[5 * 100000 + 5], b[5 * 100000 + 5]; int n, k, sol; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; a[i] -= i; } for (int i = 1; i <= k; ++i) cin >> b[i]; a[0] = -(int)1e9; b[0]...
7
#include <bits/stdc++.h> using namespace std; long long fact[1000005], fact_inv[1000005], inv[1000005]; inline long long quick_pow(long long a, int n) { long long res = 1; while (n) { if (n & 1) res = res * a % 1000000007; a = a * a % 1000000007; n >>= 1; } return res; } int main() { int k, w; s...
11
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int n, m; cin >> n >> m; int ans = 0, right = 0, both = 0; int a[n][2][2]; for (int i = 0; i < n; i++) { cin >> a[i][0][0] >> a[i][0][1] >> a[i][1][0] >> a[i][1][1]; if (a[i][0][1] == a[i][1][...
0
#include <bits/stdc++.h> using namespace std; const string digit = "0123456789ABCDEFGHIJKLMNOPQRSTUVXWYZ"; string s, hour, mins; vector<int> ans; int main() { int base = 0; cin >> s; hour = s.substr(0, s.find(":")); mins = s.substr(s.find(":") + 1); for (int i = 0; i < hour.length(); i++) base = max(base,...
4
#include <bits/stdc++.h> using namespace std; int main() { int T, N; cin >> T >> N; T += 1; int i, count; count = 1; int k = T - N; if (N % 2 == 0) { if (T == 3) { cout << 1; } else { i = T - 1; while (i != N) { count++; i -= 2; } cout << count; } ...
1
#include <bits/stdc++.h> using namespace std; struct $ { $() { ios_base::sync_with_stdio(false); cin.tie(NULL); } } $; const int Mod = 1e9 + 7; void printMatrix(vector<vector<int> > &X) { for (int i = 0; i < X.size(); i++) { for (int j = 0; j < X[i].size(); j++) { cout << X[i][j] << " \n"[(j + 1...
6
#include <bits/stdc++.h> using namespace std; int n; char s[1001]; int Gao(bool now) { int res = 0; for (int i = 0; i < n; i++, now = !now) if (s[i] - '0' != now) res++; return res; } int main() { while (scanf("%d", &n) != EOF) { scanf("%s", s); int res = min(Gao(0), Gao(1)); if (res == 19921005...
5
#include <bits/stdc++.h> using namespace std; const long long LLINF = 8e18; const int MOD = 1e9 + 7; const int INF = 2e9; const int N = 2e5; int n; string s, ans; int a[26]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> s; for (auto c : s) { a[c - 'a']++; } for (int i = 0...
2
#include <bits/stdc++.h> using namespace std; const int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0}; int n, m, ans[505][505]; bool a[505][505]; char s[505]; vector<pair<int, int>> to[505][505]; void dfs(int i, int j) { for (auto [x, y] : to[i][j]) { if (ans[x][y] == ans[i][j]) { puts("NO"); exit(0); ...
9
#include <bits/stdc++.h> using namespace std; struct addq { int tp, v, id; long long a, b; bool operator<(const addq &x) const { return v > x.v; } }; struct mulq { int tp, id, addid1, addid2; long long a, b; bool operator<(const mulq &x) const { return a * x.b < b * x.a; } }; struct Ans { int tp, id; bo...
10
#include <bits/stdc++.h> using namespace std; long long int n, k, d, t, a[200007]; int main() { scanf("%lld", &t); while (t--) { scanf("%lld %lld %lld", &n, &k, &d); for (long long int i = 0; i < n; ++i) scanf("%lld", &a[i]); map<long long int, long long int> occ; long long int distinct = 0; lon...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], i, j, k1 = 0, k2 = 0; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) k1++; else k2++; } int k3 = 0, k4 = 0; for (i = 0; i < n; i++) { if (a[i] == 1) k3++; else k4++; ...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, T, k; int main() { cin >> T; while (T--) { cin >> n >> k; int tmp = n / k; int cnt = 0; for (int i = 1; i <= k; i++) { for (int j = 0; j < tmp; j++) { printf("%c", 'a' + i - 1); cnt++; } } ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long h, l; scanf("%lld %lld", &h, &l); long long div = 2 * h; h = h * h; l = l * l; double ans = (double)(l - h) / div; printf("%.15lf\n", ans); }
1
#include <bits/stdc++.h> const int max_n = 131072; struct edge { int v, num; edge *next; edge(int _v, int _num, edge *_next) : v(_v), num(_num), next(_next) {} } * E[max_n]; int n, t = 0, size[max_n], prt[max_n], heavy[max_n], dep[max_n], edge_num[max_n], top[max_n], num[max_n], len[max_n], w[max_n], ...
5
#include <bits/stdc++.h> using namespace std; using vint = vector<long long>; using pint = pair<long long, long long>; using vpint = vector<pint>; template <typename A, typename B> inline void chmin(A& a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A& a, B b) { if (a < b) a = b; }...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 1000; pair<long long, long long> p[maxn]; vector<long long> v; int getpos(long long V) { return lower_bound(v.begin(), v.end(), V) - v.begin() + 1; } long long C1[2][maxn]; long long C2[2][maxn]; void add(int x, long long K, long long C[][maxn], int...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n; long long m; cin >> n >> m; vector<pair<long long, long long>> nrs; for (long long i = 0; i < m; ++i) { pair<long long, long long> nr; cin >> nr.second >> nr.first; nrs.emplace_back(nr)...
0
#include <bits/stdc++.h> using namespace std; const long long int N = 3e5 + 7; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; string s; cin >> s; long long int ans = 8; if (s[0] == 'a' || s[0] == 'h') ans -= 3; if (s[1] == '1' || s[1] == '8') ans -= 3; if (ans == 2) ans = 3; ...
0
#include <bits/stdc++.h> using ll = long long; using namespace std; namespace Debug { template <class A, class B> ostream &operator<<(ostream &out, pair<A, B> &p) { out << "(" << p.first << ", " << p.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, vector<T> &v) { out << "{"; st...
6
#include <bits/stdc++.h> using namespace std; struct Q { int x, y, w; } A[200010]; int cmp(Q a, Q b) { return a.w < b.w; } int k; int p[400010], head[400010], nex[400010], w[400010], e; void add(int a, int b, int c) { p[e] = b; nex[e] = head[a]; head[a] = e; w[e++] = c; } long long dp[200010], vis[200010]; qu...
7
#include <bits/stdc++.h> using namespace std; long long a[300000]; int main() { int n, k, m; scanf("%I64d%I64d%I64d\n", &n, &k, &m); for (int i = 0; i < n; i++) { scanf("%I64d", a + i); } sort(a, a + n); printf("%I64d\n", (a[n - 1] * m + a[n - 2]) * (k / (m + 1)) + a[n - 1] * (k % (m + 1))); ...
1
#include <bits/stdc++.h> const int M = 12; const int N = 200100; using namespace std; int a[N]; long long pow_10[M]; map<int, int> cnt[M]; inline int get_len(int x) { int len = 0; while (x != 0) { len++; x /= 10; } return len; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, k; ...
5
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; set<int> s; int x[200100], y[200100]; bool exist(int xx, int yy) { return mp.count(pair<int, int>(xx, yy)) && mp[pair<int, int>(xx, yy)] != -1; } bool check(int xx, int yy) { if (!exist(xx, yy)) return true; if (yy == 0) return true; if ...
6
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const long long linf = (1ll << 62) - 1; const int N = 5e3 + 100; int n; int a[N], na[N]; int result[N][N]; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < n; i++) { for (int j = 0;...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; const int inf = INT_MAX; const long long inff = 1e18; const long long mod = 1e9 + 7; string t, s[maxn]; int n; int x = 1, N; int trie[maxn][28], cnt[maxn], fail[maxn], last[maxn]; int ps[2][maxn]; void init() { x = 1; memset(trie, 0, sizeof(tri...
8
#include <bits/stdc++.h> using namespace std; int const maxn = 200000 + 5; int lx[4 * maxn]; int tree[4 * maxn]; int n = 200000, m, k; void pushdown(int n) { lx[2 * n] += lx[n], lx[2 * n + 1] += lx[n], lx[n] = 0; } void update(int n, int l, int r, int begin, int end) { if (l >= begin && r <= end) lx[n] += 1; el...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = int(1e+9); const int MAXN = 200000; const int CNTN = MAXN + 10; long long Fib[CNTN], pFib[CNTN]; pair<long long, long long> operator>>(pair<long long, long long> lhs, int rhs) { if (rhs == 0) return lhs; return make_pair((lhs.first * Fib[rhs - 1] +...
3
#include <bits/stdc++.h> using namespace std; int a[6], b[6]; int main() { int n; while (cin >> n) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for (int i = 0; i < n; i++) { int c; scanf("%d", &c); a[c]++; } for (int i = 0; i < n; i++) { int c; scanf("%d", &c...
1
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int Mod = 998244353; int T; long long n; long long a[N]; template <typename T> T myceil(T x, T y) { return x / y + (x % y != 0); } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> T; vector<pair<long long, lon...
7
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e3 + 10; int k, n; int a[MAX_N]; bool fun(int x) { if (a[n - x] >= x) return 1; return 0; } int main() { cin >> k; while (k--) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = n; i >= 1; i--) { ...
0
#include <bits/stdc++.h> using namespace std; long long n; long long f[100001]; int main() { cin >> n; if (n == 2ll) { cout << 1 << endl; return 0; } f[0] = 1; f[1] = 2; for (int i = 2;; ++i) { f[i] = f[i - 2] + f[i - 1]; if (f[i] > n) { cout << i - 1 << endl; return 0; } }...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; 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 a, long long int b) { long long int ans = 1; while (b) { if (b % 2 == 1) { ans = (ans * a) % M...
0
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; map<long long, long long> deg; long long x, y; for (int i = 0; i < n - 1; i++) { cin >> x >> y; deg[x]++; deg[y]++; } if (deg[k] <= 1) ...
4
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = 3.141592653589793238462; const int dr[] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dc[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; int p[300005], out[300005]; int main() { ios_bas...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 9, MOD = 1e9 + 7; long long n, m, b[MAX], ans, res, a[MAX]; long long pw(long long a, long long b) { return b ? pw(a * a % MOD, b >> 1) * (b & 1 ? a : 1) % MOD : 1; } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> ...
6
#include <bits/stdc++.h> using namespace std; const bool print = false; const int N = 57; const long long mod = 1e9 + 7; int main() { int i, j, n; scanf("%d", &n); long long p = 0; for (i = 0; i <= n && i <= 8; i++) { p += n - i + 1; if (i < 8) for (j = 0; j <= n - i && j <= 4; j++) p += n - i - j...
6
#include <bits/stdc++.h> using namespace std; char a[300010]; char b[300010]; char c[300010]; bool cmp(char a, char b) { return a > b; } int main() { scanf("%s", a); scanf("%s", b); int n = strlen(a); for (int i = 0; i < n; i++) c[i] = '\0'; sort(a, a + n); sort(b, b + n, cmp); int l = 0, r = n - 1; int...
5
#include <bits/stdc++.h> using namespace std; bool sortinrev(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.first > b.first); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long tc = 1, i, j; while (tc--) { long long n, m; cin >> n >...
3
#include <bits/stdc++.h> using namespace std; pair<int, int> A[300005]; int B[300005]; pair<int, int> st[300005]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); A[i] = pair<int, int>(x, i); } for (int i = 0; i < n; i++) scanf("%d", &B[i]); sort(A, A + ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, d, e, f; cin >> n >> a >> b >> c >> d >> e >> f; int a1 = min(a, e) + min(b, f) + min(c, d); int a2 = n - (min(a, d + f) + min(b, e + d) + min(c, e + f)); cout << a2 << " " << a1; return 0; }
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const int MOD = 1e9 + 7; long long n, arr[MAXN]; long long dp[MAXN], len[MAXN]; long long answer = 0; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; answer += arr[1]...
7
#include <bits/stdc++.h> const int mod = 1e9 + 7; using namespace std; inline int read() { int x = 0, y = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') y = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return y ? ...
8
#include <bits/stdc++.h> int main() { int n; std::cin >> n; long long int ans = 1; long long int mod = (long long int)(1e9 + 7); for (int i = 1; i <= n; i++) { ans = (ans * i) % mod; } long long int sub = 1; for (int i = 1; i < n; i++) { sub = (sub * 2) % mod; } ans = ((ans - sub) % mod + mo...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; char str1[maxn], str2[maxn], str3[maxn]; char vis[maxn]; int main() { scanf("%s%s%s", str1, str2, str3); int len = (int)strlen(str1); for (int i = 0; i < len; i++) { vis[str1[i]] = str2[i]; } int len2 = (int)strlen(str3); for (int i = ...
0
#include <bits/stdc++.h> using namespace std; int main() { int h, a[100005], i, j, k; scanf("%d", &h); for (i = 0; i <= h; i++) { scanf(" %d", &a[i]); } for (i = 1; i <= h; i++) { if (a[i - 1] > 1 && a[i] > 1) { printf("ambiguous\n"); int level = 1, startNode = 1; printf("0"); ...
3
#include <bits/stdc++.h> using namespace std; int n; vector<long long> fo[61]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { long long tmp; scanf("%lld", &tmp); for (int j = 60; j >= 0; --j) { if (tmp & (1LL << j)) { fo[j].push_back(tmp); break; } } } lo...
7