func_code_string
stringlengths
59
71.4k
#include<bits/stdc++.h> using namespace std; int main() { int t,n,k=0,c; cin >> t; while(t--) { cin >> n; c=1; for(int i=2; i<=n; i++) { cout << i << ; } cout << 1; cout << endl; } }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { int n; cin >> n; int maxn = 0; int x, y; while (n--) { scanf( %d %d , &x, &y); maxn = max(maxn, x + y); } cout << maxn << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int t, n, w; string s; cin >> t; while (t--) { cin >> n >> s; bool flag = 0; if (n % 2) { for (int i = 0; i < n; i += 2) { if ((s[i] - 0 ) % 2) { flag = 1; break; } ...
#include <bits/stdc++.h> using namespace std; int a[1111], x, n, s, y, o, oo; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x == 0 || x == 100) a[s++] = x; else if (x < 10 && o == 0) a[s++] = x, o = 1; else if (x % 10 == 0 && oo == 0) a[...
#include <bits/stdc++.h> double dist(long long x, long long y) { return sqrt(x * x + y * y); } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int test; std::cin >> test; double inf = 1000.0 * 1000.0 * 1000.0; while (test--) { long long w, h; std::cin >...
#include <bits/stdc++.h> using namespace std; mt19937_64 rnd(time(0)); ifstream in; ofstream out; const long long INF = LLONG_MAX; const long double EPS = 1e-9; const long double pi = 3.141592653589793238462643383279502884; long long n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; int c[2][501][501]; int main() { int n, m, b, mod; scanf( %d%d%d%d , &n, &m, &b, &mod); int a[n + 1]; for (long i = 1; i <= n; i++) scanf( %d , &a[i]); memset(c, 0, sizeof(c)); c[0][0][0] = 1; for (long i = 1; i <= n; i++) for (long j...
#include <bits/stdc++.h> using namespace std; void solve() { long long int N; cin >> N; long long int A[N]; for (long long int i = 0; i < N; i++) cin >> A[i]; map<long long int, long long int> M; for (long long int i = 0; i < N; i++) { if (A[i] != 0) M[A[i]]++; } cout << M.size...
#include <bits/stdc++.h> using namespace std; int main() { int n, arr[10000], x[5], z1[10000], z2[10000], z3[10000], a = 0, b = 0, c = 0; x[0] = {0}, x[1] = {0}, x[2] = {0}; cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 1; i <= n; i++) { if (arr[i] == 1) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; struct pos { double x, y; } p[maxn]; int n; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %lf%lf , &p[i].x, &p[i].y); double ans = 0x3f3f3f3f; for (int i = 0; i < n; i++) { pos a = p[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, i, j, k, x, MOD = 1000000007, ans, a1, a2, b1, b2, a, b; string s1, s2; cin >> n >> s1 >> s2; vector<vector<long long>> dp(n + 1, vector<long long>(4, 0)); dp[0][0] = 1; f...
#include <bits/stdc++.h> using namespace std; int n, m, k; char a[55][55]; int u[55][55][4][2]; int d[] = {0, 1, 1, 0, 0, -1, -1, 0}, dp, cp = -1; int ls[50010000]; int lsk; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %s , a[i] + 1); m = strlen(a[1] + 1); for ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; int dx[] = {0, 0, +1, -1}; int dy[] = {+1, -1, 0, 0}; template <typename first, typename second> ostream &operator<<(ostream &os, ...
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, i, j, ii, jj, zx, xc, qw[200009], we[200009], pas, pi, k[200009]; pair<pair<long long, long long>, long long> p[600009]; bool bo[200009], rko[200009]; vector<long long> v[200009]; deque<long long> de; void dfsst(long long q, long...
#include <bits/stdc++.h> using namespace std; bool mysort(const pair<double, int> &a, const pair<double, int> &b) { if (a.first == b.first) return a.second < b.second; else return a.first > b.first; } int main() { int n, t1, t2, k, a, b, i; double h1, h2; vector<pair<double, int>...
#include <bits/stdc++.h> using namespace std; int c[1000001]; int b[1000001]; int main() { int n, i, l, r, m, kq = 1, a; scanf( %d , &n); for (i = 1; i <= n; i++) { cin >> a; c[a] = i; b[i] = 0; } cin >> a; b[1] = c[a]; for (i = 2; i <= n; i++) { cin >> a; ...
#include <bits/stdc++.h> int a[201][3]; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<string> a; for (int i = 0; i < n; i++) { string r; cin >> r; a.push_back(r); } int count = 0, ans = 0; fo...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, i = 1; cin >> n >> k; while (~k & 1) k >>= 1, i++; cout << i; return 0; }
#include <bits/stdc++.h> using namespace std; struct edge { int to, cost; }; vector<edge> G[500005]; int q, n, k; long long f[500005], g[500005]; vector<long long> weights[500005]; void add_edge(int u, int v, int cost) { G[u].push_back((edge){v, cost}); G[v].push_back((edge){u, cost}); } ...
#include <bits/stdc++.h> using namespace std; mt19937 ran(time(0)); long long mod = 1e9 + 7; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long Bpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) { ans *= a; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 23, D = 1000 * 1000 * 1000 + 7, MXLN = 17 + 3; int mul() { return 1; } template <typename... T> int mul(int x, T... a) { return 1ll * x * mul(a...) % D; } int add() { return 0; } template <typename... T> int add(int x, T.....
#include <bits/stdc++.h> using namespace std; int z[201010]; int cost[201010], acc[201010]; string s, aux, text, text2, patt; pair<int, int> dp[201010]; void build() { text = aux; text2 = aux; int n = (int)aux.size(); for (int i = 0; i < n; i++) { cost[i] = -1; acc[i] = 0; ...
#include <bits/stdc++.h> using namespace std; const int mxn = 5005; int dp[mxn][mxn], ans, n, a[mxn]; int md7[8], pos[114514]; inline void ckmax(int& x, int y) { if (x < y) x = y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n...
#include <bits/stdc++.h> using namespace std; long long value(const vector<long long>& a, long long b) { long long result = 0; for (int i = 0; i < a.size(); ++i) { result += min(b, a[i]); } return result; } int main() { long long n, k; cin >> n >> k; vector<long long> a(n); ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 2e2 + 10; vector<string> v[N]; int nex[N]; int flag[N]; int main() { int n; cin >> n; map<char, int> mc; memset((nex), (-1), sizeof(nex)); while (n--) { string str; cin >> str; ...
#include <bits/stdc++.h> using namespace std; template <class T> using v2d = vector<vector<T> >; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } mt19937 rng(chrono::system_clock:...
// Author : Epsilon573 // If it works, don t touch it. #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; const ll mod = 1e9+7; const ld eps = 1e-9 ; const ll maxn = 1e5+1; const ll inf = 1e15 ; const ll minf = -i...
#include <bits/stdc++.h> using namespace std; int n, a[1234567], ans[1234567]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int in = 0; for (int i = 0; i < n; i++) if (!a[i]) { in = i; break; } for (int i = 0; i <= in; i++) ans[i] = in - i; fo...
#include <bits/stdc++.h> using namespace std; int n, k, s = 0, a; int sg(int x) { if (x == 0 || x == 1) return x; if (k % 2 == 0) { if (x == 2) return 2; if (x % 2 == 0) return 1; else return 0; } else { if (x == 2) return 0; if (x == 3) return 1; if...
#include <bits/stdc++.h> using namespace std; const int mn = 2e5 + 10; int bit[mn]; void update(int a, int b) { for (; a < mn; a += a & -a) bit[a] += b; } int query(int a) { int b = 0; for (; a; a -= a & -a) b += bit[a]; return b; } int a[mn], v[mn], n; void go() { int i; for (...
#include <bits/stdc++.h> using namespace std; void reverseQueue(queue<long long int>& q) { if (q.empty()) return; long long int data = q.front(); q.pop(); reverseQueue(q); q.push(data); } int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; vector<long long int...
#include <bits/stdc++.h> int main(void) { int n, m; char g[1000][1000]; int min_row = 1000, max_row = -1; int min_col = 1000, max_col = -1; scanf( %d %d , &n, &m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf( %c , &g[i][j]); if (g[i][j] == B ) { ...
#include <bits/stdc++.h> using namespace std; struct qq { char c; long long dis; } a[500050], b[500050], c[500050], d[500050], e[500050], f[500050], g[500050], h[500050]; int cmp(qq a, qq b) { return a.dis < b.dis; } int main() { int n; cin >> n; int x, y; cin >> x >> y; int ...
#include <bits/stdc++.h> using namespace std; bool ok[100010]; int a[100010]; int b[100010]; int c[100010]; vector<int> ans; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) scanf( %d , &b[i]); memset(ok, false, sizeof(o...
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long k; cin >> k; map<char, long long> m; for (long long g = 0; g < k; g++) { long long n; cin >> n; string s, t; cin >> s >> t; m.c...
#include <bits/stdc++.h> using namespace std; using namespace std; const int N = 1e6 + 100; const int inf = 1e9 + 100; int n, w, m, a[N], seg[N << 2]; long long fen[N]; void change(int dex, int val, int v = 1, int s = 0, int e = N) { if (dex < s || e <= dex) { return; } if (e - s == 1) {...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int n; long long int d[MAXN], st[2 * MAXN]; long long int arr(int i) { if (i == 0 || i == n - 1) return 0; return max(0ll, -d[i - 1]) + max(0ll, d[i]); } void build() { for (int i = 0; i < n; ++i) st[i + n] = arr(i); fo...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << { << p.first << , << p.second << } ; return os; } co...
#include <bits/stdc++.h> int main() { int a; scanf( %d , &a); int A[a]; for (int i = 0; i < a; ++i) { scanf( %d , &A[i]); } for (int i = 0; i < a; ++i) { int l, m; int K = 0; l = (int)(sqrtl(A[i])); m = (int)(cbrtl(A[i])); int z = 0; z = (int)cbrtl(sqr...
#include <bits/stdc++.h> int N; int T[20000 + 10]; int Cnt[20000 + 10]; int Ans; int main() { scanf( %d , &N); for (int i = 0; i < N; i++) scanf( %d , &T[i]); Ans = -1000000000; for (int i = 1; i <= N; i++) if (N % i == 0 && N / i >= 3) { for (int j = 0; j < i; j++) Cnt[j] = 0; ...
#include <bits/stdc++.h> using namespace std; int i[105] = {0}; int j[105] = {0}; int f[100005] = {0}; int main() { int n, m; cin >> n; for (int a = 1; a <= n; a++) cin >> i[a]; cin >> m; for (int a = 1; a <= m; a++) cin >> j[a]; for (int a = 1; a <= m; a++) { for (int b = 1; b <...
#include <bits/stdc++.h> using namespace std; const int N = 205; char g[N]; map<char, int> h; void work() { int i, j; int s1 = 0, s2 = 0; h[ q ] = 9; h[ r ] = 5; h[ b ] = 3; h[ n ] = 3; h[ p ] = 1; h[ k ] = 0; for (i = 0; i < 8; ++i) { scanf( %s , g); for (j = 0...
#include <bits/stdc++.h> using namespace std; struct segment { int pos; int len; int type; }; struct lengthComparator { bool operator()(const segment &a, const segment &b) const { if (a.len != b.len) return a.len > b.len; else return a.pos < b.pos; } }; struct...
#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}; long long ax, ay, bx, by, cx, cy; long long dist(long long x1, long long y1, long long x2, long long y2) { return ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)); }...
#include <bits/stdc++.h> using namespace std; const int N = 5e2 + 7; int c[N], n; int f[N][N]; int main() { memset(f, 0x7f7f, sizeof f); scanf( %d , &n); for (register int i = 1; i <= n; ++i) { scanf( %d , &c[i]); f[i][i] = 1; } for (register int i = 1; i < n; ++i) { if (...
#include <bits/stdc++.h> using namespace std; string s, ans; int p; int main() { cin >> s; while (p < s.length()) { if (s[p] == . ) ans.push_back( 0 ), ++p; else if (s[p + 1] == . ) ans.push_back( 1 ), p += 2; else ans.push_back( 2 ), p += 2; } cout <<...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int a[N]; int main() { int T; scanf( %d , &T); while (T--) { int n; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); } sort(a + 1, a + n + 1); int ans = a[1]; for...
#include <bits/stdc++.h> using namespace std; int main() { string s[100]; int i, j, count = 0, num = 0; cin >> s[0]; for (i = 0; i < s[0].length(); i++) { s[i + 1] = s[i]; num = 0; rotate(s[i + 1].rbegin(), s[i + 1].rbegin() + 1, s[i + 1].rend()); } for (i = 0; i < s[0].len...
#include <bits/stdc++.h> using namespace std; int d[10010][8]; int d1[8]; int p[3][10010]; int n; vector<int> var; int MD = 1000000007; int mod(long long a) { if (a % MD < 0) return a % MD + MD; else return a % MD; } void put(int i, int prof) { if (prof == 0) { d[i + 1]...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); queue<int> x, y; for (int i = 0; i < n; ++i) { int tmp; scanf( %d , &tmp); x.push(tmp); } for (int i = 0; i < m; ++i) { int tmp; scanf( %d , &tmp); y.push(tmp); ...
#include <bits/stdc++.h> void err() { std::cout << std::endl; } template <typename T, typename... Args> void err(T a, Args... args) { std::cout << a << ; err(args...); } using namespace std; const int mod = 1e9 + 7; const int maxn = 1e3 + 22; int n, m, d[maxn], vis[maxn], root0, g[maxn]; in...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; char str[maxn]; int pre[30], now[30]; int l, r, len, cnt; void sov() { scanf( %s , str); len = strlen(str); cnt = 1; l = 0, r = 0; memset(now, 0, sizeof(now)); int i = 1; while (i < len) { if (str[i] =...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, x, res = 0; cin >> n; int t[n + 1]; fill(t, t + (n + 1), 0); for (int i = 1; i <= n; i++) { cin >> x; t[x] = t[x - 1] + 1; res = max(res, t[x]); } cou...
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = RDLU ; long long ln, lk, lm; int r, c; vector<int> v[3105]; multiset<int> ms; int pos[30]; void fmain() { scanf( %d%d%d%d , &r, &c, &n, &k); for (int...
#include <bits/stdc++.h> using namespace std; int main() { int T, a, b, c; cin >> T; for (int t = 0; t < T; t++) { cin >> a >> b >> c; cout << (min(c / 2, b) * 3) + min(a, (b - min(c / 2, b)) / 2) * 3 << n ; } }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; while (a > 0) { if (2 * a <= b && 4 * a <= c) { cout << 7 * a; return 0; } else { a--; } } cout << 0 ; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 505; const int nmax = 1e3 + 5; const long long inf = 1e9; const int mod = 1e9 + 7; const long long P = 31; const int K = 20; const long double eps = 1e-9; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return true; } return false; } constexp...
#include <bits/stdc++.h> int main(void) { int a, b, x, y; scanf( %d %d , &a, &b); x = (a > b) ? a : b; y = (a < b) ? a : b; printf( %d %d n , y, ((x - y) / 2)); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ull = uint64_t; using ld = long double; using uint = uint32_t; const double EPS = 1e-8; const int INF = 0x3F3F3F3F; const ll LINF = 4611686018427387903; const int MOD = 1e9 + 7; signed main() { ios::sync_with_stdio(0); c...
#include <bits/stdc++.h> const long long MOD = 1000000007; using namespace std; long long ans[2005][2005]; int main() { long long i, j, k; long long A[2005], N, H; cin >> N >> H; for (i = 0; i < N; i++) { cin >> A[i]; } if (A[0] == H - 1) { ans[0][0] = 1; ans[0][1] = 1;...
#include <bits/stdc++.h> using namespace std; int dis(char a, char b) { if (a > b) swap(b, a); return min(b - a, a + 26 - b); } string tmp = ACTG ; int main() { int n; scanf( %d , &n); string s; cin >> s; int mn = INT_MAX; for (int i = 0; i + 4 - 1 < n; i++) { int now = ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 90; vector<long long> col[2]; long long savecol[maxn]; long long dis[maxn][12]; long long g[88][88]; void solve() { long long n, k; scanf( %lld %lld , &n, &k); for (long long i = 1; i <= n; i++) for (long long j = 1; j ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; int a[MAXN]; int nxt[6]; long long solve() { int n; scanf( %d , &n); vector<int> ids[6]; for (int i = 0; i < n; i++) { int x; scanf( %d , &x); if (x == 4) ids[0].push_back(i); if (x == 8) ids[1].push_bac...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 11, inf = 1e9 + 10; char ch[4] = { D , I , M , A }; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1}, ans = -inf, tans[N][N], n, m; char c[N][N]; bool mark[N][N], indfs[N][N]; bool isOkay(int x, int y) { return (x >= 0 && x < n && y >= 0 &...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int maxn = 611111; long long num[maxn]; namespace SAM { int trans[maxn][30], par[maxn], len[maxn], tot, last; long long cnt[maxn][3]; inline int NewNode() { memset(trans[tot], 0, sizeof(trans[tot])); return tot++; } ...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; int x1, y1, z1; cin >> x >> y >> z; cin >> x1 >> y1 >> z1; int a[6]; int ans(0); for (int i(0); i < 6; ++i) cin >> a[i]; if (z > z1) ans += a[3]; if (z < 0) ans += a[2]; if (x < 0) ans += a[4]; if (x ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { string str; cin >> str; char g = str[0]; long count = 0, d = 1; for (string::iterator i = str.begin() + 1; i < str.end(); ++i) { if (*i != g) { count++; g = *i; d = 1; } else if (d...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c = 0; cin >> a; b = 1; while (c < a) { c = (b * (b + 1)) / 2; b++; } b--; if (c == a) cout << b << endl; else { cout << b - c + a << endl; } }
#include <bits/stdc++.h> const double EPS = 1e-9; const int INT_INF = 1 << 31 - 1; const long long I64_INF = 1ll << 63 - 1ll; const double PI = acos(-1.0); using namespace std; long long solve(int len) { if (len == 1 || len == 2) return 9LL; long long pow = 1LL; for (int i = 0; i < len - 2; i++)...
#include <bits/stdc++.h> using namespace std; const int MxN = (int)2e5 + 9; const int mod = 998244353; long long fact[MxN + 9]; vector<int> adj[MxN + 9]; long long f(const int u, const int parent) { long long res = fact[(int)adj[u].size()]; for (int v : adj[u]) if (v != parent) { res *...
#include <bits/stdc++.h> using namespace std; int n, x1, x2, x3, x4; int main() { cin >> n; cout << YES << endl; for (int i = 0; i < n; i++) { cin >> x1 >> x2 >> x3 >> x4; x1 = abs(x1) % 2; x2 = abs(x2) % 2; cout << x1 * 2 + x2 + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000009; long long int power(int x, int y) { if (y == 0) return 1; long long int temp = power(x, y / 2); temp *= temp; temp %= mod; if (y & 1) temp *= x; return temp % mod; } long long int ans[100005]; int main() { ...
#include <bits/stdc++.h> using namespace std; char s[302][302]; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int n, p; cin >> n >> p; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); vector<int> ans; for (int i = 1; i < 2003; i++)...
#include <bits/stdc++.h> using namespace std; int main() { int t; long long n; cin >> t; while (t--) { set<long long> a; a.insert(0); cin >> n; for (int i = 1; i <= sqrt(n); i++) { a.insert(i); a.insert(n / i); } cout << a.size() << endl; for...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; int inf = 1e9 + 7; long long INF = 1e18; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { ios_base::sync_with_stdio(false); int k; cin >> k; vector<long long> a; map<long long, pa...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 1e7 + 5; const long long INF = 9e18; const int M = 1e5 + 5; map<long long, vector<int> > f; long long p[N], ans1[M], a[M]; void solve() { for (int i = 2; i <= N; ++i) { if (i % 2 == 0) { p[i] = 2; ...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { long long n, k; cin >> n >> k; if (k % 3 != 0) { if (n % 3 == 0) cout << Bob << endl; else cout << Alice << endl; } else { n %= (k + 1); ...
#include <bits/stdc++.h> using namespace std; string tostr(int n) { stringstream rr; rr << n; return rr.str(); } int sc() { register int c = getchar(); register int x = 0; int neg = 0; for (; ((c < 48 || c > 57) && c != - ); c = getchar()) ; if (c == - ) { neg = 1; ...
#include <bits/stdc++.h> struct circle { double x, y, r; }; double dis(circle a, circle b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } bool canGo(circle tar, circle small, circle big) { if (small.r >= tar.r + dis(tar, small)) return true; if (big.r + tar.r <= dis(ta...
#include <bits/stdc++.h> using namespace std; int n; int m; void bfs(int u, vector<pair<int, int>> &p, vector<vector<pair<int, int>>> &adj) { queue<int> q; q.push(u); while (!q.empty()) { int cur = q.front(); q.pop(); for (auto as : adj[cur]) { int v = as.first; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 2e18 + 33; const int MX = 2 * 1e5 + 11; long long N, M, k, s, d; int arr[MX]; vector<pair<int, int> > v; int main() { cin >> N >> M >> s >> d; for (int i = 0; i < N; i++) scanf( %d , &arr[i]); arr[N] = M + 1; sort(arr, arr...
#include <bits/stdc++.h> using namespace std; vector<int> a; int main() { string s; cin >> s; int i, l = 0, can = 0, can_too = 0; for (i = 0; i < s.length(); i++) { if (s[i] == @ && can == 0) { can = 1; a.push_back(i); } else if (s[i] == . && can && !can_too) { ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { int n; int k; cin >> n >> k; auto dp = vector<int>(n); auto mas = vector<int>(n); for (int i = 0; i < n; ++i) cin >> mas[i]; if (k == n || k == n - 1) { for (int i = 0; i < n; ++i) cout << n << ; ...
#include <bits/stdc++.h> using namespace std; vector<int> adj[1000000 + 342]; set<int> ans; bool incl[1000000 + 342]; bool isleader[1000000 + 342]; map<pair<int, int>, bool> egd; int main() { ios::sync_with_stdio(false); int n, m, x, y; cin >> n >> m; for (int i = 0; i < m; i++) { ci...
#include <bits/stdc++.h> using namespace std; int n, les, m, f[5010], g[5010]; char s[5010]; template <class Aqua> inline void read(Aqua &s) { s = 0; Aqua f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) s = s * 10 +...
#include <bits/stdc++.h> using namespace std; int n, l[1010], ch, h = 0, kol = 0; int main() { cin >> n; memset(l, 0, sizeof l); for (int i = 0; i < n; ++i) { cin >> ch; ++l[ch]; } for (int i = 0; i <= 1000; ++i) { if (l[i]) ++kol; h = max(h, l[i]); } cout << h ...
#include <bits/stdc++.h> const size_t N = 2 * 100002; int main(void) { long long n, k, res = 0; std::cin >> n >> k; int arr[N]; for (long long i = 0; i < n; ++i) std::cin >> arr[i]; int next[N]; next[n - 1] = n; for (long long i = n - 2; i >= 0; --i) next[i] = arr[i + 1] != 1 ? i +...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; char A[SIZE]; long long d[SIZE]; int len; vector<long long> D; long long dp[2][4000][2][2]; void ADD(long long &x, long long v) { x = (x + v) % MOD; } long long CC(long long x) { return x * (x - 1) / 2 ...
#include <bits/stdc++.h> using namespace std; template <class T> void dbs(string str, T t) { cerr << str << : << t << n ; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find( , ); cerr << str.substr(0, idx) << : << t << , ; dbs(str.substr(idx + ...
#include <bits/stdc++.h> int inp() { char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); int sum = 0; while (c >= 0 && c <= 9 ) { sum = sum * 10 + c - 0 ; c = getchar(); } return sum; } int n, x[200010]; long long ans[200010], sum[200010]; void solve(int a, in...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long maxn = 1e5 + 7; const long long maxe = 1e6 + 7; const long long INF = 1e9 + 7; const double PI = acos(-1); int dx[4] = {0, 0, 1, -1}; int dy[4] = {-1, 1, 0, 0}; inline void Max(int &a, int b) { if (b > a) ...
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 0, 1, -1}, dy[] = {-1, 1, 0, 0}; const int dxx[] = {0, 0, 1, -1, -1, -1, 1, 1}, dyy[] = {-1, 1, 0, 0, 1, -1, 1, -1}; ifstream f( ); ofstream g( ); int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long ...
#include <bits/stdc++.h> using namespace std; string s, a, b; int to[27], k, T; bool vis[27]; bool up(int dir) { if (dir == s.size()) return 1; if (to[s[dir] - a ] != -1) { int t = to[s[dir] - a ]; if (t > a[dir] - a ) return 1; if (t < a[dir] - a ) return 0; return up(dir ...
#include <bits/stdc++.h> using namespace std; int main() { map<int, int> container_1; map<int, int> container_2; int n; cin >> n; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; container_1[a] = b; container_2[a] = 0; } int k; cin >> k; for (int i =...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 1000005; vector<int> dp[MAX]; int a[MAX]; void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } int main() { int n, k; long long l; scanf( %d %I64d %d , &n, &l, &k); for (int i = 0; i ...
#include <bits/stdc++.h> int main() { char str[1000][1000], str1[] = bcdfghjklmpqrstvwxyz ; int i, j, k, c = 0, s = 0; scanf( %s , str[0]); for (i = 0; i < strlen(str[0]); i++) { for (j = 0; j < strlen(str1); j++) { if (str[0][i] == str1[j]) { s = s + 1; if (str[0][i...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, x, y, b, a, temp; cin >> n >> b >> a; temp = a; long long int c[n]; for (i = 0; i < n; i++) cin >> c[i]; for (i = 0; i < n; i++) { if (c[i] == 0 && a != 0) a--; else { if (b > 0 && c...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; bool gt = true; long long mn = m, mx = m; long long curt = 0; for (lo...