func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int connected; int par[N], sz[N]; struct DSU { void init(int n) { for (int i = 1; i <= n; i++) { par[i] = i; sz[i] = 1; } connected = n; } int getPar(int k) { while (k != par[k]) { ...
#include <bits/stdc++.h> using namespace std; inline int Get() { int res = 0, q = 1; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) q = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) res = res * 10 + ch - 0 , ch = getchar(); return res * ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; const int INFINITE = 0x3f3f3f3f; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, res; int a[400], c; while (cin >> n >> k) { cin >> c; for (int i = 0; i < c; i++) cin >> a[i]; sort(a, a + c); res = 0; for (int t = 0, ci = 0; t < n; res++) { if (ci < c && a[ci] <= t + k && a[ci]...
#include <bits/stdc++.h> using namespace std; const int D = 1000005; const int N = 100005; const int mo = 1000000007; int tg[D * 3], sum[D * 3]; void pushdown(int k) { if (!tg[k]) return; sum[k * 2] = sum[k * 2 + 1] = 0; tg[k * 2] = tg[k * 2 + 1] = 1; tg[k] = 0; } void pushup(int k) { su...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int l = s.length(); int open = 0; int closed = 0; int hash = 0; for (__typeof((l)) i = 0; i < (l); i++) { if (s[i] == ( ) open++; if (s[i] == ) ) closed++; if (s[i] == # ) hash++; if...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int suma = 0; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; suma += a[i]; } int half = 0; for (int i = 0; i < n; i++) { half += a[i]; if (half >= suma / 2 + suma % 2) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, num, prev = 0, total = 0; cin >> n; for (i = 0; i < n; i++) { cin >> num; if (num - prev < 0) total += abs(num - prev); prev = num; } cout << total; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { int n, i; cin >> n; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int ans = min(a[n - 1] - a[1], a[n - 2] - a...
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= k; i++) { scanf( %d%d , &x, &y); if (x <= 5 || (n - x + 1) <= 5 || y <= 5 || (m - y + 1) <= 5) return printf( YES n ), 0; } printf( NO n ); }
#include <bits/stdc++.h> using namespace std; int inline read() { int num = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) neg = -1; c = getchar(); } while (isdigit(c)) { num = (num << 3) + (num << 1) + c - 0 ; c = getchar(); } return num * n...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const int maxn = 21; char s[maxn][maxn]; int dp[1 << maxn], a[maxn][maxn], cost[maxn][maxn], same[maxn][maxn]; int main() { int n, m; ios::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) for (int ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const int N = 1e3 + 5; long long fac[N], ifac[N]; long long be(long long b, long long e, long long m) { long long r = 1; while (e) if (e & 1) r = (r * b) % m, e ^= 1; else b = (b * b) % m, e >>= ...
#include <bits/stdc++.h> using namespace std; int main() { int arr[5][5]; int r, c, cnt = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cin >> arr[i][j]; if (arr[i][j] == 1) { r = i; c = j; } } } if (r != 2) { int tmp...
#include <bits/stdc++.h> using namespace std; const int DIM = 2 * 100001; struct nr { int val, ind; } mins[DIM]; int n, m, d; int used[DIM], afis[DIM]; bool cmp(nr x, nr y) { return x.val < y.val; } int main() { cin >> n >> m >> d; for (int i = 1; i <= n; ++i) { cin >> mins[i].val; ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ...
#include <bits/stdc++.h> using namespace std; void dfs(long long x, bool b[], vector<long long> adj[], long long depth[]) { b[x] = true; vector<long long>::iterator it; for (it = adj[x].begin(); it != adj[x].end(); it++) { if (!b[*it]) { depth[(*it)] = depth[x] + 1; dfs((*it), b, a...
#include <bits/stdc++.h> using namespace std; const int maxx = 27; vector<int> v; int main() { long long n, l, sum = 0; cin >> n; for (int(i) = (0); (i) < (n); (i)++) { cin >> l; v.push_back(l); } sort(v.begin(), v.end()); n = n - 1; while (v.size() > 1) { int n = v...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int k; cin >> k; int a[n][m]; for (int i = (0); i < (n); i++) { for (int j = (0); j < (m); j++) { cin >> a[i][j]; } } int ans = 0; int sum = 0, msum = 0, nans = 0, ones = 0, ts...
#include <bits/stdc++.h> using namespace std; int main() { long long a, c, b, d, e, f = 0, g, k, l, i, j, u, m, p, n, t; string s; cin >> n >> k; cin >> s; l = s.size(); map<int, int> mp; for (i = 0; i < l; i++) { mp[s[i]]++; } for (i = a ; i <= z && k; i++) { if (...
#include <bits/stdc++.h> using namespace std; int cntl(long long k) { int res = 0; while (k != 0) { int a = k % 10; if (a == 4 || a == 7) res++; k /= 10; } return res; } int main() { long long a, l; cin >> a >> l; if (a == 369999995 && l == 5) { cout << 380000...
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf( %d , &x); return x; } template <typename T> inline istream& operator>>(istream& i, vector<T>& v) { for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j]; return i; } template <typename T> string join(const ...
#include <bits/stdc++.h> using namespace std; const int MAX = 200200; int head[MAX], nxt[MAX * 2], to[MAX * 2], dpthMx[MAX], dpthMn[MAX], Ecnt, n; int ch[MAX], sz; void dfs(int cur, int par) { for (int i = head[cur]; ~i; i = nxt[i]) if (to[i] != par) { dfs(to[i], cur); dpthMn[cur] = ...
#include <bits/stdc++.h> using namespace std; const int OO = INT_MAX; const int N = 2e5 + 2; const int MOD = 1e9 + 7; double ebs = 1e-6; const int INF = 0x3f3f3f3f; int in[N]; map<int, int> mp; int main() { ios::sync_with_stdio(0); int t; cin >> t; while (t--) { mp.clear(); ...
#include <bits/stdc++.h> using namespace std; int a[100010]; int main() { int T; cin >> T; while (T--) { int n, sum = 0; int z = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; sum = sum + a[i]; if (a[i] == 0) { z++; } } ...
#include <bits/stdc++.h> using namespace std; const int M = 1000005; int read() { int x = 0, f = 1; char c; while ((c = getchar()) < 0 || c > 9 ) { if (c == - ) f = -1; } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return x ...
#include <bits/stdc++.h> using namespace std; struct trip { int a, b, c; }; const int MAXINT = 2 * 1e5 + 1; int n, c, stairs[MAXINT], elevator[MAXINT], dp[MAXINT][2]; void solve(int pos) { if (pos < n) { dp[pos][0] = min(dp[pos - 1][1], dp[pos - 1][0]) + stairs[pos - 1]; dp[pos][1] = min...
#include <bits/stdc++.h> using namespace std; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const double err = 1e-12; const double PI = 3.141592653589793; const int N = 1e5 + 5; vector<string> V(6); vector<bool> used(6, false); vector<string> res(6); vector<string> bres; bool f = false; void bt(int lvl) { if...
#include <bits/stdc++.h> using namespace std; const int N = 110000; int x[N], y[N]; vector<int> vec[2]; int main() { int n; scanf( %d , &n); auto prv = [&n](int x) { return (x - 1 + n) % n; }; auto nxt = [&n](int x) { return (x + 1) % n; }; for (int i = 0; i < n; i++) scanf( %d%d , &x[i], ...
#include <bits/stdc++.h> using namespace std; int n, m, mn = 2e9, cnt, num, s[2505][2505]; bool v[2505]; char a[2505][2505]; int main() { int i, j, r, c, tr, tc, sz; cin >> n >> m; for (i = 1; i <= n; i++) { scanf( %s , &a[i][1]); } for (i = 1; i <= n; i++) { for (j = 1; j <= m...
#include <bits/stdc++.h> using namespace std; vector<long long> inp; long long lim; long long dp[25][2][2][5]; long long DP(long long pos, long long isSmall, long long isStart, long long val) { if (val > 3) return 0; if (pos == lim) { return 1; } if (dp[pos][isSmall][isSta...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long solve(long long l, long long r, long long x) { long long res = 0; for (int i = 1; i <= 62; i++) { long long p = (1LL << i) - 1; long long val = (x ^ p); if (l <= p && p <= r) { res = max(res, v...
#include <bits/stdc++.h> using namespace std; long long n, k; inline bool check(vector<long long>& prev, long long x) { long long sz = prev.size(); for (long long i = 0; i < sz; i += x) { long long j = min(i + x - 1, sz - 1); if (prev[j] - i > k) return false; } return true; } int ...
#include <bits/stdc++.h> using namespace std; char Start; int n, m; char S[400005], T[400005]; int fa[400005], tr[400005][26], len[400005], rt[400005], pos[400005], tot, last; vector<int> G[400005]; void ins(int c, bool debug = 0) { if (tr[last][c]) { int p = last, q = tr[last][c]; if (len...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000000 + 7; int main() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); long long n; cin >> n; if (n < 3) { cout << -1; return 0; } for (int i = n; i >= 1; i--) { co...
#include <bits/stdc++.h> using namespace std; bool prime(int n) { if (n % 2 == 0) return false; for (int i = 3; i * i <= n; i += 2) if (n % i == 0) return false; return true; } int r(int n) { int div = 1; int ans = 0; while (div <= n) { ans *= 10; ans += ((n / div) % 10...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long add(long long x, long long y, long long CMOD = MOD) { return (x + y + CMOD + CMOD) % CMOD; } long long mult(long long x, long long y, long long CMOD = MOD) { return add(x, 0) * add(y, 0) % CMOD; } long long fa...
#include <bits/stdc++.h> using namespace std; int sign(long long x) { return x < 0 ? -1 : x > 0 ? 1 : 0; } struct point { long long x, y; point(long long a = 0, long long b = 0) : x(a), y(b) {} point operator-(point q) { return point(x - q.x, y - q.y); } long long operator%(point q) { return x * q...
#include <bits/stdc++.h> using namespace std; const long long oo = 1e18; const long long MOD = 998244353; const long long MAXN = 2e5 + 100; long long qpow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b /= 2; } ret...
#include <bits/stdc++.h> using namespace std; int str[26][1505]; int ans[26][1505]; int main(int argc, char *argv[]) { int n; scanf( %d , &n); getchar(); char c; for (int i = 0; i < n; i++) { c = getchar(); str[c - a ][i]++; } for (int i = 0; i < 26; i++) { for (in...
#include <bits/stdc++.h> using namespace std; int main() { double s = 0, n; cin >> n; while (n > 0) { s += (1 / n); n--; } cout << s << endl; }
#include <bits/stdc++.h> #define ll long long #define db double #define str string #define pii pair<int, int> #define pll pair<ll, ll> #define pdd pair<db, db> #define fi first #define se second #define vc vector<char> #define vvc vector<vc> #define vi vector<int> #define vvi vector<vi> ...
#include <bits/stdc++.h> using namespace std; long long l[200010]; int n; long long teste(long long x) { if (x <= 1) return n; long long res = 0; for (int i = 0; i < n; i++) { if (l[i] < x) res += x - (l[i] % x); else res += min(l[i] % x, x - (l[i] % x)); } return...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, t; cin >> s >> t; vector<int> f1(26); vector<int> f2(26); for (int i = 0; i < n; i++) { f1[s[i] - 97]++; f2[t[i] - 97]++; } int f = 0; for (int i = 0; i < 26; i++) { if (f1...
#include <bits/stdc++.h> using namespace std; const char letters[] = { A , G , C , T }; const int NMAX = 3e5 + 5; int N, M; int A, G, C, T; int best; vector<vector<int> > a, b; vector<int> prm, bestprm; int fqlin[NMAX][2][4], fqcol[NMAX][2][4]; char gletter() { char ch = getchar(); while ...
#include <bits/stdc++.h> using namespace std; struct Lem { int m, v, id; bool operator<(Lem b) const { return m < b.m || (m == b.m && v < b.v); } }; int n, k, h; Lem a[(100000 + 10)]; bool can(double t) { int j = k; for (int i(n - 1), _l(0); i >= _l; --i) { if (j > 0 && (double)j * h /...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.size() >= 1 && s.size() <= 100) { int i, j, k = 0, m = 0; for (i = 0; i < s.size(); i++) { if (s[i] >= a && s[i] <= z ) k++; if (s[i] >= A && s[i] <= Z ) m++; } if (k >= m) ...
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; string direc = URDL ; const long long MOD2 = (long long)1000000007 * (long lon...
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1000 * 1000 * 1000 + 9; const int maxn = 1000 * 100 + 1; int n, m, r[maxn], parent[maxn]; long long javab = 1; int par(int x) { if (x == parent[x]) return x; return parent[x] = par(parent[x]); } bool merge(int x, int ...
#include <bits/stdc++.h> using namespace std; int main() { int k25 = 0, k50 = 0, n; cin >> n; bool f = 1; for (int i = 0; i < n; i++) { int q; cin >> q; if (q == 25) k25++; else if (q == 50) { if (k25) { k25--; k50++; } else ...
#include <bits/stdc++.h> using namespace std; int main() { int x, a, b = 0; cin >> x; for (int i = 1; i <= x; i++) { int k = 1; while (i * k <= x) { if (i * i * k > x && k < x) { a = i * k; b = i; break; } else k = k + 1; } } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; int a[maxn]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); a[x] = i; } int x = 0; for (int i = 0; i < n; i++) { int m; scanf( %d , &m); ...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n + 2]; map<long long, long long> m; for (long long i = 1; i <= 1000; i++) { m[i] = 0; } for (long long i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; int n, x, frq, ans[25][25]; map<int, int> mp; priority_queue<pair<int, int> > pq; priority_queue<pair<int, set<pair<int, int> > > > mat; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n * n; ++i) ...
#include <bits/stdc++.h> using namespace std; const int MAXI = numeric_limits<int>::max() / 2; const int MINI = numeric_limits<int>::min() / 2; const long long MAXL = numeric_limits<long long>::max() / 2; const long long MINL = numeric_limits<long long>::min() / 2; int cnt[2][2]; long long pro(long long s...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; long long powmod(long long b, long long e, long long m) { if (!e) return 1; long long r = powmod(b, e / 2, m); return ((r * r) % m * ((e & 1) ? b : 1)) % m; } string s; long long k; int main() { cin >> s >> k...
#include <bits/stdc++.h> using namespace std; using ll = long long; int mode, t; const int INF = 1e9 + 7; void solve() { int n, k; cin >> n >> k; string s; cin >> s; int rot = 0; if (s[0] == s[n - 1]) { int start = -1; for (int i = 0; i < n - 1; i++) { if (s[i] != s...
#include <bits/stdc++.h> using namespace std; int n, l, v1, v2, k; int main() { cin >> n >> l >> v1 >> v2 >> k; long double T = 0; long double S = l, t1, t2, d; int m = ((n + k - 1) / k); S = S / ((long double)(m) - ((long double)(m - 1) * (v2 - v1)) / (v2 + v1)); t1 = S / v2; t2 = (S ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; int main() { int n; cin >> n; int sum = 0; int zero = 0; for (int i = 0; i < 2 * n; i++) { int x; scanf( %*d.%d , &x); sum += x; if (x == 0) zero++; } int ans = INF; for (int k = 0; k ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long pwr(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % MOD; b >>= 1, a = a * a % MOD; } return ans; } long long inv(long long a) { return pwr(a, MOD - 2); } ...
#include <bits/stdc++.h> using namespace std; int const INF = 100000; int p[INF + 1]; int M[INF + 1]; int main() { memset(p, -1, sizeof(p)); memset(M, -1, sizeof(M)); set<pair<int, int> > S; int n, x, k; cin >> n; while (n--) { cin >> x >> k; if (p[k] < x) { p[k] = ...
#include <bits/stdc++.h> #define LOG(FMT...) fprintf(stderr, FMT); #define rep(i, j, k) for(int i = j; i <= k; ++ i) #define per(i, j, k) for(int i = j; i >= k; -- i) using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair typedef pair<int, int> pii; typede...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } set<pair<long long, int>> all; for (int i = 0; i < n; i++) { all.insert({a[i], i}); } vector<pair<long long, int>> res; ...
#include <bits/stdc++.h> int main() { int n, m, min, max; scanf( %d %d %d %d , &n, &m, &min, &max); int arr[m]; for (int i = 0; i < m; i++) { scanf( %d , &arr[i]); } int chmin = 0, chmax = 0, wrong = 0; for (int i = 0; i < m; i++) { if (arr[i] == min) chmin = 1; if (arr[i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; map<string, string> map1; for (int i = 0; i < n; ++i) { string t1, t2; cin >> t1 >> t2; map1[t2] = t1; } for (int j = 0; j < m; ++j) { string t1, t2, t3; cin >> t1 >> t2; f...
#include <bits/stdc++.h> using namespace std; long long a[100000], i, n, m, k; set<int> s; int main() { cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); s.insert(a[0]); for (i = 1; i < n; i++) { m = s.size(); if (a[i] % k != 0) { s.insert(...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; long long a[3][N]; int p[3][N]; int n; map<long long, int> mp; map<pair<int, int>, int> f; int solve(int x, int y) { if (p[0][x] == -1 && p[1][y] == -1 && p[2][min(x, y)] == -1) return 0; pair<int, int> cnt(x, y); if (f.co...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int maxm = 100005; int x[maxm], xr[maxm]; int main() { int n, i, j, k, sum, m, cnt = 0, ans, t; int x1, x2, y; scanf( %d%d , &n, &m); for (i = 0; i < n; i++) scanf( %d , &x[i]); ans = t = 0; sort(x, x + n); fo...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 1e3 + 10; int len[N]; int h[N]; int cost[N]; int main() { memset((cost), (0x3f), sizeof(cost)); int n; cin >> n; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b >> h[i]; len[...
#include <bits/stdc++.h> #define pb push_back using namespace std; const int N = 3e5 + 5; vector<int> G[N], G0[N]; long long day; int cur, n, pv, pt, a[N], fa[N], dep[N]; int prv[N], pst[N], np[N], bp[N], ep[N]; void Build(int u) { for(int v : G0[u]) { if(v == fa[u]) continue; fa[v] = u; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, w; cin >> n >> w; vector<int> a(n), b(n); for (int& v : a) cin >> v; for (int& v : b) cin >> v; double l = 0, r = 2e9; for (int t = 0; t < 500; t++) { double m = (l + r) / 2; do...
#include <bits/stdc++.h> using namespace std; int a, b, c; double dp[102][102][102]; int main() { scanf( %d%d%d , &a, &b, &c); int n = max(max(a, b), c); dp[1][0][0] = 1; dp[1][1][0] = 1; for (int i = 1; i <= n; i++) dp[i][0][0] = 1; for (int i = 1; i <= n; i++) for (int j = 0; j <...
#include <bits/stdc++.h> using namespace std; char tmp[100001]; string v[100001][2]; long long dp[100001][2]; long long c[100001]; int n; long long f(int i, int j) { if (i == n - 1) return 0; if (dp[i][j] == -1) { dp[i][j] = 1000000000000000LL; if (v[i][j] <= v[i + 1][0]) dp[i][j] = mi...
#include <bits/stdc++.h> using namespace std; int N; set<pair<int, int>> E[202020]; signed long long ntot[202020]; int vis[202020]; vector<pair<int, signed long long>> V; map<pair<int, int>, int> M; vector<signed long long> chi[202020]; void dfs(int cur, signed long long tot) { if (vis[cur]) retur...
#include <bits/stdc++.h> using namespace std; bool cmp(long long a, long long b) { return (a > b); } long long ceil(const long long &a, const long long &b) { if (a % b == 0) return a / b; return a / b + 1; } long long mod = 1000000007; const long long N = 105; string s; long long n1; long long...
#include <bits/stdc++.h> using namespace std; bool s[] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0}; int main() { string str; cin >> str; for (int x = 0; x < str.length() / 2; x++) { if (str[x] != str[str.length() - 1 - x]) { cout << NO ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 5; int n; long long int a[MAX], BIT[MAX]; void update(int idx, long long int val) { for (; idx <= n; idx += (idx & (-idx))) { BIT[idx] += val; } } long long int sum(int idx) { idx--; long long int sumi = 0; for (...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, sumk; cin >> n >> k; k--; int out[500][500]; sumk = 0; int current = n * n; for (int i = 0; i < n; ++i) { for (int j = n - 1; j >= k; --j) { out[i][j] = current; if (j == k) { sumk += cur...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1E-9; const int INF = (int)1E9; int deg[2005]; long long w[2005][2005]; int main() { int N, K; long long sum = 0, x; cin >> N >> K; memset(deg, 0, sizeof(deg)); for (int i = 0; i < (N); i++) ...
#include <bits/stdc++.h> using namespace std; const int N = 5 * 1e5 + 5; const int M = 2e6 + 5; vector<int> a[M], b[M]; vector<int> c[M], d[M]; int vis[M]; int n, w, cnt; int main() { scanf( %d%d , &n, &w); w--; for (int i = 1; i <= n; i++) { int k; scanf( %d , &k); a[i].re...
#include <bits/stdc++.h> using namespace std; template <typename U, typename V> void Min(U &a, const V &b) { if (a > b) a = b; } template <typename U, typename V> void Max(U &a, const V &b) { if (a < b) a = b; } template <typename U, typename V> void add(U &a, const V &b) { a = (a + b) % 1...
#include <bits/stdc++.h> int n, m; std::vector<std::pair<int, int> > a[2]; void normalize(std::vector<std::pair<int, int> >& v) { if (v.empty()) { return; } std::sort((v).begin(), (v).end()); int k = 1; for (int i = 1; i < ((int)(v).size()); i++) { if (v[i].first != v[i - 1].first)...
#include <bits/stdc++.h> using namespace std; bool SR(int &x) { return scanf( %d , &x) == 1; } bool SR(long long &x) { return scanf( %lld , &x) == 1; } bool SR(double &x) { return scanf( %lf , &x) == 1; } bool SR(char *s) { return scanf( %s , s) == 1; } bool RI() { return true; } template <typename I, typ...
#include <bits/stdc++.h> using namespace std; int const N = 13; int n, m, q; long long dp[N][1 << N]; struct lca { int u, v, c; }; struct edge { int u, v; }; vector<edge> edges; vector<lca> lcas; inline bool valid(int mask, int sub, int u, int v) { if (!(mask & (1 << u)) || !(mask & (1...
#include <bits/stdc++.h> using namespace std; const int maxn = 101000; int fa[maxn], sz[maxn], c[maxn]; int fd(int f) { return fa[f] == f ? f : fa[f] = fd(fa[f]); } int n, m, f[maxn]; bool isok(int x) { while (x) { int d = x % 10; if (d != 4 && d != 7) return false; x /= 10; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); int n, x, y; cin >> n >> x >> y; int a[n]; for (int j = 0; j < n; j++) cin >> a[j]; if (x > y) { cout << n; return 0; } int count = 0; for (int j = ...
#include <bits/stdc++.h> using namespace std; vector<int> g[100001]; long long v[100001]; pair<long long, long long> r[100001]; int mark[100001]; void dfs(int s) { mark[s] = 1; r[s] = pair<long long, long long>(0, 0); for (int i = 0; i < g[s].size(); i++) { if (!mark[g[s][i]]) { df...
#include <bits/stdc++.h> using namespace std; long long n, grid[2500][2500], R[10005], C[10005]; vector<pair<long long, pair<long long, long long> > > A, B; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = 0; i < n; i++) for (long long j = 0; j < n; j++) ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long now = 0; long long mx = -1; while (true) { long long rem = (n - (now * 7)); if (rem < 0) { break; ...
#include <bits/stdc++.h> using namespace std; int a[100005]; int Gcd(int x, int y) { if (y == 0) return x; return Gcd(y, x % y); } int main(void) { int n, i, ans; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + n + 1); ans = 0; for (i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char mat[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> mat[i][j]; } } char a = mat[0][0]; char b = mat[0][1]; if (a == b) { cout << NO << endl; re...
#include <bits/stdc++.h> long long prod_dig(long long n) { long long prod = 1; int a; while (n) { a = n % 10; if (a) { prod *= a; } n /= 10; } return prod; } int arr[10][1000000 + 1]; int main() { int t; for (int i = 1; i <= 1000000; i++) { t = i...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T Abs(T a) { return a > 0 ? a : -a; } void split(string s, string seps, vector<string> &res, bool doEmpty = false) { int start = 0; res.clear(); for (int i = 0; i < s.size(); i++) { if (seps.find(s[i]) != string::...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t > 0) { string s1, s2; cin >> s1 >> s2; long long int f = 0; if (s1.length() > s2.length()) { cout << NO << endl; f = -1; } else { long long int i = 0, j ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = 1; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (f) x = -x; } template <typename F> i...
#include<bits/stdc++.h> using namespace std; #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define endl n #define mp make_pair #define pb push_back...
#include <bits/stdc++.h> using namespace std; const int N = 100010, M = 1505, mod = 1e9 + 7; inline int qpow(int x, int y = mod - 2) { int res = 1; for (; y; y >>= 1, x = 1ll * x * x % mod) if (y & 1) res = 1ll * res * x % mod; return res; } int fac[N], inv[N]; inline int C(int x, int y) {...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; const long long L = 1e18 + 18; int Z; struct edge { int s; int t; long long W; int ind; edge(int a, int b, long long c, int I) { s = a; t = b; W = c; ind = I; } }; struct cmp { bool ope...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template <typename T> int SIZE(const T &t) { return t.size(); } st...