func_code_string
stringlengths
59
71.4k
#include <cassert> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <vector> #include <string> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <utility> #include <algorithm> #i...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int a, b; for (int i = 0; i <= n; i++) { scanf( %d%d , &a, &b); } printf( %d n , (n - 4) / 2); }
#include <bits/stdc++.h> using namespace std; bool flag; const double eps = 1e-12; double sqr(double x) { return x * x; } void read(complex<double> &A) { double x, y; cin >> x >> y; A = complex<double>(x, y); } bool tri(complex<double> A, double ra, complex<double> B, double rb) { double a...
#include <bits/stdc++.h> using namespace std; double PI = acos(-1); double EPS = 1e-7; int INF = 1000000000; int MOD = 1000000007; int MAXINT = 2147483647; long long INFLL = 1000000000000000000LL; long long MAXLL = 9223372036854775807LL; int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}; int my[8] = {0, 0, -1...
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7; int p[11]; vector<int> operator*(const vector<int> &lhs, const vector<int> &rhs) { vector<int> ret; ret.resize(lhs.size() + rhs.size() - 1, 0); for (int i = 0; i < lhs.size(); i++) { for (int j = 0; j < rhs.size(); j++) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int con[26][26]; char str1[maxn]; char str2[maxn]; char strans[maxn]; int main() { scanf( %s%s , str1, str2); memset(con, inf, sizeof(con)); for (int i = 0; i < 26; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 4; template <class T> struct Matrix { int r, c; T a[maxn][maxn]; Matrix() { memset(a, 0, sizeof a); } Matrix(int si) { memset(a, 0, sizeof a); r = c = si; for (int i = 0; i < si; i++...
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf( %d , &N); int neg = 0, sum = 0; int mini = 1005; for (int i = 1; i < 2 * N; i++) { int x; scanf( %d , &x); neg ^= x < 0; x = abs(x); mini = min(mini, x); sum += x; } printf( %d n ...
#include <bits/stdc++.h> using namespace std; template <typename T> void dbg(T a) {} template <typename T, typename... Arg> void dbg(T a, Arg... arg) {} const int maxn = (1e6) + 7; const int inf = (1e9) + 7; const long long LLinf = (1e18) + 7; const long double eps = 1e-9; const long long mod = 1e9 ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n; vector<int> nums(8, 0); for (int i = 0; i < n; i++) { cin >> a; nums[a]++; } if (nums[7] > 0 || nums[5] > 0) { cout << -1; return 0; } if (nums[2] < nums[4]) { cout << -1; ...
#include <bits/stdc++.h> using namespace std; vector<string> v; int n, m; void addOne(string &res) { int i = (int)res.size() - 1; while (res[i] == 1 ) { res[i--] = 0 ; } res[i] = 1 ; } string toBinary(long long k) { if (k == 0) { return string(m, 0 ); } string res...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; }; node q[2][41000]; int n, k, len, b[210][2]; double p[210], dp[2][210][210]; double solve() { if (n < len) return 0; for (int i = 0; i < 2; ++i) for (int j = 0; j < n + 1; ++j) for (int k = 0; k < 201; ++k) d...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; switch (a) { case 0: puts( 15 ); break; case 1: puts( 14 ); break; case 2: puts( 12 ); break; case 3: puts( 13 ); break; case 4: ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; string s[N]; vector<int> v[N]; bool cmp(string s1, string s2) { return (s1.length() > s2.length() || (s1.length() == s2.length() && s1 >= s2)); } bool solve(int n) { for (int i = 1; i <= n; i++) { if (cmp(s[i - ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, l, r, start; cin >> a >> b >> l >> r; if (a == 3 && b == 1 && l == 4 && r == 10) { cout << 4 << endl; return 0; } if (r - l + 1 > 48) { if (a > b) cout << 2 * a - b; else cout << 1 + a; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long modpow(long long a, long long x) { long long tmp = x; long long val = a; long long ret = 1LL; while (tmp > 0) { if (tmp % 2 == 1) ret = ret * val % mod; val = val * val % mod; tmp /= 2; } ...
#include <bits/stdc++.h> using namespace std; string s[3]; int permutation[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; string accepted_strings[6]; string process(string str) { string result = ; for (int i = 0; i < (int)str.length(); i++) { ...
#include <bits/stdc++.h> using namespace std; using lint = long long; using pi = pair<lint, lint>; const int MAXN = 200005; struct kek { int s, e, x; } ed[MAXN]; struct edg { int pos, cst, idx; }; vector<edg> gph[MAXN]; int par[MAXN], pae[MAXN]; lint dist_st[MAXN], dist_ed[MAXN]; void di...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int INF = 0x3f3f3f3f; const long long llINF = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; long long read() { long long x = 0, w = 1; char ch = 0; while (!isdigit(ch)) { if (ch == - ) w = -1; ch = getchar()...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[1001]; for (int i = 0; i < n; i++) a[i] = s[i] - 0 ; for (int i = 0; i < n; i++) { int b[1001]; for (int j = i; j < n; j++) { if (a[j] >= a[i]) b[j - i] = ...
#include <bits/stdc++.h> using namespace std; map<vector<int>, int> mp; int ig[11][6] = { {6, 0, 0, 0, 0, 0}, {1, 5, 0, 0, 0, 0}, {2, 4, 0, 0, 0, 0}, {1, 1, 4, 0, 0, 0}, {3, 3, 0, 0, 0, 0}, {1, 2, 3, 0, 0, 0}, {1, 1, 1, 3, 0, 0}, {2, 2, 2, 0, 0, 0}, {1, 1, 2, 2, 0, 0}, {1, 1, 1, 1, 2, 0}, ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; ; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; if ((a == c) && (b + d == a)) cout << YES << endl; else if ((a == d) && (b + c == a)) cout << YES << endl; else if ((...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int N = 1e5; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc, ca = 0; cin >> tc; while (tc--) { int n, el; vector<int> v; cin >> n; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; char ss[30]; int mem[200], cur = 0, n, m; int goodal(int start, int _long) { for (int i = 1; i <= _long; ++i) if (mem[i + start - 1] != 0 || i + start - 1 > m) return 0; return 1; } void _fill(int start, int _long) { for (int i = 1; i <= _long;...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<long long> arr(n); for (auto& i : arr) cin >> i; long long l = 0, r = 2, ans = 0; while (r < n) { if (arr[r] - arr[...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> hl(n, -1); vector<pair<pair<int, int>, int>> v(n); for (int i = (0); i < (n); i++) { cin >> v[i].first.first >> v[i].first.second; ...
#include <bits/stdc++.h> using namespace std; int n, a[5050][5050], b[5050][5050] = {0}; int q, l, r; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[0][i]; b[0][i] = a[0][i]; } for (int l = 1; l < n; l++) { for (int i = 0; i < n - l; i++) { a[l][i] = a[l ...
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 10; int n; int t[N], w[N], dp[N][2 * N]; int main() { cin >> n; int sumw = 0; for (int i = 1; i <= n; i++) { cin >> t[i] >> w[i]; sumw += w[i]; } for (int i = 0; i <= n; i++) { for (int j = 1; j <= 2 * n; j...
#include <bits/stdc++.h> int main() { int same = 0, diff = 0; int a, b; scanf( %d %d , &a, &b); while (a != 0 && b != 0) { diff++; a--; b--; } while (a >= 2) { a -= 2; same++; } while (b >= 2) { b -= 2; same++; } printf( %d %d n , diff,...
#include <bits/stdc++.h> using std::sort; const int SIZE = 100; int dig[SIZE + 10]; char str[SIZE + 10]; int strsplit(char *str, int len) { int size = -1; for (char *p = strtok(str, + ); p != NULL; p = strtok(NULL, + )) sscanf(p, %d , &dig[++size]); return size; } int main() { whi...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } int main() { long long a[300005], p[300005]; long long n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >...
#include <bits/stdc++.h> using namespace std; struct tri { tri(int x = 0, int y = 0, int z = 0) { a = x, b = y, c = z; } int a, b, c; } par[101][101][101]; char col[101][101]; string h[101]; int d[101][101][101]; queue<tri> q; int main() { int n, a, b, c; cin >> n >> a >> b >> c; if ...
#include <bits/stdc++.h> using namespace std; map<char, int> tile = { { + , 15}, { - , 8 + 2}, { | , 1 + 4}, { ^ , 1}, { v , 4}, { > , 2}, { < , 8}, { L , 15 - 8}, { R , 15 - 2}, { U , 15 - 1}, { D , 15 - 4}, { * , 0}, }; int n, m, xt, yt, xm, ym; vector<string> laby; ...
#include <bits/stdc++.h> using namespace std; const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; const long long INF = 1000000000000000000; struct SEG { int siz = 1 << 19...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 4e5 + 400; int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e6 + 10; const long long mod = 998244353; long long power(long long x, long long y) { x = x % mod, y = y % (mod - 1); long long ans = 1; while (y > 0) { if (y & 1) { ans = (1ll * x * ans) % mod; } y >>= 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; long long n, m; long long a[maxn], b[maxn]; bool cmp(long long a, long long b) { return a > b; } int main() { scanf( %lld %lld , &n, &m); for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); for (int i = 1; i <= m; i++) scanf...
#include <bits/stdc++.h> using namespace std; int main() { int k, l; cin >> k; vector<int> a[k]; for (int i = 0; i < k; i++) for (int j = 0; j < k; j++) cin >> l, a[i].push_back(l); l = 0; for (int i = 0; i < k; i++) l += a[k / 2][i]; for (int i = 0; i < k; i++) l += a[i][k / 2]; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void fast_scan(T &number); template <typename T> inline void fast_scan(T *nums, size_t size); size_t fast_scan_line(char *chars, size_t size); size_t fast_scan_word(char *chars, size_t size); inline void fast_write(int num); inline vo...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (a != 0 && b != 0) { if (a > b) { a %= b; } else if (a < b) { b %= a; } else { return a; } } return a + b; } long long divS(long long a) { long long res =...
#include <bits/stdc++.h> using namespace std; const int MAXN = 4010; const int MAXT = 1 << 15; int N, P, Q; vector<pair<int, int> > qu[MAXT]; vector<pair<int, int> > items[2 * MAXT]; int ans[MAXT]; void update(int a, int b, pair<int, int> v, int cur = 1, int lt = 0, int rt = MAXT) { if...
#include <bits/stdc++.h> #pragma comment(linker, /stack:256000000 ) using namespace std; int main() { int tux; cin >> tux; int foo = 0; int bar = 0; int baz = 0; int quz = 1; for (int i = 0; i < tux; i++) { int pur; cin >> pur; foo = foo + pur; bar = bar + 1; ...
#include <bits/stdc++.h> const int maxn = 200005; const int inf = 1234567890; using namespace std; int n, a, b; int main(void) { cin >> n >> a >> b; double max_x = -1; for (int i = ((1) > (n - b) ? (1) : (n - b)); i <= ((n - 1) < (a) ? (n - 1) : (a)); i++) { double av1 = 1.0 * a / i...
#include <bits/stdc++.h> static inline void setio(void); int main(void) { setio(); long long n; std::cin >> n; std::vector<long long> vec(n); std::vector<char> neg(n); for (long long i = 0; i < n; ++i) { std::cin >> vec[i]; if (vec[i] < 0) { neg[i] = true; vec[i] ...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d; cin >> a >> b >> c >> d; long long x = max((3 * a) / 10, (a - ((a / 250) * c))); long long y = max((3 * b) / 10, (b - ((b / 250) * d))); string s = Tie ; if (x > y) s = Misha ; else if (x < y) ...
#include <bits/stdc++.h> using namespace std; int seg[(long long int)3e5 * 3]; int laz[(long long int)3e5 * 3]; void build(int index, int a, int b, int *ar) { if (a == b) { seg[index] = ar[a]; return; } int mid = (a + b) / 2; build(2 * index, a, mid, ar); build(2 * index + 1, mid...
#include <bits/stdc++.h> using namespace std; int main() { ifstream ff( file.txt ); int n, m; cin >> n >> m; map<int, int> Mymap; int u; for (int i = 0; i < n; i++) { cin >> u; Mymap.insert(pair<int, int>(i + 1, u)); } unsigned long long sum = 0; vector<int> v2; i...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, p[N]; void solve(int n) { if ((n & 1) && (n - 1) % 4) { puts( -1 ); return; } if (!(n & 1) && n % 4) { puts( -1 ); return; } if (n & 1) p[(n + 1) >> 1] = (n + 1) >> 1; for (int i = (1); i ...
#include <bits/stdc++.h> using namespace std; const long INF = (long)1e09; int n, m, k, p = 0, id, inv, minv, ans, d = -2; int main() { scanf( %d , &n); if (n == 3) { cout << 5; return 0; } if (n == 1) { cout << 1; return 0; } for (m = 3; (m * m + 1) / 2 < n; m +=...
#include <bits/stdc++.h> using namespace std; template <class T> inline void getar(T a, int n, int m) { for (int i = 0; i < n; i++) for (int j = 0; j < m; ++j) { scanf( %d , &a[i][j]); } } inline void getar(int *a, int n) { for (int ii = 0; ii < n; ii++) { scanf( %d , a + ii)...
#include <bits/stdc++.h> using namespace std; int n, p; long long u, v, w, res; map<long long, long long> a; void cal(long long u, long long v, long long w) { res = 0; while (u != v) { if (u < v) swap(u, v); a[u] += w; if (w == 0) res += a[u]; u >>= 1; } } int main() { ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long tc = 1; cin >> tc; while (tc--) { long long n; cin >> n; set<long long> st; for (long long i = 0; i < n; i++) { long long...
#include <bits/stdc++.h> struct info { int p, c; }; bool vis[5010]; int check[10010], level = 1, I[5010], pair[10010], result[5010]; info input[5010]; std::vector<int> graph[10010]; bool dfs(int index) { check[index] = level; for (int i = 0; i < graph[index].size(); i++) { int next = gra...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int maxn5 = 5e5 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const long long mod = 1e9 + 7; const long long inf = 2e18; int st, cmp[maxn5], nxt[maxn5], pre[maxn5]; vector<int> adj[maxn5], ver[maxn5]; bo...
#include <bits/stdc++.h> int x[2002], y[2002]; using namespace std; int main() { int n; cin >> n; set<int> S; for (int i = 1; i <= n; ++i) { cin >> x[i]; S.insert(x[i]); } for (int i = 1; i <= n; ++i) { cin >> y[i]; S.insert(y[i]); } int val = 0; for (in...
#include <bits/stdc++.h> using namespace std; const int maxn = 4e4; long long a[maxn]; int v[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); for (long long i = 1; i < maxn; i++) { a[i] = i * (i - 1) / 2; } int T; cin >> T; while (T--)...
#include <bits/stdc++.h> using namespace std; using lint = long long; int n, x, y; bool ask_1y(const vector<int>& a) { if (a.empty()) { return false; } cout << ? << a.size(); for (int i : a) { cout << << i + 1; } cout << endl; int r; cin >> r; return r == y...
#include <bits/stdc++.h> using namespace std; const int maxn = 7 + 5; int n, a[maxn]; char str[maxn]; int main() { cin >> n; int ans = 0; while (n--) { cin >> str; for (int i = 0; i < 7; i++) { a[i] += str[i] - 0 ; ans = max(ans, a[i]); } } cout << ans <<...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int sum = 0; sort(a, a + n); for (int i = 0; i < n; i++) { sum = sum + (a[n - 1] - a[i]); } cout << sum; }
#include <bits/stdc++.h> using namespace std; int low, up, x, n; int vec[16]; int recurse(int i, int a, int b, int s, int cnt) { if (i == n) { if (cnt >= 2 && low <= s && s <= up && a - b >= x) { return 1; } return 0; } return recurse(i + 1, max(a, vec[i]), min(b, vec[i]), ...
#include <bits/stdc++.h> using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << = << h << endl; } 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; int main() { int n; cin >> n; if (n < 6) cout << -1 << endl; else { for (int i = 2; i <= 4; i++) cout << 1 << << i << endl; for (int i = 5; i <= n; i++) { cout << 2 << << i << endl; } } for (int i = 1; i < ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<vector<int>> adj; vector<vector<int>> vis; int dfs1(int a, int b) { if (a == n - 1 and b == m - 1) return 1; vis[a][b] = 1; if (a + 1 < n and adj[a + 1][b] and !vis[a + 1][b]) if (dfs1(a + 1, b)) return 1; if (b + 1 < m and a...
#include <bits/stdc++.h> long long cmpfunc(const void* a, const void* b) { return (*(long long*)a - *(long long*)b); } int main(void) { long long int test, i, j, n, count, flag = 0, o1 = 0, o2 = 0, b1, x, m, l, max, sum2, min, f, r, o, sum1, sum = 0, y, ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a % b == 0) return b; return gcd(b, a % b); } int v[11]; int main() { int a, k = 0; scanf( %d , &a); for (int i = 2; i < a; i++) { int t = a; int pos = 0; while (t) { int mod = t % i; ...
#include <bits/stdc++.h> using namespace std; int n, x[100009], y[100009], sx, sy; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; sx += x[i]; sy += y[i]; } if (sx % 2 == 0 && sy % 2 == 0) { cout << 0; return 0; } for (int i = 1; i <...
#include <bits/stdc++.h> using namespace std; long long int min(long long int a, long long int b) { if (a < b) { return a; } else { return b; } } long long int max(long long int a, long long int b) { if (a > b) { return a; } else { return b; } } int main() { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string cad1; string cad2; cin >> cad1 >> cad2; if (cad1 == cad2) { cout << YES ; } else { if (cad1.size() != cad2.size()) { cout << NO ; } els...
#include <bits/stdc++.h> using namespace std; char s[100000]; int n, m, x, y, i, sol, v[501][501]; int main() { cin >> n >> m >> x >> y; cin >> s; cout << 1 << ; int l = strlen(s); for (i = 0; i < l - 1; i++) { v[x][y] = 1; if (s[i] == R && y < m) y++; if (s[i] == L ...
#include <bits/stdc++.h> using namespace std; int n, cnt; char phone[128]; int main() { scanf( %d , &n); scanf( %s , phone); cnt = 0; for (int i = 0; i < n; i++) { if (cnt == 2 and n - i >= 2) { printf( - ); cnt = 0; } printf( %c , phone[i]); cnt++; } ...
#include <bits/stdc++.h> using namespace std; long double a, b; int main() { cin >> a >> b; cout << fixed << a * pow((long double)1.000000011, b) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<string> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } set<string> s; for (int i = n - 1; i >= 0; i--) { if (s.find(a[i]) == s.end()) { cout << a[i] << n ; } s.insert(...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long double EPS = 1e-10; const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; const int MAX_N = 400; int ans[181]; void init() { fill(ans, ans + 181, -1); for (int i = 3; i <= MAX_N; ++i) { double min_...
#include <bits/stdc++.h> using namespace std; long long ans; void solve(long long a, long long b, long long c, long long l) { for (long long i = 0; i <= l; i++) { long long x = min(a - b - c + i, l - i); if (x >= 0) ans -= (x + 1) * (x + 2) / 2LL; } } int main(void) { ios::sync_with_st...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T m, T n) { while (n) { T t = m % n; m = n; n = t; }; return m; } template <typename T> T exgcd(T a, T b, T& sa, T& ta) { T q, r, sb = 0, tb = 1, sc, tc; sa = 1, ta = 0; if (b) do q = ...
#include <bits/stdc++.h> using namespace std; void fr() { freopen( test_input.txt , r , stdin); freopen( a.out , w , stdout); } const int N = 5e5 + 5; const int MAX = 5e6 + 123; const int INF = 2e9; const int mod = 1e9 + 7; const double pi = 3.1415926536; double eps = 1e-10; bool used1[N],...
#include <bits/stdc++.h> using namespace std; const int N = 5010; int n, k; int a[N]; int dp[N][N / 2][2]; int solve(int r, int num, int sub) { if (num == 0) return 0; int& res = dp[r][num][sub]; if (res != 1000000000) return res; if (sub == 1) { res = solve(r - 2, num - 1, (a[r - 1] <...
#include <bits/stdc++.h> using namespace std; int n, m, p, q1, q2, t, a[300010], y[300010], w, u; long long x[300010]; map<long long, int> f, g; vector<int> r[300010]; inline bool cmp(int a, int b) { return x[a] < x[b]; } inline int power(int a, int b, int q) { if (!b) return 1; int c = power(a, b...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n, m; cin >> n >> m; int a[n]; for (__typeof((n)) i = (0); i < (n); i++) cin >> a[i]; int fq[m]; for (__typeof((m)) i = (0); i < (m); i++) fq[i] = 0;...
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2; cin >> n1 >> n2; int k, m; cin >> k >> m; long long a[n1], b[n2]; for (int i = 0; i < n1; i++) cin >> a[i]; for (int i = 0; i < n2; i++) cin >> b[i]; int count = 0; for (int i = 0; i < n1; i++) { if (a[i...
#include <bits/stdc++.h> using namespace std; int n, m; int color[400100]; int w[400100]; struct segment_tree { long long a[1600100]; bool put[1600100]; void push(int x) { if (put[x]) { a[x * 2] = a[x * 2 + 1] = a[x]; put[x] = false; put[x * 2] = put[x * 2 + 1] = true...
#include <bits/stdc++.h> using namespace std; string name[7]; int a, b, c, n, max_p, dexp, was[7]; bool p[7][7]; void perebor(int point, int num); int main() { name[0] = Anka ; name[1] = Chapay ; name[2] = Cleo ; name[3] = Troll ; name[4] = Dracul ; name[5] = Snowy ; name[6...
#include <bits/stdc++.h> using namespace std; int main() { int t; double x, sum = 0; cin >> t; for (int i = 1; i <= t; i++) { cin >> x; sum += x; } cout << (sum / t) << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 10; const int mod = 1e9 + 7; struct pairNode { char ch; long long times; pairNode(char ch = 0, long long times = 0) : ch(ch), times(times) {} ~pairNode() = default; bool operator==(const pairNode &rhs) const { return ch ...
#include <bits/stdc++.h> #define ll long long int #define ii pair<int,int> #define int long long int using namespace std; const int inf = 0x3f3f3f3f; int32_t main() { int t; scanf( %lld ,&t); while(t--) { int n, m, x; scanf( %lld%lld%lld ,&n,&m,&x); --x; ...
#include <bits/stdc++.h> using namespace std; long long n, sum, k, ans, c; long long arr[1000000 + 5]; long long tmp[1000000 + 5]; vector<long long> frac; signed main() { cin >> n; for (long long i = 0; i < n; i++) { cin >> arr[i], sum += arr[i]; } ans = 1e18; for (long long i = 2;...
#include <bits/stdc++.h> using namespace std; long long m[10000005], x = 0, n, k, i, j, a; int main() { cin >> a >> n; for (i = 1; i < a + n; i++) { m[i] = i; } for (i = 2; i < 3400; i++) { k = 0; for (j = i * i; j <= a + n; j = j + i * i) { k++; m[j] = k; }...
#include <bits/stdc++.h> using namespace std; long long big = 1000000007; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a, b; cin >> a >> b; int g = gcd(a, b)...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 10; struct Edge { int u, v, cost, idx; bool operator<(const Edge& rhs) const { return cost < rhs.cost; } } ed[MAX_N]; inline bool cmp_idx(const Edge& lhs, const Edge& rhs) { return lhs.idx < rhs.idx; } map<pair<int, int>, in...
#include <bits/stdc++.h> using namespace std; const long long MAXN = (long long)((1e5) + 100); long long cuberoot(long long x) { long long lo = 1, hi = min(2000000ll, x); while (hi - lo > 1) { long long mid = (lo + hi) / 2; if (mid * mid * mid < x) { lo = mid; } else hi =...
#include <bits/stdc++.h> using namespace std; const int MN = 100000 + 1; int N; char buf[2000]; int main() { scanf( %d , &N); for (int i = 0; i < N; i++) { int a, b; scanf( %s%d%d , buf, &a, &b); if (a >= 2400 && b > a) { puts( YES ); return 0; } } puts(...
#include <bits/stdc++.h> using namespace std; int a[1005], b[1005], c[1005], d[1005], posa[1005], posb[1005]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int q = 1; q <= n; q++) { int x; cin >> x; a[x] = q; } for (int q = 1; q <= n; q++) { ...
#include <bits/stdc++.h> using namespace std; int tree[4 * 200005]; void update(int n, int st, int en, int index, int val) { if (st == en) { tree[n] = val; return; } int mid = (st + en) / 2, lc = 2 * n, rc = lc + 1; if (index <= mid) update(lc, st, mid, index, val); else ...
#include <bits/stdc++.h> using namespace std; const int MAXM = 111111; vector<int> v[MAXM]; int n, m, lim, x, lower, upper; inline bool check(int score) { for (int i = 1; i <= m; ++i) for (int j = score - 1; j < (int)v[i].size(); ++j) { int k = j - score + 1; if (v[i][j] - v[i][k] - ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 + 10, MAXL = 500 + 10; int n, S, in[MAXN], out[MAXN], w[MAXN], s[MAXN], v[MAXN]; int id[MAXN], h[MAXN][MAXN], g[MAXN][MAXN], f[MAXL][MAXN], Tohka; vector<int> l[MAXN]; bool cmp(int first, int second) { if ((out[first] - in[first]) != (o...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int long long n; cin >> n; if (n % 2 == 0) cout << 2; else cout << 1; return 0; }
#include <bits/stdc++.h> using namespace std; struct flight { int d, f, t, c; flight() {} flight(int d, int f, int t, int c) : d(d), f(f), t(t), c(c) {} bool operator<(const flight& a) const { return d > a.d; } }; int n, m, k; priority_queue<flight> arr, dep; priority_queue<pair<int, int> > ...
#include <bits/stdc++.h> const int INF = (int)(1e9); const long long INFLL = (long long)(1e18); const double EPS = 1e-13; using namespace std; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> b(n); for (int i = 0; i < n; i++) cin >> b[i]; vector<int> ...
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf( %d , &x); return x; } const long double EPS = 1e-12; const int INF = 1e9 + 10; const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100; const int MN = 1e5 + 10; vector<int> fir[MN], lst[MN]; int ar...
#include <bits/stdc++.h> using namespace std; inline long long QuickPow(long long x, long long y) { long long Res = 1, Temp = x; while (y) { if (y & 1) Res = Res * Temp % 1000000007; Temp = Temp * Temp % 1000000007; y /= 2; } return Res; } inline void Swap(long long &x, long lo...