func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; } inline int read() { int x = 0, f = 1; char cc = getchar(); while (cc < 0 || cc > 9 ) { if (cc == - ) f = -1; cc = getchar(); } ...
#include <bits/stdc++.h> using namespace std; class ConvexHullTrick { public: vector<long long int> a, b; int size = -1; bool can_remove(int a, int b, int c, int d) { if (a / b != c / d) return a / b < c / d; a %= b; c %= d; if (a == 0) return true; if (c == 0) return fa...
#include <bits/stdc++.h> using namespace std; int bits(int num) { int c = 0; while (num > 0) { c++; num = num / 2; } return c; } int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; long long int i; long long int a[n]; for (...
#include <bits/stdc++.h> using namespace std; int dp[100][100]; vector<long long> can; int test; int r(long long a, long long b) { if ((a == 0) || (b == 0)) return 0; int k = r(b % a, a); if (k == 0) return 1; long long v = (b % a); v += a; long long c = (b - v) / a; if (a & 1) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; const int LOG = 20; const int CNTSZ = 30; const long long INF = 1e18; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; vector<pair<long ...
#include <bits/stdc++.h> using namespace std; struct ako { int b2, c2, d; ako(int B = -1, int C = -1, int D = -1) : b2(B), c2(C), d(D) {} }; const int minb = -2000, maxb = 4000, maxa = 1005; ako vis[maxb - minb + 79][maxa]; int main() { ios::sync_with_stdio(false); cin.tie(0); int a; ...
#include <bits/stdc++.h> using namespace std; int d[1005][2]; char M[1005][1005]; struct Node { int l = 0, r = 0; int p; } L[1005], R[1005]; int n, m; int v[1005]; void Cal(int i) { L[i].l = L[i].p; R[i].l = R[i].p; L[i].r = m - 1 - L[i].p; R[i].r = m - 1 - R[i].p; } int main...
#include <bits/stdc++.h> using namespace std; const int N = (int)1E5 + 5; int MOD = (int)1E9 + 7; namespace CHT { struct cnode { int s; int e; int ls; int rs; int res; } nodes[N * 40]; void copy(int s, int d) { nodes[d].s = nodes[s].s; nodes[d].e = nodes[s].e; nodes[d].ls =...
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; stack<char> s; for (int i = 0; i < a.size(); i++) { if (s.empty() || s.top() != a[i]) s.push(a[i]); else s.pop(); } if (s.empty()) cout << Yes ; else cout << No ; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, d, m, s; cin >> n >> d; vector<pair<int, int> > v; vector<int> money; for (int i = 0; i < n; i++) { cin >> m >> s; pair<int, int> p = make_pair(m, s); v.push_back(p); money.push_back(m); } sort(v.be...
#include <bits/stdc++.h> using namespace std; int dp[11][1001], a[11], b[11], c[11], d[11], n, m; int main() { a[0] = 100000, b[0] = 0; scanf( %d %d %d %d , &n, &m, &c[0], &d[0]); for (int i = 1; i <= m; i++) scanf( %d %d %d %d , &a[i], &b[i], &c[i], &d[i]); for (int i = 0; i <= m; i++) dp[i][0] =...
#include <bits/stdc++.h> using namespace std; int main() { long a[1001]; long i, j, k = 0, l, n; scanf( %ld , &n); for (i = 0; i < n; i++) { scanf( %ld , &a[i]); } sort(a, a + n); if (a[0] == a[1] && a[0] != 0) k++; for (i = 2; i < n; i++) { if (a[i] == a[i - 1] && a[i - ...
#include <bits/stdc++.h> using namespace std; struct pairvar { int a; int b; }; bool isPrime(long long x) { if (x == 1) { return false; } long long a = (long long)x; for (int i = 2; i <= (long long)sqrt((double)a); i++) { if (a % i == 0) { return false; } } ...
#include <bits/stdc++.h> using namespace std; int n; int f[100010]; int main() { int x; cin >> n; for (int i = 0; i <= n - 1; i++) { cin >> x; f[x]++; } for (int i = 100000; i >= 0; i--) { if (f[i] & 1) { printf( Conan n ); return 0; } } printf...
#include <bits/stdc++.h> using namespace std; const int INF = 0x60000000; const int MINF = -1000000000; const int mod = 1000000007; const int cons = 100001; const double pi = 3.141592653589793; const int sqrtMax = 317; const int blocks = cons / 3; const int MOD = 100000; long long dp[1000001]; int...
#include <bits/stdc++.h> struct Widget { std::string name; long long width, height; Widget(const std::string& name, long long width, long long height) : name(name), width(width), height(height) {} ~Widget() {} virtual void calculateSize() {} }; struct Box : public Widget { int spac...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, t; cin >> n >> t; string str; cin >> str; long long ptr = 0; while (str[ptr] != . ) ptr++; long long tmp = ptr; ptr++; while (ptr < n...
#include <bits/stdc++.h> template <class T> inline T gcd(T a, T b) { a = abs(a); b = abs(b); if (!b) return a; return __gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { a = abs(a); b = abs(b); return (a / __gcd(a, b)) * b; } template <class T> inline T ncr(T n, T ...
#include<bits/stdc++.h> using namespace std; #include<algorithm> #include<map> #include<fstream> #define ll long long #define ld long double #define pb push_back #define fi first #define se second #define endl n #define For(i,n) for(long long i=0; i<n; i++) #define FOR(i,f,l) for(long long i=...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { double a, b, c, d, k; cin >> a >> b >> c >> d >> k; if (ceil(a / c) + ceil(b / d) > k) { cout << -1 << endl; } else { cout << ceil(a / c) << << ceil(b / d) << endl; ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 34; const int N = (int)1e6 + 34; int p[N], sz[N]; int fnd(int v) { return (p[v] == v ? v : fnd(p[v])); } void uniq(int v1, int v2) { v1 = fnd(v1); v2 = fnd(v2); if (v1 == v2) return; p[v1] = v2; sz[v2] += sz[v1]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int *a = new int[n]; int max = 0; for (int i = 0; i < n; i++) { cin >> a[i]; max += a[i]; } for (int del = 2; del < n; del++) { int vLeft = n / del; if (n % del == 0 && vLeft > 2) { ...
#include <bits/stdc++.h> using namespace std; namespace fastIO1 { inline char read() { static const int IN_LEN = 1000000; static char buf[IN_LEN], *s, *t; return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++); } template <class T> i...
#include<bits/stdc++.h> using namespace std; #define sz(s) (int)s.size() #define f first #define s second #define pb push_back #define all(s) s.begin(), s.end() #define vi vector<int> #define vvi vector<vi> #define ll long long #define vll vector<ll> #define ii pair<int, int> #define...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, mod = 998244353; int mu[maxn], n, m, l[51], r[51], prime[maxn], cnt; bool is_composite[maxn]; int dp[maxn], pre[maxn]; int cal(int d) { int M = m / d; for (int i = 1; i <= M; i++) dp[i] = 0; dp[0] = 1; for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100000; typedef struct P { int x, y; P() {} P(int x, int y) : x(x), y(y) {} } P; bool operator<(const P &a, const P &b) { if (a.x != b.x) return a.x <...
#include <bits/stdc++.h> char s[2000005]; int sign[2000005], o[2000005], n, m, L; int main() { scanf( %s , s), n = strlen(s), m = 0; for (int i = 0; i < n; i++) { int x = s[n - 1 - i] - 48; if (x) { if (m == 1) o[L++] = i - 1; m += m < 2; } else if (m == 1) sign[L...
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5; int n, q, num, b0[N], b[N], c[2][N], ans[N]; struct data { int p, s, b; } a[N]; struct qry { int x, y, id; } Q[N]; bool cmp(qry a, qry b) { return a.x < b.x; } bool cmp1(data a, data b) { return a.p < b.p; } bool cmp2(data ...
#include <bits/stdc++.h> using namespace std; vector<int> l[100010], r[100010], chosenl[100010], chosenr[100010]; vector<bool> badl[100010], badr[100010]; bool monst[100010]; int ans[100010]; vector<pair<int, int> > edges[100010]; int cnt[100010], toFather[100010], fromFather[100010]; void longPathChild...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; const int maxm = 3e5 + 10; vector<pair<int, int> > g[maxn]; stack<int> S; struct edge { int x, y; } e[maxm]; int n, m, cnt, dfn; int d[maxn], low[maxn], fa[maxn], pre[maxn]; void tarjan(int now, int f) { d[now] = low[no...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; const long long INF = 1e15 + 7; const long long N = 2e5 + 10; const long long mod = 998244353; long long pow(long long x, long long y) { long long res = 1; while (y > (long long)0) { if (y & (long long)1) res = ((res) * (...
#include <bits/stdc++.h> using namespace std; void magic(int n) { int cnt = 0; set<vector<vector<int>>> s; vector<pair<int, string>> ans; map<int, int> mp; function<void(vector<vector<int>>)> f = [&](const vector<vector<int>> &x) { if (s.find(x) != s.end()) return; s.insert(x); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; long num; cin >> n; set<long> s; while (n > 0) { cin >> num; while (num % 2 == 0) { num = num / 2; } while (num % 3 == 0) { num = num / 3; } s.insert(num); n--; } i...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } template <typename t1> t1 gcd(t1 a, t1 b) { return b == 0 ? a : gcd(b, a % b); } template <typename t1> t1 lcm(t1 a, t1 b) { return a * (b / gcd(a...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int start; int tail; int head[150500], to[150500], nxt[150500], wei[150500], cost[150500], tot = 1; int dis[5050], pre[5050], pres[5050]; bool vis[5050]; queue<int> que; int n, sum, k; int used, flow; char str[105]; int nu...
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, u; int e[N]; double ans = -1; int search(int l, int r, int k) { int m, p = -1; while (l <= r) { m = (l + r) / 2; if (e[m] <= k) { p = m; l = m + 1; } else r = m - 1; } return ...
#include <bits/stdc++.h> using namespace std; const int N = 600005; int n, m, l, r, ma, a[N], f[N][22]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d%d , &l, &r); a[l] = max(a[l], r); ma = max(ma, r); } for (int i = 1; i <= ma; i++) a[i] = max(a[i...
#include <bits/stdc++.h> using namespace std; const long long N = 1000000 + 5; const long long MOD = 1000000007; long long n, m, k; long long ans; long long v[N], sum[N]; long long Pow(long long x, long long k) { long long z = 1; for (; k; k >>= 1, (x *= x) %= MOD) if (k & 1) (z *= x) %= MOD...
#include <bits/stdc++.h> using namespace std; const int _ = 1e5 + 7, P = 1e9 + 7; int N, A[_], prm[_], cprm, phi[_], cnt[_]; bool nprm[_]; vector<int> lst[_]; void sieve() { phi[1] = 1; for (int i = 2; i <= 1e5; ++i) { if (!nprm[i]) { prm[++cprm] = i; phi[i] = i - 1; } ...
#include <bits/stdc++.h> using namespace std; int main() { pair<int, int> a[555555]; double n, k, t, l = -1, r = 1e12, c, maxx, yes = 0; int i; cin >> n; for (i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a[i].second); for (k = 0; k < 300; k++) { maxx = -1e30; c = (l + r) * 0.5;...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cin.ignore(); string arr; getline(cin, arr); int mx = 0; int cur = 0; for (int i = 0; i < n; i++) { if (arr[i] == ) { mx = max(mx, cur); cur = 0; continue; } if (i...
#include <bits/stdc++.h> using namespace std; int i, j, k, l, x, y, z, m, n, a, b, ans, p, q, r; int numbers[800000]; int gcd(int x, int y) { if (y == 0) return x; else return gcd(y, x % y); } int main() { scanf( %d %d %d , &a, &b, &n); ans = gcd(a, b); m = sqrt(ans); for...
#include <bits/stdc++.h> int main(int argc, char *argv[]) { std::string s; std::cin >> s; int yes = 0; int len = s.length(); if (len < 3) { std::cout << No ; return 0; } for (int i = 0; i < len - 2; i++) { std::string ss = s.substr(i, 3); if (ss == ABC || ss == ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); vector<int> ans(n); for (int i = 0; i < n; i++) cin >> v[i]; int flagie = 1; for (int i = 1; i < n; i++) if (v[i] != v[i - 1]) fl...
#include <bits/stdc++.h> using namespace std; namespace patch { template <typename T> std::string to_string(const T& n) { std::ostringstream stm; stm << n; return stm.str(); } } // namespace patch int m, lim, len; long long dp[1 << 18][101]; string s; long long fac[19]; int freq[10]; ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, a[N]; int cnt[N], odd, neg, sum; int f[N]; long long res; bool check(int L, int R) { for (int i = 1; i <= n; ++i) if (!(L <= (i) && (i) <= R) && !(L <= (n - i + 1) && (n - i + 1) <= R) && a[i] != a[n - i + 1]) ...
#include <bits/stdc++.h> using namespace std; const long long Mod = 1e9 + 7; const long long INF = (long long)(1e18) + 5; const long long N = 2e5 + 5, M = 18; int n, m, p; int a[N]; tuple<long long, long long, long long> b[N]; long long suf_s[N], suf_c[N]; long long dp[N], prev_dp[N]; void solve(int...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e9 + 9; const long long N = 500500; signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(10); cout << fixed; long long v; cin >> v; if (v...
#include <bits/stdc++.h> using namespace std; void dfs(bool* visit, vector<int>* am, int n, int sv, vector<int>& v) { visit[sv] = true; v.push_back(sv); for (int p = 0; p < am[sv].size(); ++p) { if (visit[am[sv][p]] == false) { dfs(visit, am, n, am[sv][p], v); } } return; }...
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n; cin >> n; if (n % 2 == 0) { cout << n - (n / 2) << endl; } else { cout << - << (n + 1) / 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, m; cin >> n >> m; char a, b; int flag1, flag2; cin >> s; for (int i = 0; i < m; i++) { cin >> flag1 >> flag2 >> a >> b; for (int j = flag1 - 1; j <= flag2 - 1; j++) { if (s[j] == a) { ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n, m; int a[300000]; int s[300000]; int main() { int i, j, k, l; cin >> n >> m; for (i = 0; i < n; i++) scanf( %d , &a[i]); m--; int ans = 0; if (a[m] != 0) ans = 1, a[m] = 0; if (n == 1) return !pr...
#include <bits/stdc++.h> using namespace std; int main() { int i; printf( 9 ? ?>> ? ?0 n ); for (i = 8; i >= 0; i--) printf( %d ? ?<>%d n , i, i + 1); printf( ? ?<>1 n ); for (i = 9; i >= 0; i--) printf( ?%d>>%d? n , i, i); printf( >>? n ); }
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long mod = 1e9 + 7; int main() { cin.tie(0); ios_base::sync_with_stdio(0); unsigned long long n; cin >> n; unsigned long long c = 2 * 3 * 4 * 5 * 7 * 3; if (c > n) { cout << 0 n ; return 0; ...
#include <bits/stdc++.h> using namespace std; //using namespace atcoder; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define REP(i, n) FOR(i,0,n) #define IFOR(i, begin, end...
#include <bits/stdc++.h> using namespace std; int n, x, y, neg, pos; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; if (x < 0) neg++; else pos++; } if (pos <= 1 || neg <= 1) cout << Yes ; else cout << No ; return 0; } ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, i, x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; cout << (x2 - x1) * (y2 - y1) + 1 << n ; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long tt; cin >> tt; while (...
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 5; long double N, t; long double Pow(long double b, long long e) { if (e == 0) return 1; long double ret = Pow(b, e / 2); ret *= ret; if (e % 2) return ret * b; return ret; } int main() { cin >> N >> t; N *= Pow...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long i, j, c = 0, k, n, x = 0, y = 0; char ch; string s; cin >> n; cin >> s; for (i = 0; i < n - 1; i++) { if (s[i] == U ) { y = y + 1; } if (s[i] == R ) {...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, k, fa[N], cnt[N], vis[N]; vector<int> G[N]; vector<pair<int, int> > p, q[N]; int findset(int x) { return x == fa[x] ? x : fa[x] = findset(fa[x]); } void dfs(int x) { vis[x] = 1; for (auto it : G[x]) dfs(it); for (au...
#include <bits/stdc++.h> using namespace std; int n, lcnt; long long m, p, q; int a[100005], lsum[100005]; long long sum[100005], rmax[100005], lmin[100005], ls[100005]; long long ans1, ans2, ans; set<int> unu; inline long long Min(long long x, long long y) { return x < y ? x : y; } inline long long M...
#include <bits/stdc++.h> using namespace std; const int maxn = 200 * 1000 + 100; int n, m, p; int a[maxn]; int b[maxn]; map<int, int> numb; map<int, int> numa; vector<int> ans; int sum = 0; void add(int x) { int val = numa[x] + 1; numa[x] = val; if (numb[x] >= val) sum++; } void remo...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using dbl = double; using ldb = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using mii = map<int, int>; using msi = map<string, int>; using umii = unord...
#include <bits/stdc++.h> using namespace std; int x, y, a, b, n; void init() { scanf( %d , &n); puts( YES ); for (int i = 1; i <= n; i++) { scanf( %d%d%d%d , &x, &y, &a, &b); printf( %d n , 2 * abs(x % 2) + abs(y % 2) + 1); } } int main() { init(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, matrica[101][101], pas = 0; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { cin >> a; matrica[i][j] = a; } for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (...
#include bits/stdc++.h #define ll long long int #define MOD 1000000007 using namespace std; ll randNum(ll a , ll b){ return a + rand() % (b-a+1); } template<class t> void print(t *a , int n){ for(int i =0 ; i<n ; i++) cout<<a[i]<< ; cout<<endl; } template<class t> void pr...
#include <bits/stdc++.h> using namespace std; const int MAXSIZE = 300010; int rank1[MAXSIZE]; int parent[MAXSIZE]; int visited[MAXSIZE]; int diameter[MAXSIZE]; int N; vector<int> V[MAXSIZE]; int maxL = 0, last = 0; int FindSet(int x) { if (x != parent[x]) parent[x] = FindSet(parent[x]); retu...
#include <bits/stdc++.h> using namespace std; const int NN = 200005; vector<int> vv[NN]; void _addedge(int x, int y) { vv[x].push_back(y); } int dfn[NN], low[NN], stk[NN], blo[NN], block, Cnt, Now; int ins[NN]; void tarjan(int n) { int i, j; low[n] = dfn[n] = ++Cnt, ins[stk[++Now] = n] = 1; fo...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, j, k, l1 = 1, l2 = 1, s, r[7], z = 0; cin >> n >> m; for (i = 7; i < n; i *= 7) l1++; for (i = 7; i < m; i *= 7) l2++; if (l1 + l2 < 8) for (i = 0; i < n; ++i) for (j = 0; j < m; ++j) { for (k =...
#include <bits/stdc++.h> using namespace std; const int M = 1500 + 5, inf = 1e9 + 7; int n, m; pair<int, int> mark[M][M]; bool A[M][M]; inline int state(int i, int j) { return (i * M + j); } void dfs(int i, int j, int i2, int j2) { i = (i % n + n) % n, j = (j % m + m) % m; if (!A[i][j]) return; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 211; vector<pair<int, int> > con[maxn]; vector<pair<int, int> > edge; bool vis[maxn]; int n, w, tmx, tv, ans; void dfs(int x, int dis) { vis[x] = 1; if (dis > tmx) tmx = dis, tv = x; for (int i = 0; i < con[x].size(); i++) if...
#include <bits/stdc++.h> char g[1001][1001]; int main() { int k, z, n = 2, i, j, b3[30], len = 0, from, prev, y; scanf( %d , &k); memset(g, N , sizeof(g)); z = k; while (z) b3[len++] = z % 3, z /= 3; for (i = 0; i < len; i++) if (b3[i]) { from = 0; prev = 1; fo...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, sum = 0, i, j, ara[100000], mid, low, high; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &j); sum += j; ara[i] = sum; } scanf( %d , &m); for (i = 0; i < m; i++) { scanf( %d , &k); ...
#include <bits/stdc++.h> using namespace std; long long pow(long long b, long long e, long long m) { long long t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; } template <class T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template <...
#include <bits/stdc++.h> using namespace std; const int MAX_N = (int)1e5 + 15; bool isAns = 1; int n, m; vector<vector<int>> gr; vector<int> a, b; void in() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; gr.resize(n + 5); for (int i = 0; i < m; ++i) { int a, b; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const long long mod = 1e9 + 7; struct Matrix { int n, m; long long a[10][10]; Matrix() { memset(this->a, 0, sizeof(this->a)); } Matrix(int n, int m) { this->n = n; this->m = m; memset(this->a, 0, sizeof(thi...
#include <bits/stdc++.h> bool isRight(int *c) { int sides[3] = {0}; sides[0] = (c[4] - c[2]) * (c[4] - c[2]) + (c[5] - c[3]) * (c[5] - c[3]); sides[1] = (c[4] - c[0]) * (c[4] - c[0]) + (c[5] - c[1]) * (c[5] - c[1]); sides[2] = (c[2] - c[0]) * (c[2] - c[0]) + (c[3] - c[1]) * (c[3] - c[1]); std::sor...
#include <bits/stdc++.h> using namespace std; long n, m, k, q, bst, onemove, pmove; int main() { ios_base::sync_with_stdio(0); cin >> n >> m >> k; bst = 1e9; for (int i = 1; i <= n; i++) { cin >> q; if (q < bst && i % 2 == 1) bst = q; } if (n % 2 == 0) { cout << 0 << endl...
#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); } long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); } long long int read_int() { char r; bool start = false, neg = false; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int inf = 0x3f3f3f3f; const long long Inf = 0x3f3f3f3f3f3f3f3f; const int maxn = 1e3 + 4; const int maxm = 1e5 + 4; vector<int> v; int n, k, b[maxn]; int main() { ios::sync_with_stdio(false); int i, j, kase; cin >...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long a, b, c; if (n / 2 < k + 1) { a = b = 0; c = n; } else { long long x = (n / 2) / (k + 1); a = k * x; b = x; c = n - x * (k + 1); } cout << b << << a...
#include <bits/stdc++.h> using namespace std; vector<tuple<long long int, long long int, long long int> > v; vector<long long int> v1, v3; vector<pair<char, long long int> > v2; long long int i, j, k, n, sum = 0, p, r, ct = 0, q, sum1 = 0, sum2, t; set<long long int> s, s1; priority_queue<long long int> g...
#include <bits/stdc++.h> using namespace std; struct point { int x, y; point(int a = 0, int b = 0) { x = a; y = b; } }; struct cmpx { bool operator()(point a, point b) { if (a.x == b.x) return a.y < b.y; return a.x < b.x; } }; struct cmpy { bool operator()(poi...
#include <bits/stdc++.h> const int MAXN = 200010; const int mod = 1000000007; void reduce(int& x) { x += x >> 31 & mod; } int mul(int a, int b) { return (long long)a * b % mod; } int remod(long long x) { x %= mod; return x + (x >> 63 & mod); } int n; int A[MAXN], W[MAXN]; long long rt[MAXN]; ...
#include <bits/stdc++.h> int main() { long n; scanf( %ld n , &n); std::vector<long> blocks(n + 2); for (long p = 1; p <= n; p++) { scanf( %ld , &blocks[p]); } for (long p = 1; p <= n; p++) { blocks[p] = std::min(blocks[p], 1 + blocks[p - 1]); } for (long p = n; p >= 0; p--)...
#include <bits/stdc++.h> using namespace std; const int N = 2000010; int a[N], pos[N], cnt[N]; long long ans[N], res; struct node { int l, r, idx; bool operator<(const node& x) const { if (pos[l] == pos[x.l]) return r < x.r; return l < x.l; } } q[N]; int L, R, n, m, k; void updat...
#include <bits/stdc++.h> using namespace std; long long p, k; long long r[20005]; int i, j; int main() { scanf( %I64d%I64d , &p, &k); while (p) { r[i] = p % (-k); p = p / (-k); while (r[i] < 0) { r[i] = r[i] + k; p++; } i++; } if (i == 0) i++; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200 + 5; string s; int dist[maxn * maxn]; bool a[maxn][maxn], chek[maxn * maxn]; vector<int> v[maxn * maxn]; void bfs(int x) { chek[x] = true; queue<int> q; q.push(x); while (!q.empty()) { x = q.front(); q.pop(); ...
#include <bits/stdc++.h> using namespace std; long long const N = 2e5 + 70; long long n, k, a[N], cnt[N], ans, fi = -1, la = -1; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (long long i = 0; i <= n; i++) { cin >> a[i]; cnt[i] = a[i]; ...
#include <bits/stdc++.h> using namespace std; long long n, a[310]; long long fac[310], rev[310]; bool mmp[310][310]; long long mod = (long long)1e9 + 7; long long qmod(long long a, long long p) { long long ret = 1; while (p) { if (p & 1) ret = (ret * a) % mod; a = (a * a) % mod; p ...
#include <bits/stdc++.h> const int MOD = 998244353; int add(int x, int y) { int res = x + y; return res < MOD ? res : res - MOD; } int mul(int x, int y) { return (long long)x * y % MOD; } int pow(int base, int p) { int res = 1; while (p > 0) { if (p & 1) res = mul(res, base); base ...
#include <bits/stdc++.h> using namespace std; int id(string s) { if (s == C ) return 1; else if (s == C# ) return 2; else if (s == D ) return 3; else if (s == D# ) return 4; else if (s == E ) return 5; else if (s == F ) return 6; else if (s == F...
#include <bits/stdc++.h> using namespace std; void solve() { string n; cin >> n; vector<string> vec; int si = n.size(); for (int i = 0; i < si; i++) { if (n[i] == 0 ) continue; string s = ; s += n[i]; for (int j = i + 1; j < si; j++) { s += 0 ; } v...
#include <bits/stdc++.h> using namespace std; static int aQWEs = []() -> int { ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); long long int power(long long int a, long long int p, long long int m = 1000000007) { a %= m; long long int val = 1; while (p > ...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; int N, w, W[100100], b, B[100100], C[100100], S[100100]; int main() { ios_base::sync_with_stdio(0); cin >> N; for (int(i) = 1; (i) <= (N); (i)++) { cin >> C[i] >> S[i]; if (C[i]) ...
#include <bits/stdc++.h> using namespace std; const int M = 3e5 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int n, q; int cnt[M]; string ss; void solve() { cin >> n >> q; cin >> ss; for (int i = 1; i <= n; i++) { if (i % 2) cnt[i] = ss[i - 1] == + ? 1 : -1; ...
#include <bits/stdc++.h> using namespace std; int findLengthOfLNDS(vector<pair<int, float> > &plants_data) { if (plants_data.size() == 0) return 0; vector<int> m; m.push_back(0); for (int i = 1; i < plants_data.size(); i++) { if (plants_data[m.back()].first <= plants_data[i].first) { m...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n0, n1, n2; cin >> n0 >> n1 >> n2; if (n1 == 0 && n2 == 0) { cout << string(n0 + 1, 0 ) << endl; continue; } string result = string(n2 + 1, 1 ); char turn =...
#include <bits/stdc++.h> using namespace std; long long n, m, k; string s; bool flag; void solve() { int n, k; cin >> n >> k; unordered_set<int> s; queue<int> q; vector<int> a(n); for (auto i = 0; i < n; i++) cin >> a[i]; ; for (auto i = 0; i < n; i++) { if (s.find(a[i]) ...
#include <bits/stdc++.h> using namespace std; const int modn = (int)1e9 + 7, N = (int)1e5 + 10; int a[N], p[N][6], q[N], c[6][6][6], n, m; inline void add(int &x, int y) { x += y; if (x >= modn) x %= modn; } struct zz { int power, x, s, t, tot; int v[N << 2], ls[N << 2], rs[N << 2], b[N << 2...