func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; long long w = 0, o = 0; for (long long i = 0; i < s.length() - 1; i++) { if (s[i] == v && s[i + 1] == v ) w++; else { ...
#include <bits/stdc++.h> using namespace std; int main(void) { int lins, cols; cin >> lins >> cols; for (int i(0); i < lins; i++) { if (i % 2 == 0) { for (int j(0); j < cols; j++) { cout << # ; } cout << endl; } else if ((i + 1) % 4 == 0) { cout << ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int ans = 0; while (1) { int maxi = 0; for (int i = 0; i < n; i++) { if (arr[i] >= arr[maxi]) maxi = i; } if (maxi == 0) break;...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, l = 0, p = 0, i, flag = 0, k, j, r = 0, q = 0, t, curr = 0, d, x; cin >> n >> x >> k; long long a[n]; for (long long i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } bool isPrime(long long x) { if (x == 1) return false; for (lon...
#include <bits/stdc++.h> using namespace std; const int N = 2005; const int M = 101; const double EPS = 1e-9; const int INF = 1e9; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } double getDist(complex<d...
#include <bits/stdc++.h> using namespace std; int main() { int n, tmp, sum = 1; int map[200000] = {0}; cin >> n; for (int i = 0; i < n; i++) { cin >> tmp; if (map[tmp] == 0) { map[tmp]++; } else sum++; } cout << sum; }
#include <bits/stdc++.h> using namespace std; long long N; long long i, j; vector<long long> v; map<long long, long long> mp; long long arr[200]; int main() { scanf( %lld , &N); for (i = 0; i < N; i++) scanf( %lld , &arr[i]); sort(arr, arr + N); long long ans = 0; for (i = 0; i < N; i+...
#include <bits/stdc++.h> using namespace std; const int maxd = 1e6 + 10; int a[maxd]; long long sum, ans = 1e18; vector<long long> b; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) sum += a[i]; if (sum == 1) { prin...
#include <bits/stdc++.h> using namespace std; int n, a; vector<int> q; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { bool w = true; for (int j = 0; j < n; j++) { scanf( %d , &a); if (a == 1 || a == 3) w = false; } if (w) q.push_back(i + 1); } ...
#include <bits/stdc++.h> using namespace std; bool can(bool print, int t, long long S, const vector<pair<int, int> >& bugs, const vector<pair<int, pair<int, int> > >& st) { priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq; int ind = ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 10; int n, m, q, pos[MAX], bit[MAX], res[MAX], XOR[MAX]; pair<int, int> cache[MAX], a[MAX], b[MAX]; struct Node { int lef, rig, tt; bool operator<(const Node& other) const { return this->lef < other.lef; } }; Node query[MAX]; vo...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100], b[100], i, c = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; if ((b[i] - a[i]) >= 2) c++; } cout << c; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a = 0, l[101], r[101], k; cin >> n; for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; } cin >> k; for (int i = 0; i < n; i++) { if (k <= r[i]) { a++; } } cout << a; }
#include <bits/stdc++.h> using namespace std; int main(void) { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> ans1, ans2; string a, b; cin >> a >> b; a = a + 0 ; b = b + 0 ; for (int i = 0; i < n; i++) { if (a[i] != a[i + 1]) ans1.pu...
#include <bits/stdc++.h> using namespace std; long long p, x, a, b, ni, ans; void e_gcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return; } e_gcd(b, a % b, x, y); int tmp = x; x = y; y = tmp - (a / b) * y; return; } int ma...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int *a = new int[n]; for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } int m; scanf( %d , &m); int bred[10000]; for (int i = 0; i < 10000; i++) bred[i] = 0; for (int i = 0; i < m; i++) ...
#include <bits/stdc++.h> inline int rd(int f = 1, int x = 0, char ch = ) { while (!isdigit(ch = getchar())) if (ch == - ) f = -1; while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return f * x; } const int N = 1e5 + 5; int n, a[N], ans; int main() { for (int T = rd(); T--;) ...
#include <bits/stdc++.h> using namespace std; long long n, k, q, a[200005], f[200005]; int main() { cin >> n >> k >> q; for (int i = 1; i <= n; i++) { long long l, r; cin >> l >> r; a[l]++; a[r + 1]--; } for (int i = 1; i <= 200000; i++) a[i] += a[i - 1]; for (int i = 1...
#include <bits/stdc++.h> using namespace std; constexpr int INF = 2e9; int main() { int t; t = 1; while (t--) { int n; string s; cin >> n; cin >> s; int res = 0; for (int d = 25; d >= 0; d--) { string tmp = ; for (int i = 0; i < s.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 2e5 + 5; int n, k, d, ansL = 1, ansR = 1, top1, top2; int a[MAXN], st1[MAXN], st2[MAXN]; map<int, int> lst; namespace SegmentTree { struct Tree { int l, r; int w, tag; } tree[MAXN << 2]; void update(in...
#include <bits/stdc++.h> using namespace std; long long add(long long a, long long b, long long mod) { return (a % mod + b % mod) % mod; } long long sub(long long a, long long b, long long mod) { return (a % mod - b % mod + mod) % mod; } long long mul(long long a, long long b, long long mod) { r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int f = n * 1.0 / 3 + 0.5; cout << f / 12 << << f % 12 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAX1 = 3e5 + 10; long long a, b, c, d, e, cnt, x, y, z, l, r, flag, num[MAX1], mod = 1e10 + 7; string s; char p[MAX1]; long long sta(long long n) { for (int i = 1; i < 1000000; ++i) { if (i * (i - 1) / 2 == n) return i; } return...
#include <bits/stdc++.h> using namespace std; long long bigpow(long long x, long long n) { if (n == 0) return 1; long long temp = bigpow(x, n / 2); return n % 2 == 0 ? (temp * temp) % 1000000009 : (x * ((temp * temp) % 1000000009)) % 1000000009; } int main() { long long n, ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char s = getchar(); while (s < 0 || s > 9 ) { if (s == - ) f *= -1; s = getchar(); } while (s >= 0 && s <= 9 ) { x = (x << 1) + (x << 3) + s - 0 ; s = getchar(); } ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MOD = 1e9 + 7; const int N = 0; int a[5], m; long long sum(int len, int x) { return 1LL * len * x - 1LL * (x + 1) * x / 2 + x; } long long cal(int x, int y, int bar, int len) { if (len < 0) return 0; int R = min(bar...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[k]; for (int i = 0; i < k; i++) cin >> a[i]; list<int> leader; for (int i = 1; i <= n; i++) leader.insert(leader.end(), i); int l = 1; int i = 0; int begin = 0; while (k--) { l = (...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } int main() { int n; cin >> n; vector<int> q(n); for (int i = 0; i < n; ++i) cin >> q[i]; vector<int> cost(n, -1); int m; cin >...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> g[200002]; vector<pair<int, pair<int, int> > > first[200002]; int lvl[200002]; int p[20][200002]; int h[20][200002]; int d[200002][2]; inline int lca(int v1, int v2) { if (lvl[v1] < lvl[v2]) swap(v1, v2); for (int i = 20 - 1; ...
#include <bits/stdc++.h> using namespace std; int t[2000002]; int longestPrefix(string &s) { t[0] = 0; for (int pos = 1; pos < s.length(); ++pos) { int prev = t[pos - 1]; while (prev > 0 && s[pos] != s[prev]) { prev = t[prev - 1]; } if (s[pos] == s[prev]) { t[pos] =...
#include <bits/stdc++.h> using namespace std; int V[200010]; char vowel[] = aeiouAEIOU ; int v(int a, int k) { if (k == 0) return 0; int x = V[a + k - 1]; if (a > 0) x -= V[a - 1]; return x; } int f(int a, int k) { return 2 * k - 3 * v(a, k); } int g(int k) { return f(0, k); } bool Good...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); void read(int& x) { x = 0; int f = 1; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) f = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch =...
#include <bits/stdc++.h> using namespace std; string n; int i, j, a[9][7], x, y; int main() { cin >> n; for (i = n.size() - 1; i >= 0; i--) { x = n[i] - 48; y = max(y, x); for (j = 0; j < x; j++) a[j][7 + i - n.size()] = 1; } cout << y << endl; for (i = 0; i < y; cout << ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; register char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar...
#include <bits/stdc++.h> using namespace std; const int D = 505; const int N = 5005; pair<int, int> pre[D][N]; int ans[D][N]; void solve() { memset(pre, -1, sizeof(pre)); memset(ans, -1, sizeof(ans)); int d, s; cin >> d >> s; queue<pair<int, int> > que; que.push(pair<int, int>(0, 0))...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5, MOD = 998244353; int m, n, k; long long res; int free_Row, free_Col, line_vert, line_hori; int Num_Row[N], Num_Row2[N][2], Num_Col[N], Num_Col2[N][2]; int c[2][2]; map<pair<int, int>, int> M; long long power(long long x, int k)...
#include <bits/stdc++.h> using namespace std; const int N = 10000; vector<int> vec(N); int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> vec[i]; } sort(vec.begin(), vec.begin() + n); int sum = 0; for (int i = 0; i < m; i++) { sum += vec[i]; } ...
#include <bits/stdc++.h> namespace algo { using std::swap; const long double PI = 3.141592653589793238462643383279502884L; const long double E = 2.718281828459045235360287471352662498L; const long double EPS = 1e-12L; template <typename T1, typename T2> T1 bin_pow(T1 a, T2 n) { T1 r{1}; while (n >...
#include <bits/stdc++.h> using namespace std; int main() { int t, i; string s; cin >> t; while (t--) { cin >> s; int cap = 0, sm = 0, dig = 0; for (i = 0; i < s.size(); i++) { if (s[i] >= 65 && s[i] <= 90) { cap++; } else if (s[i] >= 97 && s[i] <= 122) { ...
#include <bits/stdc++.h> using namespace std; bool BeauYear(int y) { int a = y % 10; int b = (y / 10) % 10; int c = (y / 100) % 10; int d = (y / 1000) % 10; if (a != b && a != c && a != d && b != c && b != d && c != d) return true; return false; } int main() { ios_base::sync_with_std...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, a, b, q, p[N], d[N]; vector<pair<int, int> > g[N]; int dp[N][17], v, ud[N], ans[N]; bool vis[N]; void dfs(int u) { vis[u] = 1; for (int i = 0; i < (int)g[u].size(); ++i) { v = g[u][i].first; if (!vis[v]) { ...
#include <bits/stdc++.h> using namespace std; string tobinary(long long x) { string ret; char ch; while (x) ch = 0 + (x % 2), ret = ch + ret, x /= 2; return ret; } long long todecimal(string s) { int sz = s.size(); long long ret = 0; for (int i = 0; i < sz; i++) ret = 2 * ret + (s[...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > points; pair<int, int> dif(pair<int, int> pa, pair<int, int> pb) { pair<int, int> res; res.first = pb.first - pa.first; res.second = pb.second - pa.second; return res; } int dot(pair<int, int> a, pair<int, int> b) { retu...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n; char s[5001]; int dp[5001][5001]; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( n%c , &s[i]); } dp[1][0] = 1; for (int j = 1; j <= n; ++j) { dp[1][j] = 0; } for (int i...
#include <bits/stdc++.h> using namespace std; using lli = long long; using Double = long double; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s[9][3]; for (int i = 0; i < 9; ++i) { for (int j = 0; j < 3; ++j) { cin >> s[i][j]; } } ...
#include <bits/stdc++.h> using namespace std; char str[606]; long long tmp[80]; long long mat[2000][32]; int see[2000]; int main() { int M; scanf( %d , &M); for (int i = 0; i < M; i++) { scanf( %s , str); int len = 0; while (str[len]) len++; for (int j = 0; j < 80; j++) t...
#include <bits/stdc++.h> using namespace std; const int maxm = 2e5 + 10; set<int> g; queue<set<int> > q; int m, n, x, y; int dfs(int top) { if (abs(top) <= 1) return 0; int now = 0; if ((-top) % 2 == 0) now = top / 2; else now = (top + 1) / 2; if (g.find(now) == g.end()) { ...
#include <bits/stdc++.h> using namespace std; vector<int> v; int qtd[100001]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { int a; scanf( %d , &a); v.push_back(a); } sort(v.begin(), v.end()); int cont = 0; for (int i = 1, tmp = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; struct W { int t, l, r; } w[100010]; int n, m, s, f; int main() { while (cin >> n >> m >> s >> f) { for (int i = (0); i < (m); i++) { cin >> w[i].t >> w[i].l >> w[i].r; } int t = 1, p = 0; int dir = f > s ? 1 : -1; whi...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int n, d, p[30005], dp1[60005][700]; int occ[30005]; int main() { scanf( %d%d , &n, &d); int xb, x2, x3; for (xb = 0; xb < n; xb++) { scanf( %d , &p[xb]); p[xb]--; occ[p[xb]]++; } d--; int res = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int t, cnt[N]; int mx; int check(int row, int col, int n, int m) { if (row < 0 || row >= n || col < 0 || col >= m) return 0; int i = 0, j = 0, ok = 1; for (; i < n; i++) { for (j = 0; j < m; j++) { if (!cnt[abs(ro...
#include <bits/stdc++.h> int main() { int i, j; int str[6]; int num[6]; char ch; for (i = 0; i < 6; i++) { str[i] = 0; num[i] = 0; } for (i = 0; i < 6; i++) { scanf( %c , &ch); switch (ch) { case R : str[0]++; break; case O : ...
#include <bits/stdc++.h> using namespace std; int Head[1000010], Next[1000010], Go[1000010], Val[1000010], iscut[1000010], Len[1000010], Dep[1000010], Fa[400010][21], Cnt = 1, n, m, q; int Head2[1000010], Next2[1000010], Go2[1000010], Val2[1000010], Cnt2 = 1; int DFN[1000010], MIN[1000010], ins[1000010], ...
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int x = 0, f = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 1) + (x << 3) - 0 + ch; ch = getchar(); } ...
#include <bits/stdc++.h> using namespace std; int a[1005]; int b[1005]; int h; bool cmp(int x, int y) { return x > y; } bool check(int x) { for (int i = 1; i <= x; i++) { b[i] = a[i]; } sort(b + 1, b + x + 1, cmp); long long sum = 0; for (int i = 1; i <= x; i += 2) { sum += (...
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf( %d , &x); return x; } template <typename T> inline istream& operator>>(istream& i, vector<T>& v) { for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j]; return i; } template <typename T> string join(const ...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; } p[8]; int cmp(node a, node b) { if (a.x == b.x) return (a.y < b.y); return a.x < b.x; } int main() { while (scanf( %d %d , &p[0].x, &p[0].y) != EOF) { int cnt1 = 0; int cnt2 = 0; int cnt3 = 0; int...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { double x, y, z, a, b, c, sq; cin >> x; a = 1.0, b = x, c = x; z = (b * b) - (4 * a * c); if (z < 0) { cout << N << endl; continue; } y = (...
#include <bits/stdc++.h> using namespace std; int r1, r2; int c1, c2; int b, e, k; int main() { ios_base::sync_with_stdio(0); b = e = k = 0; cin >> r1 >> c1; cin >> r2 >> c2; if (r1 > r2) { swap(r1, r2); swap(c1, c2); } b = (r1 == r2 || c1 == c2) ? 1 : 2; e = ((((r1...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 789; const int M = 2e5 + 5; const int NN = 1e5 + 55; const long long mod = 1e9 + 7; const long long inf = 0x3f3f3f3f; const long long INF = 1LL << 62; bitset<2000> P[N], S[N], T; char ms[N][N]; int main() { ios::sync_with_stdio(0)...
#include <bits/stdc++.h> using namespace std; inline void Boost() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int NMax = 1e6 + 50; string convert(const string &s) { string ret = @ ; for (int i = 0; i < (int)s.size(); ++i) { ret += # + s.substr(i, 1); ...
#include <bits/stdc++.h> using namespace std; bool is_prefix(string s, string comp) { bool res = false; int sz = s.size(); int comp_sz = comp.size(); if (sz > comp_sz) return res; else { res = true; for (int i = 0; i < sz; i++) { if (s[i] != comp[i]) { res = f...
#include <bits/stdc++.h> int du[100010], fa[100010], s1[100010], s2[100010]; int find(int x) { if (x != fa[x]) fa[x] = find(fa[x]); return fa[x]; } int main() { int n, m, x, y, i, j, k, sum; scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) fa[i] = i; memset(du, 0, sizeof(du)); memset(...
#include <bits/stdc++.h> const int maxn = 100001; int n, val[maxn], cL[maxn], cR[maxn], ord[maxn], tot, in[maxn], out[maxn], bit[maxn], ans; bool vis[maxn]; void dfs(int u) { if (u == -1) return; in[u] = ++tot; dfs(cL[u]); dfs(cR[u]); out[u] = tot; } void bit_add(int x, int v) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 210; int n, m, x; long long dp[maxn][maxn], v[maxn], ans = -1; void read_and_parse() { scanf( %d%d%d , &n, &m, &x); for (int i = 1; i <= n; i++) scanf( %d , &v[i]); } void solve() { memset(dp, 0xcf, sizeof(dp)); dp[0][0] = 0; ...
#include <bits/stdc++.h> using namespace std; void checkDefine(); string x; string y; string z; int main() { cin >> x >> y; long long int n = x.size(); for (int i = (0), _b = (n - 1); i <= _b; i++) { if (x[i] < y[i]) { cout << -1; return 0; } } cout << y; ...
#include <bits/stdc++.h> using namespace std; template <class L, class R> ostream &operator<<(ostream &os, map<L, R> P) { for (auto const &vv : P) os << ( << vv.first << , << vv.second << ) ; return os; } template <class T> ostream &operator<<(ostream &os, set<T> V) { os << [ ; for (au...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; const long double pi = acos(-1); const int MOD = 1e9 + 7; const int N = 2e5 + 100; int tr_min[4 * N][1 << 5]; int tr_max[4 * N][1 << 5]; vector<int> cara[N]; int n, k; void build(...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; bool operator<(pair<int, int> lhs, pair<int, int> rhs) { return (lhs.first != rhs.first) ? (lhs.first < rhs.first) : (lhs.second < rhs.second); } set<pair<int, int> > inqUp, inqDown, pendUp, pendDown...
#include <bits/stdc++.h> using namespace std; map<char, char> mp; string check(string s) { for (int i = 0; i <= s.size() / 2; i++) if (s[i] != mp[s[s.size() - 1 - i]]) return NIE ; return TAK ; } int main() { mp[ A ] = A ; mp[ b ] = d ; mp[ d ] = b ; mp[ H ] = H ; mp[ I...
#include <bits/stdc++.h> using namespace std; int main() { int a[3][3], b[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; a[i][j] %= 2; b[i][j] = 0; } } pair<int, int> f[] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {0, 0}}; for (in...
#include <bits/stdc++.h> using namespace std; const int maxn = 200000; const long long mod = 1e9 + 7; long long fac[maxn + 5], inv[maxn + 5]; long long f[2005]; struct node { long long x, y; } data[2005]; long long qmod(long long a, long long b) { long long ans = 1; a = a % mod; while (b...
#include <bits/stdc++.h> using namespace std; int n, x[100], s[100]; struct par { int v, id; bool operator<(const par &r) const { return v < r.v; } }; vector<par> v; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &x[i]); v.push_back({x[i], i}); } ...
#include <bits/stdc++.h> using namespace std; const int oo = 3e5 + 7; unordered_map<int, vector<int>> values[2]; int t, n, q, a[oo], p[oo]; vector<int> ans; int psum(int l, int r) { return p[r] - (l ? p[l - 1] : 0); } int first(vector<int>& list, int val) { int l = 0, r = list.size(); while (l < r...
#include <bits/stdc++.h> using namespace std; int a[1050], b[1050]; int main() { int n, m, s = 0, d = 0; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i]; b[i] = a[i]; } for (int i = 1; i <= n; i++) { sort(a, a + m); for (int j = 0; j < m; j++) { if (a[j...
#include <bits/stdc++.h> using namespace std; long long mx(long long a, long long b) { return a >= b ? a : b; } long long mn(long long a, long long b) { return a <= b ? a : b; } string a[3] = {( twone ), ( two ), ( one )}; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long lon...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; int max = 0; vector<int> b; int x; for (int i = 0; i < a; i++) { cin >> x; b.push_back(x); } sort(b.begin() + 1, b.end()); int count = 0; if (b[0] > b[b.size() - 1]) { cout << 0 ; ...
#include <bits/stdc++.h> using namespace std; int vet[1010], dp[2][1010]; const int mod = 998244353; long long soma(long long x, long long y) { x += y; if (x >= mod) x -= mod; return x; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> vet[i]; } for (...
#include <bits/stdc++.h> using namespace std; template <class node> struct link_cut_tree { bool connected(node* u, node* v) { return lca(u, v) != NULL; } int depth(node* u) { access(u); return get_sz(u->ch[0]); } node* get_root(node* u) { access(u); while (u->ch[0]) u = u->...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; const int N = 1e5 + 10; const long long mod = 1e9 + 7; const long long mod2 = 998244353; const int inf = 1e9; const int LOG = 22; long long pw(long long a, long long b, long long M) { return (!b ? 1 : (b & 1 ? (a...
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 60; string operator*(const string& s, int k) { if (k == 0) return ; string p = (s + s) * (k / 2); if (k % 2 == 1) p += s; return p; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; ...
#include <bits/stdc++.h> using namespace std; int vis[100005], mark[100005]; vector<int> g[100005]; int prob = 0; void dfs(int node, int k) { mark[node] = k; vis[node] = 1; for (auto i : g[node]) { if (!vis[i]) { dfs(i, 1 - k); } else { if (mark[i] == k) { pro...
#include <bits/stdc++.h> using namespace std; int n, pd[4][10100], x, y, gox[4] = {1, 0, -1, 0}, goy[4] = {0, 1, 0, -1}, w[16], dp[10100][8], mo = 1000000007; char getin() { char ch = getchar(); while (ch != . && ch != X && ch != O ) ch = getchar(); return ch; } i...
#include <bits/stdc++.h> using namespace std; template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x < 0 ? -x : x; } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } set<vector<int> > s; vector<pair<char, pair<int, int> >...
#include <bits/stdc++.h> using namespace std; void fast(); int main() { fast(); int k, d; cin >> k >> d; string ans = ; if ((d > (pow(10, k) - 1)) || (d == 0 && k != 1)) { cout << No solution ; return 0; } for (int i = 0; i < k; i++) { if (d > 9) { ans += ...
#include <bits/stdc++.h> using namespace std; const int INF = 1029384756; const double PI = acos(-1); const double EPS = 0.0000000304; long long A, B, C; int main() { scanf( %I64d%I64d%I64d , &A, &B, &C); if ((A % 2) == (B % 2) && (B % 2) == (C % 2)) { printf( %I64d , A + B + C - max(A, max(B,...
#include <bits/stdc++.h> using namespace std; vector<long long int> v; int main() { long long int n, m, a, b, sum = 0, i, j, k; cin >> n >> k; long long int s[n], x[n]; for (i = 0; i < n; i++) { cin >> a >> b; sum += min(a, b); v.push_back(min(2 * a, b) - min(a, b)); } so...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << p.first << , << p.second; } template <typename T> struct point { T x, y; point(T xx = 0,...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) neg = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - 0 , c = getchar(); return x * neg; } inline int qpow(int x, int e, int...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int t, n, son[maxn], root, p[maxn], rt; vector<int> g[maxn]; void dfs(int u, int fa) { son[u] = 1; p[u] = fa; for (auto it : g[u]) { if (it == fa) continue; dfs(it, u); son[u] += son[it]; } } void ge...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool cmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int N = 444444; int fa[N], ch[N][26], l[N], f[N], a[N], c[N], pos[N], top[N]; char s[N]; int last = 1, cnt = 1, n, ans = 1; void ins(int c, int k) { int p ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const long long MOD = 998244353; const long long N = (long long)1e4 + 9; const long long inf = 1 << 30; template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b) { r...
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846; int a[100010], d[100010]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) scanf( %d , a + i); for (int i = 1; i <= n + 1; i++) d[i] = a[i] - a[i - 1]; stack<int> st; int r = 0; for (int...
#include <bits/stdc++.h> using namespace std; long long n, k, q, a, b, ans, t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> q; while (q--) { cin >> k >> n >> a >> b; ans = a * n; if (b * n >= k) cout << -1 << n ; else { if...
#include <bits/stdc++.h> using namespace std; long long n, m, k, x, y, z, a[5005], b[50005], ans, val; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; cin >> m; for (long long i = 0; i < m; i++) cin >> b[i]; s...
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long INF = ~0ULL >> 1; template <class T> inline void read(T &n) { char c; int flag = 1; for (c = getchar(); !(c >= 0 && c <= 9 || c == - ); c = getchar()) ; if (c == - ) flag = -1, n = 0; ...
#include <bits/stdc++.h> using namespace std; const int prime = 151; const long long mod = 1e9 + 7; const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; int slen, tlen; string t, s; unsigned long long hs1[maxn], base[maxn], hs2[maxn]; inline unsigned long long check(int l, int r, unsigned long long h...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& x) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == - ) fu = 1, c = getchar(); for (x = 0; c > 32; c = getchar()) x = x * 10 + c - 0 ; if (fu) x = -x; }; template <...
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; ...