func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; template <class T> using vv = vector<vector<T>>; template <class T> ostream &operator<<(ostream &os, const vector<T> &t) { os << { ; for (int(i) = 0; (i) < (t.size()); ++(i)) { os << t[i] << , ; } os << } << endl; return os; } tem...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long INF = mod * mod; const long double eps = 1e-8; void solve() { int n; cin >> n; vector<long long> val(n), mask(n); long long sum = 0; for (int i = 0; i < n; i++) { cin >> val[i] >> mask[i]; ...
#include <bits/stdc++.h> using namespace std; int xor_sum(int x) { if (x % 4 == 0) { return x; } if (x % 4 == 1) { return 1; } if (x % 4 == 2) { return x + 1; } if (x % 4 == 3) { return 0; } return -1; } int main() { ios_base::sync_with_stdio(0); ...
#include <bits/stdc++.h> using namespace std; inline char getc() { static char buf[1 << 20], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } template <typename T> void rd(T& x) { int f = 0, c; wh...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int MAXN = 6 + 5; const int MAXM = 6 + 5; const int base = 5; const int ALL = 1.6e4 + 5; const int inf = 0x3f3f3f3f; int pwb[MAXM]; int n,m; int a[MAXN], b[MAXM], c[MAXN][MAXM]; int f[MAXN][...
#include <bits/stdc++.h> using namespace std; const int N = 200200; int n; long long b[N], c[N]; long long a[N]; int dg[32]; void solve() { memset((dg), (0), sizeof(dg)); long long sum = 0, suma = 0; for (int i = (int)0; i < (int)n; ++i) sum += b[i] + c[i]; suma = sum / (n + n); bool f...
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) - 1; const long double EPS = 1e-9; const long double PI = fabs(atan2(0.0, -1.0)); int get(int n) { int res = 0; for (int b = 0; n > 0; b++) { if (n & 1) res = b; n >>= 1; } return res; } int p[1000100]; v...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); map<long long, long long> mp; deque<long long> a; long long n, k, d, m = 0; cin >> n >> k; for (auto i = 0; i < n; i++) { cin >> d; if (!mp[d...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using v2 = vector<vector<T>>; template <typename T> inline v2<T> fill(int r, int c, const T& t) { return v2<T>(r, vector<T>(c, t)); } ll a, b, c, d; const ll INF = 1e18; ll nc2(ll n) { return (n * (n - 1)) ...
#include <bits/stdc++.h> using namespace std; int n, l, r; long long ans; int pr[10000005]; int cnt[10000005]; void solve() { n--; for (int i = (1); i <= (10000000); i++) pr[i] = i; for (int i = (2); i <= (10000000); i++) if (pr[i] == i) { for (int j = i + i; j <= 10000000; j += i)...
#include <bits/stdc++.h> using namespace std; const int M = 200005; int n, f[M], ans; int tot, head[M], Next[M * 2], vet[M * 2], len[M * 2]; void add(int a, int b, int c) { Next[++tot] = head[a], vet[tot] = b, len[tot] = c; head[a] = tot; } void dfs1(int x, int pre) { for (int i = head[x]; i; ...
#include <bits/stdc++.h> const int N = 2e5 + 5; const int inf = 2e9; struct Edge { int u, v, cost, isin; int ind; bool operator<(const Edge& x) const { return cost < x.cost; } }; std::vector<Edge> e; std::vector<std::pair<int, int> > l[N]; int tata[N], sz[N], ans[N]; int findDaddy(int node) ...
#include <bits/stdc++.h> using namespace std; string s; char ok[100] = { A , H , I , M , O , T , U , V , W , X , Y }; int main() { while (cin >> s) { if (s.length() == 1) { int flag = 0; for (int i = 0; i <= 10; i++) { if (s[0] == ok[i]) { puts( YES ); ...
#include <bits/stdc++.h> using namespace std; map<long long int, long long int> m; int main() { long long int n; cin >> n; vector<long long int> v; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; v.emplace_back(x); m[x]++; } sort(v.begin(), v.end(...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int a = 0, b = 0, c = 0, sum1 = 0, d = 0; cin >> a >> b >> c >> d; for (; sum1 <= d;) { sum1 += b; a -= c; } if (a > 0) cout << YES ; else cout << NO ; ...
#include <bits/stdc++.h> using namespace std; inline long long minOf(long long x, long long y) { return (x < y ? x : y); } inline long long maxOf(long long x, long long y) { return (x > y ? x : y); } char arr[50000000], *ptr; long long ret; string str; inline long long get_int() { bool isNeg = false; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>;...
#include <bits/stdc++.h> using namespace std; vector<vector<unsigned long long>> g; vector<bool> visited; vector<unsigned long long> s; void dfs(unsigned long long x) { visited[x] = 1; for (unsigned long long i : g[x]) if (!visited[i]) dfs(i); s.push_back(x); } int main() { unsigned ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int n, ans[N], cnt = 1; vector<int> id[N], cur[N]; vector<int> g[N]; bool vis[N], done[N]; int sz[N], ns[N], ns2[N], comp_cnt, comp[N], allns = 0; void DFS(int node) { sz[comp_cnt]++; vis[node] = true; comp[node] = comp_cnt...
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000 + 47; const long long LINF = (long long)INF * INF; const int MAX = 2e5; const double EPS = 1e-9; const double PI = acos(-1.); int n; int a[10][10]; int dx[8] = {2, 2, 1, -1, -2, -2, -1, 1}; int dy[8] = {1, -1, -2, -2, -...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, i, j, k; cin >> n >> m; int a[101] = {0}; for (i = 0; i < m; i++) { cin >> j; a[j]++; } vector<int> v; for (i = 1; i <= 100; i++) { if (a[i] != ...
#include <bits/stdc++.h> template <class T> inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) { f |= ch == - ; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ? -x : x; ...
#include <bits/stdc++.h> using namespace std; const int maxb = 20; const int maxn = 300000 + 7; int dp[maxn][maxb]; int n, q; int seq[maxn]; int last[maxb]; void init() { cin >> n >> q; for (int i = (1); i <= (n); ++i) cin >> seq[i]; } void solve() { for (int i = (0); i < (maxb); ++i) dp...
#include <bits/stdc++.h> const int maxn = 2e3 + 5; using namespace std; int arr[maxn]; int dp[maxn][maxn]; int check(int x, int lef, int rig) { return (lef <= x && x <= rig ? 1 : 0); } int main() { int n, h, l, r; scanf( %d %d %d %d , &n, &h, &l, &r); for (int i = 1; i <= n; i++) { scanf( ...
#include <bits/stdc++.h> using namespace ::std; const long double PI = acos(-1); const long long MOD = 1000000000 + 7; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long add(long long a, long long b, long long m = MOD) { return (a % m + b % m + 2 * m) % m; } long ...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); if (n == m && s == t) cout << -1; else cout << max(n, m); }
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; if (n == 0) cout << 1; else { switch (n % 4) { case 0: cout << 6 << endl; break; case 1: cout << 8 << endl; break; case 2: cout ...
#include <bits/stdc++.h> using namespace std; const long long max_n = INT_MAX - 1000000; long long dp[30][30001]; pair<int, int> par[30][30001]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { long long n, m, k; cin >> n >> m >> k;...
#include <bits/stdc++.h> using namespace std; static const int N = 1000; int t[N][N]; int d[4][N][N]; int di[4] = {1, 0, -1, 0}; int dj[4] = {0, 1, 0, -1}; int n, m, q; int p[N]; bool check(int k, int i) { if (i < 0) return 0; if (k) return i < m; return i < n; } int solve(int c, int b...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007LL; int n, l; long long a[102], b[102]; long long dp[2 * 3002][102][2]; int main() { while (cin >> n >> l) { for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; } memset(dp, 0, sizeof(dp)); for (int i ...
#include <bits/stdc++.h> int x[1000], y[1000]; using namespace std; int main() { int n, counter = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; if (x[i] != y[i]) { cout << rated ; return 0; } } for (int i = 0; i < n; i++) { if (x[i] < ...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { vector<int> a(n); for (int i = 0; i < n; scanf( %d , &a[i++])) ; sort(a.begin(), a.end()); bool ok = 0; for (int i = 0; i < n; i++) { if (a[i] != i + 1) { cout << i + ...
#include <bits/stdc++.h> using namespace std; int a0, a1, n, ans, table[500]; int getans(int); int main() { scanf( %d%d%d , &a0, &a1, &n); printf( %d n , getans(n)); return 0; } int getans(int an) { if (an == 0) return a0; if (an == 1) return a1; return getans(an - 1) + getans(an - 2...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int a[maxn], b[maxn], ww[maxn], www[maxn]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); ww[a[i]] = 1; } for (int i = 1; i <= n; i++) { scanf( %d , &b[i]); ...
#include <bits/stdc++.h> using namespace std; int dp[110][110]; int main() { int n, v; cin >> n >> v; for (int i = 1; i <= v; i++) dp[1][i] = i; for (int i = 2; i <= n; i++) { for (int j = 0; j < v; j++) { dp[i][j] = min(dp[i - 1][j + 1], dp[i - 1][j] + i); } dp[i][v] = d...
#include <bits/stdc++.h> using namespace std; int gi() { int x = 0, w = 1; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) w = 0, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = (x << 3) + (x << 1) + ch - 0 , ch = getchar(); return w ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 1; int bit[N] = {0}; void update(int x, int val) { for (; x <= N; x += x & (-x)) bit[x] += val; } int query(int x) { int sum = 0; for (; x >= 1; x -= x & (-x)) sum += bit[x]; return sum; } int a[N]; int main() { int ...
#include <bits/stdc++.h> using namespace std; const int N = 101; int n, a[N][30]; long long nd[N][N], num[N]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) cin >> nd[i][j]; memset(a, 0, sizeof(a)); for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; inline int Getlen(int x) { int res = 0; while (x) { res++; x /= 10; } return res; } int PP[5]; int a[51], len[51], n, p; int id[51]; int res[51], tot; inline void dfs(int now, int Gmod, int Gxor) { if (Gmod == 0 && Gxor == 0 &...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 5]; for (int i = 1; i <= n; i++) cin >> a[i]; int m = 1; for (int i = 2; i < n; i++) { if (abs(a[i] - a[i + 1]) < abs(a[m] - a[m + 1])) m = i; } if (abs(a[n] - a[1]) < abs(a[m] - a[m + 1])) { ...
#include <bits/stdc++.h> using namespace std; constexpr long long maxN = 1e5 + 43; long long n, d; vector<long long> a; long long suff[maxN]; long long had_max[maxN]; signed main() { ios_base::sync_with_stdio(false); cin >> n >> d; a.resize(n + 1); for (long long i = 1; i <= n; ++i) cin >>...
#include <bits/stdc++.h> using namespace std; void output() { long long n; cin >> n; long long a[n], i; for (i = 0; i < n; i++) cin >> a[i]; map<long long, bool> make_pair; long long s = 0; make_pair[0] = true; long long c = 0; for (i = 0; i < n; i++) { s += a[i]; if ...
#include <bits/stdc++.h> const int INF = (int)1e9; const double PI = acos(-1.); using namespace std; string s; long long sumr, suml, need; int main() { cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == ^ ) need = i; } for (int i = need - 1; i >= 0; i--) { if (s[i] != ...
#include <bits/stdc++.h> using namespace std; int main() { string s = abcdefghijklmnopqrstuvwxyz ; string s2 = ; int n, k; cin >> n >> k; for (int i = 0; i < n; i++) s2 += s[i % k]; cout << s2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int forbidInd; int A[100000 + 10]; long long int memo[60][60][60]; long long int solve(int i, int k, int x) { if (k < 0 || x < 0) return 0; if (i == 0) { if (x == 0 && k == 0) return 1; if (k == 1 && x == A[i] && forbidInd != 0) return ...
#include <bits/stdc++.h> using namespace std; const int nsz = 1e5, ksz = 8, msksz = (1 << ksz) - 1, inf = 0x3f3f3f3f; bool vis[nsz + 5]; int n, m, k, full, p[nsz + 5], q[ksz + 5], dp[2][msksz + 5], ans; struct event { int pos, id, st; event(int pos = 0, int id = 0, int st = 0) { this->pos = pos,...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <class T1, class T2> struct cmpf { bool rev; inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const { return (a.first < b.first) ^ rev; } cmp...
#include <bits/stdc++.h> using namespace std; const int inf = 200000000; struct Point { int x, y; Point(int _x, int _y) { x = _x; y = _y; } }; bool operator<(const Point a, const Point b) { return a.x < b.x; } long long solve(vector<Point> v) { int n = (int)v.size(); vector<i...
#include <bits/stdc++.h> using namespace std; int n; long long int aib[15][100005]; inline void update(long long int aib[], int pos, long long int val) { for (; pos <= n; pos += ((pos) & (-(pos)))) aib[pos] += val; } inline long long int query(long long int aib[], int pos) { long long int ans = 0; ...
#include <bits/stdc++.h> #define Mid ((l + r) >> 1) #define lson (rt << 1) #define rson (rt << 1 | 1) using namespace std; int read(){ char c; int num, f = 1; while(c = getchar(),!isdigit(c)) if(c == - ) f = -1; num = c - 0 ; while(c = getchar(), isdigit(c)) num = num * 10 + c - 0 ; return f * ...
#include <bits/stdc++.h> using namespace std; int main() { string s, r; cin >> s; int k, l, x, n; cin >> k; l = s.length(); if (l % k != 0) { cout << NO n ; return 0; } x = l / k; for (int i = 0; i < l; i += x) { r = s.substr(i, x); n = r.length() - 1; ...
#include <iostream> #include <algorithm> using namespace std; inline int gcd(int a, int b) { int Max = max(a, b); int Min = min(a, b); if (Max % Min == 0) return Min; else return gcd(Min, Max % Min); } inline int lcm(int a, int b) { return a * b / gcd(a, b); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[3] = {0}; cin >> n; while (n--) { cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); int ans = 0; if (a[0] > 0) { ans++; a[0]--; } if (a[1] > 0) { ans++; a[1]--; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int q, n; int a[MAXN], lef[MAXN], rig[MAXN]; vector<int> v; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> q; while (q--) { cin >> n; for (int i = 1; i <= n; i++) { lef[i] = rig[i] =...
#include <bits/stdc++.h> using namespace std; int i, j, qan, n, m, k, l, p; bool mark[102]; char s; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> s; if (s == * ) { mark[i] = true; } } qan = (n - 5) / 4; for (i = 0; i <= qan; i++) { for (j = 1; j ...
#include <bits/stdc++.h> using namespace std; int main() { int test; cin >> test; while (test--) { char str[10000], cpy[10000], st[10000]; cin >> str; int ln = strlen(str), ck = 0; for (int i = 0, j = ln - 1; i < ln; i++, j--) { cpy[j] = str[i]; } for (int i =...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int a[MAXN]; int cnt[101][101]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; cnt[i % k][a[i]]++; } int ans = 0; for (int i = 0; i < k; i++) { ans += min(cnt[i]...
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; const long long INFLL = 1001001001001001001LL; template <typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << ; cout << endl; } template <typename T> void chmin(T& a, T b) { if (a > b) a = b; }...
#include <bits/stdc++.h> using namespace std; int main() { int sizePermute, sizebkp, x, minimum = 100, maximum = 0, maximumIndex, minimumIndex, counter = 0; cin >> sizePermute; sizebkp = sizePermute; vector<int> myvec(sizePermute); myvec.clear(); while (sizeP...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; cin >> a >> b >> c; long long power = 0, l = 0, emp = 1, aa = 0; for (long long i = 0; i > -1; i++) { if (i != 0) { for (long long j = 0; j < i; j++) { emp = emp * c; } } if (emp...
#include <bits/stdc++.h> const long long mod = 1000 * 1000 * 1000 + 7; const long long mod1 = 998244353; const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; using namespace std; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = (...
#include <bits/stdc++.h> using namespace std; const int N = 10005; int a[N], sorted[N], n, m, sum[20][N], tree[20][N]; inline void build(int deep, int l, int r) { int i, mid = (l + r) >> 1, lm = mid - l + 1, lp = l, rp = mid + 1; for (i = l; i <= mid; i++) if (sorted[i] > sorted[mid]) lm--; fo...
#include <bits/stdc++.h> using namespace std; const int maxn = 210, INF = 1 * 1000 * 1000 * 1000 + 10, maxm = 150, maxk = 10; int n, m, k, sar, now, par[maxn], x[maxk], c[maxn], d[maxn], f[maxn][maxn], dp[maxm][maxn], dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}, cur, X, Y, save; vec...
#include <bits/stdc++.h> using namespace std; const int N = 1 << 21 | 1; int n, p[N]; long long a[N], b[N], c[N]; char s[N], t[N]; void OR(long long* a) { int i, j, u, v, l, t; for (i = 2; i <= n; i <<= 1) for (j = 0, t = i >> 1; j < n; j += i) for (u = j, v = l = j + t; u < l; ++u, ++...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; const double PI = 3.14159; vector<int> v; long long n, m, k, t, ans, sum, r, l, b, c, d, a; bool f; string s; set<int> st; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> m; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9 + 5; const long long INF64 = 1e18; string to_string(const string &s) { return + s + ; } string to_string(bool b) { return b ? true : false ; } template <typename A, typename B> string to_string(pair<A, B...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; bool vis[N]; int n, a[N], go[N]; pair<int, int> v[N]; bool isLucky(int x) { while (x > 0) { if (x % 10 != 4 && x % 10 != 7) return false; x /= 10; } return true; } void solve() { bool hasLN = false; for ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); namespace IO { bool REOF = 1; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && REOF && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? (REOF = ...
#include <bits/stdc++.h> using namespace std; unsigned long long int a, b, c, l; int main() { ios::sync_with_stdio(false); cin >> a >> b >> c >> l; unsigned long long int ans = ((l + 3) * (l + 2) * (l + 1)) / (6); for (int i = 0; i <= l; i++) { if (a + i >= b + c) { unsigned long lon...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; string s; long long a, b; long long v[N], pre[N], suf[N]; int32_t main() { cin >> s >> a >> b; long long n = s.size(); for (long long i = 1; i <= n; i++) v[i] = s[i - 1] - 0 ; for (long long i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; int de(int x) { if (x == 0) return 0; if (x & 1) return de(x / 2) + 1; return de(x / 2); } long long val[101000]; int main() { int n, i, j, a; while (scanf( %d , &n) != EOF) { memset(val, 0, sizeof(val)); for (i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { string n, r; cin >> n; r = n; reverse(r.begin(), r.end()); cout << n << r << n ; return 0; }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; const int M1 = 1000000007; const int M2 = 1000000087; int N; int H1[310000]; int P1[310000]; int H2[310000]; int P2[310000]; int HH1, HH2; int n, m; vector<int> g[100007]; string s[100007]; char t[300007...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; bool usa[n], usb[n]; for (int i = 0; i < n; ++i) { usa[i] = 1; usb[i] = 1; } for (int i = 0; i < n; ++i) { int a; cin >> a; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool f = false; char ch = getchar(); while (!isdigit(ch)) { f |= ch == - ; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return f ? -...
#include <bits/stdc++.h> using namespace std; int nn[100000], np[100000][19], ni[100000], nl[100000], nh[100000], nc[100000], nv[100000], nd[100000], dist[100000]; vector<int> ne[100000]; int es[100000], ee[100000]; bool eb[100000]; int curp[100000]; int trav = 0; bool dfs(int n, int p) { ni[n...
#include<bits/stdc++.h> #define fill(arr,c) memset(arr,c,sizeof(arr)) #define perm(r) next_permutation(all(r)) //it gives bool value ans permute the string lexoggraphically #define sortdesc greater<int>() #define ll long long int //std::setfill( 0 ) << std::setw(5) << 25; it adds leaing zeroes; #defin...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) { return os << ( << p.first << , << p.second << ) ; } template <typename T> inline std::ostream& operator<<(std::ostream& os, const std::v...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int find_first_num_index(long long &k, long long n) { if (n == 1) { return 0; } n--; int first_num_index; long long n_partial_fact = n; while (k >= n_partial_fact && n > 1) { n_partial_fact *= (n - 1);...
#include <bits/stdc++.h> inline int read() { char c; int x; for (c = getchar(); !isdigit(c); c = getchar()) ; for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - 0 ; } return x; } int n; long long ans; std::priority_queue<int> que; int main() { n = read(); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; int n, m, k; while (t--) { cin >> n >> m >> k; if (n % 2 == 0 && k % 2 == 1) { cout << NO n ; continue; } if (n % 2 == 0 && k ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e7; const long long MOD = 1e9 + 7; const long long mod = 998244353; const int MAX_N = 1e5 + 5; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << endl; } template <typename Arg1, typenam...
#include <bits/stdc++.h> using namespace std; const int maxn = 152; int previ[maxn]; int curr[maxn]; int temp[maxn]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; previ[0] = 1; curr[1] = 1; for (int i = 0; i < n - 1; i++) { temp[0] = 0; for (int j = 0; j <= ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &dig) { dig = 0; bool flag = false; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) flag = true, c = getchar(); while (isdigit(c)) dig = dig * 10 + c - 0 , c = getchar()...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, cnt; double ans, a, dp[100005] = {0}, pr[100005] = {0}; cin >> n; for (i = 1; i <= n; i++) { cin >> a; pr[i] = pr[i - 1] * a + a; dp[i] = dp[i - 1] + a * (2 * pr[i - 1] + 1); } printf( %.15lf , dp[n]); ...
#include <bits/stdc++.h> using namespace std; int fa[5010], ba[5010], b[5010]; int main() { ios_base::sync_with_stdio(0); int i, j, k, l, n, m, t, tt, x = 0, y; string s, second; cin >> s; n = s.length(); fa[0] = 0; ba[n + 1] = 0; b[0] = 0; for (j = 1; j <= n; j++) { fa[j...
#include <bits/stdc++.h> using namespace std; int maxn; int vis[100010], a[100010], in[100010], temp[100010], res[100010]; vector<int> q[100010]; int bfs(int x) { int i, sum = 1, hash[100010] = {0}; hash[x] = 1; while (in[x] < 2) { temp[sum++] = x; if (!hash[q[x][0]]) { if (q[x...
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { bool b = 0; char c; while (!isdigit(c = getchar()) && c != - ) ; if (c == - ) c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48; if (b) x = -x; } template <...
#include <bits/stdc++.h> using namespace std; int n, i, j, m, k; int a[2000000]; bool bo[2000000]; int l, r, ans, tot; int main() { scanf( %d%d%d , &n, &m, &k); for (i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + 1 + n); int now = 0; bo[0] = true; for (i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; int n; int A[200005]; vector<int> L[105]; int dp[400005]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &A[i]); L[A[i]].push_back(i); } int opt = 0; int D = 0; int N = min(n, 100); for (int i = 1...
#include <bits/stdc++.h> using namespace std; const int K = 26; struct Vertex { int next[K]; long long int leaf = 0; int p = -1; char pch; int link = -1; int go[K]; long long int count = -1; int leaflink = 0; Vertex(int p = -1, char ch = $ ) : p(p), pch(ch) { fill(begin(...
#include <bits/stdc++.h> using namespace std; void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } void swap(char *a, char *b) { char temp = *a; *a = *b; *b = temp; } int main() { int xa, xb, xc, ya, yb, yc; cin >> xa >> ya >> xb >> yb >> xc >> yc; char ca = ...
#include <bits/stdc++.h> using namespace std; int main() { int n; int has = 0; ; cin >> n; int d[n - 1]; for (int i = 0; i < n - 1; i++) cin >> d[i]; int a, b; cin >> a >> b; int m; has = 0; for (int m = a - 1; m < b - 1; m++) { has = has + d[m]; } cout << h...
#include <bits/stdc++.h> using namespace std; class SuffixArrayBuilder { int n, gap; string s; vector<int> pos; public: SuffixArrayBuilder(string &s) : s(s) {} bool operator()(int i, int j) { if (pos[i] != pos[j]) return pos[i] < pos[j]; i += gap; j += gap; return (...
#include <bits/stdc++.h> int max(int a, int b) { return a > b ? a : b; } int main() { static int aa[200000]; int n, d, q, i, h, j; scanf( %d%d , &n, &d); for (i = 0; i < n; i++) scanf( %d , &aa[i]); scanf( %d , &q); h = -1; while (q--) { int x, di, dj, d_; double alpha, beta;...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; using namespace std; string s; long long ispalindroma[2005][2005]; long long ispalindrome(long long i, long long j) { if (i > j) return (1); if (i == j) return (1); if (ispalindroma[i][j] != -1) return (ispalindroma[i][...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; if (x >= y) { x = x - y; if (x > z) { cout << + ; } else if (x <= z) { if (z == 0) { cout << 0 ; } else { cout << ? ; } } } else ...
#include <bits/stdc++.h> int main() { long long int n, x, y, i, j, k = 0, s; scanf( %lld %lld %lld , &n, &x, &y); long long int X[n], Y[n]; for (i = 0; i < n; i++) { scanf( %lld %lld , &X[i], &Y[i]); for (j = i - 1; j >= 0; j--) { s = x * Y[i] + X[i] * Y[j] + X[j] * y - X[i] * y - ...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; int d[210][210][510][2]; short vis[210][210][510][2]; int q, n, k, b, cas; int nex[210][22], out[210]; int fal[210]; int s[210]; int dp(int pos, int len, int w, int m) { w = min(w, k + 5); if (vis[pos][len][w][m] == cas)...
#include <bits/stdc++.h> using namespace std; const long long int MOD = (long long int)1e9 + 7; long long int powmod(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b = b >> 1; } return res % MOD; }...