func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 512345, lgN = 20, rootN = 1123; const double eps = 1e-11; vector<int> cities; int root = -1; int dp[N]; bool visited[N], rem[N]; vector<int> adj[N]; void dfsTree(int v) { int sum = 0; auto it = lower_bound(cities.begin(), cities.end()...
#include <bits/stdc++.h> using namespace std; int f[200010], fi[200010]; const int MOD = 1e9 + 7; int add(long long a, long long b) { return (a + b) % MOD; } int mul(long long a, long long b) { return (a * b) % MOD; } int fp(long long a, int b) { if (b == 0) return 1; int tp = fp(a, b >> 1); tp ...
#include <bits/stdc++.h> using namespace std; vector<string> grid; int main() { int n; cin >> n; string line = ; for (int i = 0; i < n; i++) { cin >> line; grid.push_back(line); } bool rowblock = false; bool colblock = false; for (int i = 0; i < n; i++) { bool f...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; const long long MOD = 1e9 + 7; long long n, a[55]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (a...
#include <bits/stdc++.h> using namespace std; int n; int a[1005]; int main() { cin >> n; int x; int ans = 0; if (n == 1) { cin >> x; if (x) cout << YES << endl; else cout << NO << endl; return 0; } for (int i = 0; i < n; i++) { cin >> x; ...
#include <bits/stdc++.h> using namespace std; const double ex = 1e-6; double pow(double x, int n) { double ret = 1; while (n) { if (n % 2) ret *= x; n >>= 1; x *= x; } return ret; } int main() { double n; int m; while (scanf( %lf %d , &n, &m) != EOF) { doubl...
#include <bits/stdc++.h> using namespace std; struct coord { int c, f, v; }; coord var, pos; int n, m, i, x, cont, h; int pasos[1001][1001]; bool ya[1001][1001], e; char mapa[1001][1001]; queue<coord> cola; stack<coord> pila; int main() { scanf( %d%d , &n, &m); for (i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, t; while (cin >> n >> t) { int x, y; vector<pair<int, int> > a; vector<pair<int, int> > v; for (int i = 0; i < n; i++) { cin >> x >> y; a.push_back(make_pair(x, y)); } for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; struct edge { int y, stat; }; struct query { int curNode; int curLength; int curGood; }; vector<edge> vec[100005]; pair<long long, long long> best[100005]; long long path[100005], pathStatus[100005]; int n, m; queue<query> q; set<pair<i...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, m; cin >> n >> m; long long int n1, m1; cin >> n1 >> m1; long long int a[n], b[m]; for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = 0; i < m; i++) cin >> b[i]; if (a[n1 - 1] < b[m -...
#include <bits/stdc++.h> const int INF_INT = 0x3f3f3f3f; const long long INF_LL = 0x7f7f7f7f; const int MOD = 1e9 + 7; const double eps = 1e-10; const double pi = acos(-1); using namespace std; vector<int> g[100010]; int n; double ans; void dfs(int fa, int u, int cnt) { ans += 1.0 / cnt; for...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MAXN = 100100; inline void add(int &a, int b) { a += b; if (a >= MOD) { a -= MOD; } } inline int mul(int a, int b) { return (a * 1LL * b) % MOD; } inline int fastPow(int a, int b) { int r = 1; w...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); long long n, R = 0, L = 0; cin >> n; long long l[n], r[n]; for (int x = 0; x < n; x++) { cin >> l[x] >> r[x]; L += l[x]; R += r[x]; } int val = abs(R - L); int ans = 0; for (int ...
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; ...
#include <bits/stdc++.h> using namespace std; const int B = 27397, MOD = 1e9 + 7; const int B1 = 33941, MOD1 = 1e9 + 9; int n, q; struct Node { int nxt[11]; long long sum[11]; Node() { for (int i = 0; i < 10; ++i) nxt[i] = i; memset(sum, 0, sizeof sum); } }; class Tournament { ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > adj[100100]; long long under[100100]; long long n; long long dfs(long long u, long long p) { under[u] = 0; long long next, edge; for (long long i = 0; i < adj[u].size(); i++) { next = adj[u][i].first; edg...
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> answer[404]; set<pair<int, int> > S; set<pair<int, int> >::iterator it, ii; bool check(pair<int, int> c) { ii = S.lower_bound(make_pair(c.first, 0)); if (ii != S.end()) { if (c.first + c.second > (*ii).first) return false; ...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g, rv; int ds[3030][3030]; vector<int> md[3030]; int rd[3030][3030]; vector<int> mr[3030]; int main() { int n, m; scanf( %d %d , &n, &m); g.assign(n, vector<int>()); rv.assign(n, vector<int>()); while (m--) { int ...
#include <bits/stdc++.h> using namespace std; const int N = 1000006; const long long int M = 935172938408392767LL; vector<long long int> kub[N]; long long int kra[N]; long long int maska[N]; int deg[N]; int main() { int n, m, a, b; long long int wynik = 0; scanf( %d%d , &n, &m); kra[1] =...
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)4e18 + 7; inline void minimize(long long &x, const long long &y) { if (x > y) x = y; } struct help { int x, s, r; help() { x = s = r = 0; } void input(void) { x = s = r = 0; int k; scanf( %d%d%d , ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n; bool init[MAXN], goal[MAXN]; vector<int> e[MAXN]; bool mark[MAXN]; bool even = true; bool eo[2]; queue<int> ans; void dfs(int v) { if (mark[v]) return; mark[v] = true; bool change = false; if ((init[v] !=...
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); using ll = long long int; using ld = long double; using pi = pair<int, int>; const double PI = acos(-1.0); const double eps = 1e-9; const ll mod = 1e9 + 7; const int inf = 1e7; const...
#include <bits/stdc++.h> using namespace std; inline int Find(string x) { if (x == rock ) return 1; if (x == scissors ) return 2; if (x == paper ) return 3; } int main() { string a, b, c; int sa, sb, sc; cin >> a >> b >> c; sa = Find(a), sb = Find(b), sc = Find(c); if (sa == 1...
#include <bits/stdc++.h> using namespace std; long long head[100005]; long long memory[100005]; int n, m; bool possible(long long t) { int curr = 1; for (int i = 1; i <= n; i++) { long long headloc = head[i]; if (headloc <= memory[curr]) { headloc += t; while (headloc >= me...
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; const int base = 31337; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const int logo = 20; const int off = 1 << logo; const int treesiz = off << 1; int n, m, k; vector<int> graph[maxn]; int a[maxn], ss[maxn], cs[maxn]; b...
#include <bits/stdc++.h> using namespace std; const int N = 300005; struct Point { int x, y; Point(int _x = 0, int _y = 0) { x = _x; y = _y; } Point operator-(const Point &R) const { return Point(x - R.x, y - R.y); } long long operator^(const Point &R) const { return (long lo...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MAXN = 1e6 + 7; const double EPS = 1e-6; const int M = 15; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); vector<vector<int> > dp(M + 1); vector<vector<pair<int, int>...
# include <algorithm> # include <iostream> # include <numeric> # include <vector> # include <set> using namespace std; int main() { int n, a, b; while (cin >> n >> a >> b) { string s; cin >> s; set<char> chars_set; for (char c : s) { chars_set.insert(c); }...
#include <bits/stdc++.h> const int maxn = 10010; const int mod = 1000000007; int n; char ch[4][maxn]; int f[maxn][8][2]; int obs[maxn]; int ot, vt; void part0() { memset(obs, 0, sizeof(obs)); for (int j = 1; j <= n; j++) for (int i = 3; i >= 1; i--) obs[j] = (obs[j] << 1) + ((ch[i]...
#include <bits/stdc++.h> using namespace std; int bs(int arr[], int n, int target) { int left = 0, mid, right = n - 1; while (left <= right) { mid = left + (right - left) / 2; if (arr[mid] < target) left = mid + 1; else right = mid - 1; } return left + 1; } int ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int N = 5e5; int main() { long long n, a, b, c, t; cin >> n >> a >> b >> c >> t; long long arr[n + 1]; for (long long i = 1; i <= n; i++) { cin >> arr[i]; } long long s = n * a; if (b >= c) { ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int main() { int n, d, h; cin >> n >> d >> h; if (h * 2 < d || h > n || d > n || h > d || n < d + 1 || (h == 1 && d == 1 && (n != 2))) cout << -1; else { if (h == 1) { for (int i = 2; i <= n; i++) cout <...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse2 ) using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << : << arg1 << n ; } template <typename Arg1, typename... Args> vo...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, res; cin >> n; while (1) { if (n % 3 != 0) { res = (n / 3) + 1; break; } n = n / 3; } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; int n, arr[206]; char str[206]; inline bool check1() { for (int i = 0; i < (n >> 1); ++i) { if (arr[i] >= arr[i + (n >> 1)]) return 0; } return 1; } inline bool check2() { for (int i = 0; i < (n >> 1); ++i) { if (arr[i] <= arr[i + (n ...
#include <bits/stdc++.h> using namespace std; long long int n, k; void inp() { cin >> n >> k; return; } void solve() { set<long long int> second; for (long long int i = 1; i <= k; i++) if (second.count(n % i)) return void(cout << No n ); else second.insert(n % i); ...
#include <bits/stdc++.h> const int MAXN = 5; const double eps = 1e-4; struct node { double x, y; node(double x = 0, double y = 0) : x(x), y(y) {} inline bool operator<(const node &rhs) const { if (fabs(x - rhs.x) >= eps) return x < rhs.x; if (fabs(y - rhs.y) >= eps) return y < rhs.y; ...
#include <bits/stdc++.h> const int maxn = 2e5 + 5; using namespace std; int a[maxn * 2]; int main() { int n; cin >> n; int flag = 0; for (int t = 0; t < n; t++) { scanf( %d , &a[t]); if (a[t] == 1) { flag = 1; } } for (int t = n; t < 2 * n; t++) { a[t] = a...
#include <bits/stdc++.h> using namespace std; vector<int> computer(100, 0); int n, q, free_computers; long s; int t, k, d; void question() { cin >> t >> k >> d; free_computers = 0; for (int j = 0; j < n && free_computers < k; j++) { if (computer[j] <= t) free_computers++; } if (k >...
#include <bits/stdc++.h> using namespace std; int Int() { int x; cin >> x; return x; } double din() { double x; cin >> x; return x; } string Str() { string x; getline(cin, x); return x; } char Ch() { char x; cin >> x; return x; } int main() { int h...
#include <bits/stdc++.h> using namespace std; int a[200008], sign[200008]; int b[200008]; int main() { int n; scanf( %d , &n); int t; memset(a, 0, sizeof(a)); memset(sign, 0, sizeof(sign)); for (int i = 0; i < n; i++) { scanf( %d , &t); int k = t; int time = 0; b[...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << n ; } 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; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } class Graph { public: ...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> arr; int n, a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; arr.push_back(a); } sort(arr.begin(), arr.end()); cout << arr[n - 1] << endl; arr.clear(); return 0; }
#include <bits/stdc++.h> int len, p; char s[111111], buf[111111]; void add(char ch) { buf[len++] = ch; } void out() { printf( < ); for (int i = 0; i < len; i++) printf( %c , buf[i]); printf( > n ); len = 0; } int main() { gets(s); len = p = 0; for (p = 0; s[p]; p++) { if (s...
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3, s4; long long int n; cin >> s1 >> s2; cin >> n; for (long long int i = 0; i < n; i++) { cout << s1 << << s2 << endl; cin >> s3 >> s4; if (s1.compare(s3) == 0) { s1 = s4; } else { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100; char s[maxn]; int l; long long make(int x, long long u) { int z = l - x; long long k = 1, u1 = 0; for (int i = 0; i < z; i++) { u1 += (s[l - 1 - i] - 0 ) * k; k *= 10; } u1 += u / k * k; if (u1 <= u) u1 +=...
#include <bits/stdc++.h> using namespace std; int n, m, q, g[13][13], lca[13][13]; long long dp[1 << 13][13]; long long f(int s, int root) { s &= ~(1 << root); if (s == 0) return 1; if (dp[s][root] != -1) return dp[s][root]; long long res = 0; int must = 0; for (int i = (0); i < (n); i++...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long MAX = 1e17; string s1, s2, v; int dp[101][101][101], pre[101][101][101]; void prt(int a, int b, int c) { if (a == 0 or b == 0) return; int x = pre[a][b][c]; if (x == 0) { prt(a - 1, b - 1, c); } else if (x...
#include <bits/stdc++.h> #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) using namespace std; inline bool isDigit(char c) { return 0 <= c && c <= 9 ; } template <class T> inline T sqr(T x) { return x * x; } template <class T> inline bool isSquare(T x) { int y = sqrt(x + 0.5); ...
#include <bits/stdc++.h> using namespace std; const int N = 510, mod = 1LL * 1000 * 1000 * 1000 + 7; int dp[N][N], n, b[N], num[N][N]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> b[i]; for (int j = 1; j <= n; j++) for (int...
#include <bits/stdc++.h> using namespace std; int mini; map<char, int> M; set<int> s; int n; void rec(int ind, vector<int> c, vector<int> d) { if (ind == 10) { int rem = n; int X = c.size() + d.size(); int i, j; set<int> S = s; set<int>::iterator it; for (i = 0; i < c...
#include <bits/stdc++.h> using namespace std; const int N = 110000; const int M = 1100000; const long long mod = 1e9 + 7; int n, m; vector<pair<int, int> > g[N]; int edge[N]; int col[N], dep[N]; int val[N], f[N]; void dfs(int x, int fa) { f[x] = fa; dep[x] = dep[fa] + 1; for (auto p : g[...
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> t; while (t--) { cin >> n; if (n % 7) cout << (n / 7) + 1 << n ; else cout << n / 7 << n ; } return 0; }
#include<iostream> #include<algorithm> using namespace std; long long cmp(long long a,long long b) { return a > b; } int main() { int t,n,i; long long array[200000],alice,bob; cin>>t; while(t--) { alice=0; bob=0; cin>>n; for(i=0;i<n;i++) { scanf( %lld ,&array[i])...
#include <bits/stdc++.h> using namespace std; static inline void canhazfast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T extgcd(T a, T b, T &x, T &y) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string t; cin >> t; int n = t.size(); int start = (n % 2) ? n / 2 : n / 2 - 1; int j = 1; int k = n / 2; putchar(t[start]); while (k--) { if (start + j <= n - 1) { pu...
#include <bits/stdc++.h> using namespace std; long n, c[long(1e7 + 50)], cnt; void sieve() { c[1] = 1; for (long i = 2; i <= long(1e7); ++i) if (!c[i]) for (long j = 2; i * j <= long(1e7); ++j) c[i * j] = 1; } bool Prime(long x) { if (x < long(1e7)) { if (c[x]) return false; ...
#include <bits/stdc++.h> using namespace std; int const maxn = 1e5 + 5; int n, m, k, p[105], second[105], mx[105]; int ans; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; ++i) scanf( %d , &p[i]); for (int i = 1; i <= n; ++i) { scanf( %d , &second[i]); if (mx[second[i...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long double PI = 4 * atan((long double)1); const long long mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long tt = 1; while ((tt)--) { long long n, m; cin >>...
#include <bits/stdc++.h> using namespace std; int a[205], max1, n, k, t; int main() { cin >> t; while (t > 0) { t--; scanf( %d%d , &n, &k); for (int i = 0; i < k; i++) scanf( %d , &a[i]); max1 = 0; if (k == 1) cout << max(n - a[0] + 1, a[0]) << endl; else { ...
#include <bits/stdc++.h> using namespace std; int a[500010], b[500010], l[500010], lb[39], at[39]; vector<int> v[500010]; int main() { int n, q, p = 0, i, r, x, y; cin >> n; for (i = 1; i <= n; i++) scanf( %d , &a[i]); cin >> q; for (i = 1; i <= q; i++) { scanf( %d%d , &l[i], &x); ...
#include <bits/stdc++.h> using namespace std; long long modpow(long long b, long long e, long long m) { b %= m; if (e == 0) return 1; if (e % 2 == 1) return (b * modpow(b, e - 1, m)) % m; return modpow((b * b) % m, e / 2, m); } long long powten[1005]; vector<long long> mods; int main() { ...
#include <bits/stdc++.h> using namespace std; bool sortin(const pair<long long int, long long int> &e, const pair<long long int, long long int> &f) { return (e.first < f.first); } bool POT(long long int x) { return x && (!(x & (x - 1))); } long long int a, b, c, i, j, k, l, m, n, p, q, r, x,...
#include <bits/stdc++.h> using namespace std; #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unrolled-loops ) int n, m, b, w, color[200010], ok[200010]; vector<int> a[200010]; void dfs(int u, int c) { color[u] = c; ok[u] = 1; b += (c == 0); w += (c == 1...
#include <bits/stdc++.h> using namespace std; inline int Get() { int res = 0, q = 1; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) q = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) res = res * 10 + ch - 0 , ch = getchar(); return res * ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; if (n & 1) { for (i = 0; i < n; i++) cout << (i) << ; cout << n ; for (i = 0; i < n; i++) cout << (i) << ; cout << n ; for (i = 0; i < n; i++) cout << ((2 * i) % n) << ; cout <...
#include <bits/stdc++.h> using namespace std; int mex(set<int> s) { int v = 0; while (s.count(v) > 0) v++; return v; } int g[65]{0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9,...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long L, v, l, r; cin >> L >> v >> l >> r; long long tot = L / v; long long minus = r / v; minus -= (l - 1) / v; cout << tot - minus << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; int a[1000000]; int ans[1000000]; int cnt; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; ans[a[i]]++; } for (int j = 1; j <= n; j++) if (ans[j] == 0) cnt++; cout << cnt << endl; return 0; ...
#include <bits/stdc++.h> using namespace std; struct habijabi { long int start_time, end_time; } work[500500]; bool cmp(habijabi a, habijabi b) { if (a.end_time == b.end_time) { return a.start_time < b.start_time; } return a.end_time < b.end_time; } int main() { long int t, n, i, j...
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; using namespace std; int v[5005]; int main() { int t1; cin >> t1; for (int t = 1; t <= t1; t++) { int n, d; cin >> n >> d; memset(v, 0, sizeof(v)); int l = 1, nr = n - 1; v[0] = 1; for (; nr >= v[l - 1] * 2; l++...
#include <bits/stdc++.h> using namespace std; int main() { long long a, i, j, n, mx, p, b[1001], m; cin >> n >> m; for (i = 1; i <= 1000; i++) b[i] = 0; for (i = 1; i <= m; i++) { mx = -1; p = -1; for (j = 1; j <= n; j++) { cin >> a; if (a > mx) { mx = a; ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; bool solve(int, int); bool trySolve(int, int); bool trySolve(int w, int m) { return (m % w == 0 && solve(w, m / w)); } bool solve(int w, int m) { return (w <= 3 || m == 1 || trySolve(w, m - 1) || trySolve(w, m) || try...
#include <bits/stdc++.h> using namespace std; int n, v[1010]; long double p[1010][1010], a[1010], d[1010]; int work() { int k; long double x = 1e100L; for (int i = 1; i <= n; i++) if (!v[i] && (d[i] + a[i]) / (1 - a[i]) <= x) x = (d[i] + a[i]) / (1 - a[i]), k = i; v[k] = 1, d[k] = ...
#include <bits/stdc++.h> using namespace std; int main() { long long int c, d, x, y, a, b; cin >> a >> b >> x >> y >> c >> d; if (c == 0 and d == 0) { if ((a == x and b == y) or (a == -x and b == -y) or (a == y and b == -x) or (a == -y and b == x)) cout << YES << endl; el...
#include <bits/stdc++.h> using namespace std; template <class T> int chkmax(T& a, T b) { if (b > a) { a = b; return 1; } return 0; } template <class T> int chkmin(T& a, T b) { if (b < a) { a = b; return 1; } return 0; } template <class iterator> void out...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int sum = accumulate(a.begin(), a.end(), 0); vector<vector<int>> dp(n + 1, vector<int>(2, -1)); function...
#include <bits/stdc++.h> using namespace std; const int nmax = 3e5 + 42; int n, m; struct edge { int u, v, c; }; edge inp[nmax]; edge make_edge(int u, int v, int c) { edge x; x.u = u; x.v = v; x.c = c; return x; } bool cmp(edge a, edge b) { return a.c < b.c; } int ans[nmax], ...
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 28; int x[24 + 2], y[24 + 2]; int dist[24 + 2][24 + 2]; int dp[(1 << 24) + 2]; int nxt[(1 << 24) + 2]; int n; int sqr_dis(int a, int b) { return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]); } int solve(int mask)...
#include <bits/stdc++.h> using namespace std; int n, arr[1000], dp[1000][10]; int solve(int i, int flag) { if (i >= n) return 0; if (dp[i][flag] != -1) return dp[i][flag]; if (arr[i] == 0) dp[i][flag] = 1 + solve(i + 1, 0); else if (arr[i] == 1) { if (flag == 0 || flag == 1) { ...
#include <bits/stdc++.h> using namespace std; void hike() { int64_t n; cin >> n; string s, t; cin >> s >> t; vector<int64_t> f; for (int64_t i = 0; i < n; ++i) { if (s[i] != t[i]) { f.push_back(i); } } if (f.size() != 2) { cout << No n ; return; }...
#include <bits/stdc++.h> using namespace std; using namespace chrono; const int infinity = (int)1e9 + 42; const int64_t llInfinity = (int64_t)1e18 + 256; const int module = (int)1e9 + 7; const long double eps = 1e-8; mt19937_64 randGen(system_clock().now().time_since_epoch().count()); inline void raiseE...
#include <bits/stdc++.h> using namespace std; int main() { int t, i; cin >> t; for (i = 0; i < t; i++) { string s; cin >> s; int j = 0, k, l = s.length(), sum = 0; while (j < l) { if (s[j] == 1 ) { k = j; j++; while (s[j] == 0 ) j++; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; long long int v[N]; inline void outv(vector<long long int> v) { for (long long int i = 0; i < v.size(); i++) { cout << v[i] << ; } cout << n ; } inline long long int pow(long long int x, long long int n) { long...
#include <bits/stdc++.h> int main() { int n, k; scanf( %d %d , &n, &k); switch (k) { case 1: printf( -1 n ); break; case 2: if (n < 5) { printf( -1 n ); break; } printf( %d n , n - 1); for (int i = 1; i < n; i++) printf( %d %d...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const int INF = 1000 * 1000 * 1000 + 7; const long long LINF = INF * (long long)INF; const int MAX = 1000 * 100 + 47; long long A[MAX]; long long P[MAX]; long long Q[MAX]; long long R[MAX]; int main() { int n; long lon...
#include <bits/stdc++.h> using namespace std; bool ma[101][101]; int m, n; bool a[101][101]; int steluta(int i, int j) { int t = 1; while (j + t <= m && j - t >= 1 && i + t <= n && i - t >= 1 && ma[i][j + t] == 1 && ma[i][j - t] == 1 && ma[i - t][j] == 1 && ma[i + t][j] == 1) { ...
#include <bits/stdc++.h> using namespace std; double dist(double a, double b, double c, double d) { return sqrt((a - c) * (a - c) + (b - d) * (b - d)); } int main() { double x, y, r, a, b, c, d; cin >> x >> y >> r >> a >> b >> c; d = dist(x, y, a, b); if (d - r - c > 0) printf( %.9lf n...
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(const T &a) { return a * a; } int x, k, timer, n[3], t[3], y[3], head[3], tail[3]; pair<int, int> z[3][100000]; int main() { scanf( %d%d%d%d%d%d%d , &k, &n[0], &n[1], &n[2], &t[0], &t[1], &t[2]); while (1) { timer++; ...
#include <bits/stdc++.h> int main(void) { char z[201], *p; const int H[] = {0, 1, 2, 3, 4, 2, 6, 7, 5, 6}; int s = 999, n = 2, Q[2][8] = {}; while (n--) for (gets(p = z); *p; ++Q[n][H[*p++ - 0 ]]) ; while (s && 8 ^ ++n) if (Q[1][n]) s = std::min(s, Q[0][n] / Q[1][n]); prin...
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; const int MAXM = 105; const int inf = 0x3f3f3f3fLL; struct NODE { long long a, b; int c, id; }; struct ANS { int prei, prej, prek; long long val; ANS() {} ANS(int _i, int _j, int _k, long long _val) : prei(_...
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0L); signed main() { long long n; cin >> n; long double x[n], y[n]; for (long long i = (0); i < (n); ++i) cin >> x[i] >> y[i]; long long ans = 0; for (long long i = (0); i < (n); ++i) { vector<long double> v...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long f = 0, s = 0; char c = getchar(); while (c > 9 || c < 0 ) f = (c == - ), c = getchar(); while (c >= 0 && c <= 9 ) s = (s << 3) + (s << 1) + (c ^ 0 ), c = getchar(); return f ? -s : s; } long long ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; long long n, k, sum; long long a[maxn]; long long goal[maxn]; long long max(long long x, long long y) { return x > y ? x : y; } long long cntmx = -9e18, cntmn = 9e18; void solve3() { long long m = k; for (register int i = n;...
#include <bits/stdc++.h> using namespace std; int main() { string s; char mi, ma; int max = 0, min = INT_MAX; pair<int, char> p[4]; for (int i = 0; i < 4; ++i) { cin >> s; p[i].first = s.length() - 2; p[i].second = s[0]; } sort(p, p + 4); int flag1 = 0, flag2 = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j; long long int x, y; cin >> n >> x >> y; y -= n; if (y < 0) cout << -1 << endl; else { x -= (n - 1); x -= (1 + y) * (1 + y); if (x > 0) cout << -1 << endl; else { cout << (1 +...
#include <bits/stdc++.h> using namespace std; int n, ji[300], k, qi, mz[400010]; char s[400010], tp[400010]; int main() { scanf( %d%s , &n, s + 1); for (int i = 1; i <= n; i++) { ji[s[i]]++; } for (int i = 0; i < 300; i++) if (ji[i] & 1) k++; qi = k; if (!qi) { for (k =...
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> using namespace std; // using namespace __gnu_pbds; #define lli long long int #define llu unsigned long long int #define pb push_back #define rt return 0 #define endln n #define all(x) x.b...
#include <bits/stdc++.h> using namespace std; const int Max_N = 1E6 + 10; int n, m, ans = 1, p[Max_N], color[Max_N]; vector<int> chil[Max_N]; bool mark[Max_N]; int dfs(int i) { int res = 0; mark[i] = true; for (int u : chil[i]) if (!mark[u] && color[i] != color[u]) ++res; return res; ...