func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; string s[101][2]; int n, m; int main() { cin >> n; m = 0; for (int i = 1; i <= n; i++) { bool mark = true; m++; cin >> s[m][0] >> s[m][1]; for (int j = 1; j < m; j++) if ((s[m][0] == s[j][0]) && (s[m][1] == s[j][1])) { ...
#include <bits/stdc++.h> using namespace std; int N; int main() { cin >> N; cout << N / 2 << n ; for (int i = 0; i < N / 2 - 1; i++) { cout << 2 ; } if (N % 2 == 0) cout << 2 n ; else cout << 3 n ; return 0; }
#include <bits/stdc++.h> using namespace std; long long int N[100000 + 100]; long long int ans = 0; int main() { int n; cin >> n; int court = 0; int court_1 = 0; int court_2 = 0; for (int i = 0; i < n; ++i) cin >> N[i]; for (int i = 0; i < n; ++i) { if (N[i] < -1) { ans...
#include <bits/stdc++.h> using namespace std; char buf[1 << 15], *fs, *ft; inline char getc() { return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft)) ? 0 : *fs++; } inline int read() { int x = 0, f = 1; char ch = getc(); whil...
#include <bits/stdc++.h> using namespace std; int n, t[200005], ans = 0; bool chk[200005]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , t + i); chk[0] = true; for (int i = n; i >= 1; i--) if (!chk[i]) { int x = i; ans++; while (!chk[x]) chk...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int x, y, z; cin >> x >> y >> z; if (x != y && y != z && z != x) cout << NO << n ; else { int a = min(min(x, y), z); int c = max(max(...
#include <bits/stdc++.h> using namespace std; long long ppow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % 998244353; a = (a * a) % 998244353; b >>= 1; } return res; } struct st { long long c, x, y; }; long long sum[2000000]; ...
#include <bits/stdc++.h> using namespace std; ifstream in( file.in ); ofstream out( file.out ); struct om { int p, t, id; } a[100005], b[100005]; int n, w, h, cnt1[200005], cnt2[200005], ans[100005], v[200005], k, m, first, nibab[100005]; pair<int, int> fk[100005]; queue<int> q[200005]; bool...
#include <bits/stdc++.h> using namespace std; template <class n, class second> ostream &operator<<(ostream &p, pair<n, second> x) { return p << < << x.first << , << x.second << > ; } template <class n> auto operator<<(ostream &p, n y) -> typename enable_if<!is_same<n, string>::value, ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> basis; void add(int x) { for (int& a : basis) if (a & -a & x) x ^= a; if (x == 0) return; for (int& a : basis) if (x & -x & a) a ^= x; basis.emplace_back(x); } int main() { ios_base::sync_with_st...
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; int pw(int a, int b) { if (b == 0) return 1; long long t = pw(a, b / 2); t = (t * t) % mod; if (b % 2) t = (t * a) % mod; return t; } int arr[26]; int main() { int n, i, j; string str; cin >> n >> str...
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long b, long long mod = (long long)(1e9 + 7)) { if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod; } mt19937 rng(chrono::steady_clock::now().time_since_epoch()...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long T; cin >> T; while (T--) { long long n; cin >> n; long long ans = 0; long long one = 0, two = 0; for (int i = 1; i <= n; i++) { long long x; cin >> x; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, cnt11 = 0, cnt12 = 0, cnt13 = 0, cnt14 = 0, cnt15 = 0, cnt16 = 0, cnt17 = 0, cnt18 = 0, cnt19 = 0; int cnt21 = 0, cnt22 = 0, cnt23 = 0, cnt24 = 0, cnt25 = 0, cnt26 = 0, cnt27 = 0, cnt28 = 0, cnt29 = 0; cin >> n >>...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mx = (1 << 30) - 1; int n, m; struct node { vector<pair<int, int> > p; void cal(int a, int b) { int res = a ^ b; for (int i = 0; i < 30; i++) { int t = res ^ (1 << i) ^ (res & ((1 << i) - 1)); if...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; inline long long rd() { long long x = 0; char c = getchar(); int neg = 1; while (c < 0 || c > 9 ) { if (c == - ) neg = -1; c = getchar(); } while (c >= 0 && c <= 9 ) x = x * 10 + c - 0 , c = getcha...
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) const int N = 2e5 + 5, L = 19; string s; int cl[L][N], sf[L][N], ct[N], pos[N], lcp[N], t[L][N], g[N]; pair<int, int> a[N + N]; int *suf = sf[L - 1]; int que(int l, int r) { int k = g[r - l + 1]; return min(t[k][l], t[...
#include <bits/stdc++.h> using namespace std; double f[100]; int k[100]; double cpw[100]; int N; double calc(int i) { return (1 - cpw[i] * f[i]) / (1 - cpw[i]); } int main() { cin >> N; int c; int highInc = 0; double P = 1; for (int i = 0; i < N; i++) { cin >> c; cpw[i] = f...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const int SIZE = 4000050; const int P = 67; const int maxn = 20; int a[maxn], b[maxn]; int F[260]; char str[10]; struct HASH { int head[SIZE], next[SIZE]; unsigned long long state[SIZE]; double dp[SIZE]; int tol; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n; cin >> n; vector<int> a(101); for (int i = 0; i < n; i++) { int x; cin >> x; ++a[x]; } cout << *max_element(a.begin(), a.end()) << ...
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<int> v; void solve() { if (k == 1) { for (int i = 0; 1 + i * (n - 1) <= n + m; i++) v.push_back(1 + i * (n - 1)); return; } for (int i = 1; i <= k; i++) v.push_back(1); v.push_back(n); for (int i = 1; i < k; i++) v...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; void solve() { int n, b, d; cin >> n >> b >> d; int res = 0; int currMass = 0; for (int i = 0; i < n; i++) { int got; cin >> got; if (got > b) continue; currMass += got; ...
#include <bits/stdc++.h> using namespace std; long long int dp[2005][2005]; int main() { int n, i, k1, j, k; cin >> n >> k1; long long int ans = 0; dp[0][1] = 1; for (i = 1; i <= k1; i++) { for (j = 1; j <= n; j++) { for (k = j; k <= n; k += j) { dp[i][k] += dp[i - 1][j...
#include <bits/stdc++.h> using namespace std; int n; int cnt = 0; void rec(vector<bool> mask, int i, int ops) { if (cnt == n) return; if (i == n) { for (int j = 0; j < n; j++) cout << char( ( + mask[j]); for (int j = 0; j < n; j++) { if (ops > 0) { cout << ) ; o...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e4 + 22; int n, m; void solve() { int l, r; cin >> n >> m; int val = INT_MAX; for (int i = 0; i < m; i++) { cin >> l >> r; val = min(val, r - l + 1); } cout << val << n ; for (int i = 0; i < n; i++) co...
#include <bits/stdc++.h> using namespace std; vector<int> x; int modulo_sum(int a, int b) { return ((a % 1000000007) + (b % 1000000007)) % 1000000007; } int modulo_subtract(int a, int b) { return ((a % 1000000007) - (b % 1000000007)) % 1000000007; } int modulo_mult(int a, int b) { return ((long lo...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = n + 1; i <= m; i++) { int count = 0; for (int j = 2; j < i; j++) { if (i % j == 0) count++; } if (count == 0) { if (m == i) { cout << YES << endl; ...
#include <bits/stdc++.h> using namespace std; long long n, S, top, pos[2005], id[2005]; struct point { long long x, y; } a[2005]; struct line { long long x, y; double k; } b[4000005]; inline bool cmp1(point A, point B) { return A.x != B.x ? A.x < B.x : A.y < B.y; } inline bool cmp2(lin...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e6; int a[maxn], ans; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; while (n--) { int tmp; cin >> tmp; a[tmp]++; } for (int i = 0; i < maxn; i++) { a[i + 1] += a[i] / 2; ans += a[i...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { long long int tc; cin >> tc; while (tc--) { long long int n; cin >> n; while (n--) cout << 1 << ; cout << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, S[2]; int num[1505][1505][2]; bool s[1505][1505]; int p[4][2] = {0, -1, 1, 0, 0, 1, -1, 0}; void dfs(int x, int y) { if (num[x % n][y % m][0] == -1 && num[x % n][y % m][1] == -1) { num[x % n][y % m][0] = x; num[x % n][y % m][1] = y; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100, SQRT = 320, MAXM = 13; int N, M, Q; pair<int, int> up[MAXN][MAXM]; pair<int, int> jump[MAXN][MAXM]; char grid[MAXN][MAXM]; bool bounded(int x, int y) { return 1 <= x && x <= N && 1 <= y && y <= M; } bool bounded(pair<int, int> p) { r...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> tree; int res = 0; int dfs(int node, int parent) { int left = 2; for (int child : tree[node]) { if (child == parent) { continue; } int x = dfs(child, node); if (x == 1 && left > 0) { ++res; ...
#include <bits/stdc++.h> using namespace std; map<int, int> a, b; int f[100005]; int main() { int n, tmp, i; scanf( %d , &n); a.clear(); b.clear(); for (i = 0; i < n; i++) { scanf( %d , &tmp); a.insert(make_pair(tmp, i)); } for (i = 0; i < n; i++) { scanf( %d , &tmp...
#include <bits/stdc++.h> using namespace std; int64_t n; vector<int64_t> adj[100001]; int64_t ss[100001]; void dfs(int64_t no, int64_t par = -1) { ss[no] = 1; for (auto j : adj[no]) { if (j == par) { continue; } dfs(j, no); ss[no] += ss[j]; } } vector<int64_t> o...
#include <bits/stdc++.h> using namespace std; const int N = 400005; multiset<int> S; int x, y, n, m, k; map<pair<int, int>, int> flag; struct Tree { int l, r, num, flag; } T[N * 4]; void build(int x, int l, int r) { T[x].l = l; T[x].r = r; if (l == r) { T[x].num = l - 1; retu...
#include <bits/stdc++.h> int main(int argc, const char* argv[]) { int n, k; int a[100000 + 1]; scanf( %d%d , &n, &k); int i; int count = 0; int is_ukn = scanf( %d , a) != 1; for (i = !is_ukn; i <= n; i++) scanf( %d , a + i) != 1 && getchar() && count++; int is_man_move = (n + 1 -...
#include <bits/stdc++.h> using namespace std; int n; inline int f(int a) { int n1 = n; bool y = 0; while (n1 != 0) { int h = a; int u = n1 % 10; n1 = n1 / 10; while (h != 0) { int j = h % 10; h = h / 10; if (u == j) { y = 1; break; ...
#include <bits/stdc++.h> using namespace std; int n, m, d = 1; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; while (n > d) { for (int i = 1; i < (m + 1); i++) { cout << d << << i << n ; cout << n << << m + 1 - i << n ;...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1073741824 ) #pragma warning(disable : 4996) using namespace std; const int N = 1e5 + 100; pair<int, int> ar[N]; int col[N], us[5]; int ct(int m) { int c = 0; while (m) { c += m & 1; m >>= 1; } return c; } int main() ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; pair<long long, long long> ans1[N], ans2[N]; long long x; long long cal(long long n) { n--; long long tmp = n * (n + 1) * (2 * n + 1) / 6; n++; tmp -= (n * n * n - n * ...
#include <bits/stdc++.h> int main() { int n, m; int left, right; int i; int count = 0; scanf( %d %d , &n, &m); while (n--) { for (i = 0; i < m; i++) { scanf( %d %d , &left, &right); if (left == 1 || right == 1) { count++; } } } printf( %d n...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 0 << endl; return 0; } if (n == 2) { cout << 3 << endl; return 0; } long long a, b, c; a = 0; b = 3; c = 6; for (int i = 3; i <= n; i++) { c = (...
#include <bits/stdc++.h> using namespace std; int main() { char str1[50], str2[50]; int n, c, k, cnt, flag; cin >> n; while (n--) { flag = cnt = 0; cin >> str1; k = strlen(str1); str1[k] = : ; str1[k + 1] = 0 ; for (int i = 0; i <= k; ++i) { if (str1[i]...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct P { int t, id; bool operator<(const P &tmp) const { if (t != tmp.t) return t < tmp.t; return id < tmp.id; } } p[N]; priority_queue<int, vector<int>, greater<int> > qu; queue<int> q; set<int> s; long long ...
#include <bits/stdc++.h> using namespace std; string b[1 << 15]; int x[100], y[100], n; map<string, int> mp; int main() { scanf( %d , &n); for (int i = 0, z; i < n; i++) { scanf( %d , &z); x[i] = z & ((1 << 15) - 1); y[i] = z >> 15; } for (int B = 0; B < (1 << 15); B++) { ...
#include <bits/stdc++.h> using namespace std; int n, m; char a[505][505]; long long int ans, mod; namespace tree { int edge[505][505]; long long int a[505][505]; inline void init() { memset(edge, 0, sizeof(edge)); } inline long long int qpow(long long int x, long long int y) { long long int ans = ...
#include <bits/stdc++.h> using namespace std; inline int ni() { int a; scanf( %d , &a); return a; } const int max_n = 5000; char s1[max_n + 1], s2[max_n + 1], res[max_n + 1]; int digits[26], minuses[26]; bool check(int from, int code, int n, int m) { bool ok = true, founded = false; di...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int intersection = n * m; int turn = 0; while (n > 1 && m > 1) { intersection -= (n + m - 1); n--; m--; turn++; } if (n == 1 && m == 1 && turn % 2 == 0) { cout << Akshat <<...
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf( %d , &x); return x; } const long long maxn = 1e5 + 10; const long long mod = 1e9 + 7; const long long inf = 1e9 + 10; long long pref[2][maxn], pref2[maxn]; long long maxDp[maxn], minDp[maxn]; int32_t ma...
#include <bits/stdc++.h> using namespace std; int stuff(int x) { int s = 0; while (x / 10 != 0) { int r = x % 10; x /= 10; s += r; } s += x; return s; } int main() { ios_base::sync_with_stdio(false); long long int i = 0; long long int p, f, a, b, c, s, spow = 1;...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; for (int k = 0; k < t; k++) { int n, total = 0; cin >> n; while (n / 10 > 0) { total = total + (n - (n % 10)); n = ((n - (n % 10)) / 10) + n % 10; } cout << total + (n % 10...
#include <bits/stdc++.h> using namespace std; template <class T> void max_self(T &a, const T &b) { if (a < b) a = b; } template <class T> void min_self(T &a, const T &b) { if (a > b) a = b; } const int INF = 1e9 + 7; const double PI = acos(-1.0); const double EPS = (1e-9); int main() { ...
#include <bits/stdc++.h> using namespace std; void init() { ios::sync_with_stdio(0); cin.tie(0); } int main() { init(); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; long long arr[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) {...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; const int maxn = 3e5 + 5; const long long mod = 998244353; const double eps = 1e-6L; struct node { int l, r; bool operator<(const node& k) const...
#include <bits/stdc++.h> using namespace std; long long N; void solve() { int i, j, k, l, r, x, y; string s; cin >> N; long long ret = 0; long long a = 1; while (N > 1) { ret += N / 2 * a; N = (N + 1) >> 1; a <<= 1; } cout << ret << endl; } int main() { so...
#include <bits/stdc++.h> using namespace std; const int maxn = 200008; int n, k, l, r; char g[2][maxn]; bool f[2][maxn]; struct arr { int t, s, x; } h[maxn]; bool Add(int t, int s, int x) { if (t >= x) return 0; if (x > n) return 1; if (f[s][x]) return 0; if (g[s][x] == X ) return 0...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m, a, b; cin >> n >> m >> a >> b; int ans = 1000000000; for (int i = 0; i <= n / m + 1; i++) { ans = min(ans, i * b + max(n - m * i, 0) * a); } cout << ans << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 5e2 + 5; vector<pair<int, int> > adj[MAX]; int dis[MAX][MAX], in[MAX][MAX]; int n, m; void dijkstra(int source) { memset(dis[source], 0x3F, sizeof dis[source]); dis[source][source] = 0; priority_queue<pair<int, int>, vector<pair<int, ...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; if (n % 2 == 0) { cout << NO << endl; return 0; } cout << YES << endl; int arr[2 * n + 5]; ...
#include <bits/stdc++.h> using namespace std; template <class II, class SZ, class OI> OI cpy_n(II _i, SZ _s, OI _o) { for (int_fast64_t _j = 1; _j <= _s; _j++) { *(_o++) = *_i; if (_j != _s) { _i++; } }; return _o; } template <class T> void slurp(vector<T>& v, int_least...
#include <bits/stdc++.h> using namespace std; const int prime = 999983; const int INF = 0x7FFFFFFF; const long long INFF = 0x7FFFFFFFFFFFFFFF; const double pi = acos(-1.0); const double inf = 1e18; const double eps = 1e-6; const long long mod = 1e9 + 7; long long qpow(long long a, long long b) { l...
#include <bits/stdc++.h> using namespace std; int addOne(int x) { return x + 1; } int main() { int a, b; cin >> a >> b; while (b) { a = addOne(a); b--; } cout << a << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int dx[4] = {0, 0, -1, 1}; const int dy[4] = {-1, 1, 0, 0}; const int N = 1e5 + 1; int n; long long a[N], s[N], p[N], k; int ans = INF; bool Check(int val) { long long ans = k + 1; for (int ...
#include <bits/stdc++.h> using namespace std; int a[100000]; int b[100000]; int c[100000]; struct P { int a, b; } p[100000]; int cmp(P x, P y) { return x.a < y.a; } int main() { int n, x; while (cin >> n) { for (int i = 1; i <= n; i++) { cin >> x; a[x] = i; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int cnt[N], steps[N], vis[N]; void solve() { int n, res = INT_MAX, x, y; cin >> n; for (int i = 1; i < n + 1; i++) { cin >> x; queue<pair<int, int>> q; q.push({x, 0}); while (!q.empty()) { x = q.fron...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, k, a[N], ans = 0; multiset<int> ms; int main(int argc, char const *argv[]) { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (!a[i] && i != k) a[i] = n + 1; if (i == k && a[i]) a[i] = 0, ans = 1;...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3e5 + 5; int n, q; struct Edge { int to, nxt; } e[MAX_N]; int head[MAX_N], tote; void add_edge(int u, int v) { e[++tote].to = v, e[tote].nxt = head[u]; head[u] = tote; } int siz[MAX_N], fa[MAX_N], ans[MAX_N]; void dfs(int u,...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long inff = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; const double eps = 1e-9; const int maxV = 3e5 + 5; int n, V, mV, a[maxV], tot; long long dp[5][maxV]; vector<long long> w[5]; void solve(int l, int r, int L...
#include <bits/stdc++.h> using namespace std; const long long max_n = 500 + 5; long long n; long long a[max_n], b[max_n]; bool are_equal(long long arr1[], long long arr2[], long long sz) { for (int i = 0; i < sz; ++i) { if (arr1[i] != arr2[i]) return false; } return true; } bool same_ele...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; const double pi = acos(-1); const double e = exp(1); const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; template <typename T> inline void read(T &x) { T ans = 0; char last = , ch = getchar(...
#include <bits/stdc++.h> using namespace std; long long a[105][105], v[105][105], dp[105][105]; long long slove(int x, int y, int n, int m) { long long t = a[x][y] - (x + y - 2); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { v[i][j] = a[i][j] - (t + i + j - 2); } } ...
#include <bits/stdc++.h> const int INF = (1 << 31) - 1; const double EPS = 1E-9; const double PI = acos(-1); using namespace std; vector<bool> U; vector<vector<int> > G; vector<int> P, order, T; int M[5100][5100]; void dfs(int v) { U[v] = true; for (int i = 0; i < G[v].size(); ++i) if (!...
#include <bits/stdc++.h> using namespace std; const long long base = 7; const long long maxn = 1e6 + 9; const long long inf = 1e9 + 7; set<long long> W, H; multiset<long long> l1, l2; long long w, h, n, a; long long x, y; char c; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 6; const long long MOD = 1e9 + 7; int par[MAX]; long long sz[MAX]; long long triplets(long long x) { return x * (x - 1) * (x - 2); } bool isLucky(long long x) { while (x) { if (x % 10 != 4 and x % 10 != 7) return false; x ...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-10; const double PI = acos(-1.L); struct Point { double x; double y; Point() { x = 0; y = 0; } Point(double x, double y) : x(x), y(y) {} Point operator+(const Point& other) const { return Point(x + othe...
#include <bits/stdc++.h> using namespace std; int main() { int a[200], b[200]; int countA = 0; int countB = 0; int countC = 0; int n = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n;...
#include <bits/stdc++.h> long long i, j, k, m, n; int main() { scanf( %lld , &n); if (n <= 1) puts( -1 ); else printf( %lld %lld %lld n , n, n + 1, n * (n + 1)); return 0; }
#include <bits/stdc++.h> int search(int n, long long int a[n], long long int target) { int i; if (a[0] >= target) { printf( 1 %lld n , target); return 0; } int L = 0, R = n - 1; int M; while ((R - L) > 1) { if ((L + R) % 2 == 0) { M = (L + R) / 2; } else { ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (a && b) a > b ? a %= b : b %= a; return a + b; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } int main() { int n; cin >> n; int i, j, sum = 0, in; int a[n]; for (...
#include <bits/stdc++.h> using namespace std; void _print(long long t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t) { cerr << t; } template <class T,...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; set<int> vec; for (int i = 0; i < n; i++) { int d; cin >> d; vec.insert(d); } cout << v...
#include <bits/stdc++.h> long long k; int _, n, a[200020]; int main() { for (scanf( %d , &_); _--;) { scanf( %d%lld , &n, &k); for (int i = 0; i < n; i++) scanf( %d , a + i); for (int i = 0; i < (k & 1) + 2; i++) for (int i = 0, d = *std::max_element(a, a + n); i < n; i++) ...
#include <bits/stdc++.h> using namespace std; const long double PI = atan(1.0) * 4.0; const long long int MOD = 1e9 + 7; const long long int INF = 1e18; const long double EPS = 0.0000001; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); int n, k; cin >> n >> k; string s; cin...
#include <bits/stdc++.h> using namespace std; struct abc { int val, key, s, e, ind; } z[100005]; bool cmp(abc a, abc b) { if (a.key == b.key) return a.val < b.val; return a.key > b.key; } bool cmp1(abc a, abc b) { return a.ind < b.ind; } int main() { int n, m, i, j, k, a[100005], l; sc...
#include<bits/stdc++.h> using namespace std; int a[505],ch[505][505],cnt[505]; int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int n,c=0,i,j; cin>>n; for(i=1;i<=n;i++)cin>>a[i],ch[i][i]=a[i],cnt[a[i]]=a[i]-1; for(i=1;i<=n&&c==0;i++){ int x,y; x=y=i; ...
#include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #de...
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 9, lg = 19, MOD = 998244353, maxV = 1e3 + 9; int T[3][maxN], n, q, arr[maxN], mp[129]; priority_queue<int> pqs[2][3]; string st; int query(int w, int *T) { int ret = 0; for (w++; w > 0; w -= w & -w) ret += T[w]; return ret; }...
#include <bits/stdc++.h> using namespace std; const int NN = 1010; double first[NN], second[NN]; int main() { int n, a, b, c, d; cin >> n; for (int i = 0; i < n; i++) { scanf( %d%d%d%d , &a, &b, &c, &d); double s = a * a * d * d + c * c * b * b; first[i] = a * b * d * d / s; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { set<pair<pair<long long, long long>, pair<long long, long long> > > rem; long long xi = 0, yi = 0, xf = 0, yf = 0; string s;...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 7; long long n; pair<long double, long double> a[MAXN]; void read() { cin >> n; for (long long i = 0; i < n; ++i) { cin >> a[i].first >> a[i].second; } bool ch1 = 0, ch2 = 0; for (long long i = 0; i < n; ++i) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); if (n % 2 == 1) { ans = a[(n - 1) / 2]; } if (n % 2 == 0) { ans = a[(n / 2) - 1]; } cout << ans; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 1e6 + 5; int n, k, top; int a[N], l[N], r[N], s[N]; long long ans; long long calc(int l, int r) { if (l > r || r - l + 1 < k) return 0; int m = (r - l + 2 - k) / (k - 1); long long ret = 1LL * (m + 1) * ...
#include <bits/stdc++.h> using namespace std; int m, n; int a[11][11] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0}, {2, 0, 1}, {0, 2, 1}, {0, 1, 2}}; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> m; cout << a[n % 6][m] << endl; return 0; } ...
#include <bits/stdc++.h> int64_t k; int a, b; int result[9]; int ascore[9] = {0, 0, 1, 1, 0, 0, 0, 1, 0}; int bscore[9] = {0, 1, 0, 0, 0, 1, 1, 0, 0}; int stack[10]; int64_t atotalscore, btotalscore; int cyclestart, cycleend, cyclelength; int acyclescore, bcyclescore; int64_t cycletime, cycleremain;...
#include <bits/stdc++.h> using namespace std; int n, x[100005], y[100005]; bool sign(int t) { return (t > 0); } bool check(long double r) { vector<pair<long double, long double> > v; for (int i = 0; i < n; i++) { long double t = (2.0 * r - y[i]) * y[i]; if (t < 0) return 0; long double...
#include <bits/stdc++.h> using namespace std; const int N = 5005; const int M = 1005; const int K = 15; int n, m; char name[N][K], oper[N][K], val[N][M]; bool isV[N]; int idx1[N], idx2[N]; map<string, int> mp; char ansmx[M], ansmn[M]; int res[N]; int work(int a, int b, char op[]) { if (op[0]...
#include <bits/stdc++.h> using namespace std; const int64_t INF = 1e18 + 10; const int N = 2e7 + 10; int MOD = 1000000007; int g[26], in[26], used[26]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (int i = 0; i < 26; i++) g[i] = -1; int n; cin >> n; vec...
#include <bits/stdc++.h> using namespace std; using vl = vector<long long>; using vpl = vector<pair<long long, long long>>; using vs = vector<string>; using pl = pair<long long, long long>; using ll = long long int; using vb = vector<bool>; void printcase(ll x) { cout << Case # << x << : ; } void ...
#include <bits/stdc++.h> using namespace std; struct plan { bool used; int type; int single; int start; int end; long long cost; }; void getInput(vector<plan> &plans, vector<vector<int> > &outs, vector<forward_list<int> > &segtree); void addPlan(vector<forward_list<int>...