func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int maxn = 500010; int n, m; int pos[maxn]; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; inline void read(int &k) { int f = 1; k = 0; char c = getchar(); while (c < 0 || c > 9 ) c == - && (f = -1), c = getchar(); while (c <= ...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; int main() { int n; char mp[100][100]; cin >> n; for (int i = 0; i < n; ++i) cin >> mp[i]; auto isin = [&](int x) { return x >= 0 && x < n; }; auto isok = [&](int x, int y) { for (int ...
#include <bits/stdc++.h> using namespace std; const int N = 5005; vector<int> adj[N]; bool visited[N]; bool reach[N]; pair<int, int> has[N]; int cnt = 0; void dfs(int s) { if (!visited[s]) { visited[s] = 1; reach[s] = 1; for (int i = 0; i < adj[s].size(); i++) { dfs(adj[s][...
#include <bits/stdc++.h> using namespace std; int main() { vector<unsigned long long> v; char x2[] = 47 ; do { v.push_back(stoi(x2)); } while (next_permutation(x2, x2 + 2)); char x4[] = 4477 ; do { v.push_back(stoi(x4)); } while (next_permutation(x4, x4 + 4)); char x6[]...
#include <bits/stdc++.h> using namespace std; char a[100][1000] = {0}; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long int t; cin >> t; while (t--) { long long int n, m, x, y; cin >> n >> m >> x >> y; for (long long int i = 1; i <= n; i++) { for (...
#include <bits/stdc++.h> const int inf = int(1e9); const int mod = inf + 7; const double PI = acos(-1.0); using namespace std; const int N = 1e5 + 155; template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 111111; const int oo = (int)(1e9); int MOD = 1000000007; const long double PI = 3.141592653589793; template <typename TT> void read(TT &x) { char ch; for (ch = getchar(); ch > 9 || ch < 0 ; ch = getchar()) ; for (x = 0; ch...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 15; vector<int> g[N]; int n, m, b[N], r[N], a[N], res; void dfs(int v, int pa) { if (a[v] == 1) r[v]++; else if (a[v] == 2) b[v]++; for (int i : g[v]) { if (i == pa) continue; dfs(i, v); b[v] += b[i]; ...
#include <bits/stdc++.h> int pos = 1 << 17; char buf[1 << 17]; inline char nextch() { if (pos == 1 << 17) fread(buf, 1 << 17, 1, stdin), pos = 0; return buf[pos++]; } inline int read() { char ch; while (!isdigit(ch = nextch())) ; int x = ch - 0 ; while (isdigit(ch = nextch())) x...
#include <bits/stdc++.h> inline int read() { int f = 1, x = 0; 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(); } return f * x; } int dx[8] ...
#include <bits/stdc++.h> using namespace std; int modi = 1e9 + 7; unsigned long long gcd(unsigned long long a, unsigned long long b) { return !b ? a : gcd(b, a % b); } int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; ...
#include <bits/stdc++.h> using namespace std; const int maxx = 800010; int t, n, m, k, b, u; int ans = 0, total = 0, cnt = 0; int a[maxx], sum[maxx]; struct no { int num, l, r; bool operator<(const no &X) const { return r < X.r; } }; priority_queue<no> q; struct node { int num; int l; ...
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { return (a < b) ? a : b; } long long max(long long a, long long b) { return (a > b) ? a : b; } int main() { long long t, n, m, i, j, k = 0, p = 0; cin >> n; string s, q, r; cin >> s; p = s.size(); if (...
#include <bits/stdc++.h> using namespace std; void Solve() { long long T; cin >> T; while (T--) { long long b, w; cin >> b >> w; if (b > w * 3 + 1 || w > b * 3 + 1) { cout << NO n ; continue; } cout << YES n ; long long x = 2, y = 2; while (b &...
#include <bits/stdc++.h> int main() { int n, a, b, c, sum = 0, i, j; int d[10001] = {0}; scanf( %d %d %d %d , &n, &a, &b, &c); for (i = 0; i <= a / 2; i++) d[i]++; for (i = a / 2; i >= 0; i--) { for (j = 1; j <= b && i + j <= n; j++) { d[i + j]++; } } for (i = 0; i <= c...
#include <bits/stdc++.h> using namespace std; vector<pair<string, string>> taken; int main() { int n; scanf( %d , &n); int ans = 0; for (int i = 1; i <= n; ++i) { string s, t; cin >> s >> t; bool flag = 1; for (auto [x, y] : taken) { if (x == s && y == t) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long m, s = -1, l = 1, r = 1e18; cin >> m; while (l <= r) { long long as = 0, i; long long mid = (l + r) / 2; for (i = 2; i * i * i <= mid; i++) as += mid / (i * i * i); if (as == m) s = mid; if (as >= m) ...
#include <bits/stdc++.h> using namespace std; struct point { long long x, y; }; point p[345678]; vector<point> important, ugly; vector<int> ilist; int n; long long ans[345678]; long long distance(int i, int j) { return llabs(important[i].x - important[j].x) + llabs(important[i].y - ...
#include <bits/stdc++.h> struct str { char s[110]; } p[110]; int n; int ans[26], connect[26][26], v, e; int toposort(int n, int mat[][26], int* ret) { int d[26], i, j, k; for (i = 0; i < n; i++) for (d[i] = j = 0; j < n; d[i] += mat[j++][i]) ; for (k = 0; k < n; ret[k++] = i) { ...
#include <bits/stdc++.h> using namespace std; int n, m, q, k, a[110000], cnt, tmp[110000]; int edgenum = 1, vet[610000], val[610000], Next[610000], Head[110000]; double ang[610000]; bool vis[110000]; map<pair<int, int>, int> rnk; vector<long long> sum[110000]; struct node { int x, y; node() {} ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m == 3) { if (n == 3) { cout << 0 << << 0 << n ; cout << 0 << << 1 << n ; cout << 1 << << 0 << n ; return 0; } else if (n == 4) { cout << 0 << ...
#include <bits/stdc++.h> using namespace std; long long n, memo[100001]; vector<long long> a; long long x; long long rek(int pos) { long long &ret = memo[pos]; if (ret != -1) return ret; ret = rek(pos - 1) + 20; x = upper_bound(a.begin(), a.end(), a[pos] - 90) - a.begin(); if (x) ret...
#include <bits/stdc++.h> using namespace std; int main() { map<int, int> mp; int n, k; cin >> n >> k; int c; cin >> c; for (int i = 1; i <= c; i++) { int x; cin >> x; mp[x] = 1; } int ans = 0; int t = 0; for (int i = 1; i <= n; i++) { t++; if (mp...
#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; bool mat[3001][3001]; vector<int> v[3010]; int main() { int n, m, a, b, result = 0; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) mat[i][j] = false; for (int i = 0; i < m; i++) { cin >> a >> b; v[a].push_b...
#include <bits/stdc++.h> using namespace std; int n; double P[1000]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %lf , P + i); } sort(P, P + n); reverse(P, P + n); double x1 = 0; double x2 = 1; double res = 0; for (int i = 0; i < n; i++) { d...
#include <bits/stdc++.h> int main(void) { int size = 0; scanf( %ld , &size); char fmt[size + 1]; fmt[size] = 0 ; scanf( %s , fmt); int width = 0; int maxHeight = 1; int ithX[size]; int depth[size]; int currentDepth = 0; char ch = 0 ; for (size_t ith = 0; ith < size;...
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, x, y, T, ans, mx, mi, cas, num, len; bool flag; int p, a[25][105], b[25][105], c[25][105]; char s[1000]; int dp[1005]; int main() { scanf( %d%d%d , &n, &m, &p); for (i = 1; i <= n; i++) { scanf( %s , s); for (j = 1; j <= ...
#include <bits/stdc++.h> using namespace std; long long LLMAX = 9223372036854775807LL; const int MOD = 1000000007; const int maxn = 500001; int n; int a[maxn]; pair<int, int> p[maxn]; int pr[maxn], ne[maxn]; int main() { scanf( %d , &(n)); for (int(i) = 0; (i) < (int)(n); ++(i)) scanf( %d , &(...
#include <bits/stdc++.h> using namespace std; int main() { long long n; string a, b, c; vector<vector<long long> > arr(3, vector<long long>((26 * 2) + 1, 0)); cin >> n; cin >> a >> b >> c; long long len = a.length(); for (long long i = 0; i < len; i++) { char cur = a[i]; if (...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; const int inf = ~0U >> 1; template <class U, class V> struct MCMF { static const int N = 8000, M = 7001010; int h[N], ing[N], pre[N], to[M], ne[M], e, s, t, n; U cap[M]; V dis[N], cost[M]; void ini(int _n = N) { fil...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12); int l; cin >> l; string s; cin >> s; size_t t = 0; for (auto c : s) t += (c == 1 ); if (t * 2 == s.length()) { cout << 2 << endl; cout <<...
#include <bits/stdc++.h> using namespace std; inline void cmin(int &x, int y) { if (y < x) x = y; } inline void cmax(int &x, int y) { if (y > x) x = y; } const int N = 1000006; int a[12][N], sum[N], tmp[N], bcj[N], f[N][22], id[N], n, m, T, i, j, l, r; int inline read() { char ch = getchar()...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long int j, n, m, po, a, b, no, flag, cnt = 0, t, cnt2, ar[200001], x, y, i, co[200001], sum = 0, k, ans ...
#include <bits/stdc++.h> using namespace std; long long cnt[5], ans1, ans2; int main() { int n, a[200010]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) cnt[1]++; else cnt[0]++; } for (int i = 0; i < n; i++) { if (a[i] == 0) ...
#include <bits/stdc++.h> using namespace std; int n, m; char s[200], t[200]; int cnt[200], cnt2[200]; int check(int p, char t[]) { int i; for (i = 0; i < 26; i++) { cnt2[i] = 0; } for (i = p; i < p + n; i++) { cnt2[t[i] - a ]++; } for (i = 0; i < 26; i++) { if (cnt[i...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct node { long long k[51][51]; } a, ans; long long t, n, m, q, op, x, y, z, s = 1, mp[26][26]; inline long long read() { long long sum = 0, x = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch...
#include <bits/stdc++.h> using namespace std; long long power(long long base, long long exp) { long long res = 1; while (exp > 0) { if (exp % 2 == 1) res = (res * base); base = (base * base); exp /= 2; } return res; } long long mod(long long a, long long b) { return (a % b + b)...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<int> s; for (int i = 0; i < n; i++) { int x; cin >> x; if (x != 0) s.insert(x); } cout << s.size(); }
#include <bits/stdc++.h> using namespace std; const int MXN = 1024 * 1024; int n; int k; int v[MXN]; int c[MXN]; int p[MXN]; pair<int, int> vstk[MXN]; pair<int, int> cstk[MXN]; int vn, cn; static pair<int, int> getxy(int iv) { int p1 = vstk[iv].first; auto cx = lower_bound(cstk, cs...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int *input = new int[n]; for (int i = 0; i < n; i++) cin >> input[i]; sort(input, input + n); int over = input[n - 1] + 1; int ans = 1; for (...
#include <bits/stdc++.h> using namespace std; map<pair<string, string>, int> m, m1; vector<pair<string, string> > ans; int main() { string s1, s2; int n, t, i, d, j; scanf( %d%d , &n, &d); for (i = 1; i <= n; i++) { cin >> s1 >> s2 >> t; for (j = 0; j < ans.size(); j++) if ((...
#include <bits/stdc++.h> using namespace std; template <typename T, typename V> void bugp(const pair<T, V> &x) { cerr << { << x.first << , << x.second << } << endl; } template <typename T, typename U, typename V> void bugpp(const pair<T, pair<U, V> > &x) { cerr << { << x.first << , { << x...
#include <bits/stdc++.h> using namespace std; namespace io { inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } template <class I> inline void fr(I &num) { ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << std::endl; } 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; const int inf = 1e9; const long long Inf = 1e18; const int N = 1010; const int mod = 0; int gi() { int x = 0, o = 1; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) o = -1, ch = getchar(); while...
#include <bits/stdc++.h> using namespace std; char s[60]; int n; long long f[60][10]; int main() { gets(s + 1); n = strlen(s + 1); for (int j = 0; j < 10; ++j) f[1][j] = 1; for (int i = 1; i < n; ++i) for (int j = 0; j < 10; ++j) { int sum = j + s[i + 1] - 48; if (sum & 1...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long a[n]; long long m = 1e9; long long sum = 0; for (long long i = 0; i < n; ++i) cin >> a[i], m = min(m, a[i]), sum += a[i]; for (long long i = 0; i < n; ++i) { if ((a[i] - m) % k != 0)...
#include <bits/stdc++.h> using namespace std; int a, b, c, d; int ansa, ansb, ansc; 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 ) { x = x * 10 + c - 0 ; c = getchar(...
#include <bits/stdc++.h> using namespace std; int main() { set<int> a; int n, t; cin >> n; while (n--) { cin >> t; a.insert(t); } cout << ((a.count(0) == 1) ? a.size() - 1 : a.size()); return 0; }
#include <bits/stdc++.h> using namespace std; struct myhash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = long double; using pl = pair<ll, ll>; using pi = pair<int, int>; vector<pi> viz[100010]; pi p[100010]; double num[100010]; bool no; set<int> val; vector<int> in; void dfs(int u) { in.push_back(u); for (auto x ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; cin >> a >> b; n = a + b + 1; for (int i = n - a; i <= n; i++) cout << i << ; for (int i = n - a - 1; i >= 1; i--) cout << i << ; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, r; cin >> n >> r; if (r <= (n + 1) / 2) { cout << (2 * r - 1) << endl; } else { r -= (n + 1) / 2; cout << 2 * r << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007, n, m, siz[100010], s[210][210], dp[100010][210], f[210], sum[210]; vector<long long> g[100010]; void jia(long long &x, long long y) { x += y; if (x >= mod) x -= mod; } void dfs(long long x, long long fa) { dp[x...
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> #ifndef ONLINE_JUDGE //freopen( code...
#include <bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define int long long int #define ld long double #define endl n #define rep(i,a,b) for(int i=a;i<b;i++) #define reprev(i,a,b) for(int i=b-1;i>=a;i--) #define all(c) c.begin(),c....
#include <bits/stdc++.h> using namespace std; vector<int> edges[500000]; bool vis[500000]; int order[1000000]; int first[500000], second[500000]; int C; void dfs(int i) { vis[i] = 1; first[i] = C; order[C++] = i; for (int j = 0; j < edges[i].size(); j++) if (!vis[edges[i][j]]) dfs(ed...
#include <bits/stdc++.h> using namespace std; template <class C> void mini(C& a, C b) { a = min(a, b); } template <class C> void maxi(C& a, C b) { a = max(a, b); } void a() { int n; cin >> n; vector<int> a(n), b(n), c(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, o = 0, z = 0; cin >> n; string s; cin >> s; for (i = 0; i < n; i++) { if (s[i] == 1 ) o++; else z++; } if (z != o) { cout << 1 << endl << s; } else { cout << 2 << endl; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100], b[100], oa = 0, ob = 0, ore = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (a[i] % 2 == 1) oa++; if (b[i] % 2 == 1) ob++; if (a[i] % 2 == 1 && b[i] % 2 == 1) ore++; } if (oa % ...
#include <bits/stdc++.h> using namespace std; void Solves(); void In(int **a, int n); int main() { Solves(); return 0; } void Solves() { long long n, k; cin >> n >> k; if (k > n * n) { cout << -1; return; } int **a = new int *[n + 1]; for (int i = 0; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; int a[1000000], l[1000000], r[1000000]; int main() { int n; cin >> n; int minn = 10000000; int kol = 0; int ans = 0; int m = 2 * n - 1; for (int i = 0; i < m; i++) { cin >> a[i]; if (a[i] < 0) { kol++; a[i] = -a[...
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000001; void run_case() { long long n; cin >> n; vector<pair<long long, long long>> v; for (long long i = 0; i < n; i++) { long long x; cin >> x; v.push_back({x, i}); } sort(v.begin(), v.end()); v...
#include <bits/stdc++.h> using namespace std; int N, K; int A, B; signed long long from[505]; signed long long to[505]; void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> K; for (x = 0; x < (505); x++) for (y = 0; y < (505); y++) from[x] = -1LL << 60; from[0] = 0; in...
#include <bits/stdc++.h> using namespace std; int main() { multiset<long long> x, y; long long n, closing = 0, count = 0, i, j, pair = 0; cin >> n; string ss; for (i = 0; i < n; i++) { stack<char> s; closing = 0; cin >> ss; for (j = 0; j < ss.length(); j++) { if (...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int n, m, i, j, a, b; long long check(long long x, long long y) { if (x == i && y == j) return 0; if (abs(x - i) % a != 0 || abs(y - j) % b != 0) return inf; if (abs(abs(x - i) / a - abs(y - j) / b) & 1) return inf; if ((i...
#include <bits/stdc++.h> using namespace std; long long C[20][20]; long long dp[20]; int cnt[16]; int k, t; long long solve(int l) { memset(dp, 0, sizeof(dp)); dp[0] = 1; for (int j = 0; j < 16; j++) { for (int i = l; i >= 0; i--) { for (int k = 1; k <= min(l - i, t - cnt[j]); k++)...
/* Note : helluva implementation. Link : Boka hoye gelum... */ #include bits/stdc++.h #define sp << #define el << n #define S second #define F first #define pb push_back #define all(ar) ar.begin(),ar.end() #define pii...
#include <bits/stdc++.h> using namespace std; int a[1000010]; int solution[1000010] = {0}; int main() { ios::sync_with_stdio(0); int n; long long int sum = 0; long long int part; long long partSum = 0; long long int result = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >>...
#include <bits/stdc++.h> using namespace std; const long long int mx = 1e5 + 1, Mod = 1e9 + 7; int n, a[mx]; long long int dpl[mx][2], dpr[mx][2]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n - 1; i++) cin >> a[i]; dpl[0][0] = dpl[0][1...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) using namespace std; const int N = 1e5 + 2; vector<pair<int, int> > seg[3 * N][2]; long long int sig[3 * N]; int a[N]; vector<pair<int, int> > m[2]; int n, x; inline long long int mrg(vector<pair<int, int> > ...
#include <bits/stdc++.h> using namespace std; const int N = 1500 + 5, INF = 2000 * 1000 * 1000; vector<pair<int, int> > li[N]; vector<int> adj[N]; pair<pair<int, int>, int> po[N]; pair<int, int> J; int d[N], out[N]; void dfs(const int &v, const int &pa) { d[v] = 1; for (int i = 0; i < (int)(adj[...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); long long int a[n + 2]; for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); } long long int mx = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i != j) { ...
#include<bits/stdc++.h> #define pb push_back #define F first #define S second using namespace std; typedef long long ll; typedef pair<int,int>pi; typedef vector<int>vi; const int maxn=1e6+10; const int M=998244353; ll t[1<<14][105]; ll d[105][105],d2[105][14],d22[14][14]; ll mind[1<<14][105],min...
#include <bits/stdc++.h> using namespace std; long long n, a[200005]; long long k; int main() { scanf( %d%I64d , &n, &k); for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); int p; for (p = 1; p <= n && a[p] == 0; p++) ; p = n - p + 1; long long mx = 0; for (int i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; int h1 = stoi(s1.substr(0, 2)); int m1 = stoi(s1.substr(3, 2)); int h2 = stoi(s2.substr(0, 2)); int m2 = stoi(s2.substr(3, 2)); int m3 = (m1 + m2) / 2; int h3 = h1 + h2; if (h3 % 2 != 0) m3...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0, sch = 0, nm = -100000, pnm = 10000; vector<int> v; scanf( %d , &n); for (int i = 0; i < n; i++) { int t; scanf( %d , &t); if ((t % 2 == 1) && (t > 0)) { pnm = ((pnm) < (t)) ? (pnm) : (t); ans...
#include <bits/stdc++.h> struct Edge { int u, v; int w; }; struct RowEdges { int sum; std::vector<Edge> vs; RowEdges() : sum(0) {} Edge &back() { return vs.back(); } Edge &front() { return vs.front(); } Edge &operator[](int i) { return vs[i]; } int size() { return (int)vs.size(...
#include <bits/stdc++.h> using namespace std; void solve() { vector<pair<long long, long long>> ar(4); for (long long i = 1; i <= 3; i++) { long long a, b; cin >> a >> b; ar[i] = {a, b}; } sort(ar.begin() + 1, ar.end()); set<pair<long long, long long>> ans; for (long long i...
#include <bits/stdc++.h> long long a[2001], b[2001], n, m, x, sa[2001], sb[2001], ans; long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } int main() { std::cin >> n >> m; for (int i = 1; i <= n; i++) std::cin >> a[i],...
#include <bits/stdc++.h> using namespace std; char mp[1000]; int main() { int n, k; cin >> n >> k; string s; cin >> s; for (int i = 0; i < n; i++) { mp[s[i] - a ]++; if (mp[s[i] - a ] > k) { cout << NO ; return 0; } } cout << YES ; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int nex = 2e5 + 5; void solve() { int a, b; cin >> a >> b; string s; cin >> s; int cnt = 0; vector<int> v; for (int i = 0; i < ((int)s.size()); i++) { if (s[i] == X ) { if (cnt) v.push_back(cn...
#include <bits/stdc++.h> using namespace std; namespace Quick_Function { template <typename Temp> void Read(Temp &x) { x = 0; char ch = getchar(); bool op = 0; while (ch < 0 || ch > 9 ) { if (ch == - ) op = 1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, n; int s = 0; cin >> a >> b >> c >> d >> n; for (int i = 1; i <= n; i++) { if (i % a && i % b && i % c && i % d) { s++; } } cout << n - s; }
#include <bits/stdc++.h> using namespace std; int gr[1005][1005], n, m, a[1005], x, y; long long g[1005]; bool vis[1005]; int main() { scanf( %d , &n), scanf( %d , &m); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } int mi = 100000100, l1 = 0; int ans = 0; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; struct _ { _() { ios_base::sync_with_stdio(0); } } _; template <class A, class B> ostream &operator<<(ostream &o, pair<A, B> t) { o << ( << t.first << , << t.second << ) ; return o; } template <class T> string tostring(T first, int len = 0,...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math ) #pragma GCC target( popcnt,abm,mmx,tune=native ) using namespace std; long long n, i, j; int main() { [=]() { ios_base ::sync_with_stdio(false); cin.tie(nullptr); }(); cin >> n; for (; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; int cnt[2]; int main() { int n, k, m; scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) { scanf( %d , &m); cnt[m % 2]++; } int r = n - k; if (r == 0) { if (cnt[1] % 2 == 1) puts( Stannis ); else puts( Da...
#include <bits/stdc++.h> using namespace std; const int sz = 317; int t[100002], a[100002]; int l[100002], r[100002]; long long sum[2][100002]; long long ans[100002]; struct node { int b, r, i; }; bool cmp(node a, node b) { if (a.b != b.b) return a.b < b.b; return a.r < b.r; } int n, k...
#include <bits/stdc++.h> using namespace std; const int DAYS = 7; int val[DAYS]; void solve() { int k; cin >> k; int tot = 0; for (int i = 0; i < DAYS; ++i) { cin >> val[i]; tot += val[i]; } int res = 1 << 30; for (int start = 0; start < DAYS; ++start) { if (val[sta...
#include <bits/stdc++.h> using namespace std; const int MAXN = 300000000 + 10; bitset<MAXN> check; void Get_prime(int n) { check.set(); check[0] = check[1] = 0; for (int i = 2; i <= sqrt(n + 0.5); ++i) { if (check[i]) for (int j = 2; i * j <= n; ++j) check[i * j] = 0; } } int m...
#include <bits/stdc++.h> using namespace std; const long long maxn = 100010; long long n, S[maxn], top, ans[maxn], cnt; int main() { cin >> n; for (long long i = 1; i * i <= n; i++) if (n % i == 0) { S[++top] = i; if (i * i != n) S[++top] = n / i; } for (long long i = 1; ...
#include <bits/stdc++.h> using namespace std; int a, b, c, res; void mo() { freopen( 1091A.inp , r , stdin); freopen( 1091A.out , w , stdout); } void nhap() { cin >> a >> b >> c; } void xuli() { if (c - 1 <= b && c - 2 <= a) { res = max(res, c + c - 1 + c - 2); } if (b + 1 <= c &...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<long long> t(n), x(n); for (int i = 0; i < n; i++) { cin >> t[i] >> x[i];...
#include <bits/stdc++.h> using namespace std; pair<int, int> Max[3005][3005]; struct ans { int a, b, c; int i, j, k; ans(int _a, int _b, int _c, int _i, int _j, int _k) { a = _a; b = _b; c = _c; i = _i; j = _j; k = _k; } }; bool operator<(const ans &a, const...
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0; int zf = 1; char ch = ; while (ch != - && (ch < 0 || ch > 9 )) ch = getchar(); if (ch == - ) zf = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x ...
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n % 2 == 0) cout << 4 << n - 4; else cout << 9 << n - 9; }
#include <bits/stdc++.h> using namespace std; struct Node { int k1, k2, i; } node[105]; bool cmp1(const Node& a, const Node& b) { return a.k1 < b.k1; } bool cmp2(const Node& a, const Node& b) { return a.i < b.i; } int main() { int n, w; scanf( %d%d , &n, &w); for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int y, l, r, x, rem; cin >> l >> r; for (x = l; x <= r; x++) { y = x; set<int> s; while (y != 0) { rem = y % 10; if (s.find(rem) == s.end()) s.insert(rem); else break; y /= 10...