solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long mod_plus(long long a, long long b) { return (a + b) % 1000000007; } long long mod_mul(long long a, long long b) { return (a * b) % 1000000007; } long long m[10], g[10]; long long go(char *second, int now) { if (now < 0) return 0; return mod_plus(m[second[now] ...
13
#include <bits/stdc++.h> using namespace std; int n; string w; string a; string h; string actual = "polycarp"; map<string, vector<string> > tree; int dfs_search(string actual) { int ans = 1; for (auto i : tree[actual]) { ans = max(dfs_search(i) + 1, ans); } return ans; } int main(void) { cin >> n; for (...
4
#include <bits/stdc++.h> using namespace std; static const int maxn = 1e5 + 5; static const int maxb = 320; vector<int> light_set[maxn]; vector<int> heavy_set[maxb]; int light_heavy_intersection[maxn][maxb]; int heavy_heavy_intersection[maxn][maxb]; int num_ele[maxn]; int mapper[maxn]; long long lazy[maxn]; long long a...
17
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 0, a = 0, cur = 0, tot = 0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a; cout << (a + tot) / m << ' '; tot = (a + tot) % m; } return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<string> g, g1; bool used[1000]; int main() { int n, kol = 0; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; g.push_back(s); } for (int i = 0; i < n; i++) { string s; cin >> s; g1.push_back(s); } for (int i = 0; i < g...
4
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; int main() { ios_base::sync_with_stdio(0); long long n, l, k; long long ans = 0; cin >> n >> l >> k; vector<long long> A(n); for (int i = 0; i < (n); ++i) cin >> A[i]; vector<vector<long long> > Cnt(k + 1); int d...
13
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 500005; priority_queue<ll, vector<ll>, greater<ll>> pq; int n, a[N], b[N], cnt[N], idx, top, stk[N]; ll sum; int main() { ios::sync_with_stdio(false); ll ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], ans += a[i]; ...
22
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long l, r; long long ans[N]; long long store1[N], store2[N]; vector<pair<long long, long long> > lft, rght; long long query1(long long i, long long j, long long k) { cout << 1 << " " << i << " " << j << " " << k << endl; long long x; ...
15
#include <bits/stdc++.h> using namespace std; char s[] = {"AEIOUY"}; const int MAXN = 5e5 + 10; bool jd(char ch) { for (int i = 0; i < 6; i++) if (ch == s[i]) return true; return false; } int n; long double ans = 0; long double sum[MAXN]; char a[MAXN]; void cal(int x, int y) { if (x > y) return; if (x == y)...
12
#include <bits/stdc++.h> using namespace std; struct pt { int x, y; }; int det(pt a, pt b, pt c) { return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x; } pt a[5], b[5]; bool inside(pt p, pt* a) { int l = 0, g = 0; for (int i = 0; i < 4; i++) { int d = det(p, a[i], a[i + 1]); if ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int counterOdd = 0; int counterPr = 0; vector<long> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; if (x[i] % 2 == 1) counterOdd++; else counterPr++; } if (counterOdd > counterPr) { cout << counterP...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, p; cin >> n >> k >> p; vector<int> even; vector<int> odd; for (int i = 0; i < n; i++) { int temp; cin >> temp; if (temp % 2 == 0) { even.push_back(temp); } else { ...
9
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 1; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (f) x = -x; } template <typename F> inline void write(F x, char...
22
#include <bits/stdc++.h> using namespace std; unsigned long long popcount(unsigned long long value) { unsigned long long pos = 0; while (value) { if (value & 1) ++pos; value >>= 1; } return pos; } unsigned long long GetLowestBitPos(unsigned long long value) { unsigned long long pos = 0; while ((valu...
9
#include <bits/stdc++.h> using namespace std; int main() { double W, H, a; cin >> W >> H >> a; if (W < H) swap(W, H); if (a > 90) a = 180 - a; a = (a / 180) * 3.14159265358979323846; double p = (W * W - H * H) / (2 * W); cout.precision(25); if (tan(a) > H / p) { cout << (H * H) / sin(a) << endl; ...
12
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC target("avx2") #pragma GCC optimize("03") #pragma GCC target("sse4") using namespace std; vector<int> divs[(long long)(1e3 + 5)]; void crib...
5
#include <bits/stdc++.h> using namespace std; const int iinf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3f; const int N = 5e5; int n, m; string s; vector<int> e[N]; void adde(int u, int v) { e[u].push_back(v), e[v].push_back(u); } const int T = 1e7; int ls[T], rs[T], val[T], tn; int newn() { ls[tn] = rs[tn]...
14
#include <bits/stdc++.h> using namespace std; char a[260]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; cin >> a; int x = 0, y = 0, m = 0, flag = 0; int t = 1, tt; for (int i = 0; i < n; i++) { if (a[i] == '(') { flag = 1; tt = i; t = 1; } else if (a[i...
3
#include <bits/stdc++.h> using namespace std; struct st { int x, y; int idx; }; st a[200011]; int d, n, m; struct compX { bool operator()(st a, st b) { return a.x < b.x; } }; struct compY { bool operator()(st a, st b) { return a.y < b.y; } }; int vst[100011]; int l[100011]; int r[100011]; int t[100011]; int dd[...
12
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } long long IsSquare(long long n) { long long res = sqrt(n); if (res * res == n) return res; ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 4e4 + 5; const int inf = 0x3f3f3f3f; int a[maxn]; int b[maxn]; int tong1[maxn]; int tong2[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> a[i]; ...
7
#include <bits/stdc++.h> using namespace std; vector<int> v; inline bool check(int i, int j) { return (2 * v[i] > v[j] && v[i] != v[j]); } int main() { int n; cin >> n; v.resize(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); for (int i = 1; i < n; i++) { if (check(i - 1, i)) { ...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") using namespace std; int n; int a[100001]; int pos[100001]; int b[100001]; set<int> poses; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int MOD; vector<long long> dif_pos; struct matr { long long m[2][2]; }; matr operator*(matr a, matr b) { matr res; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) { res.m[i][j] = 0; for (int k = 0; k < 2; k++) { res.m[i][j] = (res.m[i][...
16
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; pair<long long, int> a[n]; long long sum = 0ll; for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; } sort(a, a + n); long long j = 0ll; for (int i = n - 1; i >= 0; i--) { sum += (a[i].first * j + 1);...
1
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1000001; long long tableau[MAXN]; int32_t main() { long long N, total; cin >> N >> total; long long valeurActu = N * (N + 1) / 2; if (valeurActu > total) { cout << -1 << endl; exit(0); } long long indice = 0; for (long long i = 0...
16
#include <bits/stdc++.h> using namespace std; const int MAX = 200005; const int INF = 1000000009; int main() { ios_base::sync_with_stdio(false); int N, X; cin >> N >> X; if (N == 1) { cout << "YES\n"; cout << X << "\n"; return 0; } if (N == 2 && X == 0) { cout << "NO\n"; return 0; } ...
11
#include <bits/stdc++.h> using namespace std; struct edge { long long nxt, to; } e[100001 << 1]; struct edges { long long x, y; } v[100001]; long long n, m, tot, cnt, id[100001], dep[100001], fa[100001], s[100001], son[100001], top[100001], h[100001]; bool ans[100001 << 2], w[100001]; inline long long read() { ...
13
#include <bits/stdc++.h> using namespace std; template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } templat...
13
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long result = 1; while (b > 0) { if (b % 2 == 1) { result *= a; } a *= a; b /= 2; } return result; } long long gcd(long long x, long long y) { long long r; while (y != 0 && (r = x % y) != 0) ...
3
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const int mod = 1000000007; const int N = 200005; int n, dp[N], ans; pair<int, int> p[N]; int root, t[30 * N], ls[30 * N], rs[30 * N], vn; void create(int &v) { if (v == 0) v = ++vn; } void update(int &v, int l, int r, int pos, int val) { ...
10
#include <bits/stdc++.h> int main() { double x; int a, h; double mind = 100000; int mina, minh; scanf("%lf", &x); for (h = 1; h <= 10; h++) { for (a = 1; a <= 10; a++) { double r; r = (double)(a * a * h * h); r /= (double)(a * a + 4.0 * h * h); r = sqrt(r); r = (double)((in...
10
#include <bits/stdc++.h> using namespace std; namespace Debug { void __print(signed x) { cout << x; } void __print(long x) { cout << x; } void __print(long long x) { cout << x; } void __print(unsigned x) { cout << x; } void __print(unsigned long x) { cout << x; } void __print(unsigned long long x) { cout << x; } void _...
7
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock() / CLOCKS_PER_SEC); long long n; cin >> n; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; a *= 60; a += b; cout << 1440 - a << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long min(long long a, long long b) { return (a < b) ? a : b; } long long max(long long a, long long b) { return (a > b) ? a : b; } long long fp(long long a, long long b) { if (b == 0) return 1; long long x = fp(a, b / 2); x = (x * x) % mo...
10
#include <bits/stdc++.h> using namespace std; int main() { int i = 0, m, n, q; cin >> n >> m; vector<vector<int> > x(n, vector<int>(2)); vector<vector<int> > p(200001); while (i < n) { scanf("%d%d", &x[i][0], &x[i][1]); i++; } i = 1; while (i <= m) { scanf("%d", &q); p[q].push_back(i); ...
8
#include <bits/stdc++.h> using namespace std; set<int> s; int n, k; string a; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k >> a; for (int i = 0; i < n - 1; i++) { if (a[i] == '4' && a[i + 1] == '7') s.insert(i); } vector<int> pos; while (!s.empty() && k > 0) { k--; ...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = double; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } const ll MODBASE = 1000000007LL;...
17
#include <bits/stdc++.h> using namespace std; deque<int> x; int main() { int n; int i, j, k; cin >> n; for (i = 0; i < n; i++) { scanf("%d", &j); x.push_back(j); } sort(x.begin(), x.end()); int ans = 1; while ((x.size() >= 2)) { if (x[0] == x[1]) ans++; x.pop_front(); } cout << ans <...
5
#include <bits/stdc++.h> using namespace std; long long data[200005][2]; vector<long long> backward[200005]; long long num; long long tot_num = 1; int cycle; int cycle_single; void dfs(int cur_seat, int n, int father) { data[cur_seat][1] = 1; int size_ = (backward[cur_seat]).size(); int i; int want; want = da...
13
#include <bits/stdc++.h> using namespace std; long long a[305], b[305], c[305]; int main() { int n; pair<long long, long long> p[2]; long long r[2]; for (int i = 0; i < 2; i++) scanf("%lld%lld", &p[i].first, &p[i].second); scanf("%d", &n); int ans = 0; for (int i = 0; i < n; i++) { scanf("%lld%lld%lld...
9
#include <bits/stdc++.h> using namespace std; const int N = 100; int a[N], b[N]; vector<int> vec; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> b[i]; sort(b, b + n); for (int i = 0; i < n; i++) { a[i] = b[n - i - 1]; } while (k > 0) { for (int i = vec.size(); i < n && k ...
8
#include <bits/stdc++.h> using namespace std; vector<pair<int, long long> > ans; void solve(long long x, long long y) { while (x != 0 && y != 0) { if (x > y) { ans.push_back(make_pair(0, x / y)); x %= y; } else { ans.push_back(make_pair(1, y / x)); y %= x; } } if (x + y != 1) {...
16
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<int, char> > v(26); for (int i = 0; i < 26; i++) v[i].second = ('a' + i); string s; int n; cin >> s >> n; for (int i = 0; i < s.length(); i++) v[s[i] - 'a'].first++; sort(v.begin(), v.end()); for (int i = 0; i < 26; i++) { if (v[...
4
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int main() { int n, d; while (cin >> n >> d) { double vv = 180.0 / n; int num; double minx = 999999999.0; for (int i = 1; i <= n - 2; i++) { double t = vv * i; if (fabs(t - 1.0 * d) < minx) { minx = fabs(t ...
5
#include <bits/stdc++.h> using namespace std; string s[60000]; bool cmp(const string& a, const string& b) { return (a + b) < (b + a); } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> s[i]; sort(s, s + n, cmp); for (int i = 0; i < n; ++i) cout << s[i]; cout << "\n"; return 0; }
9
#include<bits/stdc++.h> #define fi first #define se second #define lo (o<<1) #define ro (o<<1|1) #define mid (l+r>>1) #define endl '\n' using namespace std; typedef long long ll; typedef vector<int>vi; typedef pair<int, int>pii; const int inf = 0x3f3f3f3f; const ll linf = 0x3f3f3f3f3f3f3f3f; const int N = 2e5 + 10; con...
18
#include <bits/stdc++.h> using namespace std; int n, m, a[1001], x, y, ans; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i < n + 1; i++) cin >> a[i]; for (int i = 0; i < m; i++) { cin >> x >> y; ans += min(a[x], a[y]); } cout << ans; return 0; }
6
#include <bits/stdc++.h> int i, p, n; int main() { scanf("%d", &n); if (n <= 3) printf("%d\n", n <= 2 ? -1 : 210); else { printf("1"); for (p = 50, i = 1; i <= n - 4; ++i) printf("0"), p = p * 10 % 210; printf("%03d\n", p); } }
6
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } inline long long power(long long a, long long n, long long m) { if (n == 0) return 1; long long p = power(a, n / 2, m); p = (p * p) % m; if (n % 2) return (p * a) ...
11
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18L + 5; const long long siz = 1e6 + 5; void solve() { long long n, k, tmp; cin >> n >> k; map<long long, long long> check; deque<long long> solution; for (int i = 0; i < n; i++) { cin >> tmp; if (check[tmp]) continue; check[tmp...
5
#include <bits/stdc++.h> using namespace std; const long long N = 1000 + 5; long long n, a[N][N]; bool check() { long long val = -1; for (long long i = 0; i < n; ++i) { long long x = 0, y = 0; for (long long j = 0; j < n; ++j) x ^= a[i][j], y ^= a[j][i]; if (val != -1 && x != val) return false; val ...
10
#include <bits/stdc++.h> int minimm(int a, int b) { if (a < b) { return a; } if (b < a) return b; if (a == b) return a; } int find_min(int a, int b, int c) { if (a < b && a < c) { return a; } else if (b < a && b < c) { return b; } else if (c < a && c < b) { return c; } if (a == b && a ...
0
#include <bits/stdc++.h> using namespace std; long long a, t, n, i = 0, j = 0; long long sum = 0, c = 0; int main() { cin >> n; for (j = 0; j < n; j++) { cin >> a; if (a == -1) { c++; if (sum > 0) { c--; sum--; } } else { sum += a; } } cout << c; return ...
0
#include <bits/stdc++.h> using namespace std; bool func(char arr[3][3], char brr[3][3]) { if (arr[1][1] == brr[1][1] && arr[1][2] == brr[1][2] && arr[2][2] == brr[2][2]) { return true; } if (arr[1][1] == brr[1][2] && arr[1][2] == brr[2][2] && arr[2][2] == brr[1][1]) { return true; } if (ar...
4
#include <bits/stdc++.h> using namespace std; int a[100005]; int main(int argc, char** argv) { int n, k; cin >> n >> k; int ans = 0; for (int i = 1; i <= n; i++) cin >> a[i]; while (a[1] < k) { for (int i = 1; i <= n; i++) { if (a[i] != a[i + 1] && a[i] != k) ++a[i]; } ++ans; } cout << a...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long l, r; long long slove(long long x) { long long p = 1, odd = 0, even = 0, flag = 1; while (p <= x) { x -= p; if (flag) odd = (odd + p) % mod; else even = (even + p) % mod; p *= 2; flag ^= 1; } i...
10
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define ll long long #define ld long double #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define pii pair<int, int> #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define vi...
18
#include<bits/stdc++.h> #define top 1000000007 #define max(a,b) (a>b) ? a:b #define min(a, b) (a<b) ? a:b #define S second #define F first using namespace std; const long long p = 1e8 +1; long long get_min(long long a, long long b, long long c, long long d) { long long x= min(a,b); x =min(x,d); return min(x,c);} int g...
8
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> v(n), x(n); for (int i = 0; i < n; i++) { cin >> v[i]; } for (int i = 0; i < n; i++) { cin >> x[i]; } sort(v.begin(), v.end()); sort(x.begin(), x.end()); for (int i = 0; i < n; i++) { cout << v[i]; ...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long int ull; typedef long double ld; ll gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(int a, int b) { return a * b / gcd(a, b); } int main() { ll n; cin >> n; ll x; ll i; int dp[4] = {0}; for (i = 0;...
10
#include <bits/stdc++.h> using namespace std; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1}; const double eps = 1e-9; const int INF = 0x7FFFFFFF; const long long INFLL = 0x7FFFFFFFFFFFFFFFLL; const double pi = acos(-1); struct point_i { int x, y; point_i(int _x = 0, int ...
10
#include <bits/stdc++.h> using namespace std; int book[1000100]; int day[1000100]; int que[1000100]; int main() { int n, i; cin >> n; int people = 0; int sum = 0; int a; int flag = 1; int all = 0, count = 1; int begin = 1, end = 1; int j; for (i = 1; i <= n; i++) { cin >> a; if (a > 0) { ...
6
#include <bits/stdc++.h> using namespace std; vector<int> x[100010]; vector<int> y[100010]; bool can[100010]; int ssqrt(int s) { int x = sqrt(s); if (x * x == s) return x; else return -1; } void init() { for (int i = 1; i < 100010; i++) { can[i] = false; for (int a = 0; a * a <= i; a++) { ...
17
#include <bits/stdc++.h> using namespace std; const int N = 5005; const int inf = 1e9 + 7; int pr[] = {2, 3, 5, 7, 11, 13}; int up; int tot[105]; int q[50000005], vis[1000005]; int sz; pair<int, int> srt[1000005]; void dfs(int x, int y) { if (y == sz) { q[x] = 1; return; } dfs(x, y + 1); x *= pr[y]; w...
15
#include <bits/stdc++.h> using namespace std; template <class T> inline bool read(T &x) { x = 0; bool f = 0; char ch; for (ch = getchar(); !isdigit(ch); ch = getchar()) { if (ch == EOF) return 0; f |= ch == '-'; } for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); if (f) x = ...
14
#include <bits/stdc++.h> using namespace std; template <typename T> void chmin(T &x, const T &y) { if (x > y) x = y; } template <typename T> void chmax(T &x, const T &y) { if (x < y) x = y; } int read() { char c; while ((c = getchar()) < '-') ; if (c == '-') { int x = (c = getchar()) - '0'; while ...
15
#include <bits/stdc++.h> using namespace std; int ans; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; if (a[0] == 1) { int x = 0; for (int i = 1; i < n; ++i) { if (a[i] != i + 1) break; x++; } ans = max(ans, x); } if (a[n - 1] == 1000) { in...
5
#include <bits/stdc++.h> const int Max = 1e6 + 100; using namespace std; vector<int> vec[Max]; int dist[Max]; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> dist[i]; } for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; vec[u].push_back(v)...
11
#include <bits/stdc++.h> using namespace std; int t, x, p, k, cnt, fac[1009]; long long solve(long long mm) { long long s = 0; for (int i = 1; i < (1 << cnt); ++i) { long long tmp = 1, sign = -1; for (int j = 0; j < cnt; ++j) { if ((i >> j) & 1) { tmp *= fac[j]; sign *= -1; } ...
14
#include <bits/stdc++.h> using namespace std; long long check(int a, int b, int c, int d, int n, int m) { if (a + c <= m) { if (b <= n and d <= n) { return a * b + c * d; } } if (b + d <= n) { if (a <= m and c <= m) { return a * b + c * d; } } return 0; } int main() { int n, a, b...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const string LN = "\n"; const double eps = 1e-9; const double pi = acos(-1.0); const int INF = (int)2e9 + 7; const long long LINF = (long long)9e18 + 7; const long long P = 353251; const long long P1 = 239017; const long long P2 =...
11
#include <bits/stdc++.h> using namespace std; int main() { long long int n, c, i; cin >> n >> c; long long int a[n - 1], b[n - 1]; for (i = 0; i < n - 1; i++) { cin >> a[i]; } for (i = 0; i < n - 1; i++) { cin >> b[i]; } b[0] = b[0] + c; for (i = 1; i < n - 1; i++) { a[i] = min(a[i - 1] + ...
9
#include <bits/stdc++.h> using namespace std; long long solve(long long n) { for (long long i = n / 2; i > 1; --i) { if (n % i == 0) { return solve(i) + i; } } return 1; } int main() { long long n; cin >> n; cout << solve(n) + n; }
2
#include <bits/stdc++.h> using namespace std; int dcmp(double a, double b) { return fabs(a - b) <= 0.0000000001 ? 0 : (a > b) ? 1 : -1; } long long fun(long long lev) { return (3 * ((lev) * (lev + 1) / 2) - lev); } int main() { long long n, i, s = 0, ans; cin >> n; for (i = 1;; i++) { ans = fun(i); if (...
9
#include <bits/stdc++.h> using namespace std; int psum(long long v) { long long ans = (v * (v + 1000000007 - 1)) % 1000000007; ans = (ans * 500000004LL) % 1000000007; return (int)ans; } pair<long long, long long> getDP(int x, int y, int k) { if (x == 0 || y == 0 || k == 0) return make_pair(0, 0); if (x == 1) ...
18
#include <bits/stdc++.h> using namespace std; int delta[310000]; int orig[310000]; int main() { long double sum = 0; long double ans; int num = 1; int n; scanf("%d", &n); int cmd, a, x; for (int i = 0; i < n; ++i) { scanf("%d", &cmd); if (cmd == 1) { scanf("%d", &a); scanf("%d", &x); ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> C(n), R(n); char c[200]; for (int i = 0; i < n; i++) { scanf("%s", c); for (int j = 0; j < n; j++) if (c[j] == 'C') { C[j]++; R[i]++; } } int ans = 0; for (int i = 0; i < n;...
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e3 + 3; int n, r; int x[MAX_N]; double y[MAX_N]; int main() { scanf("%d%d", &n, &r); for (int i = (1); i <= (n); i++) scanf("%d", &x[i]); for (int i = (1); i <= (n); i++) { y[i] = r; for (int j = (1); j <= (i - 1); j++) { if (x[j] + r ...
7
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, a, b; cin >> n; n = n / 2; while (n--) { cin >> a >> b; cout << -b...
0
#include <bits/stdc++.h> using namespace std; inline void read(register int *n) { register char c; *n = 0; do { c = getchar(); } while (c < '0' || c > '9'); do { *n = c - '0' + *n * 10; c = getchar(); } while (c >= '0' && c <= '9'); } vector<string> rot(vector<string> V) { vector<string> res((...
10
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const int MAXN = 2e5 + 5; int n; vector<int> G[MAXN]; long long fact[MAXN]; long long f(int v, int p = -1) { long long ret = 1; for (int u : G[v]) { if (u == p) continue; ret = ret * f(u, v) % MOD; } ret = ret * fact[G[v].siz...
11
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long mod = 1000000009; long long mod2 = 1000000009; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } bool is_vowel(char c) { if (c == 'a' || c ...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; string tempS; cin >> n; bool purple = 1, green = 1, blue = 1, orange = 1, red = 1, yellow = 1; for (int i = 0; i < n; i++) { cin >> tempS; if (tempS == "purple") purple = 0; if (tempS == "green") green = 0; if (tempS == "blue") ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 10; vector<int> g[maxn]; bool vis[maxn]; int n, m, q; void add(int x, int y) { g[x].push_back(y); } void dfs(int x) { int si = g[x].size(); vis[x] = true; for (int i = 0; i < si; i++) { int to = g[x][i]; if (vis[to]) continue; dfs(to...
11
#include <bits/stdc++.h> char A[13][5] = {{"C"}, {"C#"}, {"D"}, {"D#"}, {"E"}, {"F"}, {"F#"}, {"G"}, {"G#"}, {"A"}, {"B"}, {"H"}}; int aa, bb, cc; void find(char a[], char b[], char c[]) { int i; for (i = 0; i < 12; i++) { if (strcmp(A[i], a) == 0) aa = i + 1; if (strcmp(A[i], b) == 0) ...
4
#include <bits/stdc++.h> using namespace std; struct tri { long long a, b, c; }; const long long N = 1e3 + 10; const long long inf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3f; const long long mod = 1e9 + 7; long long t[3], n, c; priority_queue<long long, vector<long long>, greater<long long>> q[3]; int32_...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { long long a, b, c; cin >> a >> b >> c; cout << (a + b + c) / 2 << endl; } }
0
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf("%d", A + i); } char s[51][51]; int N, dp[51][51][51][51]; int dyn(int x, int y, int X, int Y) { if (x > X || y > Y || x >= N || y >= N || X < 0 || Y < 0) return 0; if (x == X && y == Y && s[x][y] ^ 35) return ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int rank; cin >> rank; vector<int> counts(rank + 2); for (int i = 0; i < n; i++) { int r; cin >> r; counts[r]++; } vector<int> changes(rank + 2); int sessions = 0; while (true) { if (counts[rank] == n) { ...
4
#include <bits/stdc++.h> using namespace std; int n; long long r1 = 0, r2 = 0, ans = 2e18; struct point { long long x, y; } a, b, p[2005]; long long dis(point a, point b) { long long x = a.x - b.x; long long y = a.y - b.y; return x * x + y * y; } int main() { scanf("%d%I64d%I64d%I64d%I64d", &n, &a.x, &a.y, &b...
8
#include <bits/stdc++.h> using namespace std; int n; int a[111111]; int b[111111]; map<int, int> s; int dist[111111]; int pos[111111]; int main(void) { istream_iterator<int> in(cin); n = *in++; for (int i = 1; i <= n; i++) a[i] = *in++; for (int i = 1; i <= n; i++) b[i] = *in++; for (int i = 1; i <= n; i++) p...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const long long p = 1000000007; int main() { long long n; scanf("%lld", &n); ; long long Test = 2 * n; stack<long long> op; stack<long long> nb; while (Test--) { char c; cin >> c; if (c == '+') op.push(1); else { ...
9
#include<iostream> #include<stdio.h> #include<string.h> using namespace std; int main() { int t; scanf("%d",&t); while(t--) { string str; cin>>str; printf("%d\n",str.length()); } }
0
#include <bits/stdc++.h> using namespace std; int n, m, tam; int get(int i, int j) { int pos = i + j + 1; if (pos <= tam / 2) return pos; return tam - pos + 1; } void solvetask() { cin >> n >> m; tam = n + m - 1; int a[n][m]; vector<int> ida(n + m), volta(n + m), cnt(n + m); for (int i = 0; i < n; i++) ...
7
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define all(v) v.begin(), v.end() #define eb emplace_back #define ll long long void solve() { int n; cin >> n; string s; cin >> s; vector<ll> pref(n, 0); vector<ll> cnt(n, 0); for(int i = 0; i < n; i += 1) { ll w = 0,...
6
#include <bits/stdc++.h> using namespace std; inline int input() { char ch = getchar(); while (ch < '0' || '9' < ch) ch = getchar(); int x = 0; do { x = x * 10 + ch - '0'; ch = getchar(); } while ('0' <= ch && ch <= '9'); return x; } inline void output(long long x) { static int st[20], top; top ...
25
#include <bits/stdc++.h> using std::cin; using std::cout; using std::deque; using std::endl; using std::fill_n; using std::max; using std::memset; using std::min; int n; const int maxn = 100; int len; int cnt[26]; char buf[101]; struct edge { int t, u, c; edge* next; edge* pair; }; int pn; const int maxpn = maxn ...
12
#include <bits/stdc++.h> using namespace std; const long long int N = 300009; const long long int mod = 998244353; long long int n, k; long long int a[N], sum = 0; void pre() {} int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); ; pre(); cin >> n >> k;...
5