func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { pair<long long, int> p[400005]; int n, m; cin >> n; for (int i = 0; i < n; i++) { cin >> p[i].first; p[i].second = 1; } cin >> m; for (int i = 0; i < m; i++) { cin >> p[i + n].first; p[i + n].second = 2; ...
#include <bits/stdc++.h> using namespace std; const int MaxN = 100100; const int Mod = 1e9 + 7; long long N, S; long long p[MaxN]; long long deg[MaxN]; long long pref[MaxN]; long long depth[MaxN]; vector<long long> child[MaxN]; void solve(long long branch) { for (int j = (2); j < (N + 1); j++) {...
#include <bits/stdc++.h> using namespace std; long long n, a, b, sum[200005], sm[200005]; struct node { long long x, y, z; } val[200005]; bool comp(node a, node b) { return a.z > b.z; } int main(void) { long long ans = 0; scanf( %lld%lld%lld , &n, &a, &b); b = min(b, n); for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 205; const int mod = 10007; void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } int mul(int x, int y) { return x * y % mod; } int pw(int x, int y) { int ret = 1; while (y) { if (y & 1) ret = mul(ret, x); x = mu...
#include <bits/stdc++.h> using namespace std; int main() { int n, A, B; while (cin >> n) { vector<int> a, b; while (n--) { int p; cin >> p; a.push_back(p); } int ans = 0; cin >> A >> B; sort(a.begin(), a.end()); a.resize(unique(a.begin(), a.e...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 5e5 + 2; const int M = 1e5 + 2; const int inf = 2e9 + 2; const long long linf = 4e18 + 2; long long add(long long a, long long b) { a += b; return a >= mod ? a - mod : a; } long long sub(long long a, lon...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int n; int a[5005], pos[5005]; long long dp[5005], f[5055], inv[5005]; void prework() { f[0] = 1; f[1] = 1; inv[1] = 1; inv[0] = 1; for (int i = 2; i <= n; i++) { f[i] = f[i - 1] * i % mod; inv[i] ...
#include <bits/stdc++.h> int a[1010], b[1010]; int n, k, inf = 0x0f0f0f0f; int test(int cur) { int i, ans = 0; if (cur <= 0) return inf; for (i = 0; i < n; i++) { if (a[i] != cur) ans++; cur += k; } return ans; } int main() { int i, j, cur; while (~scanf( %d%d , &n, &k)...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; struct Event { int t, L, R, on; Event(int t = 0, int L = 0, int R = 0, int on = 0) : t(t), L(L), R(R), on(on) {} bool operator<(const Event &rh) const { return t < rh.t; } } E[maxn * 2]; int V[maxn * 2], cnt; int Pre[...
#include <bits/stdc++.h> using namespace std; int a[105]; int f[105]; int v[105]; bool cmp(int i, int j) { return a[i] > a[j]; } int main() { int n, w; while (cin >> n >> w) { int sum = 0; int sum2 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; ...
#include <bits/stdc++.h> using namespace std; class BIT { std::vector<int> bit; public: BIT(int size) : bit(size + 1, 0) {} void add(int i, int x) { i++; while (i < (int)bit.size()) { bit[i] += x; i += i & -i; } } int sum(int a) { a++; int res ...
#include <bits/stdc++.h> const int N = 1000001; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, k; string s; cin >> n >> k >> s; m = s.size(); int last[200]; memset(last, -1, sizeof last); for (int i = 0; i < m; i...
#include <bits/stdc++.h> #pragma comment(linker, /stack:640000000 ) using namespace std; const double EPS = 1e-9; const int INF = 0x7f7f7f7f; const double PI = acos(-1.0); template <class T> inline T _abs(T n) { return ((n) < 0 ? -(n) : (n)); } template <class T> inline T _max(T a, T b) { r...
#include <bits/stdc++.h> using namespace std; const int iinf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3f; const int N = 1e4, M = 1e5; int n, m, p, a[N], b[M]; int gcd(int a, int b) { return a ? gcd(b % a, a) : b; } int mypow(int a, int first = p - 2, int res = 1) { for (; first; first >>= ...
#include <bits/stdc++.h> using namespace std; int n; double p[101], f[101], ans = 0, last = 1; double Calc(int x) { return 1 - (1 - f[x]) * (1 - p[x]); } int main() { cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; p[i] = f[i] = x / 100.0; last *= p[i]; } ans ...
#include <bits/stdc++.h> using namespace std; pair<double, double> p[100100]; double dt[100100]; double db[100100]; double da[100100]; int main() { double ax, ay, bx, by, tx, ty; int n; cin >> ax >> ay >> bx >> by >> tx >> ty; cin >> n; double ans = 0; scanf( %lf %lf , &p[0].first, &...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, n; while (~scanf( %d%d%d%d , &a, &b, &c, &n)) { if (c > a || c > b || n - (a + b - c) < 1) printf( -1 n ); else printf( %d n , n - (a + b - c)); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int count = 0, wc = 0; bool flag = 0; int m = n; while (n--) { string s; cin >> s; int l = s.size(); if (l % 2 == 1) flag = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k; cin >> n >> k; long long int cost = 0, ans = 0, a[n]; vector<pair<long long int, long long int>> pr(n); for (long long int(i) = 0; (i) < (n);...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; string ans; for (int i = 0; i < n; i++) ans += U ; for (int i = 0; i < m; i++) ans += L ; for (int i = 0; i < n; i++) { for (int j = 0; j ...
#include <bits/stdc++.h> using namespace std; const int N = 2010, mod = 998244353; int sm[2][N], n, f[N][N], a[N][N], ans; void add(int x, int y, int z) { for (; x <= n; x += x & -x) sm[z][x] += y; } int query(int x, int z) { int ret = 0; for (; x; x -= x & -x) ret += sm[z][x]; return ret; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; vector<int> p0; vector<int> p1; vector<int> ans(n); for (int i = 0; i < n; i++) { int newpos = p0.size() + p1.size(); ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { string s; cin >> s; reverse(s.begin(), s.end()); if (s.substr(0, 2) == op ) { cout << FILIPINO n ; } else if (s.substr(0, ...
#include <bits/stdc++.h> using namespace std; char field[1000][1000]; int deltas[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; int n, m; int si, sj, ti, tj; bool possible; void go(int i, int j, char num) { for (auto d : deltas) { int ii = i; int jj = j; while (true) { ii += d[0...
#include <bits/stdc++.h> using namespace std; int Df[300005], GG, RR, fw[300005 * 2], U, lt[300005], val[300005], rt[300005], color[300005], Dep[300005], st[300005], rev[300005], cnt, fa[300005][20], Fa[300005], cl, dfn[300005], in, col[300005], low[300005], tot = 1, node[300005], vst[300005 << 1]...
#include <bits/stdc++.h> using namespace std; long long int powe(long long int n, long long int m) { if (m == 0) return 1; long long int t = powe(n, m / 2); if (m % 2 == 0) return (t * t); return (((t * t)) * n); } long long int mpowe(long long int n, long long int m) { if (m == 0) return 1;...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const double PI = 3.1415926535897932; const int dir[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1}; const int maxn = 2e5 + 5; const int MOD = 998244353; int n, m; long long A[maxn], invA[maxn]; int w[maxn]; bool ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, m, i, j, k, sum; long long int a[100001]; cin >> n >> k; bool yo = false; for (i = 1; i <= k; i++) cin >> a[i]; sum = LONG_LONG_MAX; for (i = 1; i <= k; i++) { if (n % a[i] < sum) { sum = n % a[i...
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } template <class T> inline T bigmod(T p, T...
#include <bits/stdc++.h> using namespace std; const int big = 1e7 + 5; long long int arr[big]; void minDivsieve() { for (long long int i = 0; i <= big; ++i) arr[i] = i; for (long long int i = 2; i <= big; ++i) { if (arr[i] != i) continue; for (long long int j = i; j <= big; j += i) arr[j] = ...
#include <bits/stdc++.h> using namespace std; long long x, y, val = 0, q[1000010]; char d[1000010]; void build(int now, int x, int y) { if (x == y) return; int mid = (x + y) / 2; build(2 * now, x, mid); build(2 * now, mid + 1, y); } int main() { build(1, 1, 1000); cin >> x >> y; ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e7 + 1; int32_t main() { long long n; cin >> n; if (n % 2) cout << 1; else cout << 2; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double EPS = 1e-6; const int INF = 0x3f3f3f3f; inline int readint() { int sum = 0; char c = getchar(); bool f = 0; while (c < 0 || c > 9 ) { if (c == - ) f = 1; c = getchar(); } while (c >= ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n, d; cin >> n >> d; pair<long long, long long> s[n]; deque<long long> p; long long ind, cnt = 1; for (long long i = 0; i < n; i++) { cin...
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; long long p[n + 1]; p[1] = -1; for (long long i = 2; i <= n; i++) cin >> p[i]; vector<long long> ans; long long x = n; while (p[x] != -1) { ans.push_back(p[x]); x = p[x]; } revers...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf( %d , &n) != EOF) { if (n & 1) { int d = (n - 1) / 2; printf( %d n , d * 2 + d * d - d); for (int i = 2; i < n; i += 2) { for (int j = 2; j < i; j += 2) { printf( 4 %d %d %d %d ...
#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 ) using namespace std; const long long int maxN = 5005; long long int n; vector<long long int> a, coords, keys; long long int cnt...
#include <bits/stdc++.h> using namespace std; int h[5005], pref[5005], dp[5005]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &h[i]); pref[i] = pref[i - 1] + h[i]; for (int j = i - 1; j >= 0; j--) { if (pref[i] - pref[j] >= h[j]) { ...
#include <bits/stdc++.h> using namespace std; const int N = 12; const int M = 305; const int INF = 1e9; int n; int a[N][N]; pair<int, int> pos[N * N]; pair<int, int> dist[M][M]; pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) { return make_pair(a.first + b.first, a.secon...
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long a[N], sum[N]; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } int main() { int n; scanf( %d , &n); int i; long long ans = 0; for (i = 1; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 3e5 + 5; long long a[MAXN], kkorz[MAXN], bit[MAXN]; long long n; long long sum(long long idx) { long long res = 0; for (; idx > 0; idx -= (idx & (-idx))) res += bit[idx]; return res; } void upd(long long idx, long long x) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int inf = INT_MAX; const long long inff = 1e18; const long long mod = 1e9 + 7; vector<int> dx = {0, 1, 1, 1, 0, -1, -1, -1}; vector<int> dy = {1, 1, 0, -1, -1, -1, 0, 1}; int can[507][507]; set<pair<int, int> > second[32][9]...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[55], b[55], ans[5000] = {}, k = 0; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; cin >> m; for (int i = 0; i < m; ++i) cin >> b[i]; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (b[j] %...
#include <bits/stdc++.h> using namespace std; int a[100005], n; int main() { while (cin >> n) { for (int i = 1; i <= n; i++) { cin >> a[i]; while (a[i] % 2 == 0) a[i] /= 2; while (a[i] % 3 == 0) a[i] /= 3; } int i; for (i = 2; i <= n; i++) if (a[i] != a[...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t, n, m, i, j, k, sum, cnt, temp, ans; cin >> t; whil...
#include <bits/stdc++.h> using namespace std; int n, m; int a[15], b[15]; int cnt[15]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= m; i++) { int k; cin >> k; ...
#include <bits/stdc++.h> using namespace std; int read() { char ch; int sig = 1; for (ch = getchar(); ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) sig = -1; int x = ch - 0 ; for (ch = getchar(); ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - 0 ; return x * si...
#include <bits/stdc++.h> using namespace std; int main() { char str[8][10]; int n, k, i, j, l, mx, mn, mind; int p[] = {1, 2, 3, 4, 5, 6, 7, 8}; cin >> n >> k; for (i = 0; i < n; i++) cin >> str[i]; mx = 0; mn = 1000000000; mind = mn - mx; do { int arr[8] = {0}; mx = ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int a; cin >> a; string s; cin >> s; map<int, int> Freq; for (int i = 0; i < s.size(); i++) { int sum = 0; bool zero = false; for (int j = i; j < s.size(); ...
#include <bits/stdc++.h> typedef struct { double x; double y; double r; } circle; typedef struct { double x; double y; } pt; int x[3]; int y[3]; int r[3]; pt np(double x, double y) { pt q; q.x = x; q.y = y; return q; } double abs_d(double d1) { if (d1 > 0) ret...
#include <bits/stdc++.h> using namespace std; long long pf(int v) { return (long long)1 * v * v; } struct sd { int a, b; bool operator<(const sd& w) const { return a < w.a; } } x[100005]; long long maxx(long long a, long long b) { return a > b ? a : b; } long long minx(long long a, long long b) { re...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int x1, x2, y1, y2; long long int k; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2 || y1 == y2) k = abs(x1 - x2) + abs(y1 - y2); else k = 2 + abs(x1 - x2) + abs(y...
#include <bits/stdc++.h> using namespace std; int N; string S[100001]; int cnt[26]; int from[26]; int find(int ind, char C) { for (int i = 0; i < S[ind].length(); i++) if (S[ind][i] == C) return i; return -1; } void merge(int I, int J, char C) { int indI = find(I, C); int indJ = fi...
#include <bits/stdc++.h> using namespace std; int vis[400000], cur, path[500000], block[500000], x, y, n, m, q, k, s, t, seen[400010], ans[400010]; vector<int> g[4000]; map<pair<int, int>, vector<pair<int, int> > > M; void color(int x) { if (block[x]) return; block[x] = 1; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; set<int> in[100005]; pair<int, int> id[100005]; int bit[100005]; int lastNum[100005]; int color[100005]; void solve() { int n, m; scanf( %d %d , &n, &m); long long sum = 0; for (int i = 1; i <= n; ++i) { int num; scanf( %d , &num)...
#include <bits/stdc++.h> using namespace std; int main() { queue<int> left; queue<int> right; int n; cin >> n; char x; for (int i = 0; i < n; ++i) { cin >> x; if (x == D ) left.push(i); else right.push(i); } while (!left.empty() && !right.empty()) {...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a, b, cnt = 0, sum = 0, i, j, hand, flag = 0, c, n, m, k, t, res, maxy = 0, miny = 12345678910; cin >> n; string str; getline(cin, str); int len = str.size(); if (st...
#include <bits/stdc++.h> const long long INF = LLONG_MAX; const long long NINF = LLONG_MIN; const long long MAX = 1e6 + 5; const long long MOD = 1e9 + 7; using namespace std; inline long long gcd(long long a, long long b) { long long t; if (a < b) { t = a; a = b; b = t; } w...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int main() { long long t, w, b; cin >> t >> w >> b; long long cas = t / (w / gcd(w, b)) / b; long long exa = t - w / gcd(w, b) * b * cas; long long minimum = min(w, b); l...
#include <bits/stdc++.h> using namespace std; const int maxn(5e5 + 5); const long long inf(1e18); struct Qry { int l, r, id; }; int n, q, dfn[maxn], idx, ed[maxn]; long long mn[maxn << 2], tag[maxn << 2], ans[maxn]; vector<pair<int, int> > edge[maxn]; vector<Qry> qry[maxn]; void Update(int x, in...
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int M = 10000005; const int mo = 1000000007; int pri[M / 10], mn[M], id[M]; vector<int> e[N]; int n, T, Q, dfn[N], ed[N]; int fa[N][20], dep[N]; int qx[N], qy[N], qL[N], qv[N]; int t[N * 2], vis[N], A[N], ans[N]; vector<int>...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long int dp[100000 + 5] = {0}; void fun(long long int *A, long long int N) { dp[0] = 0; long long int a = 0; for (long long int i = 1; i <= 100000; ++i) { while (a < N and A[a] <= i) ++a; dp[i] = a; } } v...
#include <bits/stdc++.h> const int maxn = 105; int a[maxn]; inline int max(int a, int b) { return a > b ? a : b; } int main() { int n, ans = 0, temp; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); if (n < 3 || n % 2 == 0) puts( -1 ); else { for (int i = (n - 1)...
#include <bits/stdc++.h> using namespace std; bool a[200087]; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { int temp; cin >> temp; a[temp + 100000] = true; } int ans = 0; for (int i = 0; i <= 200000; i++) { if (i != 100000 && a[i] == true) { ...
#include <bits/stdc++.h> using namespace std; inline void Fail() { printf( 0 ); exit(0); } const int maxn = 100005; int n, l, r, mn, id, ans, from, to, cnt, clen, mxdep, mid; vector<pair<int, int> > edge[maxn]; pair<int, pair<int, int> > cur[maxn]; vector<int> beauty; int sz[maxn], u[maxn], v[...
#include <bits/stdc++.h> using namespace std; int n, l, r; int ans[1000000 + 5]; long long mmod = 2333, mod = 1e9 + 7; long long shash[1000000 + 5], base[1000000 + 5]; char s[1000000 + 5]; int main() { scanf( %d%s , &n, s + 1); base[0] = 1; for (int i = 1; i <= n; i++) { shash[i] = (shas...
#include <bits/stdc++.h> using namespace std; int mat[6][7] = { {0, 0, 0, 1, 1, 1, 1}, {0, 1, 1, 0, 0, 1, 1}, {1, 0, 1, 0, 1, 0, 1}, {0, 1, 1, 1, 1, 0, 0}, {1, 0, 1, 1, 0, 1, 0}, {1, 1, 0, 0, 1, 1, 0}, }; int aux[6][7]; int res[7]; bool solve() { int p, div; for (int i = 0; i < 6; ++i) {...
#include <bits/stdc++.h> using namespace std; const long long MAX = 150004; const long long mod = 998244353; struct edge { long long next, to; } h[MAX << 1]; long long head[MAX], cnt, cnt_dfsn; long long n, q, ans, inv; inline void add(long long x, long long y) { h[++cnt] = edge{head[x], y}; ...
#include <bits/stdc++.h> using namespace std; const int limit = 1000005; void die() { cout << NO << endl; exit(0); } void computereachable(int u, int code, vector<int> g[limit], int reachable[limit]) { if (reachable[u] & code) return; reachable[u] |= code; vector<...
#include <bits/stdc++.h> using namespace std; long long n, len, wmax, ans; vector<long long> vec[2]; inline void _read(long long &x) { long long f = 1; x = 0; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; else f = 1; c = getchar(); } wh...
#include <bits/stdc++.h> using namespace std; const int maxn = 3010; bool visit[maxn]; int n, m, ans, f[maxn]; vector<int> ve; vector<pair<int, int> > maps[maxn]; void first_dfs(const int u) { visit[u] = 1; for (int i = 0; i < ((int)(maps[u]).size()); ++i) { int v = maps[u][i].first; i...
#include <bits/stdc++.h> using namespace std; int check(int m, int k, string s) { int i; for (i = m + 1; i <= m + k && i < s.size(); i++) { if (s[i] == 1 ) return i; } return -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t;...
#include <bits/stdc++.h> using namespace std; int t; bool ans[50000][4]; int main() { cin >> t; for (int i = 0; i < t; i++) { int toys[4]; for (int j = 0; j < 4; j++) { cin >> toys[j]; } bool neg = (toys[0] + toys[1]) % 2 == 1; bool small = toys[1] >= 1 || toys[2] >...
#include <bits/stdc++.h> using namespace std; const int N = 12005, inf = 2e9; int n, q, a, b, k, m; double x[N], y[N], ans[N], p[N], t, s; int main() { scanf( %d%d%d%d , &n, &q, &a, &b); for (int i = 1; i <= n; i++) scanf( %lf , &p[i]); x[m] = 1, y[m] = 2.0 * (1 - p[1]), m++; x[m] = inf, y[m] ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using u32 = unsigned int; using db = double; using ld = long double; using pii = std::array<int, 2>; using pll = std::array<ll, 2>; const int INF = 0x3f3f3f3f; const long long INFll = 0x3f3f3f3f3f3f3f...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v[100005]; bool visit[100005]; int n; vector<int> ans; bool dfs(int i, int last) { visit[i] = true; bool flag = false; for (int j = 0; j < v[i].size(); j++) { if (!visit[v[i][j].first]) { if (v[i][j].second == 2)...
#include <bits/stdc++.h> using namespace std; long long int shuruHoJaa(long long int test) { while (test--) { long long int a, b, c, d; cin >> a >> b >> c >> d; long long int time = 0; if (b >= a) { cout << b; } else if (c <= d) { cout << -1; } else { ...
#include <bits/stdc++.h> using namespace std; char s[1010]; int main() { int n; scanf( %d , &n); scanf( %s , s); int a0 = 0; int a1 = 0; int b0 = 0; int b1 = 0; for (int i = 0; i < n; i++) { if (s[i] == 0 ) { if (i % 2) b0++; else a0++; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, pl = 4, otv = 1; cin >> n; if (n > 1) { for (long long i = 1; i < n; i++) { otv = otv + pl; pl += 4; } } else if (n == 1) { otv = 1; } cout << otv; }
#include <bits/stdc++.h> using namespace std; struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _; struct House { int height; int initial_position; }; int main() { int n; cin >> n; vector<House> houses; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; long long n, x, freq[100123], pairs = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> x; long long v[n]; for (long long i = 0; i < n; i++) { cin >> v[i]; freq[v[i]]++; } for (long long i = 0; i < 100123;...
#include <bits/stdc++.h> using namespace std; const int Buffer_Size = 1 << 10; char buffer[Buffer_Size], *ihead = buffer + Buffer_Size, *itail = ihead; char Next_Char() { if (ihead == itail) fread(buffer, 1, Buffer_Size, stdin), ihead = buffer; return *ihead++; } template <typename T> void read(T ...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[200020], b[200020]; int x, y, c, d; int n; int mx[200020]; int calc(pair<int, int> a[], int len, int val) { for (int i = 1; i <= len; ++i) { mx[i] = max(mx[i - 1], a[i].second); } int ret = 0; for (int i = len, j = 1; i >= ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 2; long long int i, j, n, m, s, ans = 0, cnt = 0; vector<pair<long long int, long long int> > nf; vector<long long int> graph[maxn]; bool foundd[maxn]; void dfs(long long int u, bool found[]) { if (!foundd[u]) ++ans; found[u] = t...
#include <bits/stdc++.h> using namespace std; void read(int &a) { a = 0; char c = getchar(); while (c < 0 || c > 9 ) { c = getchar(); } while (c >= 0 && c <= 9 ) { a = (a << 1) + (a << 3) + c - 0 ; c = getchar(); } } int Set(int n, int pos) { return n = n | (1LL ...
#include <bits/stdc++.h> using namespace std; int main() { long long k, sum = 0, i, j, n, cnt = 0; int a[20] = {0}, value; string s; cin >> k; cin >> s; for (i = 0; i < ((int)s.size()); ++i) { n = s[i] - 0 ; sum += n; a[n]++; } if (sum >= k) { cout << cnt << ...
#include <bits/stdc++.h> using namespace std; long long x, y; int main() { ios_base::sync_with_stdio(0); ; cin >> x >> y; if ((long long)sqrt(x * x + y * y + 0.5) == sqrt(x * x + y * y)) { cout << black << n ; return 0; } long long d = sqrt(x * x + y * y); if...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<vs> vvs; typedef vector<pii> vpii; typedef set<int> si; typede...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * f; } inline void write(long long...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 7; int vis1[MAXN], vis2[MAXN], dis[MAXN]; int st, ed, n, ans; queue<int> q; vector<int> G[MAXN]; void Bfs1() { for (; !q.empty();) q.pop(); q.push(1); vis1[1] = 1; for (; !q.empty();) { int u = q.front(); q.po...
#include <bits/stdc++.h> using namespace std; long long K[5], T[5]; int main() { queue<pair<long long, long long> > Q[5][2]; string ln; int n; getline(cin, ln); istringstream(ln) >> K[1] >> K[2] >> K[3]; getline(cin, ln); istringstream(ln) >> T[1] >> T[2] >> T[3]; getline(cin, ln);...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; inline int read() { char c = getchar(); int x = 0, f = 1; while ((c < 0 || c > 9 ) && c - - ) c = getchar(); if (c == - ) f = -1, c = getchar(); while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + c - 4...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double PI = acos(-1.); const int MXN = 200005; const int MOD = 1000000000; int a[MXN], n, m; long long fib[MXN]; long long prefib[MXN]; struct SEG { int l, r; long long lazy; long long g[2]; SEG() {} SEG(i...
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; const char vow[] = { a , e , i , o , u , y }; char str[maxn]; bool check(char ch) { for (int i = 0; i < 6; ++i) { if (ch == vow[i]) return true; } return false; } int main() { int n; while (~scanf( %d , &n)...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-11; void fast() { std::ios_base::sync_with_stdio(0); } vector<vector<int>> seq(1e5 + 9); int main() { int n, x; cin >> n; for (int i = 0; i < n; i++) { scanf( %d , &x); seq[x].push_back(...
#include <bits/stdc++.h> using namespace std; int main() { long int t; cin >> t; while (t--) { int n, m; cin >> n >> m; long int a[n + 1][m + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } long int b[n +...
#include <bits/stdc++.h> typedef long long LL; const double INF = 1e100; const int oo = ~0u >> 2; const double pi = acos(-1.0); const double EPS = 1e-8; const int MAXN = 100033; double a, b, c; double x11, x2; int main() { scanf( %lf%lf%lf , &a, &b, &c); x11 = sqrt(b * b - 4.0 * a * c); if...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); long long t; cin >> t; while (t--) { vector<long long> A(3); for (auto &a : A) cin >> a; sort((A).begin(), (A).end(), greater<long long>()); long long a, b, c; a = A[...
#include <bits/stdc++.h> using namespace std; int main() { { long long int r, n, c, m, i, j, count = 0, x, a, b, y, sum = 0; long long int mn = 1e18, mx = 0, ans = 0, k, ind; long long int br = 0, T, rz = 0; string s = ; cin >> n; long long int a1, a2, a3, b1, b2, b3; ...
#include <bits/stdc++.h> using namespace std; inline void open(const char *s) {} inline int rd() { static int x, f; x = 0; f = 1; char ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) f = -1; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - ...