func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int chkpower2(int x) { return (x && !(x & x - 1)); } void solve() { long long int n; cin >> n; long long int a[n], sum = 0; for (int i1 = 0; i1 < n; i1++) { cin >> a[i1]; sum += a[i1]; } sort(a, a + n); if (sum % (n - 1)) { ...
#include <bits/stdc++.h> using namespace std; bool vowel(char a) { a = toupper(a); if ((a == A ) || (a == E ) || (a == I ) || (a == O ) || (a == U )) return 1; return 0; } long long int n, m, q, a, b, c, sum = 0, cnt = 0; long long int arr[500055]; map<long long int, bool> mp; strin...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m; cin >> n >> m; ; int a[n + 1]; memset(a, 0, sizeof(a)); for (long long i = 0; i < m; i++) { long long t; cin >> t; ; for (long long j = t; j < n + 1; j++) { if (a[j] == 0) a[j] = t; ...
#include <bits/stdc++.h> using namespace std; int N, K; vector<int> tabs; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N >> K; tabs.resize(N); for (int i = 0; i < N; i++) cin >> tabs[i]; int most = 0; for (int b = 0; b < N; b++) { int sum = 0; for ...
#include <bits/stdc++.h> using namespace std; template <typename T> void setmax(T& x, T y) { x = max(x, y); } template <typename T> void setmin(T& x, T y) { x = min(x, y); } const double PI = acos(-1.0); const long long INF = 1e9 + 47; const long long LINF = INF * INF; mt19937 rng(chrono::...
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const int md = 1e9 + 7; const int N = 1e5 + 10; int n, m; int T; int k; long long p; long long q[N]; long long ar[N]; int now = -1; set<long long> se[N]; inline long long up(long long x, long long y) { long long re = x ...
#include <bits/stdc++.h> using namespace std; const int N = 5005; int n, m, w, o[N], K[N], P[N], C[N]; int vis[N]; vector<int> adj[N]; void bfs(int src) { for (int i = 0; i <= n; ++i) vis[i] = -1; queue<int> q, qw; q.push(src); qw.push(0); vis[src] = 0; while (!q.empty()) { int...
#include <bits/stdc++.h> using namespace std; int n; void solve_1() { if (n < 6) { printf( -1 n ); return; } puts( 1 2 ); puts( 2 3 ); puts( 2 4 ); puts( 4 5 ); puts( 4 6 ); for (int i = 7; i <= n; i++) { printf( 2 %d n , i); } } void solve_2() { for (...
#include <bits/stdc++.h> #define debug(x) cerr << #x << = << x << endl using namespace std; typedef long long LL; const int N = 400005; int a[N], b[N], n; vector<int> vec; int main() { int T; scanf( %d , &T); while(T--) { vec.clear(); scanf( %d , &n); for...
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << t ; return *this; } } dbg; template <class T> void setmax(T& a, T b) { if (a < b) a = b; } template <class T> void setmin(T& a, T b) { if...
#include <bits/stdc++.h> using namespace std; int head[2 * 200005], nex[2 * 200005], from[2 * 200005], to[2 * 200005], cnt, n; int sn[200005], num[200005]; long long d[200005], ans; void add(int u, int v) { nex[++cnt] = head[u]; from[cnt] = u; to[cnt] = v; head[u] = cnt; nex[++cnt] = head[...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma comment(linker, /STACK:100000000 ) const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 5e3 + 5; const double eps = 1e-9; using namespace std; bool vis[MAXN]; int a[MAXN * 20], L[MAXN], R[MAXN], mx...
#include <bits/stdc++.h> using namespace std; int A[200005], B[200005], N; int O[200005][5]; void ucitaj() { scanf( %d , &N); if (N == 5) { printf( 1 5 3 4 2 n ); exit(0); } int i, j; for (i = 1; i <= 2 * N; i++) { scanf( %d%d , A + i, B + i); if (O[A[i]][1] == 0) ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int num = sqrt(n); if (num * num == n) { for (int i = n - num + 1; i >= 1; i -= num) { for (int j = 0; j < num; j++) { printf( %d , i + j); } } printf( n ); return 0...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first; } for (int i = 0; i < n; i++) { cin >> a[i]...
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); int k; int a[n]; for (k = 0; k < n; k++) scanf( %d , &a[k]); int p = n - 2; int i, j; for (i = 0; i < p; i++) { for (j = i + 2; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, performance; long long cost = 0; long long k; cin >> n >> k; int x[n], c[n]; for (int& e : x) cin >> e; cin >> performance; for (int& e : c) cin >> e; priority_queue<int, vector<int>, greater<int>> rem; int i =...
#include <bits/stdc++.h> using namespace std; struct dame { int b, i, r; dame() {} dame(int b_, int i_, int r_) : b(b_), i(i_), r(r_) {} }; bool greater_compare(dame A, dame B) { return A.b > B.b || A.b == B.b && A.i < B.i || A.b == B.b && A.i == B.i && A.r < B.r; } bool by_i(dame...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cout << INTERCAL ; return 0; }
#include <bits/stdc++.h> using namespace std; const long double PI = 3.1415926535897932384626433832795; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << ( << p.first << , << p.second << ) ; return out; } template <typename T> ostream& operator...
#include <bits/stdc++.h> using namespace std; /*DEBUGGER*/ #define deb(x) cout << #x << = << x << endl #define deb2(x, y) cout << #x << = << x << , << #y << = << y << endl typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typede...
#include <bits/stdc++.h> long long int trie[10000007][2] = {0}; long long int bin[40] = {0}, x = 0; long long int a[100005] = {0}, prefix[100005] = {0}, suffix[100005] = {0}; void tobinary(long long int x) { int cnt = 0; memset(bin, 0, sizeof(bin)); while (x > 0) { bin[cnt++] = (x % 2); ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native ) static int a[100001], n, m, l, r, x, cnt; static bool type; inline static int read() { register int x = 0; static...
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int> > v; long long dp[2][5001][51][51]; const long long oo = 1e16; int main() { cin >> n; v.resize(n); for (auto &x : v) cin >> x.first; int total = 0; for (auto &x : v) { cin >> x.second; total += x.secon...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int o = 0, t = 0, to = 0; int n = s.length(); for (int i = 0; i < n; i++) { if (s.substr(i, 3) == one ) { o++; i++; } else if (...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; const int N = 50 + 10, M = 1e6 + 10, inf = 1e9 + 10; const long long INF = 5e17 + 10, mod = 1e9 + 7; int a[N][N], cnt[N][N][N][N]; int s[N][N], sum[N][N][N][N]; int main() { int n, m, q; scanf( %d...
#include <bits/stdc++.h> using namespace std; char t[200002]; struct node { int nt[5][5]; }; node st[4 * 200000 + 2]; node merge(node a, node b) { if (a.nt[0][0] == -1) return b; if (b.nt[0][0] == -1) return a; node ans; for (int i = 0; i <= 4; i++) for (int j = 0; j <= 4; j++) ans...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k, m, t; cin >> n >> k >> m >> t; while (t--) { int x, y; cin >> x >> y; if (x == 1) { if (y <= k) k++; n++; } else { if (y...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; int expo(int x, int y) { int res = 1; x = x % M; while (y > 0) { if (y & 1) res = (1ll * res * x) % M; y = y >> 1; x = (1ll * x * x...
#include <bits/stdc++.h> using namespace std; constexpr int MOD = 998244353; int main() { int R, C; cin >> R >> C; int X = 1; while (R--) X = (2 * X) % MOD; while (C--) X = (2 * X) % MOD; cout << X << endl; }
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<pair<int, int>>> g(n); vector<int> goes(m, -1); vector<int> offset(m); vector<int> from(m); vector<int> to(m); for (int i = 0; i < m; ++i...
#include <bits/stdc++.h> using namespace std; const long long inf = 3 * 1e18; long long mi[5], ma[5], low[5], high[5]; long long resx, resy, resz; long long div2(long long x, long long y) { if (x > 0 && y > 0 || x < 0 && y < 0) { long long f = 0; if (x % 2 && y % 2) f = 1; if (x > 0 && y...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const long long LINF = (long long)1e18 + 23111992; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long...
#include <bits/stdc++.h> using namespace std; const double E = 1e-10; const int inf = (int)1e9; const int maxn = 1010; int LIM = 60 * 12; int a[maxn]; int b[maxn], bc = 0; int t[maxn]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , a + i); sort(a, a + n); ...
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #define endl n #define ll long long #define sz(s) (int)(s.size()) #define INF 0x3f3f3f3f3f3f3f3fLL #define all(v) v.begin(),v.end() #define watch(x) cout<<(#x)<< = <<x<<endl const int dr[] { -1, -1, ...
#include <bits/stdc++.h> using namespace std; long n, k; long ans[1000010]; int main() { cin >> n >> k; if ((k > n) || ((k <= n) && (k == 1) && (n != 1))) { cout << -1 << endl; return 0; } if ((n == 1) && (k == 1)) { cout << a << endl; return 0; } if (!(n & 1)...
#include <bits/stdc++.h> using namespace std; int x[110], y[110], n, epsilon, k; double dist[110], p[110], mem[110][110]; double solve(int idx, int k) { if (k == 0) return 1; if (idx == n) return 0; double& res = mem[idx][k]; if (res != -1) return res; res = p[idx] * solve(idx + 1, k - 1); ...
#include <bits/stdc++.h> const long long int MAX = 1e12; using namespace std; const int alpha = 26; void solve() { int n; cin >> n; vector<int> arr(n); for (auto &it : arr) cin >> it; for (int i = 0; i < n; i++) { while (arr[i] % 2 == 0) arr[i] /= 2; while (arr[i] % 3 == 0) arr[i...
#include <bits/stdc++.h> using namespace std; vector<string> ans; string f = 1 ; bool sort2(string &a, string &b) { if (a.size() == b.size()) { return a < b; } return a.size() < b.size(); } void calc(string s) { if (s.size() >= 11) { return; } ans.push_back(s); s += ...
#include <bits/stdc++.h> int n, cnt; char ch[100005], tmp; int main() { scanf( %d , &n); scanf( %s , ch + 1); for (int i = 1; i <= n; i++) if (ch[i] != tmp) { if (tmp != 0) { if ((tmp == o || tmp == e ) && cnt == 2) printf( %c%c , tmp, tmp); else { ...
#include <bits/stdc++.h> using namespace std; int main() { int a[100005], i, j, m, n, ans = 0, pos = 1; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 3; i <= n;) { if (a[i] == a[i - 1] + a[i - 2]) { while (a[i] == a[i - 1] + a[i - 2] && i <= n) { i++; } ...
#include <bits/stdc++.h> using namespace std; const int ms = 2005, me = 4005; int adj[ms], to[me], ant[me], z = 0, idx[ms], path[ms], bridge[me], ind, vis[ms]; int s[ms], l[ms], ans; bool dfs(int v, int end) { if (vis[v]) return false; else if (v == end) ret...
#include <bits/stdc++.h> using namespace std; struct node { int l, r, mx, pre, suf; }; vector<node> T; vector<pair<int, int> > ht; int n, m, a[100055], root[100055], first, second, z; int init(int l, int r) { int ind = T.size(); if (l == r) { T.push_back({-1, -1, 1, 1, 1}); return ...
#include <bits/stdc++.h> using namespace std; int n, q, x, y, xx, yy; long long read() { long long x = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) ch = getchar(); while (ch >= 0 && ch <= 9 ) { x = (x << 3) + (x << 1) + ch - 0 ; ch = getchar(); } return x; } str...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t; cin >> t; for (int i = 0; i < t; i++) { long long a, b; long long uns = 0; cin >> a >> b; uns = abs(a - b) / 5; if (abs(a - b) % 5 == 1) uns++; ...
#include <bits/stdc++.h> using namespace std; int v[1000005]; long long int l[1000005]; long long int r[1000005]; int main(void) { int n, m; int sum; scanf( %d %d , &n, &m); for (int i = 0; i < n; i++) { scanf( %d , &v[i]); } l[0] = 0; sum = 0; for (int i = 1; i < n; i+...
#include <bits/stdc++.h> using namespace std; long long g[222222][2]; int f[222222], p[222222][2], n, i; long long dfs(int x, int k, int z) { if (x < 1 || x > n) return 0; if (g[x][z] == -1 || p[x][z] == k) return -1; if (p[x][z]) return g[x][z]; long long ans = 0; p[x][z] = k; if (z) ...
#include <bits/stdc++.h> int a[100001], p[100001], N, Q; int T[2100001], ls[2100001], rs[2100001], n, root[100001]; int end[100001], steps[100001]; int build(int l, int r) { int p = ++n; T[p] = r - l + 1; if (l < r) { int m = l + r >> 1; ls[p] = build(l, m); rs[p] = build(m + 1, r)...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, x, y, x1, y1; cin >> a >> b >> c >> d; x = (3 * a) / 10; x1 = (a - (a / 250) * c); int m = max(x, x1); y = (3 * b) / 10; y1 = (b - (b / 250) * d); int m1 = max(y, y1); if (m < m1) cout << Vasya << ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 50; const int MOD = 1e9 + 9; int n, k, a, b, c, d, m, L, R, tot = 1; pair<int, int> cities[MAXN]; struct TreeNode { int x, l, r, lson, rson; pair<int, int> v; } tree[MAXN]; int newNode(int &x) { return x = ++tot; } pair<int, ...
#include <bits/stdc++.h> int main() { int i, n; scanf( %d , &n); for (i = 0; i < n; i++) { long long int x; long long int k, y; scanf( %I64d %I64d , &k, &x); y = x + 9 * (k - 1); printf( %I64d , y); printf( n ); } }
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int i = 0; i < q; ++i) { int n; cin >> n; set<int> st; for (int j = 0; j < n; ++j) { int x; cin >> x; st.insert(x); } int ans = 0; int mx = *st.rbegin(); ...
#include <bits/stdc++.h> using namespace std; int n, m, a, b, w, start = 0, k; long long int MAX = 1e18; vector<vector<int> > wait(100005); vector<vector<pair<int, int> > > adj(100005); void binarySearch(int v, long long int& d) { if (v == n - 1 or wait[v].size() == 0) { return; } int low ...
#include <bits/stdc++.h> using namespace std; bool *Seive(long long n, bool *p) { memset(p, 1, sizeof(p)); long long i, j; for (i = 2; i <= n; i++) { if (p[i] == 1) for (j = i * i; j <= n; j += i) { p[j] = 0; } } p[1] = 0; return p; } long long gcd(long lo...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e+7; const int N = 1e5 + 5; long long pwr(long long x, long long y); long long a[N]; vector<long long> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, k; cin >> n >> m >> k; for (int i...
#include <bits/stdc++.h> using namespace std; long long b[60005], c[60005]; signed main() { long long a; scanf( %lld , &a); long long MIN = LLONG_MAX / 3, MAX = 0; for (long long d = 0; d < a; d++) { scanf( %lld , &b[d]); MIN = min(MIN, b[d]); MAX = max(MAX, b[d]); } for ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[101], b[101], c[101], i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) cin >> b[i]; for (i = 0; i < n; i++) if (a[i] <= b[i]) c[i] = 1; int bs = 0, rc = 0, sett; for (i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<long long> a; vector<long long> b; long long sum; if (k + 1 < n) { sum = k + 1; b.push_back(sum); } else { for (long long i = 0; i < n; i++) { cout << n << ; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { scanf( %lld , &a[i]); } int m; cin >> m; long long int b[m]; for (int i = 0; i < m; i++) { scanf( %lld , &b[i]); } int i = 0, j = 0, a...
#include <bits/stdc++.h> using namespace std; int main() { int c[100], w[2000], q[2000]; int b[100]; for (int i = 0; i <= 20; i++) { q[i] = 0; b[i] = 0; c[i] = 0; } for (int i = 5; i <= 9; i++) { cin >> c[i]; } int n = 0; string a; cin >> n; for (int i...
#include <bits/stdc++.h> using namespace std; int X[1000000], F[100000], i, j, x, y, k, N = 1000000; int main() { int n; cin >> n; for (i = 1; i < N; i++) X[i] = 1; for (i = 2; i < N; i++) if (X[i] == 1) { j = i + i; while (j < N) { X[j] = 0; j += i; ...
#include <bits/stdc++.h> int main() { int n, h, a, b, t, f; int t1, f1, t2, f2; int sum; while (~scanf( %d%d%d%d%d , &n, &h, &a, &b, &t)) { while (t--) { sum = 0; scanf( %d%d%d%d , &t1, &f1, &t2, &f2); if (t1 > t2) { f = t1; t1 = t2; t2 = f; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1, LOGN = 20; vector<pair<int, long long> > adj[N]; long long a[N], dis[N]; int lca[N][LOGN]; int upd[N]; void dfs1(int u, long long d = 0, int par = 0) { dis[u] = d; lca[u][0] = par; for (int i = 1; i < LOGN; i++) lca[u][i] = l...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; const int inf = INT_MAX; const long long inff = 1e18; const long long mod = 1e9 + 7; int n, m, x, y; int a[maxn], p[maxn]; int b[maxn]; int dp1[maxn], dp2[maxn]; vector<int> v; int32_t main() { ios::sync_with_stdio(0); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e6 + 10; const long long int md = 1e9 + 7; long long int n, fac[MAXN], invf[MAXN]; inline long long int inv(long long int a, long long int b = 1e9 + 5ll) { long long int k = 1ll; while (b) { if (b & 1) k = (k * a) % md; a = (a...
#include <bits/stdc++.h> using namespace std; bool seen[100005], x[100005]; vector<int> g[100005], ans; inline void add(int u) { ans.push_back(u + 1), x[u] ^= 1; } void dfs(int u, int p) { seen[u] = true; add(u); for (auto v : g[u]) if (v != p && !seen[v]) dfs(v, u), add(u); if (x[u]) { ...
#include <bits/stdc++.h> using namespace std; bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { int maxz, tempbuff, tempbuff2; cin >> maxz; vector<pair<int, int>> z; for (int i = 0; i < maxz; i++) { cin >> tempbuff >> tempbuff2; z.push_back(m...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; template <typename T> T sqr(T a) { return a * a; } template <typename T> int sign(T a) { if (a == 0) return 0; return (a > 0 ? 1 : -1); } template <typename T1, typename T2> T2 sum_mod(T1 x, T2 MOD) { if (x <...
#include <bits/stdc++.h> /* ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) solve(); */ using namespace std; typedef long long ll; typedef long double ld; int magic(vector<int> &a, int del){ auto it = lower_bound(a.begin(), a.end(), del); i...
#include <bits/stdc++.h> using namespace std; void solve() { long long int i, j, n, m, k; cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } cin >> m; long long int b[m]; for (i = 0; i < m; i++) { cin >> b[i]; } sort(a, a + n); sort(b, b + ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<long long> a(n); for (long long& v : a) cin >> v; vector<long long> p(n); for (long long& v : p) cin >> v; int m; cin >> m; vector<long long> b(m); ...
#include <bits/stdc++.h> double Pow(double x, int n) { double ans = 1; for (; n; n >>= 1) { if (n & 1) ans *= x; x *= x; } return ans; } int main() { int n, m; double ans = 0; scanf( %d%d , &m, &n); for (int i = 1; i < m; i++) ans += Pow((double)i / (double)m, n); a...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, m, n, c; cin >> n >> c; int ar[n]; for (i = 0; i < n; i++) { cin >> ar[i]; } long long int l = 1, h = n, mid; long long int co = 0, res1 = 0, res2 = 0; while (l <= h) { co = 0; mid = (l +...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N = 19; int g[N]; unsigned long long dp[1 << N][N + 1]; unsigned long long ok[1 << N]; unsigned long long slen[N + 1][1 << N]; unsigned long long cur[N + 1][1 << N]; un...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-5; struct line { double x, y, vx, vy; void read() { double t1, t2; cin >> t1 >> x >> y >> t2 >> vx >> vy; vx = (vx - x) / (t2 - t1); vy = (vy - y) / (t2 - t1); x -= vx * t1; y -= vy * t1; } } L[10...
#include <bits/stdc++.h> using namespace std; const int A = 26; const int maxn = 5e3 + 5; const long long mod = 1e9 + 7; char s[maxn]; int n; int nxt[maxn][A]; long long fat[maxn], inv[maxn]; long long dp[maxn][maxn]; string t; void fillNxtTable() { t = s; t = $ + t; int last[A]; ...
#include <bits/stdc++.h> using namespace std; int nbElems, nbAuto; bitset<2000> autos[2000]; bitset<2000> inverse[2000]; int main() { scanf( %d%d , &nbElems, &nbAuto); vector<pair<int, int> > paires; for (int iPaire = 0; iPaire < nbAuto; iPaire++) { int pos, elem; scanf( %d%d , &pos, &...
#include <bits/stdc++.h> using namespace std; long long n, m, a[100005], tot = 0, tmp; int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); cin >> n >> m; for (long long i = 1; i <= m; i++) { cin >> a[i]; if (i + a[i] - 1 > n) { cout << -1 << endl; ...
#include <bits/stdc++.h> using namespace std; long long n, mod, s, s1, s2; inline long long get(long long id, long long rem, long long l, long long r, long long b, long long e, long long x) { if (e < l || r < b) { return 0; } if (b <= l && r <= e) { if (x < rem) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; int p = 0; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; x--; if (x % 2) p++; if (p % 2) cout << 1 << endl; else cout << 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> m >> n; map<int, vector<pair<int, int>>> matrix; vector<int> cnt(n, m), mag(m, n); int cnt2 = m; for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { int a; cin >> a; matrix[a]....
#include <bits/stdc++.h> using namespace std; int up_div(int a, int b) { return a / b + (a % b != 0); } int down_div(int a, int b) { return a / b; } int main() { int a, b; cin >> a >> b; int res = 0; for (int k = 1; k <= a + b; ++k) { int d = (a + b) / k; int min_k = k; int max...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = 10e17 + 9; const long double p = acos(-1); int n, x; vector<int> v[200009]; int dis1[200009]; int dis2[200009]; void dfs1(int node, int p, int k) { dis1[node] = k; for (int i = 0; i < v[node]....
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; long long m, n, t, a1, b1, cnta, cntb, b[maxn]; struct point { long long x, y; point(long long x = 0, long long y = 0) : x(x), y(y) {} bool operator<(const point& p) const { return x < p.x || (x == p.x && y < p.y); } ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } const int N = 1e3 + 10; const double eps = 1e-5; int n; struct Tarr { long long tarr[N][N]; Tarr() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { ...
#include <bits/stdc++.h> using namespace std; int n, m, hd, el; char s[1000]; struct E { char tag; int p[26]; } e[1000000]; void ins() { int i, j, k, l; for (i = 0, l = hd; s[i]; i++) { if (!e[l].p[s[i] - a ]) e[l].p[s[i] - a ] = el++; l = e[l].p[s[i] - a ]; } } void d...
#include <bits/stdc++.h> using namespace std; int tree[10000][2]; int lights; void mark(int node, int l) { int p = node / 2; if (p == 0) return; tree[p][node % 2] = min(tree[p][node % 2], lights - l); mark(p, l); } int cont[10000]; int main() { cin.tie(0); ios_base::sync_with_stdio...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n), ans; for (int i = 0; i < n; i++) { cin >> a[i]; } auto cyc = [&...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 7; vector<long long> v[N]; long long vis[N], prt[N], bip[N], cs, ce; void dfs(long long ver, long long par) { bip[ver] = (!bip[par]); vis[ver] = 1; prt[ver] = par; for (auto it : v[ver]) { if (vis[it] == 2 || it == p...
#include <bits/stdc++.h> using namespace std; int main() { int n, l; cin >> n >> l; double a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(&a[0], &a[n]); float x = a[0] - 0; float y = l - a[n - 1]; for (int i = 0; i < n - 1; i++) a[i] = (a[i + 1] - a[i]) / 2; if (x > y) ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 2; const int mod = 100003; const int INF = 0x3f3f3f; int n, m, x, y; int vis[N]; struct node { int x, r, i, v; } tar[N]; bool cmp1(node &x, node &y) { return x.x < y.x; } bool cmp2(node &x, node &y) { return x.i < y.i; } int fin...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s[1] == 1 ) { if (s[0] == a || s[0] == h ) { cout << 3 << endl; } else { cout << 5 << endl; } } else if (s[1] == 8 ) { if (s[0] == a || s[0] == h ) { cout <<...
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point() {} Point(double a, double b) { x = a, y = b; } }; const double eps = 1e-10; Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); } Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y ...
#include <bits/stdc++.h> using namespace std; struct Node { int l, r, b, No; bool operator<(const Node &t) const { if (b != t.b) return b < t.b; return r < t.r; } }; const int N = 200005; const int M = 1000005; int n, Q; int seq[N]; Node q[N]; int cnt[M]; long long ans[N]; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int l = s.length(); vector<int> v(26, 0); for (int i = 0; i < l; i++) { if (s[i] == s[i + 1]) { i++; } else { v[s[i] - a ] = 1;...
#include <bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {...
#include <bits/stdc++.h> using namespace std; long long n, k; long long calc(long long n, long long k) { map<long long, long long> l, r; l.clear(); r.clear(); long long cnt[2]; cnt[0] = cnt[1] = 0; if (k == 1) return n / 2; k--; l[n / 2] = 1; r[n / 2 + (n % 2)] = 1; while (...
#include <bits/stdc++.h> using namespace std; int ed; int l[360360 + 1], qd[8405400 + 1], qn[8405400 + 1]; int q[360360 + 1]; void bd(int first, int second) { qd[++ed] = second; qn[ed] = l[first]; l[first] = ed; } inline void bfs(int st, long long v[]) { for (int i = (0); i < (360360 + 1);...
#include <bits/stdc++.h> using namespace std; int const N = 250000, B = 18; vector<int> tr1[N + 1], tr2[N + 1]; int n, dp[N + 1], pa[N + 1][B], gr[N + 1]; int P(int v) { return gr[v] ? gr[v] = P(gr[v]) : v; } void pl(int v = 1, int p = 0) { dp[v] = dp[p] + 1; pa[v][0] = p; int k = 1, z; whil...