func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; void mego() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool isp(long long x) { for (long long i = 2; i * i <= x; i++) if (!(x % i)) return false; return true; } long long coun = 0; int gcd(long long a, long long b) { if...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; string second; cin >> second; vector<long long> cnt(k, 0); for (long long i = 0; i < n; i++) { cnt[second[i] - A ]++; } long long ans = cnt[0]; for (long long i = 0; i < k; i++) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 21; int cnt, u; int sz[1 << MAXN], g[1 << MAXN], p[1 << MAXN]; long long int f[1 << MAXN], h[1 << MAXN]; inline long long int read() { register long long int num = 0, neg = 1; register char ch = getchar(); while (!isdigit(ch) && ch !...
#include <bits/stdc++.h> using namespace std; const long long NMAX = 300000 + 5; const long long inf = 922337203685477580LL; vector<vector<pair<long long, long long> > > g(NMAX); vector<vector<int> > id(NMAX); long long dis[NMAX]; long long last[NMAX]; long long a[NMAX]; int main() { int n, m; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long mod = 1e18; long long fast_pow(long long b, long long p) { if (p == 0) return 1; long long m = fast_pow(b, p / 2); m = ((m % mod) * (m % mod)) % mod; if (p % 2 == 1) m = ((m % mod) * (b % mod)) % mod; return m; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, p, x, y; int a[1010], b[1010]; int i, j; while (scanf( %d%d%d%d%d , &n, &k, &p, &x, &y) != EOF) { int sum = 0; for (i = 0; i < k; i++) { scanf( %d , &a[i]); sum += a[i]; } if (sum > x) { ...
#include <bits/stdc++.h> using namespace std; map<int, int> mm; map<int, int>::iterator it; int x[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> v; for (int i = 1; i <= n; i++) cin >> x[i]; for (int i = n; i >= 1; i--) { if...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; pair<long double, long double> st[4 * N]; int n, q; template <typename T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { pair<T, T> res; res.first = a.first + b.first * a.second; res.second = a.second * b.seco...
#include <bits/stdc++.h> using namespace std; const int MAXN = 53; const int MAXM = 53; char mp_cur[MAXN][MAXM]; char mp_end[MAXN][MAXM]; vector<pair<int, int>> ans; int n, m; void podn(int i, int j); void opus(int i, int j) { if (mp_cur[i][j + 1] == L ) { podn(i, j + 1); } ans.push...
#include <bits/stdc++.h> namespace solution { class ISolution { public: virtual void init(){}; virtual bool input() { return false; }; virtual void output(){}; virtual int run() = 0; }; } // namespace solution namespace solution {} namespace solution { using namespace std; const int ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a = 1, b = 2, flag = 0; cin >> n; long long int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { if (arr[i] == 1 && (a == 1 && b == 2)) { b = 3; } else if...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); printf( %d n , (n + 1) / 2); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; ; int bit; cin >> bit; ; int sum = 0; bool test = false; for (int i = 1; i < n; i++) { int h; cin >> h; ; bit -= (h + 1); if (bit < 0) { cout << NO ; return ...
#include <bits/stdc++.h> using namespace std; template <typename T> T POW(T b, T p) { T r = 1; while (p) { if (p & 1) r = (r * b); b = (b * b); p >>= 1; } return r; } template <typename T> T BigMod(T b, T p, T m) { T r = 1; while (p) { if (p & 1) r = (r * b) %...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; if (n == 3) { cout << >vv << endl << ^<. << endl << ^.< << endl; cout << 1 << << 3; } if (n == 5) { cout << >...v << endl << v.<.. << endl << ..^.. << endl ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; int count25 = 0; int count50 = 0; int ans = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 25) { count25++; } else if (arr[i] == 50) { if (count25 > 0)...
#include <bits/stdc++.h> using namespace std; const int N = 600005; const long long mod = 1000000000000000003; char str[N]; long long f[N]; unordered_set<long long> st; int main() { f[0] = 1; int n, m; for (int i = 1; i < 600000; i++) f[i] = f[i - 1] * 3 % mod; cin >> n >> m; while (n-...
#include <bits/stdc++.h> using namespace std; const long long N = 2e6 + 5; long long mod = 1e9 + 7, bas = 31; long long h[2][N], pw[N], cnt[N]; char c[N]; long long n, q; long long query(long long l, long long r, long long op) { return ((h[op][r] - h[op][l - 1] * pw[cnt[r] - cnt[l - 1]]) % mod + mod) ...
#include<bits/stdc++.h> using namespace std; #define endl n int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin>>t; while(t--) { long long int n,i,j,k,l; cin>>n>>k; if(k==1) { cout<< 1 <<endl; co...
#include <bits/stdc++.h> using namespace std; void doRoutine() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } bool isInside(pair<long long int, long long int> p, pair<long long int, long long int> a[]) { return (p.first >= a[0].first) && (p.second >= a[0].second) ...
#include <bits/stdc++.h> using namespace std; int n, m, k, x; int bot[100001]; int top[100001]; int mir[101]; int hr, hl; int uuh, bbh, ubh, buh; int L = 100000; double eps = 0.00001; int mxr; int sco(int s, bool up) { int res = 0; int dh = ((s % 2) ? (up ? uuh : bbh) : (up ? ubh : buh)); ...
#include <bits/stdc++.h> int main() { int n, i, s = 0, m = 0, t; int a[100001]; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , a + i); s += a[i]; } t = a[0]; if (t > m) m = t; for (i = 1; i < n; i++) { if (t > 0) t += a[i]; else t = a[i];...
#include <bits/stdc++.h> using namespace std; const int N = 200000; int a[N], n, m, k; int check(int x) { int cnt = 1, space = k; for (int i = x; i < n; i++) { if (a[i] <= space) space -= a[i]; else { if (cnt == m) return 0; ++cnt, space = k - a[i]; } } ...
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false), cin.tie(0) #define debug(a) cout << #a : << a << endl using namespace std; typedef long long ll; const int N = 1010; int a[N][N], b[N][N], mov[3], loc[3]; int main(void){ IOS; int T; cin >> T; while (T--){ int...
#include <bits/stdc++.h> using namespace std; const long long int N = 200005; const long long int mod = 1e9 + 7; long long int n, i, j, m, k; long long int a[N]; long long int sz[N], c[N]; long long int vis[N]; vector<long long int> g[N]; long long int ans = 0; void dfs(long long int v, long long in...
#include <bits/stdc++.h> using namespace std; template <class T> bool checkMin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool checkMax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } const int INF = 1e9; const i...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; set<int> s; for (int i = 0; i < n; i++) { int a; cin >> a; s.insert(a);...
#include <bits/stdc++.h> using namespace std; long long Seg[3][1 << 21 + 2], X, Cnt = 1; pair<long long, int> P[1000001]; int l_q, r_q, Len; long long RSQ(int l, int r, int root) { if (l > r_q || l_q > r || l > r) return 0; if (l >= l_q && r <= r_q) return Seg[Len][root]; int mid = (r + l) / 2; ...
#include <bits/stdc++.h> using namespace std; long long ans; int a[305], b[305], c[305], dp[150005], DP[150005], i, j, k, n, m, d, l, r, J, MIN; struct node { int x; int y; }; node st[150005]; int main() { scanf( %d%d%d , &n, &m, &d); for (i = 1; i <= m; i++) { scanf( %d%d%d , ...
#include <bits/stdc++.h> int main(void) { int n; while (scanf( %d , &n) != EOF) { int k = 0, flag = 0, su; for (int i = 9; i >= 0; i--) { if (i == n && i != 1) continue; if (n % i == 0) { k = n / i; su = i; break; } } if (flag == 0)...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops ) #pragma GCC target( avx,avx2,fma ) using namespace std; template <typename T> using vc = vector<T>; template <typename T> using uset = unordered_set<T>; template <typename A, typename B> using umap = unordered_map<A, B>; template <t...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; int n, m; vector<vector<pair<int, int>>> adj; vector<int> dist, color; void bfs(int v) { queue<int> q; q.push(v); while (!q.empty()) { int u = q.front(); q.pop(); for (auto it : adj[u]) { int to = it...
#include <bits/stdc++.h> using namespace std; vector<long long> a; vector<long long> dp(2001); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t = 1; long long n, k, x, temp; 2000000001LL; while (t--) { cin >> n >> k; for (int i = 0; i < n; i...
#include <bits/stdc++.h> using namespace std; string r, s, t, u; int mini; int main() { int i, j, k; cin >> r >> u; int n, m = u.size(); mini = INT_MAX; s = ; for (i = 0; i < m; i++) s.append( 0 ); s.append(r); for (i = 0; i < m; i++) s.append( 0 ); n = s.size(); for (i...
#include <bits/stdc++.h> using namespace std; int main() { int n; int p = 0, q = 0; cin >> n; int ar[n]; for (int i = 0; i < n; i++) { cin >> ar[i]; } for (int i = 0; i < n; i++) { if (ar[i] == 5) p++; else q++; } int r = p / 9; if (q == 0) ...
#include <bits/stdc++.h> using namespace std; const int M = 100100; long long mabs(long long x) { return x < 0 ? -x : x; } int n, m; long long a[M], h[M]; long long q[M], c[M], qf, qs, sum; void read() { cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> h[i]; } for (int i = 0; i + ...
#include <bits/stdc++.h> using namespace std; using namespace rel_ops; const double PI = acos((double)-1); int ts, ts2, ts3, ts4; int n, m; long long gcd(long long x, long long y) { long long t; for (; y != 0;) { t = x % y; x = y; y = t; } return x; } class point { p...
#include <bits/stdc++.h> using namespace std; struct edge { int src, dst; }; int const MOD = 1000000007; long long _MOD = 1000000009; double EPS = 1e-9; long long INF = LLONG_MAX / 2; int main() { int N, w; cin >> N >> w; vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; long long exp(long long a, long long n) { if (n == 0) return 1; long long residue = 1, result = a % 1000000007LL; while (n > 1LL) { if (n % 2LL == 1LL) residue = residue * result % 1000000007LL; result = result * result % 1000000007LL; n = ...
#include <bits/stdc++.h> #pragma GCC target( avx,tune=native ) using namespace std; template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << [ ; for (auto const &vv : V) os << vv << , ; os << ] ; return os; } template <class L, class R> ostream &operator<<(ostream &os, p...
#include <bits/stdc++.h> #pragma GCC optimize( O3 , unroll-all-loops ) #pragma GCC target( sse4.2 ) using namespace std; ifstream in; ofstream out; const long long kk = 1000; const long long ml = kk * kk; const long long mod = ml * kk + 7; const long long inf = ml * ml * ml + 7; mt19937 rng(chrono:...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y; cin >> n >> m >> x >> y; vector<vector<int>> chessboard(n, vector<int>(m)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) chessboard[i][j] = 0; cout << x << << y << endl; chessboard[x - 1][y - 1] =...
#include <bits/stdc++.h> using namespace std; int main() { vector<string> strs; int n = 0; int j = 0; int count = 0; cin >> n; for (int i = 0; i < n; i++) { if (i != 0) { string temp = ; cin >> temp; } string str1 = ; string str2 = ; string...
#include <bits/stdc++.h> using namespace std; const int N = 3e2 + 5; int n; long long hx, hy; long long ux, uy; struct line { long long x1, y1; long long x2, y2; line(long long _x1, long long _y1, long long _x2, long long _y2) { x1 = _x1; y1 = _y1; x2 = _x2; y2 = _y2; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int n, t, num, x; long long int ans; cin >> n; vector<int> vect; vect.push_back(0); for (int i = 0; i < n; ++i) { cin >> x; vect.push_back(x); }...
#include <bits/stdc++.h> void err() { std::cout << std::endl; } template <typename T, typename... Args> void err(T a, Args... args) { std::cout << a << ; err(args...); } template <template <typename...> class T, typename t, typename... A> void err(const T<t> &arg, const A &...args) { for (aut...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; int cnt = 1; if (k & 1) puts( 1 ); else { do { k /= 2; cnt++; } while (k % 2 != 1); cout << cnt; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, root; vector<vector<int> > tree, par, sub; vector<vector<long long> > dp; void dfs(int u) { sub[root][u] = 1; for (int v : tree[u]) { if (v == par[root][u]) continue; par[root][v] = u; dfs(v); sub[root][u] += sub[root][v]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, i, j, k, l, m, b, t, sum, sum1, flag, max1, min1, tmp; cin >> n; long long a[n + 1]; vector<long long> v; queue<long long> q; for (i = 1; i <= n; i++) { cin ...
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; cin >> n; map<string, int> mp; mp[ Tetrahedron ] = 4; mp[ Cube ] = 6; mp[ Octahedron ] = 8; mp[ Dodecahedron ] = 12; mp[ Icosahedron ] = 20; while (n--) { string s; cin >> s; sum += mp[s]...
#include <bits/stdc++.h> using namespace std; double A[100], B[100]; int main() { int n, V; cin >> n >> V; double S = 0.0; for (int i = 0; i < n; i++) { cin >> A[i]; S += A[i]; } for (int i = 0; i < n; i++) A[i] *= V / S; double MIN = 1.0; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; map<char, int> m; map<char, int> m1; int main() { long long int n = 0, d, i = 0, j = 0, l = 0, r = 0, a = 0, b = 0, c1, c2, p, b2, s1 = 0, t = 0, t1 = 0, y = 0, x = 0, s2 = 0, c = 0; char ch; cin >> a >> b >> c; vector<int> adj[1000...
#include <bits/stdc++.h> using namespace std; template <typename T> void mnm(T &a, T b) { a = min(a, b); }; template <typename T> void mxm(T &a, T b) { a = max(a, b); }; template <typename T> int discrete_id(vector<T> &vals, T val, int startId = 1) { return startId + (int)(lower...
#include <bits/stdc++.h> using namespace std; bool f1(pair<long long, long long> x, pair<long long, long long> y) { return x.first > y.first; } bool f2(pair<long long, long long> x, pair<long long, long long> y) { return x.second > y.second; } bool f3(long long x, long long y) { return x > y; } bo...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, -1, 0, 1}; long long msum(long long a, long long b, long long m) { return (a % m + b % m) % m; } long long msub(long long a, long long b, long long m) { return (a % m -...
#include <bits/stdc++.h> using namespace std; int dp[500005][28]; int ar[500005]; int p[500005][28]; int ans[500005]; string st; int main() { int a, b, c, d, e, x, y, z, k, n; cin >> n >> k; cin >> st; for (a = 0; a < n; a++) ar[a + 1] = st[a] - A ; for (a = 1; a <= n; a++) { fo...
#include <bits/stdc++.h> using namespace std; vector<int> tree[300001]; int cento[300001]; int sub[300001]; int maxCh[300001]; int n, q; void dfs(int u, int p = -1) { sub[u] = 1; maxCh[u] = 0; for (int j = 0; j < tree[u].size(); ++j) { int v = tree[u][j]; if (v == p) continue; ...
#include <bits/stdc++.h> using namespace std; const int N = 400005; int tr[N << 2], lz[N << 2]; set<int> st[N]; inline void push(int v, int l, int r) { tr[v] += lz[v]; if (l != r) { lz[2 * v] += lz[v]; lz[2 * v + 1] += lz[v]; } lz[v] = 0; } void build(int v, int l, int r, int n...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int mod = 998244353; long long qpow(long long a, long long b) { long long ans = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) ans = ans * a % mod; a = a * a % mod; } return ans; } ...
#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 n; long long b[200005]; long long cnt[65]; vector<long long> vec, vec2; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long N = 1e5 + 1; const long long mod = 1e9 + 7; const long double eps = 1E-7; vector<int> a[N]; int n, k, x, ans; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; for (int i = 1; i <= k; i++) cin >>...
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } signed main() { fast_io(); long long x, y, z, t1, t2, t3; cin >> x >> y >> z >> t1 >> t2 >> t3; long long time1 = abs(y - x) * t1; long long time2 = abs(x -...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[1000001]; int b[1000001], ans[1000001]; int main() { int n, h; cin >> n >> h; for (int i = 0; i < n; i++) { int c; cin >> c; a[i] = make_pair(c, i + 1); } sort(a, a + n); for (int i = 0; i < n; i++) b[i] = a...
#include <bits/stdc++.h> using namespace std; int power(int x, int y, int p) { int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { { ios_base::sync_with_stdio(0...
#include <bits/stdc++.h> using namespace std; int main() { string second; int ans = 0, a = 1; cin >> second; int k = second.length() - 1; for (int i = 1; i < second.size(); i++) { ans += (1 << i); } for (int i = 0; i < second.length(); i++) { if (i == k) { if (second[...
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; const int MAXN = 500117; int n, a[MAXN], ans; int main() { scanf( %d , &n); for (int i = 0; i < n; scanf( %d , &a[i++])) ; int j = 0, cur = 0; for (int i = 1; i < n - 1; i++) { if (a[i] != a[i - 1] && a[i] ...
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0; bool ne = 0; for (int i = 0; i < 5; i++) { int x; cin >> x; sum += x; } if (sum % 5 != 0 or sum == 0) { cout << -1 ; } else cout << sum / 5; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, q; char s[N]; int t[26][4 * N]; int c[26][4 * N]; int d[26]; void pushDown(int id, int p, int l, int r, int m) { if (c[id][p] == 0) { t[id][p << 1] = 0; t[id][p << 1 | 1] = 0; c[id][p << 1] = 0; c[id][...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native ) #pragma comment(linker, /STACK:256000000 ) using namespace std; mt19937 rd( (unsigned int)chrono::steady_clock::now().time_since_epoch().count()); const int ...
#include <bits/stdc++.h> int n, a[200010]; int main() { scanf( %d , &n); for (int i = 0; i < n * 2; i++) scanf( %d , a + i); std::sort(a, a + n * 2); long long ans = (a[n - 1] - a[0]) * 1ll * (a[n * 2 - 1] - a[n]), tmp; for (int i = 0; i < n; i++) if ((tmp = (a[n * 2 - 1] - a[0]) * 1ll * (...
#include <bits/stdc++.h> using namespace std; int n, p, c, t, sum = 0, res = 0, m, x = 0, y = 0; vector<int> v, z; int main() { cin >> n >> c; for (int i = 0; i < n; ++i) { cin >> p; v.push_back(p); } for (int i = 0; i < n; ++i) { cin >> t; z.push_back(t); } m = n...
#include <bits/stdc++.h> using namespace std; const long long INF = 10000000000000000; const int maxN = 1000 + 10; const int maxM = 20000 + 10; long long d1; int er[maxM]; vector<int> paths1; struct Edge { int from, to; long long dist; }; struct HeapNode { long long d; int u; boo...
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > *e; int *parent; set<int> *v; int fp(int a) { if (parent[a] != a) parent[a] = fp(parent[a]); return parent[a]; } void dsu(int a, int b) { a = fp(a); b = fp(b); if (a != b) { if (v[a].size() < v[b].size()) swap(a, ...
#include <bits/stdc++.h> using namespace std; int main() { map<pair<long long int, long long int>, long long int> m; long long int ans = 0; long long int n, count = 0; cin >> n; string s; for (int i = 1; i <= n; i++) { int l = 0, r = 0; cin >> s; for (int j = 0; j < s.lengt...
#include <bits/stdc++.h> using namespace std; int seq[100]; int ans; vector<string> in; void solve(int k, int l) { if (k <= l) { vector<int> buf(in.size()); for (int i = 0; i < (int)in.size(); ++i) { buf[i] = 0; } for (int i = 0; i < (int)in.size(); ++i) { for (int ...
#include <bits/stdc++.h> using namespace std; int M = 1000000007; long long n, m; void solve() {} void test() { long long n; cin >> n; vector<int> a(n); int count[101] = { 0, }; for (long long i = 0; i < n; i++) { cin >> a[i]; count[a[i]]++; } bool flag = 1;...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const long long inf = 1e9 + 5; int n, m, a[maxn], b[maxn], nxt[maxn], prv[maxn]; long long gt, ct[maxn]; pair<int, int> sa[maxn]; set<pair<long long, int> > cross; long long up(long long x) { return x + (n - x % n) % n; } long lon...
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) { ans = (ans * a); } a = (a * a); b >>= 1; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, k, l[N], r[N], f[2][N], q[N]; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= k; ++i) scanf( %d%d , &l[i], &r[i]); f[0][0] = 0; for (int i = 1; i <= (n << 1); ++i) f[0][i] = 0x3f3f3f3f; for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, x[100005]; cin >> n; for (int i = 1; i <= n; i++) cin >> x[i]; sort(x + 1, x + 1 + n); for (int i = 2; i <= n; i++) if (x[i - 1] * 2 > x[i] && x[i - 1] != x[i]) return cout << YES , 0; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool ylmin(T &a, T b) { return a < b ? 0 : (a = b, 1); } template <class T> inline bool ylmax(T &a, T b) { return a > b ? 0 : (a = b, 1); } template <class T> inline T abs(T x) { return x < 0 ? -x : x; } inline cha...
#include <bits/stdc++.h> using namespace std; int temp, i, j, k, T; long long pow_r(long long d, long long n) { long long x = 1ll; while (n > 0) { if (n & 1) x = (x * d); d = (d * d); n >>= 1; } return x; } int n, da[6], db[6]; pair<int, pair<int, int> > a[8]; int dist(in...
#include <bits/stdc++.h> using namespace std; const int p = 1e9 + 7; inline int read() { int neg = 1, num = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) neg = -1; for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c - 0 ; return neg * num; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 150; const double eps = 1e-8; struct point { double x, y; point() {} point(double _x, double _y) : x(_x), y(_y) {} friend bool operator<(const point &a, const point &b) { if (fabs(a.x - b.x) < eps) { return a.y < b.y; ...
#include <bits/stdc++.h> using namespace std; bool prime(int x) { int cnt = 0; for (int i = 1; i <= x; i++) if (x % i == 0) cnt++; return (cnt <= 2); } void fl() { fflush(stdout); } int kul[] = {4, 9, 25, 49}; char odg[5]; int main() { int prosti = 1; for (int i = 0; i < 4; i++) ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename T1> ostream &operator<<(ostream &out, pair<T, T1> obj) { out << ( << obj.first << , << obj.second << ) ; return out; } template <typename T, typename T1> ostream &operator<<(ostream &out, map<T, T1> cont) { typenam...
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535; double squared(double n) { return n * n; } typedef struct { int cx; int cy; int r; int R; } circle_t; bool isBlack(double x, double y, circle_t c) { double val = squared(x - (double)c.cx) + squared(y - (double)...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; scanf( %d%d , &n, &x); int i, j, ans = 0; int a1[100002], a2[100002]; for (i = 1; i <= n; i++) { scanf( %d%d , &a1[i], &a2[i]); ans = ans + (a2[i] - a1[i] + 1) + (a1[i] - a2[i - 1] - 1) % x; } printf( %d n ,...
#include <bits/stdc++.h> int i, j, k, n, m, a[128][128], z, x, y, t, s, l, b, A, v[128][128], f[256][128], g[256][128], X[] = {0, 1, 0, -1}, Y[] = {1, 0, -1, 0}; char u[128][128]; char p[] = 0123456789abcdefghijklmnopqrstuvwxyz ; void dfs(int x, int y, int d) { for (int i = 0; i < 4; ++i) { t =...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int M = 1e3 + 10; const long long mod = 1e9 + 7; const long long inf = 1e18 + 10; int a[N], st[N], ft[N], ind[N], lzy[4 * N], t, n, m; vector<int> adj[N]; bitset<M> seg[4 * N], P, res, one; void dfs(int v, int p) { st[v] =...
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr i...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while ((c < 0 || c > 9 ) && (c != - )) c = getchar(); if (c == - ) f = -1, c = getchar(); while (c >= 0 && c <= 9 ) x = x * 10 + c - 0 , c = getchar(); return x * f; ...
#include <bits/stdc++.h> using namespace std; map<long long, long long> m1; long long query(long long a, long long b) { long long ans = 0; while (a != b) { if (a > b) { ans += m1[a]; a = a / 2; } else { ans += m1[b]; b = b / 2; } } return ans; } ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 400 + 5; int n = 0, m = 0; int dp[N][N] = {}; int c[N][N] = {}, smc[N] = {}; int ans = 0; int main(){ cin >> n >> m; dp[0][0] = 1; for(int i = 0 ; i <= n + 1 ; i ++) for(int j = 0 ; j <= i ; j ++){ if...
#include <bits/stdc++.h> using namespace std; const int maxn = 100003; int l[maxn], r[maxn], L, R, K, n, cnt[maxn][30], sum[30], A[30], B[30]; char c[maxn], s[maxn]; int List[30][maxn], a[maxn], len[maxn], tot = 0; inline int get() { int f = 0, v = 0; char ch; while (!isdigit(ch = getchar())) ...
#include <bits/stdc++.h> using namespace std; int n; int m; struct Edge { int x; int y; int t; Edge(int x, int y, int t) : x(x), y(y), t(t) {} void print() { cout << x << << y << << t << endl; } }; vector<Edge> edges; vector<int> edge_idx[200005]; int in_digree[200005]; que...
#include <bits/stdc++.h> using namespace std; constexpr long long MOD = 1e9 + 7; constexpr long double EPS = 0.0 + 1e-6; void YES() { cout << YES << n ; } void NO() { cout << NO << n ; } bool search(const string& s, long long i, const string& t, long long j, ...
#include <bits/stdc++.h> using namespace std; int n, m; int counter = 0; int ans = 0; vector<int> L[500000]; bool visited[500000]; bool cat[500000]; int main() { int a, b, k1, k2; deque<int> q1, q2, t1, t2; set<pair<deque<int>, deque<int> > > st; scanf( %d , &n); scanf( %d , &k1); ...
#include <bits/stdc++.h> using namespace std; void start() {} vector<long int> g[200007]; map<long int, bool> vis; long int siz = 0; void dfs(long int x) { vis[x] = 1; siz++; for (auto i : g[x]) { if (!vis[i]) { dfs(i); } } return; } double dist(long int x, long i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; vector<int> G[1000010]; int a[MAXN], s[MAXN], L[MAXN], R[MAXN]; int n, k; long long ans; int query(int k, int l, int r) { return upper_bound(G[k].begin(), G[k].end(), r) - lower_bound(G[k].begin(), G[k].end(), l); } ...