func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, m; struct Node { long long x, y; } Edge[300005]; long long pre[300005]; bool cmp(Node a, Node b) { return a.y > b.y; } int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %lld%lld , &Edge[i].x, &Edge[i].y); } ...
#include <bits/stdc++.h> using namespace std; char x, y, t; struct node { char c; int p; } ans[4]; inline bool cmp(const node &a, const node &b) { return a.p < b.p; } int main() { for (register int i = 1; i <= 3; i++) { ans[i].c = A + i - 1; cin >> x >> t >> y; if (t == > ) ...
#include <bits/stdc++.h> using namespace std; const int MX = 1e6 + 5; long long ans[MX]; long long upd[MX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, w; cin >> n >> w; vector<int> a[n]; int mx[n]; for (int i = 0; i < n; i++) { int l; cin >> l; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string a; string b; cin >> a >> b; int order = 0; while (a[order] == 0 ) { order++; } a.erase(0, order); order = 0; while (b[order]...
#include <bits/stdc++.h> unsigned long long tmp[131073], invn; int a_[131072]; inline int ksm(unsigned long long a, int b) { int ans = 1; while (b) (b & 1) && (ans = a * ans % 998244353), a = a * a % 998244353, b >>= 1; return ans; } void init(int n) { for (int i = 1; i < n; i++) a...
#include <bits/stdc++.h> using i8 = std::int8_t; using i16 = std::int16_t; using i32 = std::int32_t; using i64 = std::int64_t; using u8 = std::uint8_t; using u16 = std::uint16_t; using u32 = std::uint32_t; using u64 = std::uint64_t; auto SolveTest() -> void { int n; std::cin >> n; std::vec...
#include <bits/stdc++.h> using namespace std; int n; unordered_map<int, int> mask, f; int SG(int s) { if (f.count(s)) return f[s]; bool t[30] = {0}; for (int i = 0; s >> i; i++) { t[SG(s >> (i + 1) | (s & ((1 << i) - 1)))] = 1; } for (int i = 0; i < 30; i++) if (!t[i]) return f[s...
//Author: AnandRaj uux #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef pair<ll,ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; typed...
#include <bits/stdc++.h> using namespace std; const int maxn = 5; inline long long rd() { long long x = 0; char c = getchar(); int neg = 1; while (c < 0 || c > 9 ) { if (c == - ) neg = -1; c = getchar(); } while (c >= 0 && c <= 9 ) x = x * 10 + c - 0 , c = getchar(); ...
#include <bits/stdc++.h> using namespace std; const int N = 405; int n, kk; vector<pair<int, int>> v[N][N], e[N]; int dp[N][N], sz[N], f[N]; void dfs1(int pos, int fa) { sz[pos] = 1; for (auto &i : e[pos]) if (i.first != fa) { dfs1(i.first, pos); sz[pos] += sz[i.first]; ...
#include <bits/stdc++.h> using namespace std; int c3[100010], c2[1010]; int graph[110][110]; int main() { ios ::sync_with_stdio(0); cin.tie(0); memset(graph, 0, sizeof graph); for (int i = (3), _b = (100); i <= _b; ++i) { c3[i] = (i * (i - 1) * (i - 2)) / 6; } for (int i = (2), _b ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout << setprecision(10); int row, column; char temp; cin >> row >> column; for (int i = 0; i < int(row - 1); ++i) { for (int j = 0; j ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; int test[maxn]; int main() { int n, num(0), x; cin >> n; char ch; int l = 2e5; int r = l + 1; int mi, ma; for (int i = 0; i < n; i++) { cin >> ch >> x; if (ch == L ) { test[x] = l; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 2; int len, ans = 0, maxdis[N]; vector<int> adj[N], cur; void dfs(int x, int p) { if (adj[x].size() == 1) { maxdis[x] = 0; return; } int i, idxmin1; for (i = 0; i < adj[x].size(); i++) { if (adj[x][i] != p) { ...
#include <bits/stdc++.h> using namespace std; struct node { int u , v , w; node(){} node(int u,int v,int w): u(u) , v(v) , w(w){}; bool operator < (const node &o) const { return w < o.w; } }; struct dsu { int par[200010]; void init() { ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int a[N]; vector<int> v; int main() { int n, s; scanf( %d%d , &n, &s); int ans = 0; for (int i = 1; i <= n; i++) scanf( %d , &a[i]); if (a[s] != 0) ans++; for (int i = 1; i <= n; i++) if (i == s) continu...
#include <bits/stdc++.h> using namespace std; const int base = 998244353; int sum(int a, int b) { int c = a + b; if (c >= base) return c - base; return c; } int diff(int a, int b) { int c = a - b; if (c < 0) return c + base; return c; } int mul(int a, int b) { return (int)(a * (lon...
#include <bits/stdc++.h> using namespace std; long long m = 1e9 + 7; long long c[4010][4010]; long long dp[4010]; int main() { c[0][1] = 0; for (int i = 0; i <= 4000; i++) c[i][0] = 1; for (int i = 1; i <= 4000; i++) { for (int j = 1; j < i + 2; j++) c[i][j] = (c[i - 1][j] + c[i - 1]...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, p; long long int cost; bool na; string line; vector<int> a, b; pair<int, int> t; priority_queue<pair<int, int> > q; getline(cin, line); n = line.length(); a.resize(n); b.resize(n); m = 0; for (in...
#include<cstdio> #include<iostream> #include<queue> #include<algorithm> #include<cstring> #include<set> #include<vector> #include<cmath> #define PII pair<int,int> #define pb push_back #define ep emplace_back #define mp make_pair #define fi first #define se second using namespace std; inlin...
#include <bits/stdc++.h> using namespace std; int main() { int singles, doubles, n; cin >> n >> singles >> doubles; int refused = 0, partlyOccDoubles = 0; for (int i = 0; i < n; i++) { int cur; cin >> cur; if (cur == 1) { if (singles > 0) { singles--; } el...
#include <bits/stdc++.h> using namespace std; void run(); int main() { ios::sync_with_stdio(0); cout.precision(10); run(); } struct vec2 { int x, y, sum; vec2 *c, *rgb; inline bool operator<(vec2 const &a) const { return x < a.x or x == a.x and y < a.y; } }; int yc[100000...
#include <bits/stdc++.h> using namespace std; int f[1001000]; int dp[22][1001000]; int get(int x, int k) { for (int i = 21; i >= 0; i--) if (k & (1 << i)) x = dp[i][x]; return x; } int dist[1001000]; int foi[1001000]; vector<int> L[1001000]; char str[1001000]; char nova[1001000]; voi...
#include <bits/stdc++.h> using namespace std; int dp[10][10][10][10], pres_path; void dfs(int x, int y, int u, int v, int p); void dfs_next(int x, int y, int u, int v, int p) { int &t = dp[x][y][u][v]; if (t == 0 or t > pres_path + 1) { t = ++pres_path; if (p < 10) dfs(x, y, u, v, p + 1); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000007; char s[maxn]; int n, cnt, a[maxn]; bool check(int p, bool need_touch) { int x = 0, maxv = 0; bool touched = 0; for (int i = 1, _c = cnt; i <= _c; i++) { maxv = max(maxv, x); x += a[i]; if (x <= p) { x...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0; int sign = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) { sign |= c == - ; } for (; isdigit(c); c = getchar()) { x = x * 10 + c - 0 ; } return sign ? -x : x; } const int ms = 1 << 22;...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (k > (n % 2 == 0 ? n * n / 2 : (n * n + 1) / 2)) { cout << NO << endl; return 0; } cout << YES << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (k && (i...
#include <bits/stdc++.h> using namespace std; const int N = 1000000 + 10; int tot; vector<int> primes; int notP[N]; vector<long long> divisors[N]; map<pair<long long, int>, int> dp; int isP(long long x) { for (int i = 0; (long long)primes[i] * primes[i] <= x; ++i) { if (x % primes[i] == 0) ret...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int i, j, k; int ag[101], a[101][101]; int g = 0, dr[101], dl[101]; for (i = 1; i <= n; i++) { scanf( %d , &ag[i]); g += ag[i]; dl[i] = 1; dr[i] = ag[i]; for (j = 1; j <= ag[i]; j...
#include <bits/stdc++.h> const int maxn = 400010, maxq = 400010; int n, cnt[maxn], tmp[maxn], lg[maxn]; int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } struct SA { char S[maxn]; int nxt[maxn], mn[maxn], sa[maxn], r[2][maxn], *rk, ht[20][maxn]; void m...
#include <bits/stdc++.h> using namespace std; string ls[] = { , one , two , three , four , five , six , seven , eight , nine }; string fr[] = { , , twenty , thirty , forty , fifty , sixty , seventy , eighty , ninety }; int main() { ios_...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { double n, m, k; cin >> n >> m >> k; if (m == 0) cout << 0 << endl; else if (n / k >= m) { cout << (int)m << endl; } else { double zz = (m - (n / k)); in...
#include <bits/stdc++.h> using namespace std; int main() { int r, h, sum, n; float k, l; cin >> r >> h; n = h / r; h -= n * r; l = r / 2.0; k = sqrt(3) / 2 * r; if (h < l) sum = n * 2 + 1; if (h >= l && h < k) sum = n * 2 + 2; if (h >= k) sum = n * 2 + 3; cout << sum << e...
#include <bits/stdc++.h> namespace IO { const unsigned int Buffsize = 1 << 15, Output = 1 << 23; static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_; static char Out[Output], *nowps = Out; inline void flush() { fwrite(Out, 1, nowps - Out, stdout); nowps = Out; } template <typename T> inline T Read()...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); vector<int> v(n); vector<pair<int, int>> vv(n); for (int i = 0; i < n; i++) { scanf( %d , &v[i]); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; ostream& operator<<(ostream& os, vector<int>& x) { for (int i = 0; i < x.size(); i++) os << x[i] << ; return os; } ostream& operator<<(ostream& os, pair<int, int> x) { cout << x.first << << x.second << ; return os; } ostream& operator<<...
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int a1[n], a2[n]; for (int i = 0; i < n; i++) a1[i] = s[i] - 0 ; for (int i = n; i < 2 * n; i++) a2[i - n] = s[i] - 0 ; for (int i = 0; i < n; i++) { int s1(i), s2(i); for (int j = i ...
#include <bits/stdc++.h> using namespace std; const int INF = int(1e9); long long n, m; pair<long long, long long> p = make_pair(0, 0); long long b[222222]; long long c[222222]; long long ans; map<long long, long long> mp; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> heros(n); for (auto& x : heros) cin >> x; sort(heros.begin(), heros.end()); long long sum = accumulate(heros.begin(), heros.end(), 0ll); int m; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 3; int last[22][22]; int a[maxn], dp[20][maxn]; int main() { ios_base::sync_with_stdio(false); int n, q; cin >> n >> q; for (int i = 1; i <= n; i++) cin >> a[i]; int l = 19; memset(last, 63, sizeof last); memset(d...
#include <bits/stdc++.h> using namespace std; int n, k; int a[100005]; int b[100005]; bool ok(long long x) { long long s = k; for (int i = 0; i < n; i++) { if (x * a[i] >= b[i]) { s -= (x * a[i] - b[i]); } if (s < 0) { return false; } } return true; } ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<string> a(n); map<string, int> M; for (int i = 0; i < n; ++i) { cin >> a[i]; M[a[i]] = i; } vector<vector<int> > Inv(1 << n, vect...
#include <bits/stdc++.h> using namespace std; const int N = 14; const int Q = 101; int n, m, q; long long dp[N][1 << N]; bool edge[N][N]; int a[Q], b[Q], c[Q]; int lowbit(int x) { return x & (-x); } int in(int i, int S) { return ((S >> i) & 1); } bool check(int u, int k) { for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; int t = 1; void solve() { long long n, i, k, s = 0, b; cin >> n >> k; long long a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); b = a[0]; for (i = 1; i < n; i++) { long long c = (k - a[i]) / b; if (c > 0...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 20; const int inf = 0x3f3f3f3f; const int modd = 1e9 + 7; inline int read() { int x = 0, f = 1; char c = getchar(); while (c != - && (c < 0 || c > 9 )) c = getchar(); if (c == - ) f = -1, c = getchar(); while (c >= ...
#include <bits/stdc++.h> using namespace std; int n, leaf; vector<int> vt[100005]; int ara[100005], chk[100005], level[100005], child[100005]; map<int, int> mp; void bfs() { int i, j, k; queue<int> qu; qu.push(0); chk[0] = 1; level[0] = 0; while (!qu.empty()) { k = qu.front(); ...
#include <bits/stdc++.h> using namespace std; int testnum; const int maxn = 100005; int par[maxn]; int size[maxn]; int find(int u) { if (par[u] == u) return u; return par[u] = find(par[u]); } bool unify(int u, int v) { int cu = find(u), cv = find(v); if (cu == cv) return true; if (si...
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf( %d , &n); if (n <= 2) { puts( No ); return 0; } puts( Yes ); if (n & 1) { printf( 2 1 %d n , n); printf( %d , n - 2); for (int i = 2; i < n; i++) printf( %d , i); puts( ); } els...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long N = 100000; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << { ; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << , ; os << *it; ...
#include <bits/stdc++.h> using namespace std; int main() { int ab, bc, ca, abc; int temp[4]; for (int i = 0; i < 4; i++) { cin >> temp[i]; } sort(temp, temp + 4); ab = temp[0]; bc = temp[1]; ca = temp[2]; abc = temp[3]; int a, b, c; a = abc - bc; b = ab - a; ...
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e) { cout << e << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << << e2 ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, T, ans = 0; cin >> n >> a >> b >> T; vector<int> d(n, 1); for (int& p : d) { char c; cin >> c; if (c == w ) p += b; } vector<int> rtime(n), ltime(n); rtime[0] = d[0], ltime[0] = d[0]; for (int ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, l; cin >> n >> l; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); double maxy = INT_MIN * 1.0; for (int i = 0; i < n - 1; i++) { ...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) return a; else return b; } long long min(long long a, long long b) { if (a < b) return a; else return b; } long long power(long long B, long long P) { if (P == 0) re...
#include <bits/stdc++.h> using namespace std; const int INF = 0x6fffffff; const int MINF = 0x80000000; const long long mod = 1000000007; const int cons = 100001; const double pi = 3.141592653589793; vector<int> pos; bool isOk(int x, int t) { double res = 0; for (int i = 1; i < pos.size(); i++) {...
#include <bits/stdc++.h> using namespace std; const int oo = 1000000001; int dp[1200][1200], out[1200][5], pre[1200][1200], a[1200]; int i, j, last, n, mi; int main() { while (~scanf( %d , &n)) { for (i = 0; i < n; i++) scanf( %d , &a[i]); if (n == 1) { printf( %d n%d n , a[0], 1); ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:1024000000,1024000000 ) template <typename T> T Max(T a, T b) { return a > b ? a : b; } template <typename T> T Min(T a, T b) { return a < b ? a : b; } template <typename T> T Abs(T A) { return A > 0 ? A : -1 *...
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 5; const long long base = 9999991; int n, m; char s1[maxN], s2[maxN]; vector<int> res; long long p[maxN], h1[30], h2[30]; int mark[30]; int check() { for (int i = 0; i <= 25; ++i) if (h1[i]) { mark[i] = -1; ...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; cin >> a >> b >> c; long long sum = 2 * c; sum += 2 * min(a, b); if (a > b || b > a) sum++; cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int ans = INT_MAX; char W[100001]; scanf( %100000s , W); string s = W, t = Bulbasaur ; map<char, int> I, M; for (char ch : t) ++I[ch]; for (char ch : s) ++M[ch]; for (auto p : I) { ans = min(ans, M[p.first] / p.second)...
#include <bits/stdc++.h> using namespace std; const int N = 2e5; const int lg = 22; int spt[2 * N + 100][lg], par[N + 100][lg], H[N + 100], E[2 * N + 100], L[2 * N + 100]; int dept[2 * N + 100], vis[N + 100], mx[N + 100][lg], P[N + 100], rg[2 * N + 100], idx = 1; vector<pair<int, int> > g[N + 10...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n; int data[maxn]; int f[25][maxn]; bool mark[(1 << 25)], tt; int res = 0, p; int tmp; int tm, tp; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> data[i]; memset(mark, 0, sizeof(mark)); for (i...
#include <bits/stdc++.h> using namespace std; map<string, int> person; vector<pair<int, string> > points; int cnt; bool compare(pair<int, string> a, pair<int, string> b) { if (a.first == b.first) return a.second < b.second; return a.first > b.first; } void update(string name, int p = 0) { if (...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 2e6 + 5; char s[maxn], t[maxn]; int m; struct Suffixam { struct state { int len, link; map<char, int> next; }; int id[maxn << 1], size[maxn << 1], cnt[maxn << 1]; state st[maxn << 1]; int las...
#include <bits/stdc++.h> using namespace std; const int mN = 30; int a[mN]; int n; void output(int x) { string s; string mid; for (int i = 1; i <= n; i++) { if (a[i] / x % 2) mid += char(i + a - 1); for (int j = 1; j <= a[i] / x / 2; j++) s += char(i + a - 1); } s += mid; ...
#include <bits/stdc++.h> using namespace std; const int maxN = 130 * 1000 + 5; const int mod = 1000 * 1000 * 1000 + 7; short dp[21][32][maxN]; int mas[maxN]; int ss[6][maxN]; int a[20], b[20]; vector<int> v[6]; int c[20], d[20]; int n, m; char ans[20][20]; int p; void solve(int lev, int mask, ...
#include <bits/stdc++.h> long long min(long long x, long long y) { if (x > y) return y; else return x; } int main() { long long n, m; long long k; scanf( %I64d %I64d %I64d , &n, &m, &k); long long l = 1, r = n * m, mid, sum; while (l <= r) { mid = (l + r) >> 1; ...
#include <bits/stdc++.h> using namespace std; bool vis[8][8]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); char t; int y, x; cin >> t >> y; --y; x = t - a ; for (int i = 0; i < 8; i++) { vis[i][y] = true; vis[x][i] = true; } auto mark = [&](...
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e16; const int N = 900300; const int K = 40; int n; long long a[N]; long long sum[N]; long long dp[N][2]; int par[N][2][3]; int intPoint[N]; int m; vector<int> ans; long long getCost(int L, int R, int f1, int f2) {...
#include <bits/stdc++.h> using namespace std; int p[111], s[111], v[111]; int main() { int n, m, k, i, Nr = 0, c; cin >> n >> m >> k; for (i = 1; i <= n; ++i) cin >> p[i]; for (i = 1; i <= n; ++i) { cin >> s[i]; if (p[i] > v[s[i]]) v[s[i]] = p[i]; } for (i = 1; i <= k; ++i) { ...
#include <bits/stdc++.h> using namespace std; long long n, m, u, cnt = 1, ch[4000005][4], dp[4000005][4], dpp[60][4][4]; long long rev[2][4], nw = 0, ans = 0; char s[100005]; const long long inf = 2e18; void dfs(int p) { for (int i = 0; i < 4; i++) dp[p][i] = inf; for (int i = 0; i < 4; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> ans, a; int n, temp; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &temp); a.push_back(temp); } for (int i = 0; i < a.size(); i++) { if (a[i] == 1) { ans.push_back(1); } else {...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; string gen = ACTG ; int sum = 10000; vector<bool> used_big(n, false); vector<bool> used_gen(4, false); for (int i = 0; i <= n - 4; i++) { int tmp_sum = 0; for (int j = 0; ...
#include <bits/stdc++.h> using namespace std; void precalc(){}; const int N = 3010; int n, m; vector<vector<int>> g; vector<vector<int>> dist; pair<int, int> pre[N][3], post[N][3]; void bfs(int x) { queue<int> q; q.push(x); while (q.size()) { int head = q.front(); q.pop(); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, c = 1; cin >> n >> t; int mn = INT_MAX; for (int i = 1; i <= n; i++) { int s, d; cin >> s >> d; while (s < t) { s += d; } if (s < mn) { mn = s; c = i; } } cout << ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); string a; cin >> a; vector<int> res[2]; for (char e : a) { vector<int> ne[2]; if (e == a ) { ne[0] = res[1]; ne[0].push_back(1); ne[1...
#include <bits/stdc++.h> using namespace std; int v, m, d, f; int main() { int n, a, b, c; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b >> c; if (a == 1) { v += b; m += c; } else { d += b; f += c; } } if (v >= m) cout << L...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <cl...
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f; const long long MOD = 1e9 + 7; const long double EPS = 1e-9; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string grid[3][3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) ...
#include <bits/stdc++.h> using namespace std; int n, a, b, arr[100009]; int main() { cin >> n >> a >> b; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); cout << max(arr[n - a] - arr[n - a - 1], 0); }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); long long n, m; cin >> n >> m; map<long long, set<long long>> adj; for (long long i = 0; i < m; i++) { long long a, b; cin >> a >> b; adj[a].ins...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); inline double cross(double x1, double y1010101010101, double x2, double y2) { return x1 * x2 + y1010101010101 * y2; } inline double len(double x, double y) { return sqrt(x * x + y * y); } inline double angle(double x1, double y101...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int mod = 1e9 + 7; const long long inf = 1e17; char a[maxn], b[maxn], s[maxn]; int v[200]; int main() { int q; scanf( %s%s , a, b); int n = strlen(a); for (int i = 0; i < n; ++i) v[a[i]] = 1; n = strlen(b); ...
#include <bits/stdc++.h> using namespace std; struct hehe { unsigned long long l, r; mutable bool z; inline bool operator<(hehe y) const { return l < y.l; } }; set<hehe> s; inline set<hehe>::iterator split(unsigned long long pos) { hehe qaq; qaq.l = pos; qaq.r = 0; qaq.z = 0; s...
#include <bits/stdc++.h> using namespace std; multiset<int> st; multiset<int>::iterator it; int arr[200000]; int main() { int n, i, a, b, c, ans = 0, temp[3]; scanf( %d , &n); scanf( %d , &temp[0]); scanf( %d , &temp[1]); scanf( %d , &temp[2]); sort(temp, temp + 3); a = temp[0]; ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; int best = 1e9; for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; best = min(best, x - 1); best = min(best, n - x); best...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> ans1; vector<char> ans2; int n1, n2; cin >> n1; vector<int> a1(n1); for (int i = 0; i < n1; i++) { cin >> a1[i]; } cin >> n2; vector<int> a2(n2); for (int i = 0; i < n2; i++) { cin >> a2[i]; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int t; int n; long long dp[500010][2]; long long x; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n + 1; i++) { ...
#include <bits/stdc++.h> using namespace std; long long t, n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n; long long k = 0, l = 0; for (int i = 0; i < (n); i++) { long long a; cin >> a; if (a % 2...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int tot; struct node { node *ch[26], *fail; int len, id; node* init(int tlen) { memset(ch, 0, sizeof(ch)); fail = NULL; len = tlen; return this; } } * root, spT[N]; vector<int> g[N]; void addin(cha...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string cad; cin >> cad; map<char, int> M; for (int i = 0; i < cad.size(); i++) M[cad[i]]++; int xx = M[ x ]; int yy = M[ y ]; int ans = max(xx, yy) - min(xx, yy); if (max(xx, yy) == M[ x ]) ...
#include <bits/stdc++.h> using namespace std; const int N = 200 * 1000 + 85; int n, m; int a[N]; vector<int> vec[N]; pair<pair<int, int>, int> b[N]; int mapp[N]; int ans[N]; int seg[N << 2]; inline void add(int, int, int = 1, int = 0, int = N); inline int get(int, int = 1, int = 0, int = N); int...
#include <bits/stdc++.h> using namespace std; int n, m, cnt; vector<int> e[105]; bool f[105]; void dfs(int x) { f[x] = 1, ++cnt; for (int i = 0; i < e[x].size(); ++i) if (!f[e[x][i]]) dfs(e[x][i]); } void work() { int i, x, y; scanf( %d%d , &n, &m); if (n != m) { puts( NO )...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 2e2 + 10; int main() { int n, m; cin >> n >> m; int l = 1, r = INF; int ans = 0; while (l <= r) { int mid = (r + l) / 2; int z = mid / 6; int x = mid / 2 - z; int y = mid / 3 - ...
#include <bits/stdc++.h> using namespace std; int n, m; int cnta[10], cntb[10]; int a[15][2], b[15][2]; int one_common(int x, int y) { if (a[x][0] == b[y][0] && a[x][1] != b[y][1]) return a[x][0]; if (a[x][1] == b[y][0] && a[x][0] != b[y][1]) return a[x][1]; if (a[x][0] == b[y][1] && a[x][1] != b[...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; const int MAX = 1e6; vector<bool> t(MAX + 1); for (int i = 0; i < n; ++i) { int x; cin >> x; t[x] = true; } int d = ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const long long INF64 = 2000000000000000007; const int eps = 10e-6; long long solve(vector<int> one, vector<int> two, vector<int> three) { long long min_w = INF64; for (auto x : one) { long long b = x; auto a = lower...
#include <bits/stdc++.h> using namespace std; int n, m, a[100001]; long long s[100001], ans[100001]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1); for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i]; cin >> m; for ...
#include <bits/stdc++.h> using namespace std; int main() { char s[101]; cin >> s; int k = 1; for (int i = 1; s[i] != 0 ; ++i) { if (s[i] == s[i - 1]) k++; else k = 1; if (k == 7) break; } if (k >= 7) cout << YES ; else cout << NO ; re...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > AdjList; vector<int> dist; vector<int> unused; void update() { queue<int> now; for (int i = 0; i < unused.size(); i++) { dist[unused[i]] = 0; now.push(unused[i]); } while (!now.empty()) { int u = now.front(); ...