func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, mi, ma, x; cin >> n; int m[n + 1]; for (i = 1; i <= n; i++) { cin >> x; m[x] = i; } int a[n + 1]; a[1] = 1; a[n] = 1; mi = m[1]; ...
#include <bits/stdc++.h> using namespace std; int main(void) { int x; scanf( %d , &x); if (x == 1) puts( 1 ); else if (x == 3) puts( 5 ); else if (x <= 5) puts( 3 ); else if (x <= 13) puts( 5 ); else if (x <= 25) puts( 7 ); else if (x <= 41) puts( ...
#include <bits/stdc++.h> using namespace std; int main() { string str; unordered_map<string, char> index; int t; cin >> t; while (t--) { cin >> str; sort(str.begin(), str.end()); str = str.substr(0, unique(str.begin(), str.end()) - str.begin()); if (index.find(str) == ind...
#include <bits/stdc++.h> using namespace std; const int N = 10; int h[20][20]; long double E[20][20]; bool vis[20][20]; void init() { for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { cin >> h[i][j]; } } } pair<int, int> go_next(int x, int y) { if (x % 2 == ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 1; cin >> n; string arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n && x == 1; i++) { string s = arr[i]; for (int j = 0; j < 5; j++) { if (s[j] == O && s[j + 1] == ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int block_size = 360; const int maxn = 100010; const long long mod = 1e9 + 7; const long double eps = 1e-9; template <typename T> int sign(const T& a) { if (a < 0) { return -1; } i...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x * f; } ...
#include <bits/stdc++.h> using namespace std; struct event { int x, size, val, ent; bool operator<(const event& rhs) const { if (x == rhs.x) return ent < rhs.ent; return x < rhs.x; } }; int main() { ios_base::sync_with_stdio(false), cin.tie(0); int n, x; cin >> n >> x; ve...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007, con = 2500000; long long n, k, a, ans; int main() { iostream::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >> k; ans += abs(a - k); a = k; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 7; int n; int a[maxn], b[maxn]; long long solve() { long long res = 0; for (int i = 0; i < int(n); i++) { long long sa = 0, sb = 0; for (int j = i; j < int(n); j++) { sa |= a[j]; sb |= b[j]; res = ...
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define uint unsigned int #define loop(n) for(int i=1;i<=n;i++) int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); uint t; cin>>t; while(t--) { int...
#include <bits/stdc++.h> using namespace std; int n; char s[2001][2002]; int wu[2][2001]; int ans; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1); for (int i = 1; i <= n; i++) { int rxor = 0, lxor = 0, d; for (int j = n; j > i; j--) { d = wu[...
#include <bits/stdc++.h> using namespace std; int main() { string s, s5; cin >> s; int c = 0; string s3 = , s4 = ; s3 += s[0]; s3 += s[1]; s4 += s[3]; s4 += s[4]; int a = atoi(s3.c_str()); int b = atoi(s4.c_str()); while (1) { if (b == 59) { if (a == 23)...
#include <bits/stdc++.h> using namespace std; struct team { int prob; int time; }; bool comp(team a, team b) { return (a.prob > b.prob) || ((a.prob == b.prob) && (a.time < b.time)); } int main(int argc, char const *argv[]) { int n, k; cin >> n >> k; team t[n]; for (int i = 0; i <...
#include <bits/stdc++.h> #pragma GCC optimize trapv long long int power(long long int x, long long int b) { long long int p = 1; while (b > 0) { if (b & 1) { p = p * x; p %= 1000000007; } b >>= 1; x *= x; x %= 1000000007; } return p % 1000000007; } ...
#include <bits/stdc++.h> using namespace std; int a[200]; int main() { int t; cin >> t; while (t--) { int m, n; cin >> m >> n; for (int i = 1; i <= m; i++) { cin >> a[i]; } map<int, int> mp; for (int i = 1; i <= n; i++) { int x; cin >> x; ...
#include <bits/stdc++.h> using namespace std; long long int n, a, b; long long int S(long long int x) { int ret = 0; long long int y = n - x; while (x > 0) { ret += x % 10; x /= 10; } while (y > 0) { ret += y % 10; y /= 10; } return ret; } long long int solv...
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize(2) using namespace std; int n, r; bool dp[666][666]; int fang[666][666]; pair<int, int> ku[666]; void dfs(int x, int y) { if (x == y) cout << () ; else if (fang[x][y] == -1) { cout << ( ; dfs(x + 1, y); ...
#include <bits/stdc++.h> const int N = 5000 + 10; struct node { int l, r, id; }; node a[N]; bool pre[N], suf[N]; std::vector<node> vector; bool cmp(const node& i, const node& j) { if (i.r ^ j.r) return i.r < j.r; else return i.l < j.l; } bool cc(const node& i, const node& j) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; double f, s, v, l, omega, r; const double tol = 1.0e-7; scanf( %d %lf %lf , &n, &r, &v); omega = v / r; double xt, xb, a, b; for (int i = 0; i < n; i++) { scanf( %lf ...
#include <bits/stdc++.h> using namespace std; long long n, m, k; map<string, long long> mm; string a[100005]; long long c[100005]; long long min(long long a, long long b) { return a < b ? a : b; } int main() { cin >> n >> k >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int...
#include <bits/stdc++.h> using namespace std; const int M = 1e6 + 10; struct node { int l, r, sum, mus; } tr[M]; int n, a[M], now[M], sz[M], place[M], q, p; vector<int> g[M]; void maket(int l, int r, int t) { tr[t].l = l; tr[t].r = r; if (l == r) { tr[t].sum += now[a[l]]; retur...
#include <bits/stdc++.h> using namespace std; const int MAX = 1000; long long d[MAX + 10][3][3]; string s; int n; long long dyn() { if (s[1] == 0) d[1][0][0] = 1; d[1][0][2] = 1; if (s[0] == 0 && s[1] == 1) d[1][1][1] = 1; if (s[0] == 1) d[1][2][2] = 1; for (int i = 1; i <= n - 2; i++) ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); string s; cin >> s; string ans = 0 ; int curr = 0; for (int i = 1; i < n; i++) { if (s[i] == ( ) curr = curr ^ 1; ans += (char)(curr + 0 ); if (s[i] == ) ) curr = curr ^ 1; } ...
#include <bits/stdc++.h> using namespace std; int n; long long c[200005]; int b[200005]; int a[100005]; void up(int n, int k) { if (!n) return; while (n <= 200000) { b[n]++; c[n] += k; k++; n <<= 1; } } void solve(int n) { int cur = 0; long long num = n * 2; ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10, mod = 1e9 + 7; long long n, x; long long f[N]; void solve() { scanf( %lld , &n); long long s1 = 0, s2 = 0, ans = 0; for (long long i = 1; i <= n; i++) { scanf( %lld , &x); if (x == 1) s1++; else ...
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 10; int n, tmp, ans, p[N], q[N], pos[N]; vector<pair<int, int> > vec; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int i, j; cin >> n; for (i = 1; i <= n; ++i) cin >> p[i]; for (i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; int n, k; const int N = 1e7 + 100; bool a[N]; int main() { cin >> n >> k; vector<long long> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; a[v[i]] = 1; } int q; cin >> q; for (int test = 0; test < q; test++) { long l...
#include <bits/stdc++.h> int main(void) { int n; int i, i2; int a[100000] = {0}; int flag = 0; int max = -1000001; int min = 1000001; int sum = 0; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a[i]); if (a[i] > 0) { if (a[i] < min && a[i] % 2 != 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int sum = 0; sum += 2 * n / k; if (2 * n % k != 0) sum++; sum += 5 * n / k; if (5 * n % k != 0) sum++; sum += 8 * n / k; if (8 * n % k != 0...
#include <bits/stdc++.h> using namespace std; const int mo = 1000000007; const int inv2 = (mo + 1) / 2; const int inv4 = (mo + 1) / 4; const int N = 500005; int dep[N], fa[N], deg[N]; int sz[N], p[N], cnt[N], n, m, nd; vector<int> e[N], vec[N]; int power(int x, int y) { int s = 1; for (; y; y ...
#include <bits/stdc++.h> using namespace std; const int maxN = 100100; const int maxM = maxN << 1; const int maxB = 17; int n, Q, Log[maxN]; int edgecnt = -1, Head[maxN], Next[maxM], V[maxM], W[maxM], Dst[maxN]; class Tree { public: int root, Dep[maxN], Fa[maxN], Dst[maxN], Mx[maxN], ST[maxB][maxN]...
#include <bits/stdc++.h> using namespace std; long long N; pair<long long, long long> arr[6005]; long long cnt[20][20]; bool good(int x1, int y1, int x2, int y2, int x3, int y3) {} int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for (int i = 1; i <= N; i++) { ...
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; string direc = URDL ; const long long MOD2 = (long long)1000000007 * (long lon...
#include <bits/stdc++.h> using namespace std; int read() { int X = 0, w = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) w = -1; c = getchar(); } while (c >= 0 && c <= 9 ) X = X * 10 + c - 0 , c = getchar(); return X * w; } const int N = 100000 + 10; ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007, oo = 1000000009; void Emsawy() {} int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, -1, -1, 1}; vector<vector<pair<int, int> > > adj; int n, m, k, w, h; struct Node { vector<int> ord; int cnt; Node() ...
#include <bits/stdc++.h> using namespace std; const int N = 200001; const int INF = 1061109567; int n, m; struct Edge { int to, val, id, next; } edge[N << 1]; int head[N], cnt; void add_edge(int u, int v, int w, int id) { cnt++; edge[cnt].to = v; edge[cnt].val = w; edge[cnt].id = id;...
#include <bits/stdc++.h> using namespace std; long long dp[102][102][2]; int m = 100000000; int main() { int n1, n2, k1, k2; cin >> n1 >> n2 >> k1 >> k2; int i, j, l1; for (i = 0; i <= n1; i++) { for (j = 0; j <= n2; j++) { if (i + j == 0) dp[i][j][0] = 1, dp[i][j][1] = 1...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long int n, m; cin >> n >> m; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; priority_queue<int> pq; long long int res[n]; pq.push(a[0]);...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int ans = 0; while (n != 0) { ans++; string s = to_string(n); int maior = s[0] - 0 ; for (int i = 0; i < s.size(); i++) { maior = max(maior, s[i] - 0 ); } n -= maior; ...
#include <bits/stdc++.h> using namespace std; vector<int> q[250000]; int color[250000]; int a[250000], b[250000]; int ssum[250000]; int main() { int n; cin >> n; for (int i = 0; i < n - 1; i++) scanf( %d%d , &a[i], &b[i]); for (int i = 1; i <= n; i++) scanf( %d , &color[i]); int sum = 0;...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 20; struct edge1 { int v, w; }; struct edge2 { int u, v, w; } e[N]; struct qry { int u, w, id; } q[N]; vector<edge1> G[N]; int n, m, c, a[N], dep[N], ans1[N], ans2[N], f[N][M], g[N][M]; void add(int u,...
#include <bits/stdc++.h> using namespace std; double dist(long long int a, long long int b, long long int c, long long int d) { return sqrt(((a - c) * (a - c)) + (b - d) * (b - d)); } struct p { double val; long long int index; }; int comp(const void* a, const void* b) { if (((...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > cpu(3); vector<vector<int> > g(201); int vs[201]; bool mission[201]; int start[3]; int ans = 1000000000; int main() { int n, startms; cin >> n; start[0] = -1; start[1] = -1; start[2] = -1; for (int i = 0; i < n; +...
#include <bits/stdc++.h> using namespace std; long long const N = 5e5; long long a[N]; void init_code() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void solve() { long long n, d, e; cin >> n >> d >> e; long long md = n / d; long long me = n / (5 * e); ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; int k, w, total; cin >> k >> n >> w; total = k * w * (w + 1) / 2 - n; if (total <= 0) { cout << 0 << endl; } else { cout << total << endl; } }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; void process() { vector<vector<char> > d(8, vector<char>(8)); int x1 = 8, y1 = 8, x2 = 8, y2 = 8; vector<vector<pair<int, int> > > steps( 8, vector<pair<int, int> >(8, make_pair(-INF, -INF))); for (int i = 0; i < 8; i++) ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int c = 2; int max = 2; for (int i = 2; i < n; i++) { if (arr[i] == (arr[i - 2] + arr[i - 1])) { c++; if (c > max) ...
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, p; int a[33], c[100010][33]; int fac[100010], inv[100010]; int l, r, L, R, len, Ans; inline int Pow(int x, int y) { int Ans = 1; for (; y; y >>= 1, x = 1ll * x * x % p) if (y & 1) Ans = 1ll * Ans * x % p; return Ans; } in...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6, inf = 2e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tc; cin >> tc; while (tc--) { int n, x, y, d; cin >> n >> x >> y >> d; if (x == y) cout << 0 n ; else if (abs(y - x) %...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a % b != 0) return gcd(b, a % b); return b; } int main() { int n, x = 0, y = 0; cin >> n; string a, b; cin >> a >> b; int k = a.size() * b.size() / gcd(a.size(), b.size()); for (int i = 0; i < k; i++) { ...
#include <bits/stdc++.h> using namespace std; typedef struct st { int a; string b; } st; bool func(st x, st y) { if (x.a == y.a) return x.b > y.b; else return x.a > y.a; } int main() { string a; cin >> a; int sum1 = 0; for (int i = 0; i < a.size(); i++) sum1 += a[...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 7; double dist(double a, double b, double x, double y) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } int n, i; double px, py, a1, a2, b1, b2, c1, c2, x1, x2, asfdasgas, y2, t...
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m >> n; double ans = m; double i = 1; while (1) { if (i >= m) break; double j = (m - i) / m; double k = 1; int q = n; while (q != 0) { if (q & 1 == 1) k *= j; q = q >> 1; ...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } x *= f; } const int N = ...
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; for (int i = 0; i < int(a.size() - 2); ++i) { char x = a[i], y = a[i + 1], z = a[i + 2]; if (x != . && y != . && z != . ) if (x != y && x != z && y != z) { cout << Yes << endl; r...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long i, j, k; int n; cin >> n; vector<int> arr(n); int f, l; f = 1; l = n; int sz = 0; while (sz < n) { if (sz % 2 == 0) { arr[sz] = f; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; vector<int> d; for (int i = 0; i < n; ++i) { int pos = upper_bound(d.begin(), d.end(), a[i]) - d.begin(); if (pos == d.size()) d.push_back(a[i]);...
#include <bits/stdc++.h> using namespace std; int main() { long long x; x = 2; long long n; cin >> n; for (long long i = 1; i <= n; i++) { long long y = (x / i); if (y >= i * (i + 1) * (i + 1)) { throw 1; } printf( %I64d n , i * (i + 1) * (i + 1) - y); x = i...
#include <bits/stdc++.h> using namespace std; const int MAXp = 100000; int p, d; int p10[8]; int dig[8]; bool ip[MAXp]; int num[8]; vector<int> v[6][10][6][MAXp / 100]; int ans = 0; void init() { p10[0] = 1; for (int i = 1; i < 8; i++) p10[i] = p10[i - 1] * 10; ip[0] = ip[1] = 1; for...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; int n, par[N], up[N], h[N], max_h[N]; vector<int> child[N], vec, ans; void dfs(int v = 0) { for (int u : child[v]) { h[u] = max_h[u] = h[v] + 1; dfs(u); max_h[v] = max(max_h[v], max_h[u]); } sort(child[v].begi...
#include <bits/stdc++.h> int main() { int mem, arr[5001], i, tri = 0; scanf( %d , &mem); for (i = 1; i <= mem; i++) { scanf( %d , &arr[i]); } for (i = 1; i <= mem; i++) { if (i == arr[arr[arr[i]]]) { tri = 1; } } if (tri == 1) { printf( YES n ); } else {...
#include <bits/stdc++.h> using namespace std; int main() { long n, k, bottom, top; cin >> n >> k; bottom = 1; top = n; for (long i = 0; i < k - 1; i++) { if (i % 2 == 0) { cout << bottom << ; bottom++; } else { cout << top << ; top--; } ...
#include <bits/stdc++.h> using namespace std; const int N = 3050; int n, p, s; int sump[N], sum[N]; struct Student { int a, b, id; void input() { scanf( %d%d , &a, &b); } bool operator<(const Student &student) const { return b - a < student.b - student.a; } } data[N]; void del() { ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MOD = 1e6 + 3; const int N = 1e2 + 5; int n, wid, hei; long long f[N], phei[N]; struct matrix { long long a[N][N]; matrix() { memset(a, 0, sizeof(a)); } } base, cur; matrix operator*(matrix a, matrix b) { matrix a...
#include <bits/stdc++.h> const int MN = 100005, MS = 1 << 18 | 7; namespace HASH { const int mod = 1e9 + 7; const int bs = 29; const int iv = 758620695; int _w[MN << 1], *w = _w + MN; void init(int N) { w[0] = 1; for (int i = 1; i < N; ++i) { w[+i] = 1ll * w[i - 1] * bs % mod; w[-i] = ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int cnt = 0; int len = s.length(); for (int i = 0; i < len; i++) { if (s.at(i) == a ) cnt++; } int ltr = len - cnt; while (ltr >= cnt) { ltr--; len--; } cout << len; return 0...
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int P = 1e9 + 7; const int inf = 1e9; const long long Inf = 1e15; inline int IN() { char ch = getchar(); int x = 0, f = 0; while (ch < 0 || ch > 9 ) ch = getchar(), f = (ch == - ); while (ch >= 0 && ch <= 9 ) { ...
#include <bits/stdc++.h> const int N = 200000; int f[N + 5]; namespace segt { const int S = (N << 2); struct type { int mn, lm, rm, m, s; friend type operator+(const type &a, const type &b) { type c; c.mn = std::min(a.mn, b.mn), c.m = std::max(a.m, b.m); if (a.mn < b.mn) { c....
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= ch == - , ch = getchar(); while (isdigit(ch)) x = 10 * x + ch - 0 , ch = getchar(); return f ? -x : x; } inline long long llread() { long long x = 0, f = 0...
#include <bits/stdc++.h> int main() { int n, m; int b[200]; int t[200]; int tmp; scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) t[i] = 1; for (int i = 0; i < m; ++i) { scanf( %d , &tmp); for (int j = tmp; j <= n; ++j) { if (t[j] == 1) { b[j] = tmp; ...
#include <bits/stdc++.h> using namespace std; void read (int &x) { char ch = getchar(); int f = 0; x = 0; while (!isdigit(ch)) { if (ch == - ) f = 1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x; } const int N = 3e5 + 5; int n, a[N], f[N], fr...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); bool ch = 0; bool arr[n + 1]; vector<int> vec, vec1; for (int i = 0; i < m; i++) { int a, b; scanf( %d%d , &a, &b); if (b > a) swap(a, b); vec.push_back(a); vec1.push_bac...
#include <bits/stdc++.h> using namespace std; int main() { int a; bool p = 1; cin >> a; int A[a]; for (int i = 0; i < a; i++) { cin >> A[i]; if (A[i] == 1) { p = 0; } } if (p) { cout << EASY ; } else { cout << HARD ; } return 0; }
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return (a > b) ? a : b; } long long min(long long a, long long b) { return (a < b) ? a : b; } vector<long long> ar[100010]; long long vis[100010], dist[10001]; long long solve() { return 0; } long long cc; double pi ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, c, a; cin >> n >> c; vector<int> arr; for (int i = 0; i < n; i++) { cin >> a; arr.push_back(a); } int maxx = 0; for (int i = 0; i < n - 1; i++)...
#include <bits/stdc++.h> using namespace std; const int maxn = 100001; long long h, c, temp; long double f(long long m) { long double r = 1.0 * (m * h + (m)*c) / (2 * m); return (abs(r - temp)); } long double f12(long long m) { long double r = 1.0 * (m * h + (m - 1) * c) / (2 * m - 1); retur...
#include <bits/stdc++.h> int n, p[4005], f[4005][4005], w[4005], tl; void solve() { scanf( %d , &n); n <<= 1; for (int i = 1; i <= n; ++i) scanf( %d , &p[i]); tl = 0; int pre = 1; w[++tl] = 1; for (int i = 2; i <= n; ++i) { if (p[i] < p[pre]) w[tl]++; else { p...
#include <bits/stdc++.h> using namespace std; long long m, d; long long a[1000][1000]; long long me[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> m >> d; long long cnt = 1, cnt1 = 0; long long pr = 0; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 4e18; const int inf = 2e9; const double eps = 1e-13; const int N = 1e5 + 5; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int mod; int a[N]; int b[N]; void norm(int &x)...
#include <bits/stdc++.h> template <class _T> bool maximize(_T &a, _T b) { return a < b ? a = b, 1 : 0; } template <class _T> bool minimize(_T &a, _T b) { return a > b ? a = b, 1 : 0; } const int ooit = 2e9; const long long ooll = 1e15; using namespace std; int n, q, a[200005]; void enter()...
#include <bits/stdc++.h> using namespace std; const int INFint = 2147483647; const long long INF = 9223372036854775807ll; const long long MOD = 1000000007ll; const long double EPS = 1e-9; vector<int> p; vector<int> used; vector<vector<int> > g; long long ans = 0; void dfs(int v) { used[v] = 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1000 * 100 + 10, Z = 26, P = 2, mod = 1e9 + 9; int pw[N], wp[N], n, m, tar[Z], hsh[N][Z]; string s, t; long long Pow(long long a, long long b) { return b ? (b & 1 ? a : 1) % mod * Pow(a * a % mod, b >> 1) % mod : 1; } int add(int a, int b...
#include <bits/stdc++.h> using namespace std; const int N = 1001; bool used[N][N]; bool best[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); vector<pair<int, int>> points(3); for (auto& [x, y] : points) { cin >> x >> y; } int x, y, cnt; auto update_x = [&](int a...
#include <bits/stdc++.h> int main() { long int a, i, s; scanf( %ld , &a); s = a; if (a != 1) { for (i = 2;; i++) { s = s + 1 + i * (a - i); if ((a - i) == 0) { break; } } printf( %ld , s); } else { printf( 1 ); } }
#include <bits/stdc++.h> using namespace std; int A[] = {2, 3, 5, 7, 11, 13, 17, 19}, n, B[5005], vmax; priority_queue<int> Q; set<int> S; inline int sol(int i) { int j, k, t, first, second; B[0] = 1; for (j = 1; j <= n; j++) { first = B[j - 1] * A[0]; for (t = 0; t < j; t++) f...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int teamA, teamB, y1, y2, y; cin >> teamA >> teamB >> y1 >> y2 >> y; int min = y - (teamA * (y1 - 1) + teamB * (y2 - 1)); if (min < 0) { cout << 0 << ; } else { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; long long a[maxn], s1, s2; double ans[maxn]; int l[maxn], r[maxn]; vector<int> gao[6][maxn]; int n, m, pos; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); l[1] = 1; for (int i = 2; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; char arr[105]; scanf( %d%*c , &t); while (t--) { gets(arr); int len = strlen(arr); char temp[20] = {arr[len - 5], arr[len - 4], arr[len - 3], arr[len - 2], arr[len - 1]}; char tem[20] = {...
#include <bits/stdc++.h> using namespace std; long long n, a, pertama, kedua, sum; vector<pair<long long, int> > v; priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > pq; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.second ==...
#include <bits/stdc++.h> using namespace std; vector<int> prime_pair; int least[1001]; void sieve(int n) { vector<int> pr, prime; for (int i = 2; i <= n; i++) { if (!least[i]) { least[i] = i; pr.push_back(i); } for (int j = 0; j < pr.size() && pr[j] <= least[i] && i * p...
#include <bits/stdc++.h> using namespace std; long long n, q, ar[200000], ans[200000]; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) cin >> ar[i]; for (int i = 0; i < n - 1; i++) { q = 1; while (i + q * 2 < n) q *= 2; ar[i + q] += ar[i]; i...
#include <bits/stdc++.h> int main() { static int aa[200000], pp[200000], qq[200000]; int n, k, i, p, q; long long x, xk, ans, a; scanf( %d%d%lld , &n, &k, &x); for (i = 0; i < n; i++) scanf( %d , &aa[i]); for (i = 0, p = 0; i < n; i++) { pp[i] = p; p |= aa[i]; } for (i = n ...
#include <bits/stdc++.h> using namespace std; string s; double ans; int cnt[200]; vector<int> v[200]; int main() { cin >> s; double n = s.size(); for (int i = 0; i < n; i++) v[s[i]].push_back(i); for (char i = a ; i <= z ; i++) { if (!v[i].empty()) { int x = v[i][0]; ...
#include <bits/stdc++.h> using namespace std; const int sz = 2e5; int n, k; long long add[sz], cost[sz], pre[sz], suf[sz], mnpre[sz], mnsuf[sz], bestSufTake[sz], bestSufTakeFromPre[sz]; void input() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> add[i]; for (int i = 0; i < n; i++) cin >...
#include <bits/stdc++.h> using namespace std; int n, i, x, y, lsum = 1, root, tot, Ans1, Ans2; int head[400010], f[400010], size[400010], d[400010], p[400010], l[400010], g[400010], o[400010]; vector<int> son[400010]; map<int, int> M; struct Edge { int t, next, l; } e[400010 * 8]; inline int F...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long n, l = 1, r; cin >> n; r = n; if (n == 1) { cout << 1 << endl << 1; return 0; } if (n == 2) { cout << 1 << endl << 1; return 0...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; ...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, vector<T> v) { os << [ ; string sep; for (const T& el : v) os << sep << el, sep = , ; return os << ] ; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int mod = 998244353; int sum(int a, int b) { int s = a + b; if (s >= mod) s -= mod; return s; } int mult(int a, int b) { return (1LL * a * b) % mod; } int pw(int a, int b) { if (b == 0) return 1; if (b & 1) ...