func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } namespace Sa { struct Node { double x, y; Node() {...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, m; cin >> n >> m; long long sum = 0, cyl = 0; long long k = (n / m); for (int i = 1; i <= 10; ++i) { cyl += (m * i) % 10; } sum = (k / 10) * cyl; ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; scanf( %d%d%d%d , &a, &b, &c, &d); if (a < max(c, d) || b < max(c, d)) { printf( -1 n ); } else if (c == 0 && d == 0) { for (int i = 0; i < a; i++) printf( 4 ); for (int i = 0; i < b; i++) printf( 7 ); ...
#include <bits/stdc++.h> using namespace std; const double EPS = 10e-12; int n, n1, n2; int dig[10] = { (1 << (1)) | (1 << (2)) | (1 << (3)) | (1 << (5)) | (1 << (6)) | (1 << (7)), (1 << (3)) | (1 << (6)), (1 << (1)) | (1 << (3)) | (1 << (4)) | (1 << (5)) | (1 << (7)), (1 << (1)) | (1 <<...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n, m; while (cin >> n >> k) { if (n * (n - 1) / 2 <= k) { puts( no solution ); } else { for (i = 0; i < n; i++) printf( 0 %d n , i); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, q; scanf( %d , &n); bool grid[n + 1][n + 1], ans = false; string s; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf( %d , &grid[i][j]); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; long long k, ans, a[501], i, g, n; long long check(long long x) { k = 0; if (x == 1) return 0; for (long long i = 1; i <= n; i++) if (a[i] / (x - 1) * x < a[i]) return 0; else k += (a[i] + x - 1) / x; if (k < ans) ans = k; ...
#include <bits/stdc++.h> using namespace std; inline int nxt() { int x; scanf( %d , &x); return x; } const int N = 55; int a[N][N]; char skdjflfsdj[N][N]; int score[N]; void add(int u, int v, int x) { a[u][v] += x; score[u] += x; } vector<int> all_out(int v, int n) { vector<c...
#include <bits/stdc++.h> using namespace std; const int mod = 256; int getNum(char tch) { int num = tch; char ch[10]; int cnt = 0; while (cnt < 8) { ch[cnt++] = num % 2 + 0 ; num /= 2; } num = 0; for (int i = 0; i < 8; i++) { num = num * 2 + (ch[i] - 0 ); } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[100001]; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a[i]; } sort(a + 1, a + 1 + m); int ans = 100000000; for (int i = 1; i <= m - n + 1; i++) { ans = min(ans, a[i + n - 1] - a[i]); } cout...
#include <bits/stdc++.h> #pragma warning(disable : 6031) #pragma warning(disable : 4101) using namespace std; const int INF = 1e9; const long long LINF = 1e18; const double PI = acos(-1); const int MAXN = 1000006; int n, m, v1, v2, Deg[MAXN], visited[MAXN]; vector<unordered_set<int>> G; vector<int> ...
#include <bits/stdc++.h> #pragma GCC optmize( Ofast ) using namespace std; const int maxn = 20009; const int inf = 1e8; int n, m, K, T; int e[1 << 10][maxn << 1]; int head[maxn], cntedge = 1; int from[maxn], to[maxn], cap[maxn], flow[maxn], nex[maxn]; void Addedge(int x, int y, int z) { nex[++cnte...
#include <bits/stdc++.h> using namespace std; void desperate_optimization(int precision) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(precision); } const int N = 2e5; int arr[N + 5]; int pre[N + 5]; in...
#include <bits/stdc++.h> using namespace std; template <typename T> string to_str(T str) { stringstream stream; stream << str; return stream.str(); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, d, e; long long result = 1000000000; cin >> n >>...
#include <bits/stdc++.h> using namespace std; bool debug = 1; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; long long ln, lk, lm; int a[100005]; int main() { scanf( %d , &n); for (int(i) = 0; (i) < (int)(n); (i)++) { scanf( %d , a + i); } sort(a, a + n); vector<i...
#include <bits/stdc++.h> using namespace std; uint64_t rnd_data = 0xDEADBEEFDULL; inline void my_srand(int seed) { rnd_data = ((uint64_t)seed << 16) | 0x330E; } inline int my_rand() { rnd_data = rnd_data * 0x5DEECE66DULL + 0xB; return (rnd_data >> 17) & 0x7FFFFFFF; } template <typename T> void my_...
#include<bits/stdc++.h> #define FOR(i,l,r) for(int i=l;i<=r;i++) #define ROF(i,l,r) for(int i=l;i>=r;i--) #define lson k<<1,l,mid #define rson k<<1|1,mid+1,r #define r(x) read(x) #define rr(x,y) read(x);read(y) #define rrr(x,y,z) read(x);read(y);read(z) #define pb(x) push_back(x) #define mp(x,y) make_...
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } long long pwr(long long base, long long p) { long long ans = 1; while (p) { if (p & 1) ...
#include <bits/stdc++.h> using namespace std; const int Inf = (1 << 30) - 1; const long long lInf = (1LL << 62) - 1; const long long Mod = 1000000007; long long fac[1000010]; long long inv[1000010]; long long powm[1000010]; long long pown[1000010]; int a, b; long long n, m; long long fpow(long lon...
#include <bits/stdc++.h> using namespace std; int n; long long A, B; struct node { long long vx, vy, w; } p[400005]; bool cmp(const node p1, const node p2) { if (p1.w == p2.w) return p1.vx < p2.vx; return p1.w < p2.w; } int main() { scanf( %d%I64d%I64d , &n, &A, &B); int i, j; lo...
#include <bits/stdc++.h> using namespace std; void solve() { string S; cin >> S; int M; cin >> M; for (int i = 0; i < M; i++) { int l, r, k; cin >> l >> r >> k; l--; rotate(S.begin() + l, S.begin() + r - k % (r - l), S.begin() + r); } cout << S << n ; } int ...
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int flag = 0; for (int i = 0; i < n - 1; i++) { if ((a[i + 1] - a[i]) > ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long n, m; cin >> n >> m; if (m % 2 == 1) { bool f = true; long ptr = (m + 1) / 2; long p1 = ptr - 1, p2 = ptr; for (long i = 1; i <= n; i++) { if (f && p2 ...
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp; string s; long long n, m, k, ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); cin >> n; vector<long long> a(n + 1, 0); for (long long i = 1; i <= n; ++i) cin >> a[i];...
#include <bits/stdc++.h> using namespace std; int prime[1000005]; int ans[5]; int idx; set<int> s, s1; set<int>::iterator it; int main() { int i, j; for (i = 2; i <= 1000000; i++) { if (prime[i] == 1) continue; for (j = i + i; j <= 1000000; j += i) prime[j] = 1; } int n; sc...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; pair<int, int> a[N]; int main() { int n; cin >> n; int mn = 1e9, mx = -1e9; for (int i = 0; i < n; ++i) { cin >> a[i].first >> a[i].second; mn = min(mn, a[i].first); mx = max(mx, a[i].second); } int a...
#include <bits/stdc++.h> using namespace std; int dp[101][101][28]; vector<pair<int, int> > graph[101]; int fun(int x, int y, int val) { if (dp[x][y][val] != -1) return dp[x][y][val]; for (int i = 0; i < graph[x].size(); i++) { if (graph[x][i].second >= val) { bool mark = true; for...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, m; int volume[N]; int amount[N]; int parent[N]; int tofill[N]; int weight[N]; std::set<int> notFull; void reducePath(int index, int lead) { while (parent[index] != index) { int oldParent = parent[index]; par...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m); vector<int> v(n + 1); for (int i = 1; i <= n; i++) scanf( %d , &v[i]); double ans = 0.0; int a, b, w; for (int i = 1; i <= m; i++) { scanf( %d %d %d , &a, &b, &w); ans = max(ans, 1.0 ...
#include <bits/stdc++.h> const int max_n = 150; const unsigned int lowest = 31; const int size = (max_n >> 5) + 1; struct row { unsigned int bits[size]; void set_bit(unsigned int j) { bits[j >> 5] |= (1 << (j & lowest)); } bool get_bit(unsigned int j) { return ((bits[j >> 5] >> (j & lowest)) &...
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<pair<int, int> > g[1001]; int obtenpadre(int u, int padre[1001]) { if (padre[u] == 0) return u; padre[u] = obtenpadre(padre[u], padre); return padre[u]; } void unir(int u, int v, int padre[1001], int llaves[1001][1001]) { padr...
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f; const long long int INF = 0x3f3f3f3f3f3f3f3f; using namespace std; inline void INP() {} long long int n, m; vector<pair<long long int, long long int> > v; void solve() { cin >> n >> m; long long int mn = INF; long long int mx = 0; for (l...
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long int ara[N]; int main() { long long int n, i, j, k, s = 0, ts; cin >> n; for (i = 1; i <= n; i++) cin >> ara[i]; for (i = 1; i < n; i++) { for (j = 30; ara[i] > 0 && j >= 0; j--) { if ((i + (1 << j)) > n) ...
#include <bits/stdc++.h> using namespace std; int cha[1000100]; int num[1000100]; int a[5010]; int limit[] = {0, 1, 3, 6, 10}; int n, k; int che[1000100]; bool check(int mod) { int bad = 0; int mostI = -1; for (int i = 0; i < n; i++) { int t = a[i] % mod; che[t]++; if (che[...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:16777216 ) const char DEBUG = 0; mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count()); struct pp { int pos, id; }; long long pos[200000]; int type[200000]; int res[100000]; vector<int> arr; in...
#include <bits/stdc++.h> using namespace std; int base1 = 115019, mod1 = 1e9 + 13; vector<int> pos[100005]; int n, t[100005], a[100005]; long long p1[100005], sum1[100005]; struct node { int st, len; bool operator<(const node &A) const { if (len == A.len) return st < A.st; return len < A...
#include <bits/stdc++.h> using namespace std; int main() { int n, p; string s, number; cin >> n; string name[n]; int taxi[n], pizza[n], cg[n], tax, pizz, cgc, taxmax = -1, pizzmax = -1, cgcmax = -1; int taxifinal[n], pizzafinal[n], cgcfinal[n...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; string s[10]; for (int i = 0; i < 8; i++) { cin >> s[i]; } bool ans = 1; for (int i = 0; i < 8 && ans; i++) { for (int k = 1; k < 8; k++) { ...
/* Clearink */ #include <queue> #include <cstdio> #include <algorithm> #define rep( i, l, r ) for ( int i = l, repEnd##i = r; i <= repEnd##i; ++i ) #define per( i, r, l ) for ( int i = r, repEnd##i = l; i >= repEnd##i; --i ) inline int rint() { int x = 0, f = 1, s = getchar(); for ( ; s < 0 ...
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } map<long long int, long long int> m; m[0] = 0; long...
#include <bits/stdc++.h> using namespace std; int loc[200000 + 10]; int n; int ans[4]; int fnext(int y) { int l = 1, r = n + 1, mid = (l + r) / 2; while (l < r) { if (loc[mid] <= y) l = mid + 1; else r = mid; mid = (l + r) / 2; } return mid; } int ok(int x...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, x1, y1; cin >> x >> y >> x1 >> y1; int X = abs(x1 - x), Y = abs(y1 - y); cout << max(X, Y); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; using ii = long long; int main() { int n, k; scanf( %d%d , &n, &k); vector<int> v(n); vector<ii> s(n); for (int &x : v) { scanf( %d , &x); } for (int i = n - 2; i + 1; --i) { s[i] = v[i + 1] + s[i + ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 55, MAXM = 20020; int n, m, k, acc[MAXN][MAXM], dp[MAXN][MAXM], ans; struct no { int beg, end, mid, mx, lz; no *l, *r; no(int beg, int end) : beg(beg), end(end), mid((beg + end) >> 1), mx(0), lz(0) { if (beg != end) l = new...
#include <bits/stdc++.h> using namespace std; int n; int d[262144][4]; map<int, int> comp; int r[262144], R, pr[262144]; vector<int> vec; bool cmp(int a, int b) { return d[a][1] > d[b][1]; } struct BIT { int m[262144 * 2]; vector<int> v[262144]; void init() { int i; for (i = 0; i...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; bool mark[MAX_N]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 0; i < n - 1; i++) { int a; cin >> a; mark[a - 1] = true; } for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; char a[100]; int main() { int i, l, c = 0; scanf( %s , a); l = strlen(a); for (i = 1; i < l; i++) { if (a[i] <= Z ) { c++; } } int t = 0; if (a[1] <= Z && c >= l - 1) t++; if (t != 0) { for (i = 0; i < l; i+...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 105; const int mod = 998244353; const double Pi = acos(-1.0); const long long INF = 1e18; const int G = 3, Gi = 332748118; long long qpow(long long a, long long b) { long long res = 1; while (b) { if (b) res = (res * a) % mod;...
#include <bits/stdc++.h> const int MAXN = 100010, inf = 2147483233; using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 0 ; ch = getchar(...
#include <bits/stdc++.h> using namespace std; struct node { int from, to, next, w, dir, id; } e[1500000]; int head[350000]; int in[350000]; int out[350000]; int ans[350000]; int n, m, cont; void add(int from, int to, int w, int dir, int id) { e[cont].from = from; e[cont].to = to; e[con...
#include <bits/stdc++.h> using namespace std; void solution() { int n, k; cin >> n >> k; vector<long long> v(n * k + 1, 0), brr(n * k + 1, 0); long long sum = 0; for (int i = 1; i <= n * k; i++) { cin >> v[i]; brr[i] = v[i]; } brr[0] = INT_MAX; sort(brr.rbegin(), brr.rend...
#include <bits/stdc++.h> using namespace std; const long long MXN = 80 + 10; const long long MX5 = 4e5 + 10; const long long MX6 = 1e6 + 10; const long long LOG = 20; const long long INF = 8e18; const double eps = 1e-9; const long long MOD = 1e9 + 7; long long power(long long a, long long b, long long...
#include <bits/stdc++.h> using namespace std; int points(int p, int t) { int first = 75 * p; int second = 250 * p - p * t; return max(first, second); } int main() { int a, b, c, d; scanf( %d %d %d %d , &a, &b, &c, &d); int misha = points(a, c); int vasia = points(b, d); if (misha...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 50; int k, w, h; int read() { int x = 0, y = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) y = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) x = (x << ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 6000 + 10; int n, t, arr[MAXN][MAXN]; void dfs(int i, int j, int val) { arr[i][j] += val; if (arr[i][j] < 4) return; int me = arr[i][j] / 4; arr[i][j] %= 4; dfs(i + 1, j, me); dfs(i - 1, j, me); dfs(i, j + 1, me); dfs...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; struct edge { int x, y, w, p; edge() {} void input() { scanf( %d%d%d%d , &x, &y, &w, &p); } } E[N], EE[N]; int n; vector<int> G[N]; long long W[N], WW[N]; void dfs(int x, int y, int id, int mi) { if (id) { int tmp...
#include <bits/stdc++.h> using namespace std; long long unsigned int n; long long unsigned int val(long long unsigned int x, long long unsigned int k) { if (x >= 1e10) return n + 1; long long unsigned int ans = x * (x - 1); ans /= 2; long long unsigned int kt = k; if (ans > n) return n + 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, t; int n; int a[100005]; int b[100005]; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a + n); int cnt = 0; for (i = 0; i < n; i++) { if (a[i] != b[i]) cnt++; }...
#include <bits/stdc++.h> using namespace std; int st[200005]; int main() { int tam1, tam2, i; string s, t; cin >> s >> t; long long r = 0; tam1 = s.size(); tam2 = t.size(); st[0] = 0; for (i = 0; i < tam2; i++) { st[i + 1] = st[i] + (t[i] - 0 ); } for (i = 0; i < tam...
#include <bits/stdc++.h> using namespace std; int n, a[10]; char c[100007]; int main() { scanf( %d , &n); scanf( %s , &c); for (int i = 0; i < n; i++) { if (c[i] == L ) { for (int j = 0; j < 10; j++) { if (a[j] == 0) { a[j] = 1; break; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; for (int t = 0; t < T; ++t) { long long int n; long long int a, b; cin >> n >> a >> b; string s; cin >> s; long long int bc = n * (a + b) + b; ...
#include <bits/stdc++.h> using namespace std; inline bool isPowerOfTwo(int x) { return (x != 0 && (x & (x - 1)) == 0); } double pi = 3.141592653589793238462643; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; inline int add(int a, int b, int m = 1000000007) { a += b; ...
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { return (a.second < b.second); } int main() { vector<pair<long long int, long long int>> v; long long int n, m, k; cin >> n >> ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long c; while (a != 0) { c = a; a = b % a; b = c; } return b; } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } long long triple(long long x) { long long a...
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return a > b; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i ...
#include <bits/stdc++.h> using namespace std; const int ALF_SIZE = 26; int val[200], sizeB = 1; struct bor { char q; int a[ALF_SIZE]; int val, par; int go[ALF_SIZE]; int link; bool updated; void init(int q) { this->q = q; val = par = 0; link = -1; updated = 0;...
#include <bits/stdc++.h> using namespace std; double s = 10000000, a, b, m; int n; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a >> b; s = min(s, a / b); } printf( %.8f , s * m); return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long a, b; cin >> a >> b; if (a > b) swap(a, b); long long ans = 0; while (a * 8 <= b) { ...
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s...
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 7; char s[maxn]; int sa[maxn], str[maxn], _rank[maxn], height[maxn]; int t1[maxn], t2[maxn], c[maxn]; int RMQ[maxn], mm[maxn], best[20][maxn], len; bool cmp(int *r, int a, int b, int l) { return r[a] == r[b] && r[a + l] == r[b + l]; ...
#include <bits/stdc++.h> using namespace std; int n, q, s, e, cc, sz, t, l, r; long long tt[150000]; void inc(int i, long long w) { for (; i <= n; i |= i + 1) tt[i] += w; } long long sum(int i) { long long sum = 0; for (; i >= 0; i = (i & (i + 1)) - 1) sum += tt[i]; return sum; } long lo...
#include <bits/stdc++.h> using namespace std; int n, a, curr; vector<long long int> v; void start() { cin >> n; int times = 0; bool flag = false; for (int i = 0; i < n; i++) { cin >> a; if (i == 0) { curr = a; times++; if (i == n - 1) v.push_back(times); ...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T x, T y) { if (x < y) swap(x, y); while (y > 0) { T f = x % y; x = y; y = f; } return x; } template <typename T> pair<T, T> exgcd(T x, T y) { int sw = 0; if (x < y) sw = true, swap(x, y); ...
#include <bits/stdc++.h> using namespace std; int n, T; const int mn = 5009; double p[mn]; double p2[102][mn]; int pi[mn]; int t[mn]; double dp[2][mn]; int main() { scanf( %d , &(n)); scanf( %d , &(T)); int pk; for (int i = 0; i < n; i++) { scanf( %d %d , &pi[i], &t[i]); p[...
#include <bits/stdc++.h> using namespace std; int main() { int minx, maxx, miny, maxy, sumofarea = 0; int n; cin >> n; for (int i = 0; i < n; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (i == 0) { minx = x1; maxx = x2; miny = y1; maxy ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; template <typename T, typename TT> inline ostream &operator<<(ostream &os, const pair<T, TT> &t) { return os << t.first << << t.second; } template <typename T> inline ostream &operator<<(ostream &os, const vector<T> &t) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a; int b; cin >> a; cin >> b; if (a != b) { cout << Happy Alex ; return 0; } } cout << Poor Alex ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int T, n, i, j, k; cin >> T; while (T--) { cin >> n; string str[51]; for (i = 0; i < n; i++) { cin >> str[i]; } if (n == 1) { cout << YES << endl; continue; } for (i = n - 1; i ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const long long int mod = 1e9 + 7; const long long int mod1 = 998244353; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long int rand(long long int l, long long int r) { uniform_int_distribution<long l...
#include <bits/stdc++.h> using namespace std; struct node { int a; int b; int idx; int k; int actor; node() {} node(int a, int b, int idx, int k, int actor) : a(a), b(b), idx(idx), k(k), actor(actor) {} }; const int MAXN = (int)1e5 + 5; set<node> s; vector<node> v; int ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; const int INF = 0x3f3f3f3f; int n, s; int a[maxn << 1], vis[maxn], nxt[maxn << 1][maxn], prv[maxn << 1][maxn], lst[maxn]; int f[maxn][maxn], h[maxn][maxn]; vector<int> g[maxn][maxn]; vector<int> vec; vector<int> pos[maxn]; in...
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int a[N], sum[N], f[N], ans[N]; int n, r, c; char ch[N * 6]; int main() { scanf( %d%d%d , &n, &r, &c); for (int i = 1; i <= n; i++) { scanf( %s , ch + sum[i - 1] + 2); a[i] = strlen(ch + sum[i - 1] + 2); sum[i] = ...
#include <bits/stdc++.h> inline void in(int &MAGNUS) { scanf( %d , &MAGNUS); } inline void out(int MAGNUS) { printf( %d n , MAGNUS); } inline void in(int &MAGNUS, int &CLAR) { scanf( %d%d , &MAGNUS, &CLAR); } inline void out(int MAGNUS, int CLAR) { printf( %d %d n , MAGNUS, CLAR); } inline void inl(long long ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; long long int mn, mx, noob; cin >> t; while (t--) { long long int flag = 0; cin >> mn >> mx >> noob; if (mn > mx) swap(mx, mn); if (noob >= mn) { cout << mn << endl; flag = 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 15; const int maxt = 235; const int MOD = 1e9 + 7; inline void upd(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } int n, T; int dp[maxt][1 << maxn][3], t[maxn], g[maxn]; int main() { scanf( %d%d , &n, &T); for (int(i) =...
#include <bits/stdc++.h> using namespace std; long long DP[100005][25]; long long arr[100005]; long long l = 1, r, ans; long long freq[100005]; void alter_range(long long l1, long long r1) { while (l1 < l) { ans += freq[arr[l - 1]]; freq[arr[l - 1]]++; l--; } while (r < r1) { ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5; long long aa[N + 2], bb[N + 2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long k1, k2, k3; cin >> k1 >> k2 >> k3; long long t1, t2, t3; cin >> t1 >> t2 >> t3; long long n; cin >> n; for (...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() { int n; scanf( %d , &n); int q = n / 3; int r = n % 3; if (r > 0) { printf( %d , 2 * q + 1); } else { printf( %d , 2 * q); } return 0; }
#include <bits/stdc++.h> using namespace std; int n; int a[31] = {4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645}; int main() { scanf( %d , &n); printf( %d , a[n - 1]); ...
#include <bits/stdc++.h> using namespace std; long long T, n; long long getFirst(long long n) { long long cur = 4; while (n > cur) { n -= cur; cur *= 4; } return cur + n - 1; } long long getSecond(long long n) { long long cur = 4; while (n > cur) { n -= cur; cur...
#include <bits/stdc++.h> using namespace std; long long k, a[1200000]; int n; int main() { cin >> a[0] >> k; n = 0; while ((a[n] >= k) || (a[n] < 0)) { if (a[n] >= k) { long long x = a[n] / k; a[n] -= k * x; a[++n] = -x; } else { long long x = (-a[n] + k -...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0, ans1 = 0, ans2 = 0, tar; cin >> n; tar = n / 3; string s; cin >> s; for (int i = 0; i < n; i++) { int val = s[i] - 0 ; if (val == 0) ans++; else if (val == 1) ans1++; else ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; inline int sign(double x) { if (x < -eps) return -1; return x > eps; } struct Tpoint { double x, y; Tpoint() {} Tpoint(double x, double y) : x(x), y(y) {} inline double norm() { retur...
#include <bits/stdc++.h> using namespace std; int fs[43][2], d[20], dp[20][10], r[20][10], from[20][10]; vector<int> pos; int main() { memset((fs), -1, sizeof((fs))); for (int i = 0; i <= 6; i++) for (int j = 0; i + j <= 6; j++) { fs[i * 7 + j * 4][0] = i; fs[i * 7 + j * 4][1] = j;...
#include <bits/stdc++.h> int main(void) { int i, j, n, k, c = 0; int a[100]; scanf( %d%d , &n, &k); for (i = 0; i < n; i++) scanf( %d , &a[i]); for (i = 0; i < n; i++) { if (a[i] <= k) { c++; } else break; } for (i = n - 1; i >= 0; i--) { if (a[i] <= k) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long b; while (cin >> b) { long long ans = 0; long long i; for (i = 1; i * i < b; i++) { if (b % i == 0) ans += 2; } if (i * i == b) ans++; cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, ans = 0, sum = 0, sum2 = 0; cin >> n; int a[n + 1]; a[0] = 0; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a, a + (n + 1)); for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; int a[100000]; int n, k; int main() { scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %d , &a[i]); int l = 0, r = n; while (r - l > 1) { int m = (l + r) / 2; if ((long long)k > (long long)m * (m + 1) / 2) l = m; el...
#include <bits/stdc++.h> using namespace std; int n, m, k, i, j, v, bor[100005][27], a[100005], b[100005]; string s; void dfs(int v) { int q = 0; int u = 0; int t = 0; for (int i = 1; i < 27; i++) { if (bor[v][i] > 0) { q = 1; dfs(bor[v][i]); if (a[bor[v][i]] == 0) ...
#include <bits/stdc++.h> using namespace std; int ls[2005], rs[2005], fa[2005], sz[2005], z[2005]; int id, n, m, rt, mn, Sz; char s[10]; void getrt(int x, int F) { sz[x] = 1; int mx = 0; if (ls[x] && ls[x] != F && !z[ls[x]]) { getrt(ls[x], x); sz[x] += sz[ls[x]]; if (sz[ls[x]] > ...