solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int mo = 1e9 + 7; const int N = 2e5 + 10; int n, k, fac[N] = {1}, fav[N]; int qpow(int a, int b) { int ans = 1; for (; b >= 1; b >>= 1, a = 1ll * a * a % mo) if (b & 1) ans = 1ll * ans * a % mo; return ans; } int C(int n, int m) { return fac[n] * 1ll * fav[m...
12
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int N = 1000005; const double PI = 4 * atan(1); long long m, x, n, p, k, q, l, r; long long a, b; long long x0, y, x2, y2; map<pair<long long, long long>, bool> isbehy; map<pair<long long, long long>, bool> vis; map<pair<long long, long lon...
10
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { x = 0; char c = getchar(); int f = 0; for (; c < '0' || c > '9'; f |= c == '-', c = getchar()) ; for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar()) ; if (f) x = -x; } const int mo = 1e9 + 7; inli...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10, mod = 1e9 + 7; inline int ad(int x, int y) { int ans = x + y; if (ans > mod) ans -= mod; return ans; } inline int mu(int x, int y) { return 1LL * x * y % mod; } inline int wop(int x, int y) { int ret = 1; while (y) { if (y & 1) ret =...
23
#include <bits/stdc++.h> using namespace std; const int M = 5101; const int N = 330000; const long long oo = 4111111111L; int n, k; long long a[N]; long long f[M][M]; int main() { while (~scanf("%d%d", &n, &k)) { for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]); sort(a + 1, a + n + 1); int p = n / k, q ...
12
#include <bits/stdc++.h> int main() { int t; char s[1000]; char f[] = {"po"}; char j1[] = {"desu"}; char j2[] = {"masu"}; scanf("%d", &t); while (t--) { int n; scanf("%s", s); n = strlen(s); if (strncmp(s + n - 2, f, 2) == 0) printf("FILIPINO\n"); else if (strncmp(s + n - 4, j1, ...
0
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; long long int a[n], s = 0; double sum; map<long long int, long long int> m; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]]++; s += 2 * a[i]; } sum = (s * 1.0) / n; if (floor(sum) - sum != 0) { cout << "0\...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; bool check[MAXN + 10]; int dp[MAXN + 10]; void init() { int n; int ans = 0; cin >> n; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (check[x - 1]) dp[x] = dp[x - 1] + 1; else dp[x] = 1; check[x] = ...
8
#include <bits/stdc++.h> using namespace std; inline int sum(int n) { return (n * (n + 1)) / 2; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n, t, a, b; cin >> a >> b; int x = abs(a - b); if (x % 2 == 0) { x /= 2; cout << 2 * sum(x) << endl; } else { ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n, k, d, res = 0, flag[1000] = {0}, a[1000]; cin >> n >> k >> d; int an = n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i...
2
#include <bits/stdc++.h> using namespace std; constexpr long long INF = 0x1fffffffffffffff; constexpr int inf = 0x3fffffff; constexpr double inf_l = 1e18; constexpr long long MOD = 1000000007LL; constexpr int mod = 1000000007; vector<long long> f(100001), w(100001); int main() { ios::sync_with_stdio(false); cin.tie...
13
#include <bits/stdc++.h> using namespace std; int main() { int maxno; cin >> maxno; int ans = 0; for (int a = 2; a <= maxno; a++) { int n = a; int i = 0; vector<int> res; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); while (n % i == 0) { n...
1
#include <bits/stdc++.h> using namespace std; double eps = 1e-10; int n; double a[2000]; double mn, mx; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; mn = 0, mx = 999999999.0; for (int i = 0; i < n; i++) mn = max(mn, a[i] / (double)(i + 1)), mx = min(mx, (a[i] + 1) / (double)(i + 1)); ...
10
#include <bits/stdc++.h> using namespace std; long long ok(long long a, long long b, long long c, long long d, long long e, long long f) { return ((c - a) * (f - b)) == ((e - a) * (d - b)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m, i, j, k, l, t, r, e, p = 0, f; cin...
4
#include <bits/stdc++.h> using namespace std; int n, d, a[110], x[110], y[110], vis[110], cost[110]; int D(int i, int j) { return d * (abs(x[i] - x[j]) + abs(y[i] - y[j])); } int Solve() { int i, v; for (i = 0; i <= n; i++) { vis[i] = 0; cost[i] = 10E8; } cost[n] = 0; v = 0; while (v != -1) { vi...
13
#include <bits/stdc++.h> using namespace std; long long i, j, n, l, t, k, w, z, h, m, s; long long a[1235], b[12345], d[12346], x[123455], c[12345], f[123434]; double y; string q, qq, p, r; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a[i] >> b[i] >> c[i]; s = s + a[i]; k = k + b[i]; t =...
2
#include <bits/stdc++.h> using namespace std; const double EPS = -1e8; const double Pi = acos(-1); bool inline equ(double a, double b) { return fabs(a - b) < EPS; } const int MAXN = 100010; struct DSJ { int mom[MAXN]; void init(int x) { for (int i = 1; i <= x; i++) mom[i] = i; } int find(int x) { return mom...
14
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args....
14
#include <bits/stdc++.h> using namespace std; const unsigned long long INF = ~0ull; const int N = 1e6 + 15; bool used[N]; int a[N], apos; void init() { memset(used, true, sizeof(used)); apos = 1; used[0] = used[1] = false; for (int i = 2; i < N; i++) { if (used[i]) { for (int j = 2; i * j < N; j++) { ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { string s; cin >> s; int len = s.size(), c1 = 0; for (int i = 0; i < len; i++) { if (s[i] == 'a' && s[i + 1] == 'b') c1++; else if (s[i] == 'b'...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, y, u = 0; string s; cin >> n >> x >> y >> s; deque<long long> A; if (s[0] == '0') A.push_back(0), u++; else A.push_back(1); for (int i = 1; i < n; i++) if (s[i - 1] != s[i]) { A.push_front(s[i] - 48); u += A...
7
#include <bits/stdc++.h> using namespace std; const int inf = (int)1.01e9; const double eps = 1e-9; const int N = 2e5 + 10; vector<int> v[N]; int a[N]; int b[N]; int n; int w[N], d[N]; int f[N]; int res; void dfs(int x) { f[x] = w[x]; vector<int> vv; for (int i = 0; (i) < (((int)(v[x]).size())); ++i) { int y ...
18
#include <bits/stdc++.h> using namespace std; inline int gi() { register int x = 0, w = 0; char ch = 0; while (ch < '0' || ch > '9') { if (ch == '-') w = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return w ? -x : x; } const int N = 1e...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int mod = 1e9 + 7; int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); return ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, d, e; cin >> n >> d >> e; int ans = n; for (int i = 0; i * 5 * e <= n; ++i) { ans = min(ans, (n - i * 5 * e) % d); } cout << ans << endl; return 0; }
6
#include <bits/stdc++.h> using namespace std; map<string, int> types; struct man { bool two; int f, s, num, ans; void read(int x) { num = x; string str, cur; cin >> str; two = false; for (int i(0); i < str.size(); ++i) if (str[i] == ',') { two = true; s = types[cur]; ...
10
#include <bits/stdc++.h> using namespace std; const int N = 400, mod = int(1e9) + 7; int n, k; long double ans, cur; int x[N]; pair<int, int> line[N][N]; int sz[N]; vector<pair<int, int> > rb; int an; long long A, C, A1, C1; bool ok = 0; long double getx(pair<int, int> x, pair<int, int> y, int i) { A = x.first - x.se...
17
#include <bits/stdc++.h> using namespace std; const int OO = 1e9; const long long INF = 1e18; const int irand(int lo, int hi) { return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo; } const long long lrand(long long lo, long long hi) { return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo; } te...
11
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 5; long long mod; vector<long long> numbers[maxn]; vector<long long> children[maxn]; char forbid[maxn]; long long dp[maxn]; long long parent[maxn]; long long gcd(long long a, long long b) { while (a && b) { if (a >= b) a %= b; el...
15
#include <bits/stdc++.h> using namespace std; int n, cnt = 1; string s; vector<int> v; int main() { cin >> n; getline(cin, s); getline(cin, s); for (int i = 0; i < s.length(); ++i) { if (s[i] == '.' || s[i] == '?' || s[i] == '!') { if (cnt > n) { puts("Impossible"); return 0; } ...
8
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, d, tmp; bool flag[N]; vector<int> V[N]; int f[2][N]; void dfs(int u, int p, int d, int f[]) { f[u] = d; for (int i = 0; i < V[u].size(); i++) if (V[u][i] != p) dfs(V[u][i], u, d + 1, f); } int main() { while (~scanf("%d %d %d", &n, ...
12
#include <bits/stdc++.h> using namespace std; const int co[] = { 3, 3, 3, 3, 15, 27, 15, 29, 27, 27, 23, 83, 27, 43, 23, 45, 15, 39, 39, 83, 39, 57, 43, 27, 15, 71, 39, 83, 23, 83, 15, 197, 83, 281, 387, 387, 83, 99, 147, 57, 15, 153, 89, 101, 27, 449, 51, 657, 113, 29,...
19
#include <bits/stdc++.h> using namespace std; int main() { int NO, n; double x[200] = {0}, Xsc, Ysc, Vb, Vs, MIN1 = 1e12, MIN2 = 1e12, Line1, Line2; cin >> n >> Vb >> Vs; for (int i = 0; i < n; i++) cin >> x[i]; cin >> Xsc >> Ysc; for (int i = 1; i < n; i++) { Line1 = x[i] / Vb + sqrt((Xsc - x[i]) * (Xs...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const double pi = 3.14159265359; const double eps = 1e-9; const int mod = 1e9 + 7; const int mod1 = 1e9 + 9; const int INF = 1e9;...
5
#include <bits/stdc++.h> using namespace std; long long get(long long n) { for (long long i = 2; i * i <= n; ++i) if (n % i == 0) return i; return n; } int main() { long long n; cin >> n; long long cnt = 0; if (n % 2 != 0) { n -= get(n); ++cnt; } cout << cnt + n / 2; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, i, j, n, k, sum; while (cin >> n >> k) { sum = 0, d = 0; if (k >= 240) { cout << "0" << endl; } else { for (i = 1; i <= n; i++) { sum = sum + (i * 5); c = sum + k; if (c > 240) break; ...
0
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, ai; vector<long long> data; cin >> n; for (long long i = 0; i < n; i++) { cin >> ai; data.push_back(ai); } vector<vector<long long> > v; for (long long i = 0; i < n; i++...
13
#include <bits/stdc++.h> using namespace std; double a[1002], b[1002]; int main() { int n; double m, cm; cin >> n >> m; cm = m; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] <= 1.0 + 1e-9) { cout << "-1"; return 0; } } for (int i = 1; i <= n; i++) { cin >> b[i]; if (...
7
#include <bits/stdc++.h> #include<map> #include<unordered_map> #include<queue> #include<stack> #include<vector> #include <cmath> #include<math.h> #define ll long long int #define pb push_back #define mod 1000000007 #define ip(ar,m,n) for(ll i=0;i<m;i++){for(ll j=0;j<n;j++){cin>>ar[i][j];}} #define mk(ar,m,n) for(ll i=0...
9
#include <bits/stdc++.h> using namespace std; const int Inf = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; auto ask = [&](int x, int y) { cout << "? " << x + 1 << ' ' << y + 1 << endl; int ret; cin >> ret; return ret; }; int bc = -1, val = In...
20
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> istream &operator>>(istr...
17
#include <bits/stdc++.h> struct Vector { long long int x, y; Vector() : x(0), y(0) {} Vector(const Vector& a, const Vector& b) : x(b.x - a.x), y(b.y - a.y) {} double len() { return hypot(x, y); } }; long long int cross(Vector& a, Vector& b); long long int cross(Vector& a, Vector& b) { return a.x * b.y - a.y * b...
6
#include <bits/stdc++.h> using namespace std; set<int> candid; vector<int> candid_arr; vector<int> mapper; vector<bool> flag; int k, n; void dump_set() { for (set<int>::iterator ptr = candid.begin(); ptr != candid.end(); ptr++) { cout << *ptr << ' '; } cout << endl; } void dump_mapper() { for (int i = 0; i ...
9
#include <bits/stdc++.h> using namespace std; const int NMAX = 1005; int N, M, K; bool dragnea[NMAX]; vector<int> graph[NMAX]; bitset<NMAX> seen; vector<int> nodes; void dfs(int node) { nodes.push_back(node); seen[node] = 1; for (auto& x : graph[node]) if (seen[x] == 0) dfs(x); } vector<int> bad, good; int ma...
7
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
9
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; cin >> n; int k = 0; int h = 0; if (n > 77774444) { cout << 4444477777; return 0; } for (int i = n; i <= 1000000000; i++) { int j = i; h = 0; k = 0; while (j > 0) { if (j % 10 != 4 && j % 10 != 7) {...
10
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr)...
18
#include <bits/stdc++.h> using namespace std; int n, m, groups[100 + 10]; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &groups[i]); } int bus = m, index, count = 1; while (index < n) { if (bus - groups[index] >= 0) { bus -= groups[index]; index++; } el...
2
#include <bits/stdc++.h> using namespace std; using LL = long long; void solve() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; ++i) { cin >> arr[i]; } bool sorted = true; for (int i = 1; i < n; ++i) { if (arr[i] <= arr[i - 1]) { sorted = false; break; } } if (so...
6
#include <bits/stdc++.h> using namespace std; vector<int>::iterator it; vector<long long int>::iterator lit; int main() { ios::sync_with_stdio(false); long long int tcase; cin >> tcase; while (tcase--) { long long int mina = LLONG_MAX; long long int n; cin >> n; vector<long long int> a(n, 0), b(...
6
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-7; const int MAXN = 20; int n, k; double p[MAXN]; double prob[2][1 << MAXN]; double pr[1 << MAXN]; double sum[1 << MAXN]; int bcnt[1 << MAXN]; int id[1 << MAXN]; double res[MAXN]; const int STEPS = 2000; int get_lowest(int mask) { int l = mask & (mas...
16
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e12; const int N = (int)1e6 + 10; int n, m, k; long long a[N]; long long b[N]; long long c[N]; long long ANS = INF * N; vector<pair<long long, int> > d[N]; int main() { scanf("%d%d%d", &n, &m, &k); while (m--) { int t, v, u; lon...
10
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a < b) gcd(b, a); int r; while ((r = a % b)) { a = b; b = r; } return b; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; whi...
15
#include <bits/stdc++.h> using namespace std; void run() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } vector<int> s; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { int x = (v[i] ^ v[j]); s.push_back(x); } } sort(s.begin(), s.end...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; priority_queue<int> q; for (int i = 0; i < (int)(n); i++) q.push(i + 1); vector<int> A, B; while (q.size() > 1) { int a = q.top(); q.pop(); int b = q.top(); q....
2
#include <bits/stdc++.h> const int mod = 1000000007; const int gmod = 3; const int inf = 1039074182; const double eps = 1e-9; const double pi = 3.141592653589793238462643383279; const long long llinf = 2LL * inf * inf; template <typename T1, typename T2> inline void chmin(T1 &x, T2 b) { if (b < x) x = b; } template <...
22
#include <bits/stdc++.h> using namespace std; long long ncrp(long long n, long long r, long long p) { long long C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (long long i = 1; i <= n; i++) for (long long j = min(i, r); j >= 1; j--) C[j] = (C[j] + C[j - 1]) % p; return C[r]; } long long mod_exp(long lon...
2
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, o = 0; for (int i = 0; i < 2; ++i) { scanf("%d%d%d", &a, &b, &c); o += (a + b) * c + a * b; } printf("%d\n", o); }
8
#include <bits/stdc++.h> double f(int d, int R); double f(int d, int R) { if (d == 0) { return 2.0f * R; } if (d == 1) { return 2.0f * R + sqrt(2.0f) * R; } return 2.0f * sqrt(2.0f) * R + 2.0f * R + 2.0f * R * (d - 2); } int q(int d, int m); int q(int d, int m) { return d == 0 ? m : 2 * (m - d); } int...
11
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 15; vector<pair<vector<int>, int>> v; vector<int> adj[N], adj2[N]; set<pair<int, int>> s; int final_pos = 1, n, m, x, y, pos = 1, root, ind[N], ans[N], is; void dfs(int x, int p) { ans[x] = final_pos++; for (int i = 0; i < adj2[x].size(); ++i) if...
16
#include <bits/stdc++.h> const long long mod = 1e9 + 7; using namespace std; void solve() { int n; cin >> n; long long ans = n; while (!(n & 1)) { n >>= 1; ans += n; } for (int i = 2; i * i <= n; i++) { if (n % i == 0) { ans += max(i, n / i); n = max(i, n / i); i = 2; } }...
2
#include <bits/stdc++.h> struct nodo { int val; struct nodo* sigte; }; struct nodo* creaNodo(int dato); void imprimeLista(struct nodo** Last); int MCD(int N, int M); void agregar(struct nodo** Last, int dato); int main() { int n, i; scanf("%d", &n); int a[n]; i = 0; while (i < n && scanf("%d", &a[i++]) ==...
4
#include <bits/stdc++.h> using namespace std; int a[100010], dp[100010], b[100010]; int main() { int n, k, num; int i, j; scanf("%d%d", &n, &k); for (i = 1; i <= n; i++) scanf("%d", &a[i]); num = 0; b[num++] = a[1]; for (i = 2; i <= n; i++) { if (a[i] != a[i - 1]) b[num++] = a[i]; } dp[b[0]]++; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c; cin >> n >> a >> b >> c; int sum = 0; for (int i = 0; i <= a; i = i + 2) { for (int j = 0; j <= b; j++) { int res = (i / 2) + (j); int diff = n - res; if (diff < 0) { break; } if (diff % 2 == 0 &...
7
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 111; long long c[111][111]; void init() { int i, j; c[0][0] = 1; for (i = 1; i < 100; i++) { c[i][0] = c[i - 1][0]; for (j = 1; j <= i; j++) { c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; } } } int main() { int i, j; long lon...
12
#include <bits/stdc++.h> using namespace std; int main() { string wd; cin >> wd; int len = wd.length(); string f = ""; int count = 1, s; if (len % 2 == 0) s = len / 2 - 1; else s = len / 2; f = f + wd[s]; while (count != len) { if (count % 2 != 0) s = s + count; else s = s ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int T, n; vector<int> v1, v2, res; string str1, str2; void solve() { v1.clear(); v2.clear(); res.clear(); for (int i = 0; i < int(n); i++) { v1.push_back(str1[i] - '0'); v2.push_back(str2[i] - '0'); } int round = 0, idx = n - 1,...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 100, INF = 10000; int main() { int n; cin >> n; vector<long long int> arr(n + 1); for (int i = 3; i <= n; ++i) { arr[i] = arr[i - 1] + i * (i - 1); } cout << arr[n] << "\n"; return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n, m, sum = 0; unsigned long long nums[2][10]; cin >> n >> m; for (int i = 0; i < 10; ++i) { nums[0][i] = n / 10LL + ((n % 10LL >= (unsigned long long)i && i > 0LL) ? 1LL : 0LL); nums[1][i] = m / 10LL + ((m % 1...
3
#include <bits/stdc++.h> using namespace std; int n, len; long long t[4 * 200007], dp[200007], mod[4 * 200007], total, modulo; void push(int v, int tl, int tr) { int tm = (tl + tr) >> 1; t[2 * v + 1] += (mod[v] * (tm - tl + 1)) % modulo; t[2 * v + 2] += (mod[v] * (tr - tm)) % modulo; t[2 * v + 1] %= modulo; t...
9
#include <bits/stdc++.h> using namespace std; using lint = long long; using VI = vector<int>; using VVI = vector<VI>; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; VI y1(n), y2(m); for (int i = 0; i < n; i++) { cin >> y1[i]; y1[i] += 10000; y1[i] *= 2; } for ...
13
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define all(v) begin(v), end(v) #define decision (yes ? "YES" : "NO") #define countlz __builtin_clz #define popcount __builtin_popcount #define mem(arr, val) memset(arr, val, sizeof(arr)) typedef long long ll; typedef pair<int, int> pii; typedef pair<lon...
9
#include <bits/stdc++.h> using namespace std; int col[300005]; vector<int> v[300005], g[300005]; void dfs(int s, int pp) { set<int> st; vector<int> vv; int i, p = 0; for (i = 0; i < v[s].size(); ++i) { int x = v[s][i]; if (col[x]) st.insert(col[x]); else vv.push_back(x); } for (i = 0...
14
#include <bits/stdc++.h> int main() { int r, c; scanf("%d%d", &r, &c); if (r == 1 && c == 1) { printf("0\n"); return 0; } for (int i = 1; i <= r; ++i, puts("")) for (int j = 1; j <= c; ++j) printf("%d ", r < c ? i * (r + j) : j * (c + i)); }
6
#include <bits/stdc++.h> using namespace std; bool siv[100000]; vector<long long> prime; void sieve(); void pri(); long long int fact(long long int n); int main() { int p; cin >> p; int need = p - 10; int n = 13; int have[13] = {0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 15, 4}; int ans = 0; for (int i = 1; i < n; i++...
0
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using qi = queue<int>; using si = set<int>; using misi = map<int, si>; using graph = vector<misi>; const int INF = 1000000; int main() { cin.tie(0), ios::sync_with_stdio(0); int n, m, u, v, t; cin >> n >> m; graph g(n); for (int i = 0; i < ...
17
#include <bits/stdc++.h> using namespace std; long long l, r, mod, k; struct mat { long long a, b, c; mat() { a = 0; b = 1; c = 1; } mat operator*(mat& dr) const { mat ret; ret.a = a * dr.a + b * dr.b; ret.a %= mod; ret.b = a * dr.b + b * dr.c; ret.b %= mod; ret.c = b * dr.b ...
16
#include <bits/stdc++.h> using namespace std; long long t1 = 114514334, t2 = 810893364; long long m1 = 1000000007, m2 = 1000000009; pair<long long, long long> gethash(vector<int> v) { sort(v.begin(), v.end()); pair<long long, long long> z = make_pair(123123, 23454); for (int i = 0; i < v.size(); i++) { z.firs...
16
#include <bits/stdc++.h> using namespace std; int main() { int l, x, res; scanf("%d", &l); ; string s; cin >> s; for (x = 1; x < l; x++) res += (s[x] != s[x - 1]); printf("%d", min(res + 2, l)); }
8
#include <bits/stdc++.h> using namespace std; int a[2005]; int sum[3][2005]; int f[2005][2005][3]; int main() { int n, ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 1; i <= n; i++) sum[1][i] = sum[1][i - 1] + (a[i] == 1); for (int i = n; i >= 1; i--) sum[2][...
10
#include <bits/stdc++.h> using namespace std; int n, m, bl, c[200005 * 5], a[200005]; long long ans, Ans[200005]; struct node { int l, r, id; } p[200005]; inline bool cmp(node x, node y) { if (x.l / bl != y.l / bl) return x.l < y.l; if ((x.l / bl) & 1) return x.r > y.r; return x.r < y.r; } inline void add(int x...
14
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > mul(vector<vector<long long> >& A, vector<vector<long long> >& B, int N) { vector<vector<long long> > C( N, vector<long long>(N, 1070000000LL * 1070000000LL)); for (int i = 0; i < (N); i++) for (int k =...
17
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 2e18; signed main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; int domino = (n * m) / 2; int extra_hori = 0, extra_ver = 0; if (n % 2...
9
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long oo = 1e16 + 5; long long m[N][20], M[N][20]; long long n, s, l; long long dis(long long L, long long R) { long long k = log2(R - L + 1); R = R - (1 << k) + 1; return max(M[L][k], M[R][k]) - min(m[L][k], m[R][k]); } long lon...
12
#include <bits/stdc++.h> using namespace std; int n; int binpow(int x, int y) { int res = 1; while (y) { if (y & 1) res *= x; x *= x; y >>= 1; } return res; } void solve() { cin >> n; string s(n, 'a'); if (n % 2 == 0) { s[n / 2 - 1] = 'b'; } else { s[n / 2] = 'b'; s[0] = 'c'; }...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int tree[maxn]; vector<int> v[maxn]; int pre; int t; bool cmp2(int a, int b) { int x = (a - pre + t) % t; int y = (b - pre + t) % t; return x < y; } int lowbit(int x) { return x & (-x); } void update(int x, int n) { while (x < maxn) { tr...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops, no-stack-protector") #pragma GCC target("avx,avx2,fma") using namespace std; mt19937_64 rnd; const long long maxn = 20; const long long mod = 1e9 + 7; const long long base = 3e18; const long double eps = 1e-7; map<long long, ...
22
#include <bits/stdc++.h> using namespace std; long long dp1[100010]; long long dp2[100010]; long long a[100100]; long long b[100100]; int main() { int n, ask, type, l, r; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); b[i] = a[i]; } sort(b, b + n); dp1[0] = a[0]; dp2[0] = b[0];...
4
#include <bits/stdc++.h> const int N = 31; const int MOD = (int)1e9 + 7; int n; int dp0[N][N], dp1[N][N]; inline void Ad(int &a, int b) { if ((a += b) >= MOD) a -= MOD; } int main() { scanf("%d", &n); dp1[30][0] = 1; for (int i = 30; i >= 1; --i) { for (int j = 0; j <= 30; ++j) { int x = (j) ? (1 << (...
19
#include <bits/stdc++.h> template <class _, class __> bool checkmax(_ &a, __ b) { return a < b ? a = b, true : false; } template <class _, class __> bool checkmin(_ &a, __ b) { return a > b ? a = b, true : false; } using namespace std; const int P = 1e9 + 7; char str[105]; int A[105]; int dp[105][4050]; int n; void...
12
#include <bits/stdc++.h> using namespace std; double v[302000], b[302000]; struct node { int L, R; double Max; int Mid() { return (L + R) / 2; } } a[302000 * 4]; void Build(int r, int L, int R) { a[r].L = L, a[r].R = R; a[r].Max = 0; if (L == R) return; Build(r << 1, L, a[r].Mid()); Build(r << 1 | 1, a[...
12
#include <bits/stdc++.h> using namespace std; int sx, sy, ex, ey; char str[3]; vector<string> ans; int main() { scanf("%s", str); sx = (int)(str[0] - 'a'), sy = (int)(str[1] - '1'); scanf("%s", str); ex = (int)(str[0] - 'a'), ey = (int)(str[1] - '1'); while (sx != ex || sy != ey) { if (sx == ex) { i...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; using pii = pair<int, int>; using pll = pair<long long, long long>; using vb = vector<bool>; using vi = vector<int>; using vl = vector<long long>; using vvb = vector<vector<bool>>; using vvi = vector<vector<int>>; using vvl = vector<vector<long lo...
14
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { int n, k; string t; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; cin >> t; string zz = t; int l1 = t.length() * (k - 1); for (int i = 0; i < l1; i++) zz.push_back('*'); l1 +...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, sum = 0; cin >> n; for (int i = 1; i <= 999; ++i) { sum += i; if (sum == n) { cout << "YES"; return 0; } if (sum > n) { cout << "NO"; return 0; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; long long t, n, s[2000001], f[2000001], m = 1000000007; void dp() { s[1] = 1; s[2] = 1; f[1] = 1; f[2] = 1; for (int i = 3; i < 2000001; i++) s[i] = (s[i - 2] * 2 + s[i - 1]) % m; for (int i = 3; i < 2000001; i++) f[i] = (f[i - 3] + s[i]) % m; } int main() { s...
11
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > beacons; int a[100005], b[100005], bst[100005]; int main() { int n, x, y; cin >> n; for (int i = 0; i < n; ++i) { cin >> x >> y; beacons.push_back(make_pair(x, y)); } sort(beacons.begin(), beacons.end()); for (int i = 0; i < n; ++...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = n; i >= 1; i--) cout << i << " "; cout << endl; } return 0; }
0
#include <bits/stdc++.h> int a[10] = {1, 6, 28, 120, 496, 2016, 8128, 32640, 130816, 523776}; int main() { int n, i, r; scanf("%d", &n); for (i = 9; i >= 0; i--) if (n % a[i] == 0) { printf("%d\n", a[i]); return 0; } return 0; }
2
#include <bits/stdc++.h> int n, m, q; char str[1005]; bool a[1005][1005]; std::vector<std::pair<int, int> > del; int num[1005][1005], tot, ld, ru; std::set<std::pair<int, int> > s; namespace FU { int f[1005 * 1005]; std::vector<int> inv[1005 * 1005]; std::set<int> su; void init(int i) { if (su.count(i)) return; su....
27