func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n; int v[200010]; int c[200010]; int ans[200010]; string s; priority_queue<pair<int, pair<int, int> > > pi, pe; int main() { memset(c, 0, sizeof c); cin >> n; for (int i = 0; i < n; ++i) { cin >> v[i]; pi.push({0, {-v[i], i}}); ...
#include <bits/stdc++.h> using namespace std; char a[101]; int main() { int n, i, l; long long int ans = 0; scanf( %s , a); l = strlen(a); for (i = 0; i < l; i++) { if (a[i] == 4 ) a[i] = 1 ; else a[i] = 2 ; } long long int c = 1; for (i = l - 1; i >=...
#include <bits/stdc++.h> const int LEN = 8; const int MASK = (1 << LEN); const int maxn = 240; double f[2][LEN + 1][MASK][2][maxn + 1]; int old, now; double result; int n, original; double add1, time2; void init() { int P; scanf( %d%d%d , &original, &n, &P); time2 = P / 100.0; add1 = 1...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int Mod = 1000000007; char s[1010]; bool dp[1010][2 * 1010][3]; int v[1010]; int pre[1010][2 * 1010][3]; char ch[4]; int main() { int n, m; ch[0] = W , ch[1] = L , ch[2] = D ; scanf( %d %d %s , &n, &m, s + 1); ...
#include <bits/stdc++.h> int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; const double PI = acos(-1), EPS = 1e-7; const int OO = 0x3f3f3f3f, N = 1e6 + 5, mod = 1e9 + 7; using namespace std; long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); } long lon...
#include <bits/stdc++.h> using namespace std; int num[200000 + 5]; int main() { int i, j, k, n, m; cin >> n; long long sum = 0; for (i = 0; i < n; i++) { cin >> num[i]; sum += num[i]; } long long ans = 0; sum++; sum /= 2; for (i = 0; i < n; i++) { ans += num[i...
#include <bits/stdc++.h> using namespace std; queue<int> d[110]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { for (int j = (n / 2) * (i - 1) + 1, g = 1; g <= (n / 2); j++, g++) { d[i].push(j); } } for (int i = 1; i <= n; i++) { for (int j = (n /...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; const int block = 450; int n, p[maxn], l[maxn], cost[maxn], nxt[maxn], f[maxn], g[maxn], aft[maxn], bit[maxn << 2]; void update(int pos, int x) { for (; pos <= n; pos += (pos & -pos)) bit[pos] = max(bit[pos], x); } int get(...
#include <bits/stdc++.h> using namespace std; vector<long long int> f(200005, 0), d(200005, 0), l(200005, 0), r(200005, -1); map<pair<long long int, long long int>, long long int> mp; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int bp...
#include <bits/stdc++.h> using namespace std; vector<int> out[1000]; int main() { int n; scanf( %d , &n); int ans; for (int i = 1; i * (i - 1) / 2 <= n; i++) { ans = i; } int id = 1; for (int i = 0; i < ans; i++) { for (int j = i + 1; j < ans; j++) { out[i].push_bac...
#include <bits/stdc++.h> namespace IO { const long long IN_LEN = 1 << 18 | 1; static char buf[IN_LEN], *s, *t; inline long long Getchar(void) { return s == t && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)), s == t ? -1 : *s++; } template <class T> inline void read(T& x) { static long ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, j, temp, num; stringstream s, t; cin >> a >> b >> n; string out; s << a; num = a; for (j = 0; j < 10; j++) { s << j; s >> temp; if (temp % b == 0) { num = temp; s.clear(); s ...
#include <bits/stdc++.h> using namespace std; int p[1000001]; int main() { int n, ind = 0, w, input; cin >> n; for (int i = 0; i < n; i++) { cin >> input; p[input]++; if (ind < p[input]) { ind = p[input]; w = input; } } cout << w << endl; }
#include <bits/stdc++.h> using namespace std; long long calc_gcd(long long a, long long b) { while (true) if (a) b %= a, swap(a, b); else return b; } void foo() { long long A, M; cin >> A >> M; long long gcd = calc_gcd(A, M); A /= gcd; M /= gcd; set<long l...
#include <bits/stdc++.h> using namespace std; long long int fib[51]; vector<long long int> calc(long long int n, long long int k) { vector<long long int> res; if (!n) return res; if (n == 1) { res.push_back(1); return res; } if (k <= fib[n - 1]) { res.push_back(1); vect...
#include <bits/stdc++.h> using namespace std; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << ; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() ...
#include <bits/stdc++.h> using namespace std; int n, k, a[100009], dau, cuoi, d[100009], c[100009], Res; string st; void Input() { cin >> n >> k >> st; for (int i = 0; i < n; ++i) { a[i + 1] = st[i] - a ; } } void Solve() { dau = 1; cuoi = 1; d[0] = 0; c[0] = 0; while ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int c[n], w[m]; for (int i = 0; i < n; i++) cin >> c[i]; for (int i = 0; i < m; i++) cin >> w[i]; int res = 0; int j = 0; for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; const int dr[] = {0, -1, 0, 1, -1, 1, 1, -1}; const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1}; const double eps = 1e-9; template <class T> void print(const vector<T> &v) { ostringstream os; for (int i = 0; i < (int)v.size(); ++i) { if (i) os << ; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; using ll = long long; using db = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; usin...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5000; const int MOD = 1000000007; string mx[MAXN]; int dp[MAXN][MAXN]; int m, n; void mainp() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> mx[i]; for (int i = 0; i < n; i++) for (int j = m - 1; j >= 0; j--) { i...
#include <bits/stdc++.h> using namespace std; using namespace std; vector<long long>::iterator ptr; long long count = 0; long long cache[10004]; long long dp[100005] = {0}; long long cnt[200005] = {0}; long long a[200005] = {0}; long long b[200005] = {0}; long long r[200005] = {0}; long long pr(lo...
#include <bits/stdc++.h> using namespace std; int main() { int a[105], b[105], t, i, k; cin >> t; for (i = 1; i < t + 1; i++) { scanf( %d , &a[i]); } for (i = 1; i < t + 1; i++) { k = a[i]; b[k] = i; } for (i = 1; i < t + 1; i++) { printf( %d , b[i]); } r...
#include <bits/stdc++.h> using namespace std; const long long int MAX = 100000; vector<long long int> great[MAX + 1]; vector<long long int> small[MAX + 1]; vector<long long int> v[MAX + 1]; bool gactive[MAX + 1] = {false}; set<long long int> sactive; long long int sz[MAX + 1] = {0}; struct moves { ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } void dv(vector<int> v) { for (int i = 0; i < v.size(); i++) cout << v[i] << ; } bool check_prime(int a) { for (int i = sqrt(a); i > 1; i--) { if (a % ...
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0; cin >> n; int r = n; int arr[n]; deque<int> d; for (int i = 0; i < n; i++) { scanf( %d , &arr[i]); d.push_back(arr[i]); } sort(arr, arr + n); for (int i = 0; i < n; i++) { if (d[i] == arr[i...
#include <bits/stdc++.h> using namespace std; int main() { int t; long long x, y; cin >> t; for (int i = 1; i <= t; i++) { cin >> x >> y; if ((x - y) >= 2) cout << YES << endl; else cout << NO << endl; } }
#include <bits/stdc++.h> using namespace std; template <class T> int size(const T &x) { return x.size(); } const int INF = ~(1 << 31); const double EPS = 1e-9; const double pi = acos(-1); template <class T> T smod(T a, T b) { return (a % b + b) % b; } int f(char c) { return c - a ; } ch...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; long long ans = 0; for (int i = 0; i < n; ++i) if (b[i] == 1) { ans += a[i]; ...
#include <bits/stdc++.h> using namespace std; using namespace std; long long z = 1000000007; long long gcd(long long a, long long b) { if (a == 0) return b; if (b == 0) return a; return gcd(b, a % b); } long long power(long long a, long long b) { long long res = 1; while (b) { if (...
#include <bits/stdc++.h> const int maxn = 150010; const int INF = 0x3f3f3f3f; using namespace std; vector<int> V; int a[maxn]; long long ans = 0; int ok(int i) { if (i & 1) return a[i] < a[i - 1] && a[i] < a[i + 1]; return a[i] > a[i + 1] && a[i] > a[i - 1]; } int ok2(int i, int j) { int f...
#include <bits/stdc++.h> using namespace std; const long double PI = acosl(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; int a[n][m], ans[n][m]; for (long long i = 0; i < n; i++) for (long long j = 0; j < m; j++) cin...
#include <bits/stdc++.h> using namespace std; long long u, v, p; map<long long, int> M; map<long long, int> pre, pre2; queue<int> x, y; bool in(int val, int rn) { return ((M.find(val) != M.end()) & (((M[val] >> rn) & 1))); } long long modpow(long long x, long long n) { long long res = 1; whi...
#include <bits/stdc++.h> using namespace std; int dp[505][505]; int a[505][505]; int main() { int n; int i, j, k; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i][i]; for (j = i; j <= n; j++) dp[i][j] = j - i + 1; } for (int len = 2; len <= n; len++) { for (i = 1; i + l...
#include <bits/stdc++.h> using namespace std; long long dp[105][105][105]; long long p[105][105]; long long c[105]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { long long n, m, K, k, i, j, num; cin >> n >> m >> K; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int main() { string a, v[6]; cin >> a; for (int i = 1; i <= 5; ++i) { cin >> v[i]; if (v[i][0] == a[0] || v[i][1] == a[1]) { cout << YES n ; return 0; } } cout << NO n ; return 0; ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int n, m, k; cin >> n >> m >> k; vector<pair<int, int> > v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(make_pair(x, i)); } sort(v.begin(), v....
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double EPS = 1e-9; long long dis(pair<long long, long long> a, pair<long long, long long> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } signed main() { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, a, moves = 0; cin >> n; while (n--) { cin >> a; moves += a - 1; moves %= 2; cout << 2 - moves << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; inline int read() { int ans = 0; bool f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == - , ch = getchar(); while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ...
#include <bits/stdc++.h> using namespace std; int main() { string S, S1, S2, S11, S21; getline(cin, S); int N = S.length(); int i, j, k; int t = 0, t3 = 0; for (i = 0; i < N; i++) { if (S[i] != S[N - i - 1] and t3 == 0) { t3 = 1; if (S[i + 1] == S[N - i - 1]) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll llinf = (1ll << 61) - 1; const int inf = 1000000007; int TC = 1, CN, n, r, c[1 << 18 | 5]; signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed); auto...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const long long INF = 0x3f3f3f3f; const double eps = 1e-9; struct P { long double x, y; P() : x(0), y(0) {} P(long double _x, long double _y) : x(_x), y(_y) {} P operator+(P& p) { return P(x + p.x, y + p.y); } P operat...
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = RDLU ; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? YES : NO ); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { assert(y >=...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; int n; struct vec { long long x, y, idx; } a, b; long double pos_ang_with_x_axis(vec a) { long double res = atan2(a.y, a.x) * 180 / acos(-1); if (res < 0) res += 360; return res; } int dot(vec a, vec b) { return a.x...
#include <bits/stdc++.h> using namespace std; long long last = -1; void dfs(long long s, vector<vector<pair<long long, long long>>> grf, vector<long long> &vis, long long &cost) { vis[s] = 1; last = s; for (auto x : grf[s]) { long long v = x.first, d = x.second; if (vis[v] == 0)...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> primes = {2, 4, 3, 9, 5, 25, 7, 49, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int n = 0; for (int i = 0; i < primes.size(); i++) { cout << primes[i] << endl; string s; cin >> s; ...
#include <bits/stdc++.h> using namespace std; long long int n, k, nb, a[1005], b[2005], t = -10000, pos = 0, p, d; long long int save[1005][2005]; long long int time(int i, int j) { if (save[i][j] != -1) return save[i][j]; if (i == n) return 0; if (j == k) return 3e9; return (save[i][j] = min(ti...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, m, t; vector<int> e[maxn]; int ecnt[maxn]; queue<int> q; bool vis[maxn]; int dep[maxn]; int ec[maxn]; bool flag; int f[maxn]; int g[maxn]; int cnt[maxn]; int read() { int x; scanf( %d , &x); return x; ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200001; const long long K = 5; const long long INF = 1e16 + 7; long long n, k, q; long long a[MAXN][K]; long long tree[MAXN << 2][1 << K]; void upd(long long v, long long tl, long long tr, long long p) { if (tl == tr) { for (...
#include <bits/stdc++.h> using namespace std; int main() { int n; int up, down; int people = 0; int max = 0; cin >> n; while (n--) { cin >> up >> down; people = people - up + down; if (people > max) max = people; } cout << max << endl; return 0; }
#include <bits/stdc++.h> using namespace std; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { return (a.first - a.second) > (b.first - b.second); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> hand(...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { if (0) return; cout << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { if (0) return; const ...
#include <bits/stdc++.h> using namespace std; int n, x, dd[270000]; int main() { cin >> n >> x; int limit = (1 << n) - 1; vector<int> Q; Q.push_back(0); for (int i = 1; i <= limit; i++) { if (i == x) continue; if (dd[i]) continue; Q.push_back(i); dd[(i ^ x)] = 1; } ...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int r = n + n - 1; int a = 0; int b = 0; int i; for (i = 0; i < n; i++) { scanf( %d , &a); if (a >= b) { r = r + (a - b); } else { r = r + (b - a); } b = a; } printf( %d , r)...
#include <bits/stdc++.h> using namespace std; int n, m, p, len; int pos[500020]; int Left[500020]; int Right[500020]; string str; void Work() { int t = p; char op; int rt; for (int i = 0; i < m; i++) { cin >> op; if (op == L ) p = Left[p]; else if (op == R ) ...
#include <bits/stdc++.h> using namespace std; unsigned long long F(unsigned long long n) { if (n < 10) return n; unsigned long long nn = n; int firstDig = 0; while (n) { firstDig = n % 10; n /= 10; } return (nn / 10) + 9 - (firstDig > (nn % 10)); } int main() { unsigned l...
#include <bits/stdc++.h> using namespace std; int n; char p[2010], tp[2010]; char q[2010]; vector<int> Res; void Rev(int L) { int i; Res.push_back(L); for (i = n - L; i < n; i++) { tp[n - 1 - i] = p[i]; } for (i = 0; i < n - L; i++) { tp[i + L] = p[i]; } for (i = 0; i...
#include <bits/stdc++.h> using namespace std; void strange(int t) { while (t--) { int n; cin >> n; vector<int> p(n); for (int i = 0; i < n; i++) { cin >> p[i]; p[i]--; } bool g = 1; int MIN = n; for (int i = 0; i < n; i++) { if (p[i] < MIN)...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, a, t; while (cin >> n >> m >> a) { if (m < n) { t = m; m = n; n = t; } if (a >= m) cout << 1 << endl; if ((a < m) && (a >= n)) { if (m % a == 0) cout << m / a << endl;...
#include <bits/stdc++.h> using namespace std; int arr[1003]; int main() { int n, x, ans, sum, t, ck; cin >> t; while (t--) { cin >> n >> x; for (int i = 1; i <= n; i++) cin >> arr[i]; sort(arr + 1, arr + n + 1); ck = 0; for (int i = 1; i <= n; i++) { if (arr[i] ==...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> int ge(const vector<T>& v, T val) { return distance(v.begin(), lower_bound(v.begin(), v.end(), val)); } template <class T> int gt(const vector<T>& v, T val) { return distance(v.begin(), upper_bound(v.begin(), v....
#include <bits/stdc++.h> using namespace std; const int NMAX = 2 * 1e5 + 2; int t, n, valeurs[NMAX]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> t; for (int test = 1; test <= t; test++) { cin >> n; if (n % 4 != 0) { cout << NO n ; } else { int ...
#include <bits/stdc++.h> using namespace std; long long n, k, m; vector<pair<int, int> > v, u; int a, b, c; int main() { cin >> n >> k >> m; a = n; for (int i = 0; i < n; i++) { int w; cin >> w; if (v.size() > 0 && v.back().first == w) { v.back().second++; if (v.b...
#include<iostream> using namespace std; int query(int a, int b) { cout << ? << a << << b << endl; cout.flush(); int ret; cin >> ret; return ret; } int main() { int n; cin >> n; int lt = 1, rt = n; int sec = query(1, n); while (rt - lt > 0) { int mid; if (rt + l...
#include <bits/stdc++.h> using namespace std; long long int fast_expo(long long int x, long long int p) { if (p == 0) return 1; else if (p % 2 == 0) { long long int t = fast_expo(x, p / 2) % 1000000007; return (t * t) % 1000000007; } else return (x * (fast_expo(x, p - 1)) % 10000...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:102400000,102400000 ) const int maxn = 5e5 + 5; struct Point { char ty; int x, y; Point(char ch = 0 , int x = 0, int y = 0) : ty(ch), x(x), y(y) {} } chess[maxn]; int X0, Y0, n; bool solve1() { vector<pair<int, ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ii = pair<ll, ll>; using vi = vector<ll>; using vb = vector<bool>; using vvi = vector<vi>; using vii = vector<ii>; using vvii = vector<vii>; const int INF = 2000000000; const ll LLINF = 90000000000000...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long power(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret *= a; a *= a; if (ret >= MOD) ret %= MOD; if (a >= MOD) a %= MOD; b >>= 1; } return ret; } long l...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int a, b, c, d; cin >> a >> b >> c >> d; long double t = (a * 1.0 / b) * (1.0 / (1 - (1 - a * 1.0 / b) * (1 - c * 1.0 ...
#include <bits/stdc++.h> using namespace std; int const MAX_N = 600100; int const INT_INF = 1000000000; int my_rank[MAX_N], my_parent[MAX_N], diam_ancestor[MAX_N]; int d[MAX_N], och[MAX_N], nnew[MAX_N]; void make_set(int v) { my_parent[v] = v; diam_ancestor[v] = 0; my_rank[v] = 0; } int find...
#include <bits/stdc++.h> using namespace std; char arr[300]; int main() { ios::sync_with_stdio(false); string s, t; cin >> s >> t; int n = s.size(); memset(arr, A , sizeof(arr)); if (n != t.size()) { cout << -1; return 0; } for (int i = 0; i < n; i++) { if (arr[t...
#include <bits/stdc++.h> using namespace std; const long long N = 1110; const long long inf = 1000000007998244353ll; struct S { long long l, r; } a[N * N]; long long si[N][N]; long long tot; long long n, m, k; string s; long long lcp[N][N]; long long dp[N][N]; long long suffix_sum[N]; long...
#include <bits/stdc++.h> char ch; inline void read(int &x) { x = 0; ch = getchar(); while (ch <= 32) ch = getchar(); while (ch > 32) { x = x * 10 + ch - 48; ch = getchar(); }; }; const int dx[8] = {0, 1, 0, -1, -1, -1, 1, 1}; const int dy[8] = {1, 0, -1, 0, -1, 1, -1, 1}; con...
#include <bits/stdc++.h> using namespace std; using ll = long long; bool cmp(pair<ll, ll> a, pair<ll, ll> b) { return a.second > b.second; } bool cmp2(vector<ll> a, vector<ll> b) { return a.size() > b.size(); } int main() { ll n, m; cin >> n >> m; vector<pair<ll, ll>> vp(n); for (ll i = 0; i <...
#include <bits/stdc++.h> using namespace std; const int maxN = 2000; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 1; i <= n; i++) { long long l, r; cin >> l >> r; int ans = 0; long long mn = r; long long cur = 0; int cnt = 0; fo...
#include <bits/stdc++.h> using namespace std; const int N = 1 << 18; int uf[N]; int cost[N]; vector<pair<int, int>> h_uf; vector<pair<int, int>> h_cost; pair<int, int> query[N]; int ans[N]; bool sample; struct edge { int u, v, w; edge(int u, int v, int w) : u(u), v(v), w(w) {} }; vector<...
#include <bits/stdc++.h> using namespace std; const int Maxn = 200010; const int inf = 2147483647; const double pi = acos(-1.0); int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <=...
#include <bits/stdc++.h> using namespace std; vector<long long> Edge[100010]; long long ar[100010]; bool Visit[100010 + 7]; bool InStk[100010 + 7]; long long Low[100010 + 7], I; long long Ind[100010 + 7]; stack<long long> Stk; long long ans1, ans2; void SCC(long long u) { Visit[u] = true; In...
#include <bits/stdc++.h> using namespace std; vector<int> arr; int maxNum = -1; int n; bool vis[1000000 + 50]; int main() { memset(vis, false, sizeof(vis)); scanf( %d , &(n)); for (int i = 0; i < n; i++) { int tmp; scanf( %d , &(tmp)); if (!vis[tmp]) { arr.push_back(tmp...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; int n, a[N * 2], b[N * 2]; pair<int, int> r[N]; int main() { int n, q; scanf( %d%d , &n, &q); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); a[n + i] = a[i]; } while (q--) { long long sum; scanf( %l...
#include <bits/stdc++.h> using namespace std; ofstream fo( test.out ); ifstream fi( test.inp ); int n, m, k, dem; int x[200005], y[200005]; int main() { long long a; cin >> a; for (long long i = 2; i * i <= a; i++) { while (a % (i * i) == 0) a /= i; } cout << a; }
#include <bits/stdc++.h> using namespace std; const int maxn = 205; const int maxm = 4005; int n, m, p, s, t, ss, tt; namespace Flow { int tot, S, T, V; int head[maxn], nxt[maxm * 2], to[maxm * 2], cap[maxm * 2], cost[maxm * 2]; int dist[maxn], parv[maxn], pare[maxn]; bool in[maxn]; queue<int> q; ...
#include <bits/stdc++.h> using namespace std; const int LEN = 100000; struct fastio { int it, len; char s[LEN + 5]; fastio() { it = len = 0; } char get() { if (it < len) return s[it++]; it = 0, len = fread(s, 1, LEN, stdin); return len ? s[it++] : EOF; } bool notend() { ...
#include <bits/stdc++.h> int main() { int a, b, c; scanf( %d%d%d , &a, &b, &c); int x = 30; while (a > 0 || b > 0 || c > 0) { switch (x % 3) { case 0: a -= 2; if (a < 0) a = 0; break; case 1: b -= 2; if (b < 0) b = 0; br...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int n, k, limit, f[1010][1 << 2][2010], sta[1 << 2], ans; int main() { scanf( %d%d , &n, &k); limit = (1 << 2) - 1; sta[0] = 1; sta[1] = 2; sta[2] = 2; sta[3] = 1; for (int i = 0; i <= 3; i++) f[1][i][sta[i]] = ...
#include <bits/stdc++.h> using namespace std; const int N=3e5+10; typedef long long ll; int pos[N],a[N],q,n; void solve() { cin>>n>>q; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=n;i;i--)pos[a[i]]=i; while(q--) { int x; cin>>x; cout<<pos[x]<< ; int t=pos[x]; pos[x]=1;...
#include <iostream> #include <algorithm> constexpr int N = 100005; int n; struct node { long long a, b; } a[N]; int main() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); std::cin >> n; long long ans = 0; for (int i = 1; i <= n; ++i) std::cin >> a[i].a >> a[...
#include <bits/stdc++.h> int n, m, k, flag, ans, cnt, p, q, w[1000005], f[1000005], g[1000005], s[1000005]; int main() { scanf( %d%d%d , &n, &m, &k); w[0] = 1; for (int i = 1; i <= n; i++) w[i] = w[i - 1] * 2 % 1000000007; for (int i = 1; i <= m; i++) { int x, y; scanf( %d%d , &x, ...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int inf = 1 << 30; const int maxn = 100000 + 5; int tot, dfn[maxn << 1], ord[maxn << 1]; namespace hld { const int maxn = ::maxn << 1; struct edge { int to, nxt; } g[maxn]; int head[maxn], ecnt = 0; void add(int x, ...
#include <bits/stdc++.h> using namespace std; int sum[5]; int n; int main() { cin >> n; int res = 0; for (int i = 1; i <= n; ++i) { int t; scanf( %d , &t); if (t) sum[t]++; } int tmp = min(sum[1], sum[2]); sum[3] += tmp; res += tmp; sum[2] -= tmp; sum[1] -= ...
#include <bits/stdc++.h> using namespace std; long long ans, heavy; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> s; for (int i = 0; i <= (int)s.size() - 5; i++) { if (s.substr(i, 5) == heavy ) { heavy++; } else if (s.substr(i, ...
#include <bits/stdc++.h> using namespace std; int K, N; long double XX, YY, P[101], PP, arr[101][101], obj[101][2], EPS = 1e-9; double calk(int n, int k) { if (arr[n][k] != -1) return arr[n][k]; double retAns = 0; if (n == 1 && k == 1) arr[n][k] = P[1]; else if (n == 1 && k == 0) arr...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int N = 5000000; const double eps = 1e-6; int n, l, m, k, a[N], rev[N], res[N]; bool used[N]; complex<double> b[N], tmp[N]; pair<int, int> p[N]; vector<int> ans; void fft(bool invert) { for (int i = 0; i < l; i++) ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-10; const int MOD = 998244353; const int INF = 0x3f3f3f3f; const int maxn = 1e3 + 10; const int maxm = 2e5 + 10; char s[maxn]; int len, arr[maxn]; pair<int, long long> dq[maxn]; int main() { scanf...
#include <bits/stdc++.h> using namespace std; long long ans = 0; int a[200005], n, len = 1 << 18; int mx1[1 << 18], mx2[1 << 18], fa[200005], w1[200005], w2[200005]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void add(int x, int w) { if (find(w) != find(mx1[x]) && a[w] > a[mx1[x]])...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int start = 0, ends = n - 1; while (start != ends) { if (arr[ends] < arr[start]) { reverse(arr + start, arr + ends + 1); break; } el...
#include <bits/stdc++.h> int main() { int n, l; std::cin >> n >> l; int *num = new int[n]; int i; for (i = 0; i < l; i++) { num[i] = i + 97; } while (i < n) { num[i] = num[i - l]; i++; } for (int i = 0; i < n; i++) std::cout << (char)(num[i]); }
#include <bits/stdc++.h> using namespace std; struct comp { double re, im; comp(double x = 0, double y = 0) : re(x), im(y) {} comp operator+(const comp& a) { return comp(re + a.re, im + a.im); } comp operator-(const comp& a) { return comp(re - a.re, im - a.im); } comp operator*(const comp& a) { ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000010LL; const int mod = 1000000007; const int MAXN = 100010; int n, m, u, v, x, y, t, a, b, ans, node, cnt; bool ok[MAXN]; bool mark[M...