func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; const int mod = 1e9 + 7; int n, m, f[N], jc[N], njc[N], ans; int qpow(int x, int y) { if (!x) return 0; int res = 1; for (; y; x = 1ll * x * x % mod, y >>= 1) if (y & 1) res = 1ll * res * x % mod; return res; } int ...
#include <bits/stdc++.h> using namespace std; int n, temp, k = 0, input[1001], a[1001]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> temp; a[temp]++; if (a[temp] == 1) input[k++] = temp; } sort(input, input + k); for (int i = 2; i < k; i++) { if (input[i]...
#include <bits/stdc++.h> static const int INF = std::numeric_limits<int>::max(); int dp[101][201]; int main() { int n; std::cin >> n; std::vector<int> t(n), w(n); for (int i = 0; i < n; ++i) { std::cin >> t[i] >> w[i]; } memset(dp, -1, sizeof(dp)); dp[0][0] = 0; for (int i = ...
#include <bits/stdc++.h> using namespace std; const int Sn = 1000010; const int Rtm = 10; long long a[Sn]; int n; long long b[Sn]; int m, c[Sn]; long long g[Sn]; long long G[Sn]; int tG, Gc[Sn]; long long P[Sn]; int tP; long long Ans = 1; long long gcd(long long a, long long b, long long t =...
#include <bits/stdc++.h> using namespace std; int main() { int n; int x; cin >> n >> x; std::vector<int> a; std::vector<int> p(1e6 + 20, 0); std::vector<int> xo; xo.push_back(0); p[x] = p[0] = 1; for (int pi = 1; pi < (1 << n); pi++) { if (p[pi]) continue; a.push_back...
#include <bits/stdc++.h> using namespace std; int a[505], b[505], n, t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { cin >> n; bool ok = 1; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { cin >> b[i]; } ...
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; if (p1 == p2) { p2 = (p1 = buf) + fread(buf, 1, 100000, stdin); if (p1 == p2) return EOF; } return *p1++; } inline int getint() { int x; char c = nc(), b = 1; i...
#include <bits/stdc++.h> using namespace std; long long dp[1024][1024]; long long f(int n, int k) { long long an = 0; if (k == 0) return 1; if (dp[n][k] >= 0) return dp[n][k]; int i; for (i = 1; i <= n - 2; i++) { an += f(i, k - 1) * (n - 1 - i); } return dp[n][k] = an % 10000000...
#include <bits/stdc++.h> using namespace std; long long a[500005], inc[1002], n, q, d; vector<pair<long long, long long> > v[1002]; int main() { ios::sync_with_stdio(false); cin.tie(), cout.tie(); cin >> n >> q; d = sqrt(n); long long cnt = 1; for (int i = 1; i <= n; i++) { long lo...
#include <bits/stdc++.h> using namespace std; template <typename T> void UpdateMax(T& a, T b) { if (a < b) a = b; } template <typename T> void UpdateMin(T& a, T b) { if (a > b) a = b; } template <typename T> inline void read(T& x) { x = 0; char c = getchar(); int flag = 1; whil...
#include <bits/stdc++.h> using namespace std; void enter(vector<long long int> &ar) { long long int n = ar.size(); for (long long int i = 0; i < n; i++) { cin >> ar[i]; } } void show(vector<long long int> &a) { long long int n = a.size(); for (long long int i = 0; i < n; i++) { c...
#include <bits/stdc++.h> using namespace std; char c[110][110][110]; bool a[110][110][110]; bool b[110][110][110]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf( %s , c[i][j]); for (int i = 0; i < n; i++) for (int j = 0;...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { register char c = getchar(); x = 0; for (; c < 0 || c > 9 ; c = getchar()) ; for (; c >= 0 && c <= 9 ; c = getchar()) x = (x << 1) + (x << 3) + c - 0 ; } priority_queue<int> q; int main() { priority_queue...
#include <bits/stdc++.h> using namespace std; void BFS(double, double, double &a); double pSquares(double, double); double n, m, k, r; struct queue_compare { bool operator()(const pair<double, double> &p1, const pair<double, double> &p2) const { return pSquares(p1.first, p1.secon...
#include <bits/stdc++.h> using namespace std; const long long linf = 1e18 + 5; const int mod = (int)1e9 + 7; const int logN = 17; const int inf = 1e9; const int N = 2e5 + 5; int temp[1 << 7][1 << 7], res[1 << 7][1 << 7], cur[1 << 7][1 << 7], x; void mul(int res[][1 << 7], int cur[][1 << 7], int t) { ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; template <typename T, typename U> pair<T, U> operator+(const pair<T, U> &l, const pair<T, U> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T, typename U> pair<T, U> operator-(const pair...
#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; void bogo(vector<int>& a) { for (int i = 0; i < a.size() - 1; i++) { int biggest = i; for (int j = i + 1; j < a.size(); j++) if (a[biggest] < a[j]) biggest = j; if (biggest != i) swap(a[i], a[biggest]); } } int main(int argc, char**...
#include <bits/stdc++.h> const int N = 52, M = 106, INF = 2000000000; inline int f(char c) { if ( a <= c && c <= z ) return c - a + 1; return c - A + 27; } inline char rf(int i) { if (i <= 26) return a + i - 1; return A + i - 27; } struct edge { int capacity, cost, flow; ed...
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const int maxn = 110; int n, m, K; long long f[maxn][maxn][maxn]; int col[maxn]; long long p[maxn][maxn]; int main() { scanf( %d%d%d , &n, &m, &K); for (int i = 1; i <= n; i++) scanf( %d , &col[i]); for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; int n, m, i; int k1, k2, k3, t1, t2, t3; long long a[MAX], b[MAX], t[MAX]; int main() { cin >> k1 >> k2 >> k3 >> t1 >> t2 >> t3 >> n; for (i = 0; i < n; i++) { scanf( %d , &a[i]); b[i] = a[i]; } for (i = 0; i ...
#include <bits/stdc++.h> using namespace std; long long a, b, c; long long n, m, k; int arr[100050]; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; bool odd = false, even = false; for (int i = 1; i <= n; i++) { cin >> arr[i]; if ((arr[i] - 0 ) % 2 == ...
#include <bits/stdc++.h> using namespace std; int p[300], a[300], num[300]; int find(int x) { if (p[x] == 0) return x; else { p[x] = find(p[x]); return p[x]; } } void merge(int x, int y) { x = find(x); y = find(y); if (x != y) p[x] = y; } int main() { int n, m...
#include <bits/stdc++.h> using namespace std; const int mod = 1000003; char in[2010]; int catlen[2010]; long long fac[4010], inv[4010], rf[4010]; int t[2010], tc; int first[2010], stc; long long dp[2010][2010]; inline int solve() { int n = strlen(in); tc = 0; bool isn = 0, ist; for (in...
#include <bits/stdc++.h> using namespace std; int read() { int nm = 0, fh = 1; char cw = getchar(); for (; !isdigit(cw); cw = getchar()) if (cw == - ) fh = -fh; for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw - 0 ); return nm * fh; } struct node { int x, y, w; } p[100001...
#include <bits/stdc++.h> using namespace std; const int N = 300; int a[N]; void solve(){ int n; cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } int left = 0, right = n - 1, index = 1; while(left <= right){ if(index++ % 2){ co...
#include <bits/stdc++.h> using namespace std; long n, m; char c; long hi[600000][3], hj[600000][3], ans; long temp; long l, u; int main() { ios_base::sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> c; if (c == . ) con...
#include <bits/stdc++.h> using namespace std; string a, b; bool x, y; bool solve(string a, string b) { char x = e , y = e ; if (a[0] != X ) { x = a[0]; } if (a[1] != X ) { if (x == e ) x = a[1]; else y = a[1]; } if (b[1] != X ) { if (y == e ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; struct rec { int x1, y1, x2, y2; }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); vector<rec> v; int n; cin >> n; multiset<int> x1, x2, y1, y2; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int l[200100], r[200100]; bool cmp(int a, int b) { if (l[a] == l[b]) return r[a] < r[b]; else return l[a] < l[b]; } int main() { int n, i, j, k; int h[200100]; cin >> n; for (i = 1; i <= n; i++) { scanf( %d%d , &l[i], &r[i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); double a[20] = {0}; int i = 0; for (i = 0; i < 16; i++) cin >> a[i]; double x1 = a[0], x2 = a[2], x3 = a[4], x4 = a[6]; double y1 = a[1], y2 = a[3], y3 = a[5], ...
#include <bits/stdc++.h> using namespace std; const int tam = 100010; const int MOD = 1000000007; const int MOD1 = 998244353; const double EPS = 1e-9; const double PI = acos(-1); const int sq = 500; int ar[tam]; int res[tam]; bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { ...
#include <bits/stdc++.h> using namespace std; int n, m, a[100010]; map<string, int> mp; int tot, cnt[100010]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + n + 1); char f[110]; string s; for (int i = 1; i <= m; i++) { scanf( ...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int C = 26; void add(int &x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x) { while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int pw(int a, int b) {...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void solve() { int n, m, k, x, y; cin >> n >> m >> k; for (int i = 0; i < 2 * k; i++) cin >> x >> y; string ans = ; ans += (string(n - 1, U ) + string(m - 1, L )); for (int i = 0; i < n; i++) { if (i & 1) ...
#include <bits/stdc++.h> int w[505]; int book[505]; int v[1005]; int used[505]; int main(void) { int n, m; int k; int r = 0; scanf( %d %d , &n, &m); for (int i = 1; i <= n; i++) { used[i] = 0; scanf( %d , &w[i]); } for (int i = 1; i <= m; i++) { scanf( %d , &v[...
#include <bits/stdc++.h> using namespace std; char b[1000050], a[1000050]; int n, m, p, P; bool c[2050], ans[2050], Ans; bool Calc(int x, int y, int z, int o, int u) { for (; o >= z; o--) { bool Flag = false; while (y >= x) { bool flag = true; for (int j = y, k = o; j <= n && k...
#include <bits/stdc++.h> using namespace std; int main() { int n, val = 0; cin >> n; int k; cin >> k; for (int i = 1; i <= n; i++) { if (k % i == 0 && k / i <= n) val++; } cout << val; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= k; ++i) cout << 2 * i << << 2 * i - 1 << ; for (int i = 2 * k + 1; i <= 2 * n; ++i) cout << i << ; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_SIZE = 10; int n; unsigned long long adj[200010], k; struct Matrix { unsigned long long a[MAX_SIZE][MAX_SIZE]; Matrix() { for (int i = 0; i < MAX_SIZE; i++) for (int j = 0; j < MAX_SIZE; j++) a[i][j] = 0; } Matrix mul(Ma...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; inline void cmin(int &x, int y) { if (y < x) x = y; } inline void cmax(int &x, int y) { if (y > x) x = y; } bool isvowel(char a) { if (a == a ||...
#include <bits/stdc++.h> using namespace ::std; const long long maxn = 1e5 + 500; const long long mod = 1e9 + 7; const long long inf = 1e9 + 500; const long long rad = 330; long long a[maxn]; long long t[maxn]; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first / rad ...
#include <bits/stdc++.h> using namespace std; int N; int Move[100005], cnt, P[100005]; vector<int> G[100005]; int TT[100005], Next[100005]; int DP[100005], Stack[100005], top; void Read() { scanf( %d , &N); for (int i = 1; i < N; i++) { int father; scanf( %d , &father); ++father;...
#include <bits/stdc++.h> using namespace std; const int N = 1000005; const int mod = 1e9 + 7; struct point { int x, y; inline friend long long operator*(point a, point b) { return 1ll * a.x * b.y - 1ll * a.y * b.x; } } p[N]; long long sx[N], sy[N], s[N], ans, sum, area; int n; inline l...
#include <bits/stdc++.h> using namespace std; void solve() { int t; cin >> t; while (t--) { int n; cin >> n; int r, p, s; cin >> r >> p >> s; string q; cin >> q; int lastn = ceil(n / 2.0); int R = 0, P = 0, S = 0; for (long long i = 0; i < q.size(); ...
#include <bits/stdc++.h> int main() { char s[20]; bool jizz = false; int value1[61] = {0}, value2[61] = {0}, k, max = 0; int m, n, a, b; scanf( %s , &s); for (m = 0; m < strlen(s); m++) { if (s[m] == : ) break; for (a = 2; a < 61; a++) { if (s[m] <= Z && s[m] >= A ) ...
#include <bits/stdc++.h> using namespace std; char s1[6], s2[6], ch; int cnt = 0, ans, ok1, ok2; bool func1(int sumA, int sumB, char s[]) { int dif = sumB - sumA; for (int i = 0; i < 3; i++) { bool fl = 0; ch = s[i]; while (ch < 9 && dif > 0) ch++, dif--, fl = 1; if (fl) cnt++;...
#include <bits/stdc++.h> const int MAX_LEN = 1010; using namespace std; template <typename U, typename V> string to_string(pair<U, V>); string to_string(const string& e_) { return + e_ + ; } string to_string(char e_) { return + string(1, e_) + ; } string to_string(bool e_) { return e_ ? t...
#include <bits/stdc++.h> using namespace std; long long int M = 998244353, q, n, p[300001], d[300001], fans, products[300001], invproducts[300001]; long long int power(long long int x, long long int n) { if (n == 0) return (long long)1; else if (n % 2 == 0) return power((x * x)...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, one, two[2], tmp, num, a[N]; bool flag, f[N]; int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { ...
#include <bits/stdc++.h> using namespace std; void getre() { int x = 0; printf( %d n , 1 / x); } void gettle() { int res = 1; while (1) res <<= 1; printf( %d n , res); } template <typename T, typename S> inline bool upmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; } templ...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adjl(500000); int s[500000] = {0}; long long int a[500000] = {0}; map<pair<int, int>, long long int> mp; int vis[500000] = {0}; void dfs(int n, vector<pair<int, int> > &ans, int p, long long int sum, long long int mini) { if...
#include <bits/stdc++.h> using namespace std; long long f[100]; int s[100]; long long dp[100][2]; int main() { f[0] = f[1] = 1; for (int i = 2; i < 100; i++) { f[i] = f[i - 1] + f[i - 2]; } int cas; cin >> cas; while (cas--) { long long n; cin >> n; int cnt = 0;...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) { return a; } else { return b; } } long long min(long long a, long long b) { if (a < b) { return a; } else { return b; } } string int2str(int& i) { string s;...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long double PI = acos((long double)-1); const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; void setIO(string name = ) { ios_base::sync_with_stdio(0); cin.tie(0); if ((int)(name)....
#include <bits/stdc++.h> using namespace std; const int SQ = 350; const int MAX_N = 100000; deque<int> a[MAX_N / SQ + 10]; int num[MAX_N / SQ + 10][MAX_N + 10]; int N, Q, lastans = 0; void print() { for (int i = 0; i <= N / SQ; i++) { for (int j = 0; j < a[i].size(); j++) { cout << a[i][...
#include <bits/stdc++.h> using namespace std; pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) { return make_pair(a.first + b.first, a.second + b.second); } pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) { return make_pair(a.first - b.first, a.second...
#include <bits/stdc++.h> using namespace std; long long i, j, k, n, a[100500][3], dp[100500][2]; int main() { cin >> n; for (j = 0; j < 3; j++) for (i = 0; i < n; i++) cin >> a[i][j]; dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; for (i = 1; i <= n; i++) { dp[i][0] = max(dp[i - 1][0] + a...
#include <bits/stdc++.h> using namespace std; const long long N = 2001111; long long n, m, k; long long md = 1000000007; long long a[N]; set<long long> s; long long len[N]; vector<long long> t[N]; vector<long long> pref[N]; void merge(vector<long long> &t, vector<long long> a, vector<long long> b, ...
#include <bits/stdc++.h> using namespace std; int n, m; int x, y; vector<int> v1[200086], v2[200086]; bool ins[200086]; bool vis[200086], vis1[200086], vis2[200086]; bool e[200086]; int ans; void dfs(int i) { vis[i] = ins[i] = true; for (int j = 0; j < v1[i].size(); j++) { int to = v1[i]...
#include <bits/stdc++.h> using namespace std; int main() { vector<char> vec(100001); vec[0] = a ; int i = 1; while (i < 100001) { if (vec[i - 1] == a ) vec[i] = b ; else if (vec[i - 1] == b ) vec[i] = c ; else if (vec[i - 1] == c ) vec[i] = d ; ...
#include <bits/stdc++.h> using namespace std; map<long long, int> cont; int n; int ans; int main() { while (~scanf( %d , &n)) { int a; long long num = 0; for (int i = 1; i <= n; i++) { scanf( %d , &a); num += a; ans = max(ans, ++cont[num]); } printf( %...
#include <bits/stdc++.h> using namespace std; int n, m, k, d1[200005], d2[200005], ty, re1, re2, re3; long long s, a[200005], b[200005], te; vector<pair<long long, int> > v1, v2; vector<long long> v3; void bs(int lo, int up) { int mid = (lo + up) / 2; if (lo == up) { v3.clear(); for (int...
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m >> n; cout << (n * m) / 2 << n ; }
#include <bits/stdc++.h> const int inf = (1ll << 30) - 1; const int maxn = (int)1e5 + 10; using namespace std; int dp[150][(1 << 16) + 100]; int c[111]; int r[111]; int b[111]; char temp[111]; int cntR[(1 << 16) + 10]; int cntB[(1 << 16) + 10]; int n; void solve() { memset(dp, -1, sizeof dp)...
#include <bits/stdc++.h> using namespace std; vector<int> adj[300005]; vector<int> vec; int par[300005]; int vis1[300005]; int vis2[300005]; int vis3[300005]; int vis4[300005]; int dia[300005]; int root(int x) { return par[x] = ((par[x] == x) ? x : root(par[x])); } void unite(int x, int y) { par[r...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n = 0, s = 0; cin >> n >> s; if (s > n) { if (s % n != 0) { cout << ((s / n) + 1); } else { cout << (s / n); } } else { cout << 1;...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); printf( %d , n); for (int i = 1; i < n; i++) { printf( %d , i); } return 0; }
#include <bits/stdc++.h> using namespace std; long long int solve(long long int a, long long int b) { long long int x = sqrt(8 * (a + b) + 1) - 1; return x / 2; } int main() { long long int a, b; cin >> a >> b; long long int x = solve(a, b); vector<long long int> w1, w2; for (long lo...
#include <bits/stdc++.h> using namespace std; int main() { int m, n, a[200005], b[200005]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> m; for (int i = 0; i < m; i++) cin >> b[i]; sort(a, a + n); sort(b, b + m); int x = 0, y = 0; int ans; int aa = (x * 2 + (n - x...
#include <bits/stdc++.h> using namespace std; int a[100500]; int p[100500]; int q[100500]; vector<pair<int, int> > moves; int n, h = -1; bool asign(int x, int y) { return a[x] < a[y]; } bool happy(int n) { if (n == 0) return true; if (n % 10 == 7 || n % 10 == 4) return happy(n / 10); return ...
#include <bits/stdc++.h> using namespace std; inline void wait(double seconds) { double endtime = clock() + (seconds * CLOCKS_PER_SEC); while (clock() < endtime) { ; } } inline int fastIn() { register char c = 0; register int a = 0; while (c < 33) c = getchar(); while (c > 33) ...
#include <bits/stdc++.h> using namespace std; int main() { int a[6]; for (int i = 0; i < 6; i++) { cin >> a[i]; } int ans = (a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - a[0] * a[0] - a[2] * a[2] - a[4] * a[4]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (x == 0) return y; else return gcd(y % x, x); } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } bool sortbysize(string &s1, string &s2) { return s1.size() < s2....
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int inf = 1000000007; const long long linf = 1LL << 62; const unsigned long long ulinf = 1ULL << 63; const double eps = 0.000001; const double pi = 3.14159265358979323846; template <class T> T abs...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k; int n; cin >> n; long arr[n][2]; for (i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1]; long long minx, miny, maxx, maxy; minx = arr[0][0]; miny = arr[0][1]; maxx = arr[0][0]; maxy = arr[0][1]; for (i...
#include <bits/stdc++.h> using namespace std; void __print(long long x) { cerr << x; } void __print(long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __pr...
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; const long double eps = 1e-8; struct frac { long long x, y; frac() {} frac(long long x, long long y) : x(x), y(y) {} bool operator==(const frac& ot) { return x * ot.y == y * ot.x; } bool operator<(const frac& ot) { r...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, c; cin >> n >> m >> c; vector<int> A(n), B(m); for (auto &a : A) cin >> a; for (auto &b : B) cin >> b; int i = 0, x = 0; for (int i = 0; i < n; ++i) { if (i < m) x = (x + B[i]) % c; if (i > n - m) x = (x - B...
#include <bits/stdc++.h> using namespace std; const int N = 500010; int n, m; struct edge { int a, b, c, t; } e[N]; inline bool operator<(const edge &a, const edge &b) { return a.c < b.c; } struct union_find { int f[N], h[N], sz[N], cnt; struct oper { int x, fx, hx, szx, tc; } op[N *...
#include <bits/stdc++.h> using namespace std; long long int a[500005], b[500005]; int main() { int i, j, k, l, x, y, z, m, n, t; cin >> t; while (t--) { cin >> x >> y >> z; while (x > 20 && y) { x = x / 2; x += 10; y--; } while (x >= 0 && z) { x ...
#include <bits/stdc++.h> using namespace std; int main() { float a, b, c, t; cin >> a >> b; if (a > b) swap(a, b); c = (b - a) / 2; t = floor(c); c = ceil(c); int f = 0, y = 0; for (int i = 1; i <= c; i++) { f += i; } for (int i = 1; i <= t; i++) { y += i; } ...
#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; map<long long, long long> cn; set<long long> fac; while (t--) { fac.clear(); cn.clear(); long long n; cin >> n; ...
#include <bits/stdc++.h> using namespace std; long long int a[200005]; long long int dist[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int n; cin >> n; for (long long int i = 0; i < n; i++) dist[i] = INT_MAX; for (long long int i = ...
#include <bits/stdc++.h> #pragma GCC optimization( O3 ) using namespace std; template <typename T> inline void Cin(T& first) { char c; T sign = 1; first = 0; for (c = getchar(); c < 0 || c > 9 ; c = getchar()) if (c == - ) sign = -1; for (; c >= 0 && c <= 9 ; c = getchar()) firs...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; using ll = long long; const int N = 120005; struct node_t { int tag, time, value, number; ll answer; } tree[N << 2]; int n, m, top_max, top_min, a[N],...
#include <bits/stdc++.h> using namespace std; long long a[300005], ans; int n, num[300005], cnt[2] = {1}, sum[300005]; int change(long long x) { int ans = 0; while (x) { ans += (x % 2); x /= 2; } return ans; } int main() { cin >> n; for (int i = 1; i <= n; i++) { sc...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000; const int MAX_E2 = 1 << 18; const int MAX_A = 100000; const int INF = 1 << 30; int uas[MAX_N]; pair<int, int> ps[MAX_N], cns[MAX_A]; vector<int> cvs[MAX_A]; bool used[MAX_A]; int check(int m, int uan, int c0, int x) { memset...
#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; --n; int right, left, down, up; right = left = down = up = n / 4; n = n - up * 4; if (n != 0) { ++right; --n; } if (n != ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; long long int freq[200001] = {0}; for (long long int i = 0; i < n; i++) { cin >> a[i]; freq[a[i]]++; } ...
// Template begins #include <iostream> #include <algorithm> #include <vector> #include <set> #include <stdio.h> #include <stack> #include <math.h> #include <complex> using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ll long long #define end...
#include <bits/stdc++.h> using namespace std; long long r, sum, lim[4], s[4], x[4], y[4], dist, a[3], d, tol; int k[4][3] = {1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1}; void func() { printf( %I64d %I64d %I64d n , (s[1] + s[2]) / 2, (s[1] + s[3]) / 2, (s[2] + s[3]) / 2); return; } bool check(i...
#include <bits/stdc++.h> const int N = 65550; int ru[N], sum[N]; int n; int s[N], t[N], cc = 0; int main() { int i; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d%d , &ru[i], &sum[i]); for (i = 0; i < n; i++) { int now = i; while (ru[now] == 1) { cc++; s[cc] = n...
#include <bits/stdc++.h> int a[200010]; int main() { long long ans = 0; int m = 0, n; scanf( %d n , &n); for (int i = 1; i <= n; i++) { int a1, b1, a2, b2; scanf( %d%d%d%d n , &a1, &b1, &a2, &b2); if (a1 + b1 >= a2 + b2) { a[++m] = a1 + b1; a[++m] = a2 + b2; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 9; const int MAX = 2e2 + 9; const double ep = 1e-6; const int mod = 998244353; const int INF = 0x3f3f3f3f; const double inf = 1e20; const double pi = acos(-1); vector<int> vec[maxn]; int n, m, k, d[maxn], cnt1, ans[maxn], tot; bo...
#include <bits/stdc++.h> using namespace std; vector<long long> v; int main() { long long p, k, rem; cin >> p >> k; v.push_back(-p / k); for (int i = 0;; i++) { for (long long x = v.back() / k - 1; x <= v.back() / k + 1; x++) { if (v.back() - x * k >= 0 && v.back() - x * k < k) { ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 55; int x[MAX]; int main() { int n; cin >> n; double sum = 0; int a[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, greater<int>()); for (int i = 0; i < n; i++) { if (i % 2 == 0) sum += ...
#include <bits/stdc++.h> using namespace std; struct edge { int u, v, l, id; edge() {} edge(int a, int b, int c, int d) { u = a, v = b, l = c, id = d; } bool operator<(const edge &p) const { return l < p.l || (l == p.l && id < p.id); } }; char *p1, *p2, buffer[10000009]; int n, m, cu...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; vector<int> p; int a[27] = {0}; for (int i = 0; i < s.size(); i++) { if (s[i] == ? ) { p.push_back(i); } else { a[int(s[i]) - 96]++; } } if (p.size() == 0) { co...
#include <bits/stdc++.h> const int MAXN = 2e5 + 7; int a[MAXN]; int main() { int N; scanf( %d , &N); for (int i = 1; i <= N; ++i) scanf( %d , &a[i]); int ans = 0; int j = 1, i; for (i = 2; i <= N;) { while (i <= N && a[i] <= 2 * a[i - 1]) { ++i; ans = (ans > i - j ? a...