func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; deque<int> enumeration; deque<int> cutOrder; struct Edge { Edge(int from, int to, int ind) : from(from), to(to), ind(ind) {} int from, to, ind; shared_ptr<Edge> nxt = nullptr; shared_ptr<Edge> rev = nullptr; shared_ptr<Edge> flip = nullptr; }; ...
#include <bits/stdc++.h> using namespace std; int main() { int slimes, values; vector<int> vec; cin >> slimes; for (int i = 0; i < slimes; i++) { vec.push_back(1); while (vec.size() > 1 && vec[vec.size() - 1] == vec[vec.size() - 2]) { vec.pop_back(); vec[vec.size() - 1] +...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, x; cin >> n >> x; long long a[n], b[n]; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; sort(a, a ...
#include <bits/stdc++.h> using namespace std; int main() { int n, r, s1, s2, d; cin >> n; r = ceil(double(sqrt(n))); s1 = r * r; s2 = (r - 1) * (r - 1); d = s1 - s2; d = d / 2; d = s1 - d; if (n < d) { cout << (r * 2) - 1; } else { cout << r * 2; } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 5; void Solution() { int n; cin >> n; cout << (n / 2) + 1 << n ; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; ci...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } r...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-8; const long double INF = 1e12; const long double PI = acos(-1); struct L : array<complex<long double>, 2> { L(const complex<long double>& a, const complex<long double>& b) { at(0) = a; at(1) = b; } L() {} }; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int MAXX = 2e6 + 10; long long phi(long long n) { long long ret = n; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) n /= i; ret -= ret / i; } } if (n > 1)...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7; const long long inf = 0x3f3f3f3f; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { double pi = 3.1415926535897932384626433832795028841971, n; ...
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long, long long> a, pair<long long, long long> b) { return a.first > b.first; } long long findBest(vector<pair<long long, long long> > &ps, long long x) { long long res = 0; for (long long i = 0; i < ps.size(); i++) { long long ...
#include <bits/stdc++.h> using ll = long long; using namespace std; int n, k, a[110]; int main() { ios::sync_with_stdio(false); cin >> n >> k; for (int i = 0; i < k; ++i) cin >> a[i]; vector<int> s; for (int i = 1; i <= n; ++i) s.push_back(i); int curr_leader = 0; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; string s; cin >> k; vector<long long> cnt(10, 0); for (long long i = 0; i < 4; i++) { cin >> s; for (long long j = 0; s[j]; j++) { if (s[j] >= 0 && s[j] <= 9 ) cnt[s[j] - 0 ]++; } } ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 2; long long gcd(long long a, long long b) { if (b > a) { return gcd(b, a); } if (b == 0) { return a; } return gcd(b, a % b); } long long expo(long long a, long long b, long long mod) { long long res = 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int INF = 0x3f3f3f3f; int d, n, m; struct Sta { int x, p; Sta() {} Sta(int x, int p) : x(x), p(p) {} void read() { scanf( %d%d , &x, &p); } bool operator<(const Sta& c) const { return x < c.x; } } p[N]; struct No...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, ans = 0, odd = 0, ev = 0; cin >> n; int a[n + 1]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] & 1) odd++; else ev++; } if (n == 1) { if (odd) cout << Yes ; else...
#include <bits/stdc++.h> using namespace std; long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); } long long lcm(long long n, long long m) { return (m * n) / gcd(n, m); } long long dx[] = {1, 0}; long long dy[] = {0, 1}; const long long inf = 1e9 + 10; const long long INF = 1e18;...
#include <bits/stdc++.h> using namespace std; bool dbg = 0; clock_t start_time = clock(); void bad(string mes = Impossible ) { cout << mes; exit(0); } void bad(int mes) { cout << mes; exit(0); } template <typename T> string bin(T x, int st = 2) { string ans = ; while (x > 0)...
#include <bits/stdc++.h> using namespace std; const int MX = 100010; int t[MX]; int main() { int n; cin >> n; for (int i = (1); i <= (n); ++i) { scanf( %d , &t[i]); } for (int i = (1); i <= (n); ++i) { printf( %d , t[i] + t[i + 1]); } }
#include <bits/stdc++.h> template <typename T> bool ckmax(T& a, const T& b) { return b > a ? a = b, 1 : 0; } template <typename T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } const int MV = 1e5 + 10; const int MM = 1e5 + 10; const int MG = 450; const int INF = 0x3f3f3f3f; ...
#include <bits/stdc++.h> using namespace std; const int mx = 2e5 + 10; long long int x[mx], y[mx]; int ord[mx]; int hs[mx], h = 0; vector<int> g[mx]; int ans[mx]; int cross(int a, int o, int b) { long long int l = (x[o] - x[a]) * (y[o] - y[b]) * y[a] * x[b]; long long int r = (y[o] - y[a]) * (x[...
#include <bits/stdc++.h> using namespace std; int main() { int mod = 1e9 + 7; string S; cin >> S; bool flag = false; long ans = 0; long plus = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == a ) { if (flag) { ans = (2 * ans + 1) % mod; } else { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int temp; int a[6] = {0}; int i = 0; while (n > 0) { a[i] = n % 2; n = n / 2; i++; } temp = a[0]; a[0] = a[4]; a[4] = temp; temp = a[2]; a[2] = a[3]; a[3] = temp; int...
#include <bits/stdc++.h> using namespace std; const int OO = 1e9; const double EPS = 1e-9; template <class T> void _db(const char* dbStr, T e) { cout << dbStr << = << e << endl; } template <class T, class... L> void _db(const char* dbStr, T e, L... r) { while (*dbStr != , ) cout << *dbStr++...
#include <bits/stdc++.h> using namespace std; int gi() { char cc = getchar(); int cn = 0, flus = 1; while (cc < 0 || cc > 9 ) { if (cc == - ) flus = -flus; cc = getchar(); } while (cc >= 0 && cc <= 9 ) cn = cn * 10 + cc - 0 , cc = getchar(); return cn * flus; } const ...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807; int main() { int n; cin >> n; long long mod = 1000000009; if (n == 2) cout << 10, exit(0); long long b = 5, g = 1, r = 6; long long fb = 2, fg = 2, t = 4; for (int i...
#include <bits/stdc++.h> using namespace std; const int N = int(500 * 1000 + 7); long long n, k; vector<pair<long long, long long> > adj[N]; long long dp[N][2]; void dfs(int v, int p = -1) { vector<long long> x; long long curr = 0; for (auto it : adj[v]) { long long to = it.first; lo...
#include <bits/stdc++.h> using namespace std; const int N = 1010; struct Point { double x, y; Point(double _ = 0, double __ = 0) { x = _, y = __; } bool operator<(const Point &_) const { if (fabs(x - _.x) > 1e-10) return x < _.x; return y < _.y; } } po[N], rec[N * 2], stk[N * 2]; s...
#include <bits/stdc++.h> bool vis[100000 + 3]; int pr[20000]; int h; int a[300]; int n; int endp[200000], next[200000], cap[200000]; int gra[300], cur[300], dist[300], prev[300]; int cnt[300]; int ecnt; char buf[10000], *bend; char out[10000], *oend; void add_edge(int u, int v, int c) { endp...
#include <bits/stdc++.h> const int MAX_N = (int)1e5 + 123; const double eps = 1e-6; const int inf = (int)1e9 + 123; using namespace std; int n, k; int mini = inf; string second; int sum[MAX_N]; int main() { cin >> n >> k >> second; for (int i = 0; i < int((second).size()); i++) sum[i] = ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, m, sum = 0; cin >> n >> m; long long int a[5] = {0}; if (n == 1) cout << 0 << endl; else if (n == 2) cout << m << endl; else ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n; vector<int> adj[N]; vector<pair<int, int> > r; int color[N]; bool vis[N]; void solve(int x) { vis[x] = true; for (auto w : adj[x]) { if (!vis[w]) { color[w] = (color[x]) ^ 1; solve(w); } } ...
#include <bits/stdc++.h> using namespace std; long long mod; long long lgput(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a % mod; long long c = lgput(a, b / 2); c = c * c % mod; if (b & 1) c = c * a % mod; return c; } map<long long, int> hh; int main() { ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) const int N = 1e5 + 5; const long double pi = 3.141592653; const long long MOD = 1e9 + 7; const long long mod = 998244353; const long long INF = 9223372036854775807LL; usi...
#include <bits/stdc++.h> using namespace std; const int MAX = 200005; map<int, int> Map; struct Node { int au, sub; } node[MAX]; int n, temp, m; int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf( %d , &temp); Map[temp]++; } int m; scanf( %d , &m); for (int...
#include <bits/stdc++.h> long long get2(long long, long long); long long get1(long long n, long long x) { if (x & 1) return (x + 1) / 2; else if (n & 1) return get2(n / 2, x / 2) + (n + 1) / 2; else return get1(n / 2, x / 2) + n / 2; } long long get2(long long n, long long x) { ret...
/* { ###################### # Author # # Gary # # 2021 # ###################### */ #include<bits/stdc++.h> #define rb(a,b,c) for(int a=b;a<=c;++a) #define rl(a,b,c) for(int a=b;a>=c;--a) #define LL long long #define IT iterator #define PB push_back #de...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; string s[N]; int n, k, fa[N], len[N], ch[N][26], root = 1, last = 1, tot = 1, times[N]; void insert(int x) { int now = ++tot, pre = last; last = now, len[now] = len[pre] + 1; for (; pre && !ch[pre][x]; pre = fa[pre]) ch[pre][x] =...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; int sum; int a[1000]; cin >> n; sum = n; for (i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); for (i = 1; i <= n; i++) { if (a[i] != 0) { for (int j = i + 1; j <= n; j++) if (a[j] % ...
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int MX = 123456; const int mod = (int)1e9 + 7; const int base = 1023456789; const unsigned long long BS1 = 10000019ULL; const int INF = (1 << 29); template <class T> inline void fastScan(T &x) { register char c = getchar(); ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007, ans = 1, n, ert, dp[1000002]; int main() { ios_base::sync_with_stdio(false); cin >> n, ert = n; dp[0] = 1, dp[1] = 1; for (int i = 2; i <= n; i++) { dp[i] = ((i - 1) * dp[i - 2] + dp[i - 1]) % mod; } for (int i...
#include <bits/stdc++.h> #define arr(i,n) for(ll i=0;i<n;i++) #define ARR(i,n) for(ll i=n-1;i>=0;i--) #define f(i,a,b) for(ll i=a;i<b;i++) #define F(i,a,b) for(ll i=b-1;i>=a;i--) #define float double #define PI 3.14159265358979323846 #define pb push_back #define mp make_pair #define vi vector<ll> ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, i, j, x, y, a[100005], v[100005]; map<long long int, long long int> ma; cin >> n; for (i = 1; i <= n; ...
#include<iostream> #include<string> using namespace std; int main() { int t; cin>>t; for(int i=0;i<t;i++) { int n; string r,b; cin>>n; cin>>r>>b; int counter1=0,counter2=0; for(int i=0;i<n;i++) { if(r[i]>b[i]) counter1++; else if(r[i]<b[i]) counter2...
#include <bits/stdc++.h> using namespace std; int n; char s[105][105]; char t[105]; bool judge1() { int i = 0; for (; i < n; i++) t[i] = E ; t[i] = 0 ; for (int i = 0; i < n; i++) if (strcmp(t, s[i]) == 0) return 1; return 0; } bool judge2() { for (int i = 0; i < n; i++) {...
#include <bits/stdc++.h> using namespace std; int main() { float n; cin >> n; int p = 1; float count = 0; while (n != 0) { count = count + 1.0 / n; n--; } cout << count; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, n1, output = 0; cin >> n; if (n % 2 == 0) cout << n / 2 - 1; else cout << n / 2; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void __print(int x) { cout << x; } void __print(long x) { cout << x; } void __print...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; long long int t; string s; long long int n; long long int dp[100][2501]; long long int adp[100][2501]; long long int l, r, sm; void solve() { cin >> s; n = s.length() - 1; sm = 0; for (auto it : s) sm += i...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int tc = 1; tc <= t; tc++) { int n; cin >> n; pair<pair<int, int>, int> arr[2 * n - 1]; for (int i = 0; i < 2 * n - 1; i++) { cin >> arr[i].first.first >> arr[i].first.second; arr[i]....
#include <bits/stdc++.h> using namespace std; pair<int, pair<int, int> > tup[100000 * 2 + 10]; multiset<int> st; int L[100000 * 2 + 10], R[100000 * 2 + 10], sl[100000 * 2 + 10], sr[100000 * 2 + 10]; int main() { int m, n, r, l, t; scanf( %d%d , &m, &n); int flag = 0; for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s[n]; map<string, int> m; set<string> k; int count = 0; for (int i = 0; i < n; i++) { cin >> s[i]; k.insert(s[i]); } for...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; cout << max(a + b, c + d) << n ; } return 0; }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:268435456 ) using namespace std; long long _gcd(long long a, long long b) { if (b == 0) return a; _gcd(b, a % b); } int main() { int n, m, k, a[20500][10], res[20500] = {0}, b[20500][10] = {0}; cin >> n >> m >> k; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = 1e+9; const double pi = acos(-1.0); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long xabs(long long a) { return a > 0 ? a : -a; } map<int, vector<string>> s; int sm[9][2] =...
#include <bits/stdc++.h> using namespace std; template <class T, class U> void maximize(T &x, U y) { if (x < y) x = y; } template <class T, class U> void minimize(T &x, U y) { if (x > y) x = y; } template <class T> T Abs(T x) { return (x < (T)0 ? -x : x); } namespace task { const int...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 55; int st[maxn]; struct E { int u, v, w, cost; int nxt; } edge[500009]; int gtot = 0, head[maxn * 100]; void addedge(int u, int v, int w, int cost) { edge[gtot].v = v; e...
#include <bits/stdc++.h> using namespace std; int read(); int n; int a[200005], b[200005], c[200005], bk[200005]; int hd[200005], nx[400005], to[400005], cnt; void add(int f, int t) { nx[++cnt] = hd[f], hd[f] = cnt, to[cnt] = t; } int fa[200005], dep[200005]; void dfs1(int u) { for (int i = hd[u], v...
#include <bits/stdc++.h> using namespace std; long long n, t = 1, c1, c2; vector<vector<long long>> adj; vector<vector<long long>> g; vector<bool> visited; void DFS(long long v) { visited[v] = true; g[t].push_back(v); for (auto i : adj[v]) if (!visited[i]) DFS(i); } long long number_of...
#include <bits/stdc++.h> using namespace std; int n, d, h; int main() { cin >> n >> d >> h; if (d - h > h) { cout << -1 << endl; return 0; } if (h == 1 && d == 1 && n > 2) { cout << -1 << endl; return 0; } for (int i = 2; i <= h + 1; i++) { cout << i - 1 <...
#include <bits/stdc++.h> using namespace std; long long n, m, k; char s[200005]; vector<long long> cnt[3][202]; vector<pair<long long, long long> > res; int main() { long long i, j; scanf( %lld , &n); scanf( %s , &s); for (i = 0; i <= n - 1; i++) { cnt[1][s[i]].push_back(i + 1); } ...
#include <bits/stdc++.h> using namespace std; int x[2000][10], y[2000][10]; double Ab(int x) { if (x >= 0) return x; return -x; }; double q(double x) { return x * x; }; double d(int i, int j) { double X, Y; if (x[i][0] == x[i][1] && y[j][0] == y[j][1]) { Y = min(Ab(y[i][0] - y[j][0]), ...
#include <bits/stdc++.h> using namespace std; const int N = 2010; char mp[N][N]; int n, m, cnt1, cnt2, in[N][N]; int xx[6] = {0, 0, 1, 0, -1}; int yy[6] = {0, 1, 0, -1, 0}; queue<pair<long long, long long> > q; int main() { int n, m; while (cin >> n >> m) { memset(in, 0, sizeof in); ...
#include <bits/stdc++.h> long long int segMax[1000010] = {0}, segSum[1000010] = {0}; long long int a[200010]; void constructMax(int low, int high, int pos) { if (low > high) return; if (low == high) { segMax[pos] = a[low]; return; } int mid = low + (high - low) / 2; constructMax(lo...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; for (int z = 0; z < t; z++) { int n, x, y; cin >> n; vector<vector<int>> v; for (int i = 0; i < n; i++) { cin >> x >> y; vector<int...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; string col[] = { Power , Space , Time , Soul , Reality , Mind }; string stone[] = { purple , blue , green , orange , red , yellow }; cout << 6 - n <...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10, M = 1e9, eps = 1e-7, MOD = 1e9 + 7; long long tab[N]; int main() { long long n, l; cin >> n >> l; n--; for (long long i = 1; i <= n; i++) cin >> tab[i]; long long pocz = 0; long long pot = 1 << 30; while (pot...
#include <bits/stdc++.h> using namespace std; bool endline = false; template <class T> istream& operator>>(istream& inp, vector<T>& v) { for (auto& it : v) inp >> it; return inp; } template <class T> ostream& operator<<(ostream& out, vector<T>& v) { for (auto& it : v) out << it << (endline ? ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i = 1; cin >> n >> k; if (k == 1) cout << n; else { vector<int> ans; while (ans.size() < k) { i = 2; while (n % i != 0 && i <= n + 1) i++; if (i >= n + 1) { cout << -1; ...
#include <bits/stdc++.h> using namespace std; void OJ() {} void solve() { long long n; cin >> n; long long digit = 1000000, a = -1, b = -1; for (long long i = 0; i < 1e6; ++i) { if (n >= 4 * i) if ((n - 4 * i) % 7 == 0) { if ((n - 4 * i) / 7 + i <= digit) digit ...
#include <bits/stdc++.h> using namespace std; int p[12]; int main() { long long n; cin >> n; if (n < 5) { cout << (n * (n - 1) / 2) << endl; return 0; } long long p = 5; for (int i = 1;; ++i) { if (p > n) { p /= 10; long long tot = p * 2; --i; ...
#include <bits/stdc++.h> using namespace std; template <class T> void rd(T &k) { char c = getchar(); int f = 1; k = 0; while (c < 0 || c > 9 ) { if (c == - ) f *= -1; c = getchar(); } while (c >= 0 && c <= 9 ) { k = k * 10 + c - 0 ; c = getchar(); } ...
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; int32_t main() { long long int n; cin >> n; if (n % 2 != 0) { cout << 0 << n ; return 0; ; } long long int k = pow(2, n / 2); cout << k << n ; return 0; ; }
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) using namespace std; using ll = long long; using db = long double; using ii = pair<int, int>; const int N = 5e5 + 5, LG = 19, MOD = 1e9 + 7; const int SQ = 225; const long double EPS = 1e-7; string s; int32_t ...
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long mod = 2e18) { long long ans = 1; x %= mod; while (y) { if (y & 1) ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1; } return ans; } signed main() { ios::sync_with_stdio(0)...
#include <bits/stdc++.h> using namespace std; long long a[51][51]; long long combinatorics(long long n, long long k) { double res = 1; for (long long i = 1; i <= k; ++i) res = res * (n - k + i) / i; return (long long)(res + 0.01); } int main() { long long n, m, i, j, numOneRow[51] = {0}, numZe...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) { return a; } else { return b; } } long long min(long long a, long long b) { if (a < b) { return a; } else { return b; } } struct P { double x, y; P() {}...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; typedef struct Item { long long v; int id; Item(long long a, int b) { v = a; id = b; } bool operator<(const Item &rhs) const { return v < rhs.v; } } Item; typedef struct Node { vector<int> p; vecto...
#include <bits/stdc++.h> const int maxn = int(1e5) + 7, mod = int(1e9) + 7; bool not_prime[maxn]; std::map<int, int> cnt[maxn]; std::vector<int> factor[maxn]; long long qpow(long long p, long long q) { long long ret = 1; while (q) { if (q & 1) ret = ret * p % mod; p = p * p % mod; q ...
#include <bits/stdc++.h> int gcd(int a, int b) { int r; while (b != 0) { r = a % b; a = b; b = r; } return a; } int main() { int n, m; int deg1, deg2; scanf( %d %d , &n, &m); for (int i = 0, a; i <= n; i++) { scanf( %d , &a); if (i == 0) deg1 = a; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; struct node { int vl, mnvl; node *l, *r; node() { mnvl = MAXN; vl = -1; l = r = NULL; } }; vector<node*> dv(MAXN); vector<bool> inarr(MAXN, false); vector<vector<int>> diverse(MAXN); deque<int> dbl(...
#include <bits/stdc++.h> using namespace std; long long fast_pow(long long a, long long p) { long long res = 1; while (p) { if (p % 2 == 0) { a = a * 1LL * a % 1000000007; p /= 2; } else { res = res * 1LL * a % 1000000007; p--; } } return res; } ...
#include <bits/stdc++.h> using namespace std; class UFDS { public: vector<int> p, rank; int count = 0; UFDS(int n) { p.resize(n); rank.resize(n); for (int i = 0; i < n; i++) p[i] = i; count = n; } int getParent(int i) { return (p[i] == i) ? i : (p[i] = getParent(p[i]))...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; priority_queue<int, vector<int>, greater<int> > pq; vector<int> v; int al[256]; char s[200001], t[200001]; int visit[200001]; int n, m; int main() { scan...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, p, k; cin >> a >> b >> c; if (c != 0) { p = b - a; k = p / c; if (p % c == 0) { if (k >= 0) cout << YES << endl; else cout << NO << endl; } else cout ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int pos[maxn]; int n, x, y; int main() { int i, j; while (scanf( %d , &n) != EOF) { memset(pos, -1, sizeof(pos)); for (i = 1; i <= n; i++) { scanf( %d%d , &x, &y); int ans = 0; for (j = 1; j * j ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 5000001; unsigned int arr[MAX], P[MAX]; void sieve() { unsigned int i, j, t, k; arr[0] = arr[1] = 0; for (i = 2; i < MAX; i++) arr[i] = i; for (i = 4; i < MAX; i += 2) arr[i] = 2; for (i = 3; i * i <=...
#include <bits/stdc++.h> using namespace std; int n, m, i; long long s, ans; int x[200000], y[200000]; long long a[200000], b[200000], c[200000], d[200000]; void count() { s = 0; for (i = 1; i <= n; i++) b[i] = c[i] = d[i] = 0; for (i = 1; i < n; i++) a[i] = a[i + 1] - a[i]; for (i = 1; i < ...
#include <bits/stdc++.h> using namespace std; int64_t solve(int m, int n) { if (m > n) swap(m, n); if (m == 1) { if (n <= 3) return 0; if (n % 6 == 2 || n % 6 == 4) return n - 2; if (n % 6 == 1 || n % 6 == 5) return n - 1; if (n % 6 == 3) return n - 3; return n; } if (m...
#include <bits/stdc++.h> using namespace std; inline int gi() { int data = 0, m = 1; char ch = 0; while (ch != - && (ch < 0 || ch > 9 )) ch = getchar(); if (ch == - ) { m = 0; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { data = (data << 1) + (data << 3) + (ch ^ ...
#include <bits/stdc++.h> using namespace std; const int MAX = 100002; map<int, int> cnt[MAX]; vector<int> adj[MAX]; long long ans[MAX]; int color[MAX]; int max_el[MAX]; void dfs(int node, int par) { cnt[node][color[node]] = true; max_el[node] = 1; ans[node] = color[node]; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inv2 = 500000004; const long long inv6 = 166666668; const long long inv4 = 250000002; const long long inv30 = 233333335; const long long inv12 = 83333334; const int KKK = 5; long long ipow(long long b, int ...
#include <bits/stdc++.h> using namespace std; const long long Base = 1e9 + 7; struct Matrix { int n, m; long long cost[101][101]; Matrix() {} Matrix(int n_, int m_) { n = n_, m = m_; for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) cost[i][j] = 0; } Matrix oper...
#include <bits/stdc++.h> using namespace std; long long n, m, b; vector<pair<long long, long long> > v; long long mask[105], cost[105], monitors[105]; long long dp[1 << 21]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> b; for (int i = 0; i <= 100; i++) mask[...
#include <bits/stdc++.h> #pragma optimize( -O3 ) using namespace std; const long long mod = 998244353; int n, m, u, v; pair<vector<int>, int> adj[1000006]; int alr[1000006]; long long ans = 0, cr = 0; bool check(int i, int j) { if ((int)adj[i].first.size() != (int)adj[j].first.size()) return false; ...
#include <bits/stdc++.h> using namespace std; int a[4][2]; int b[4][2]; int vis[205][205]; int main() { bool flag = 0; int x1, x2, y1, y2; for (int i = 0; i < 4; i++) { scanf( %d %d , &a[i][0], &a[i][1]); } for (int i = 0; i < 4; i++) { scanf( %d %d , &b[i][0], &b[i][1]); }...
#include <bits/stdc++.h> const double eps = 1e-9; const int inf = 2000000000; const double pi = acos(-1.0); const long long mod = 1000000007; using namespace std; char s[150]; int t; long long d[26 * 100 + 200][130]; int main() { scanf( %d n , &t); memset(d, 0, sizeof(d)); for (int num = 0...
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 10; const long long INF = 1000 * 1000 * 1000LL * 1000 * 10000; int n, q, pt = 1, cnt; vector<long long> ans; set<pair<long long, long long> > s; set<pair<long long, long long> >::iterator it1, it2; long long po[100], a[N], sum[N * ...
#include <bits/stdc++.h> using namespace std; long long a, s, d[500002][3], f, g, h, j, k, l, i, n, m; long long inf = 100000000000000000ll; pair<long long, int> p[500003], p1; int main() { cin >> n; for (i = 1; i <= n; i++) { scanf( %d , &a); d[i][0] = a; d[i][1] = i - 1; d[i]...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n - 1; i++) { if (arr[i] % 2 != 0) { if (arr[i + 1] > 0) { arr[i + 1] -= 1; if (arr[i + 1] < 0) {...
#include <bits/stdc++.h> using namespace std; int a[1000][1000]; int main() { int n, m, x, y; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> x >> y; x--, y--; for (int k = -2; k < 1; k++) for (int l = -2; l < 1; l++) if (x + k >= 0 && x + k < n && y + l >= 0 &&...