func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> arr; vector<int> t; for (int i = 0; i < n; i++) { int a; cin >> a; t.push_back(a); arr.push_back({a, i}); } sort(arr.begin(), arr.end()); int i, j; for (i = ...
#include <bits/stdc++.h> using namespace std; struct point { long double x, y; }; point a1, a2, a3, a4, b1, b2, b3, b4, c; int l, r, u, d; bool corner(point b) { if (b.x <= r && b.x >= l && b.y <= u && b.y >= d) return true; else return false; } pair<long double, long double> lin...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); srand(time(NULL)); ; int T = 1; cin >> T; while (T--) { int n; cin >> n; cout << setprecision(10) << cos(3.141592653589793238 / (4 * n)) / ...
#include <bits/stdc++.h> using namespace std; long long int get(long long int x) { long long int y = 1, ans = 0; while (y < x) { y = y * 2; if (y <= x) ans++; else break; } return ans; } int main() { int t = 1; cin >> t; while (t--) { long long...
#include <bits/stdc++.h> using namespace std; const int debug_ = 0; const int maxn = 200000; const long long inf = 998244353; int unum[33], dnum[33]; long long dp[33][2][2][2]; long long dfs(int pos, int u, int e, int d) { if (pos == -1) { return 2 - e; } if (dp[pos][u][e][d] != -1) { ...
#include <bits/stdc++.h> using namespace std; const long long N = 205, P = 1e9 + 7ll; struct node { long long x, y; node operator-(const node &t) const { node c; c.x = x - t.x; c.y = y - t.y; return c; } long long operator*(const node &t) const { return x * t.y - y * t.x; }...
#include <bits/stdc++.h> using namespace std; long long quick_pow(long long a, long long b, long long mod) { long long ans = 1, base = a; while (b) { if (b & 1) (ans *= base) %= mod; b >>= 1; (base *= base) %= mod; } return ans; } struct node { int pos, len; bool operat...
#include <bits/stdc++.h> using namespace std; long long parent[200001]; long long urank[200001]; void create(long long x) { parent[x] = x; urank[x] = 1; } long long find(long long x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } void merge(long long...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const long double pi = acos(-1.0); const long long inf = 1e+9; const long long inf64 = inf * inf; #pragma comment(linker, /STACK:36777216 ) template <typename T> istream &operator>>(istream &, vector<T> &); template <typename...
#include <bits/stdc++.h> using namespace std; int a[11], n; long long dp[11][111], c[111][111]; int main() { memset(c, 0, sizeof(c)); for (int i = (0); i < (111); i++) c[i][0] = 1; for (int i = (1); i < (111); i++) for (int j = (1); j <= (i); j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][...
#include <bits/stdc++.h> using namespace std; const int inf = 0x7f7f7f7f; int main() { string s; cin >> s; int ans = 0; stack<char> S; for (int i = 0; i < s.length(); i++) { if (S.empty()) { S.push(s[i]); } else if (S.top() == s[i]) { ans++; S.pop(); }...
#include <bits/stdc++.h> long long int x, y, z, i, flag, flag2, top; long long int A[200010]; int main() { scanf( %lld , &x); for (i = 1; i <= x; i++) { scanf( %lld , &A[i]); if (A[i] == 1 && flag == 0) { y = i + 1; flag = 1; } } for (i = y; i <= x; i++) { i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005, INF = 1 << 31; struct A { int x, w; } a[MAXN]; int b[MAXN], c[MAXN], n, d[MAXN], f[MAXN]; bool cmp(const A &x, const A &y) { return x.x < y.x; } int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d%d , &a[i]....
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, mod = 1e9 + 7; const long long inf = 1e18; long long tn[20], fv[20]; long long Mul(long long a, long long b, long long md) { long long ans = 0; while (b) { if (b & 1) ans = (ans + a) % md; a = (a + a) % md; b >>...
#include <bits/stdc++.h> template <typename T> inline bool MIN(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool MAX(T &a, const T &b) { return a < b ? a = b, 1 : 0; } inline int plu(int a, int b) { return a + b >= 1000000007 ? a + b - 1000000007 : a + b; }...
#include <bits/stdc++.h> using namespace std; unsigned int inet4[100010]; int main(int argc, char* argv[]) { ios_base::sync_with_stdio(false); int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) { char* str; int inet[4]; scanf( %d.%d.%d.%d , &inet[0], &inet[1], &inet[2],...
#include <bits/stdc++.h> using namespace std; int a[114514]; int l[114514], r[114514]; bool solve(int n) { int curr = a[1]; l[1] = a[1]; for (int i = 2; i <= n; i++) { if (a[i] < a[i - 1]) curr -= a[i - 1] - a[i]; if (curr < 0) return false; l[i] = curr; } return true; } ...
#include <bits/stdc++.h> using namespace std; int t[95]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> t[i]; } t[0] = 0; int langkah; langkah = 0; for (int i = 1; i <= n; i++) { int a; a = t[i] - t[i - 1]; if (a <= 15) langkah++...
#include <bits/stdc++.h> using namespace std; int n, nn = 0, pp = 0; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); if (x < 0) nn++; else if (x > 0) pp++; } if (nn >= n / 2 + n % 2) printf( -1 ); else if (pp >=...
#include <bits/stdc++.h> using namespace std; int N, M, K, R; char arr[102][102]; int best[102][102][1002]; int solve(int r, int c, int p) { if (r < 0) { if (p % K == 0) return p; return -1 << 30; } if (best[r][c][p] != -1) return best[r][c][p]; int ret = -1 << 30; if (c - 1 >=...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; char ch; bool v[111][111]; struct data { int x1, y1, s1, x2, y2, s2; void sv(int a, int b, int c, int d, int e, int f) { x1 = a; y1 = b; s1 = c; x2 = d; y2 = e; s2 = f; } } p[111][111][2...
#include <bits/stdc++.h> using namespace std; int N, M, i, X, A[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M; for (i = 0; i < 2 * M; i++) { cin >> X; A[X]++; } if (N == M) { for (i = 1; 1; i++) { if (A[i] != 2) { ...
#include <bits/stdc++.h> using namespace std; int main() { int hour, minute, sleeph, sleepm; char temp; scanf( %d%c%d , &hour, &temp, &minute); scanf( %d%c%d , &sleeph, &temp, &sleepm); int shour, smin; smin = minute - sleepm; if (smin < 0) { smin += 60; hour--; } sho...
#include <bits/stdc++.h> using namespace std; vector<int> x, y, z; inline int sqr(int x) { return x * x; } inline double dist(int i, int j) { return sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j])); } int main() { int n; cin >> n; x.resize(n), y.resize(n), z.resize(n); for (i...
#include <bits/stdc++.h> using namespace std; long long modpow(long long b, long long e, long long mod) { long long ans = 1; for (; e; b = b * b % mod, e /= 2) if (e & 1) ans = ans * b % mod; return ans; } const int N = 5050; int dp[N][N][2], c[N], n; bool vis[N][N][2]; int solve(int x, ...
#include<bits/stdc++.h> using namespace std; #define endl n #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; cin>>t; while(t--) { ll n; cin>>n; if(n<=3) cout<<n-1<<endl; else { if(n%2==0) cout<<2<<endl; else { ...
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for(int i=0;i<a;i++) #define repA(i,a,b)for(int i=a;i<b;i++) #define l list #define v vector #define u_m unordered_map typedef long long ll; const int mxN=101,MOD=1e9+7; void solve(){ int n,m,count=1,r=0; cin>>n>>m; string s; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e13; void solve() { long long n; cin >> n; vector<pair<long long, long long> > a(n); for (long long i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; } sort(a.begin(), a.end()); long long cnt = 1, a...
#include <bits/stdc++.h> using namespace std; int main() { int tosub = 0; int pls = 1; int mins = 0; string s; char a; cin >> a; while (a != = ) { if (a == + ) { s.push_back(a); pls++; } else if (a == - ) { mins++; s.push_back(a); } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 100; int head[maxn], cnt; vector<int> pos[maxn]; int len[maxn]; int val[maxn], pre[maxn], vis[maxn]; char str[1100]; char pat[1100]; struct edge { int from, to, flow, next, cost; } e[2 * maxn]; void addedge(int from, int to, ...
#include <bits/stdc++.h> using namespace std; inline const int read() { int r = 0, k = 1; char c = getchar(); for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) k = -1; for (; c >= 0 && c <= 9 ; c = getchar()) r = r * 10 + c - 0 ; return k * r; } long long n; int k, a[110]; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int k; string s, t; int dp[100005][2], cnt[2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> s >> t; cin >> k; int n = s.length(); for (int i = 1; i < n; i++) { int l = n - i; st...
#include <bits/stdc++.h> using namespace std; long long ar[1000000 + 9]; long long POW1[1000000 + 9]; long long POW2[1000000 + 9]; pair<long long, long long> KEEP[1000000 + 9]; map<pair<long long, long long>, long long> mymap; struct data { long long a, b, val; }; vector<data> vec; long long que...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 23, maxm = 30000; int n, K, a[maxn], w[maxn], F[maxn][maxm + 10000]; int main() { scanf( %d%d , &n, &K); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) scanf( %d , &w[i]), w[i] = a[i] - w[i] * K; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const long long INF = (long long)1e17 + 10; int n, m, s, t; int a[N], b[N], l[N]; struct edge { int to, cost; edge(int to, int cost) : to(to), cost(cost) {} }; vector<edge> e; vector<int> g[N]; vector<int> g2[N]; long lo...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; int N, M, X[1000], a, b, c; int main() { ios_base::sync_with_stdio(0); cout.precision(15); cin >> N >> M; for (int(i) = 1; (i) <= (N); (i)++) cin >> X[i]; long double answer = 0; fo...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, l = 1, a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (l == 1) { if (a % 2 == 1) { cout << 2 << endl; l = 1; } else { l = 2; cout << 1 << endl; ...
#include <bits/stdc++.h> using namespace std; const int MAXQ = 2e5; vector<int> solve(int K, vector<tuple<uint32_t, uint32_t, int> > V) { uint32_t mask = (((uint32_t)1) << K) - 1; vector<int> HT(1 << K), LT(1 << K); for (auto [l, r, v] : V) if (v) { uint32_t lhi = l >> K, llo = l & mask;...
#include <bits/stdc++.h> using namespace std; const int rmax = 15; const int nmax = 100500; struct DP { int x; int y; int z; int i; int j; int k; }; bool operator<(const DP& l, const DP& r) { return l.x < r.x || (l.x == r.x && l.y < r.y) || (l.x == r.x && l.y == r.y &&...
#include <bits/stdc++.h> #pragma GCC target( sse4,avx ) const int inf = 100000; int rec(size_t gl, std::vector<int>& odd, std::vector<bool>& flags, std::vector<std::vector<int>>& graph) { if (gl == odd.size()) { return 0; } if (flags[gl]) { return rec(gl + 1, odd, flags, graph); ...
#include <bits/stdc++.h> using namespace std; void Oli() { int a; cin >> a; vector<pair<int, int>> pr(a); for (int i = 0; i < a; i++) { cin >> pr[i].first >> pr[i].second; } int s = 0; int k = 1; for (int i = 0; i < pr.size(); i++) { if (pr[i].second >= 1) { k--; ...
#include <bits/stdc++.h> int loya[8]; int tloyal[8]; int level[8]; double pb[1 << 8]; int N, K, A; void init_search(int state, int B, int deepth, int cnt) { if (deepth == N) { pb[state] = cnt > (N >> 1) ? 1.0 : A / (double)(A + B); } else { init_search(state | (1 << deepth), B, deepth + ...
#include <bits/stdc++.h> using namespace std; long long h, n; long long ret = 0LL; int a[60]; long long two(int x) { if (x == 0) return 1LL; long long half = two(x / 2); half *= half; return x % 2 ? half * 2 : half; } void solve() { int c = 0; --n; while (n) { a[c++] = n ...
#include <bits/stdc++.h> using namespace std; int n, k, a[101], m, ans; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> k; if (k % 2) a[++m] = k; ans += k; } if (m == 0) { cout << 0 << endl; return 0; } if (m % 2 == 0) { sort(a + 1, a + m + ...
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[100010]; struct node { int x, id; } p[100010]; int main() { while (scanf( %d%d , &n, &k) != EOF) { for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } int ans = 99999999; int pos = 1; for (int i =...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void upd_min(T& dest, const T& src) { if (src < dest) dest = src; } template <typename T> inline void upd_max(T& dest, const T& src) { if (dest < src) dest = src; } template <typename T, int n> struct Queue { T q[n]...
#include <bits/stdc++.h> using namespace std; const int Max = 2e5 + 10; int n, k; int v, u; vector<int> stl[Max]; struct node { long long cou; long long huo; node() { cou = huo = 0; } } point[Max]; int vis[Max]; long long tot = 0; void dfs(int idex, int cou) { vis[idex] = 1; poin...
#include <bits/stdc++.h> using namespace std; long long n, m, k; string s; int a[4][100]; vector<int> seq; vector<pair<int, int> > poseq; bool check() { for (int i = 0; i < n; i++) { if (a[1][i] != 0 || a[2][i] != 0) { return true; } } return false; } pair<int, int> nex...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, l, r, m; cin >> n >> k; deque<pair<int, int>> bfs; vector<int> lines; vector<int> ans(n); --k; bfs.push_back({0, n}); while (!bfs.empty()) { l = bfs[0].first; r = bfs[0].second; m = (l + r) / 2; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010, mod = 1e9 + 7, INF = 0x3f3f3f3f; const double eps = 1e-6; int n, m; int id[N]; vector<int> v[N]; bool st[N]; bool check() { int cnt = 0; for (int i = 1; i <= n; i++) if (!id[i]) { cnt++; id[i] = cnt; ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 1010; const int inf = 1 << 23; int ch[Maxn << 1][3], siz[Maxn << 1], maxs[Maxn << 1], alls, core; bool vis[Maxn << 1]; int n, tot, T; void dfs(int x, int fa) { siz[x] = 1; maxs[x] = 0; for (int i = 0; i < 3; i++) { int y = ch...
#include <bits/stdc++.h> using namespace std; int to[2000]; char used[2000]; int a[2000]; int s; char res[3000]; int calc(int x, char &f) { f = 0; int cnt = 1; if (x == s) f = 1; while (to[x] != -1) { ++cnt; x = to[x]; if (x == s) { f = 1; cnt = 1; }...
#include <bits/stdc++.h> using namespace std; const int SIZE = 1000005; char sa[SIZE], sb[SIZE]; char rab[SIZE * 2], ba[SIZE * 2]; int f1[SIZE * 2]; int f2[SIZE * 2]; int main() { while (gets(sa) && gets(sb)) { int l1 = strlen(sa); int l2 = strlen(sb); if (l1 != l2) { printf(...
#include <bits/stdc++.h> using namespace std; int CeilIndex(int A[], int l, int r, int key) { int m; while (r - l > 1) { m = l + (r - l) / 2; (A[m] <= key ? l : r) = m; } return r; } int LongestIncreasingSubsequenceLength(int A[], int size) { int *tailTable = new int[size]; i...
#include <bits/stdc++.h> using namespace std; int weight(char c) { if (c == Q || c == q ) return 9; if (c == R || c == r ) return 5; if (c == B || c == b ) return 3; if (c == N || c == n ) return 3; if (c == P || c == p ) return 1; return 0; } int main() { int white = ...
#include <bits/stdc++.h> using namespace std; const int N = 200 * 1000 + 10; struct edge { int u, v, w; edge() {} edge(int u, int v, int w) : u(u), v(v), w(w) {} } e[N]; vector<int> vec[N]; int n, m, root[N], mx[35][N], par[35][N], h[N], ans[N]; bool mst[N], mark[N]; multiset<int> add[N], re...
#include <bits/stdc++.h> using namespace std; int main() { double a, b, m, vx, vy, vz; cin >> a >> b >> m >> vx >> vy >> vz; double X = a / 2 - m / vy * vx; double Z = -m / vy * vz; while (X < 0 || X > a) if (X > a) X = 2 * a - X; else X = -X; while (Z < 0 || Z > ...
#include <bits/stdc++.h> using namespace std; char table[500 + 10][500 + 10]; int vis[500 + 10][500 + 10]; int n, m; int dirr[4] = {1, -1, 0, 0}; int dirc[4] = {0, 0, 1, -1}; vector<tuple<int, int, int> > ans; int dfs(int i, int j, int depth) { if (i < 0 || i >= n || j < 0 || j >= m) return 0; i...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int b[8]; for (int i = 1; i <= 7; ++i) cin >> b[i]; int first = b[7] - b[6]; int last = b[7] - b[5]; ...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; int f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } x ...
#include <bits/stdc++.h> using namespace std; int main() { string arr[11] = { ABSINTH , BEER , BRANDY , CHAMPAGNE , GIN , RUM , SAKE , TEQUILA , VODKA , WHISKEY , WINE }; int n; cin >> n; int counter = 0; string str; int num_convert; for (int i = ...
#include <bits/stdc++.h> const int LIM = 1e5 + 5; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> x(n), y(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; if (n % 2) { cout << NO ; return 0; } else { ...
#include <bits/stdc++.h> using namespace std; bool isp(const int x) { if (x <= 1) return false; for (int i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; } int pow(int x, int e, const int MOD) { int r = 1; for (; e; e >>= 1, x = (long long)x * x % MOD) if (e & 1...
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; void no() { cout << NO << endl; } void yes() { cout << YES << endl; } int main() { int q, n, wyn; cin >> q; for (int i = 0; i < q; i++) { cin >> n; char a; string s; cin >> a; cin >> s; if (s.length() == 1 && a >= ...
#include <bits/stdc++.h> using namespace std; const int maxn = 10000; int degree[maxn + 5]; int Cn_i(int n, int i) { int up = 1; int down = 1; for (int t = n; t >= n - i + 1; t--) { up = up * t; } for (int t = i; t >= 1; t--) { down = down * t; } return up / down; } i...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; if (n * m % 2 == 1) cout << n * m / 2 + 1 << endl; else cout << n * m / 2 << endl; } }
#include <bits/stdc++.h> using namespace std; int F[60][60], f[60][60], g[60][60], h[60][60], dp[60][60], fac[60], inv[60], mod = 1000000007; int fpow(int a, int b) { int ans = 1, t = a; while (b) { if (b & 1) ans = 1ll * ans * t % mod; t = 1ll * t * t % mod; b >>= 1; } ret...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; char s[maxn]; int size[maxn], last[200]; bool isover[maxn]; string ans[maxn], now; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> s; int len = strlen(s); bool hasdel = false; now = ...
#include <bits/stdc++.h> using namespace std; vector<int> children[1000005]; int r_1[1000005], r_2[1000005], timer, n, k, p[1000005], mx[1000005 << 2], inc[1000005 << 2]; stack<int> seq; vector<int> ans; void dfs(int node) { timer++; r_1[node] = timer; for (int i = 0; i < children[node].si...
#include <bits/stdc++.h> using namespace std; vector<int> gph[500005]; int n, par[500005], dep[500005], msk[500005]; int dp[500005], sz[500005]; int mx[1 << 22]; int l[23] = {}; void dfs2(int x, vector<pair<int, int> > &v) { v.push_back(pair<int, int>(dep[x], msk[x])); for (auto &i : gph[x]) dfs2(...
#include <vector> #include <array> #include <stack> #include <queue> #include <list> #include <bitset> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <numeric> #include <iostream> #include <iomanip> #include <string> #include <...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int inf = 0x3f3f3f, maxn = 5e5 + 500; long long gcd(long long x, long long y) { if (y == 0) return x; else return gcd(y, x % y); } long long ksm(long long a, long long b) { long long r = 1; while (b) { ...
/** * Author: N.Nafi1211 || <nomaannafi99@gmail.com> #~# **/ #include <bits/stdc++.h> using namespace std; clock_t startTime; double getCurrentTime(){ return (double) (clock() - startTime) / CLOCKS_PER_SEC; } #define PB push_back typedef long long ll; typedef vector<char> vc; ty...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int test; cin >> test; while (test--) { int n; cin >> n; for (int i = 0; i < n; i++) { cout << 8 << ; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int, int> > > adj; vector<int> in; vector<int> out; vector<pair<int, int> > visit; pair<int, int> cal(int son) { if (visit[son].first > 0) return visit[son]; if (visit[son].first == -2) return {-1, -1}; visit[son] = {-2, 0}; pa...
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 5; pair<long long, long long> a[maxn]; long long n; long long cnt[maxn][2]; void solve() { cin >> n; for (long long i = 1; i <= n; i++) cnt[i][0] = cnt[i][1] = 0, cin >> a[i].first >> a[i].second; long long ans = n ...
#include <bits/stdc++.h> using namespace std; using namespace std; const long long int mod = 1e9 + 7; const long long int MAX = LLONG_MAX; const long long int MIN = LLONG_MIN; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int n, k; cin >> n...
#include <bits/stdc++.h> using namespace std; long long n, a[100005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; long i; for (i = 0; i <= n - 1; i++) cin >> a[i]; sort(a, a + n); long long pc = 1, qc = 1, rc = 1; long long b[3]; long long p...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; signed main() { long long int t; cin >> t; vector<long long int> nums = {6, 10, 14, 15}; long lo...
#include<cstdio> const int N=100005; int n,a[100005]; inline int ask2(int x){ if(a[x]) return a[x]; printf( ? %d n ,x); fflush(stdout); scanf( %d ,a+x); return a[x]; } inline int ask(int x){ if(ask2(x)>ask2(x+1)) return 1; else return 0; } int main(){ scanf...
#include <bits/stdc++.h> using namespace std; const int N = 1e3, MOD = (1e9) + 7; int n, m, k, A[N + 9][N + 9], row[N + 9], col[N + 9], x, y; char c; void init() { for (int i = 0; i < N + 5; ++i) row[i] = col[i] = i; } int main() { scanf( %d%d%d , &n, &m, &k); init(); for (int i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; void my_dbg() { cout << endl; } template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << << A; my_dbg(B...); } using ll = long long; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; const int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; long long int a = 0, b = 0, c = 0; for (int i = 0; i < s.length(); i++) { if (i > 0 && s[i - 1] == v && s[i] == v ) { a++; ...
#include <bits/stdc++.h> using namespace std; int n, k, x, nr; bool kgood(int N, int K) { int i, ap[10] = {0}; while (N) { ++ap[N % 10]; N /= 10; } for (i = 0; i <= K; ++i) if (!ap[i]) return false; return true; } int main() { int i; scanf( %d%d , &n, &k); for...
#include <bits/stdc++.h> using namespace std; long long add(long long a, long long b) { a += b; if (a >= 1000000007) { a -= 1000000007; } return a; } long long sub(long long a, long long b) { a -= b; if (a < 0) { a += 1000000007; } return a; } long long mul(long l...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int flag = 0; if (s.length() < 7) { cout << NO n ; return 0; } for (int i = 0; i <= s.length() - 7; i++) { flag = 0; for (int j = i; j < i + 7; j++) { if (s[i] == s[j]) c...
#include <bits/stdc++.h> using namespace std; long long d[61]; int ans; int n, a[200005]; void insert() { for (int i = 1; i <= n; i++) { long long x = a[i]; for (int j = 60; j >= 0; j--) if (x & (1LL << j)) { if (d[j] == 0) { d[j] = x; ans++; ...
#include <bits/stdc++.h> using namespace std; const long long MX = 100; long long A[MX][MX]; long long acum[MX][MX]; long long n, m; long long getAns(long long a, long long b) { long long ans = n * m; for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) { if (i + a - 1...
#include <bits/stdc++.h> using namespace std; using ll = long long; int const nmax = 100; int v[1 + nmax]; map<int, int> dp; int mex(vector<int> v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); for (int i = 0; i < v.size(); i++) if (v[i] != i) return i; retu...
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } long long cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { int n, m; cin >> n >> m; char a[n + 1][m + 1]; for (int i = ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10101; const int BIT = 30; int N; int arr[MAXN], brr[MAXN]; int real_arr[MAXN]; bool isb[MAXN], risb[MAXN]; vector<pair<int, int> > vans; void action(int a, int b) { arr[b] ^= arr[a]; vans.push_back(make_pair(b + 1, a + 1)); } ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, a, b, s1, s2; cin >> n >> m >> a >> b; if (n % m == 0) cout << 0 << endl; else { s1 = (n - ((n / m) * m)) * b; s2 = (((n / m) + 1) * m - n) * a; if (s1 > s2) printf( %I64d , s2); el...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long cnt = 0.5 * n / (k + 1); cout << cnt << << cnt * k << << n - cnt - cnt * k << endl; }
#include <bits/stdc++.h> using namespace std; void solution() { int n, m; cin >> n >> m; int rows[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> rows[i][j]; } } int cols[m][n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) ...
#include<bits/stdc++.h> using namespace std; #define task sol #define lb lower_bound #define ub upper_bound #define fi first #define se second #define pb push_back #define mp make_pair #define zs(v) ((int)(v).size()) #define BIT(x, i) (((x) >> (i)) & 1) #define CNTBIT __builtin_popcountll ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, x = 0; cin >> n >> m >> k; if (n + m - 2 < k) { cout << -1; return 0; } if (m > n) swap(m, n); if (k < m) x = n * (m / (k + 1)); if (k < n) x = max(x, m * (n / (k + 1))); if (k >= n) x = m / (k ...
#include <bits/stdc++.h> using namespace std; using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = s...
#include <iostream> #include <cstdio> #include <algorithm> #include <bits/stdc++.h> #define ALL(x) (x).begin(), (x).end() #define sz(a) int(a.size()) #define rep(i,x,n) for(int i=x;i<n;i++) #define repd(i,x,n) for(int i=x;i<=n;i++) #define pii pair<int,int> #define pll pair<long long ,long long> #de...
#include <bits/stdc++.h> using namespace std; int main() { int T, l, r; cin >> T; for (int i = 1; i <= T; i++) { cin >> l >> r; cout << l << << 2 * l << endl; } }