solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; string s; int main() { ios_base::sync_with_stdio(0); for (int i = 1; i < 10; i++) s += i + '0'; for (int i = 1; i <= 9; i++) for (int j = 0; j <= 9; j++) { s += i + '0'; s += j + '0'; } for (int i = 1; i <= 9; i++) for (int j = 0; j <= 9; j++...
0
#include <bits/stdc++.h> using namespace std; int X[1 << 10]; int Y[1 << 10]; int L[1 << 10]; int A[1 << 10]; int B[1 << 10]; int Res[1 << 10]; int F(int N, int M, int from) { memset(B, 0, sizeof(B)); memset(Res, -1, sizeof(Res)); int i, j; for (i = from; i < N; i += 2) { int len = A[(i - 1 + N) % N] + A[i]...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const double pi = 3.1415926535897, Eps = 1e-10, g = 9.8; int n, m; pair<double, double> data[maxn]; double v, alp[maxn], x[maxn], y[maxn], lim[maxn]; double maxs[maxn]; int main() { scanf("%d%lf", &n, &v); for (int i = 1; i <= n; i++) scanf("%lf...
14
#include <bits/stdc++.h> using namespace std; vector<long long> test; long long lower, higher; bool check() { bool t1 = true, t2 = true, t3 = true; for (long long i = 2; i <= sqrt(higher); i = i * 2) { if (test[0] % i == 0 && test[1] % i == 0) { t1 = false; break; } if (test[2] % i == 0 && t...
3
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int INF = 1e6; int n, m; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int i, j, t, k, x, y, z, N; cin >> t; while (t--) { cin >> n >> k; vector<vector<int>> s(k); for (int i = 0; i < k; i++) { cin >>...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, lm = 2e5 + 5; int rd() { int x = 0, w = 1; char ch = 0; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + (ch ^ 48); ch = getchar(); } return x * w; } s...
26
#include <bits/stdc++.h> const long long int MOD = 998244353LL; const int mxsz = 500055; using namespace std; set<int> adj[mxsz]; vector<int> mat[mxsz]; int dp[mxsz]; int depth[mxsz]; int red[mxsz]; int total; bool vis[mxsz]; void dfs(int n, int d, int r) { vis[n] = true; depth[n] = d; for (int i = 0; i < mat[n]....
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 10; int a[MAXN], dp[MAXN][MAXN]; int n, h, l, r; bool in(int t) { return l <= t && t <= r; } int main() { scanf("%d %d %d %d", &n, &h, &l, &r); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); memset(dp, -1, sizeof(dp)); dp[0][0] = 0; for (i...
9
#include <bits/stdc++.h> using namespace std; int n, k, simpanJ, simpanH; int maxi(int x) { int jumlah = 0, y = x; while (y > 0) { jumlah += y; y = y / k; } if (jumlah >= n) { if (simpanH > x) simpanH = x; return 1; } else return 0; } void binser() { int l = 1, r = n, mid, a = 0; while...
7
#include <bits/stdc++.h> using namespace std; const int N = 7005; int n, q, mu[N], pri[N], tot; bool notp[N]; bitset<N> a[100007], G[N], Mu[N]; inline void init() { notp[0] = notp[1] = true; mu[1] = 1; for (register int i = 2; i <= N - 5; i++) { if (!notp[i]) { pri[tot++] = i; mu[i] = -1; } ...
17
#include <bits/stdc++.h> using namespace std; long long a[101][101]; long long dist[101][101]; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); long long n; cin >> n; for (long long i = 0; i < 101; i++) { for (long long j = 0; j < 101; j++) { if (i != j) dist[i][j] = 1e9; ...
9
#include <bits/stdc++.h> using namespace std; int n, i, j, a[500001], b[500001], l, r, m, k; int main() { cin >> n; k = n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); j = n / 2 - 1; for (i = n - 1; i >= n / 2; i--) { while (a[j] > a[i] / 2) j--; if (j >= 0) k--; j--; if (j < 0) brea...
8
#include <bits/stdc++.h> using namespace std; int main() { long long t, i, j, n, m, k, l, r; cin >> t; string str; while (t--) { cin >> str; l = 0; n = str.length(); for (i = 0; i < n; i++) { if (str[i] == '0') { l++; } } r = n - l; m = min(l, r); if (m % 2 ==...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, kg; cin >> n >> kg; float ans = 100000000000; for (int i = 0; i < n; ++i) { float k, price; cin >> k >> price; ans = min(ans, (k / price) * kg); } cout << fixed; cout << setprecision(6); cout << ans; }
0
#include <bits/stdc++.h> using namespace std; int n; map<pair<int, int>, set<pair<int, int> > > m; pair<int, int> baccha; int main() { scanf("%d", &n); int akela = 0; int akelakabaccha = 0; int dukela = 0; for (int i = 1; i <= n; i++) { int a[3]; for (int j = 0; j < 3; j++) scanf("%d", &a[j]); sor...
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:10000000000") using namespace std; const int INF = 1000000007; const long long INF2 = 1000000000000000007; const long long MOD = 1e6; const long long MOD1 = 1864463441; const int SIZE = 150010; long long n, p; vector<pair<int, int> > vec; int C_musor(long long x)...
8
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int test = 1; while (test--) { long long int n, k; cin >> n >> k; long long int ans = 1; for (int i = 1; i < k; i++) { ans *= k; ans %= 1000000007; } for (int i ...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, l; cin >> n >> l; double pos1 = 0, pos2 = l, a1 = 0, a2 = n - 1; double a[n]; double v1 = 1, v2 = 1; double time = 0; for (int i = 0; i < n; i++) cin >> a[i]; bool flag = true; ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; pair<unsigned int, unsigned int> p[100100]; cin >> n; for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second; sort(p, p + n); for (int i = 1; i < n; i++) { if (p[i].first - p[i - 1].first > 15) continue; else { unsig...
8
#include <bits/stdc++.h> using namespace std; int main() { long long x, y, x1, y1; cin >> x >> y >> x1 >> y1; long long n; if (x == x1) { n = abs(y - y1) + 1 + 2; n *= 2; } else if (y == y1) { n = abs(x - x1) + 1 + 2; n *= 2; } else { n = abs(x - x1) + abs(y1 - y) + 2; n *= 2; } ...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2") #pragma GCC optimize("unroll-loops") #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define req(i,a,b) for(int i=(a);i>=(b);--i) #define rep_(i,a,b) for(int i=(a);i<(b).size();++i) #define F(a) rep(a,1,n...
15
#include <bits/stdc++.h> using namespace std; string s, t; int n, m, f[200009][30], vis[30], l, r, ans, flag, mid; int main() { cin >> n >> s; for (int i = 0; i < n; i++) { if (!i) f[i][s[i] - 'a'] = 1; else { for (int j = 0; j < 30; j++) { if (s[i] - 'a' == j) { f[i][j] = f[i ...
5
#include <bits/stdc++.h> using namespace std; int main() { int player[6]; for (int i = 0; i < 6; i++) cin >> player[i]; sort(player, player + 6); if (player[5] + player[0] + player[1] > (player[2] + player[3] + player[4])) { cout << "NO" << endl; return 0; } if ((player[5] + player[0] + player[1] + ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long int i, j, n; cin >> n; if (n == 1) cout << "-1\n"; else if (n == 2) { cout << "2 3 6\n"; } else { cout << n << " "; i = n + 1; j = n * (n + 1); cout << i << " " << j << "\n"; ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n; long long a[n], b[n], c[n]; long long sum = 0; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; } cin >> m; long long a_[m], b_[m], c_[m]; for (int i = 0; i < m; i++) { cin >> a_[i] >> b_[i] >> c_[i]...
8
#include <bits/stdc++.h> using namespace std; using i64 = long long; using f64 = double; using f80 = long double; using pii = pair<int, int>; using ptx = pair<f64, f64>; const int INF = 1e9; pii diag(-INF, INF), first(-INF, INF), second(-INF, INF); vector<pii> v; int n; static pii meet(pii a, pii b) { return pii(max(...
18
#include <bits/stdc++.h> using namespace std; struct node { int a, b, c; }; const int MAXX = 80; int n, A, B, C, dis[MAXX][MAXX][MAXX]; node par[MAXX][MAXX][MAXX]; bool vis[MAXX][MAXX][MAXX], mark1[MAXX], mark2[MAXX]; string s[MAXX]; void Sort(int &x, int &y, int &z) { if (x > y) swap(x, y); if (y > z) swap(y, z)...
13
#include <bits/stdc++.h> using namespace std; int main() { int x; string ar[] = { "Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "Lincoln", "Jo...
6
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define maxn 5000005 #define ll long long #define mo 1000000007 using namespace std; int n,i,j,k,st,tot,d[maxn],L[maxn],R[maxn]; ll t[maxn],a[maxn],b[maxn],c[2]; void read(){ int m,pre=0; scanf("%d",&m); while (m--){ int R,k; ll sd,bs; scan...
24
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int nax = 1e6 + 10; vector<int> tree(4 * nax); long long i, j, x, y, k; bool sortbysec(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.second < b.second); } bool premutation(vector<long lo...
5
#include <bits/stdc++.h> using namespace std; long long pwr(long long a, long long b, long long mod) { a %= mod; if (a < 0) a += mod; long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b /= 2; } return ans; } long long pwr(long long a, long long b) { long long ...
2
#include <bits/stdc++.h> //v.erase(unique(v.begin(),v.end()),v.end()); #define ff first #define ss second #define pb push_back #define sz(v) (ll)v.size() #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) typedef long double ld; typedef long long ll; const ll N = 250100; const ll mod = 1e+9 + 7; const ll MAX...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, c, i, j; string s; vector<string> v; cin >> n; cin >> s; for (c = 0; c < n; c++) { for (i = 2; i <= n - c; i = i + 2) { v.push_back(s.substr(c, i)); } } j = 0; for (i = 0; i < v.size(); i++) { size_t nu = count(v[i].be...
2
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, mini = 1e12; cin >> a >> b >> c >> d; for (int i = 0; i <= 1000; i++) { for (int j = 0; j < 1001; j++) { if (i * a - j * c == d - b && mini > b + i * a) { mini = b + i * a; } } } if (mini == 1e12) ...
4
#include <bits/stdc++.h> using namespace std; struct haha { int x, y; haha() {} haha(int a, int b) : x(a), y(b) {} }; int d[2][1000][1000], sum[1000001], r, c; char m[1111][1111]; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; void BFS(int idx, int x, int y) { queue<haha> q; q.push(haha(x, y)); d[idx][...
7
#include <bits/stdc++.h> using namespace std; priority_queue<long long int, vector<long long int>, greater<long long int> > ti; vector<long long int> p[200005], y[300005], f(2000005, 0), b(100005, 0); long long int vis[100005]; map<pair<long long int, long long int>, long long int> mp; set<pair<long long int, long ...
0
#include <bits/stdc++.h> using namespace std; int V1[110]; int main() { int n, i, S = 1, num = 0; cin >> n; for (i = 0; i < n; i++) cin >> V1[i]; sort(V1, V1 + n); for (i = 0; i < n - 1; i++) { if (V1[i] == V1[i + 1]) S++; else { num = max(num, S); S = 1; } } num = max(num, S...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long power(long long a, long long b) { a = a % mod; long long ans = 1; while (b > 0) { if (b % 2 == 1) { ans = (ans * a) % mod; } b = b / 2; a = (a * a) % mod; } return ans; } int main() { ios_base::sync_...
7
#include <bits/stdc++.h> using namespace std; class Solver { private: int n; vector<int> comp; vector<vector<int> > Lists; vector<vector<int> > forComp; public: void InputData() { cin >> n; comp.resize(n); forComp.resize(3); for (int i = 0; i < n; i++) { cin >> comp[i]; comp[i]-...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int ans = 0; if (m == 0) ans = 1; else if (m < (n + 1) / 2) ans = m; else if (m == (n + 1) / 2) ans = n / 2; else ans = n - m; cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; template <class T> struct SuffixAutomaton { static const int sigma = 29; struct Node { int len; int slnk; bool cloned; int son[sigma]; int cnt[3]; Node() : len(0), slnk(-1), cloned(false) { memset(son, 0, sizeof ...
16
#include <bits/stdc++.h> using namespace std; long long n, X1, X2, Y1, Y2; bool get2(long long x1, long long y1, long long x2, long long y2) { int x; printf("? %lld %lld %lld %lld\n", x1, y1, x2, y2); fflush(stdout); scanf("%d", &x); if (x1 <= X1 && y1 <= Y1 && x2 >= X2 && y2 >= Y2) x--; if (x > 0) return t...
14
#include <bits/stdc++.h> using namespace std; const int MaxN = 105; bool List[MaxN][MaxN], mark[MaxN]; int predict[MaxN]; int n, cnt; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); memset(mark, 0, sizeof(mark)); cnt = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> s; for (int j ...
15
#include <bits/stdc++.h> using namespace std; bool solve(long long a, long long b, long long c) { if (c == 0) return a == b; if (c < 0) return (b <= a && (a - b) % (-c) == 0); else return (b >= a && (b - a) % c == 0); } int main() { long long a, b, c; cin >> a >> b >> c; if (solve(a, b, c)) cout...
3
#include <bits/stdc++.h> using namespace std; map<long long, int> mp; long long a[200010], b[200010], c[200010]; int main() { long long n, q, k, m, i, j, total = 0, op; cin >> n >> q >> a[0]; long long mx = a[0]; for (i = 1; i < n; i++) { cin >> a[i]; b[i] = mx; c[i] = min(a[i], mx); mx = max(mx...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d, x, y, z; cin >> a >> b >> c >> d; x = (a + b) / 2; y = (b + c) / 2; z = (c + d) / 2; if (x + y == z || y + z == x || z + x == y) x = b; else { if (x + y == z || y + z =...
0
#include <bits/stdc++.h> using namespace std; signed main() { long long T; scanf("%lld", &T); while (T--) { string t; cin >> t; long long vis[26] = {}, cnt[26] = {}; long long len = t.length(); string rk = ""; long long o = 0, num = 0; for (long long i = 0; i < 26; i++) vis[i] = -1, cn...
10
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const int M = 100100; const double pi = acos(-1.0); double x[M], y[M]; double d[M]; int n; double mi = 1e16; double ma = 0; double px, py; void relax(double x) { ma = max(ma, x); mi = min(mi, x); } int main() { cout.precision(11); cout << fi...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pii = pair<int, int>; using Vi = vector<int>; void run(); int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(18); run(); return 0; } int uplg(int n) { return 32 - __builtin_clz(n); } int uplg(ll n) { return 6...
21
#include <bits/stdc++.h> using namespace std; int chot[500003]; int find(int u) { return chot[u] < 0 ? u : chot[u] = find(chot[u]); } void combine(int u, int v) { u = find(u); v = find(v); if (u != v) { if (-chot[u] < -chot[v]) swap(u, v); chot[u] += chot[v]; chot[v] = u; } } int main() { ios::syn...
13
#include <bits/stdc++.h> using namespace std; int p[200010]; int father[200010]; int getfather(int x) { if (father[x] == 0) { return x; } return father[x] == x ? x : father[x] = getfather(father[x]); } int main() { int n; int f1, f2; int i, j; int cnt = 0; int root = 0; scanf("%d", &n); for (i =...
9
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tt; cin >> tt; while (tt--) { long long int n; cin >> n; long long int x = 1, m = 0; for (int i = 1; i <= 39; i++) x *= 3; int done[4...
7
#include <bits/stdc++.h> using namespace std; vector<long long> v; int ar[1009]; int main() { long long n, k, modd, i; scanf("%lld", &n); scanf("%lld", &k); for (i = k - 1; i > 0; --i) { if (n % i == 0) { modd = i; break; } } cout << ((n / modd) * k) + modd << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; long long a[200009], b[200009], ind[200009], f[200009]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t = 1, n, k, i, ans, p; cin >> t; while (t--) { cin >> n >> k; i = 0; while (i < n) { cin >> a[i]; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string k; cin >> k; if (k[k.size() - 1] == 'o') cout << "FILIPINO" << endl; else if (k[k.size() - 1] == 'u') cout << "JAPANESE" << endl; else cout << "KOREAN" << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; char s[1100][1100]; int l[1100]; int main() { int n, m, wg, ws, pan = 1, ma = 0, i, j, t, sum = 0; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%s", s[i]); } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (s[i][j] == 'G') { ...
4
#include <bits/stdc++.h> using namespace std; inline double calc(double l1, double r1, double l2, double r2) { return max(min(r1, r2) - max(l1, l2), 0.0); } int main() { int nf, ne, ns; double rf, re, rs; int df, de; cin >> nf >> ne >> ns >> rf >> re >> rs >> df >> de; rf = sqrt(rf * rf - 1); re = sqrt(re...
18
#include <bits/stdc++.h> int main() { int n, v; int q, i, j, k, l; int res = 0; scanf("%d", &n); for (0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &v); if (i == j) res ^= v; } } scanf("%d", &q); for (i = 0; i < q; i++) { scanf("%d", &v); if (v == 3) printf("%d...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; vector<string> x(n); for (int i = 0; i < n; i++) cin >> x[i]; vector<int> tab(k); for (int i = 0; i < k; i++) tab[i] = i; long long res = 1e15; do { vector<int> W; long long minl =...
6
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long mp(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) r...
20
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, z1, z2; ; cin >> n >> a >> b; if (n < a && n < b) { cout << "NO"; return 0; } if (n % a == 0) { cout << "YES\n"; cout << n / a << " " << 0; return 0; } else if (n % b == 0) { cout << "YES\n"; cout << ...
3
#include <bits/stdc++.h> using namespace std; const int N = 400400, P = 1e9 + 7; struct edge { int n, v; } e[N << 1]; int n, u, v, S, T, fl, tot, tp, sum, ans, s1, s2, cnt; int hd[N], a[N], w[N], p[N], fa[N], d[N], sz[N]; int we[N], top[N], df[N], ed[N], vi[N], su[N]; int pr[N], ck[N], fi[N], mu[N], h[N], st[N]; void...
23
#include <bits/stdc++.h> using namespace std; const int MAXN = 200001; int A[MAXN]; int B[MAXN]; int vis[MAXN]; vector<int> lista[MAXN]; void dfs(int u, int c) { vis[u] = c + 1; for (int i = 0; i < lista[u].size(); i++) { int v = lista[u][i]; if (!vis[v]) dfs(v, 1 - c); } } int main() { ios_base::sync_w...
18
#include <bits/stdc++.h> using namespace std; int mineq(int &a, int b) { return a > b ? a = b, true : false; } int maxeq(int &a, int b) { return a < b ? a = b, true : false; } const int MAXN = 1e5 + 10; struct edge { int w, id; bool b; }; edge e[MAXN]; int n, m; pair<int, int> a[MAXN]; pair<int, int> ans[MAXN]; boo...
9
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; const int oo = 998244353; const ll loo = 1e18; ll modpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = res * a % oo; a = a * a % ...
14
#include <bits/stdc++.h> using namespace std; const int N = 20; const int INF = 16843009; int n; char a[N][N]; int memo[N + N][1 << N]; int dp(int d, int mask) { if (d == n + n - 2) { if (a[n - 1][n - 1] == 'a') return 1; if (a[n - 1][n - 1] == 'b') return -1; return 0; } int &ret = memo[d][mask]; i...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 3; int si[maxn], di[maxn], n; int main() { while (~scanf("%d", &n)) { for (int i = 1; i <= n; i++) scanf("%d%d", &si[i], &di[i]); int prev = si[1], ans = si[1]; for (int i = 2; i <= n; i++) { int j = 0; while (si[i] + j * di...
1
#include <bits/stdc++.h> using namespace std; inline int read() { int a = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0'; return a * f; } const int mod = 1e9 + 7; const int N = 4e5 + 5; const...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int maxn = 1e3 + 5; int arr[maxn]; int brr[maxn]; int n; vector<int> vec; bool cal(ld x, ld st) { for (int i : vec) { x -= (x / i); if (x < st) return 0; } return 1; } void solve() { cin >> n; ld st; ci...
7
#include <bits/stdc++.h> using namespace std; char s[100010]; int check[30], ans = 0, tim = 0; bool flag = false; int main() { int n; scanf("%d", &n); memset(check, 0, sizeof(check)); for (int i = 1; i <= n; i++) { scanf("%s", s + 1); if (s[1] == '!') { scanf("%s", s + 1); if (flag) { ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, l, v1, v2, k; scanf("%d%d%d%d%d", &n, &l, &v1, &v2, &k); int x = (n - 1) / k; double t = l / (2. * v1 * (double)x * (double)v2 / double(v1 + v2) + v2); double t_ = double(v2 - v1) / double(v1 + v2) * t; double T = (x + 1) * t + x * t_; prin...
11
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 9, mod = 1e9 + 7; int arr[N]; bool occured[N]; long long dp[N][N]; int main() { ios::sync_with_stdio(false), cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; if (arr[i] > 0) { occured[arr[i]]++; } } ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int M = 11; const int K = 10; map<pair<int, int>, int> r; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; void solve() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), ...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7, N = 1e3 + 7, A = 4, M = 1e9 + 9; int idx(char c) { if (c == 'A') return 0; else if (c == 'C') return 1; else if (c == 'G') return 2; else return 3; } void add(int &a, int b) { a += b; if (a >= M) a -= M; } struct AC { i...
17
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x, flag = 0; cin >> n; for (i = 0; i < n; i++) { cin >> x; if (x == 1) flag = 1; } if (flag) cout << -1 << endl; else cout << 1 << endl; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n, x, cnt[6] = {}; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); cnt[x]++; } cnt[5] = cnt[0] ? cnt[5] / 9 : 0; cnt[0] = cnt[5] ? cnt[0] : min(cnt[0], 1); for (int i = 0; i < cnt[5]; i++) printf("555555555"); for (in...
2
#include <bits/stdc++.h> using namespace std; int a[200005]; int gg[200005]; int num[200005]; int l[200005], r[200005]; int main() { int n, q, now = 0, ans = 0, temp, nex = 0; scanf("%d%d", &n, &q); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); num[a[i]]++; if (!l[a[i]]) l[a[i]] = i; r[a[i]] ...
12
#include <bits/stdc++.h> using namespace std; const long long INF = 2e18; inline long long mul(long long a, long long b) { if (b == 0) return 0; if (INF / b < a) return INF; else return a * b; } struct E { int v, id; long long c; }; vector<E> G[200001]; int maxch[200001]; int cnt[200001] = {0}; int de...
16
#include <bits/stdc++.h> using namespace std; const int N = 2505; int n, num[N][N]; pair<int, pair<int, int> > dat[N * N]; bitset<N> bs[N]; void rd(int &x) { int f = 1; x = 0; char c; while (c = getchar(), c < 48 || c > 57) if (c == '-') f = -1; do x = (x << 3) + (x << 1) + (c ^ 48); while (c = getchar(...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000010; struct Treap { int ch[2], key, size, cnt; long long dat, sum; } T[MAXN]; int root, tot; inline int cmp(int x, int tar) { if (T[x].dat == tar) return -1; return (tar > T[x].dat) ? 1 : 0; } inline void maintain(int x) { T[x].size = T[T[x].c...
18
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<long long> rng_int; long long modpow(long long b, long long e, long long mod) { long long ans = 1; for (; e; b = b * b % mod, e /= 2) if (e & 1) ans = ans * b % mod; retu...
21
#include <bits/stdc++.h> int x[1005]; int y[1005]; int cross(int x_1, int y_1, int x_2, int y_2) { return ((((x_1 * y_2) - (y_1 * x_2)) > 0) > 0 ? 1 : -1); } int main() { int n; int i, j, k; int max_x = -10006; int max_i; int x_1, y_1, x_2, y_2; int dir, sub_dir; int cnt; scanf("%d", &n); for (i = 0...
7
#include <bits/stdc++.h> using namespace std; int n; long long a, b; int arr[1000111]; bitset<100011> bs; vector<int> primes; void sieve() { bs.set(); for (long long i = 2; i <= 100000; i++) { if (bs[i]) { primes.push_back(i); for (long long j = i * i; j <= 100000; j += i) { bs[j] = 0; ...
15
#include <bits/stdc++.h> using namespace std; const int Maxn = 100000 + 10; int pre[Maxn * 2], last[Maxn], other[Maxn * 2]; long long a[Maxn], lcm[Maxn]; long long sum; int n, l; void Add_edge(int p, int q) { pre[++l] = last[p]; last[p] = l; other[l] = q; pre[++l] = last[q]; last[q] = l; other[l] = p; } lon...
13
#include <bits/stdc++.h> using namespace std; int b[33], c[33], p[33]; int n, u, r; long long sum, ans; void dfs(int now, int a[], int id) { int d[33], i; if (now == u + 1 || (u - now + 1) % 2 == 0) { sum = 0; for (i = 1; i <= n; i++) { sum += (long long)a[i] * c[i]; } ans = max(ans, sum); ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; string s; cin >> s; for (int i = 0; i < n; i++) { if (abs('a' - s[i]) > abs('z' - s[i])) { int diff = min(s[i] - 'a', k); k -= diff; s[i] -= diff; } els...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; long long x = 0; bool flag = false; bool is_exist = true; cin >> n; while (n > 1) { if (!(n % 6)) { n /= 6...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k, num, c, maxi = -1000000000000000000, ans = 1000000000000000000, sum; cin >> n >> k; vector<pair<long long int, long long int> > v; m...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n, count = 0; vector<long> a, b; cin >> n; for (int i = 0; i < n; i++) { long long t; cin >> t; a.push_back(t); } b = a; sort(b.begin(), b.end()); for (int i = 0; i < n; i++) { vector<long>::iterator it = upper_bound(b....
5
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const int maxn = 500050; const int mod = 1e9 + 7; using namespace std; int main() { int n; cin >> n; if (n <= 3) puts("NO"); else { cout << "YES" << endl; if (n == 4) { printf("1 * 2 = 2\n"); printf("2 * 3 = 6\n"); printf("6 * 4 ...
7
#include <bits/stdc++.h> using namespace std; int n; map<int, int> m; vector<int> c; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); c.push_back(x); } m.clear(); for (int i = 0; i < n; i++) { m[c[i]] = 1; } int cnt = -1; while (true) { cnt += 1; ...
11
#include <bits/stdc++.h> using namespace std; const int NMAX = 51; const long long MAX_LONG_LONG = 1LL << 62; int Q; long long a, b, m; long long pow2[NMAX]; long long safeAdd(long long a, long long b) { if (a >= MAX_LONG_LONG - b) { return MAX_LONG_LONG; } return a + b; } long long safeMul(long long a, long ...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 5e4 + 5; vector<int> G[maxn]; int n, root, nroot; int par[maxn]; int vis[maxn]; void dfs(int u) { vis[u] = 1; for (auto v : G[u]) { if (vis[v] == 0) { par[v] = u; dfs(v); } } } int main() { cin >> n >> root >> nroot; --root, --...
8
#include <bits/stdc++.h> using namespace std; long long fpb(long long p, long long q) { if (q == 0) return p; else return fpb(q, p % q); } int main() { long long x, y, a, b, k; long long i, banyak = 0; cin >> x >> y >> a >> b; k = ((x * y) / fpb(x, y)); if ((a % k == 0)) { banyak = (b / k) - (...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; n -= 2; cout << n * n; return 0; }
3
#include <bits/stdc++.h> using namespace std; int n, m, cnt, ans, S, T; int to[100010], nxt[100010], head[210], cost[100010], flow[100010], dis[210], pe[210], pv[210], inq[210], ml[210]; queue<int> q; inline int rd() { int ret = 0, f = 1; char gc = getchar(); while (gc < '0' || gc > '9') { if (gc == '-') ...
21
#include <bits/stdc++.h> using namespace std; int n; double a, s, s1, s2, t1, t2; double t0, v; int main() { double tm = 0; scanf("%d%lf%lf", &n, &a, &s); for (int i = 0; i < n; i++) { scanf("%lf%lf", &t0, &v); t1 = v / a; s1 = 0.5 * a * t1 * t1; if (s1 > s) { t1 = sqrt(2 * s / a); t2 ...
8
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)1e5 + 100; const int K = 350; int A[N]; int B[N]; int id[N]; int lef[N]; int r...
26
#include <bits/stdc++.h> const int maxn = 4e5 + 7; using namespace std; int n, x, y, ans; int a[maxn], b[maxn], c[maxn], last[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); b[a[i]]++; } for (int i = 1; i <= n; i++) if (b[i] > b[x]) x = i; int lim = trunc(sq...
22
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; { int a, b; cin >> a >> b; int p = 3 * a - b; if (p > 0) cout << p; else cout << 0; } return 0; }
1