func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; pair<int, int> volc[100000]; int main() { int n, m; scanf( %d , &n); scanf( %d , &m); for (int i = 0; i < m; i++) { scanf( %d , &volc[i].first); scanf( %d , &volc[i].second); } sort(volc, volc + m); int x = 0; vector<pair<in...
#include <bits/stdc++.h> using namespace std; struct Polynom { long long x, y; } a[6001], b[6001]; int main() { string s; cin >> s; if (s.length() == 1) { cout << s << endl; return 0; } for (int i = s.length(); i > 0; i--) s[i] = s[i - 1]; int n = s.length(); long lon...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; int main() { ios::sync_with_stdio(0); int n; cin >> n; long long int a[10000], sum[10000], all[10000], m[10000]; memset(all, 0, sizeof(all)); for (int i = 2; i < pow(2, n + 1); i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); vector<complex<double> > fft(const vector<complex<double> >& as) { int n = (int)as.size(); int k = 0; while ((1 << k) < n) k++; vector<int> r(n); r[0] = 0; int h = -1; for (int i = 1; i < n; i++) { if ...
#include <bits/stdc++.h> using namespace std; char grid[512][512]; bool used[512][512]; int n, m; struct op { char type; int x, y; op() {} op(char c, int a, int b) { type = c; x = a; y = b; } }; vector<op> res; int dx[4] = {0, -1, 0, 1}; int dy[4] = {1, 0, -1, 0};...
#include <bits/stdc++.h> using namespace std; long long n, a[1005]; int main() { scanf( %I64d , &n); for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); sort(a + 1, a + n + 1); long long ans = 0; for (int i = 2; i <= n; i++) ans += a[i] - a[i - 1] - 1; printf( %I64d n , ans); return 0;...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; bool f = false; for (int x = 0; x < n; x++) { cin >> a[x]; if (a[x] == 1) f = true; } if (f) { cout << -1; } else cout << 1; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxN = 50 + 10; long long dp[maxN]; int used[maxN]; int main() { int n; long long l; cin >> n >> l; dp[0] = 1; dp[1] = 1; for (int i = 2; i < maxN; i++) dp[i] = dp[i - 1] + dp[i - 2]; l--; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; void Emsawy() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const double PI = acos(-1.0); const double eps = 1e-10; const long long mod = 1e9 + 7, oo = 1e9; int dx[]{1, -1, 0, 0, 1, -1, 1, -1}; int dy[]{0, 0, 1, -1, 1, -1, -1, 1}; v...
#include <bits/stdc++.h> using namespace std; int nod, edge; int a[401][401]; int dist[401]; int vis[401]; int bfs(int node) { queue<int> q; q.push(node); vis[node] = 1; while (q.size()) { int cur = q.front(); q.pop(); if (cur == nod) return dist[cur]; for (int i = no...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int f = 0; int a[502] = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496}; ...
#include <bits/stdc++.h> using namespace std; struct point { int x, y; int det(point p) { return x * p.y - y * p.x; } }; point a[10], b[10]; int GetCross(point p1, point p2, point p) { return (p2.x - p1.x) * (p.y - p1.y) - (p.x - p1.x) * (p2.y - p1.y); } bool check(point p) { return GetCro...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int sqrtn = 505; int l = 1, r, sum, cant; int n, m, p, s[maxn], w[maxn], cnt[maxn], last[maxn], pre[maxn], nxt[maxn], qwq[maxn][sqrtn], num[maxn]; vector<int> v; struct node { int l, r, id; } a[maxn]; inline bool cm...
#include <bits/stdc++.h> using namespace std; int a[123][123], b[123][123], f1[54][54][54][54], f2[54][54][54][54]; int n; void getans(int i1, int j1, int i2, int j2) { int i, j, t; printf( ? %d %d %d %d n , i1, j1, i2, j2); fflush(stdout); scanf( %d , &t); if (t == f1[i1][j1][i2][j2]) { ...
#include <bits/stdc++.h> using namespace std; bool isprime(int n) { for (int i = 2; i < n; i++) { if (n % i == 0) { return false; } } return true; } int main() { int n; cin >> n; string s; cin >> s; int diff = 1; int i = 0; while (i < n) { cout <...
#include <bits/stdc++.h> using namespace std; vector<pair<char, pair<int, int> > > closest(10, make_pair( * , make_pair(0, 0))); int n, X, Y; int check_dir(int x, int y) { if (x == X && y > Y) return 1; if (x == X && y < Y) return 5; if (Y == y && x > X...
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i += 6) {...
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 5; int n, a[N], m, k; long long ans; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); if (n % 2 == 0) { puts( 0 ); return 0; } int mn = N * 100; for (int i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; string ITS(long long x) { string s = ; while (x > 0) { s += (char)(x % 10 + 0 ); x /= 10; } string t = ; for (int i = s.size() - 1; i > -1; i--) t += s[i]; return t; } long long inf = 1e9; long long mod = 1e9 + 7; const l...
#include <bits/stdc++.h> using namespace std; long long n = 0, m = 0, q = 0; long long ans = 0; vector<vector<int>> G = vector<std::vector<int>>(100001); vector<long long> f(112345), fa(100001), dep(100001), val(100001), sz(100001), s(100001); long long F(long long x) { return x == f[x] ? x : (f[x] = ...
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const long long maxn = 1000001, mod = 1e9 + 7; int main() { ios_base::sync_with_st...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = 3e5 + 5, M = 1e8 + 5, OO = 1000000; int T, n, m; int u, v; int deg[N]; int main() { scanf( %d , &n); for (int i = 1; i < n; ++i) { scanf( %d %d , &u, &v); ++deg[u], ++deg[v]; } for (int i = 1...
#include <bits/stdc++.h> #pragma GCC target( sse ) const int maxn = 2e5 + 5; struct IO { char c; inline char gc() { static char buf[maxn], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, maxn, stdin), p1 == p2) ? EOF : *p1++; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, i, j, k, sum = 0, ev = 0, ze = 0; string s; cin >> s; n = s.length(); for (i = 0...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans; cin >> n; long long a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ans = a[0]; for (int i = 1; i < n; i++) { a[i] += ans; if (a[i] - ans > 0) { ans = a[i]; } } for (int i = ...
#include <bits/stdc++.h> using namespace std; int MOD = 1000000007; int tree[20000][2]; int main() { ios::sync_with_stdio(0); int n, a, b, k; cin >> n >> a >> b >> k; for (int i = 1; i <= n; i++) { if (i != b) tree[i][0]++; } int h = 1; for (int j = 1; j <= k; j++) { for ...
#include <bits/stdc++.h> template <typename T> bool Chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool Chkmin(T &x, T y) { return y < x ? x = y, true : false; } const int MAXN = 1e5 + 1e4, MAXK = 5 + 5; const double eps = 1e-4; int n; int k; std::pair<int,...
#include <bits/stdc++.h> int mod = 1000000007; using namespace std; using namespace std; int n, k; int a[400005]; int pos[400005]; map<int, int> m; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; cin >> n >> k; for (int i = 1; i <= n; i++) pos[i] = 1e7; m[a[...
#include <bits/stdc++.h> using namespace std; int main() { int n = ({ int x; scanf( %d , &x); x; }); string s; cin >> s; string ans = no ; for (int d = (1); d < (30); d += (1)) { for (int i = (0); i < (n); i += (1)) { int g = 1; for (int j = (0); j < ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair<int, int>; using C = complex<double>; const double PI = 3.14159265; const double eps = 1e-8; const int N = 1 << 17; const int M = 1e9 + 7; const int inf = 1e...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long x, y; cin >> x >> y; long long l = x - y; l = l < 0 ? -l : l; int r = l % 10; long long a = l / 10.0; if (r) a++; cout << a; cout << n ; } } ...
#include <bits/stdc++.h> using namespace std; const long double INF = 1e9; const long double EPS = 1e-9; long double dist(long double x1, long double y1, long double x2, long double y2) { return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)); } long double func(long double X, long double Y, ...
#include <bits/stdc++.h> using namespace std; int v, e; vector<int> out[30005]; vector<int> ans; bool vis[30005]; void dfstree(int n) { for (auto x : out[n]) { if (!vis[x]) { vis[x] = true; dfstree(x); } } ans.push_back(n); } int main() { cin >> v >> e; fo...
#include <bits/stdc++.h> using namespace std; long long n, a[300005], ans; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); for (int i = 1; i <= n / 2; i++) { ans += (a[i] + a[n - i + 1]) * (a[i] + a[n - i + 1]); } cout << ans; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100; int n, m, ans; int num[maxn]; set<int> st[2]; set<int>::iterator it, itt; void get_st(int begin, int end, set<int> &st) { st.clear(); st.insert(0); for (int i = 0; i < (1 << (end - begin)); ++i) { int tmp = 0; for ...
#include <bits/stdc++.h> using namespace std; int n, m, a[200005], head[200005]; struct edge { int to, nxt; edge(int _t = -1, int _n = -1) { to = _t; nxt = _n; } } e[400005]; void addedge(int u, int v) { e[m] = edge(v, head[u]); head[u] = m++; e[m] = edge(u, head[v]); h...
#include <bits/stdc++.h> using namespace std; const int N = int(3e5), mod = int(1e9) + 7, block = 316; int n, m, q; vector<int> g[N], comp[N], heavy, di[N]; int root[N], cur, sz[N], d[N], dr[N], d1[N], d2[N]; bool used[N]; bool h[N]; long double ans[N], fans[N]; vector<pair<int, int> > qu[N]; void d...
#include <bits/stdc++.h> using namespace std; int a, b, c, d, p; int main() { cin >> a >> b >> c >> d; d -= c - 1; a -= c; b -= c; if (d == 2) { a--; b--; p = 3; } if (d == 1) { if (a) { a--; p = 1; } else { b--; p = 2; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n, k; int ver[maxn], t[maxn], dp[maxn], tin[maxn], cnt = 0, tout[maxn], h[maxn], p[maxn][30], important[maxn], ans = 0; vector<int> e[maxn]; void dfs(int u, int par = 0) { cnt++; tin[u] = cnt; h[u] = h[par] + 1; ...
#include <bits/stdc++.h> using namespace std; string ar; string br; int n = 0, lst = 0, lstmin = 0, lp = 0, lpc = 0; int gzg = 0, rzg = 0, gzy2 = 0, rzy2 = 0; int gzf = 0, gzc = 0, rzf = 0, rzc = 0; int gzcc = 0, rzff = 0; int main() { int f = 0; cin >> n; ar.reserve(n + 1); br.reserve(n...
#include <bits/stdc++.h> using namespace std; int ToInt(string& s, int len) { int r = 0; for (int i = 0, max_ = (len); i < max_; ++i) { r *= 10; r += s[i] - 0 ; } return r; } int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; } int LCM(int a, int b) { return a * (b / GCD(a...
#include <bits/stdc++.h> using namespace std; int cnt[(100000 + 10)]; int f[(100000 + 10)]; int main() { int n; cin >> n; int ans = 0; int mx = 0; for (int i = 1; i <= n; i++) { int v; cin >> v; cnt[f[v]]--; f[v]++; cnt[f[v]]++; int ok = 0; mx = max(...
#include <bits/stdc++.h> using namespace std; template <class T> inline void amin(T &x, const T &y) { if (y < x) x = y; } template <class T> inline void amax(T &x, const T &y) { if (x < y) x = y; } template <class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp = 0...
#include <bits/stdc++.h> using namespace std; struct art { int t, d, p, id; } a[101]; pair<int, int> go[101][2001]; bool cmp(art xx, art yy) { return xx.d < yy.d; } int f[101][2001], num[101][2001], ans[1000], tt; int main() { int n; cin >> n; for (register int i = 1; i <= n; i++) ci...
#include <bits/stdc++.h> int main() { int i = 0, z, flag = 0, even = 0; char str[100002], temp; scanf( %s , str); int size = strlen(str); char x = str[size - 1]; for (i = 0; i < size; i++) { if (str[i] % 2 == 0) { even = 1; if (str[i] < x) { flag = 1; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; long long n; bool valid(long long x) { long long a = 0, b = 0; long long r = n; while (r) { a += min(r, x); r -= min(r, x); b += r / 10; r -= r / 10; } return a >= b; } signed main() { io...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_str...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 7; int T, n, t, a[N]; map<long long, long long> mp; int main() { scanf( %d , &T); while (T--) { mp.clear(); scanf( %d%d , &n, &t); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); } if (t % ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; int dp[maxn][2]; int n, cnt = 1, head[maxn], to[maxn], nxt[maxn], val[maxn]; inline void add(int x, int y, int z) { nxt[++cnt] = head[x]; head[x] = cnt; to[cnt] = y; val[cnt] = z; } void dfs(int x, int fa) { for (i...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int a, b, c; scanf( %d%d%d , &a, &b, &c); int temp = 0; if (a == b && b == c) { printf( 0 n ); } else { if (b > a) { temp = b; b = a; a = ...
#include <bits/stdc++.h> using namespace std; int fireball1, fireball2, health[100], attack[100], attack1[100]; int n, sum = 2e+8; void dfs(int x, int y) { if (y >= sum) return; if (x == n) { sum = y; for (int i = 1; i <= n; i++) attack[i] = attack1[i]; return; } for (int i = 0...
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 3000; int n, m; int a[maxn], l[maxn], r[maxn], pos[maxn]; struct Segtree { int l, r; int val; } node[maxn << 3]; inline int read() { int x; scanf( %d , &x); return x; } inline void build(int p, int l, int r) { ...
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } int n, m, k, s; vector<in...
#include <bits/stdc++.h> using namespace std; struct sb { long long x; long long y; bool operator<(const sb &wakaka) const { return x < wakaka.x; } } test; set<sb> node; int main() { long long x; cin >> x; long long len = 2 * pow((double)x, (double)1 / (double)3); long long cnt = 0...
#include <bits/stdc++.h> using namespace std; using namespace std; int n, a, b, ans; int main() { cin >> n; while (n--) { cin >> a >> b; a++, b--; while (b /= 4) a++; ans = max(ans, a); } cout << ans; }
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; const int N = 30 + 7; const int mod = 1e9 + 7; const int B = 317; int n; int u, r; int a[N][N]; int b[N]; int c[N]; i...
#include <bits/stdc++.h> using namespace std; long long ans; int n, l, w, x, pn; vector<int> pos, neg; int cal(long long a, int b) { if (b == 0) return (a > 0 ? INT_MAX : -INT_MAX); if (a < 0) { if (a % b != 0) return (a / b - 1); } return a / b; } int main() { ios::sync_with_std...
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; set<int> s; int m; pair<int, int> p[100001]; long long ans; const long long md = 1e9 + 9; int up[3][2] = {-1, 1, 0, 1, 1, 1}; int dwn[3][2] = {-1, -1, 0, -1, 1, -1}; int cnt(int ind) { int res = 0; int x = p[ind].firs...
#include <bits/stdc++.h> using namespace std; const long long maxn = 50050; const long long bign = 55000; long long n, m; long long tmp[bign], judge[bign]; long long ans, head[maxn], sz[maxn], maxp[maxn]; long long dis[bign], size; long long q[bign], targetnum; long long rt, tot, vis[maxn]; struct e...
#include <bits/stdc++.h> using namespace std; const int maxn = 12, mod = 1e9 + 7; long long dp[maxn][2][maxn]; int num[maxn]; long long dfs(int pos, bool bnd, int ned) { if (ned < 0) return 0; if (pos < 0) return ned == 0; long long& ndp = dp[pos][bnd][ned]; if (~ndp) return ndp; ndp = 0; ...
#include <bits/stdc++.h> using namespace std; int arr[100][100]; bool dp[100][100][1000]; bool W[100][100][1000]; int main() { int N; int M; int K; scanf( %d %d %d , &N, &M, &K); K++; char ch[101]; for (int n = 0; n < N; n++) { scanf( %s , ch); for (int m = 0; m < M; m+...
#include <bits/stdc++.h> using namespace std; long len; string a, b; const long long mo = 1000000007; long long good[200001], bad[200001]; int x, y, n; int main() { cin >> a >> b >> n; if (a.length() != b.length()) { cout << 0; return 0; } len = a.length(); bool f; for ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; unordered_map<bitset<maxn>, int> ma, flag; bitset<maxn> s[35]; int t1, t2; void dfs1(bitset<maxn> z, int cost, int pos) { if (pos > t1 + t2) { if (flag[z] == 0) ma[z] = cost; else ma[z] = min(ma[z], cost)...
#include <bits/stdc++.h> using namespace std; constexpr int maxn = 3e3 + 4; struct Node { int la, nx; } nodes[maxn]; int X[maxn], Y[maxn]; std::vector<int> yp[maxn]; int R, C, N, K; int ordX[maxn], ord[maxn]; int ans[maxn], xans = 0; inline void update(int x) { int c = x; for (int k = 1;...
#include <bits/stdc++.h> #pragma comment(linker, /stack:247474112 ) #pragma GCC optimize( Ofast ) using namespace std; string ans[2] = { Bob , Alice }; void solve() { long long n, k; cin >> n >> k; if (k % 3 != 0) { if (n % 3) cout << ans[1]; else cout << ans[0]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3000 + 50; const int maxm = 3000 + 50; const int maxt = 3000000 + 100; const int maxk = 10 + 3; const long long unit = 1LL; const int INF = 0x3f3f3f3f; const long long Inf = 0x3f3f3f3f3f3f3f3fLL; const double eps = 1e-3; const double inf...
#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]; } sort(a, a + n); for (int i = 0; i < n - 2; i++) { if (a[i] == a[i + 1] && a[i] == a[i + 2]) { cout << NO ; return 0; } ...
#include <bits/stdc++.h> using namespace std; int n; int maxt[5210][5210]; int a[5210][5210]; char str[5210]; int getn(char ch) { if (ch >= 0 && ch <= 9 ) { return ch - 0 ; } else { return 10 + ch - A ; } } int main() { scanf( %d , &n); memset(maxt, 0, sizeof(maxt));...
#include <bits/stdc++.h> using namespace std; using namespace std; const long long MOD = 1e9 + 7; const int INF = 1e9; int n, k, mn, mx, ans = INF; int a[8] = {0, 1, 2, 3, 4, 5, 6, 7}; char s[8][10]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 4; long long int a[N][20], pre[N][20], ans; struct node { node *left, *right; long long int cnt; node() { left = NULL; right = NULL; cnt = 0; } }; struct trie { node *x; }; void insert(node *t, long l...
#include <bits/stdc++.h> using namespace std; const int N = 100004; long long a[N], b[N]; int n, p = 0; long long fun(int n) { long long ans = 0, sum = 0; for (int i = 1; i <= n; i++) { sum += b[i]; if (sum < 0) sum = 0; ans = max(ans, sum); } return ans; } int main() { ...
#include <bits/stdc++.h> using namespace std; int A[55]; int main() { int n; long long int m; cin >> n >> m; if (n == 1) { printf( %d n , 1); return 0; } long long int tot = 1LL << (n - 1); int l = 1; int r = n; for (int i = 1; i < n + 1; i++) { if (m > tot / ...
#include <bits/stdc++.h> using namespace std; long long n, m, k, sum, num, ans; long long a[200005]; int main() { cin >> n >> m >> k; for (int i = 1; i <= m; i++) cin >> a[i]; sort(a + 1, a + m + 1); sum = 0, num = 1, ans = 1; for (int i = 2; i <= m; i++) { if ((a[i] - 1 - sum) / k != ...
#include <bits/stdc++.h> using namespace std; long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; class pa3 { public: long long x; long long y, z; pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3& p...
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define ll long long int #define ld long double #define pii pair<ll,ll> #define pb push_back #define rep(i,a,b) ...
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int numOfPoints(long long int &x, long long int &y, long long int &n, long long int t) { long long int region1 = 2 * t * (t + 1) + 1; long long int region2; if (y - t >= 1) region2...
#include <bits/stdc++.h> using namespace std; ifstream in; ofstream out; const long long kk = 1000; const long long ml = kk * kk; const long long mod = ml * kk + 7; const long long inf = ml * ml * ml + 7; long long n, i, j; vector<long long> m; vector<long long> bef[10 * kk]; bool viv = false; i...
#include <bits/stdc++.h> using namespace std; const int N = 330000; int a[N], m; long long dp[5500][5500]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); m = n / k; ...
#include <bits/stdc++.h> using namespace std; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<...
#include <bits/stdc++.h> using ll = long long; using ull = unsigned long long; using std::cin; using std::cout; void print() {} template <typename T, typename... Args> void print(T t, Args... args) { cout << t << , print(args...); } template <typename... Args> void println(Args... args) { ...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; const long long int MAXN = 100010; long long int par[MAXN], nxt[MAXN]; int find_root(int a) { if (par[a] == a) { return a; } int f = par[a]; par[a] = find_root(par[a]); nxt[a] = (nxt[a] + nxt[f]) % MOD; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long int> arr; arr.push_back(0); arr.push_back(1); if (n == 1) { cout << 1 << << 0 << << 0 << endl; return 0; } else if (n == 2) { cout << 1 << << 1 << << 0 << endl; ...
#include <bits/stdc++.h> using namespace std; int uf[310100]; int get_fa(int x) { return uf[x] == x ? x : uf[x] = get_fa(uf[x]); } struct Edge { Edge *next; int np; int id; } E[310100 * 2], *V[310100]; int tope = -1; void add_edge(int x, int y, int id) { E[++tope].np = y; E[tope].id = ...
#include <bits/stdc++.h> using namespace std; long long n; string s; long long cnt[10]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; cin >> s; for (long long(i) = (0); (i) <= (n - 1); (i)++) cnt[s[i] - 0 ]++; cout << min(n / 11, cnt[8]) << endl; return 0; }
#include <bits/stdc++.h> int main() { long n(0); scanf( %ld , &n); const long maxSquare = n * n; int total(0); for (long a = 1; a < n; a++) { for (long b = a; b < n; b++) { long sumOfSquares = a * a + b * b; if (sumOfSquares > maxSquare) { break; } i...
#include <bits/stdc++.h> using namespace std; vector<int> mil, omil; int main() { int n, t; string a, b; char c[100010]; cin >> n >> t; cin >> a; cin >> b; t = n - t; for (int i = 0; i < a.size(); i++) { if (a[i] == b[i]) mil.push_back(i); else omil.push...
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, k, fri = 0; cin >> n >> m >> k; vector<int> v; for (int i = 0; i < m + 1; i++) { int t; cin >> t; v.push_back(t); } int la = v[m]; vector<int> labit; for (int i = 0; i < 32; i++) { if ((1 <...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1000100; long long n, k, a[maxn]; string s; struct t { long long open = 0, close = 0, ans = 0; } tree[4 * maxn], ft; t merge(t x, t y) { t temp; temp.ans = x.ans + y.ans + min(x.open, y.close); temp.open = x.open + y.open...
#include <bits/stdc++.h> using namespace std; bool compare(pair<double, int> p1, pair<double, int> p2) { return p1.first > p2.first; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, t1, t2, k; cin >> n >> t1 >> t2 >> k; vector<pair<double, int>> participan...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long fact[100001]; vector<long long> vec[100001]; long long vis[100001], win[100001], flag[100001]; long long power(long long x, long long y) { long long res = 1; while (y) { if (y & 1) res = (res * x) % mod; ...
#include <bits/stdc++.h> using namespace std; struct node { int v, r, siz; node* ch[2]; long long sum[5]; void maintain() { int pre = 0; int s = 1; if (ch[0] != NULL) s += ch[0]->siz; pre = s; if (ch[1] != NULL) s += ch[1]->siz; siz = s; memset(sum, 0, sizeo...
#include <bits/stdc++.h> using namespace std; int n; vector<int> f, s; int main() { long long buf, sumf = 0, sums = 0; int last = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> buf; if (buf > 0) { f.push_back(buf); sumf += buf; last = 1; } else { ...
#include <bits/stdc++.h> using namespace std; int main() { int color[3], time = 30; for (int i = 0; i < 3; i++) cin >> color[i]; int maxi = *max_element(color, color + 3); int index; if (maxi == color[0]) index = 0; if (maxi == color[1]) index = 1; if (maxi == color[2]) index = 2; in...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); cout << fixed; int base; cin >> base; string s; cin >> s; vector<long long> dp(s.size() + 1); dp[0] = 0; long long MAX = 1e18; for (int i = ...
#include <bits/stdc++.h> using std::abs; using std::bitset; using std::cerr; using std::cin; using std::copy; using std::cout; using std::endl; using std::fill; using std::fixed; using std::greater; using std::lower_bound; using std::map; using std::max; using std::min; using std::next_per...
#include <bits/stdc++.h> using namespace std; bool exitInput = false; int ntest = 1, itest = 1; const char* directions[4] = { NE , SE , SW , NW }; const long long Mod = 1000000000LL + 7; const int maxn = 100 + 2; const int maxv = 1000000 + 5; const int maxe = 600000 + 5; const int root = 1; int a...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a % b == 0) return b; return gcd(b, a % b); } void solve() { int n; int ans = 0; cin >> n; int a[8008]; int b[8008] = {0}; for (int i = 1; i <= n; i++) { cin >> a[i]; b[i] = b[...
#include <bits/stdc++.h> using namespace std; int main(void) { int i, n; long long int s; s = 0; set<int> x, k; map<int, int> m, mu; cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; m[a[i]]++; x.insert(a[i]); } for (i = 0; i < n; i++) { if (k...
#include <bits/stdc++.h> const int N = 110; using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) { f = -1; } ch = getchar(); } while (ch <= 9 && ch >= 0 ) { x = (x << 1) + (x << 3) + ch ...
#include <bits/stdc++.h> using namespace std; int read(); const int N = 1.5e5 + 5; int n, p, k, m, a[N]; vector<pair<int, int> > seg[N << 2], res; int eq[N << 2]; void puteq(int k, int l, int r, int v) { eq[k] = v; seg[k].clear(); seg[k].push_back(make_pair(v, r - l + 1)); } bool cmp(const...