solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; int n, l; string s; vector<long long> u; long long syma(int i) { return (2 * n - l - 1 - i); } long long symb(int i) { return (n - 1 - i); } long long f(int i) { u[i] = 1; int c = 0; vector<vector<long long> > dp(2, vector<long long>(2, 0));...
16
#include <bits/stdc++.h> using namespace std; int read() { int ret = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') { ret = ret * 10 + c - '0'; c = getchar(); } return 0; } const int MAXN = 100000; const int Mod = 1000000007; int dis[MAXN + 10]; int f[M...
12
#include <bits/stdc++.h> #pragma GCC optimize(1) #pragma GCC optimize(2) #pragma GCC optimize(3) using namespace std; int n, m, maxv, valx, ww; char res[10][10], ans[10][10]; char figure[4][3][3] = {{{'#', '#', '#'}, {'.', '#', '.'}, {'.', '#', '.'}}, {{'.', '#', '.'}, {'.', '#', '.'}, {'#', '#'...
15
#include <bits/stdc++.h> using namespace std; set<int> v[200005]; bool vis[200005]; int count1[200005]; int u, k; int c = 1, ans; int no[200005]; int yes[200005]; void dfs(int u) { count1[u] = 1; no[u] = c; yes[c] = u; vis[u] = true; for (auto it = v[u].begin(); it != v[u].end(); it++) { if (!vis[*it]) { ...
8
#include <bits/stdc++.h> using namespace std; int p[55], t[55]; int ans1, ans2, z1, z2; int main() { int n, c; cin >> n >> c; for (int i = 0; i < n; i++) { cin >> p[i]; } for (int i = 0; i < n; i++) { cin >> t[i]; } for (int i = 0; i < n; i++) { z1 += t[i]; ans1 += max(0, p[i] - (c * z1));...
0
#include <bits/stdc++.h> using namespace std; long long v[100005]; void init() { for (long long i = 0; i <= 1e5 + 1; i++) v[i] = i * i * i; } pair<int, long long> dfs(long long m) { if (m == 0) return pair<int, long long>(0, 0); int a = 1; while (v[a] <= m) a++; a--; pair<int, long long> t1 = dfs(m - v[a]),...
14
#include <bits/stdc++.h> using namespace std; int n, m, i, j, a[111111], b[111111], c; int main() { cin >> n >> m >> c; for (i = 0; i < n; i++) cin >> a[i]; cin >> b[0]; for (j = 1; j < m; j++) { cin >> b[j]; b[j] += b[j - 1]; } for (i = 0; i < m; i++) a[i] += b[i]; for (i = m; i < n; i++) a[i] +=...
4
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B; cin >> N >> A >> B; string x; cin >> x; if (x[A - 1] == x[B - 1]) cout << 0 << "\n"; else { cout << 1 << "\n"; } }
4
#include <bits/stdc++.h> using namespace std; int l1, l2, d, n, m, i, j, k, ma; string s1, s2; char c[100005]; map<long long, bool> M; long long X; bool f(int L) { for (j = 0; j < L; j++) if (s1[j] != s2[j]) return 0; for (k = 1; (k * L + L) <= l1; k++) for (j = 0; j < L; j++) if (s1[k * L + j] != s1[...
6
#include <bits/stdc++.h> using namespace std; const long long R = 998244353; long long n, i, ans, b; vector<long long> v(31), y; int main() { cin >> n; n *= 2; long long a[n + 5]; for (i = 0; i < n; i++) { cin >> a[i]; } b = 1; sort(a, a + n); for (i = 0; i < n; i++) { if (i < n / 2) ans -...
11
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); map<long long, long long> m; int n, x; cin >> n; for (int i = -10; i < 11; ++i) { m[i] = 0; } long long ans = 0; for (int i = 0; i < n; ++i) { cin >> x; m[x]...
4
#include<bits/stdc++.h> using namespace std; const int N = 2000006; long long a[N]; long long b[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--){ long long n; cin>>n; long long cnt = 0; long long ans = 0; for(long long i=1;i<=n;i++){ cin>>a[i]; //...
9
#include <bits/stdc++.h> using namespace std; int main() { int a[6], s1, s2, s3, s4, num = 0; for (int ii = 0; ii < 6; ++ii) { cin >> a[ii]; } int i = 1; s2 = a[1]; s3 = a[0] - a[2]; if (s3 > 0) { s1 = a[2]; s4 = a[5]; } else { s1 = a[0]; s4 = a[3]; s3 = -s3; } for (int ii = ...
8
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1e9; const int MOD = 1e9 + 7; const int M = INF; const double RRR = 180.0 / PI; const long double EPS = 1e-8; int n, s; vector<int> x, y, k; int main() { double TIME_START = clock(); cin >> n >> s; x.resize(n); y.resize(...
4
#include <bits/stdc++.h> using namespace std; int n, m; int mp[411][411]; int dis1[411]; int dis2[411]; bool cover[411]; int main() { int i, j, k; int xx, yy; scanf("%d %d", &n, &m); memset(mp, 0, sizeof(mp)); for (i = 1; i <= m; i++) { scanf("%d %d", &xx, &yy); mp[xx][yy] = mp[yy][xx] = 1; } mems...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; if (n & 1) return cout << -1, 0; for (int i = 1; i <= n; i += 2) cout << i + 1 << ' ' << i << ' '; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s[n]; for (int i = 0; i < n; i++) cin >> s[i]; multiset<pair<int, int> > imposs; multiset<int> poss; for (auto &x : s) { int prefs = 0; int mins = 0; int flag = 0; ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int base = 31337; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const int logo = 20; const int off = 1 << logo; const int treesiz = off << 1; int n; int niz[maxn]; int pc[maxn]; vector<int> graph[maxn]; vector<int> v[maxn]; bool bio[m...
16
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int w = 1, c = 0; for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) c = (c << 1) + (c << 3) + (ch ^ 48); return w * c; } const int M = 2e5 + 10; struct pv { long long x, y...
24
#include <cstdio> #include <set> using namespace std; const int maxn = 200010; set<int> S; int b[maxn]; int main() { int t; scanf("%d", &t); int n; bool ans; set<int>::iterator cur; while (t--) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", b + i); ans = tr...
12
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; const int M = 100000 + 10; const int MOD = 1e9 + 7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t, n, m, k, p, l, r, u, v; int ans, cnt, flag, temp, sum; int save[N]; vector<int> g[N]; int cal(int x) { ...
13
#include <bits/stdc++.h> using namespace std; const int N = 50, mod = (int)1e9 + 7; int n, m, k; int mp[N][N], path[N][N]; long long C[N][N]; long long fac[N]; int to[N]; int at[N][N]; int used[N]; int cts[(1 << 20)]; long long res = 0; int vis[N], ccolor = 0; void dfs(int x, int y, int cntc) { if (y > m) y -= m, x +...
19
#include <bits/stdc++.h> using namespace std; int n, m, sum[100011]; struct data { int id, val; } a[100011], srt[19][100011]; struct node { int x; long long y; int id; node() {} node(int a, long long b, int c) { x = a; y = b; id = c; } inline long long plot(node a, node b) { return (b.y ...
21
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 10; int n, k, m, y[310]; long double h[310][1235]; int main() { scanf("%d%d", &n, &k); m = 1234; long double la = 0, res; for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) scanf("%d", y + j); res = 0; for (int j = 0; j < k; ...
17
#include <bits/stdc++.h> int main(int argc, const char* argv[]) { int n; std::cin >> n; std::priority_queue<long long, std::vector<long long>, std::greater<long long>> queue; for (int i = 0; i < n; i++) { long long k; std::cin >> k; queue.push(k); } if (n % 2 == 0) qu...
15
#include <bits/stdc++.h> using namespace std; int t; int x, y, a, b; int main() { scanf("%d", &t); while (t--) { scanf("%d %d %d %d", &x, &y, &a, &b); printf("%lld\n", 1ll * (1ll * min(2 * a, b) * min(x, y) + 1ll * a * abs(x - y))); } }
2
#include <bits/stdc++.h> using namespace std; int a[350][350]; int dp[305][305][305 * 2 + 5]; int main() { int n; while (~scanf("%d", &n)) { for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= 2 * n; k++) { dp[i][j][k] = -0x3f3f3f3f; } } }...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; bool check(vector<int> seq, int diff) { int n = (int)seq.size(); assert(1 <= n && n <= 2000); for (int x : seq) assert(abs(x) <= 1000000); ll res = 0, cur = 0, k = -1; for (int i = 0; i < n; i++) { cur += seq[i]; if (cur < 0) { ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, a = 0, b = 0; cin >> n; string s; cin >> s; for (i = 0; i < n; i++) { if (s[i] == '0') a++; else b++; } if (a == b) { cout << 2 << endl; for (i = 0; i < n - 1; i++) cout << s[i]; cout << " " << s...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 500000; const int SUPERN = 5000000; const int MAXS = 325; const int SUPERS = 1000; const int MD = 1e9 + 7; long long s, g, rt, x, dp[60][200][2], v, re; long long sum(long long a, long long b) { return (a + b) % MD; } long long mu(long long a, long long b) ...
24
#include <bits/stdc++.h> using namespace std; string str, pat; int n, p; long long dp[2234][2234]; long long pos[1234567]; long long recur(int ind, int num) { if (ind == 0) { if (num == 0) return 0; return -123456789; } if (dp[ind][num] != -1) return dp[ind][num]; long long ans = -123456789; if (num >...
14
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int l, r; cin >> l >> r; int h = max(2 * l, r + 1); if ((l % h) >= ((h + 1) / 2)) cout << "YES\n"; else cout << "NO\n"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int N; const int MAXN = 5e4 + 15; int X[MAXN], Y[MAXN], Z[MAXN]; int XX[MAXN], YY[MAXN], ZZ[MAXN]; vector<pair<pair<int, int>, int> > P[MAXN]; int V[MAXN]; int main() { ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; ++i) { cin >> X[i] >> Y[i] >> Z[i...
9
//#include <bits/stdc++.h> #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> #define ll long long #define LL long long ...
0
#include <bits/stdc++.h> using namespace std; int n, g[15], cnt; char s[5]; vector<pair<int, int> > v; int getid(char c) { if (isdigit(c)) return c - '1'; if (c == 'R') return 5; if (c == 'G') return 6; if (c == 'B') return 7; if (c == 'Y') return 8; if (c == 'W') return 9; } bool check(int s) { int t[15]...
9
#include <bits/stdc++.h> using namespace std; const int N = 500043; vector<int> g[N]; vector<int> t[N]; int tin[N], tout[N], fup[N]; int p[N]; int T = 1; int rnk[N]; vector<pair<int, int>> bridges; int st; int d[N]; int n, m; int get(int x) { if (p[x] == x) return x; else return p[x] = get(p[x]); } void lin...
13
#include <bits/stdc++.h> using namespace std; const int N = 2005; const double eps = 1e-10; double f[N][N], p[N], u[N], t[N]; int cnt[N][N], n, a, b; inline int check(double k) { for (int i = 1; i <= n; ++i) { for (int j = 0; j <= a; ++j) { f[i][j] = f[i - 1][j]; cnt[i][j] = cnt[i - 1][j]; if (j...
22
#include <bits/stdc++.h> using namespace std; int n, ans = 0, c[30]; string s; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> s; c[int(s[0]) - 96]++; } for (int i = 1; i <= 27; i++) { int m = c[i]; ans += m / 2 * (m / 2 - 1) / 2 + (m / 2 + m % 2) * (m / 2 + m % 2 - 1) / 2; } co...
1
#include <bits/stdc++.h> using namespace std; long long l, r; void readInput() { cin >> l >> r; } void solve() { if (l == r) cout << 0 << endl; else cout << (1ll << (63 - __builtin_clzll(l ^ r)) + 1) - 1 << endl; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); readInput(), solve(); re...
9
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 300000; int n; int a[N + 2], pos[N + 1]; struct segtree { struct node { int l, r, mn1, mn2, cnt1, cnt2, lz; } nd[N << 2]; void sprup(int p) { int s[] = {nd[p << 1].mn1, nd[p << 1].mn2, nd[p << 1 | 1].mn1, ...
21
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> ar(n); for (auto &i : ar) cin >> i; vector<vector<int> > pos(n); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (ar[i] > ar[j]) pos[j].push_back(i...
17
#include <bits/stdc++.h> using namespace std; static const double PI = 2 * acos(0); int main() { ios::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; int lo = 1, hi = N; while (lo < hi) { int mid1 = (lo + hi) / 2; int mid2 = mid1 + 1; cout << 1 << " " << mid1 << " " << mid2 << endl;...
14
#include <bits/stdc++.h> using namespace std; int dp[4][10000007]; int main() { dp[0][0] = 1; int n; cin >> n; for (int i = 1; i <= n; ++i) for (int j = 0; j < 4; ++j) for (int k = 0; k < 4; ++k) if (j != k) { int &ans = dp[j][i]; ans += dp[k][i - 1]; if (ans >= 1...
7
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long n, m, si; vector<long long> g[100010], s; long long dep[100010]; bool mar[100010]; void dfs(long long p) { s.push_back(p); dep[p] = s.size(); for (long long i : g[p])...
13
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; #define F first #define S second const int MOD = 1e9 + 7;//XXX const int C = 26;//XXX void add(int &x, int y){ x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x)...
8
#include <bits/stdc++.h> int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); } long long lcm(long long x, long long y) { return ((x / gcd(x, y) * y)); } using namespace std; void fast() { ios_base::sync_with_stdio(f...
5
#include <bits/stdc++.h> using namespace std; const int M = INT_MAX; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int h(char c) { if (c >= 'a' && c <= 'z') return c - 'a' + 1; if (c >= 'A' && c <= 'Z...
12
#include <bits/stdc++.h> using namespace std; long block_size; bool comp(vector<long> a, vector<long> b) { if ((a[0] / block_size) == (b[0] / block_size)) return (a[1] < b[1]); return (a[0] < b[0]); } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); long n, m, s = 0; cin >> n >> m; bl...
10
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cout << v << " "; return *this; } } dbg; int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; int dy[] = {0, 0, 1, -1, -1, 1, -1, 1}; int a[111]; int main() { int t = 0, z = 0, len; int n = 0, k ...
1
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << '=' << h << '\n'; } template <typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, t...); } ...
15
#include <bits/stdc++.h> using namespace std; int N; long long arr[100005], r, l, ans; int main() { cin >> N; for (int i = 0; i < N; i++) cin >> arr[i]; sort(arr, arr + N); l = r = 0; ans = r = accumulate(arr, arr + N, r); for (int i = 0; i < N; i++) { r -= arr[i]; l += arr[i]; ans = min(ans, ab...
3
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e5 + 5, MOD = 1e9 + 7; long long dp[2][3]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, l, r; cin >> n >> l >> r; int m[3]; int prev = 0, cur = 1; for (int i = 0; i < 3; ++i) { int a = ceil((l - i) / 3.0); int...
7
#include <bits/stdc++.h> using namespace std; struct node { long long r1; long long r2; } dis[2005]; bool cmp(node a, node b) { return a.r1 < b.r1; } long long dp[2005]; int main() { long long n, x1, y1, x2, y2; scanf("%lld %lld %lld %lld %lld", &n, &x1, &y1, &x2, &y2); for (register int i = 1; i <= n; i++) {...
8
#include <bits/stdc++.h> using namespace std; vector<int> a, b; struct trie { trie *f[2]; int sz; trie() { memset(f, 0, sizeof f); sz = 0; } void add(int val, int with) { auto *t = this; for (int i = 29; i >= 0; --i) { bool dir = val & (1 << i); if (!t->f[dir]) { t->f[dir] ...
10
#include <bits/stdc++.h> using namespace std; int holes[100010]; int main() { int n, b, a, i, suma = 0, first, cnt = 0; scanf("%d%d%d", &n, &b, &a); for (i = 1; i <= n; i++) { scanf("%d", &holes[i]); suma += holes[i]; } first = holes[1]; sort(holes + 2, holes + n + 1); for (i = n; i > 1; i--) { ...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; bool comp(pair<long long int, int> &a, pair<long long int, int> &b) { return a.first > b.first; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int n, m; cin >> n >> m; long long int arr[n...
12
#include <bits/stdc++.h> using namespace std; const long long P = 1000000007; int n, p[1004]; long long f[1004]; int main() { int i; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &p[i]); f[1] = 0; for (i = 1; i <= n; i++) f[i + 1] = (f[i] + f[i] - f[p[i]] + P + 2) % P; printf("%I64d\n", f[n + 1]); ...
8
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int gcd(int a, int b) { if (b) return gcd(b, a % b); return a; } int func1(int a, int b) { return ((a * b) << 2) - ((a + b) << 1) - (gcd(a, b) << 1); } int func2(int a, int b) { return ((a * b) << 1) - (gcd(a, b) << 1); } int func3(int a, int ...
17
#include <bits/stdc++.h> using namespace std; int A[100005], B[100005]; int main() { int i, j, k, m, n; while (~scanf("%d", &n)) { memset(B, 0, sizeof(B)); for (i = 1; i <= n; i++) scanf("%d", &A[i]); for (i = 1; i <= n; i++) { m = min(A[i - 1], A[i + 1]); m = min(m + 1, A[i]); m = min...
8
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15; signed main() { long long i, n, type, tec_speed, obg = 0, max_speed = inf; cin >> n >> type >> tec_speed; stack<long long> speeds; speeds.push(inf); long long ans = 0; for (i = 1; i < n; i++) { cin >> type; if (type == 1) { ...
10
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; const long long MAX = 1e5 + 5; vector<pair<long long, long long> > ans; vector<long long> even; bool O[MAX]; bool prime(long long i) { for (long long j = 2; j * j <= i; j++)...
17
#include <bits/stdc++.h> using namespace std; string str; int main() { getline(cin, str); int len = str.length() - 1; while (!isalpha(str[len])) len--; if (str[len] == 'A' || str[len] == 'E' || str[len] == 'I' || str[len] == 'O' || str[len] == 'U' || str[len] == 'Y' || str[len] == 'a' || str[len] ==...
0
#include <bits/stdc++.h> using namespace std; int main() { string w; cin >> w; bool ch = 1; for (int i = 1; i < w.size(); i++) { if (w[i] > 92 && ch) { ch = !ch; break; } } if (ch) { for (int i = 0; i < w.size(); i++) { if (w[i] > 92) w[i] = (char)(w[i] - 32); els...
2
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383279502884197169399375105820974944; inline void io() {} const long long mod = 1e9 + 7; const long long maxn = 3e5 + 5; void solve() { long long n, k; cin >> n >> k; long long a[n]; map<long long, long long> mp; ...
7
#include <bits/stdc++.h> using namespace std; long long a, b, ans; int main() { cin >> a >> b; for (int i = 2; i < 62; i++) { long long mask = (1LL << i) - 1; for (int j = 0; j < i - 1; j++) { long long tmp = mask ^ (1LL << j); if (tmp >= a && tmp <= b) ans++; } } cout << ans; }
5
#include <bits/stdc++.h> using namespace std; const int inf = 1000 * 1000 * 1000; int n, X1, Y1, X2, Y2; int main() { scanf("%d%d%d%d%d", &n, &X1, &Y1, &X2, &Y2); if (X1 == 0 && X2 == 0) { printf("%d", abs(Y1 - Y2)); return 0; } if (Y1 == 0 && Y2 == 0) { printf("%d", abs(X1 - X2)); return 0; }...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; vector<long long> a(n), b(n); set<long long> s; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < n; i++...
7
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #pragma GCC optimize("-Ofast") using namespace std; long long sf[+500500], pr[+500500], ans2, ans1, p, b[+500500], a[+500500], mid, n, i, B[+500500]; long long t[4 * +500500]; void upd(long long v, long long l, long long r, lo...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n; long long m, a[MAXN], inv[MAXN]; set<int> all; bool check(int x, int d) { for (int i = 0; i < n; i++) { if (!all.count((x + (long long)i * d) % m)) return false; } return true; } int main() { cin >> m >> n; for (int i = 0; i <...
18
#include <bits/stdc++.h> using namespace std; vector<int> ans(0); int main() { int a1, a2, h1, h2, c; scanf("%d%d%d%d%d", &h1, &a1, &c, &h2, &a2); while (1) { if (h2 - a1 > 0) { if (h1 - a2 > 0) { h2 -= a1; h1 -= a2; ans.push_back(1); } else { h1 += c - a2; ...
4
#include <bits/stdc++.h> using namespace std; long long a, b, w, x, c; long long solve() { if (c <= a) return 0; else { long long det = c - a; double upp = det * x - b; double dow = w - x; long long lam = (long long)ceil(upp / dow); return lam + det; } } int main() { scanf("%I64d%I64d%I6...
12
#include <bits/stdc++.h> using namespace std; int main() { int n1; cin >> n1; int *a = new int[n1]; for (int i = 0; i < n1; i++) { cin >> a[i]; } cout << abs(a[0] - a[1]) << " " << abs(a[0] - a[n1 - 1]) << endl; for (int i = 1; i < n1 - 1; i++) { int x1 = abs(a[i - 1] - a[i]); if (abs(a[i] - a...
1
#include <bits/stdc++.h> using namespace std; int read() { char c = getchar(); int t = 0, f = 1; while (c > '9' || c < '0') f = (f == '-') ? -1 : 1, c = getchar(); while (c >= '0' && c <= '9') t = t * 10 + c - '0', c = getchar(); return t * f; } int n, ans[100005], tp; int len(int x) { int ret = 0; while ...
4
#include <bits/stdc++.h> long long ans, x, y, n, a, s, kk; int num[9000000]; long long sum[10000000]; int main() { int j, k; long long i; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &num[i]); } std::sort(num + 1, num + n + 1); x = 0; for (i = n; i >= 1; i--) { x += num[i]; sum[n ...
11
#include <bits/stdc++.h> int fix(double x) { if (fabs(x) <= 1e-9) return 0; else if (x > 1e-9) return 1; else return -1; } int main() { double s; while (scanf("%lf", &s) != EOF) { double num[4]; double ans[4]; for (int i = 1; i <= 3; i++) scanf("%lf", &num[i]); num[0] = 0; for ...
10
#include <bits/stdc++.h> using namespace std; int n, q, a, b, v, d, x, t, mx; int l[200005]; int r[200005]; int z[200005]; vector<vector<int> > lbt; vector<int> e[200005]; void trv(int k, int f) { l[k] = l[f] + 1; z[r[k]] = l[k]; for (int i = 0, br = r[k]; i < e[k].size(); i++) { if (e[k][i] != f) { r[e...
13
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } const char lf = '\n'; namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *t ...
21
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; int n, m, ver[N * 6], nxt[N * 6], head[N], tot, la, col[N], num[3]; void add(int x, int y) { ver[++tot] = y; nxt[tot] = head[x]; head[x] = tot; } void f() { puts("-1"); exit(0); } int main() { scanf("%d%d", &n, &m); for (int i = 1, x, y...
11
#include <bits/stdc++.h> using namespace std; int print(int z[], int n) { for (int i = 0; i < n; i++) { if (z[i] == 0) { z[i] = 1; return i + 1; } } } int main() { int n, m; cin >> n >> m; int z[n]; for (int i = 0; i < n; i++) { z[i] = 0; } int a[m][2]; for (int i = 0; i < m; i...
7
#include <bits/stdc++.h> int main() { int n, d, e; std::cin >> n >> d >> e; int result = n - n / d * d; int dollars = n / d, euros = 0; while (dollars > -1) { while (dollars * d + 5 * euros * e <= n) { result = std::min(result, n - (dollars * d + 5 * euros * e)); euros++; } dollars--; ...
6
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ull unsigned long long #define pi 3.141592653589793238 #define lb lower_bound #define ub upper_bound #define rep(i,a,n) for(ll i=a;i<n;i++) #define For(i,a,n) for(ll i=a;i<=n;i++) const ll inf = 100000000000000000; const ...
6
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, e, f, g, h, i, d; cin >> a >> b >> c; e = a + b + c; f = 2 * (a + b); g = 2 * (b + c); h = 2 * (c + a); if (e < f) { i = e; } else { i = f; } if (g < h) { d = g; } else { d = h; } if (i < d) { cout << i...
0
#include <bits/stdc++.h> using namespace std; int main() { long long test = 1; cin >> test; while (test--) { long long n; cin >> n; vector<long long> v(n); for (long long i = 0; i < n; i++) { cin >> v[i]; } long long ans = 0, res = 0; map<long long, long long> mp; for (long l...
4
#include <bits/stdc++.h> using namespace std; int a[100005], f[100005]; int Q, n, m, T; int main() { scanf("%d%d%d%d", &Q, &n, &m, &T); T = min(min(n, m), T); for (; Q--;) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 0; i <= m; i++) f[i] = 0; for (int i = 1; i <= T; i++) for (...
18
#include <bits/stdc++.h> using namespace std; int main() { long long int i, n, x, cnt = 0; cin >> n >> x; for (i = n; i > 0; i--) { if (x % i == 0 && x <= n * i) cnt++; } cout << cnt; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { string j, p; cin >> j; int best = 0, i, k, g, a; for (i = 0; i < j.length() - 1; i++) { for (k = 1; k < j.length() - i; k++) { p = j.substr(i, k); a = 0; for (g = 0; g < j.length() - p.length() + 1; g++) { if (j.substr(g, p...
4
#include <bits/stdc++.h> using namespace std; long long n, m, k, x, y; long long ans1, ans2, ans3; long long num[110][110]; int main() { int i, j; scanf("%lld%lld%lld%lld%lld", &n, &m, &k, &x, &y); if (n == 1) { for (i = 1; i <= m; i++) { num[1][i] = k / m; } k = k % m; for (i = 1; i <= k; i...
9
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m; cin >> n >> m; long long a[n][m], b[n][m]; for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) cin >> a[i][j]; } for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) cin >> b[i][j]; } ...
7
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<int, int> > v; int x, y; int n; int total = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; v.push_back(make_pair(x, y)); } int cost = 0; for (int i = 0; i < v.size(); i++) { if (v[i].first != -1) { tota...
1
#include <bits/stdc++.h> using namespace std; int main() { char c; int n, k, dis = 0; cin >> n >> k; if (k == 2) { dis = n - 1; } else { if ((n % k) == 1) { dis = n / k * 2; } else if (n % k == 2) { dis = n / k * 2 + 1; } else { dis = (n - 1) / k * 2 + 2; } } cout << ...
10
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<pair<int, string>> input_array(n); for (int i = 0; i < n; i++) { cin >> input_array[i].first >> input_array[i].second; } int current_ = 0; for (int i = 0; i < n; i++) { int temp_len = input_array[i].first; ...
5
#include <bits/stdc++.h> using namespace std; long long int a[200000 + 1]; vector<long long int> b; int main() { long long int n, m; cin >> n >> m; for (long long int i = 1; i <= n; i++) cin >> a[i]; for (long long int i = 1; i <= m; i++) { long long int l, r; cin >> l >> r; long long int sum = 0; ...
4
#include <bits/stdc++.h> using namespace std; int main() { char c; unsigned long long ret = 1; cin >> c; int a = c - '0', yes = 0, n = 1; while (cin >> c) { int x = c - '0'; if (n == 0) { if (x == a) { n ^= 1; } else { n = 1; a = x; yes = 0; } } el...
7
#include <bits/stdc++.h> using namespace std; const int _ = 1e6 + 5, yl = 998244353; long long POW(long long x, long long y) { long long res = 1; while (y) { if (y & 1) res = res * x % yl; x = x * x % yl; y >>= 1; } return res; } long long f[_], mul[_], inv[_], n, ans; long long C(int x, int y) { re...
17
#include <bits/stdc++.h> using namespace std; int main() { long long n = 0, m = 0, k = 0; cin >> n; if (n == 1 || n == 2) { cout << -1; return 0; } if (n % 2 == 0) { cout << (n * n / 4) - 1 << " " << (n * n / 4) + 1; return 0; } else { cout << (n * n - 1) / 2 << " " << (n * n + 1) / 2; ...
7
#include <bits/stdc++.h> using namespace std; int main() { double a, b, all; scanf("%lf%lf%lf", &a, &b, &all); double Ttime = 0, Ts = 0; double alltime; Ttime = (ceil)(a / b); Ttime *= b; Ts = a + (Ttime - a) / 2; alltime = (long long int)(all / Ts) * Ttime; all -= (long long int)(all / Ts) * Ts; if...
9
#include <bits/stdc++.h> using namespace std; const long long modulo = 1073741824; int main() { long long n; cin >> n; if (n == 1) cout << 1; else if (n == 2) cout << 2; else if (n & 1) cout << n * (n - 1) * (n - 2); else if (n % 3 == 0) cout << (n - 3) * (n - 1) * (n - 2); else cout <...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long a[N], c[N]; multiset<long long> m; int main() { long long n, p, x; cin >> n >> p; for (int i = 0; i < n; i++) cin >> a[i]; cin >> x; for (int i = 0; i < n; i++) cin >> c[i]; long long P = p, ans = 0; for (int i = 0; i < n; i++...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n, a, b, k; int x[maxn]; int main() { cin >> n >> a >> b >> k; for (int i = 1; i <= n; ++i) { cin >> x[i]; x[i] = x[i] % (a + b); if (x[i] == 0) x[i] = a + b; } sort(x + 1, x + n + 1); int ans = 0; for (int i = 1; i <= n...
7
#include <bits/stdc++.h> using namespace std; int X[301][300]; int main(void) { int i, j, k, n; cin >> n; for (i = 1; i <= n; i++) for (j = 0; j < n; j++) cin >> X[i][j]; for (j = 0; j < n; j++) cin >> X[0][j]; for (i = 1; i <= n; i++) { for (j = 0; true; j++) if (X[i][j] != i) { for (k ...
10