func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 100; double alpha[maxn], beta[maxn]; double a[maxn], b[maxn]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %lf , &beta[i]); for (int i = 0; i < n; i++) scanf( %lf , &alpha[i]); double Sa = ...
#include <bits/stdc++.h> using namespace std; const int N = 5010; const int mod = 1e9 + 7; const long long INF = 1e15; int nex[N]; long long x[N], a[N], b[N], c[N], d[N]; int main() { int n, s, e; while (~scanf( %d%d%d , &n, &s, &e)) { nex[s] = e; for (int i = 1; i <= n; i++) scanf( %I...
#include <bits/stdc++.h> using namespace std; using namespace chrono; long long int ceil(long long int r, long long int d) { return (r / d) + (bool)(r % d); } void inputAArray(int siz, vector<int> &arr) { for (int i = 0; i < siz; i++) arr[i] = 1 + rand(); } int main() { ios_base::sync_with_std...
#include <bits/stdc++.h> using namespace std; double n, l, v1, v2, k; bool c(double x) { int num; if ((int)n % (int)k == 0) num = n / k; else num = n / k + 1; if (num * x + (num - 1) * x * (v2 - v1) / (v2 + v1) <= x + (l - x * v2) / v1) return 1; return 0; } int main() { ...
#include <bits/stdc++.h> using namespace std; int t, n, m, i, ans, a; int main() { cin >> t; while (t--) { cin >> n >> m; ans = 0; for (i = 1; i <= n; i++) { cin >> a; ans += a; } if (ans == m) cout << YES << endl; else cout << NO << ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const int maxn = 1000100; int n; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; int N, M, dp[MAXN], res = 0; vector<pair<int, int>> adj[MAXN]; int check(int v) { if (dp[v]) return dp[v]; dp[v] = 1; for (auto p : adj[v]) { int n = p.first; if (check(n) + 1 > dp[v]) { dp[v] = dp[n] + 1; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; template <typename T> using V = std::vector<T>; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } dbg; int gcd(int a, int b) { return a ? gcd(b % a,...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; pair<string, string> arr[n]; for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second; for (int i = 0; i < n; i++) if (arr[i].second == rat ) cout << arr[i].first << endl; for (int i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; std::map<long long, long long> factors; void primeFactors(long long n) { while (n % 2 == 0) { factors[2]++; n = n / 2; } for (long long i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { factors[i]++; n = n / i; ...
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b) { if (b == 0) return 1; long long x = powmod(a, b / 2); long long y = (x * x) % 1000000007; if (b % 2) return (a * y) % 1000000007; return y % 1000000007; } long long mulmod(long long a, long long b, lon...
#include <bits/stdc++.h> using namespace std; char buf[1 << 21], *p1 = buf, *p2 = buf; inline long long qread() { register char c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++); register long long x = 0, f = 1; while (c < 0 ...
#include <bits/stdc++.h> using namespace std; long n, d, k, l, m, i, j, a[105], b[2]; int main() { cin >> n >> d >> l; b[0] = n / 2; b[1] = n - b[0]; k = 0; if (d > l * b[1] - b[0] || d < b[1] - l * b[0]) { cout << -1 << endl; return 0; } else { for (i = 1; i <= n; i +=...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; struct Node { long long val[4], len; Node() { memset(val, 0, sizeof(val)); len = 0; } }; vector<Node> tree; long long n, m; string s; long long ch[100]; long long choice(long long i, long long j = -1...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; map<int, vector<int> > pos; map<int, int> result; for (int i = 0; i < n; i++) { int t; cin >> t; if (pos.find(t) == pos.end()) { vector<int> temp...
#include <bits/stdc++.h> using namespace std; int trees(vector<vector<int> >& v, int a, int b, int y, int x) { int trees = 0; for (int i = y; i < (y + a); ++i) { for (int j = x; j < (x + b); ++j) { trees += v[i][j]; } } return trees; } int main() { int n, m; cin >> n ...
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, m, len; cin >> n >> m; if (n >= 1 && n <= 100 && m >= 1 && m <= 100) { cin >> s; len = s.size(); if (len == n) { int l, r, z; char c1, c2; while (m--) { cin >> l >> r >> c1...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353, inv2 = mod + 1 >> 1; inline void add(int &a, int b) { (a += b) >= mod && (a -= mod); } inline int Add(int a, int b) { return add(a, b), a; } inline void sub(int &a, int b) { (a -= b) < 0 && (a += mod); } inline int Sub(int a, int b) { ...
#include <bits/stdc++.h> using namespace std; int v[1005]; int a[1005], b[1005]; char s[1005]; vector<int> c, d; int main() { cin >> s + 1; int len = strlen(s + 1); int num = 0; for (int i = 1; i <= len; i++) { if (s[i] == ( ) { a[i]++; c.push_back(i); } a[...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long a, b, n, m; cin >> a >> b >> n >> m; if (a + b < n + m) { cout << no << ...
#include <bits/stdc++.h> int n; char str[250000]; int main() { while (~scanf( %d , &n)) { scanf( %s , str); int len = strlen(str); int sum1 = 0, sum2 = 0; for (int i = 0; i < len; i++) { if (str[i] == < ) { sum1++; } else { break; } } ...
#include <bits/stdc++.h> using namespace std; const int MaxN = 100009; unsigned long long a[MaxN], b[MaxN], c[MaxN]; int main() { unsigned long long n, ans = 0, p, sum = 0, sum2 = 0; cin >> n >> p; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { sum += a[i]; b[...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3 ) const long long MOD = 1e9 + 7; long long n_bits(long long n) { long long x = __builtin_popcount(n); return x; } int pow(int a, int b, int m) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2;...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using v...
#include <bits/stdc++.h> using namespace std; string s; int x, y, len, a, b; int main() { cin >> s; len = s.length(); for (int i = 0; i < len; ++i) { if (s[i] == ( ) ++x; else if (s[i] == ) ) --x; else if (s[i] == # ) --x, ++y; if (x < 0) { ...
#include <bits/stdc++.h> using namespace std; int n, m, a[105][105]; int sum[2][105]; bool inv[2][105]; int main() { while (scanf( %d%d , &n, &m) == 2) { memset(inv, false, sizeof(inv)); memset(sum, 0, sizeof(sum)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ...
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const long long INF = 8e18; const int maxn = 2e5 + 5; int n, k, cnt; int a[maxn], b[maxn], p[maxn], fp[maxn], num[maxn]; vector<int> zz[maxn]; inline void init() { cin >> n >> k; for (int i = 1; i <= n; ++i) { int x; ...
#include <bits/stdc++.h> using namespace std; char BUFFER[100000 + 5]; bool readn(int &n) { return scanf( %d , &n) == 1; } bool readl(long long &n) { return scanf( %I64d , &n) == 1; } bool readd(double &n) { return scanf( %lf , &n) == 1; } bool reads(string &s) { s = ; int n = scanf( %s , BUFFER);...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long double PI = 4 * atan(1); int n, r, val[2001], x, flag, ch[2001]; bool isChild[2001][2001]; pair<int, int> p[2001]; vector<int> v[2001]; queue<int> q1, q2, ans; void solve(int i) { int rem = ch[i] - p[i].second; whil...
#include <bits/stdc++.h> using namespace std; const int maxn = 50000 + 10; struct query { int type, x, y; } qu[maxn]; int n, fa[maxn]; long long val[maxn], sz[maxn]; vector<int> v[maxn]; bool mark[maxn], have[maxn]; long long d[maxn]; int dfs(int x) { sz[x] = 1; int ret = 0; for (aut...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, s; scanf( %lld , &a); a = a - 2; if (a % 3 == 0) { printf( 1 2 %lld , a - 1); } else printf( 1 1 %lld , a); return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } int findGCD(int arr[], int n) { int result = arr[0]; for (int i = 1; i < n; i++) { result = gcd(arr[i], result); } return result; } void swap(int* a...
#include <bits/stdc++.h> using namespace std; using i64 = long long; using f64 = double; using f80 = long double; using pii = pair<int, int>; using ptx = pair<f64, f64>; const int N = 105; bool f[N][N]; int n, m, first, second; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0...
#include <bits/stdc++.h> using namespace std; int n, m, k, a[1003][1003], row[1003], col[1003]; int main() { scanf( %d%d%d , &n, &m, &k); int i, j; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) scanf( %d , &a[i][j]); for (i = 0; i <= n; i++) row[i] = i; for (i = 0; i <= m; i++) col[i...
#include <bits/stdc++.h> using namespace std; long long r(long long a) { long long i = 0; while (a % 2 == 0) { a /= 2; ++i; } return i; } void one_case() { long long a, b; cin >> a >> b; auto ra = r(a); auto rb = r(b); a /= (1ll << ra); b /= (1ll << rb); i...
#include <bits/stdc++.h> using namespace std; int high[500005], ata[500005], cost[500005], par[500005], der[500005]; long long ans; vector<int> v[500005]; int n, k, m, x, y, z; vector<pair<int, pair<int, int> > > e; int bul(int node, int ar[]) { if (node == ar[node]) return node; return ar[node] =...
#include <bits/stdc++.h> using namespace std; const int64_t inf = 1e18; vector<vector<int64_t> > adj; int64_t inp() { int64_t x; cin >> x; return x; } vector<int64_t> level; int64_t res = 0; void dfs(int64_t u, int64_t LV = 0) { level[u] = LV; res = max(res, LV); for (auto v : ad...
#include <bits/stdc++.h> using namespace std; long long po(long long a, long long x, long long m) { if (x == 0) { return 1; } long long ans = 1; long long k = 1; while (k <= x) { if (x & k) { ans = ((ans * a) % m); } k <<= 1; a *= a; a %= m; } ...
#include <bits/stdc++.h> using namespace std; const int MX = 200100; int N, M; char S[MX]; int A[MX]; struct Segment { int a, b, c, d, e; int z, l, r; void add(int x) { a += x, b += x, c -= x, d -= x, z += x; } } T[MX << 2]; inline void PushUp(int i) { Segment &t = T[i], &x = T[(i << 1)]...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int a[maxn]; int n, l, t; int main() { scanf( %d%d%d , &n, &l, &t); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } double ans = 0; int k = 2 * t / l, c = 2 * t % l; for (int i = 0; i < n; i++) { in...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > dist(51, vector<int>(3, 100)); int n, m; int dp[51][8]; void calc_s(int i, string &s) { for (int j = 0; j < s.length(); j++) { if (s[j] == # || s[j] == * || s[j] == & ) { dist[i][2] = min(dist[i][2], j); dist[i][...
#include <bits/stdc++.h> using namespace std; int mult(int a, int b, int p = 1000000007) { return ((a % p) * (b % p)) % p; } int multbig(int a, int b, int mod) { if (a == 0 or b == 0) return 0; if (a == 1 or b == 1) return (a * b) % mod; int cur = multbig(a, b / 2, mod); cur = (2 * cur) % mod; ...
#include <bits/stdc++.h> using namespace std; void dice() { int x, y; cin >> x >> y; x = max(x, y); vector<string> str; str = { 1/6 , 1/3 , 1/2 , 2/3 , 5/6 , 1/1 }; x = 6 - x + 1; cout << str[x - 1] << endl; } int main() { dice(); }
#include <bits/stdc++.h> using namespace std; int ask(int c, int d) { cout << ? << c << << d << endl; fflush(stdout); int x; cin >> x; return x; } void go(int a, int b) { cout << ! << a << << b << endl; fflush(stdout); exit(0); } bool same[50]; signed main() {...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; bool z[MAXN] = {0}; void prework() { for (int i = 2; i <= 1000; i++) { if (z[i]) continue; for (int k = i + i; k <= 1000; k += i) z[k] = true; } } struct node { char c; int n; bool operator<(node b) const { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n == 1) cout << 2; else if (n == 2) cout << 3; else if (n == 3) cout << 1; else if (n == 4) cout << 2; else cout << 1; return 0; }
#include <bits/stdc++.h> using namespace std; const int Mo = (int)1e9 + 7; int i, j, m, n, p, k, sum, id, x, y, a[1000005], flag, ans; int power(int x, int y) { int sum = 1; for (; y; y >>= 1) { if (y & 1) sum = 1ll * x * sum % Mo; x = 1ll * x * x % Mo; } return sum; } int main()...
#include <bits/stdc++.h> using namespace std; const int MOD = int(1e9) + 7; const long long int MOD64 = (long long int)(1e18) + 7; const int INF = 0x7fffffff; const long long int INF64 = 0x7fffffffffffffff; const int N = 5000 + 10; int a[N], lnum[N], rnum[N]; int n, m; vector<int> H[N]; long long in...
#include <bits/stdc++.h> using namespace std; int a[1000]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); double ans = 0; for (int i = 1; i <= m; ++i) { int x, y, z; scanf( %d%d%d , &x, &y, &z); ans = max(ans, ((double)a[x] + a[...
#include <bits/stdc++.h> using namespace std; struct node { int num; int num_num; } num[105]; int main() { int N, M; scanf( %d%d , &N, &M); num[0].num = 0; num[0].num_num = 0; for (int i = 1; i <= N; i++) { int flag; scanf( %d , &flag); num[i].num = num[i - 1].num +...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; long long ar[maxn]; int main() { long long n, m; cin >> n >> m; long long a, b, c; cin >> a >> b >> c; ar[a] = 1, ar[b] = 2, ar[c] = 3; for (int i = 1; i < m; ++i) { cin >> a >> b >> c; if (!ar[a] and !ar...
#include <bits/stdc++.h> using namespace std; const double fs = 6e-2, Pi = acos(-1.0); struct point { double x, y; } p[4]; double a, b, c, r, S, C, P, C1, A1, B1, R1, Ans; double s(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } double gcd(double a, doub...
#include <bits/stdc++.h> using namespace std; int dx[4] = {0, -1, 0, 1}; int dy[4] = {1, 0, -1, 0}; int x[100000], y[100000], DP[100000], CP[100000], R, C, used[50][50][4][4]; char s[64][64]; bool Out(int xx, int yy) { return xx < 0 || yy < 0 || xx >= R || yy >= C; } void next(int x1, int y1, int DP1, int...
#include <bits/stdc++.h> using namespace std; string eq(string c) { string s = ; for (int i = 0; i < c.size(); i++) { if (c[i] == 2 ) s += 2 ; else if (c[i] == 3 ) s += 3 ; else if (c[i] == 4 ) s += 223 ; else if (c[i] == 5 ) s += 5 ; e...
#include <bits/stdc++.h> using namespace std; int n, m, a[4], num, sum; string s[4], str; bool check(char ch) { return ch == a || ch == e || ch == i || ch == o || ch == u ; } int work() { sum = 0; for (int i = str.length() - 1; i >= 0; i--) { sum += check(str[i]); if (sum ==...
#include <bits/stdc++.h> int main() { long int n, a[100001], i, flag; char c[100001], c1; while (scanf( %ld , &n) == 1) { flag = 0; long int a1[100001] = {0}; c1 = getchar(); gets(c); for (i = 0; i < n; i++) { scanf( %ld , &a[i]); } i = 0; while (1) ...
#include <bits/stdc++.h> using namespace std; template <typename T> void chmin(T &x, const T &y) { if (x > y) x = y; } template <typename T> void chmax(T &x, const T &y) { if (x < y) x = y; } inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int x = 2 * n, y = 3 * m; int k = 1; while (6 * k <= x && 6 * k <= y) { if (x + 2 <= y + 3) x += 2; else y += 3; k += 1; } cout << max(x, y); return 0; }
#include <bits/stdc++.h> using namespace std; inline int read() { int res = 0, w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) ch == - ? w = -1, ch = getchar() : ch = getchar(); while (ch >= 0 && ch <= 9 ) { res = res * 10 + ch - 0 ; ch = getchar(); } return ...
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); } int main() { fast(); int n, k; cin >> n >> k; vector<int> v(n), vc(k + 1); for (int i = 0; i < n; i++) { cin >> v[i]; } auto it = unique(v.begin(),...
#include <bits/stdc++.h> long long p[16]; void F() { p[1] = 10; for (int i = 2; i <= 14; i++) p[i] = p[i - 1] * 10; } using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); F(); long long n, ans = 0; cin >> n; if (n < 10) { cout << n;...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; array<long long, 2> parent[1000][1000]; long long sze[1000][1000]; array<long long, 2> p(array<long long, 2> x) { if (x == parent[x[0]][x[1]]) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int r, c, n, k; cin >> r >> c >> n >> k; int tab[r][c]; for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) tab[i][j] = 0; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int mod = 998244353; int T; int a[N], b[N], p[N]; bool vis[N]; int main() { scanf( %d , &T); while (T--) { int n, k; scanf( %d%d , &n, &k); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); p[a[i...
#include <bits/stdc++.h> using namespace std; int main() { int tc; scanf( %d , &tc); for (int i = 0; i < tc; i++) { int N, K; scanf( %d %d , &N, &K); if (N < K) { printf( NO n ); continue; } if (N % 2 == 0) { if (2 * K <= N) { printf( YES n...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, q; long long ans, in[N], out[N]; vector<int> f[N]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; ++i) { int x, y; scanf( %d%d , &x, &y); if (x > y) swap(x, y); f[x].push_back(y); ...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; long double x1, y1, x2, y2, s, x3, y3, x4, y4, x5, y5, x6, y6; cin >> a >> b >> c; cin >> x1 >> y1 >> x2 >> y2; x3 = x1; y3 = (-a * x3 - c) / b; y4 = y1; x4 = (-b * y4 - c) / a; x5 = x2; y5 = (-a * ...
#include <bits/stdc++.h> using namespace std; int main() { int n, ai, nb = 0; map<int, int> dict; map<int, int>::iterator it; cin >> n; int i = 0; while (i < n) { cin >> ai; dict[ai]++; i++; } for (it = dict.begin(); it != dict.end(); it++) { while ((it->secon...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int a[N]; int b[N]; int main() { int n; cin >> n; a[1] = 0; for (int i = 2; i <= n; ++i) { int k; cin >> k; a[i] = a[i - 1] + k; } int x = 1e6; for (int j = 1; j <= n; ++j) { x = min(x, a[j...
#include <bits/stdc++.h> using namespace std; queue<pair<int, int> > q; int c[2048][2048]; int dr[4] = {-1, 0, 1, 0}; int dc[4] = {0, 1, 0, -1}, nr, nc; int main() { int n, t, x, y; scanf( %d%d , &n, &t); c[1023][1023] = n; q.push(make_pair(1023, 1023)); pair<int, int> s; int mxr = 1...
#include <bits/stdc++.h> using namespace std; int n, m; long long a[15]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); a[x]++; } long long ans = 0; for (int i = 1; i <= m; i++) for (int j = i + 1; j <= m; j++) ans += a[i] *...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; pair<int, int> p[maxn]; int a[maxn]; int b[maxn]; int n, k, cnt; bool F(int a, int b) { return a > b; } void solve() { scanf( %d %d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d , a + i); for (int i = 1; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; using VVI = vector<VI>; using VB = vector<bool>; using VVB = vector<VB>; using VD = vector<double>; using VVD = vector<VD>; using VS = vector<string>; using PII = pair<int, int>; using VPII = vector<PII>; using VL = vector<long ...
#include <bits/stdc++.h> using namespace std; const int N = 520; int n, m, q, s[4][N][N], id[N], s2[N / 2][N][N], Mx; char c[N][N]; bool CK(int s[N][N], int x1, int y1, int x2, int y2, int op) { int dat = s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1]; return op ? dat : dat == (x2 - x1 ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, k, r; cin >> n >> k >> r; long long ar[n], arr[k]; for (i = 0; i < n; i++) { cin >> ar[i]; } for (i = 0; i < k; i++) { cin >> arr[i]; } sort(ar, ar + n); sort(arr, arr + k); long long a ...
#include <bits/stdc++.h> int getmin(int a, int b) { if (a == -1) return b; else if (b == -1) return a; else return a < b ? a : b; } int solve(int a, int b) { int tot = 0; while (a != 1 || b != 1) { tot++; if (!a || !b) return -1; if (a > b) a -= b; ...
#include <bits/stdc++.h> using namespace std; char s[1010], a[1010], p[1020]; int a1, a2, tot; void cal() { if (a[tot - 2] == . ) { a2 += ((a[tot - 1] - 0 ) * 10 + (a[tot] - 0 )); tot -= 3; } if (a2 >= 100) a2 -= 100, a1++; int sum = 0; for (int i = 1; i <= tot; i++) if ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int n, q; struct X { int id, val; } s[maxn]; struct XX { int a, b; XX() {} XX(int A, int B) { a = A; b = B; } bool operator<(const XX &aa) const { return b > aa.b; } }; XX fir, sec; vector<int> v...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); long long n; cin >> n; vector<long long> a; for (long long i = 0; i < n; ++i) { long long x; cin >> x; a.push_back(x); } sort(a.begin(), a.end()); long long c = 0; for (...
#include <bits/stdc++.h> using namespace std; int c[110]; int main() { int n, i, x, y, j; cin >> n; for (i = 0; i < n; i++) { cin >> x; for (j = 0; j < x; j++) { cin >> y; c[y]++; if (c[y] == n) { cout << y << ; } } } return 0; }...
#include <bits/stdc++.h> using namespace std; void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void R() {} template <class T, class... U> void R(T &head...
#include <bits/stdc++.h> using namespace std; int n, i, ans, a[1001]; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 2; i < n; i++) if ((a[i] > a[i - 1] && a[i] > a[i + 1]) || (a[i] < a[i - 1] && a[i] < a[i + 1])) ans++; cout << ans; return 0; }...
#include <bits/stdc++.h> using namespace std; int Int() { int x; scanf( %d , &x); return x; } long long Long() { long long x; scanf( %lld , &x); return x; } void err(istream_iterator<string> it) { cout << endl; } template <typename T, typename... Args> void err(istream_iterator<s...
#include <bits/stdc++.h> using namespace std; double vp, vd, t, f, c; int main() { cin >> vp >> vd >> t >> f >> c; if (vp >= vd) { cout << 0 ; return 0; } int numberOfBojous = 0; double timeToHaveTheDragonBack = 0, overtakePosition = 0; double princessPosition = vp * t; wh...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double EPS = 1e-10; const int MOD = 1000000007; const int MAXN = 110000; const double PI = acos(-1.0); template <class T> T abs(T x) { return x < 0 ? -x : x; } int num, kase; int flag[22][MAXN]; long long fun() {...
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int> > vt; bool cmp(pair<int, int> x, pair<int, int> y) { return (x.first < y.first || (x.first == y.first && x.second < y.second)); } int main() { cin >> n; for (int i = 1; i <= n; i++) { int u; cin >> u; vt...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2500 + 10, MAXK = 7; int k, sum[MAXN][MAXN], l[MAXK], r[MAXK]; long long Tohka; vector<string> Rotate(vector<string>& a) { vector<string> Houki; for (int i = 0; i < (int)a[0].size(); ++i) { string str; for (int j = 0; j < (int)...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; const int INF = 1e9; int main() { string s; cin >> s; long long n = s.length(); vector<long long> v; long long ans = 0; for (long long i = ...
#include <bits/stdc++.h> using namespace std; map<long long, vector<long long>> v; map<long long, long long> visited, dist, pt; long long mx = 0, nd = 0, mxd = 0, mxn = 0; void bfs(long long u) { visited[u] = 1; queue<long long> q; q.push(u); dist[u] = 0; while (!q.empty()) { u = q.f...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; static int comp[maxn]; static int pr[maxn]; static int n; void make_set() { for (int i = 0; i < n; ++i) { pr[i] = i; comp[i] = 1; } } int find_set(int a) { if (pr[a] == a) return a; return pr[a] = find_set(pr...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > G[100005]; int dp[100005], Xor[100005]; int rec(int n) { int answer = 1e9; for (int i = 0; i < G[n].size(); i++) { int st = G[n][i].first; int ed = G[n][i].second + st - 1; int x = Xor[ed] ^ Xor[st - 1]; if (x ...
#include <bits/stdc++.h> using namespace std; bool is_possible(int m, long long k, long long p[], int n, int x, int a, int y, int b) { if (a != b) { int first = 0; int second = 0; int third = 0; for (int i = 1; i <= m; i++) { if (i % a == 0 && i % b == 0) ...
#include <bits/stdc++.h> using namespace std; void dbg_out() { cerr << b b] n ; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << , ; dbg_out(T...); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; ...
#include <bits/stdc++.h> using namespace std; struct ball { float coord; int mass; float vel; short num; }; bool sort_num(ball a, ball b) { return a.num < b.num; } bool sort_coord(ball a, ball b) { return a.coord < b.coord; } void collide(ball &a, ball &b) { float temp = a.vel; a.vel...
#include <bits/stdc++.h> using namespace std; int n; vector<int> v[10005]; int color[10005]; int flag[10005]; void dfs(int src, int p, int ctr) { if (src == p) { return; } flag[src] = ctr; int i; for (i = 0; i < v[src].size(); i++) { if (color[v[src][i]] == color[src]) { ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int maxar(int arr[], int n) { int res = arr[0]; for (int i = 0; i < n; i++) { res = max(res, arr[i]); } return res; } long long maxar(long long arr[], long long n) { long long res = arr[0]; for (long long...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000 + 10; int a[MAXN]; int sum[MAXN]; int cnt[100 + 10]; vector<int> vc; unordered_map<int, int> mp; int exist[MAXN]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); cnt[a[...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int pc[1 << 10]; for (size_t i = 0; i < (1 << 10); i++) { int buf = 0; for (int j = 0; j < 10; j++) { if ((1 << j) & i) buf++; } pc[i] = buf...
#include <bits/stdc++.h> using namespace std; int n, m, a[105]; int main() { int s = 0, t = 0; ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { if (s >= m) break; else { ...
#include <bits/stdc++.h> using namespace std; const int N = 300 * 1000 + 13; int n; long long a[N], b[N]; void solve() { scanf( %d , &n); for (int i = 0; i < int(n); ++i) scanf( %lld%lld , &a[i], &b[i]); long long ans = 0, mn = 1e18; for (int i = 0; i < int(n); ++i) { int ni = (i + 1) % ...