func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n; int x[20005], y[20005], c[20005], ans[20005], LOC; bool cmp(const int &u, const int &v) { return (x[u] - x[LOC]) * (y[v] - y[LOC]) - (y[u] - y[LOC]) * (x[v] - x[LOC]) < 0; } void solve(int l, int r) { if (l > r) return; int loc = l;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int MOD = 1e9 + 7; int m, d, L; int bit[2001]; long long dp[2001][2001]; void add(long long &x, long long y) { x = (x + y) % MOD; } long long DFS(int pos, int preyu, bool yes) { if (pos == L) return preyu == 0; if (!y...
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using si = unordered_set<int>; using vsi = vector<si>; using vvi = vector<vi>; using qi = queue<int>; int n, k, r, s = -1; vi d, depth; vsi h; vvi g; bool dfs(int u, int p) { if (p == -1 && (d[u] != 2 && d[u] != 3)) return 0...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long N = 4e5; long long fac[N]; long long qpow(long long x, long long y) { long long res = 1; for (; y; y >>= 1, x = x * x % mod) if (y & 1) res = res * x % mod; return res; } long long inv(long lon...
#include <bits/stdc++.h> using namespace std; int used[1123], used1[1123]; char a[1123][1123]; int main() { int n, m, i, j; bool flag = 0; cin >> n >> m; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cin >> a[i][j]; } } int ans = 0; for (j = 1; j <= m; j++...
#include <bits/stdc++.h> using namespace std; vector<long long> bitr; void update(long long ind, long long val, long long n) { long long i = ind + 1; while (i <= n) { bitr[i] += val; i += i & (-i); } } long long sum(long long ind) { long long i = ind + 1; long long ans = 0; ...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; const long long linf = 1ll * inf * inf; const int N = 100000 + 7; const int multipleTest = 0; vector<pair<int, int> > adj[N]; int pa[N][20]; int depth[N]; int g[N]; int root[N]; int k = 0; int n; int low[N]; int high[N...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m; cin >> n >> m; vector<vector<int> > file(n); for (int i = (0); i < ((m)); ++i) { int tmp; cin >> tmp; vector<int> f(tmp); for (int j = (0); j < ((tmp)); ++j) cin >> f[j]; file.push_back(f); } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<int> x(n + m - 1); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ...
#include <bits/stdc++.h> using namespace std; char getOtherValue(char val) { if (val == . ) return 0 ; if (val == 1 ) return 0 ; return 1 ; } int main() { int n, p; cin >> n >> p; string str; cin >> str; bool ok = false; for (int i = 0; i < n - p; ++i) { if (str[i]...
#include <bits/stdc++.h> using namespace std; const int INF = 2000000009; const int Max = 1000007; const double PI = acos(-1.0); double binSearch(double p, double b) { int low = 0, high = INF, k; double x; while (low <= high) { k = (low + high) / 2; x = p / (2.0 * k); if (x < b) ...
#include <bits/stdc++.h> using namespace std; vector<int> v[10005]; long long a[100005], dis[10005]; int b[100005], vis[10005]; bool cmp(const int &first, const int &second) { return a[first] < a[second]; } priority_queue<pair<long long, int> > T, Q; int main() { long long h; int n, m, p; scan...
#include <bits/stdc++.h> using namespace std; char str[1010000]; int b[1010000]; int a[1010000]; int bb[1010000]; int main() { int n; int flag = 1; scanf( %d , &n); scanf( %s , str); for (int i = 1; i <= n; i++) { scanf( %d , &b[i]); } int coutt1 = 0; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; vector<pair<double, double> > vec; double x[10], y[10]; int cross(pair<double, double> a, pair<double, double> b, pair<double, double> c) { double re = (a.first - c.first) * (b.second - c.second); re -= (a.second - c.second) * (b.first - c.first)...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } v.insert(v.begin(), 0); for (int i = 1; i <= n; i++) { v[i] += v[i - 1]; } int ans = 0; int l, r; cin >> l >> r; if (...
#include <bits/stdc++.h> using namespace std; const long long int MAX = 1e6 + 5; const int N = 2e5 + 5; const long long int mod = 1e9 + 7; const long long int mx = 1e16; bool comp(const int a, const int b) { return a > b; } const double PI = 2 * acos(0.0); long long int fac[N]; void pre() { fac[0]...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2 * (1e5) + 10, inf = 2147483647; long long ans; int n, lastR, lastB, lastP, mxR, mxB; int main() { int x; char c; scanf( %d , &n); lastR = lastB = lastP = -inf; mxR = mxB = 0; for (int i = 1; i <= n; ++i) { scanf( %d...
#include <bits/stdc++.h> using namespace std; int a[41][1001][1001]; int bir(int n) { int s = 0; while (n > 0) { s += n % 2; n /= 2; } return s; } bool fun(int x, int i) { if (i < 0) return 0; return ((x >> i) & 1); } bool funk(int a, int b, int c, int m) { for (int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long k, left; cin >> k; long long base = k + 1; vector<long long> v; v.push_back(-1); left = base; for (long long i = 1; i < 2001; i++) { left++; if ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:64000000 ) char buf[1 << 7]; string s; int smask; int D1[5][5] = {{0, 3, 7, -1, -1}, {1, 4, 8, 12, -1}, {2, 5, 9, 13, 16}, {6, 10, 14, 17, -1}, {11, 15, 18, -...
#include <bits/stdc++.h> using namespace std; string s[500000]; const int mod = 1000003; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; int result = 1; for (int i = 0; i < n; i++) { bool ok1 = false, ok2 = false; for (int j = 0; j < m; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int i, n, t, p = 0, hPxl, hPxl1, wPxl, Pxl, sum = 0; scanf( %d , &n); int h[n + 5], w[n + 5]; for (i = 0; i < n; ++i) { scanf( %d %d , &w[i], &h[i]); sum += w[i]; } hPxl = *max_element(h, h + n); for (i = 0; i < n; ++...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; const long long int LINF = 1LL * INF * INF; const int MAXN = 2e5 + 10; const int MAXM = 5e3 + 10; priority_queue<int> pq; vector<vector<int> > graph; queue<int> que; long long int mygcd(long long int a, long long int b) { retu...
#include <bits/stdc++.h> using namespace std; signed main() { long long i, j, t, n, m; cin >> n; long long a[n], b[n], c[n]; if (n & 1) { for (long long i = 0; i < n; ++i) { a[i] = i; b[i] = i; c[i] = i + i; c[i] %= n; } for (long long i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; const int SIZE = 100005; int gap, tmp[SIZE * 2]; class SuffixArray { public: int sa[SIZE], rk[SIZE], ht[SIZE]; static bool cmp(int x, int y) { if (tmp[x] != tmp[y]) return tmp[x] < tmp[y]; return tmp[x + gap] < tmp[y + gap]; } void gao...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector ) using namespace std; int n, k, nrr = 1, t[502 * 1005]; string s; struct point { double x, y; int ind; point() {} point(const point& a) { x = a.x, y = a.y; ind = a.ind; } point(double _x, ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> t; while (t--) { cin >> n; vector<int> a(n); int mx = 0; for (auto &it : a) { cin >> it; mx = max(mx, it); } int r = n - 1; int ind = -1; for (int l = 0; l < n; l++...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 100010; int a[N]; bool cont[110][N]; long long f[N][110], sumf[N]; int main() { ios::sync_with_stdio(false); int n, k, len; cin >> n >> k >> len; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 1; long long gcd(long long a, long long b) { long long r; while (b > 0) { r = a % b; a = b; b = r; } return a; } int main() { long long n, k, a, b, maxkq = 0, minkq = 1e18, l, kq, g, tmp; cin >...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const long long INF_LL = 1000000000000000000LL; const double pi = 2 * acos(0.0); template <class T> void smin(T& a, T b) { if (a > b) a = b; } template <class T> void smax(T& a, T b) { if (a < b) a = b; } template <c...
#include <bits/stdc++.h> using namespace std; int main() { srand(time(0)); if (rand() % 2 == 0) cout << Odd ; else cout << Even ; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 3 * (n / 2); }
#include <bits/stdc++.h> using namespace std; struct ppp { int x, y, id; } a[120000], b[120000]; int i, j, k, l, n, m, p, t; bool cmp(const ppp& a, const ppp& b) { return a.y < b.y || a.y == b.y && a.x > b.x; } bool cmp2(const ppp& a, const ppp& b) { return a.x > b.x || a.x == b.x && a.y > b.y...
#include <bits/stdc++.h> using namespace std; const int Maxn = 1000 + 10; const int INF = 0x7f7f7f7f; const double eps = 1e-8; const double pi = 3.1415926535897932384626433832795; double p[Maxn], f[Maxn][Maxn]; long long L[Maxn], R[Maxn]; inline long long power(int a, int b) { long long ans = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> m >> k; vector<long long> v; for (int i = 0; i < n; i++) { long long x; cin >> x; v.push_back(x); } long long sum = 0; int i; for (i = n - 1; i >= 0; i--) { sum += v[i]; ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long x = a, y = b; if (y > x) { swap(x, y); } while (y != 0) { x = x % y; swap(x, y); } return (a * b) / x; } long long x, a, y, b, k, c; bool checker(long long n, long long k...
#include <bits/stdc++.h> using namespace std; int n, m; vector<vector<int> > adj; bool acyclic = 1; int topo[500005]; int ptr = 0; bool visited[500005]; bool in_stack[500005]; void solve(int i) { if (in_stack[i]) { acyclic = 0; return; } if (visited[i]) { return; } ...
#include <bits/stdc++.h> using namespace std; using namespace chrono; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _p...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; string s; cin >> s; long long n = s.length(); s = 1 + s; long long x[n + 1], y[n + 1], z[n + 1]; x[0] = 0; y[0] = 0; z[0] = 0; for (long long i = 1; i ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; } template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; } inline int nxt() { int wow; scanf( %d , &wow); return wo...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, ans, G[8][8], vis[8]; vector<pair<int, int> > Edge; void dfs(int x) { if (x > n) { int res = 0; for (auto tmp : Edge) { int u = vis[tmp.first]; int v = vis[tmp.second]; if (u > v) swap(u, v)...
#include <bits/stdc++.h> using namespace std; const int iinf = 1e9 + 7; const long long linf = 1ll << 60; const double dinf = 1e60; template <typename T> inline void scf(T &x) { bool f = 0; x = 0; char c = getchar(); while ((c < 0 || c > 9 ) && c != - ) c = getchar(); if (c == - ) {...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; int a[SIZE], b[SIZE], c[SIZE], cnt[SIZE]; bool used[SIZE]; vector<int> r[SIZE]; set<int> H; void print_array(vector<int>& arr) { for (int i = 0; i < (((int)(arr).size())); ++i) { if (i) printf( ...
#include <bits/stdc++.h> using namespace std; char s[200001], t[200001]; int main() { int i; int n, m; scanf( %d %d %s %s , &n, &m, s, t); for (i = 0; i < n; i++) { if (s[i] == * ) break; } if (i == n) { if (n != m) { printf( NO n ); return 0; } for...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t; cin >> t; while (t--) { int a0, a1, a2, b0, b1, b2, ex0, ex1, ex2, ever, only0, only1, only2; cin >> a0 >> a1 >> a2 >> b0 >> b1 >> b2 >> ever >> ex2 >> ex1 >> only0 >> ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i = 1, j = n, count = 0, k = 1; while (k <= (n - 1)) { count = count + ((i + j) % (n + 1)); if (k % 2 == 1) { i++; } else { j--; } k++; } cout << count; }
#include <bits/stdc++.h> using namespace std; struct point { int x, y, z; double dist(point& p) { return sqrt((double)((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y) + (p.z - z) * (p.z - z))); } }; int N; point P[5005]; double solve() { double res = 1e10; ...
#include <bits/stdc++.h> using namespace std; inline vector<int> prefix(string p) { vector<int> pi; int m = p.size(); for (int(i) = (0); (i) < (m); ++(i)) pi.push_back(-1); int k = -1; for (int(i) = (1); (i) < (m); ++(i)) { while (k != -1 && p[k + 1] != p[i]) k = pi[k]; if (p[k + 1] ...
#include <bits/stdc++.h> using namespace std; int main() { int n, oh, wow; cin >> n >> oh >> wow; vector<int> res; res.push_back(1); int sum = 1; for (int i = 0; i < wow; i++) { res.push_back(sum + 1); sum += sum + 1; } if (!wow && oh) res.push_back(1); for (int i = 0...
#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 int INF = (int)1e9 + 1; const long double EPS = 1e-9; voi...
#include <bits/stdc++.h> using namespace std; int a[1000010]; long long cnt[1000010]; int main() { ios::sync_with_stdio(0); int n; cin >> n; long long s = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; s += a[i]; } if (s % 3 != 0) cout << 0 n ; else { s /=...
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { ios_base::sync_with_stdio(false); cin.tie(NULL); int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; double slope; slope = x2 == x1 ? INT_MAX : (double)(y2 - y1) / (double)(x2 - x1); if (slope == 0 || abs(slope)...
#include <bits/stdc++.h> using namespace std; int N, M; int For[100000], Against[100000]; int TotalFor = 0, TotalAgainst = 0; int Vote[100000]; int Sign[100000]; int J[100000]; int R[100000]; void Solve() { int c = 0; for (int i = 0; i < N; i++) { J[i] = true; if (For[i] + TotalAga...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; long long a[maxn]; int main() { long long n, k, x; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> x; a[i] = a[i - 1] + x; } long long ans = a[n] * k; sort(a + 1, a + n); for (int i = 1; i < k; ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int N = 510; const int MOD = 998244353; int a[N]; int b[N]; int dp[N][N]; void add_self(int& x, int y) { if ((x += y) >= MOD) { x -= MOD; } } void sub_self(...
#include <bits/stdc++.h> using namespace std; const int N = 102; int t, n, m, r[N], b[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> t; for(int ti = 1; ti <= t; ++ti) { cin >> n; for(int i = 1; i <= n; ++i) { cin >> r[i]; r[i] += r[i - 1]; } cin >> m; ...
#include <bits/stdc++.h> using namespace std; const int maxi = 1e6 + 6; int b, di; string a, c, t; pair<int, int> d[maxi], d1[maxi]; int ob[maxi]; int main() { cin >> b >> di; cin >> a; cin >> c; int n = a.size(); int m = c.size(); for (int i = 0; i < m; i++) { int id = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n; cin >> k; vector<string> s(n); set<string> exist; for (int i = 0; i < n; i++) { cin >> s[i]; exist.insert(s[i]); } long long int count = 0; for (int x = 0; x < n - 1; x++) { for (int ...
#include <bits/stdc++.h> using namespace std; inline long long max(long long a, long long b) { return a > b ? a : b; } inline long long min(long long a, long long b) { return a > b ? b : a; } template <typename T> inline int read(T& res) { long long x = 0, f = 1, flag = 0; char ch; flag = ch = get...
#include <bits/stdc++.h> using namespace std; int main() { int n, t; scanf( %d%d , &n, &t); int x, y; vector<pair<int, int> > v(n); for (int i = 0; i < (int)(n); ++i) { scanf( %d%d , &x, &y); v[i].first = x; v[i].second = y; } int a[4] = {v[0].first, v[0].second, 7 - v[...
#include <bits/stdc++.h> using namespace std; template <typename T> void deb(T v[], long long n) { if (false) cerr << ARRAY : ; long long i; for (i = 0; i < n; i++) if (false) cerr << v[i] << ; if (false) cerr << endl; } template <typename T> void deb(set<T> s) { if (false) ...
#include <bits/stdc++.h> using namespace std; int n; int m; int p[100]; int f() { int r = 0; for (int i = 0; i < n; i++) { int m = p[i]; for (int j = i; j < n; j++) { if (m > p[j]) m = p[j]; r += m; } } return r; } void print() { for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; string a, b, c, d; int pref[123456]; int main() { int n, k; cin >> n >> k; string s; cin >> s; s = . + s; for (int i = 1; i < s.length(); i++) { pref[i] = pref[i - 1]; if (s[i] == 0 ) pref[i]++; } int ans = INT_MAX; ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int n; cin >> n; int a[100005]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int inter = a[1] - a[0]; for (int i = 2; i < n; i++) { inter = gcd(inte...
#include <bits/stdc++.h> using namespace std; struct Meth { int hud, ten; void init(int hud, int ten) { this->hud = hud, this->ten = ten; } bool operator==(const class Meth &ans) const { return hud == ans.hud && ten == ans.ten; } }; bool cmpC(const struct Meth &ans1, const struct Meth &ans...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; const long long MOD = 1000000007; const long long mod = 1000000007; const int Nmax = 2000006; long long gcd(long long a, long long b) { if (a == 0) { return b; } return gcd(b % ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %d%d , &n, &k); char a[4][n]; for (int i = 0; i < 4; i++) for (int j = 0; j < n; j++) a[i][j] = . ; if (!k) { printf( YES n ); for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) printf( ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; int ary[10005]; int bry[10005]; vector<pair<int, int> > ans; int pivot[31], pid[31]; int pivot2[31], pid2[31]; bool vis[10005]; void solve(int n, int a[]) { for (int i = 0; i < 31; ++i) pid[i] = -1; for (int k = 0; k < n; +...
#include <bits/stdc++.h> int n; struct camel { int x, d; inline bool operator<(const camel& a) const { return x < a.x; } } c[105]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d%d , &c[i].x, &c[i].d); std::sort(c, c + n); for (int i = 0; i < n; i++) for (int j ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.); const double eps = 1e-6; int n, d; int main() { scanf( %d%d , &n, &d); if (n == 1) printf( %d n , d); else { if (d == 0) { puts( No solution ); } else { printf( %d , 1); for (int i ...
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int> > ans; int a[1000000]; int b[1000000]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n; i++) { if (b[i] ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; int a[n]; int sum = 0, ans = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } for (int i = 0; i < n; i++) if (!((sum - a[i]) % 2)) ans++; cout << ans ...
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { ~debug() { cerr <...
#include <bits/stdc++.h> using namespace std; long long iHateGeometry[100001]; int main() { int N; scanf( %d , &N); long long maxi = -1, sum = 0; for (int i = 0; i < N; i++) { scanf( %lld , &iHateGeometry[i]); sum += iHateGeometry[i]; maxi = max(maxi, iHateGeometry[i]); } ...
#include <bits/stdc++.h> using namespace std; long long a[3000005], has[3000005], visited[2000005], dist[1000005]; long long pr[3000010]; long long addmod(long long n, long long m) { return ((n % 1000000007) + (m % 1000000007)) % 1000000007; } long long multmod(long long n, long long m) { return ((n...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) using namespace std; template <class T> inline bool setmin(T &a, T b) { if (a > b) return a = b, 1; return 0; } template <class T> inline bool setmax(T &a, T b) { if (a < ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9 + 7; const int sz = 1e5 + 10; int main() { ll k, b, n, t, z, ans, zz; while (cin >> k >> b >> n >> t) { z = 1; ans = n; for (int i = 0; i < n && z < t; i++) { z = z * k + b; ans--;...
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long res = 0, pd = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) pd = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { res = (res << 1) + (res << 3) + ch - 0 ; ch =...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; string s; cin >> s; long long int mid = n / 2; long long int check = 0; for (long long int i = 0; i < n; i++) { if (s[i] == 0 ) { check = 1; if (i >= mid) { cout << 1 ...
#include <bits/stdc++.h> using namespace std; void sol_problem(const long *, long); int main() { long n, t, *matriz; cin >> n >> t; matriz = new long[n - 1]; for (int i = 0; i < n - 1; i++) cin >> matriz[i]; sol_problem(matriz, t); return 0; } void sol_problem(const long *matriz, long ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; long long mod = (1e9 + 7); int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } bool is_vowel(char c) { if (c == a || c == e || c == i || c == o || ...
#include <bits/stdc++.h> int main() { int64_t n, i, j; scanf( %I64d , &n); j = (n) * (2 * 3 + (n - 1) * 3) + 1; printf( %I64d , j); return 0; }
#include <bits/stdc++.h> using namespace std; void fail(string s) { cout << s; exit(0); } void fail(int s) { cout << s; exit(0); } int n; int x[5005], y[5005]; int d[5005]; vector<int> v[5005]; int len(int a, int b) { return abs(x[a] - x[b]) + abs(y[a] - y[b]); } int ok = 0; void...
#include <bits/stdc++.h> using namespace std; bool ask(int a, int b, int c, int d) { cout << ? << a << << b << << c << << d << endl; fflush(stdout); string response; cin >> response; if (response == BAD ) { exit(0); } else if (response == YES ) return true; e...
#include <bits/stdc++.h> using namespace std; int main() { int a; scanf( %d , &a); string ans = NO ; for (int i = 0; i < a; i++) { string name; int bef, aft; cin >> name; scanf( %d %d , &bef, &aft); if (bef >= 2400 && aft > bef) { ans = YES ; } } ...
#include <bits/stdc++.h> using namespace std; int n, t1, p; int b[200000], h[200000]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> b[i]; if (!b[i]) { --i; --n; } } for (int i = 0; i < n; i++) { cin >> h[i]; if (h[i] == b[0]) p = i; ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; double memo[105][105][105]; double dp(int R, int S, int P) { if (R == 0) return 0; if (S + P == 0) return 1; double& ret = memo[R][S][P]; if (memo[R][S][P] >= 0) return ret; ret = 0; i...
#include <bits/stdc++.h> using namespace std; const int maxn = 500000 + 10; int n; vector<int> li; struct node { int x, y; } p[maxn]; bool cmp1(node a, node b) { return a.x < b.x; } bool cmp2(node a, node b) { return a.y < b.y; } long long vis[maxn], ans; int main() { scanf( %d , &n); fo...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int maxn = 222222; int main(int argc, char const *argv[]) { long long s, x; cin >> s >> x; if (s < x || (s - x) % 2) { puts( 0 ); } else { long long c = (s - x) / 2; long long ans = 1; for (int i...
#include <bits/stdc++.h> using namespace std; string s; int n; int oddb, evenb, oddr, evenr; int main() { cin >> n; cin >> s; int ans = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { if (s[i] == b ) evenb++; else if (s[i] == r ) evenr++; } ...
#include <bits/stdc++.h> using namespace std; long long int s[4]; int main() { long long int x, y; while (scanf( %I64d%I64d , &x, &y) == 2) { s[0] = y; s[1] = y; s[2] = y; sort(s, s + 3); long long int cnt = 0; while (1) { if (s[0] == x && s[1] == x && s[2] == x...
#include <bits/stdc++.h> using namespace std; const int N = 2000100; const int inf = 1000000007; int dp[N][2], n, m[2], t, tot = 0, g[N][2], path[N], ans[N]; struct nd { int d, id; } a[N][2]; struct element { int d, id[2]; } b[N]; struct point { int x, y; } po[N]; inline int read() { ...
#include <bits/stdc++.h> using namespace std; inline void FAST_IO() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const int N = 3e5 + 5; long long n, k, A, B; long long a[N]; inline long long dfs(long long l, long long r) { long long now = upper_bound(a, a + k, r) - lower_bound...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long n, m; cin >> n >> m; vector<set<long long>> v((size_t)n); auto add = [&](long long a, long long b) { v[a].insert((b - a + n) % n); }; for (long long i = 0; i < m; i++)...
#include <bits/stdc++.h> using namespace std; const int MAXSIZE = 10000020; int bufpos; char buf[MAXSIZE]; void init() { buf[fread(buf, 1, MAXSIZE, stdin)] = 0 ; bufpos = 0; } int readint() { int val = 0; for (; !isdigit(buf[bufpos]); bufpos++) ; for (; isdigit(buf[bufpos]); bu...
#include <bits/stdc++.h> using namespace std; int n, m, q; std::vector<int> val(500005); std::map<int, pair<int, int> > edges; std::vector<pair<int, int> > query(500005); int vis[500005]; int par[500005]; set<pair<int, int> > ss[500005]; int sz[500005]; std::vector<pair<int, int> > changes[500005]; ...
#include <bits/stdc++.h> const int bufSize = 1e6; using namespace std; inline char nc() { return getchar(); static char buf[bufSize], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++; } inline void read...
#include <bits/stdc++.h> using namespace std; void solve(long long int test) { long long int n; cin >> n; cout << n << endl; for (long long int i = 1; i <= n; i++) cout << i << ; cout << endl; } int main() { long long int t = 1, test = 1; cin >> t; while (t--) { solve(te...
#include <bits/stdc++.h> using namespace std; const int INF = 303303; const int Max = 101101; int n, S, L; int a[Max]; int lg[Max]; struct sparse { int g, h; }; sparse s[22][Max]; void build_table() { for (int i = 1; i <= n; i++) { s[0][i].g = a[i]; s[0][i].h = a[i]; } fo...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct ...