func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 1e9; const long long N = (1 << 20); long long mod_expo(long long a, long long b, long long c) { long long ans = 1; while (b) { if (b & (long long)1) ans = (ans * a) % c; a = (a * a) % c; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; vector<string> vec_splitter(string s) { s += , ; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find( , ))); s = s.substr(s.find( , ) + 1); } return res; } void debug_out(vector<stri...
#include <bits/stdc++.h> using namespace std; int num[100010]; int num1[100010]; int a[100010]; int main() { int n; cin >> n; int flag = 0; for (int i = 1; i <= n; i++) { cin >> num[i]; num1[i] = num[i]; } sort(num + 1, num + n + 1); sort(num1 + 1, num1 + n + 1); in...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, int> nrs; for (int i = 0; i < n; i++) { int x; cin >> x; nrs[x]++; } int max_times = nrs.begin()->second; for (auto it : nrs) max_times = max(it.second, max_times); if (max_times > ...
#include <bits/stdc++.h> using namespace std; struct s { long long col, colf, flag; } node[100010 << 2]; void build(int l, int r, int tr) { node[tr].col = node[tr].colf = node[tr].flag = 0; if (l == r) { node[tr].col = l; return; } int mid = (l + r) >> 1; build(l, mid, tr << ...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << { ; string sep; for (const auto &x : v) os << sep << x, sep = , ; return os << } ; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { ...
#include <bits/stdc++.h> using namespace std; long double pi = 3.14159265358979323; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); vector<int> a(100000, 0); vector<int> ans; for (int i = 0; i < (int)n + m; ++i) { if (a[i] < k) { for (int j = 0; j < (int)k - a[i]; ++j) ans...
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } 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(...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; struct node { int num, cnt; node *l, *r, *p, *path; }; typedef node *pnode; const int N = 100003; node tr[N + 1]; pnode tmp[100002]; const pnode pNull = tr + N; inline void upd(pnode v) { if (v == pN...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; long long sz, ans, x, y; string s, str = ; cin >> n >> x >> y >> s; str += s[0]; for (i = 1; i < n; i++) if (s[i - 1] != s[i]) str += s[i]; sz = (long long)str.size(); if (str[0] == 0 ) sz = (sz >> 1L...
#include <bits/stdc++.h> using namespace std; long double dist(long double x1, long double y1, long double x2, long double y2) { long double D = ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)); return sqrt(D); } int main() { const int inf = 1e9; int n; cin >> n; vect...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( no-stack-protector ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( fast-math ) #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native ) using namespace std; int a, b, c, d, e, f, p = 1000000007, base = 15...
#include <bits/stdc++.h> #pragma GCC target( popcnt ) using namespace std; constexpr int siz = 1 << 9 | 1, INF = 0x7f7f7f7f; constexpr int fx[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}}; int n, m, sx, sy, cnt; long long val[9], sum[siz]; int f[21][21][siz]; char c[21][21]; pair<int, int> t[9]; queue<...
#include <bits/stdc++.h> using namespace std; int n, V, offset; int d[1005]; int u[1000005], v[1000005], cnt = 0; inline void print(int u, int v) { ::u[++cnt] = u + offset; ::v[cnt] = v + offset; } int main() { int i, j; scanf( %d , &n); for (i = 1; i <= n; ++i) scanf( %d , d + i); ...
#include <bits/stdc++.h> using namespace std; inline void boost() { ios_base::sync_with_stdio(); cin.tie(0); } const long long MAX = 1e5 + 111; const long long mod = 1e9 + 7; map<string, int> maap; vector<int> g[MAX]; int main() { boost(); int n; bool ans = false; cin >> n; s...
#include <bits/stdc++.h> using namespace std; template <class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os << ( << v.first << , << v.second << ) ; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << [ ; for (int i = int(0); i ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long power(long long a, long long b, long long p) { if (a == 0) return 0; long long res = 1; a %= p; while (b > 0) { if (b & 1) res = (res * a) % p; b >>= 1; a = (a * a) % p; } return res; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; struct Trie { int next[maxn][26], fail[maxn]; int depth[maxn]; vector<int> sons[maxn]; int _dp[maxn][2]; int root, L; int newnode() { for (int i = 0; i < 26; i++) next[L][i] = -1; return L++; } void...
#include <bits/stdc++.h> using namespace std; const int N = 20; const int MOD = (int)1e9 + 7; const int dx[] = {0, -1, 0, 1, 0}; const int dy[] = {0, 0, 1, 0, -1}; struct Matrix { long long mat[N][N]; }; bool blocked[N][N]; int m, n, q; int size; Matrix operator*(const Matrix a, const Matrix b...
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; int a[MAXN]; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int n, i; while (scanf( %d , &n) == 1) { scanf( %d , &a[0]); int temp = a[0]; int mmax = a[0]; for (i = 1; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int n; vector<int> u[100005]; int d[100005]; int a[100005], b[100005], x[100005]; int p[18][100005]; int up[100005], down[100005]; void go(int i, int pr) { p[0][i] = pr; d[i] = d[pr] + 1; for (int j : u[i]) if (j != pr) { go(j, i); ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int MAXX = 2e6 + 10; long long f(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) r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; pair<int, int> a[105]; for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i + 1; } sort(a, a + n); for (int i = 0; i < n / 2; i++) cout << a[i].second << << a[n - i - 1].second <...
#include <bits/stdc++.h> using namespace std; int n, m; vector<string> checkWorks(vector<vector<bool>> arr) { vector<int> row = vector<int>(n, 2); vector<int> col = vector<int>(m, 2); row[0] = 0; for (int j = 0; j < m; j++) { col[j] = arr[0][j]; } bool works = true; for (int i = ...
#include <bits/stdc++.h> using namespace std; int n; int a[100001]; int pmid; int pfromside; char sideequal[50001]; int leftplenty, rightplenty; int ln[100001] = {0}, rn[100001] = {0}; int wn1[100001] = {0}, wn2[100001] = {0}; int possible(int l, int r) { int includemid; int left = l - 1; ...
#include <bits/stdc++.h> using namespace std; long long a[1003]; int main() { long long n, s; cin >> n >> s; long long miner = 0x3f3f3f3f3f3f3f3f; long long sumer = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; sumer += a[i]; miner = min(miner, a[i]); } if (sume...
#include <bits/stdc++.h> using namespace std; template <class T> inline T BMOD(T p, T e, T m) { T ret = 1; while (e) { if (e & 1) ret = (ret * p) % m; p = (p * p) % m; e >>= 1; } return (T)ret; } template <typename T> inline T POW(T B, T P) { if (P == 0) return 1; i...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T sqr(const T& a) { return a * a; } template <typename T> inline int sign(const T& a) { return a < 0 ? -1 : a > 0; } void task(); int main() { task(); return 0; } char dp[21][1 << 5][161050 + 10]; char par...
#include <bits/stdc++.h> using namespace std; void magic() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; ++i) { cin >> arr[i]; } sort(arr, arr + n); cout << min(arr[n - 1] - arr[1], arr[n - 2] - arr[0]) << endl; } int main() { ios_base::sync_with_stdio(false); c...
#include <bits/stdc++.h> using namespace std; long long int is_prime[1000500]; int main() { for (long long int i = 0; i < ((long long int)(1000500)); ++i) if (2 <= i) is_prime[i] = true; for (long long int i = 2; i * i < 1000500; i++) { if (!is_prime[i]) continue; for (long long int j = ...
#include <bits/stdc++.h> using namespace std; long long volume[100001][2]; vector<long long> sell, buy; int main() { long long n, s; cin >> n >> s; for (long long i = 0; i < n; i++) { char a; long long b, c, d; cin >> a >> b >> c; if (a == B ) d = 1; else ...
#include <bits/stdc++.h> using namespace std; long long p[2007], hs[2007]; string q, w; vector<int> k, st, st1, st2; long long hashing(long long z, long long x) { return (hs[x + 1] - hs[z]) * p[q.size() - x + 1]; } void kmp_process() { int g, h; g = 0, h = -1, k[0] = -1; while (g < w.lengt...
#include <bits/stdc++.h> using namespace std; struct vect { int h, p1, p2; }; struct point { int p1, p2; }; int n, mod, nr, t; long long solf; int viz[200005]; point poz[200005]; map<int, vect> h; vector<int> aib[200005]; void precalc() { int i, j, x; for (i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; int ans = 0; string searchS; map<string, int> mp; set<string> st; void getans(string s, int idx) { if (idx == searchS.size()) { if (!st.count(s)) { ans += mp[s]; st.insert(s); } return; } if (searchS[idx] == ? ) { ...
#include <bits/stdc++.h> using namespace std; const int N = 3050; int a[N]; int b[N]; long long dp[N][N]; int main() { int n, m, i, j; long long ans = 0, minPre; scanf( %d , &n); set<int> S; for (i = 1; i <= n; i++) { scanf( %d , &a[i]); a[i] -= i; S.insert(a[i]); }...
#include <bits/stdc++.h> using namespace std; const int MAXN = 150 + 10; void remax(int& x, int y) { if (x < y) { x = y; } } int n; char s[MAXN]; int a[MAXN]; bool read() { if (scanf( %d n , &n) < 1) { return 0; } for (int i = 0; i < (int)n; ++i) { scanf( %d , &a[i ...
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); long long int q; cin >> q; while (q--) { long long int l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2; cout << l1 << << ((l1 != l2) ? l2 : r2) << n ; } }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 3e5 + 10; class SegmentTree { public: long long addv[N * 4]; int ql, qr, qx; void set(int l, int r, int x = 0) { ql = l, qr = r, qx = x; } void add(int l, int r, int o = 1) { if (ql <= l && r <= q...
#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; int main() { long long i, n, x, j, c = 0; cin >> n >> x; if (n >= x) { for (i = 2; i <= n; i++) { if (x % i == 0 && (x / i) <= n) c++; } cout << c + 1 << endl; } else { for (i = 2; i <= n; i++) { if (x % i == 0 && ...
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf( %d , &N); int P; scanf( %d , &P); vector<int> As, Bs; long long SA = 0, SB = 0; for (decltype(N) _i = 0, _n = (N); _i < _n; _i++) { int A; scanf( %d , &A); int B; scanf( %d , &B); As.pu...
#include <bits/stdc++.h> using namespace std; const long long INF = 9e18; const long long N = 2e5 + 5; const long long M = 1e9 + 7; bool chk(vector<long long> a, long long x, long long y) { long long A = 0, B = 0; for (long long i = 2; i < a.size(); i++) if (a[i] > a[i - 1] && a[i] > a[i + 1]) ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(0); cin.tie(0); int q; std::cin >> q; while (q--) { int n; std::cin >> n; std::cout << ((n + 6) / 7) << n ; } return ...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 10, mod = 11092019; int n, m[2], leaf[N][2], dep[N][2], p[16][2][N], pre[N][2], dist[N][N][2], dp[N][2]; vector<int> adj[N][2]; void predfs(int u, int pa, int lst, bool st) { p[0][st][u] = pa; dep[u][st] = dep[pa][st] + 1; pre...
#include <bits/stdc++.h> int n, k, a[100001], is[100001], i, j, sum, ans; int main() { scanf( %d %d , &n, &k); for (i = 0; i < n; i++) scanf( %d , &a[i]); for (i = 0; i < n; i++) scanf( %d , &is[i]); for (i = 0; i < k; i++) sum += a[i]; for (i = k; i < n; i++) if (is[i]) sum += a[i]; a...
#include <bits/stdc++.h> using namespace std; int N, M, ans, S, T, C; pair<int, int> ap; struct edge { int u, v, w, i; bool operator<(const edge &o) const { return w < o.w; } } tmp[30300]; vector<edge> e; vector<pair<int, int>> adj[1100]; int id[1100], lo[1100], tp[1100], ep[1100]; bool art[11...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e6 + 100; int n, m, q; struct Qu { int op, x; } qu[N]; struct Edge { int u, v, w; bool operator<(const Edge& t) const { return w < t.w; } } edge[N]; struct Max { int val, pos; Max() {} Max(...
#include <bits/stdc++.h> using namespace std; unsigned long long part[4001]; unsigned long long pmod(unsigned long long n, int exp) { unsigned long long x = 1, y = n; while (exp > 0) { if (1 == (exp % 2)) { x = x * y; if (x > 1000000007) x = x % 1000000007; } y = y * y; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, last = 1; cin >> n >> a >> b; if (a > 0 && a > n - 2) { cout << -1; return 0; } cout << last; for (int i = 1; i < n; i++) { cout << ; if (b) { last <<= 1; cout << last; ...
#include <bits/stdc++.h> using namespace std; int sz[100005]; long long pw[100005]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; sz[a]++; sz[b]++; } int lf = 0; for (int i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); long long ss4 = 0, ss7 = 0, swap = 0; string s, t; cin >> s >> t; for (long long i = 0; i < s.length(); i++) { if (s[i] != t[i] && s[i] == 4 ) { if (ss7) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; set<int> ase; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &x); if (ase.size() >= x) { ase.insert(x); } else { cout << i << endl; return 0; } } cout << -1 << en...
#include <bits/stdc++.h> using namespace std; int n, m, half; long long k, ans = 0, a[25][25]; map<long long, int> mp[20][20]; void calcf(int x, int y, long long val, int cnt) { val ^= a[x][y]; if (cnt == half) { mp[x][y][val]++; return; } if (x + 1 < n) calcf(x + 1, y, val, cnt + ...
#include <bits/stdc++.h> using namespace std; template <typename T> T sqr(T x) { return x * x; } inline unsigned long long bit(int num) { return 1ull << num; } long long FindXor(long long r) { long long rem = r % 4; switch (rem) { case 0: return r; case 1: return 1; ...
#include <bits/stdc++.h> using namespace std; int gi() { char ch = ! ; int res = 0, f = 0; while (ch < 0 || ch > 9 ) { ch = getchar(); if (ch == - ) f = 1; } while (ch >= 0 && ch <= 9 ) res = res * 10 + ch - 0 , ch = getchar(); return f ? -res : res; } const int N = ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int ar[100000], br[10000]; memset(br, 0, sizeof(br)); for (long long int i = 1; i <= n; i++) { cin >> ar[i]; br[ar[i]]++; } sort(ar + 1, ar + n + 1); if (n == 1) { cout <...
#include <bits/stdc++.h> using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << = << h << n ; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != , ) cerr << *sdbg++; cerr << = << h << , ; _dbg(sdbg + 1...
#include <bits/stdc++.h> using namespace std; void solve() { int x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; cout << 3 << endl; cout << x2 - x1 << << y3 - y1 << endl; cout << x1 - x2 << << y3 - y2 << endl; cout << x2 - x3 << << y1 - y3 << endl; } void sol...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; long long n = s.length(); char ch = z ; for (long long i = 0; i < n; i++) { if (ch < s[i]) cout << Ann n ; else { ...
#include <bits/stdc++.h> using namespace std; int abslt(int n) { if (n < 0) return -n; else return n; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n + 1]; int i; for (i = 1; i <= n; i++) cin >> arr[i]; arr[0] = arr[1];...
#include <bits/stdc++.h> using namespace std; int main() { int n, s, cnt = 0; cin >> n >> s; int arr[100]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (int i = 0; i < n - 1; i++) s -= arr[i]; if (s >= 0) { cout << YES << endl; } else { ...
#include <bits/stdc++.h> using namespace std; int main() { int q; long long int a, b, c; cin >> q; while (q--) { cin >> a >> b >> c; cout << (a + b + c) / 2 << n ; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 9; struct node { int id; long long t; bool operator<(const node &A) const { return id > A.id; } } e[maxn]; bool cmp(node a, node b) { return a.t < b.t || a.t == b.t && a.id < b.id; } long long ans[maxn]; int tr[maxn]; void ...
#include <bits/stdc++.h> using namespace std; int n, m, mon_cost; vector<tuple<int, int, int>> friends; const long long oo = 1LL << 60; void solve() { cin >> n >> m >> mon_cost; friends.resize(n); for (int i = 0; i < n; ++i) { int x, k, num; cin >> x >> k >> num; int mask = 0; ...
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; void solve() { int n; cin >> n; vi a(n), b(n); vector<pii> p, q; ...
#include <bits/stdc++.h> using namespace std; int main() { int n = 1000 + 1000 + 1; printf( %d n , n); for (int i = (int)(1); i <= (int)(1000); ++i) printf( %d %d %d %d n , i, 1, i, 2); puts( 1 1 1 2 ); for (int i = (int)(1); i <= (int)(1000); ++i) printf( %d %d %d %d n , i, 1, i, 2)...
#include <bits/stdc++.h> using namespace std; int n, m; long double x; int a[5005]; int mem[5005][5005]; int lis(int ind, int ant) { if (ind >= n) return 0; if (mem[ind][ant] != -1) return mem[ind][ant]; int op1, op2; op1 = op2 = 0; if (ant <= a[ind]) op1 = lis(ind + 1, a[ind]) + 1; ...
#include <bits/stdc++.h> using namespace std; long long bigmod(long long b, long long p, long long n) { if (p == 0) return 1; else if (p % 2 == 0) { long long half1 = bigmod(b, p / 2, n); return ((half1 * half1) % n); } else if (p % 2 == 1) { long long p1 = b % n; long long...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int c, r; cin >> c >> r; bool flag = true; for (int i = 1; i <= c; i++) { if (i & 1) { for (int j = 1; j <= r; j++) { cout << # ; } cout << endl; } else { ...
#include <bits/stdc++.h> using namespace std; const int sMAX = 10010; const int MAX = 114514; const long long bMAX = 1919180; int main() { int t; cin >> t; while (t--) { string zs; cin >> zs; int ans = zs.size() + 1; int m[4] = {0, 0, 0, 0}; for (int i = 0; i < zs.siz...
#include <bits/stdc++.h> using namespace std; int n, k; int f[3001][3001], vis[3001][3001]; char s[3001][3001]; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1); memset(f, 0x3f, sizeof(f)); f[0][1] = f[1][0] = 0; for (int i = 1; i <= n; i++) for ...
#include <bits/stdc++.h> using namespace std; int main() { int n, pos, l, r; while (cin >> n >> pos >> l >> r) { if (l == 1 && r == n) cout << 0 << endl; else if (l == 1) cout << (abs(r - pos) + 1) << endl; else if (r == n) cout << (abs(l - pos) + 1) << endl; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 786433, MAXN = 2000005, LOGN = 18, MAXM = 5005; inline void S(int& n) { n = 0; int ch = getchar(); int sign = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) sign = -1; ch = getchar(); } while (ch >= 0 && ch <= 9...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long dp[21][2001]; long long fact[200001]; long long tcaf[200001]; int pow1(int n, int p) { long long cur, res; cur = n; res = 1; while (p) { if (p & 1) { res *= cur; res %= MOD; } p...
#include <bits/stdc++.h> using namespace std; int dp[15][105][105]; int main() { int n, q, c; int x, y, s; int t, x1, y1, x2, y2; memset(dp, 0, sizeof dp); scanf( %d%d%d , &n, &q, &c); while (n--) { scanf( %d%d%d , &x, &y, &s); dp[s][x][y]++; } for (int i = 0; i < c + 1...
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[100010]; int p[100010]; int cnt; int ans; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 2; i <= n; i++) { p[++cnt] = (a[i] - a[i - 1] - 1); } sort(p + 1, p +...
#include <bits/stdc++.h> using namespace std; const int MX = 3e5; const int LG = 20; struct Query { int i, x, y; bool operator<(Query q) const { if (x != q.x) return x > q.x; return i < q.i; } }; int N, Q; Query query[MX + 10]; int A[MX + 10]; int dp[MX + 10][LG + 10]; int la...
#include <bits/stdc++.h> using namespace std; long long int powmod(long long int a, long long int e) { if (e == 0) return 1; long long int x = powmod(a * a % 1000000007, e >> 1); return e & 1 ? x * a % 1000000007 : x; } set<int> unvis; set<pair<long long int, long long int> > forbid; void dfs(in...
#include <bits/stdc++.h> using namespace std; int main() { int n, sum_even = 0, sum_odd = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { int val; scanf( %d , &val); if (val & 1) return puts( First ), 0; } puts( Second ); }
#include <bits/stdc++.h> using namespace std; long long bigmod(long long a, long long b) { if (b == 0) return 1; if (!(b & 1)) { long long ret = bigmod(a, b / 2); return ((ret % 1000000007) * (ret % 1000000007)) % 1000000007; } else return ((a % 1000000007) * (bigmod(a, b - 1) % 100000...
#include <bits/stdc++.h> using namespace std; int II() { int q; scanf( %d , &q); return q; } long long LII() { long long q; scanf( %lld , &q); return q; } const long long Mx = 100005, K = 22; long long step, jump; long long Rank[K][Mx]; struct info { long long tup[2], indx;...
#include <bits/stdc++.h> using namespace std; int fact[100005]; bitset<100005> p; int cnt[100005]; int best[100005]; int arr[100005]; int bestFactor(int n) { if (fact[n] == 0) { return n; } int curFactor = fact[n]; int bestChildFactor = bestFactor(n / curFactor); if (best[curFact...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int t = 1; cin >> t; while (t--) { string n, k; cin >> n >> k; string A, B, C, other; for (int i = 0; i < n.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { if (j % i == 0 && i * j > n && j < n * i) return cout << j << << i, 0; } } cout << -1; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { int n; cin >> n; vector<long long> v(2 * n); for (int i = 0; i < 2 * n; i++) cin >> v[i]; sort(v.begin(), v.end()); long long ans = (v[n - 1] - v[0]) * (v[2 * n - 1] - v[n]); long long minx = 1e9 + 10; ...
#include <bits/stdc++.h> using namespace std; int facts[1002][3], v[1002]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> facts[i][0] >> facts[i][1] >> facts[i][2]; if (facts[i][0] == 1) { for (int j = facts[i][1]; j < facts[i][2]; ++j) v[j] = 1; ...
#include <bits/stdc++.h> using namespace std; void solve(int cases) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int su = 0; for (int i = 0; i < n; i++) su += a[i]; sort(a, a + n); if (su == 0) { cout << NO n ; return; } cout << YES n ; ...
#include <bits/stdc++.h> using namespace std; void solve() { int a, b, c; cin >> a >> b >> c; if (a + c <= b) puts( 0 ); else { int a2 = max(((a + b + c) >> 1) + 1, a); a += c; cout << a - a2 + 1 << endl; } return; } int main() { int T; cin >> T; while...
#include <bits/stdc++.h> using namespace std; const int NN = 111 * 1000; int n, a, d; int t[NN], v[NN]; int main() { ios::sync_with_stdio(false); cin >> n >> a >> d; for (int i = 0; i < n; i++) { cin >> t[i] >> v[i]; } double Max = -1.; for (int i = 0; i < n; i++) { double ...
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; const int oo = 1e9 + 7; const ll loo = 1e18; ll modpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = res * a ...
#include <bits/stdc++.h> using namespace std; const int Size = 1024; const int mod = 998244353; const int INF = 2147483647; const int maxn = 1e5 + 15; int a[maxn]; int main() { int n, x, y, i, f, j; scanf( %d%d%d , &n, &x, &y); for (i = 1; n >= i; i++) { scanf( %d , &a[i]); } for...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ; cerr << endl; } int n, w, b; const long long int mod = 1000000009; int C[4005][4005]; int main() { for (int i = 0; i < 4003; ++i)...
#include<bits/stdc++.h> #define fo(i,a,b) for(int i=(a);i<=(b);++i) #define fd(i,a,b) for(int i=(a);i>=(b);--i) #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) using namespace std; typedef long long ll; const int maxn = 1e6 + 5; const ll mod = 1e9 + 7; int t, m, n, k; vector<int>e[maxn]; ...
#include <bits/stdc++.h> using namespace std; struct IO { char buf[(1 << 20)], *p1, *p2; char pbuf[(1 << 20)], *pp; IO() : p1(buf), p2(buf), pp(pbuf) {} inline char gc() { return getchar(); if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin); return p1 == p2 ? : *p1...
#include <bits/stdc++.h> using namespace std; const int mxN = 1e6; int n, k, a[mxN], l[mxN]; struct dsu { int p[mxN], ld[mxN], lb[mxN]; void init() { iota(p, p + n, 0); iota(lb, lb + n, 0); } int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); } void join(int x, int y) ...
#include <bits/stdc++.h> using namespace std; int n; void result() { set<int> s; s.insert(0); int i = 1; while (i * i <= n) { int d = n / i; s.insert(d); s.insert(n / d); i++; } cout << s.size() << n ; for (auto v : s) { cout << v << ; } cout ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)2E9; const long long LINF = (long long)9E18; const long double PI = acos(-1.0); const long double EPS = 1E-11; template <typename T> inline T sqr(const T x) { return x * x; } template <typename T> T gcd(T a, T b) { return (b ...
#include <bits/stdc++.h> using namespace std; int sub_tern(int c, int a) { int temp_c; int temp_a; int diff; long sum = 0; int three_power = 1; while (c > 0 || a > 0) { temp_c = c % 3; c = c / 3; temp_a = a % 3; a = a / 3; diff = temp_c - temp_a; if (diff ...
#include <bits/stdc++.h> using namespace std; int main() { long n, m; while (cin >> n >> m) { long c = 0; if (n * 2 >= m) { for (int i = 0; i < m; i++) { cout << i + 1 << ; } } else { c = 1; for (int i = 2 * n + 1; i <= m; i++) { cout ...