solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int MAXN = 1e5 + 5; const long long MOD = 1e9 + 7; int a[MAXN]; int main() { int n, x; cin >> n >> x; int sum = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); sum += a[i]; } sum = sum + n - 1; if (sum == x) cou...
3
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return (a < b); } int main() { int n, i, k, i1 = 0, i2 = 0, i3 = 0, n1, n2, n3, mem; cin >> n; int a[n], b[n], x1[n], x2[n], x3[n]; for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n; i++) b[i] = i + 1; n1 = count(a, a + n, 1...
0
#include <bits/stdc++.h> using namespace std; int n, a, b; double p[2][2013]; pair<double, pair<int, int> > dp; pair<double, pair<int, int> > check(double k, double l) { dp = make_pair(0, make_pair(0, 0)); for (int i = 1; i <= n; i++) { auto cur = dp; cur = max(cur, make_pair(dp.first + p[0][i] - l, ...
22
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; cin >> n; int flag = 0; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int i = 0; while (i < n) { if (a[i] == 1) { flag = 1; break; } i++; } if (flag == 1) cout << "HARD"; else if (flag ==...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; const int INF = 0x3f3f3f3f; int a[maxn], b[maxn], cnt[maxn][4]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); for (int i = 0; i <= n; i++) for (int j = 0; j <= 3; j++) cnt[i][j] = 0; for (in...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, d, m; int ca, cb; long long a[N], b[N]; int main() { scanf("%d %d %d", &n, &d, &m); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (x > m) a[++ca] = x; else b[++cb] = x; } sort(a + 1, a + ca + 1); ...
10
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; bool Finish_read; template <class T> inline void read(T &x) { Finish_read = 0; x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; if (ch == EOF) return; ch = getchar(); } while (isdigit(ch))...
11
#include <bits/stdc++.h> int main() { int n, a[101] = {0}, i, j, sum, t, count, sum1; scanf("%d", &n); for (i = 0, sum = 0; i < n; i++) { scanf("%d", &a[i]); sum += a[i]; } sum /= 2; for (j = 0; j < n; j++) { for (i = 0; i < n - j; i++) { if (a[i] < a[i + 1]) { t = a[i]; a[...
1
#include <bits/stdc++.h> using namespace std; const int N = 200002; long long n, arr[N], ans, sum[N]; map<long long, long long> mp; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i], sum[i] = sum[i - 1] + arr[i], ++mp[arr[i]]; long double ans = 0; for (int i = 0; i < n; ++i) { long long y...
14
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; const long long MOD = 1e9 + 7; const long long mxN = 2e5 + 3; bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) { if (p1.first > p2.first) return true; else if (p1.first == p2.firs...
8
#include <bits/stdc++.h> using namespace std; int main() { int base, power; cin >> base >> power; int n = power; int* arr = new int[power]; for (int i = 0; i < n; i++) { cin >> arr[i]; } if (power == 1) { if (arr[0] % 2 == 0) cout << "even" << endl; else { cout << "odd" << endl; ...
1
#include <bits/stdc++.h> using namespace std; const long long INF = 2e18; int n, m; string s; int frec[20][20]; long long rec[1 << 20]; long long search(int mask, int cur) { if (rec[mask] != -1) { return rec[mask]; } long long minAns = INF; for (int i = 0; i < m; i++) { if ((mask & (1 << i)) > 0) { ...
14
#include <bits/stdc++.h> using namespace std; int T, x, maxx, n; double s; int main() { scanf("%d", &T); while (T--) { s = 0, maxx = 0; n = 250; for (int i = 1; i <= n; i++) { scanf("%d", &x); s += x * x, maxx = std::max(maxx, int(abs(x))); } s /= n; s /= maxx * maxx; if (s <...
20
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int T, a, b, ans; cin >> T; while (T--) { cin >> a >> b; int ans = 1; while (1) { if (2 * a <= ans && b <= ans) break; if (2 * b <= ans && a <= ans) break; ans++; } cout <...
0
#include <bits/stdc++.h> using namespace std; set<int> e[200010]; long long dp[200010]; int nxt[200010], w[200010]; bool vis[200010]; vector<int> q; long long dfs(int x, int y) { long long sol = 0; for (auto& i : e[x]) { if (i == y) continue; sol = max(sol, dfs(i, x)); } return sol + w[x]; } signed main...
14
#include <bits/stdc++.h> using namespace std; int main() { int num, cnt = 0, i = 1; cin >> num; while (true) { if (i == 1) cout << "a"; if (i == 2) cout << "b"; if (i == 3) cout << "c"; if (i == 4) cout << "d"; if (i % 4 == 0) i = 0; cnt++, i++; if (cnt == num) return 0; } }
3
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
20
#include <bits/stdc++.h> using namespace std; void FastInputOutput() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void ReadFromFile() { freopen("input.in", "r", stdin); } int D() { int t; scanf("%d", &t); return t; } long long LLD() { long long t; scanf("%lld", &t); return t; } char C()...
9
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; set<pair<int, int> > desc; set<pair<int, int> > ascBound; set<pair<int, int> > asc; int a[100100]; int b[100100]; int aInv[100100]; int bInv[100100]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; ...
13
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; bool pr(int k) { for (int l = 2; l * l <= k; l++) { if (k % l == 0) return false; } return true; } int main() { int n; cin >> n; if (pr(n)) { cout << 1; return 0; } else if (n % 2 == 0) { cout << 2; return ...
8
#include <bits/stdc++.h> using namespace std; template <class T> string tostring(T x) { ostringstream out; out << x; return out.str(); } long long toint(string s) { istringstream in(s); long long x; in >> x; return x; } int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[8] = {1, -1, 0, 0, -1, 1, -1, 1}; int ...
19
#include <bits/stdc++.h> using namespace std; int n, ans, xs; int A[200000 + 5]; int tot[3][4]; char zm[3] = {'R', 'G', 'B'}; int main() { cin >> n; char c; for (int i = 1; i <= n; i++) { cin >> c; if (c == 'R') A[i] = 0; else if (c == 'G') A[i] = 1; else if (c == 'B') A[i] = 2; ...
5
#include <bits/stdc++.h> using namespace std; int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); } int gcd_iter(int u, int v) { int t; while (v) { t = u; u = v; v = t % v; } return u < 0 ? -u : u; } int gcd(int u, int v) { return (v != 0) ? gcd(v, u % v) : u; } int main() { ...
4
#include <bits/stdc++.h> using namespace std; int main() { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (abs(x1 - x2) and abs(y1 - y2)) { cout << 2 * (2 + abs(x1 - x2) + abs(y1 - y2)) << endl; } else if (abs(x1 - x2) and !abs(y1 - y2)) { cout << 4 + 2 * abs(x1 - x2) + 2 << endl; } else { co...
3
#include <bits/stdc++.h> using namespace std; int x[10000]; int main() { int n, i, j; while (scanf("%d", &n) != EOF) { for (i = 0; i < n; i++) scanf("%d", &x[i]); int Max = 0; for (i = 0; i < n; i++) { int sum = 1; for (j = i + 1; j < n; j++) { if (x[j] <= x[j - 1]) sum++; ...
3
#include <bits/stdc++.h> using namespace std; int N; vector<long long> A; long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); } int main() { cin >> N; A.resize(N); for (int i = 0; i < N; ++i) cin >> A[i]; A.push_back(0LL); sort(A.begin(), A.end()); auto l = 0LL, r = accumulate(A.beg...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1050; struct Edge { int dest; int value; Edge *link; } * edge1[maxn] = {}, *edge2[maxn] = {}; int n, m, x, y; bool vis[maxn] = {}; long long dist[maxn] = {}; const long long inf = 1LL << 45; void Addedge(Edge **edge, int a, int b, int c) { Edge *t =...
11
#include <bits/stdc++.h> using namespace std; const int Max = 301000; const int Max_log = 30; vector<int> G[Max]; int root, V, n; int parent[Max_log][Max]; int depth[Max]; int son[Max]; int leaf[Max]; void dfs(const int v, int p, int d) { parent[0][v] = p; depth[v] = d; leaf[v] = v; son[v] = 1; int temp = 0; ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, i, a[2005], res[2005], j, cnt; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { cnt = 0; for (j = 0; j < n; j++) { if (a[j] > a[i]) cnt++; } res[i] = cnt + 1; } for (i = 0; i < n; i++) c...
0
#include <bits/stdc++.h> using namespace std; vector<int> pri; void sieve() { bool f[1000007]; f[0] = f[1] = 1; for (int i = 2; i < 1000007; ++i) { if (f[i]) continue; pri.push_back(i); for (int j = i * i; i <= 10000 && j < 1000007; j += i) f[j] = 1; } } bool prime(int x) { if (x == 2) return true...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } long long cnt = 0; while (m--) { long long x, y, z; cin >> x; if (x == 3) { cin >> y; cout << arr[y - 1] + cnt << "\n"; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<pair<int, int> > G[N]; vector<int> com; bool vis[N]; int U, V; void dfs1(int u) { com.push_back(u); vis[u] = true; for (auto &x : G[u]) { if (x.second) { U = u; V = x.first; } if (vis[x.first]) continue; dfs1(x....
14
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a % mod; b >>= 1; a = a * a % mod; } return res; } long long inv(long long x) { return power(x, mod - 2); } long long gcd(long long...
12
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adjlist; vector<int> visited; int depth[1000000], par[1000000], arr[1000000], tin[1000000], tout[1000000]; int y = 0; void dfs(int s) { tin[s] = y; y++; visited[s] = 1; for (int i = 0; i < adjlist[s].size(); i++) { int v = adjlist[s][i]; ...
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5, mod = 1e9 + 7, Log = 21; vector<int> adj[N]; int label[N], memo[N][Log], depth[N], fact[N]; int firstEdge[N], lastEdge[N]; map<int, int> nextEdge[N], prevEdge[N]; void dfs(int node, int prev, int Depth) { depth[node] = Depth; memo[node][0] = prev;...
25
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; v.push_back(0); for (int i = 0; i < 3; i++) { int y; cin >> y; v.push_back(y); } if (v[1] == v[2] && v[2] == v[3]) { if (v[1] % 2 == 0) { cout << v[1] / 2 << " " << v[2] / 2 << " " << v[3] / 2; return 0; ...
4
#include <bits/stdc++.h> using namespace std; int cbit(int n) { int cc = 0; while (n) { cc++; n >>= 1; } return cc; } int n, t1, t2; int main(void) { ios_base::sync_with_stdio(0); cin >> n; vector<int> v(n + 1, -1); long long t3 = 0; for (int i = n; i >= 0; i--) { if (v[i] != -1) continue;...
9
#include <bits/stdc++.h> using namespace std; template <typename T> void _dbg(char const *s, const T &t) { cout << s << "=" << t << endl; } template <typename T, typename... TA> void _dbg(char const *s, const T &t, const TA &...ta) { while (*s != ',') cout << *s++; cout << "=" << t << ","; _dbg(s + 1, ta...); }...
10
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string a[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; string aa[] = {"V", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "...
2
#include <bits/stdc++.h> using namespace std; long long int n, m, k; long long int MOD = 10000000007; int ql, qr; long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } long long int exGcd(long long int a, long long int b, long long int& x, long long int& y) { ...
10
#include <bits/stdc++.h> long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long countDivisor(long long n) { long long divisor = 0; for (long long i = 1; i * i <= n; i++) { if (i * i == n) divisor += 1; else if (n % i == 0) divisor += 2; } return divisor; } i...
13
#include <bits/stdc++.h> using namespace std; vector<int> ans, pr; int lp[10000]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 2; i <= n; ++i) { if (lp[i] == 0) { lp[i] = i; pr.push_back(i); } for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <...
7
#include <bits/stdc++.h> int mod = 1000000007; using namespace std; bool isp(long long x) { for (long long i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; } void pog() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; } bool sortinrev(const pair<long long, long long> &a, ...
2
#include <bits/stdc++.h> using namespace std; const int N = 75, M = 17, inf = 0x3f3f3f3f; int read() { int f = 1, g = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) g = g * 10 + ch - '0'; return f * g; } int n, m, cnt, bel[N], h[N], ...
22
#include <bits/stdc++.h> int main() { long long n, m; std::cin >> n >> m; std::map<long long, int> count; std::set<long long> bs; long long bsum = 0; long long maxb = -1; for (int i = 0; i < n; i++) { long long num; std::cin >> num; bs.insert(num); if (count.find(num) == count.end()) count...
7
#include <bits/stdc++.h> using namespace std; const unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); mt19937 rnd(seed); const int MOD = 998244353; long long getScore(long long aa, long long bb) { return aa - 3 * bb * bb - 3 * bb; } void solve() { long long n, k; cin >> n >> k; ve...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int arr[maxn]; int arr1[maxn]; void solve() { int n; scanf("%d", &n); for (int i = 0; i <= n - 1; i++) { scanf("%d", &arr[i]); } for (int i = 0; i <= n - 1; i++) { scanf("%d", &arr1[i]); } sort(arr, arr + n, greater<int>()); ...
5
#include <bits/stdc++.h> using namespace std; vector<int> E[200000]; vector<long long> W[200000]; long long low_dist[200000], max_dist[200000]; int n; pair<long long, long long> best(pair<long long, long long> a, long long x) { if (x >= a.first) return pair<long long, long long>(x, a.first); return pair<long long, ...
20
#include <bits/stdc++.h> using namespace std; int n, m, ans; bool flag; int a, b, w1, w2, l, used[7]; int main() { cin >> n >> m; --n; --m; int k = n; if (!k) w1 = 1; while (k) { k /= 7; ++w1; } k = m; if (!k) w2 = 1; while (k) { k /= 7; ++w2; } if (w1 + w2 > 7) printf("0"); ...
9
#include <bits/stdc++.h> using namespace std; const int N = 27; int n, m, a[N], sum[4096], cnt, onecnt; bool dp[2][4096][N]; int main() { scanf("%d", &n); for (int i = (1), iE = (n); i <= iE; i++) { scanf("%d", &a[i]); if (a[i] > 1) a[++cnt] = a[i]; else onecnt++; } if (cnt * 2 + 1 > n) ...
15
#include <bits/stdc++.h> using namespace std; bool check(long long a[], long long b[], long long c) { long long d = c; for (long long i = 0; i < 26; i++) { if (a[i] < b[i]) { if (d < (b[i] - a[i])) return false; else d -= (b[i] - a[i]); } if (a[i] > b[i]) return false; } ...
7
#include <bits/stdc++.h> using namespace std; int sum_array(vector<int>& a) { int sum = 0; for (int i = 0; i < a.size(); i++) { sum += a[i]; } return sum; } int main() { int t; cin >> t; while (t--) { int n, x, a, b, temp; cin >> n >> x >> a >> b; temp = a; if (b > a) { a = b; ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t, s, q; cin >> t >> s >> q; int ans = 1, curPos = 0, reset = 0; while (curPos < t) { ++curPos, ++reset; s += (reset > 1); if (curPos > s) { ++ans, curPos = 1; } ...
7
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { unsigned int t, i, k; cin >> t; unsigned long long n, j, count; for (i = 0; i < t; i++) { cin >> n; if (n % 2 == 0) { cout << (n * 4) + 1 << endl; } else { if ((n - 1) % 4 == 0) cout << n * 2 + 1 << e...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; void solve() { int n; string s; cin >> n >> s; vector<int> last[2]; vector<int> ans(n); int now = 0; for (int i = 0; i < n; i++) { int cur = s[i] - '0'; if (last[cur ^ 1].empty()) { ans[i] = ++now; ...
7
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > val; int n; struct bit { int b[200010]; bit() { memset(b, 0, sizeof b); } int query(int pos) { int maximo = -1; for (int i = pos; i > 0; i -= (i & (-i))) maximo = max(maximo, b[i]); return maximo; } void update(int p...
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int i, j, k; int n; cin >> n; string s1, s2; cin >> s1 >> s2; for (i = 0; i < n; i++) { if (s1[i] != s2[i]) break; } for (j = n - 1; j >= i; j--) { if (s1[j] != s2[j]) break; } int ans = 0; if (i == j...
10
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int P = 3; int pow(int a, int k) { if (k == 0) return 1; if (k == 1) return a; long long res = pow(a, k / 2); res = res * res % mod; if (k & 1) res = res * a % mod; return res; } void ntt(vector<int> &v, int inv = 0) { int n = ...
17
#include <bits/stdc++.h> using namespace std; int x[33], y[33], n, m, k, X, Y, L; char s[1003], a[103][103]; int main() { scanf("%d%d%d", &n, &m, &k); for (int j, i = 1; i <= n; i++) for (scanf("%s", a[i] + 1), j = 1; j <= m; j++) if (isalpha(a[i][j])) x[a[i][j] - 'a'] = i, y[a[i][j] - 'a'] = j, a...
15
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T x) { cout << x << "\n"; } template <typename T1, typename T2> void print2(T1 x, T2 y) { cout << x << " " << y << "\n"; } template <typename T1, typename T2, typename T3> void print3(T1 x, T2 y, T3 z) { cout << x << " " << y << " " <<...
2
#include <bits/stdc++.h> int main() { int n, i, f; scanf("%d", &n); i = n / 3; n -= i * 3; if (n == 2) i++; f = i / 12; i -= f * 12; printf("%d %d\n", f, i); }
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; long long int cnt = 0, zeros = 0, ones = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '?') cnt++; else if (s[i] == '0') zeros++; else if (s[i] == '1'...
11
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, pos, count = 0, countr = 0; cin >> n; int arr[n]; for (int i = 1; i <= n; i++) { cin >> pos; arr[pos] = i; } cin >> m; for (int i = 0; i < m; i++) { cin >> pos; count += arr[pos]; countr += (n - (arr[pos] - 1));...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1000000], i, j, k, flag; while (scanf("%d", &n) == 1) { flag = 0; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); for (i = n - 1; i >= 2; i--) { j = i - 1, k = i - 2; if (a[k] + a[j] > a[i]) { ...
2
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
13
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; long long x; int main() { ios_base::sync_with_stdio(0); scanf("%I64d", &x); int dif = INF, ans = -1; for (int i = 0; i < 4; ++i) { int y = ((x - 90 *...
10
#include <bits/stdc++.h> using namespace std; int N, M, T; int ini[100001][11]; struct node { int pre[24]; int cnt; } s[400001]; inline int find(int x, int* fa) { for (; x != fa[x]; x = fa[x]) ; return x; } inline void upload(node& L, node& R, node& res, int pos) { res.cnt = L.cnt + R.cnt; int id[50] = ...
18
#include <bits/stdc++.h> using namespace std; int arr[100005][2]; int main() { int n, neg = 0, pos = 0; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { cin >> arr[i][j]; } if (arr[i][0] > 0) pos++; else neg++; } if (pos == 1 || neg == 1) cout << "Yes...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int dep[N]; struct Node { int x, t, id; Node() {} void input() { scanf("%d%d", &x, &t); } bool operator<(const Node &a) const { if (t + dep[x] == a.t + dep[a.x]) return x < a.x; return t + dep[x] < a.t + dep[a.x]; } } Q[N]; int n, m...
25
#include <bits/stdc++.h> using namespace std; int main() { int x, arr[1000], count = 0; cin >> x; for (int i = 0; i < x; i++) { cin >> arr[i]; } sort(arr, arr + x); for (int i = 0; i < x; i++) { if (arr[i] == arr[i + 1]) { arr[i] = 0; } } sort(arr, arr + x); for (int i = 0; i < x - 1...
1
#include <bits/stdc++.h> using namespace std; long long int i, j, k, n, ans; bool check[100000000]; long long int a[10000], b[10000]; int main() { cin >> n; memset(check, false, sizeof(check)); for (i = 0; i < n; i++) { cin >> a[i]; check[a[i]] = true; } for (i = 0; i < n; i++) { cin >> b[i]; ...
3
#include <bits/stdc++.h> using namespace std; const int bit = 100; unsigned long long n, sum, len; int main() { scanf("%llu", &n); sum = 45 * bit; for (int i = 1; i <= bit - 1; i++) sum = sum * 2 % n * 5 % n; sum = n - sum - 1; len = sum == 0 ? 1 : log10(sum) + 1; printf("%llu ", sum + 1); printf("1"); ...
17
#include <bits/stdc++.h> using namespace std; struct Fenwick { vector<long long> BIT; long long N; Fenwick(long long n) { N = n + 2; BIT.resize(N + 10); } void reset() { for (long long i = 0; i <= N; i++) { BIT[i] = 0; } } void add(long long r, long long value) { for (long long i...
15
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; const long long linf = 1000000000000000000LL; typedef struct { int dia, mes, ano; } data; vector<data> vetor; string linha, str; map<int, int> mapa; int main() { cin >> linha; int s = linha.size(); data d; for (int i = int(0); i <= int(...
8
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { long long n; while (~scanf("%lld", &n)) { while (n % 3 == 0) n /= 3; printf("%lld\n", n / 3 + 1); } return 0; }
8
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int mod = 1e9 + 7; int n, t[105], w[105], st[105], sw[105], second[205], u[205]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> t[i] >> w[i]; st[i] = st[i - 1] + t[i]; sw[...
9
#include <bits/stdc++.h> using namespace std; int n; double ans[100004], len[100004], add[100004], p[100004]; int main() { int i; while (scanf("%d%*c", &n) != EOF) { for (i = 1; i <= n; ++i) { scanf("%lf%*c", &p[i]); len[i] = (len[i - 1] + 1) * p[i]; add[i] = (len[i - 1] * 2 + 1) * p[i]; ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int z; cin >> z; while (z--) { string a; cin >> a; sort(a.begin(), a.end()); bool cek = false; for (int q = 0, w = a.size() - 1; q <= w; q++, w--) { if (a[q] ...
1
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int maxn = 1e5 + 100; vector<pair<int, int> > point; int n; int main() { cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; point.push_back(make_pair(x, y)); } int ans = 0; for (int i = 0; i < n; i++) { bool...
2
#include <bits/stdc++.h> using namespace std; const signed int MAX = 4000 + 5; const signed int INF = 1e9; bool grid[MAX][MAX]; vector<pair<signed int, signed int> > edge; signed int deg[MAX]; signed int main() { signed int n; signed int m; scanf("%d %d", &n, &m); signed int first, second; for (signed int i =...
7
#include <bits/stdc++.h> using namespace std; double dp[1500][150], dp2[1500][150]; int sm[1500], lg[1500]; double m[150][150]; int M[1500]; double tmp[150]; int main() { int t = 1; while (t--) { int n; scanf("%d", &n); int p; p = pow(2, n); n = p; for (int i = 1; i < n + 1; i++) { for...
13
#include <bits/stdc++.h> using namespace std; const int N = 2010; const int mod = 1000003; char s[N]; int nxt[N]; long long dp[N][N]; long long solve(int b, int e) { if (dp[b][e] >= 0) return dp[b][e]; if (b == e) return 0; dp[b][e] = 0; if (s[b] == '/' || s[b] == '*') return dp[b][e]; bool seen = 0; if (s[...
18
#include <bits/stdc++.h> int main() { int n, m, a; scanf("%d %d", &n, &m); if (n < m) { if (n % 2 == 0) printf("Malvika"); else printf("Akshat"); } else { if (m % 2 == 0) printf("Malvika"); else printf("Akshat"); } }
1
#include <bits/stdc++.h> using namespace std; const int MAX = 1e3 + 5; int n, m; char grid[MAX][MAX]; bool visited[MAX][MAX]; int memo[MAX][MAX]; bool EH_NOIS = false; inline bool inside(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; } inline char nxt(char c) { if (c == 'D') return 'I'; if (c == 'I'...
11
#include <bits/stdc++.h> long long min(long long a, long long b) { return a < b ? a : b; } int oo[1 + 500000 - 1], oj[1 + 500000 - 1]; int link(int o, int j) { static int _ = 1; oo[_] = o, oj[_] = j; return _++; } int aa[500000], ae[500000], stack[500000]; long long ans; void dfs(int i, int d) { int o; stack[...
20
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int x, y; cin >> x >> y; int a, b; cin >> a >> b; int r = y - x; if (r % (a + b) != 0) { cout << -1 << '\n'; continue; ...
0
#include <bits/stdc++.h> using namespace std; int n, k; long long x = 0; int a[100001], b[100001]; void czytaj() { cin >> n >> k; for (int i = 1; i <= n / k; i++) cin >> a[i]; for (int i = 1; i <= n / k; i++) cin >> b[i]; } long long pot(long long D, long long d) { int z = 1; while (d--) z = z * D; return z...
8
#include <bits/stdc++.h> using namespace std; int n, k, q, ans[1005], p; double dp[10 * 1005][1005]; int main(void) { scanf("%d%d", &n, &q); dp[0][0] = 1; for (int i = 1; i < 10 * 1005; ++i) { dp[i][0] = 0; for (int j = 1; j <= n; ++j) dp[i][j] = (dp[i - 1][j - 1] * (n - j + 1) + dp[i - 1][j] * j) /...
14
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 5]; for (int i = 1; i <= n; i++) { cin >> a[i]; } int x, f = 0, s = 0; for (int i = 1; i <= n; i++) { if (a[i] > 1) { x = i; if (x % 2 == 0) ...
3
#include <bits/stdc++.h> using namespace std; long long in() { long long a; scanf("%lld", &a); return a; } double din() { double a; scanf("%lf", &a); return a; } long long bigmod(long long b, long long p, long long md) { if (p == 0) return 1; if (p % 2 == 1) { return ((b % md) * bigmod(b, p - 1, md)...
6
#include <bits/stdc++.h> using namespace std; inline long long C(int n, int m) { long long re = 1; for (int i = 0; i < m; ++i) re *= (n - i); for (int i = 1; i <= m; ++i) re /= i; return re; } inline long long divide(int n, int m) { return C(n + m - 1, m - 1); } long long pre[300010]; int main() { long long a...
13
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; double eps = 1e-8; int head[1100000], vet[1100000], nxt[1100000], q[1100000], inq[1100000], ind[1100000], stk[1100000], a[1100000], ans[1100000], tot; int read() { int v = 0, f = 1; char c = getchar(); while (c < 48 || 57 < c) { if (...
13
#include <bits/stdc++.h> using namespace std; int a[101000]; int ac[101000]; int b[101000]; int bc[101000]; pair<int, pair<bool, int> > all[201000]; int allc; int n, m; inline int val(const pair<int, int>& a) { int x = a.first, y = a.second; if (all[x].second.first == 0) { return ((m - 1 - all[y].first) + all[x...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; long long c[maxn][maxn], f[10] = {1, 0, 1, 2, 9}, ans; int main() { long long n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { c[0][i] = 1; c[i][0] = 1; c[i][i] = 1; } for (int i = 1; i <= n; i++) for (int j = 0; j <=...
8
#include <bits/stdc++.h> using namespace std; const int Nmax = 112; int n, m, a[Nmax][Nmax], b[Nmax][Nmax], c[Nmax][Nmax]; bool check() { for (int i = (int)1; i <= (int)n; ++i) for (int j = (int)1; j <= (int)m; ++j) { if (c[i][j] <= c[i - 1][j] || c[i][j] <= c[i][j - 1]) return false; } return true; }...
6
#include <bits/stdc++.h> using namespace std; int pow1(int x, int y) { int i; long long ans; ans = 1; for (i = 30; i >= 0; i--) { ans = ans * ans % 1000000009; if (((1 << i) & y) != 0) ans = ans * x % 1000000009; } return (int)ans; } int main() { int n, m, k, tmp; int ans; scanf("%d%d%d", &n, ...
8
#include <bits/stdc++.h> #define LLI long long #define umap unordered_map #define uset unordered_set #define all(v) v.begin(),v.end() #define loop_arr(arr, n) for (LLI i=0;i<n;i++) {cin >> arr[i];} #define loop_vec(arr, n) for (LLI i=0;i<n;i++) {cin >> arr[i];} #define loop_print(arr) for (const auto &i: arr) { cout <<...
9
#include <bits/stdc++.h> using namespace std; bool P(string x) { int i = 0, j = x.size() - 1; while (i <= j) { if (x[i] != x[j]) return false; i++; j--; } return true; } int main() { int t; string x; cin >> t; while (t--) { cin >> x; int flag = 0; for (int i = 0; i < x.size(); i+...
1
#include <bits/stdc++.h> using namespace std; const int N = 201000; const long long inf = (1LL << 55); int n, x[N], p[N]; long long dt[N][2]; long long d[N][3]; vector<int> v[N]; void calc(int nod) { vector<int>::iterator it; int i; if (!v[nod].size()) { d[nod][0] = x[nod]; d[nod][1] = 0; d[nod][2] = ...
12
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:640000000") using namespace std; const int INF = (int)(1e9); const long long INF64 = (long long)(INF) * (long long)(INF); const double eps = 1e-9; const double pi = double(3.1415926535897932384626433832795); inline bool in(int i, int j, int n, int m) { return i...
10