func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &t) { t = 0; char ch = getchar(); int f = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } do { (t *= 10) += ch - 0 ; ch = getchar(); } while ( 0 <= ch &&...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[100005]; int n, t, v[100005], c[100005]; int main() { cin >> n; for (int i = 0; i < n - 1; ++i) cin >> a[i].first >> a[i].second; for (int i = 0; i < n; ++i) cin >> c[i + 1]; for (int i = 0; i < n - 1; ++i) { if (c[a[i].first] ...
//Shrey Dubey #include<iostream> #include<string> #include<algorithm> #include<map> #include<unordered_map> #include<vector> #include<set> #include<list> #include<iomanip> #include<queue> #include<stack> #include <math.h> #include<climits> #include<bitset> #include<cstring> #...
#include <bits/stdc++.h> using namespace std; const pair<int, int> DD[] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; template <class T> T smin(T &a, T b) { if (a > b) a = b; return a; } template <class T> T smax(T &a, T b) { if (a...
#include <bits/stdc++.h> using namespace std; vector<long long int> v; int bil; void gen(long long int now) { if (now > 1000000000LL) return; if (now != 0) v.push_back(now); gen(now * 10 + 4); gen(now * 10 + 7); } int main(void) { gen(0); sort(v.begin(), v.end()); cin >> bil; ...
#include <bits/stdc++.h> using namespace std; long long const mod = 1e9 + 7; long long const N = 1e9 + 10; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, a[111] = {}, sol = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) {...
#include <bits/stdc++.h> using namespace std; long long n, i = 1; int main() { cin >> n; while ((n % i) == 0) i *= 3; cout << n / i + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < s.length() - 1; i++) { if (s[i] > s[i + 1]) { cout << YES << endl << i + 1 << << i + 2; return 0; } } cout << NO ; return 0; }
#include <bits/stdc++.h> using namespace std; const int p[] = {1, 2, 2, 1}; const int q[] = {1, 1, 2, 2}; const int N = 500005; int n, m; int a[N], b[N]; long long ans; void check(int& a, int b) { if (!a) a = b; else if (a != b) ans = 0; } int F(int a, int b) { return (b & 1) ? a...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, m, en, q[maxn], depth[maxn], f[maxn][20], dist[maxn]; struct edge { int e; edge *next; } * v[maxn], ed[maxn << 1]; void add_edge(int s, int e) { en++; ed[en].next = v[s]; v[s] = ed + en; v[s]->e = e; } ...
#include <bits/stdc++.h> using namespace std; struct ty { int d[4][11], a; } t[400005], ans; int n, m, q, x, y, a[11][100005], co[42], col, fa1, fa2, fa[42]; int find(int x) { if (x == fa[x]) return x; return fa[x] = find(fa[x]); } ty update(ty x, ty y) { ty z; for (int i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; using namespace std; string best; void LongestPalindromicPrefix(string str) { string temp = str + ? ; reverse(str.begin(), str.end()); temp += str; int n = temp.length(); int lps[n]; fill(lps, lps + n, 0); for (int i = 1; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; long double l[200006]; int main() { l[1] = 0; l[0] = 0; for (int i = 2; i < 200005; i++) { l[i] = log(i) + l[i - 1]; } int n, m, k; scanf( %d%d%d , &n, &m, &k); if (k >= m) { printf( 1.00000 n ); } else if (k + n < m) { ...
#include <bits/stdc++.h> using namespace std; vector<long long> adj[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); bool flag = true; int test_case = 1, tc; if (!flag) cin >> test_case; tc = test_case; while (tc--) { int i, j, n, m, sum ...
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { ios::sync_with_stdio(0); int n, mn = 1e9; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; mn = min(mn, a[i]); } int last = -1; int ans = n + 1e1; for (int i = 1; i <= n; ++i) { if (a[i...
#include <bits/stdc++.h> using namespace std; int main() { int hr, mt; int h, d, c, n; scanf( %d%d , &hr, &mt); scanf( %d%d%d%d , &h, &d, &c, &n); int p = h + max((1200 - (hr * 60 + mt)) * d, 0), t; if (p % n != 0) t = p / n + 1; else t = p / n; double ans = t * c * 0.8; ...
#include <bits/stdc++.h> using namespace std; long long n, clr[300001][3] = {{0}}; vector<long long> v[300001]; void dfs(long long node, long long parent) { for (auto x : v[node]) { if (x == parent) continue; dfs(x, node); clr[node][1] += clr[x][1]; clr[node][2] += clr[x][2]; } ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; int main() { int n; scanf( %d , &n); int a[n + 1], b[n + 1]; for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); } for (int i = 1; i <= n; ++i) { scanf( %d , &b[i]); } for (int i = 1; i <= n; ++i)...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T x, T y) { while (y > 0) { x %= y; swap(x, y); } return x; } template <class _T> inline _T sqr(const _T& x) { return x * x; } template <class _T> inline string tostr(const _T& a) { ostringstream ...
#include <bits/stdc++.h> template <typename T> std::istream& operator>>(std::istream& input, std::vector<T>& v) { for (T& a : v) input >> a; return input; } void answer(int v) { std::cout << v << n ; } void solve(const std::vector<size_t>& id) { int z = 0; std::unordered_map<size_t, size_t> ...
#include <bits/stdc++.h> std::pair<int, int> a[111111]; int main() { int i, n, m, max = 0; scanf( %d%d , &n, &m); for (i = 0; i < m; i++) scanf( %d%d , &a[i].first, &a[i].second); max = std::max(a[0].second + a[0].first - 1, a[m - 1].second - a[m - 1].first + n); for (i = 1; i...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, pos[N], ans[N]; vector<int> g[N]; map<int, int> tot; struct data { int a, i; } a[N]; bool cmp(data u, data v) { return u.a > v.a; } int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) { scanf( %d , &a[...
#include <bits/stdc++.h> using namespace std; long long n, m, aid = 1, did = 1, atk[105], def[105], c[105]; char s[10]; int main() { cin >> n >> m; for (long long i = 1; i <= n; i++) { scanf( %s , s); if (s[0] == A ) scanf( %lld , &atk[aid++]); else scanf( %lld , &def[...
#include <bits/stdc++.h> using namespace std; const int MX = 2020; const int MOD = 1e9 + 7; const long long INF = 1061109567; const long double EPS = 1e-9; const long double PI = acos(-1); const int MXX = 2e5 + 5; long long F[MXX + 5], iF[MXX + 5]; long long qpow(long long b, long long e) { if (!e...
#include<bits/stdc++.h> using namespace std; #define M 500000 typedef long long ll; typedef unsigned long long ull; inline ll read() { char ch; ll f = 1, res = 0; while ((ch = getchar()) < 0 || ch > 9 ) if (ch == - ) f = -1; while (ch >= 0 && ch <= 9 ) { res = (res << 1) + (res << 3...
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[1 << 16], *S, *T; if (S == T) { T = (S = buf) + fread(buf, 1, 1 << 16, stdin); if (T == S) return EOF; } return *S++; } inline long long read() { long long x = 0, f = 1; char ch = gc(); while...
#include <bits/stdc++.h> using namespace std; long long sq(long long x) { return x * x; } long double ptos(pair<long long, long long> A, pair<long long, long long> B, pair<long long, long long> C) { long long area = abs((B.first - A.first) * (C.second - A.second) - ...
#include <bits/stdc++.h> using namespace std; const long long N = 100005; vector<vector<long long> > adj(N), w(N); long long out[N], col[N], res[N], cnt; queue<long long> q; void dfs(long long v, long long p) { for (auto &u : adj[v]) { if (u == p) continue; dfs(u, v); } for (auto &u ...
#include <bits/stdc++.h> using namespace std; struct point { int x; int y; }; struct vec { int x; int y; }; point r_array[12], b_array[12]; int root[12]{}, ocupied[12]{}; int r, b; double cross(point a, point b, point c) { vec v1 = {c.x - a.x, c.y - a.y}; vec v2 = {b.x - a.x, b...
#include <bits/stdc++.h> using namespace std; using DO = double; using LL = long long; using VI = vector<LL>; const int N = 5e5 + 10; int head[N], nxt[N << 1], to[N << 1]; LL wei[N << 1]; int E; void init(int n) { for (int i = 1; i <= n; i++) { head[i] = -1; } E = 0; } void add(i...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int M = 205; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; struct node { int l, r, id; } p[N << 1]; bool cmp(node a, node b) { return a.r < b.r; } int sum[N << 4]; void update(int p, int L, int R, int pos) { if...
#include <bits/stdc++.h> using namespace std; int t, n, m, har[27]; string s; int sum[200005][27]; int main() { cin >> t; while (t--) { cin >> n >> m; cin >> s; for (int i = 0; i <= 25; i++) har[i] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) sum[i][j...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct node { int x, y; bool operator<(const node &_) const { return x < _.x || (x == _.x && y < _.y); } } A[2005]; int h, w, n; long long dp[2005], jie[200005 << 1], inv[200005 << 1]; long long Pow(long long x)...
#include <bits/stdc++.h> using namespace std; int n; vector<vector<int> > adj; vector<bool> top; vector<int> branched; vector<bool> visited; vector<bool> fertile; int root = -1; void fail() { cout << No << endl; exit(0); } void dfsFindRoot(int u) { if (root != -1) return; visited...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, ans = 0, a, b, t = 1; cin >> n >> x; while (n--) { cin >> a >> b; while (t <= a) t = t + x; t = t - x; ans = ans + b - t + 1; t = b + 1; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 10; long long bit[maxn]; void update(long long idx, long long v) { while (idx <= maxn) { bit[idx] += v; idx += idx & -idx; } } long long query(long long idx) { long long ans = 0; while (idx > 0) { an...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v, a; vector<pair<double, int> > ans; int n, sum, del, sx, sy, x, y, Nx, Ny; set<int> u; int cmp(pair<int, int> a, pair<int, int> b) { return ((a.first) * (a.first)) + ((a.second) * (a.second)) < ((b.first) * (b.first)) + (...
#include <bits/stdc++.h> using namespace std; long long ax, ay, bx, by, cx, cy; void check(long long axx, long long ayy) { if (cx == 0 && cy == 0) { if (axx == bx && ayy == by) { cout << YES ; exit(0); } else return; } if ((cx * (by - ayy) - cy * (bx - axx)) % (cx ...
#include <bits/stdc++.h> using namespace std; int A[2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; long long ans = 0; cin >> n; while (cin >> n) { ++A[n]; if (!n) ans += A[1]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; int ans[4005] = { 0, 1, 9, 245, 126565, 54326037, 321837880, 323252721, 754868154, 328083248, 838314395, 220816781, 893672292, 166441208, 251255697, 114256285, 118775501, 482714697, 11784725, 460862131, 55038...
#include <bits/stdc++.h> using namespace std; int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[9] = {0, 1, 0, -1, 1, -1, 1, -1}; struct edge { int st, ed; char col; edge() { this->st = 0; this->ed = 0; this->col = 0; } edge(int st, int ed, char col) { this->st = st; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { x = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } } int fr[100005], to[100005 << 1], ne[100005 << 1], x[100005]; i...
#include <bits/stdc++.h> using namespace std; long long dp[1005][1005]; int K; void init() { dp[0][0] = 0; dp[0][K + 1] = 1; for (int i = 1; i <= 1000; i++) { dp[i][0] = (dp[i - 1][1] * 2 + dp[i - 1][0] * 8) % 1000000007; for (int j = 1; j <= K; j++) dp[i][j] = (dp[i - 1][K + 1] ...
#include <bits/stdc++.h> using namespace std; inline long long mod(long long n, long long m) { long long ret = n % m; if (ret < 0) ret += m; return ret; } long long gcd(long long a, long long b) { return (b == 0LL ? a : gcd(b, a % b)); } long long exp(long long a, long long b, long long m) {...
#include <bits/stdc++.h> using namespace std; long long n, m, ans, ini, fin, med, idx; bool t[40]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (long long i = 0; i < m; i++) { cout << 1 n ; cout.flush(); cin >> ans; if (!ans) return 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 5001; long long n, m, a[N + 1], b[N + 1], type[N], l[N], r[N], x[N]; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) a[i] = 1e9; for (int j = 1; j <= m; j++) { cin >> type[j] >> l[j] >> r...
#include <bits/stdc++.h> using namespace std; int mat[105][105]; int n, m, res; void solve(int p) { if (p % 2) return; for (int i = 0, j = p - 1; i < p / 2; i++, j--) for (int k = 0; k < m; k++) if (mat[i][k] != mat[j][k]) return; res = res / 2; solve(p / 2); } int main() { ...
#include <bits/stdc++.h> using namespace std; const int M = 400005; int read() { int x = 0, flag = 1; char c; while ((c = getchar()) < 0 || c > 9 ) if (c == - ) flag = -1; while (c >= 0 && c <= 9 ) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return x * flag; } int...
#include <bits/stdc++.h> using namespace std; int n, ans, m; queue<int> q; int main() { cin >> n; int *a = new int[n + 1]; int *j = new int[n + 1]; memset(a, 0, sizeof(int) * (n + 1)); for (int i = 1; i <= n; i++) { cin >> j[i]; a[j[i]]++; if (a[j[i]] > 1) ans++; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 5; int a[maxn]; int main() { int n; cin >> n; int mn = 0x3f3f3f3f; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); mn = min(a[i], mn); } int ans = 0x3f3f3f3f; for (int i = 1; i <= n; i++) { i...
#include <bits/stdc++.h> using namespace std; void xx(int *a, int n) { for (int j = 1; j < n; ++j) for (int i = j; i <= n; ++i) if (a[j] < a[i]) { int t = a[i]; a[i] = a[j]; a[j] = t; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL)...
#include <bits/stdc++.h> using namespace std; bool check(long long x, long long y, long long p, long long q, long long t) { return p * t >= x && q * t - p * t >= y - x; } int main() { long long t; cin >> t; while (t--) { long long x, y, p, q, m; cin >> x >> y >> p >> q; long lo...
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int INF = 0x3f3f3f3f; const int iinf = 1 << 30; const long long linf = 2e18; const int mod = 1000000007; const double eps = 1e-7; void douout(double x) { printf( %lf n , x + 0.0000000001); } template <class T> void print(T a) ...
#include <bits/stdc++.h> using namespace std; const int N = 1000; const double eps = 1e-9; long long INF = 1e9; const int OO = 0x3f3f3f3f; int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, -1, -1, 1}; bool comp(pair<int, int> a, pair<int, int> b) { if (a.first < b.first) retu...
#include <bits/stdc++.h> using namespace std; long long xorsum(long long n, long long k) { if (k == 1) return n; int msb = (int)log2((double)n); if ((1ll << msb) > n) msb--; return (2ll << msb) - 1; } int main() { long long n, k; cin >> n >> k; cout << xorsum(n, k) << endl; retur...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; void manupulate(string &str) { for (long long int i = 0; i < str.size(); ++i) str[i] -= 48; } bool isprime(long long int n) { if (n <= 1) return false; for (long long int i = 2; i * i <= n; ++i) if (n % i == 0) retur...
#include <bits/stdc++.h> using namespace std; inline int read() { register int x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ 0 ); ch = getchar(); } return f ? x ...
#include <bits/stdc++.h> enum { N = 201 }; int n; int where[N][N]; int cnt[N] = {}; int what[N]; int set[N][N]; int sn[N] = {}; int eq(int i, int j) { int k; for (k = 0; k < n - 1; ++k) { if (where[i][k] != where[j][k]) return 0; } return 1; } int main(void) { scanf( %d , &...
#include <bits/stdc++.h> using namespace std; const int N = 42; int n, m; char s[N]; long long dp[N][N][2], nex[N]; void kmp_init() { int j = 0; nex[1] = 0; nex[0] = -1; for (int i = 1; i < n; i++) { while (j >= 0 && s[i + 1] != s[j + 1]) j = nex[j]; if (j == -1 || s[i + 1] == s[...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 100; int n, p, k; int dp[2][maxn][55][55]; int maks[2][2][maxn][55]; int tmaks[2][maxn]; int question[2][maxn]; int main() { scanf( %d %d %d , &n, &p, &k); int cnt, x; int res = 0; for (int i = 0; i < 2; ++i) { sc...
#include <bits/stdc++.h> using namespace std; typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev; const int INF = INT_MAX; const long long LINF = LLONG_MAX; const int MOD = 1000000000 + 7; const double EPS = 1e-9; const double PI = acos(-1); const int di[]{0, -1, 0, 1, -1, -1, 1, 1}; c...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e18 + 7; const long long N = 2e6 + 5; int main() { long long i, j, k, l = 0; long long n, m, t; cin >> n; for (long long i = 0; i < n; i++) cin >> k, l += k; if (l % n) cout << n - 1 << endl; else cout << n ...
#include <bits/stdc++.h> using namespace std; int num[100005]; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) { scanf( %d , &num[i]); } sort(num, num + n); if (n < k) { printf( %d n , num[n - 1]); return 0; } else { vector<int> ans; ...
#include <bits/stdc++.h> using namespace std; const int m5 = 100042; int main(void) { string s, ans = ; getline(cin, s); for (int i = 0; i < s.size(); i++) { if (s[i] == . ) { if (i == 0) { ans += ... ; } else { ans += ... ; } i += 2; ...
#include <bits/stdc++.h> int main(void) { int n, i, j; scanf( %d , &n); int a[n], h[3] = {0}, c[3] = {0}; for (i = 0; i < n; i++) { scanf( %1d , &a[i]); h[a[i]]++; } for (i = 0; i < n; i++) { if (h[a[i]] > n / 3) { c[a[i]]++; for (j = 0; j < 3; j++) { ...
#include <bits/stdc++.h> using namespace std; int minn(int, int, int); int main() { int x1, x2, x3; cin >> x1 >> x2 >> x3; int d1 = abs(x2 - x1) + abs(x3 - x1); int d2 = abs(x1 - x2) + abs(x3 - x2); int d3 = abs(x3 - x1) + abs(x3 - x2); cout << minn(d1, d2, d3) << endl; return 0; } ...
#include <bits/stdc++.h> using namespace std; long long sqr(long long x) { return x * x; } int mysqrt(long long x) { int l = 0, r = 1e9 + 1; while (r - l > 1) { int m = (l + r) / 2; if (m * (long long)m <= x) l = m; else r = m; } return l; } mt19937 rnd(1227);...
#include <bits/stdc++.h> using namespace std; int main() { int m, n; scanf( %d%d , &m, &n); int t[m][n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) scanf( %d , &t[i][j]); } int latest[m]; fill(latest, latest + m, 0); for (int i = 0; i < n; i++) { for (int j...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, vector<int>> mp; for (int i = 1; i <= n; i++) { int a; cin >> a; mp[a].push_back(i); } vector<pair<int, int>> ans; int cnt = 0; for (auto ele : mp) { int a = ele.first; ...
#include <bits/stdc++.h> using namespace std; int n, m, k, w, nm; char ls[1000][10][10]; int _d[1000][1000]; int used[1000], res[1000], sz = 0, c = 0; int main() { cin >> n >> m >> k >> w; nm = n * m; c = nm; for (int i = 0; i < k; i++) for (int y = 0; y < n; y++) for (int x = ...
#include <bits/stdc++.h> using namespace std; const int N = 15e4 + 5; int n, b[N]; long long a[N]; int prev(int x) { int y = x - 1; if (y == 0) y = n; return y; } int nxt(int x) { return x % n + 1; } int main() { scanf( %d , &n); bool f = true; for (int i = 1; i <= n; i++) scanf(...
#include <bits/stdc++.h> using namespace std; string str; int main() { long long int i, j, t, n; cin >> t; while (t--) { cin >> str; int ar[4]; for (i = 0; i < 4; i++) { ar[i] = 0; } int l = str.length(); int count = 0; int mn = l + 1; for (i = 0...
#include <bits/stdc++.h> using namespace std; long long n, c[6][223456], child[223456]; double ans[223456], res = 0.0; vector<pair<int, double> > ke[223456]; pair<pair<int, int>, double> way[223456]; int dad[223456]; void dfs1(int u, int par) { child[u] = 1; dad[u] = par; for (int i = 0; i < k...
#include <bits/stdc++.h> using namespace std; int n, k; void query(int x) { cout << ? ; for (int i = 1; i <= k + 1; ++i) if (i != x) cout << << i; cout << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; int x, y, px, py; query(k + 1); ...
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846; void solve() { long long n, m, a, b, k, x, y, queries; string s; cin >> n >> s; s = G + s; long long i = 1; while (i <= n) { if (s[i] == 8 ) break; i++; } if (i + 10 <= n) c...
#include <bits/stdc++.h> inline long long read() { char c; long long x; for (c = getchar(); !isdigit(c); c = getchar()) ; for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - 0 ; } return x; } const int N = 2e5 + 5; int n, q, d[N], f[N]; long long a[N], b[N], c[N], s[...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000000 ) using namespace std; int n, l[30], m[30], w[30]; int tw[30], P1, P2; map<pair<long long, long long>, pair<long long, long long> > mp; long long best = -(1ll << 58), msk1, msk2; void rec(int p, int msk, long long L, long long M, lon...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); long long n, r1, r2, r3, d; cin >> n >> r1 >> r2 >> r3 >> d; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long adv[n + 1], ret[n + 1]; adv[0] = ret[n] = 0; ret[n - 1] = min( ...
#include <bits/stdc++.h> using namespace std; void solve() { int t; cin >> t; for (int _ = 0; _ < (t); ++_) { int n; cin >> n; if (n < 4) { cout << -1 << n ; continue; } deque<int> p{3, 1, 4}; vector<int> nums{2}; for (int i = 5; i <= n; ++i) {...
#include <bits/stdc++.h> using namespace std; const int c = 102; int kezd[c][c], veg[c][c], dp[c][c], n, m, sum; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { int db; cin >> db; for (int j = 1; j <= db; j++) { int a, b; cin >> a >> b; for (int k = a...
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; vector<long long> lol = {0}; for (long long i = n - 1; i >= 1; i...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t != 0) { int n; cin >> n; long long m = (n - 1) / 2; long long sum = m * (m + 1) * (2 * m + 1) / 6; long long raspuns = 8 * sum; cout << raspuns << n ; t--; } }
#include <bits/stdc++.h> using namespace std; void ensure(bool b) { if (!b) { cout << 0 << endl; exit(0); } } void solve() { int n; cin >> n; vector<vector<int>> g(n); vector<int> e(2 * n - 2); for (int i = 0; i < n - 1; i++) { int x, y; cin >> x >> y; x...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k; cin >> n >> k; long long a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } std::map<long long, long long> m; for (int i = 0; i < ...
#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( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) using namespace std; int n, q, fa[66666], aa[66666...
#include <bits/stdc++.h> #pragma comment(linker, /stack:256000000 ) using namespace std; int main() { int n; scanf( %d , &(n)); vector<int> v1(n), v2(n), v3(n); if (!(n % 2)) { printf( -1 n ); return 0; } for (int i = (0), endi = (n); i < endi; ++i) v1[i] = i; for (int i =...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int n, t, x, y, a = 0, b = 0, suma = 0, sumb = 0; cin >> n; while (n--) { cin >> t >> x >> y; if (t == 1) { a++; suma += ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e15; struct Edge { int t, w; } e[100010 << 1]; queue<int> g[100010]; long long d[100010], f[100010]; int i, j, k, n, m, q, x, h[100010]; struct _ { int x; _(int x) : x(x) {} bool operator<(const _& a) const { return d[x...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const int xx[4] = {1, -1, 0, 0}; const int yy[4] = {0, 0, 1, -1}; int inline in() { int x = 0, c; for (; (unsigned)((c = getchar()) - 0 ) >= 10;) { if (c == - ) return -in()...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, e = 0, o = 0, k, p, j; long long int arr[100005]; vector<long long int> v[100005], od, ev; cin >> n >> k >> p; for (i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] % 2 == 0) { ev.push_back(arr[i]); ...
#include <bits/stdc++.h> template <class T_T> T_T gcd(T_T a, T_T b) { return b ? gcd(b, a % b) : a; } template <class T_T> T_T f_max(T_T a, T_T b) { return a > b ? a : b; } using namespace std; const int N = 100000; int a[105][105], r[105], c[105], cnt_r[105], cnt_c[105], ans; int main() { ...
#include <bits/stdc++.h> using namespace std; int n, k; char s[1000005]; int main() { scanf( %d%d%s , &n, &k, s); for (int i = 0; i < n && k; ++i) { if (s[i] == 4 && s[i + 1] == 7 && s[i + 2] == 7 && !(i & 1)) k %= 2; if (k && s[i] == 4 && s[i + 1] == 7 ) { if (i & 1) ...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, m, a = 0, b = 0, c = 0, d, h, p, x, y, z, i = 0, j = 0, k = 0, l, r, rem, time = 0, ans = 0, mini = 1e18 + 1, maxi = 0, count = 0, sum = 0, sign = 0, xx, yy, zz; cin >> n; if (n ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> r; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; r.push_back(tmp); } int m_lng = 0; for (int i = 0; i < n; i++) { int cnt = 1; int lng = 0; int sum = 0; ...
#include <bits/stdc++.h> using namespace std; int fact[500005]; void criba() { for (int i = 2; i * i < 500005; i++) if (fact[i] == 0) for (int j = i * i; j < 500005; j += i) fact[j] = i; for (int i = 2; i < 500005; i++) if (fact[i] == 0) fact[i] = i; } bool vis[500005]; int F[500...
#include <bits/stdc++.h> int main() { int n, m, a[1003], b[1003], i, j, count = 0, k = 0, flag = 0; scanf( %d %d , &n, &m); for (i = 0; i < n; i++) { scanf( %d , &a[i]); } for (i = 0; i < m; i++) { scanf( %d , &b[i]); } for (i = 0; i < m; i++) { for (j = k; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; int n, c[3010]; struct info { int x, y; }; struct as { int a, b, c; } ans; struct node { int x, id; } a[3010]; inline bool cmp(node a, node b) { return a.x > b.x; } inline info max(info a, info b) { if (a.x < b.x) return b; return a; ...
#include <bits/stdc++.h> using namespace std; int A, B; char a[5555]; char b[5555]; int dp[5555][5555]; int main() { scanf( %d%d , &A, &B); scanf( %s%s , a + 1, b + 1); int ans = 0; int i, j; for (i = 1; i <= A; i++) { for (j = 1; j <= B; j++) { if (a[i] == b[j]) dp[i][j] =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x, l; int cnt = 0; for (int i = 0; i < n; i++) { cnt = 0; cin >> x; if (x % 7 != 0) { cnt++; } x /= 7; cout << x + cnt << endl; } return 0; }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:36777216 ) using namespace std; long long pow_mod(long long x, long long y, long long z) { long long res = 1; while (y) { if (y & 1) res *= x, res %= z; x *= x, x %= z, y >>= 1; } return res % z; } void ext_gcd(long long a, l...