func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; pair<int, int> V[2001010]; int cnt[2002]; long long cum[2002], N; string s; void make(int l, int r) { while (l >= 0 && r < (int)s.size()) { if (s[l] == s[r]) { V[N++] = (make_pair(l, r)); cnt[l]++; } else break; l--,...
#include <bits/stdc++.h> using namespace std; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; char E[1005][1005]; int N, M; struct Node { int step[3]; } s[1005][1005]; struct use { int x, y; }; void bfs(int x) { queue<use> que; use u, v; for (int i = 0; i < N; i++) { ...
#include <bits/stdc++.h> using namespace std; char a[200][200]; int lef[200], righ[200]; bool is[200]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, bot = 0; cin >> n >> m; for (int i = 0; i < n + 1; i++) { lef[i] = m - 1; righ[i] = 0; } f...
#include <bits/stdc++.h> using namespace std; template <class T> bool cmin(T &a_, T b_) { return a_ > b_ ? (a_ = b_, true) : false; } template <class T> bool cmax(T &a_, T b_) { return a_ < b_ ? (a_ = b_, true) : false; } template <class T> void OUT(T s_) { cout << s_ << n ; exit(0);...
#include <bits/stdc++.h> int main() { int n, i, j, k = 0, p; scanf( %d , &n); int a[n], b[n]; for (i = 0; i < n; i++) scanf( %d , &a[i]); for (i = n - 1; i >= 0; i--) { j = i + 1; p = 1; while (j <= n - 1) { if (a[i] == a[j]) { p = -1; break; }...
#include <bits/stdc++.h> using namespace std; int main() { long long int mod = 1000000007, c = 1, n, k; cin >> n >> k; for (int i = 1; i <= n - k; i++) c = (c * (n - k)) % mod; for (int i = 1; i <= k - 1; i++) c = (c * k) % mod; cout << c; }
#include <bits/stdc++.h> bool isVowel(char c) { return (c == a || c == e || c == i || c == o || c == u || c == A || c == E || c == I || c == O || c == U || c == y || c == Y ); }; int main() { char word[100]; scanf( %s , word); int i; int length; ...
#include <bits/stdc++.h> using namespace std; int n, t, k, cnt[100010], a[100010][4]; void work(int l, int r) { if (r - l + 1 == 3) { cnt[++k] = 3; a[k][1] = l, a[k][2] = l + 1, a[k][3] = l + 2; cnt[++k] = 3; a[k][1] = l, a[k][2] = l + 1, a[k][3] = l + 2; return; } if (r ...
#include <bits/stdc++.h> struct node { int v; node *next; } edge[400000 * 2 + 10], *adj[200000 + 10], *ecnt = &edge[0]; struct Edge { int u, v; Edge() {} Edge(int u, int v) : u(u), v(v) {} } e[400000 + 10], ans[400000 + 10]; int n, m, s, t, ds, dt, col[200000 + 10], cntcol, cnta, fa[200000...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; cin >> n; int a = (int)sqrt(n); if (a * a == n) { cout << a * 4 << endl; } else if (a * (a + 1) >= n) { cout << a * 4 + 2 << endl; } else { cout << a * 4 + 4 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; void solve() { string s; cin >> s; int cntr1 = 10, cntr2 = 10; int wt1 = 0, wt2 = 0; for (int i = 0; i < 10; i++) { if (i % 2 == 0) { if (s[i] == 1 || s[i] == ? ) wt1++; } else { if ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, maxn = 100001; typedef long long M[9][9]; const int p = 1e9 + 7, inv2 = 500000004; void Mul(M &A, M B) { M C; for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) { C[i][j] = 0; for (int k = 0; k < 9; k+...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, t = 0, min, d = 0; cin >> n >> m; int a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> a[i][j]; } vector<vector<int>> b(2, vector<int>(m, -1)); vector<vector<int>> c(n, vector<in...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, a, b; cin >> n >> a >> b; long long int c = 0; vector<long long int> v(n); for (long long int i = 0; i < n; i++) cin...
#include <bits/stdc++.h> using namespace std; const int oo = (int)2147483647; const double PI = 2 * acos(0.0); const long double eps = 1e-11; int diri[] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; int dirk[] = {1, 0, -1, 0, 1, -1, 1, -1, 0}; int main() { int n, m; double k; cin >> n >> m >> k; k += ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000500; typedef struct treap *ptreap; struct treap { int v, c, y; ptreap l, r; treap() {} treap(int v) : v(v), c(1), y(rand()), l(0), r(0) {} }; int cnt(ptreap t) { return t ? t->c : 0; } void recalc(ptreap t) { if (t) t->...
////#include <iostream> ////#include <cstdio> ////#include <cstring> ////#include <algorithm> //// ////#define LL long long //// ////LL gcd(LL a,LL b) { //// if(b == 0) return a; //// else return gcd(b,a % b); ////} //// ////inline LL calc(LL x) { //// LL ret = 0; //// while(x) {...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int n; int fn[200005] = {}; int a, b, c; vector<string> st(t); for (int j = 0; j < t; j++) { cin >> n; int rn[n]; for (int i = 0; i < n; i++) { cin >> rn[i]; fn[rn[i]] = i + 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n + 1]; for (int i = 0; i < n; i++) { int k; cin >> k; arr[k] = i + 1; } int m; long long int vas = 0, pet = 0; cin >> m; for (int i = 0; i < m; i++) { int k; cin >> ...
#pragma GCC optimize( Ofast , unroll-loops , no-stack-protector ) #include <bits/stdc++.h> using namespace std; #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() using ll = long long; using ld = long double; // using ld = __float128; using pii = pair<int, int>; using...
#include <bits/stdc++.h> using namespace std; int main() { int v; cin >> v; v == 1 || v == 2 ? cout << v : cout << 1; }
#include <bits/stdc++.h> using namespace std; int main() { long long t, j; cin >> t; for (j = 0; j < t; j++) { long long a, b, c, p = 0, r = 0; cin >> a >> b >> c; if (a >= c) p = -1; else p = 1; if ((c / b) >= a) r = -1; else r = b; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; long long f[N][2]; long long a[N]; long long n, r1, r2, r3, d; int main() { cin >> n >> r1 >> r2 >> r3 >> d; for (int i = 1; i <= n; i++) cin >> a[i]; memset(f, 0x3f, sizeof f); f[1][0] = r1 * a[1] + r3; f[1][1] = min(r...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; namespace io { template <class T> void re(complex<T>& x); template <class T1, class T2> void re(pair<T1, T2>& p); template <class T> void re(vector<T>& a); template <class T, size_t SZ> void re(array<T, S...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; multiset<int> gr[maxn]; vector<int> order, odd; int n, m; void go(int cur) { for (auto it = gr[cur].begin(); gr[cur].size() != 0; it = gr[cur].begin()) { int v = *it; gr[cur].erase(it); gr[v].erase(gr[v].find(cur));...
#include <iostream> #include <iomanip> #include <cstdio> #include <vector> #include <algorithm> #include <cmath> #include <cstring> #include <cassert> #include <string> #include <set> #include <map> #include <random> #include <bitset> #include <string> #include <unordered_set> #include <un...
#include <bits/stdc++.h> using namespace std; const int N = 5e6 + 50; vector<int> v; int vis[N] = {0}, n; int flag[N] = {0}, ans = 0; void dfs(int k) { if (vis[k]) return; vis[k] = 1; if (flag[k]) dfs(k ^ ((1 << n) - 1)); for (int i = 0; i < n; i++) if ((1 << i) & k) dfs(k ^ (1 << i));...
#include <bits/stdc++.h> using namespace std; int cnt[10]; int main() { int n; while (scanf( %d , &n) != EOF) { int sum = 0; memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < n; i++) { int j; scanf( %d , &j); cnt[j]++; sum += j; } int ans = -1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; struct node { int v, nxt; } edge[maxn << 1]; int first[maxn], tot = 0; void add(int u, int v) { edge[++tot].v = v; edge[tot].nxt = first[u]; first[u] = tot; } int n, m; double dp[maxn], p[maxn], ans = 0; int f[max...
#include <bits/stdc++.h> int main() { puts( INTERCAL ); return 0; }
#include <bits/stdc++.h> using namespace std; void Ask(int x1, int y1, int x2, int y2, bool rot = false) { if (!rot) { cout << ? << x1 << << y1 << << x2 << << y2 << endl; } else { cout << ? << y1 << << x1 << << y2 << << x2 << endl; } } int Find(int n, bool r...
#include <bits/stdc++.h> using namespace std; void solution() { int n, k, i, j, sum = 0; cin >> n >> k; string s; cin >> s; if (k == 2) { int c1 = 0, c2 = 0; for (i = 0; i < n; i++) { c1 += abs(s[i] - 65 - (i % 2)); c2 += abs(s[i] - 65 - (i + 1) % 2); } if...
#include <bits/stdc++.h> using namespace std; const long long N = 1100; const long long M = 260; const long long mod = 998244353; const long long MOD = 998244353; const long double eps = 0.000000001; const long long P = 1336; const long long inf = 1e16; mt19937 gen(chrono::high_resolution_clock::now()...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template <typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937 rng(chrono...
#include <bits/stdc++.h> using namespace std; vector<int> adj[200005]; int sz[200005]; int n, k; long long int ans; void dfs(int u, int p) { for (int v : adj[u]) { if (v == p) continue; dfs(v, u); sz[u] += sz[v]; ans += min(sz[v], 2 * k - sz[v]); } } int main() { ios_...
#include <bits/stdc++.h> using namespace std; int spf[5000002]; int f[5000002]; void init() { spf[0] = spf[1] = 1; for (int i = 2; i < 5000002; ++i) { if (spf[i] == 0) { spf[i] = i; long long int start = 1LL * i * i; for (long long int j = start; j < 5000002; j += i) { ...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; long long mas[1000100]; long long dmas[1000100]; int main() { ios::sync_with_stdio(0); int n; cin >> n; long long x; long long ans = -100000000000000000; int ansl, ansr; for (int i = 0; i < n; ++i) { cin >> x; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int _; for (cin >> _; _--;) { int n, q; cin >> n >> q; string a; cin >> a; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; const int INF = 2000 * 1000 * 1000; const double EPS = 1e-9; const double pi = acos(-1.0); const int maxn = 1010; const int maxsum = 10010; template <typename T> inline T sqr(T n) { return (n * n); } int n, a...
#include <bits/stdc++.h> const int mod = 1000000007; using namespace std; long long c[100005]; int v[100005]; set<int> s; int n, k; long long all, ans; int main() { scanf( %d %d , &n, &k); for (int i = 1; i <= n; i++) scanf( %I64d , &c[i]); for (int i = 0; i < k; i++) scanf( %d , &v[i]); ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 1; const int N = 200123; int z, n, s; deque<int> dq; int t[N]; int main() { ios_base::sync_with_stdio(0); int ans = 0; cin >> n >> s; for (int i = 0; i < n; i++) { cin >> t[i]; if (i + 1 == s) { ans += ...
#include <bits/stdc++.h> using namespace std; int main() { int n, s, idx; cin >> n >> s; s--; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } if (a[0] == 1) { for (int i = 0; i < n; i++) { if (i =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1]; int ans = 1; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { int m = 1; for (int j = i; j < n - 1 and a[j] >= a[j + 1]; j++) m++; for (int j = i; j > 0 and a[j] ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int s, n; cin >> s >> n; int temp = s, p = 1; while (temp > 0) { temp /= 10; p *= 10; } p /= 10; wh...
#include <bits/stdc++.h> const double PI = 3.141592653589793238463; using namespace std; inline long long add(long long a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; return a; } inline long long sub(long long a, long long b) { a -= b; if (a < 0) a += 1000000007; retur...
#include <bits/stdc++.h> using namespace std; int main() { int a[5][5], i, j, one[2], nr = 0, nc = 0; for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { cin >> a[i][j]; if (a[i][j] == 1) { one[0] = i; one[1] = j; } } } if (one[0] == 0 || one[0...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18 + 9; const long long mod = 1e9 + 7; const long long maxn = 2e5 + 8; char s[5][5], t[5][5]; long long n, m; void solve() { long long i, j; cin >> s[1] + 1 >> s[2] + 1 >> t[1] + 1 >> t[2] + 1; if (s[2][2] == X ) swap(s[2][...
#include <bits/stdc++.h> using namespace std; const int maxn = 150005; const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; const double pi = 3.14159265359; int n, t[maxn], ans, cnt; vector<int> v, vp; inline bool check(const vector<int> &vt) { for (const int &i : vt) { if (i == 0) { if (t[i] >= t...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, i, j, k, l = 0, s, x, y, z = 0, r = 1000000001, rr = 0; cin >> n >> s >> k; long long int a[k]; for (i = 0; i < k; i++) cin >> a[i]; sort(a, a + k); for (i = 0; ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename F> class SegTree { int n; T uni; F f; vector<T> dat; public: SegTree(int _n, F f, T uni) : f(f), uni(uni) { n = 1; while (n < _n) n *= 2; dat = vector<T>(2 * n, uni); } void set(int k, ...
#include <bits/stdc++.h> using namespace std; int n, w, s, a[110]; int in[110], out[110]; int main() { scanf( %d%d , &n, &w); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); s += a[i]; } if (n == 1 && w == a[0]) { puts( Yes ); for (int i = 0; i < w * 2; i++) { p...
#include <bits/stdc++.h> using namespace std; int main() { char ar[1002][1002]; int n, m, i, j, count, ar1[1002]; scanf( %d%d , &n, &m); for (i = 0; i < n; i++) { scanf( %s , ar[i]); } for (i = 0; i < m; i++) { ar1[i] = 1; } for (i = 1; i < n; i++) { for (j = 0; j <...
#include <bits/stdc++.h> template <class T> inline bool rd(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; while (c != - && (c < 0 || c > 9 )) c = getchar(); sgn = (c == - ) ? -1 : 1; ret = (c == - ) ? 0 : (c - 0 ); while (c = getchar(), c >= 0 && c <= 9 ) re...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int clean(vector<pair<int, int> > &I) { for (int i = 0; i < (int)I.size(); i++) { swap(I[i].first, I[i].second); I[i].second *= -1; } sort(begin(I), end(I)); for (int i = 0; i < (int)I.size(); i++) { I[i].s...
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6 + 50; #define int long long #define ll long long #define pb push_back #define mp make_pair #define debug(a) cout << #a << << a << n ; #define debug2(a , b) cout << #a << << a << || << #b << << b << n ; #define ye cou...
#include <bits/stdc++.h> using namespace std; const long long MX = 1e2 + 5; vector<long long> g[MX]; long long vis[2][MX], ways[2][MX], dist[2][MX]; void bfs(long long x, long long idx) { vis[idx][x] = 1; queue<long long> q; q.push(x); ways[idx][x] = 1; while (!q.empty()) { long long...
#include <bits/stdc++.h> using namespace std; int main() { long long x, y, z, t1, t2, t3; cin >> x >> y >> z >> t1 >> t2 >> t3; if (abs(x - y) * t2 + t3 * 3 + t2 * abs(z - x) <= abs(x - y) * t1) cout << YES ; else cout << No ; return 0; }
#include <bits/stdc++.h> using namespace std; int a[156], T, n, k, ans, lw, que[100]; int main() { int T; cin >> T; while (T--) { cin >> k; lw = 0; for (int i = 1; i <= 7; i++) { cin >> a[i]; a[i + 7] = a[i]; lw += a[i]; } int n = k / lw; if ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000; const double EPS = 1e-9; const double PI = 2 * acos(0.); const int N = 10; const int dx[] = {-2, -1, 1, 2, 2, 1, -1, -2}; const int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1}; char a[N][N]; bool r[N]; int main() { int ans...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC optimize( unroll-loops ) using namespace std; const int BLK = 320; const int MXN = 1e5 + 5; const int MOD = 998244353; int add(int x, int y) { return (x += y) < MOD ? x : x - MOD; } int sub(int x, int y) { return (x -=...
#include <bits/stdc++.h> using namespace std; const int SIGMA_SIZE = 26; const int MAXNODE = 1000010; struct AhoCorasickAutomata { int ch[MAXNODE][SIGMA_SIZE]; int f[MAXNODE]; int match[MAXNODE]; int mp[MAXNODE]; int sz; void init() { sz = 1; } int idx(char c) { if (c <= z &&...
#include <bits/stdc++.h> using namespace std; long long Gcd(long long a, long long b) { if (a % b == 0) return b; return Gcd(b, a % b); } long long Max(long long a, long long b) { if (a > b) return a; return b; } long long Min(long long a, long long b) { if (a < b) return a; return b...
#include <bits/stdc++.h> using namespace std; long long cdiv(long long x, long long y) { return x / y + (x % y > 0); } long long w(long long a, long long b) { return cdiv(a, 2) * cdiv(b, 2) + (a / 2) * (b / 2); } long long W(long long x1, long long y1, long long x2, long long y2) { return w(x2, y2) - ...
/* author : Piyush Singh */ #include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false), cin.tie(0) #undef _GLIBCXX_DEBUG using namespace std; int main(){ IOS; int tt; cin >> tt; while (tt--) { int a, b, k; cin >> a >> b >> k; vector<int> A(k); for (int i = 0; i<k; i...
#include <bits/stdc++.h> using namespace std; long long m; inline long long Nr(long long n) { long long cnt = 0, k, lim, put; for (k = 2; 1LL * k * k * k <= n; ++k) { put = 1LL * k * k * k; lim = n / put; if (1LL * lim * put > n) --lim; if (1LL * (lim + 1) * put <= n) ++lim; ...
#include <bits/stdc++.h> using namespace std; int N, K, M; int main() { scanf( %d%d , &N, &K); if (K <= 1) printf( -1 n ); else if (K >= 2 * N) printf( 1 n ); else if (K > N) printf( 3 n ); else if (N == K) printf( 5 n ); else if (K == 2) { if (N == 3) ...
#include <bits/stdc++.h> using namespace std; int main() { int x, y; int cnt = 0; cin >> x >> y; if (x != y) cout << min(x, y) << ; else cout << x << ; if (x > y) { x = x - y; for (int i = 2; i <= x; i += 2) { cnt++; } cout << cnt; } else...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, ans, final = 0, play = 0, study = 0, big, small, i, j; cin >> n >> m; int a[n + 1]; for (i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == 1) { study++; } else { play++; } } for (i = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int amin = 10, bmin = 10; char mat[8][8]; map<int, int> mapping; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { cin >> mat[i][j]; } getchar(); } for (int i = 0; i < 8; i++) { for (int j = ...
#include <bits/stdc++.h> using namespace std; int dp[1 << 20], w[25][25]; string s[25]; pair<int, int> alph[25][26]; int ma[25][26]; int cost[1 << 20]; vector<pair<int, int> > rco; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; if (b) b = (b / abs(b)) * (abs(b) % n); if (!b) { cout << a; return 0; } if (b > 0) { int i, cnt = 0; for (i = a; cnt != b; (i != n) ? (i++) : i = 1) { cnt++; } ...
#include <bits/stdc++.h> using namespace std; int ret[1001]; int main() { int N; scanf( %d n , &N); char s[1000]; scanf( %s , s); fill(ret, ret + N, 1); for (int i = 0; i < N; i++) { int t = 1; for (int j = i; j < N; j++) if (s[j] == R ) break; else i...
#include <bits/stdc++.h> using namespace std; int main() { { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }; long long t; cin >> t; while (t--) { long long a, b, n, s; cin >> a >> b >> n >> s; bool ans = false; long long f = s / n; ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int sign = 1, tmp = 0, ans = 0; for (int i = 0; i < s.size(); i++) { if (!(s[i] >= 0 && s[i] <= 9 )) { ans += tmp * sign; if (s[i] == - ) sign = -1; else sign = 1; ...
#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; bitset<4096> bs[100050]; pair<int, int> carac[100005][15]; int c[15][100005]; int n, k, q; int type[100050]; int a[1000...
#include <bits/stdc++.h> using namespace std; const int N = 203; const int MOD = 1e9 + 7; int n, ssz; string s; int len[N][2]; int dp[N][N][N][2]; int calc(const string &t) { int tsz = t.size(); for (int i = tsz; i > 0; --i) { if (s.substr(0, i) == t.substr(tsz - i, i)) return i; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)2e5 + 7; const int mod = 998244353; int n, m, l; int a[maxn << 2], b[maxn << 2], rev[maxn << 2]; int num[maxn << 2]; const int pr = 3; const int phi = mod - 1; int qpow(int x, int y) { int t = 1; while (y) { if (y & 1) t...
#include <bits/stdc++.h> int b[100005], a[100005], n, x, A, k; int main() { while (~scanf( %d %d , &n, &k)) { memset(b, 0, sizeof(b)); scanf( %d , &a[1]); x = 2; for (int i = 2; i <= n; i++) { scanf( %d , &A); if (A != a[x - 1]) a[x++] = A; } for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; const long long INF = (1e9) + 7; const long long C = (1 << (17)); vector<vector<long long> > up, sum; vector<long long> cost, maxw, d; long long LOG = 20; void push(long long v, long long x) { cost.push_back(x); maxw.push_back(x); d.push_back(0); ...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX / 2; int main() { int n, k, q; scanf( %d%d%d , &n, &k, &q); vector<int> vec(n); for (int i = 0; i < n; i++) { scanf( %d , &vec[i]); } set<pair<int, int> > st; map<int, int> mp; for (int i = 0; i < q; i++) {...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, ans = 1e9 + 1; string s; cin >> n >> s; vector<double> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; } for (int i = 0; i < n; i++) { if (i < n + 1 && s[i] == R && s[i + 1] == L && (x[i + 1]...
#include <bits/stdc++.h> using namespace std; const int MAX = 100009; int n, m, k, a[MAX], b[MAX], pos[MAX]; int main() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; pos[a[i]] = i; } long long ans = 0; for (int i = 1; i <= m; i++) { cin >> b[i]; in...
#include <bits/stdc++.h> using namespace std; int a[200001]; bool b[200001]; int main() { string s1, s2; int n, i; cin >> s1 >> s2; n = s1.size(); for (i = 1; i <= n; i++) cin >> a[i]; int l, r, mid, pr = 0, j; l = 0; r = n; while (l != r) { mid = (l + r + 1) / 2; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; k++; vector<int> v; for (int i = 0, x; i < n; i++) { cin >> x; v.push_back(x); } int lo = 1; int hi = 1000000000; while...
#include <bits/stdc++.h> using namespace std; const int maxn = 12; unsigned long long ans; unsigned long long n; unsigned long long data[maxn]; void init() { scanf( %I64d , &n); memset(data, 0, sizeof(data)); ans = 0; } void solve() { for (int i = 1; i <= n; ++i) { ++data[i % 9]; ...
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long x[1000005], r, cur[1000005]; long long len; bool check(long long cnt) { long long res = 0, s = 0; for (int i = (1); i < (n + 1); i++) cur[i] = 0; for (int i = (1); i < (r + 1); i++) s += x[i]; for (int i = 1; i <= n; i+...
#include <bits/stdc++.h> using namespace std; const int M = 6 * 1e5; const long long Q = 1e9 + 7; int ans; int a[10]; bool used[10]; void dfs(int i) { used[i] = true; if (!used[a[i]]) dfs(a[i]); } void gen(int i, int n) { if (i == n + 1) { bool ok = true; for (int j = 1; j <= n...
#include <bits/stdc++.h> int ans = 2, n, t; double m; struct T { int x, t; } a[1111]; bool my(T a, T b) { return (a.x < b.x); } int main() { scanf( %d%d , &n, &t); for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].x, &a[i].t); std::sort(a + 1, a + n + 1, &my); for (int i = 2; i <= n; i++)...
#include bits/stdc++.h using int64 = long long; const int N = 305; const int Q = 998244353; inline void add(int &x, int y) { x += y; if (x >= Q) x -= Q; } int n, dep[N]; std::vector<int> e[N]; int f[N][N]; // x , y : max uncovered depth int g[N][N]; // x , y : max extended leng...
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; const long long o5 = 716327852; const int N = 2e5 + 34; long long f[N], o[N]; long long ans, n, w, h; long long dp[N]; pair<long long, long long> a[N]; long long c(long long h, long long w) { return (((f[h + w] * o[h]) % m...
#include <bits/stdc++.h> using namespace std; const int N = 1005; int k; long long pa, pb; long long A, B, C; long long f[N][N]; void exgcd(int a, int b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return; } exgcd(b, a % b, y, x); y -= a / b * x; } long long i...
#include <bits/stdc++.h> using namespace std; vector<int> adj[202]; int height[202], best[202][3]; int N; int getHeight(int ind, int parent) { if (height[ind] != -1) return height[ind]; int ret = 1; for (int i = 0; i < (int)adj[ind].size(); i++) { if (adj[ind][i] == parent) continue; r...
#include <bits/stdc++.h> using namespace std; long long n, ans[100001], curr, deg[100001] = {0}; vector<pair<int, int>> adj[100001]; void dfs(long long u, long long p) { for (auto v : adj[u]) { if (v.first == p) { continue; } if (ans[v.second] == -1) { ans[v.second] = curr+...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; void merge(int l, int r, int lev) { if (lev == 0) { ans.push_back({l, r}); return; } int mid = (l + r) >> 1; merge(l, mid, lev - 1); merge(mid + 1, r, lev - 1); int j = mid + 1; for (int i = l; i <= ...
#include <bits/stdc++.h> using namespace std; const int MaxK = 53, MaxN = 2000005; int N, K; char A[MaxN]; char B[MaxN]; int id(char c) { return ( a <= c && c <= z ) ? c - a : c - A + 26; } namespace KuhnMunkres { const int MAX_N = 505; const int INF = 100000000; const int BASE = 1000; int n...
#include <bits/stdc++.h> using namespace std; int x[500500], y[500500]; long long minl[500500], maxl[500500], minr[500500], maxr[500500], ll, rr; int n; pair<long long, long long> a[500500]; bool ok(long long M) { int j = 0; for (int i = 0; i < n; i++) { while ((j < n) && (a[j].first - a[i].fi...
#include <bits/stdc++.h> const int maxi = 2000000000; const int maxq = 1000000000; const double eps = 1e-10; const double pi = 3.1415926535897932; const double inf = 1e+18; const int mo = 1000000007; using namespace std; int stn, ms[1111][1111], n, k, t, st[1111111], x, y, z, sum; bool f[11111]; voi...
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > dp; const long long mod = 1e9 + 7; bool used[1005][1005]; int n; long long dfs(int opening, int closing) { if (dp[opening][closing] != -1) return dp[opening][closing]; if (opening > n or closing >= n) return 0; long long an...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) v[i] = i + 2; int n_colors = 1; vector<bool> prime(n, true); vector<int> colors(n); for (int i = 0; v[i] <= sqrt(n + 1); ++i) { if (prime[i]) { for ...