func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string rat[100], cw[100], man[100], c; int a = 0, b = 0, d = 0; for (int i = 0; i < n; i++) { string name, s; cin >> name >> s; if (s == captain ) c = name; else if (s == woman || s == ...
#include <bits/stdc++.h> using namespace std; int n, m, k; int p[2010] = {0}; int cnt = 0; int sum[2010]; int dp[2010]; int a[200010]; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); sort(a + 1, a + n + 1); n = min(n, k); for (int i = 1, x, ...
#include <bits/stdc++.h> using namespace std; int main() { int n, min = INT_MAX, count = 0; int arr[1000001]; int j; cin >> n; for (j = 0; j < n; j++) cin >> arr[j]; sort(arr, arr + n); int i, diff; for (i = 0; i < n - 1; i++) { j = i + 1; diff = arr[j] - arr[i]; if...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; using namespace std; int num[1001]; long long n; long long check(long long k) { long long p = 0, v = 0; long long t = n; while (t) { if (t >= k) { p += k; t -= k; } else { p += t; t...
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int mod = 1e9 + 7; int n, m, d, k, x, ans, pos[N], a[30]; bool f[1 << 20]; int cal(int x) { int res = 0; for (int i = (0); i < (m); i++) if (x & (1 << i)) res++; return res; } int main() { scanf( %d%d%d , &n,...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const int MOD = 1e9 + 7; int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; } int mul(int a, int b) { return 1ll * a * b % MOD; } int n, x[N], y[N]; vector<int> g[N]; map<int, int> px, py; int far[N], cnt, cir; void...
#include <bits/stdc++.h> int a, b, yue[100000], l[10100], h[10100], p[10100], ans[10100], gs, c, n; void qsort(int x, int y) { int i, j, t, mid; i = x; j = y; mid = yue[(i + j) / 2]; do { while (yue[i] < mid) i++; while (yue[j] > mid) j--; if (i <= j) { t = yue[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; map<char, int> mp; for (auto it : s) { mp[it]++; } int ans = 1; for (int i = 1; i * i <= k; i++) { ...
#include <bits/stdc++.h> using namespace std; long long nxt[45][3], lnk[45], pre[45][3]; string s; long long n; pair<long long, long long> sh[45][45][2]; long long dp[41][41][41][41][2]; long long sol(long long i, long long pre, long long l, long long r, long long f = 0) { if (pre == s...
#include <bits/stdc++.h> using namespace std; int a[1010]; int main() { int n, m; cin >> n >> m; int tmp; int ans = 0; memset(a, 0, sizeof(a)); for (int i = 1; i <= m; i++) { cin >> tmp; a[tmp]++; int b = 1; for (int i = 1; i <= n; i++) if (!a[i]) b = 0; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, q, x, y, cnt = 0; cin >> n >> q; vector<vector<long long int>> dp(3, vector<long long int>(n + 2, 0)); while (q--) { cin >> x >> y; if (dp[x][y] == 0) { cnt += (dp[3 - x][y] == 1); cnt += (dp[3 ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; long long ans = 0; priority_queue<int, vector<int>, greater<int>> pq; while (n--) { int x; cin >> x; if (pq.size() && x > pq.top()) { ans += x - ...
#include <bits/stdc++.h> int main() { int n, k; int h[1001] = {0}; scanf( %d%d , &n, &k); int i, j; for (i = 1; i <= n; i++) scanf( %d , &h[i]); int min = 9999999, nn = 1; for (i = 1; i <= n; i++) { if (h[i] < 1 + k * (i - 1)) continue; int ans = 0; for (j = 1; j <= n; j+...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; vector<int> v(2 * n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < 2 * n; i++) { if (i >= n) { v[i] = a[i - n]; } else v[i] = a[i]; } int an...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; scanf( %d%d%d , &a, &b, &c); int m; scanf( %d , &m); string s; int val, ans = 0; vector<int> u, p; for (int i = 0; i < int(m); i++) { cin >> val >> s; if (s[0] == U ) u.push_back(val); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, maxm = 1e5 + 5; int first[maxn], n, k; struct edge { int to; int next; } E[maxm]; int vis[maxn]; int order[maxn], p; int a[maxn]; bool dfs(int u) { vis[u] = -1; for (int e = first[u]; e != -1; e = E[e].next) { ...
#include <bits/stdc++.h> using namespace std; int n, m, q, cnt, f[400005]; int fnd(int x) { return f[x] == 0 ? x : f[x] = fnd(f[x]); } int main() { scanf( %d%d%d , &n, &m, &q); cnt = n + m - 1; for (int i = 1, x, y; i <= q; i++) { scanf( %d%d , &x, &y); y += n; x = fnd(x); y ...
#include <bits/stdc++.h> int main() { int n, m, a; scanf( %d%d%d , &n, &m, &a); printf( %I64d n , ((n - 1LL) / a + 1) * ((m - 1) / a + 1)); return 0; }
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 10; const int INF = 0x3f3f3f3f; const int mod = 998244353; struct node { int dif; long long need; bool operator<(const node &f) const { if (f.need != need) return f.need > need; else return f.dif > dif; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; map<int, bool> mp; for (int i = 0; i < m; i++) { int x; cin >> x; mp[x] = 1; } int pos = 1; int ans = -1; if (mp[pos]...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010, maxm = maxn * 2; int h[maxn], ne[maxm], e[maxm], cnt; int d[maxn], dp[maxn][3], w[maxn], root; int a[maxn]; int vis[maxn]; void solve() { int T; scanf( %d , &T); while (T--) { int n; scanf( %d , &n); for (...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFLL = 1e18; const int MOD = 1e9 + 7; const int MAXN = 2e5 + 5; vector<int> G[MAXN]; int n; long long s[MAXN]; long long a[MAXN]; void dfs(int v, int p) { if (s[v] == -1) { long long aux = INF; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(T x) { return x * x; } const double EPS = 1e-6; const int INF = 0x3fffffff; const long long LINF = INF * 1ll * INF; const double PI = acos(-1.0); using namespace std; long long gcd(long long a, long long b) { return b ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; t = 1; while (t--) { int n, k, mx = 0, mn = 101, j; cin >> n >> k; int a[n]; for (int i = 0; i < n; i += 1) { cin >> a[i]; mx = max(mx, a[i]); ...
#include <bits/stdc++.h> using namespace std; int n; string a[100]; int m[100][26]; bool s1[100]; string makestr(string s1, string s2) { char w = * ; string make = ; int s[26]; for (int i = 0; i < 26; ++i) s[i] = 0; for (int i = 0; i < s1.length(); ++i) s[int(s1[i]) - 97] = 1; for...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; vector<int> v[1000]; map<vector<int>, int> mp; const int N = 495; int dp[N * N]; int ns[10][10]; vector<int> from[N * N]; int deg[N * N]; void solve(int i, int j) { vector<int>& v1 = v[i]; vector<int>& v2 = v[j]; f...
#include <bits/stdc++.h> using namespace std; int A[1 << 18], vis[1 << 20], n, k, d, t; int main() { scanf( %d , &t); while (t--) { scanf( %d%d%d , &n, &k, &d); int ans = k, cnt = 0; for (int i = 1; i <= n; i++) { scanf( %d , &A[i]); if (!vis[A[i]]) cnt++; vis[A[i...
#include <bits/stdc++.h> const int N = 1123; const double eps = 1e-6; const int inf = (int)1e9 + 123; using namespace std; int n, m; char a[N][N]; int mini = inf; int d[N][N]; int sum(int x, int y, int x2, int y2) { return d[x2][y2] - d[x - 1][y2] - d[x2][y - 1] + d[x - 1][y - 1]; } bool check...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << ( << p.first << , << p.second << ) ; return os; } template <typename T1, typename T2, typename T3> ostream& operator<<(ostream& os, const tuple<T1, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int inf = INT_MAX; const long long inff = 1e18; const int mod = 1e9 + 7; long long a[50]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); a[0] = 0; for (long long i = 1; i <= 31; i++) { ...
#include <bits/stdc++.h> using namespace std; long long int computeXOR(long long int n) { if (n % 4 == 0) return n; if (n % 4 == 1) return 1; if (n % 4 == 2) return n + 1; return 0; } void solve() { vector<long long int> v; map<long long int, long long int> mp; long long int e, i, j,...
#include <bits/stdc++.h> void putin(char s[]); int main() { int i, total = 0; char c, ori1[120], ori2[120], ori3[120], a[6][400], temp[700]; putin(ori1); putin(ori2); putin(ori3); strcpy(a[0], ori1); strcat(a[0], ori2); strcat(a[0], ori3); strcpy(a[1], ori2); strcat(a[1], ori...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const long long inf = (((long long)1) << 61) + 5; const int N = 200005; int a[N]; int b[N]; int f1[N]; int f2[N]; int bit[N]; int n; int sum(int i) { int s = 0; ...
#include <bits/stdc++.h> using namespace std; struct node { int next, to; } e[500020 * 2]; int head[500020], cnt, fa[500020], n, sz[500020]; long long f[500020][2][2][4], g[2][2][4]; inline void adde(int x, int y) { e[++cnt].to = y; e[cnt].next = head[x]; head[x] = cnt; } void dfs(int x)...
#include <bits/stdc++.h> using namespace std; const int max_n = 1e5 + 5; vector<int> g[max_n], path; bool vis[max_n], x[max_n]; int s; void dfs(int u) { vis[u] = 1; x[u] ^= 1; path.push_back(u); bool leaf = 1; for (int v : g[u]) { if (!vis[v]) { if (!leaf) leaf = 0; ...
#include <bits/stdc++.h> using namespace std; const int OO = 0x3f3f3f3f, N = 1e2 + 5, mod = 1e9 + 7; int ans, lst = OO, gt[26]; string s1, s2; vector<int> idx[26]; int main() { cin >> s1 >> s2; for (int i = 0; i < s1.size(); ++i) idx[s1[i] - a ].push_back(i); for (int i = 0; i < s2.size(); ++i)...
#include <bits/stdc++.h> using namespace std; int dfs(long long int n, int i, long long int b[]) { int ans = i * (n / b[i]); n = n % b[i]; if (n == 0) return ans; else return (ans + min(i + dfs(b[i] - n, i - 1, b), dfs(n, i - 1, b))); } int main() { long long int a[17], i, n; ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; int modpow(int x, int y, int md) { if (y == 0) return 1; int ret = modpow(x, y >> 1, md); ret = (long long)ret * ret % md; if (y & 1) ret = (long long)ret * x % md; return ret; } int n, q, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; int st[maxn << 2]; int a[maxn], b[maxn]; vector<int> pos[maxn]; void build(int id, int l, int r) { if (l == r) { st[id] = a[l]; return; } int mid = (l + r) >> 1; build(id << 1, l, mid); build(id << 1 | 1,...
#include <bits/stdc++.h> using namespace std; int main() { long long int q; cin >> q; while (q--) { long long int n; cin >> n; long long int x, y; int l, u, r, s; long long int nl = -100000, nu = 100000, nr = 100000, ns = -100000; for (long long int i = 0; i < n; i++)...
#include <bits/stdc++.h> using namespace std; const long long A = 31, mod = 1000000033LL; vector<string> read(int n) { vector<string> ans(n); for (auto &x : ans) cin >> x; return ans; } vector<long long> hsh(vector<string> vec, long long a) { vector<long long> ans; for (auto x : vec) { ...
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, const string& delim = ) { vector<string> res; string t; for (int i = 0; i != s.size(); i++) { if (delim.find(s[i]) != string::npos) { if (!t.empty()) { res.push_back(t); t = ; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000 ) bool ascending(int i, int j) { return (i < j); } bool descending(int i, int j) { return (i > j); } using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; unsigned long long powmod(unsigned long long a, unsigned long long b, ...
#include <bits/stdc++.h> using namespace std; struct Node { long long val, pos; }; deque<long long> dq; bool flag = false; void go(long long a, long long b) { if (a > b) return; if (a == b) { cout << YES << endl; dq.push_back(b); cout << dq.size() << endl; flag = true; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) const long double EPSILON = 0.000000001; const long long int mod = 1000000007; const long long int AM = 2e5 + 5; const long double pi = 3.14159265358979323846; long long int max(long long int a, long long int b) { if (a > b) return a; else...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; struct zt { int ss, ii; } frm[1 << 22], ans[25]; struct node { int l, r, t, id; } a[25], b[25]; bool cmp1(node aa, node bb) { return aa.l < bb.l; } bool cmp2(node aa, node bb) { return aa.t < bb.t; } int N, P, S, f[1 << ...
#include <bits/stdc++.h> using namespace std; int b[1111][1111], n, m, k, q1, q2, xs, ys, step = 0, x, y, c; vector<char> v; char a[1111][1111]; queue<pair<int, int> > q; void add(int x, int y, int c) { if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] == * || b[x][y] <= c) return; b[x][y] =...
#include <bits/stdc++.h> using namespace std; long long a, b, in; long long shift(long long i) { return (1 << i); } void getx(long long x, long long y) { cout << ? << x << << y << endl; cin >> in; return; } int main() { ios_base::sync_with_stdio(false); long long curbit = 29; ...
#include <bits/stdc++.h> using namespace std; int n; char arr[1002][7]; bool sit = false; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %s , arr[i]); if (!sit) { if (arr[i][0] == O && arr[i][1] == O ) { sit = true; arr[i][0] = arr[i][1] =...
#include <bits/stdc++.h> using namespace std; long long n, m, x, y; int main() { cin >> x >> y >> m; if (x >= m || y >= m) { cout << 0 << endl; return 0; } if ((x <= 0 && y <= 0)) { cout << -1 << endl; return 0; } long long ans = 0; while (x < m && y < m) { ...
#include <bits/stdc++.h> using namespace std; const int md = 1000000007; const int maxn = 30303; const int maxk = 220; const int maxn4 = 4 * maxn; const long long inf = 2020202020202020202LL; int n, k, a[maxn]; int ans[maxn][maxk], ansp[maxn][maxk], ansm[maxn][maxk], t1, t2, t3, t4, t5, t6; int main()...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; const long long inf = 1e18; int f[maxn][32], rt; long long ans, a[maxn]; vector<int> G[maxn]; void dfs(int u, int p) { long long d = 0; f[u][0] = p; for (d = 1; d <= 20; d++) { if (f[u][d - 1] != -1) f[u][d] = f[f[u]...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 2e18; const int N = 1231234; int n, m; int a[N], b[N]; bool ok(long long x) { int i, j; for (i = 0, j = 0; i < m; ++i) { while (j < n && abs(b[i] - a[j]) <= x) j++; } return j == n; } ...
#include <bits/stdc++.h> using namespace std; int n, a[3][55], b[55]; int sum(int row, int f, int e) { int res = 0; for (int i = f; i <= e; ++i) res += a[row][i]; return res; } int main() { cin >> n; for (int x = 1; x <= 2; ++x) for (int i = 1; i < n; ++i) cin >> a[x][i]; for (in...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; int n, m; string s[100000]; int a[100000]; int b[100000]; string name; int id; vector<pair<int, string> > All; bool canMaxi(int k) { pair<int, string> He = make_pair(-a[id], name); He.first -= b[n - 1]; ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:20000000 ) using namespace std; template <typename T1, typename T2, typename T3> struct triple { T1 a; T2 b; T3 c; triple(){}; triple(T1 _a, T2 _b, T3 _c) : a(_a), b(_b), c(_c) {} }; template <typename T1, typename T2, typename T3>...
#include <bits/stdc++.h> const int inf = 2000000000; using namespace std; vector<vector<int> > g; vector<int> color; vector<bool> on_cycle; vector<int> parent; int n; bool isexit = false; void dfs(int v, int p = -1) { if (isexit) return; color[v] = 1; parent[v] = p; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; const int N = 3010; int n; int x[N], y[N], top; pair<int, pair<int, int> > st[N * N]; bitset<N> adj[N]; int sqr(int u) { return u * u; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d %d , &x[i], &y[i]); } for (i...
#include <bits/stdc++.h> using namespace std; int Set(int n, int pos) { return n = n | (1LL << pos); } int reset(int n, int pos) { return n = n & ~(1LL << pos); } bool check(int n, int pos) { return (bool)(n & (1LL << pos)); } int mul(int a, int b) { int c; c = (a % 1000000007 * b % 1000000007) % 1000...
#include <bits/stdc++.h> using namespace std; void maximize(int &a, int b) { a = max(a, b); } int absolut(int x) { if (x < 0) return -x; return x; } const int tope = 1 << 19; const int first = 1 << 18; struct elem { int ls, lH, lh, lb; int rs, rH, rh, rb; int sol; }; elem v[tope]; ...
#include <bits/stdc++.h> using namespace std; int n, k, plen; char p[200], ar[200]; char res[200]; int preone[200]; bool pos, found; bool is_start(int ind) { if (plen + ind > n) return false; for (int l = 0; l < plen; l++) if (p[l] != res[l + ind]) return false; return true; } bool b...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:10000000000 ) using namespace std; const int MOD = 1000000007; const int INF = 1000000007LL; const long long INF2 = 1000000007LL * 1000000007LL; const long double EPS = 1e-9; const int SIZE = 100100; mt19937 rng(time(0)); uniform_int_distributio...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long double pi = acos(-1); const int MOD = 1e9 + 7; const long long int LINF = 0x3f3f3f3f3f3f3f3f; int n, m, k, s; const int MAXN = 2005; int a[MAXN][MAXN]; int maxma[15], maxme[15], minma[15], minme[15]; int seq[MAXN * ...
#include <bits/stdc++.h> using namespace std; void make_uni(vector<int> &v) { sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); } int get(vector<int> &v, int d) { return lower_bound(v.begin(), v.end(), d) - v.begin(); } int getu(vector<int> &v, int d) { return upper...
#include <bits/stdc++.h> using namespace std; int prime(int n) { int val = sqrt(n), counter = 0; ; if (n == 1) return false; for (int i = 2; i <= val; i++) { if (!(n % i)) counter++; } if (counter) return -1; return n; } int root(int n) { int val = sqrt(n); int x = n, f...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int a1, a2, a3, b1, b2, b3, n, total = 0; cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> n; if ((a1 + a2 + a3) % 5 == 0) { total = total + (a1 + a2 + a3) / 5; ...
#include <bits/stdc++.h> using namespace std; const int R = 300005; const int inf = 2000000001; const int mod = 998244353; map<char, int> m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; string second; cin >> second; if (k == 1) ...
#include <bits/stdc++.h> long long int maxx(long long int a, long long int b) { return a > b ? a : b; } long long int minn(long long int a, long long int b) { return a > b ? b : a; } using namespace std; int dx[] = {1, 1, 1, 0, 0, -1, -1, -1, 0}; int dy[] = {-1, 0, 1, 1, -1, 0, 1, -1, 0}; void boostIO() { ...
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define N 300000 int min(int a, int b) { return a < b ? a : b; } unsigned int X; void srand_() { struct timeval tv; gettimeofday(&tv, NULL); X = tv.tv_sec ^ tv.tv_usec; if (X % 2 == 0) X++; } int rand_() { ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long long dp[1001][2001][4]; long long solve(long long n, long long k, long long i) { if (dp[n][k][i] != -1) { return dp[n][k][i]; } if (k < 1 || k > 2 * n) return 0; if (i == 0) { dp[n][k][i] = solve(n - ...
#include <bits/stdc++.h> using namespace std; const long long int maxn = 2005; long long int cnt[26]; long long int n, k; bool ok(long long int l, long long int k) { long long int k2 = k % l; if (k2 == 0) return 1; if (l % k2 != 0) return cnt[25] >= l; long long int need = l / k2; for (lon...
#include <bits/stdc++.h> using namespace std; const int oo = 1e9; const int MOD = 1000000007; const int N = 100010; vector<int> g[N]; multiset<int> seg[4 * N], stk; int n, u, v, sz[N], st[N], ed[N], bk[N], cnt = 1, res[N]; void dfs(int u, int p) { sz[u] = 1, bk[cnt] = u, st[u] = cnt++; for (int ...
#include <bits/stdc++.h> using namespace std; vector<int> myvec; long long int dp[100003]; int main() { int t1, t2, x, index1, index2, time, n; vector<int>::iterator it, it2; cin >> n; myvec.push_back(0); dp[0] = 0; for (int i = 0; i < n; i++) cin >> x, myvec.push_back(x); for (int i...
#include <bits/stdc++.h> using namespace std; mt19937_64 random_num( chrono::high_resolution_clock::now().time_since_epoch().count()); const int MOD = 1000000007; const int inf = 2000000000; const int mod = 1007050321; const double e = 0.000001; const int N = 200005; const bool aut = 788480; con...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } long lon...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; int ans[N]; int main() { int n, k; scanf( %d %d , &n, &k); if (k == 1 or k * 3 > n) return !printf( -1 n ); for (int x = 1; x <= k; x += 2) { for (int j = 0; j < 6; ++j) { if (j == 0 or j == 1 or j == 3) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3E4 + 5; const int maxm = 1E5 + 5; int n, m, cnt; int ans[maxn]; bool vis[maxn]; vector<int> to[maxn]; void DFS(int u, int fa) { vis[u] = 1; for (int i = 0; i < to[u].size(); ++i) { int v = to[u][i]; if (!vis[v]) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2016; vector<int> g[2][maxn]; vector<int> g2[2][maxn]; vector<int> gr[2][maxn]; int n; int neg(int first) { if (first < n) { return first + n; } else { return first - n; } } void add(int f, int first, int second) { ...
#include <bits/stdc++.h> using namespace std; bool h[1000009]; int main() { int n, m, k, tmp, tmp1, pos = 1; cin >> n >> m >> k; for (int i = 0; i < m; ++i) { cin >> tmp; h[tmp] = true; } if (h[1]) { cout << pos << endl; return 0; } for (int i = 0; i < k; ++i) {...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, d, i, j, k, n, m, t; cin >> t; while (t--) { cin >> n; long long int ar[n + 5]; memset(ar, -1, sizeof(ar)); int f = 0; for (i = 0; i < n; i++) { cin >> a; if (ar[a] == -1) ...
#include <bits/stdc++.h> using namespace std; vector<string> tmp; long long num(string str) { int len = str.size(); long long res = 0; for (int i = 0; i < len; i++) { res = res * 10 + str[i] - 0 ; } return res; } void solve(int N) { queue<string> q; q.push( 11 ); q.push(...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 50; int n, cnt; pair<int, int> poi[maxn], A[maxn]; void solve(int l, int r) { if (l > r) return; int mid = (l + r) >> 1; for (int i = l; i <= r; i++) poi[++cnt] = (pair<int, int>){A[mid].first, A[i].second}; solve(l, mi...
#include <bits/stdc++.h> using namespace std; const int maxn = 100100, INF = 0x7fffffff, _INF = 0x80000000; class Splay_Tree { public: int tot, root; struct Splay_Node { int c[2], fa, key, cnt, size; Splay_Node() { c[0] = c[1] = fa = key = cnt = size = 0; return; } ...
#include <bits/stdc++.h> using namespace std; template <class T> using vc = vector<T>; template <class T> using vvc = vc<vc<T>>; template <class T> void mkuni(vector<T>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } long long rand_int(long long l, long long r) ...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, t, b, c, m, n, ck = 0, ans = 0, sum = 0; cin >> t; cin.ignore(); while (t--) { ck = 0; cin >> a; cin.ignore(); string s; cin >> s; b = a - 10; for (int i = 0; i < b; i++) { i...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; if (n == 5 && x == 5) { printf( >...v nv.<.. n..^.. n>.... n..^.< n1 1 ); return 0; } if (n == 3 && x == 2) { printf( >vv n^<. n^.< n1 3 ); return 0; } for (int i = 0; i < 50; i++)...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); using ll = long long; template <typename T> void DEBUG(string label, T value) { cerr << [ << label << = << value << ] n ; } const int oo = 1 << 30; void solve() { int n; ...
#include <bits/stdc++.h> using namespace std; int dirx[] = {1, -1, 0, 0, 1, 1, -1, -1}, diry[] = {0, 0, 1, -1, 1, -1, 1, -1}; long long bigmod(long long x, long long p) { long long res = 1; while (p) { if (p & 1) res = (res * x) % 1000000007; x = (x * x) % 1000000007; p >>= 1; } ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; int n, k, sz, trie[MAX][26]; bool win[MAX], lose[MAX]; char s[MAX]; void dfs(int u) { int ady = 0; for (int i = 0; i < 26; i++) { if (trie[u][i] == 0) continue; ady++; int v = trie[u][i]; dfs(v); win...
#include <bits/stdc++.h> using namespace std; const int N = 100004; int v[N]; int main(void) { priority_queue<int> q; int x, n; cin >> n; int res = 0; set<pair<int, int> > S; for (int i = 0; i < n; ++i) { int x; cin >> x; S.insert(make_pair(x, i + 1)); } int k =...
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<int> ini[100005]; vector<int> mat[100005]; int maior[100005]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { int a; cin >...
#include <bits/stdc++.h> const int MAXN = 3e5 + 5; const int SQ = 600; int n, p, m, w[MAXN]; long long sum[MAXN], ans[MAXN]; std::vector<int> vec[SQ]; struct Ques { int a, b; } ques[MAXN]; void ss(int x) { int step = ques[x].b; if (step > m) { long long res = 0; for (int i = ques...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1e6, inf = 1e9, mod = 1000000007; vector<pair<int, int> > ad[N + 2], tree[N + 2]; int vis[N + 2], lev[N + 2]; void dfs(int node, int par, int lv) { vis[node] = 1, lev[node] = ...
#include <bits/stdc++.h> using namespace std; char aa[100100]; int a[550][550]; int main() { int x, y, x0, y0; cin >> x >> y >> x0 >> y0; for (int i = 1; i <= x; i++) for (int j = 1; j <= y; j++) a[i][i] = 0; a[x0][y0] = 1; int sum = 1; scanf( %s , aa); int len = strlen(aa); ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int l = s.length(); vector<char> s1; for (int i = 0; i < l; i++) { s1.push_back(s[i]); int f = 0; while (s[i] == / && i < l) { i++; f = 1; } if (f == 1) i--; } i...
#include <bits/stdc++.h> using namespace std; int n, m, k, x[100039], y[100039], z, now, cur, flag[100039]; long long d[100039], ans = 1e15; struct yyy { int to; long long w; int z; } tmps; struct ljb { int head, h[100039]; yyy f[600039]; inline void add(int x, int y, long long z) { ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c =...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; string a, b; signed main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> a; b += a; rev...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; long long n, m, a[200010], dp[200010][2]; vector<pair<long long, long long> > allseg, okseg; vector<long long> hvseg[200010]; void solve() { long long i, j, l, r, mn, dx, dy; scanf( %lld%lld , &n, &m); a[0] = -1000000000000; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 53; const int maxm = 23; int n, m; char s[maxn][maxm]; double dp[1 << 20]; long long f[1 << 20]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %s , s[i]); m = strlen(s[1]); memset(f, 0, sizeof(f)); for ...