func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const long long int N = 1e9 + 7; long long int h[200009], a[200009]; int main() { long long int n, m, i, b, j, c, d, x, y, z, k, sum = 0, l, r = 1; vector<long long int> v; vector<long long int>::iterator it; cin >> n; cout << (n / 2) + 1; }
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 77, LOG = 32; int T, n, a[N], tim = 1; int dp[N * LOG], is[N * LOG], le[N * LOG], ri[N * LOG]; inline void Add(int x) { int cur = 1; is[cur] = 1; for (int i = 29; i >= 0; --i) { if ((x >> i) & 1) { if (ri[cur] == 0)...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long int md[500]; signed main() { ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long int n; cin >> n; for (long long int i = 0; i < 500; i++) md[i] = -1; for (long long int i = 0; i <= 8; i++) { for (...
#include <bits/stdc++.h> using namespace std; const int N = 200005, M = N * 4; int n, q, a[N], t, l, r, k; struct sgt { long long p[M], s[M]; void B(int l, int r, int k, bool t) { if (l == r) { if (((l & 1) && !t) || (!(l & 1) && t)) p[k] = min(0, a[l] - a[l - 1]), s[k] = a[l] - ...
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> data; UnionFind(int sz) { data.assign(sz, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x;...
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; using namespace std; const int N = 1000100; bool isp[N]; void prep() { for (int(i) = (2); (i) < (N); ++(i)) isp[i] = true; for (int i = 2; i * i < N; i++) if (isp[i]) for (int j = i * i; j < N; j += i) isp[j] = false; } int a, b, k...
#include <bits/stdc++.h> using namespace std; namespace polynomials { int const p = 998244353, G = 3; int const N = (1 << 18) + 1; int w[N], iv[N], r[N], last; int mod(int x) { return x >= p ? x - p : x; } int pw(int x, int y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % p; ...
#include <bits/stdc++.h> using namespace std; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1}; const double eps = 1e-9; const int INF = 0x7FFFFFFF; const long long INFLL = 0x7FFFFFFFFFFFFFFFLL; const double pi = acos(-1); template <class T> T take(queue<T> &O...
#include <bits/stdc++.h> using namespace std; char a[500000 + 10]; int n, t; int mh; int h, s; int go(int mid) { int num = mid; int cnt = 0; int en = mh; int last; if (mid < h) { int u = 0; for (int i = 0; i < n; i++) { if (a[i] == S ) { u++; if (...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> adj[1001]; int vis[1001]; int main() { long long k, b, n, t, m = 1; cin >> k >> b >> n >> t; while (n >= 1 && k * m + b <= t) m = k * m + b, n--; cout << n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int dp[160][160]; int main() { int n; scanf( %d , &n); dp[1][1] = 1; dp[0][0] = 1; for (int i = 2; i <= n; i++) { for (int j = 0; j <= n; j++) { if (j == 0) dp[i][j] = dp[i - 2][j]; else dp[i][j] = (dp[i - ...
#include <bits/stdc++.h> namespace my_std { using namespace std; template <typename T> inline void read(T &t) { t = 0; char f = 0, ch = getchar(); double d = 0.1; while (ch > 9 || ch < 0 ) f |= (ch == - ), ch = getchar(); while (ch <= 9 && ch >= 0 ) t = t * 10 + ch - 48, ch = getchar(...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, temp; cin >> n; map<int, int> a, b; for (int i = 0; i < n; i++) { cin >> temp; a[temp]++; } for (int i = 0; i < n; i++) { cin >> temp; b[tem...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; char str[MAXN][MAXN]; bool used[MAXN][MAXN]; int n, m; int Move[][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}}; int pp[4]; void gao(int id, int dis[][MAXN]) { queue<pair<int, int> > q; for (int i = 0; i < n; i++) { for (int j ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<long long> mult(32, 1); for (int i = 0; i < 32; i++) mult[i] = (1 << i) + 1; int t; cin >> t; while (t--) { long long d, m, final = 1; cin >> d >>...
#include <bits/stdc++.h> using namespace std; int T[1000010][30], cnt = 0, fa[1000010]; char s[400010]; struct Q { int id, x; }; int A[400010], val[400010]; vector<Q> g[1000010]; vector<int> gg[1000010]; queue<int> q; void insert(int id) { int f = 0, i, v; for (i = 0; s[i]; i++) { ...
#include <bits/stdc++.h> using namespace std; int sum; int cV = 0; void add(string n, int c) { if (n.size() == 1) { cV = c; return; } sum = 0; for (char e : n) { int a = e - 0 ; sum += a; } c++; add(to_string(sum), c); } int main() { ios::sync_with_st...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& v) { os << ( << v.first << << v.second << ) ; return os; } template <typename T, typename U = typename T::value_type, typename = typename enable_if<!is_sa...
#include <bits/stdc++.h> using namespace std; int INF = 2147483647; int inf = -2147483648; const double PI = acos(-1.0); const double pi = 2 * asin(1.0); int vis[1000009]; int vi[1000009]; int main() { ios::sync_with_stdio(false); int a, b, c, d; cin >> a >> b >> c >> d; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; clock_t start; void Time(bool timeIt) { if (!timeIt) return; clock_t end = clock(); double elapsed_time = ((long double)end - (long double)start) / (long double)CLOCKS_PER_SEC; fprintf(stderr, Time elapsed = %0.4lf n , elapsed_time); } con...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) #pragma GCC target( avx,avx2 ) using namespace std; long long mod = 1e9 + 7; const long long inf = 1e9; int main() { cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0); in...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int main() { int n; scanf( %d , &n); long long sum = 0; for (int i = 0; i < n; i++) { int a; scanf( %d , &a); while (1) { if (mp[a] == 0 || a == 0) { mp[a] = 1; sum += (long long)a; ...
#include <bits/stdc++.h> using namespace std; int main() { int i, c, a, b; cin >> a >> b >> c; c -= 1; while (c) { c--; i = a + b; a = b; b = i; } cout << b << endl; }
#include <bits/stdc++.h> using namespace std; int n; int p[100010]; bool used[100010]; int main() { scanf( %d , &n); memset(p, 0, sizeof(p)); memset(used, false, sizeof(used)); if (n == 1) { printf( 1 n ); return 0; } if (n % 2 == 0) { if (n % 4 != 0) { printf...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v; for (int i = 1; i <= 20; ++i) { int first = ((1 << i) - 1) * (1 << (i - 1)); if (first > 1e5) break; v.push_back(first); } for (int i = v.size() - 1; i >= 0; --i) { if (n % v[i]...
#include <bits/stdc++.h> int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; using namespace std; long long power(long long a, long long p, long long M) { long long r = 1; a = a % M; while (p > 0) { if (p % 2) r = (r * a) % M; a = (a * a) % M; p /= 2; ...
#include <bits/stdc++.h> using namespace std; int n, a[51][51], ans[51]; bool check(int j, int x) { for (int i = 1; i <= n; i++) if (a[j][i] > x || a[i][j] > x) return false; ans[j] = x; return true; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) for (int j = 1; j...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.length() < 26) { cout << -1 << endl; return 0; } int j = -1; for (int i = 0; i < s.length(); i++) if (s[i] == a ) { j = i + 1; break; } if (j == -1) { cout ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; long long a[maxn], l[maxn], r[maxn], lans[maxn], rans[maxn]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); for (int i = 1; i <= n; i++) { l[i] = max(a[i], l[i - 1] + 1); l...
#include <bits/stdc++.h> using namespace std; const int N = 2005, INF = 2e9; int n, m, k, p[N][N], rnk[N][N], le[N][N], ri[N][N]; bool used[N][N], iswap; pair<int, pair<int, int> > ans; int dsu_get(int x, int y) { return p[x][y] == y ? y : p[x][y] = dsu_get(x, p[x][y]); } inline void dsu_unite(int x...
#include <bits/stdc++.h> using namespace std; const int P = 998244353; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(n), c(m, -1), d(m), bb(m); map<int, int> b; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int j = 0...
#include <bits/stdc++.h> using std::cin; using std::cout; using std::deque; using std::endl; using std::map; using std::max; using std::min; using std::multiset; using std::pair; using std::queue; using std::set; using std::sort; using std::stack; using std::string; using std::vector; in...
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, p, q, a; cin >> t; while (t--) { cin >> n >> p >> q; vector<long long int> player1, player2; for (unsigned long long i = 0; i < p; i++) { cin >> a; player1.push_back(a); } for (un...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; int N, M, Q; vector<int> V[100002], W[100002]; int X[100002], Y[100002], T[100002], weight[100002]; int A[100002]; bool S[100002]; int xglob, yglob; inline bool compare(const int& i1, const int& i2) { return atan2(Y[i1] - yglob...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int n; cin >> n; vector<long long int> a, d; for (long long int i = 0; i < n; i++) { long long int temp; cin >> temp; a.push_back(...
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; int ans = 0; while (n.size() > 1) { int k = 0; for (int i = 0; i < n.size(); i++) { k += n[i] - 48; } ans++; stringstream ss; ss << k; string str = ss.str(); n = str...
#include <bits/stdc++.h> using namespace std; int main() { int T, a, b, c, i, count = 0; cin >> T; for (i = 0; i < T; i++) { cin >> a >> b >> c; if ((a + b + c) >= 2) { count++; } } cout << count << n ; return 0; }
#include <bits/stdc++.h> namespace fft { using namespace std; const double PI = std::atan2(0, -1); using dbl = double; struct num { dbl x, y; num(dbl x_ = 0, dbl y_ = 0) : x(x_), y(y_) {} }; inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); } inline num operator-(num a, num ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct Node { int a[3], idx; bool operator<(const Node& ano) const { if (a[1] == ano.a[1]) { if (a[2] == ano.a[2]) return a[0] < ano.a[0]; return a[2] < ano.a[2]; } return a[1] < ano.a[1]; } } t[N...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:65777216 ) using namespace std; const int N = 2222; const int INF = 111111111; const double eps = 1e-9; const double pi = 3.14159265358979; char s[N], u[N]; int n, m, ans = INF; inline int check(int pos) { int res = 0; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; int main() { int k = 0; int ladder = 0; string slogan; cin >> k >> ladder; cin >> slogan; int h = k / 2; if (ladder != 1 && ladder != k) { if (ladder > h) { while (ladder != k) { cout << RIGHT << endl; ladd...
#include <bits/stdc++.h> using namespace std; const int md = 1000000007; void add(int &a, int b) { a += b; if (a >= md) a -= md; } int f[155][155][2][2], oldf[155][155][2][2], trueoldf[155][155][2][2]; int main() { int n, m; scanf( %d %d , &n, &m); memset(f, 0, sizeof(f)); for (int a...
#include <bits/stdc++.h> using namespace std; long long v[3], l, ans, minusVal; long long accSum(long long limit) { return (limit + 1LL) * (limit + 2LL) / 2LL; } long long invalidCase(long long a, long long b, long long c) { long long ret = 0LL; for (long long i = 0LL; i <= l; i++) { long lo...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; const long long MAXN = 100 * 1000 + 10; long long t; long long n, k; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> t; while (t--) { cin >> n >> k; cout << ...
#include <bits/stdc++.h> using namespace std; int fin(string s, int i1) { int mi = 999999999; for (int d = 1; d <= 9; d++) { for (int i = i1; i < i1 + 10; i++) { if (i + 2 * d < s.length()) { if (s[i] == s[i + d] && s[i] == s[i + 2 * d]) { mi = min(mi, i + 2 * d); ...
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 100; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } long long int modexp(long long int x, long long int n, long long int mod) { long long int result = 1; while (n > 0) { ...
#include <bits/stdc++.h> using namespace std; const long long INF = 9223372036854775807ll; const int inf = 2147483647, nmax = 1000006; struct thing { long long a, b, c, i; bool operator<(const thing &obj) const { return c < obj.c; } } e[nmax], e2[nmax], apm[nmax]; struct thing2 { long long a, b,...
#include <bits/stdc++.h> using namespace std; template <typename T> struct compF { bool operator()(const pair<T, T> &a, const pair<T, T> &b) { return a.first < b.first; } }; template <typename T> struct compS { bool operator()(const pair<T, T> &a, const pair<T, T> &b) { return a.seco...
#include <bits/stdc++.h> using namespace std; int isP(long int hj) { long int op; for (op = 2; op <= sqrt(hj); op++) { if (hj % op == 0) return 0; } return 1; } void swap(long long int *p, long long int *q) { long long int tmp = *p; *p = *q; *q = tmp; } void tog(int *p) { ...
#include <bits/stdc++.h> using namespace std; int q; long long int input; long long int lastSum[20]; long long int limit[20]; long long int targetSum(int digit, long long int target) { long long int ret = lastSum[digit - 1] * target; ret += target * (target + 1) * digit / 2; return ret; } lo...
#include <bits/stdc++.h> using namespace std; long long BigMod(long long B, long long P, long long M) { long long R = 1; while (P > 0) { if (P % 2 == 1) { R = (R * B) % M; } P /= 2; B = (B * B) % M; } return R; } template <class T1> void deb(T1 e1) { cout <<...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (a != 0 && b != 0) { if (a > b) a %= b; else b = b % a; } return a + b; } int main() { int k, l, m, n, d; cin >> k >> l >> m >> n >> d; int ans = 0; for (int i = (1); i < (d + 1); ...
#include <bits/stdc++.h> using namespace std; long long rdtsc() { long long tmp; asm( rdtsc : =A (tmp)); return tmp; } inline int myrand() { return abs((rand() << 15) ^ rand()); } inline int rnd(int x) { return myrand() % x; } const long long INF = (long long)1e16 + 1; const long double EPS ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; const int INF = INT_MAX; const double EXP = 0.0001; void files() { freopen( output.txt , w , stdout); } long long pow3(long long x) { return x * x * x; } pair<int, long long> answer; void solution(long long m, int step, long lo...
#include <bits/stdc++.h> using namespace std; void ret(string s) { cout << s; exit(0); } int main() { int n, m; cin >> n >> m; bool ok; string s[100]; int xn = 200, xm = 0, yn = 200, ym = 0; for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < s[i].length();...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 2, M = 1e9 + 7, OO = 0x3f3f3f3f; int n, m, u, v; int ic[N]; int fc[N]; int adj[N][N]; pair<int, int> p[N]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> ic[i]; for (int i = 0; i < m; i++) { cin >> u >> v...
#include <bits/stdc++.h> template <typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First& first, Rest&... rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } template <typename T> void MACRO_VEC_ROW_Init(int n, T& t) ...
#include <bits/stdc++.h> const int N = 1000005; using namespace std; int n, m, t = 0, tot = 0, cnt = 0, q[N]; int dl[N], dr[N], vis[N][27]; int edge[N], nxt[N], lst[N], pt[N], fail[N], val[N], nm[N], vvis[N]; string s; struct nn { int lx, rx, num; } tr[N << 2]; void add(int x, int y) { edge[++...
#pragma GCC optimize( Ofast,unroll-loops ) #pragma GCC target( avx,avx2,sse,sse2,ssse3,sse4,mmx,popcnt ) #include <bits/stdc++.h> #define ar array using namespace std; using ll = long long; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int mxN = 2e5, mxM = 60; int n...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-8; const int mod = 1000000007; const double pi = acos(-1.0); inline void gn(long long& x) { int sg = 1; char c; while (((c = getchar()) < 0 || c > 9 ) && c != - ) ; c == - ? (sg = -1, ...
#include <bits/stdc++.h> using namespace std; int main() { int h1, a1, c, h2, a2, h; cin >> h1 >> a1 >> c >> h2 >> a2; vector<string> v; h = h1; while (h2 > 0) { if ((a1 >= h2) || h1 > a2) { v.push_back( STRIKE ); h2 -= a1; } else { v.push_back( HEAL ); ...
#include <bits/stdc++.h> #pragma GCC optimize( -Ofast,unroll-loops ) #pragma GCC target( avx2 ) std::mt19937 rnd(237); using namespace std; const int N = 2e5, mod = 1e9 + 7; int n, m, type[N], cmp[N], cmp_p = 0; vector<array<int, 2>> g1[N], g2[N]; long long dfs(int v) { cmp[cmp_p++] = v; long lo...
#include <bits/stdc++.h> int check(int num1, int num2); using namespace std; int main() { int k, l, m, n, d; cin >> k; cin >> l; cin >> m; cin >> n; cin >> d; int total = 0; for (int i = 1; i < d + 1; i++) { if (check(i, k) || check(i, l) || check(i, m) || check(i, n)) { ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > con[3]; vector<pair<long long, long long> > sum; int main() { for (long long i = 0; i < ((long long)3); i++) { long long n; cin >> n; for (long long j = 0; j < ((long long)n); j++) { long long x, y; ...
#include <bits/stdc++.h> using namespace std; int n; char c[10005]; int main() { int i, a, b, l1, l2; a = b = l1 = l2 = 0; scanf( %d , &n); scanf( %s , &c[1]); for (i = 1; i <= n; i++) { if (c[i] == L ) a++; if (c[i] == R ) b++; } if (a == 0 && b == 0) l1 = l2 = 1...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5050; int n, b, c[MAXN], d[MAXN], fa[MAXN], sum[MAXN], f[MAXN][MAXN], g[MAXN][MAXN]; int buff[MAXN], bufg[MAXN]; int main() { memset(f, 63, sizeof(f)); memset(g, 63, sizeof(g)); scanf( %d%d , &n, &b); for (int i = 1; i <= n; i++) {...
#include <bits/stdc++.h> int main() { int n, q; std::cin >> n >> q; std::vector<std::pair<int, int>> a(q); std::vector<int> cnt(n), k1(q), pr(n, -1); std::vector<std::vector<int>> k2(q, std::vector<int>(q)); for (auto &i : a) { std::cin >> i.first >> i.second; --i.first; --i....
#include <bits/stdc++.h> using namespace std; int main() { long long x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4 >> x5 >> y5 >> x6 >> y6; long long a1 = (x2 - x1) * (y2 - y1); x3 = max(x3, x1); x4 = min(x4, x2); x5 = max(x5, x1); x6...
#include <bits/stdc++.h> using namespace std; bool cmp_x(const complex<double>& a, const complex<double>& b) { return abs(a.real() - b.real()) < 1e-6 ? a.imag() < b.imag() : a.real() < b.real(); } bool cmp_y(const complex<double>& a, const complex<double>& b) { ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 500 * 1000 + 10; int n, h[Maxn], ans; vector<int> adj[Maxn], vec; bool mark[Maxn]; void dfs(int v) { mark[v] = true; if ((int)adj[v].size() == 1) vec.push_back(h[v]); for (int i = 0; i < (int)adj[v].size(); i++) if (!mark[adj[v...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; void solve() { string p, h; cin >> p >> h; swap(p, h); so...
#include <bits/stdc++.h> using namespace std; enum { UP, DOWN, LEFT, RIGHT }; const int MaxN = 1005; const int MaxM = MaxN * MaxN; const int oo = 0x3F3F3F3F; char mp[MaxN][MaxN]; int dir[MaxM][4]; int d[MaxM][4]; int id[MaxN][MaxN], K; int R, C, s, t; struct Node { int u, dir, d; Node() {}...
#include <bits/stdc++.h> using namespace std; void PLAY() { cout << fixed << setprecision(10); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; deque<long long> x; map<lon...
#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 N; cin >> N; for (int i = 0; i < N; i++) cout << 1 ; cout << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, m, ans = 0; long long d[N], h[N]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n >> m; for (long long i = 1; i <= m; i++) cin >> d[i] >> h[i]; for (long long i = 2...
#include <bits/stdc++.h> using namespace std; int a[100005]; bool vis1[100005], vis2[100005]; vector<int> e1[100005], e2[100005]; queue<int> q1, q2; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= m; i++) { int x, y; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int m; cin >> m; int i; map<int, int> ipattern; for (i = 1; i <= n; i++) { int x; cin >> x; ipattern[i] = x; } int max = 0; for (i = 1; i <= n; i++) { if (ipattern[i] > max) { ...
#include <bits/stdc++.h> int height; std::vector<int> graph[1 + 127]; bool mark[1 + 127]; int answer; void setup(void) { scanf( %d , &height); for (int i = 1; i <= 127; i++) { graph[i].clear(); mark[i] = false; } answer = 0; } void ask(int v) { if (!graph[v].empty()) { ...
#include <bits/stdc++.h> using namespace std; int main() { int w, l; cin >> w >> l; int a[w]; long long sum[w]; sum[0] = 0; for (int i = 1; i < w; i++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } long long mn = 100000000000000005; for (int i = l; i < w; i++) { ...
#include <bits/stdc++.h> using namespace std; struct InputReader { char buf[1000001]; int p; inline InputReader() { p = 1000001; } inline void Flush() { p = 0; fread(buf, 1, 1000001, stdin); } inline char C() { if (p >= 1000001) Flush(); return buf[p++]; } inl...
#include <bits/stdc++.h> int main() { int g[6] = {0, 2, 3, 1, 2, 1}, i; while (scanf( %d , &i) == 1) { printf( %d n , g[i]); } return 0; }
#include <bits/stdc++.h> using int64 = long long; using uint64 = unsigned long long; using uchar = unsigned char; constexpr int maxn(200000); constexpr int maxm(200000); template <class _Tp> inline void swap(_Tp& x, _Tp& y) { _Tp z = x; x = y; y = z; } template <class _Tp> inline _Tp Min...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int INF = 0x3f3f3f3f; int arr[N]; int dq[N * 2]; int main() { int n; scanf( %d , &n); int dl = N, dr = N - 1; for (int i = 0; i < n; i++) { scanf( %d , &arr[i]); if (arr[i] == 1) { dr++; dq...
#include<iostream> using namespace std; void func(int i,int arr[],int ans[]){ if(arr[i]>=i+1){ return ; } if(arr[i]==0){ ans[i]=0; func(i-1,arr,ans); return; } else{ int currpos=i;int destionation=i-(arr[i]-1); while(currpos>=0){ if(currpos!=destionation){ if(ar...
#include <bits/stdc++.h> using namespace std; long long gcd(long long ar1, long long ar2) { return ar2 == 0 ? ar1 : gcd(ar2, ar1 % ar2); } long long add(long long ar1, long long ar2, long long m) { if (ar1 >= m) ar1 %= m; if (ar2 >= m) ar2 %= m; if (ar1 < 0) ar1 += m; if (ar2 < 0) ar2 += m; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, z; vector<int> x; bool check(int p) { for (int i = 0; i < p; i++) ...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; cin >> a >> b >> c; long long d; d = min(a, b) * 2 + c * 2; if (a != b) { d++; } cout << d; }
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, j, c; char chr; cin >> t; bool first_diag, second_diag; while (t--) { cin >> n; string arr[n]; vector<int> v; c = 0; for (i = 0; i < n; i++) cin >> arr[i]; first_diag = (arr[0][1] == arr[1...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, m, k; cin >> n >> m >> k; vector<vector<int> > edges(m, vector<int>(2)); vector<vector<int> > graph(n + 1); vector<int> degrees(n + 1, 0); for (int i = 0; i < m; ++i) { scanf( %d %d , &edges[i...
#include <bits/stdc++.h> using namespace std; long long n, m, a, b, res; int main() { cin >> n >> m; for (a = 0; a <= 1000; a++) { for (b = 0; b <= 1000; b++) { if (a * a + b == n && a + b * b == m) { res++; } } } cout << res; }
#include <bits/stdc++.h> using namespace std; const int M = 200009; int n, q, k, x, s; vector<pair<int, int> > p; vector<vector<int> > pb; set<int> last; void solve() { cin >> n; p.resize(n + 1); pb.resize(n + 1); for (int i = 0; i < n; i++) { cin >> x >> s; p[i] = {x, s}; ...
#include <bits/stdc++.h> using namespace std; vector<int> gr[300005]; int n, m; int col[300005]; void go(int now) { for (auto to : gr[now]) { if (col[to]) continue; col[to] = 3 - col[now]; go(to); } int cnt = 0; for (auto to : gr[now]) { cnt += (col[to] == col[now]); ...
#include <bits/stdc++.h> using namespace std; bool M[3000][6000]; int dr[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dc[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int parent[18000000]; int Find(int x) { if (parent[x] != x) parent[x] = Find(parent[x]); return parent[x]; } void Union(int x, int y) { x = Find(x...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000000 ) using namespace std; int n, vis[(1 << 21) + 1], col = 1, m, tw[22], cnt[(1 << 21) + 1]; long long dp[(1 << 21) + 1]; string st[55]; long long rep[(1 << 21) + 1]; int count_bit(long long x) { int ret = 0; while (x) { r...
#include <bits/stdc++.h> using namespace std; int a[20005][15]; int c[15], b[20005], ans[20005]; int main() { int n, m, k, i, j, x, y; cin >> n >> m >> k; for (i = 1; i <= n; ++i) { for (j = 1; j <= m; ++j) { scanf( %d , &a[i][j]); } } for (i = 1; i <= k; ++i) { cin...
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pli = pair<ll, int>; using pil = pair<int, ll>; using pll = pair<ll, ll>; template <typename T> using vec = vector<T>; using vi = vec<int...
#include <bits/stdc++.h> using namespace std; const int N = int(1e5 + 3); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; int size = s.length(); int count4 = 0; int count7 = 0; for (int i = 0; i < size; i++) { if (s[i] == ...
#include <bits/stdc++.h> using namespace std; int n, a[4], leaf; vector<int> son[5140]; void no() { puts( NO ); exit(0); } void init() { scanf( %d , &n); for (int i = 0; i < 4; i++) scanf( %d , &a[i]); for (int i = 2; i <= n; i++) { int pi; scanf( %d , &pi); son[pi].pus...
#include <bits/stdc++.h> using namespace std; vector<int> g[2000]; void DFS(int v, int n) { while (g[v].size() != 0) { int x = g[v].back(); g[v].pop_back(); for (int k = 0; k < g[x].size(); k++) if (g[x][k] == v) { g[x].erase(g[x].begin() + k); break; } ...
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int INF((1 << 30) - 1); const int MAXN(); int main() { int n; scanf( %d , &n); string a; cin >> a; int b[26]; for (int i = 0; i < 26; i++) b[i] = -1; vector<int> d; int cnt = 0; for (int i = 0; i...